Skip to content

Commit 521d704

Browse files
thibaudmichaudguybedford
authored andcommitted
deps: V8: backport 89dc6eab605c
Original commit message: [wasm] Add missing type canonicalization for exceptions JS API When we encode a JS value in a wasm exception, canonicalize the type stored in the tag's signature first. Canonicalize it using the tag's original module by storing the instance on the tag object. [email protected] Bug: 346197738 Change-Id: I7575fd79c792d98e4a11c00b466700f0ab82d164 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5613375 Commit-Queue: Thibaud Michaud <[email protected]> Reviewed-by: Jakob Kummerow <[email protected]> Cr-Commit-Position: refs/heads/main@{#94335} Refs: v8/v8@89dc6eab605c
1 parent 696df7e commit 521d704

6 files changed

Lines changed: 31 additions & 9 deletions

File tree

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.46',
41+
'v8_embedder_string': '-node.47',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/wasm/module-instantiate.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2655,8 +2655,10 @@ void InstanceBuilder::ProcessExports(
26552655
isolate_);
26562656
uint32_t canonical_sig_index =
26572657
module_->isorecursive_canonical_type_ids[tag.sig_index];
2658+
Handle<WasmInstanceObject> instance =
2659+
handle(trusted_instance_data->instance_object(), isolate_);
26582660
wrapper = WasmTagObject::New(isolate_, tag.sig, canonical_sig_index,
2659-
tag_object);
2661+
tag_object, instance);
26602662
tags_wrappers_[exp.index] = wrapper;
26612663
}
26622664
value = wrapper;

deps/v8/src/wasm/wasm-js.cc

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,8 @@ void WebAssemblyTagImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
18521852
i::wasm::GetWasmEngine()->type_canonicalizer()->AddRecursiveGroup(&sig);
18531853

18541854
i::Handle<i::JSObject> tag_object =
1855-
i::WasmTagObject::New(i_isolate, &sig, canonical_type_index, tag);
1855+
i::WasmTagObject::New(i_isolate, &sig, canonical_type_index, tag,
1856+
i_isolate->factory()->undefined_value());
18561857
info.GetReturnValue().Set(Utils::ToLocal(tag_object));
18571858
}
18581859

@@ -1898,6 +1899,7 @@ uint32_t GetEncodedSize(i::Handle<i::WasmTagObject> tag_object) {
18981899

18991900
void EncodeExceptionValues(v8::Isolate* isolate,
19001901
i::Handle<i::PodArray<i::wasm::ValueType>> signature,
1902+
i::Handle<i::WasmTagObject> tag_object,
19011903
const Local<Value>& arg, ErrorThrower* thrower,
19021904
i::Handle<i::FixedArray> values_out) {
19031905
Local<Context> context = isolate->GetCurrentContext();
@@ -1955,6 +1957,19 @@ void EncodeExceptionValues(v8::Isolate* isolate,
19551957
case i::wasm::kRefNull: {
19561958
const char* error_message;
19571959
i::Handle<i::Object> value_handle = Utils::OpenHandle(*value);
1960+
1961+
if (type.has_index()) {
1962+
// Canonicalize the type using the tag's original module.
1963+
i::Tagged<i::HeapObject> maybe_instance = tag_object->instance();
1964+
CHECK(!i::IsUndefined(maybe_instance));
1965+
auto instance = i::WasmInstanceObject::cast(maybe_instance);
1966+
const i::wasm::WasmModule* module = instance->module();
1967+
uint32_t canonical_index =
1968+
module->isorecursive_canonical_type_ids[type.ref_index()];
1969+
type = i::wasm::ValueType::RefMaybeNull(canonical_index,
1970+
type.nullability());
1971+
}
1972+
19581973
if (!internal::wasm::JSToWasmObject(i_isolate, value_handle, type,
19591974
&error_message)
19601975
.ToHandle(&value_handle)) {
@@ -2015,7 +2030,8 @@ void WebAssemblyExceptionImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
20152030
runtime_exception));
20162031
i::Handle<i::PodArray<i::wasm::ValueType>> signature(
20172032
tag_object->serialized_signature(), i_isolate);
2018-
EncodeExceptionValues(isolate, signature, info[1], &thrower, values);
2033+
EncodeExceptionValues(isolate, signature, tag_object, info[1], &thrower,
2034+
values);
20192035
if (thrower.error()) return;
20202036

20212037
// Third argument: optional ExceptionOption ({traceStack: <bool>}).
@@ -3231,9 +3247,9 @@ void WasmJs::PrepareForSnapshot(Isolate* isolate) {
32313247
// Note the canonical_type_index is reset in WasmJs::Install s.t.
32323248
// type_canonicalizer bookkeeping remains valid.
32333249
static constexpr uint32_t kInitialCanonicalTypeIndex = 0;
3234-
Handle<JSObject> js_tag_object =
3235-
WasmTagObject::New(isolate, &kWasmExceptionTagSignature,
3236-
kInitialCanonicalTypeIndex, js_tag);
3250+
Handle<JSObject> js_tag_object = WasmTagObject::New(
3251+
isolate, &kWasmExceptionTagSignature, kInitialCanonicalTypeIndex,
3252+
js_tag, isolate->factory()->undefined_value());
32373253
native_context->set_wasm_js_tag(*js_tag_object);
32383254
JSObject::AddProperty(isolate, webassembly, "JSTag", js_tag_object,
32393255
ro_attributes);

deps/v8/src/wasm/wasm-objects.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,8 @@ void WasmArray::SetTaggedElement(uint32_t index, Handle<Object> value,
17851785
Handle<WasmTagObject> WasmTagObject::New(Isolate* isolate,
17861786
const wasm::FunctionSig* sig,
17871787
uint32_t canonical_type_index,
1788-
Handle<HeapObject> tag) {
1788+
Handle<HeapObject> tag,
1789+
Handle<HeapObject> instance) {
17891790
Handle<JSFunction> tag_cons(isolate->native_context()->wasm_tag_constructor(),
17901791
isolate);
17911792

@@ -1806,6 +1807,7 @@ Handle<WasmTagObject> WasmTagObject::New(Isolate* isolate,
18061807
tag_wrapper->set_serialized_signature(*serialized_sig);
18071808
tag_wrapper->set_canonical_type_index(canonical_type_index);
18081809
tag_wrapper->set_tag(*tag);
1810+
tag_wrapper->set_instance(*instance);
18091811

18101812
return tag_wrapper;
18111813
}

deps/v8/src/wasm/wasm-objects.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ class WasmTagObject
605605
static Handle<WasmTagObject> New(Isolate* isolate,
606606
const wasm::FunctionSig* sig,
607607
uint32_t canonical_type_index,
608-
Handle<HeapObject> tag);
608+
Handle<HeapObject> tag,
609+
Handle<HeapObject> instance);
609610

610611
TQ_OBJECT_CONSTRUCTORS(WasmTagObject)
611612
};

deps/v8/src/wasm/wasm-objects.tq

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ extern class WasmGlobalObject extends JSObject {
211211
extern class WasmTagObject extends JSObject {
212212
serialized_signature: PodArrayOfWasmValueType;
213213
tag: HeapObject;
214+
instance: WasmInstanceObject|Undefined;
214215
canonical_type_index: Smi;
215216
}
216217

0 commit comments

Comments
 (0)