Skip to content

Commit f49efcf

Browse files
thibaudmichaudguybedford
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. [email protected] Bug: 333067164 Change-Id: I6f43df8d254dd7450137d99ff7cc9cbffb697663 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5454404 Reviewed-by: Andreas Haas <[email protected]> Commit-Queue: Thibaud Michaud <[email protected]> Cr-Commit-Position: refs/heads/main@{#93398} Refs: v8/v8@b8f91e5
1 parent 652fc6e commit f49efcf

5 files changed

Lines changed: 43 additions & 35 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.44',
41+
'v8_embedder_string': '-node.45',
4242

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

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
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
4141
}});
4242

4343
let obj = {};
44+
// Creating a WA.Exception with the JSTag explicitly is not allowed.
45+
assertThrows(() => new WebAssembly.Exception(WebAssembly.JSTag, [obj]), TypeError);
4446

4547
// Catch with implicit wrapping.
4648
assertSame(obj, instance.exports.test(obj));
47-
// Catch with explicit wrapping.
48-
assertSame(obj, instance.exports.test(new WebAssembly.Exception(WebAssembly.JSTag, [obj])));
4949
// Don't catch with explicit wrapping.
5050
let not_js_tag = new WebAssembly.Tag({parameters:['externref']});
5151
let exn = new WebAssembly.Exception(not_js_tag, [obj]);
@@ -63,10 +63,6 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
6363
// Catch with explicit wrapping.
6464
assertSame(obj, instance.exports.test(new WebAssembly.Exception(not_js_tag, [obj])));
6565
// Don't catch with explicit wrapping.
66-
exn = new WebAssembly.Exception(WebAssembly.JSTag, [obj]);
67-
// TODO(thibaudm): Should the exception get implicitly unwrapped when it
68-
// bubbles up from wasm to JS, even though it was wrapped explicitly?
69-
assertThrowsEquals(() => instance.exports.test(exn), exn);
7066
// Don't catch with implicit wrapping.
7167
assertThrowsEquals(() => instance.exports.test(obj), obj);
7268
})();
@@ -107,8 +103,6 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
107103

108104
// Catch with implicit wrapping.
109105
assertSame(obj, instance.exports.test(obj));
110-
// Catch with explicit wrapping.
111-
assertSame(obj, instance.exports.test(new WebAssembly.Exception(WebAssembly.JSTag, [obj])));
112106
// Don't catch with explicit wrapping.
113107
let not_js_tag = new WebAssembly.Tag({parameters:['externref']});
114108
let exn = new WebAssembly.Exception(not_js_tag, [obj]);
@@ -125,11 +119,6 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
125119

126120
// Catch with explicit wrapping.
127121
assertSame(obj, instance.exports.test(new WebAssembly.Exception(not_js_tag, [obj])));
128-
// Don't catch with explicit wrapping.
129-
exn = new WebAssembly.Exception(WebAssembly.JSTag, [obj]);
130-
// TODO(thibaudm): Should the exception get implicitly unwrapped when it
131-
// bubbles up from wasm to JS, even though it was wrapped explicitly?
132-
assertThrowsEquals(() => instance.exports.test(exn), exn);
133122
// Don't catch with implicit wrapping.
134123
assertThrowsEquals(() => instance.exports.test(obj), obj);
135124
})();
@@ -171,11 +160,6 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
171160

172161
// Catch and rethrown with implicit wrapping.
173162
assertThrowsEquals(() => instance.exports.test(obj), obj);
174-
// Catch and rethrown with explicit wrapping.
175-
// TODO: Should the exception get implicitly unwrapped when it
176-
// is rethrown from wasm to JS, even though it was wrapped explicitly?
177-
let exn = new WebAssembly.Exception(WebAssembly.JSTag, [obj]);
178-
assertThrowsEquals(() => instance.exports.test(exn), exn);
179163
// Don't catch with explicit wrapping.
180164
let not_js_tag = new WebAssembly.Tag({parameters:['externref']});
181165
exn = new WebAssembly.Exception(not_js_tag, [obj]);
@@ -193,11 +177,29 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
193177
// Catch and rethrow with explicit wrapping -> not unwrapped in this case.
194178
exn = new WebAssembly.Exception(not_js_tag, [obj]);
195179
assertThrowsEquals(() => instance.exports.test(exn), exn);
196-
// Don't catch with explicit wrapping.
197-
exn = new WebAssembly.Exception(WebAssembly.JSTag, [obj]);
198-
// TODO(thibaudm): Should the exception get implicitly unwrapped when it
199-
// bubbles up from wasm to JS, even though it was wrapped explicitly?
200-
assertThrowsEquals(() => instance.exports.test(exn), exn);
201180
// Don't catch with implicit wrapping.
202181
assertThrowsEquals(() => instance.exports.test(obj), obj);
203182
})();
183+
184+
(function TestThrowJSTag() {
185+
print(arguments.callee.name);
186+
let builder = new WasmModuleBuilder();
187+
let js_tag = builder.addImportedTag("", "tag", kSig_v_r);
188+
189+
// Throw a JS object with WebAssembly.JSTag and check that we can catch
190+
// it as-is from JavaScript.
191+
builder.addFunction("test", kSig_v_r)
192+
.addBody([
193+
kExprLocalGet, 0,
194+
kExprThrow, js_tag,
195+
])
196+
.exportFunc();
197+
198+
let instance = builder.instantiate({"": {
199+
tag: WebAssembly.JSTag,
200+
}});
201+
202+
let obj = {};
203+
assertThrowsEquals(() => instance.exports.test(obj), obj);
204+
assertThrowsEquals(() => instance.exports.test(5), 5);
205+
})();

0 commit comments

Comments
 (0)