deps: V8: cherry-pick b8f91e510e0f · nodejs/node@d0c24a2 · GitHub
Skip to content

Commit d0c24a2

Browse files
thibaudmichaudmarco-ippolito
authored andcommitted
deps: V8: cherry-pick b8f91e510e0f
Original commit message: [wasm][exnref] Update WA.JSTag semantics According to the last spec updates: - Passing WebAssembly.JSTag to the WebAssembly.Exception constructor is not allowed in JS, - Throwing an exception with the JSTag in wasm is allowed, but the exception should conceptually be "unwrapped" when it exits wasm, and JS should observe the raw externref. Instead, we simply throw the externref in this case, which has the same observable behavior and is consistent with how JSTag has been implemented so far. R=ahaas@chromium.org Bug: 333067164 Change-Id: I6f43df8d254dd7450137d99ff7cc9cbffb697663 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5454404 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Thibaud Michaud <thibaudm@chromium.org> Cr-Commit-Position: refs/heads/main@{#93398} Refs: v8/v8@b8f91e5 PR-URL: #62783 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d358687 commit d0c24a2

5 files changed

Lines changed: 43 additions & 35 deletions

File tree

common.gypi

Lines changed: 1 addition & 1 deletion

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,18 @@ RUNTIME_FUNCTION(Runtime_WasmThrow) {
354354
ClearThreadInWasmScope clear_wasm_flag(isolate);
355355
HandleScope scope(isolate);
356356
DCHECK_EQ(2, args.length());
357-
isolate->set_context(GetNativeContextFromWasmInstanceOnStackTop(isolate));
357+
Tagged<Context> context = GetNativeContextFromWasmInstanceOnStackTop(isolate);
358+
isolate->set_context(context);
358359
Handle<WasmExceptionTag> tag(WasmExceptionTag::cast(args[0]), isolate);
359360
Handle<FixedArray> values(FixedArray::cast(args[1]), isolate);
360-
Handle<WasmExceptionPackage> exception =
361-
WasmExceptionPackage::New(isolate, tag, values);
362-
return isolate->Throw(*exception);
361+
auto js_tag = WasmTagObject::cast(context->wasm_js_tag());
362+
if (*tag == js_tag->tag()) {
363+
return isolate->Throw(values->get(0));
364+
} else {
365+
Handle<WasmExceptionPackage> exception =
366+
WasmExceptionPackage::New(isolate, tag, values);
367+
return isolate->Throw(*exception);
368+
}
363369
}
364370

365371
RUNTIME_FUNCTION(Runtime_WasmReThrow) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,11 @@ void WebAssemblyExceptionImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
20012001
i::Handle<i::WasmTagObject>::cast(arg0);
20022002
i::Handle<i::WasmExceptionTag> tag(
20032003
i::WasmExceptionTag::cast(tag_object->tag()), i_isolate);
2004+
auto js_tag = i::WasmTagObject::cast(i_isolate->context()->wasm_js_tag());
2005+
if (*tag == js_tag->tag()) {
2006+
thrower.TypeError("Argument 0 cannot be WebAssembly.JSTag");
2007+
return;
2008+
}
20042009
uint32_t size = GetEncodedSize(tag_object);
20052010
i::Handle<i::WasmExceptionPackage> runtime_exception =
20062011
i::WasmExceptionPackage::New(i_isolate, tag, size);

deps/v8/test/mjsunit/wasm/exceptions-api.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,11 @@ function TestGetArgHelper(types_str, types, values) {
295295
}});
296296

297297
let obj = {};
298+
// Creating a WA.Exception with the JSTag explicitly is not allowed.
299+
assertThrows(() => new WebAssembly.Exception(WebAssembly.JSTag, [obj]), TypeError);
298300

299301
// Catch with implicit wrapping.
300302
assertSame(obj, instance.exports.test(obj));
301-
// Catch with explicit wrapping.
302-
assertSame(obj, instance.exports.test(new WebAssembly.Exception(WebAssembly.JSTag, [obj])));
303303
// Don't catch with explicit wrapping.
304304
let not_js_tag = new WebAssembly.Tag({parameters:['externref']});
305305
let exn = new WebAssembly.Exception(not_js_tag, [obj]);
@@ -316,11 +316,6 @@ function TestGetArgHelper(types_str, types, values) {
316316

317317
// Catch with explicit wrapping.
318318
assertSame(obj, instance.exports.test(new WebAssembly.Exception(not_js_tag, [obj])));
319-
// Don't catch with explicit wrapping.
320-
exn = new WebAssembly.Exception(WebAssembly.JSTag, [obj]);
321-
// TODO(thibaudm): Should the exception get implicitly unwrapped when it
322-
// bubbles up from wasm to JS, even though it was wrapped explicitly?
323-
assertThrowsEquals(() => instance.exports.test(exn), exn);
324319
// Don't catch with implicit wrapping.
325320
assertThrowsEquals(() => instance.exports.test(obj), obj);
326321
})();

deps/v8/test/mjsunit/wasm/exnref-api.js

Lines changed: 25 additions & 23 deletions

0 commit comments

Comments
 (0)