Skip to content

Commit 00480c9

Browse files
thibaudmichaudguybedford
authored andcommitted
deps: V8: cherry-pick b2f3aea23a01
Original commit message: [wasm][exnref] Do not allow exnref at the wasm/JS boundary [email protected] Bug: v8:14398 Change-Id: I5bb75a83e9de9f838d8e530c77c89aa031f473f9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5381603 Reviewed-by: Matthias Liedtke <[email protected]> Commit-Queue: Thibaud Michaud <[email protected]> Cr-Commit-Position: refs/heads/main@{#92944} Refs: v8/v8@b2f3aea
1 parent 9568ca7 commit 00480c9

8 files changed

Lines changed: 145 additions & 56 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.40',
41+
'v8_embedder_string': '-node.41',
4242

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

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,9 +2445,9 @@ void WebAssemblyTableGrowImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
24452445
namespace {
24462446
void WasmObjectToJSReturnValue(v8::ReturnValue<v8::Value>& return_value,
24472447
i::Handle<i::Object> value,
2448-
i::wasm::HeapType type, i::Isolate* isolate,
2448+
i::wasm::ValueType type, i::Isolate* isolate,
24492449
ErrorThrower* thrower) {
2450-
switch (type.representation()) {
2450+
switch (type.heap_type().representation()) {
24512451
case internal::wasm::HeapType::kStringViewWtf8:
24522452
thrower->TypeError("%s", "stringview_wtf8 has no JS representation");
24532453
break;
@@ -2457,6 +2457,10 @@ void WasmObjectToJSReturnValue(v8::ReturnValue<v8::Value>& return_value,
24572457
case internal::wasm::HeapType::kStringViewIter:
24582458
thrower->TypeError("%s", "stringview_iter has no JS representation");
24592459
break;
2460+
case internal::wasm::HeapType::kExn:
2461+
case internal::wasm::HeapType::kNoExn:
2462+
thrower->TypeError("invalid type %s", type.name().c_str());
2463+
break;
24602464
default: {
24612465
return_value.Set(Utils::ToLocal(i::wasm::WasmToJSObject(isolate, value)));
24622466
break;
@@ -2490,8 +2494,8 @@ void WebAssemblyTableGetImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
24902494
i::WasmTableObject::Get(i_isolate, receiver, index);
24912495

24922496
v8::ReturnValue<v8::Value> return_value = info.GetReturnValue();
2493-
WasmObjectToJSReturnValue(return_value, result, receiver->type().heap_type(),
2494-
i_isolate, &thrower);
2497+
WasmObjectToJSReturnValue(return_value, result, receiver->type(), i_isolate,
2498+
&thrower);
24952499
}
24962500

24972501
// WebAssembly.Table.set(num, any)
@@ -2767,8 +2771,7 @@ void WebAssemblyExceptionGetArgImpl(
27672771
case i::wasm::kRefNull: {
27682772
i::Handle<i::Object> obj = handle(values->get(decode_index), i_isolate);
27692773
ReturnValue<Value> return_value = info.GetReturnValue();
2770-
return WasmObjectToJSReturnValue(return_value, obj,
2771-
signature->get(index).heap_type(),
2774+
return WasmObjectToJSReturnValue(return_value, obj, signature->get(index),
27722775
i_isolate, &thrower);
27732776
}
27742777
case i::wasm::kRtt:
@@ -2836,8 +2839,7 @@ void WebAssemblyGlobalGetValueCommon(
28362839
case i::wasm::kRef:
28372840
case i::wasm::kRefNull: {
28382841
WasmObjectToJSReturnValue(return_value, receiver->GetRef(),
2839-
receiver->type().heap_type(), i_isolate,
2840-
&thrower);
2842+
receiver->type(), i_isolate, &thrower);
28412843
break;
28422844
}
28432845
case i::wasm::kRtt:

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,12 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
25472547
case HeapType::kStringViewIter:
25482548
*error_message = "stringview_iter has no JS representation";
25492549
return {};
2550+
case HeapType::kExn:
2551+
*error_message = "invalid type (ref null exn)";
2552+
return {};
2553+
case HeapType::kNoExn:
2554+
*error_message = "invalid type (ref null noexn)";
2555+
return {};
25502556
default: {
25512557
HeapType::Representation repr =
25522558
expected_canonical.heap_representation_non_shared();
@@ -2589,8 +2595,7 @@ MaybeHandle<Object> JSToWasmObject(Isolate* isolate, Handle<Object> value,
25892595
return {};
25902596
}
25912597
case HeapType::kExn:
2592-
if (!IsNull(*value, isolate)) return value;
2593-
*error_message = "null is not allowed for (ref exn)";
2598+
*error_message = "invalid type (ref exn)";
25942599
return {};
25952600
case HeapType::kStruct: {
25962601
if (IsWasmStruct(*value)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bool IsJSCompatibleSignature(const FunctionSig* sig) {
3333
// Rtts are internal-only. They should never be part of a signature.
3434
DCHECK(!type.is_rtt());
3535
if (type == kWasmS128) return false;
36+
if (type == kWasmExnRef) return false;
3637
if (type.is_object_reference()) {
3738
switch (type.heap_representation_non_shared()) {
3839
case HeapType::kStringViewWtf8:

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ let kSig_e_v = makeSig([], [kWasmExnRef]);
2828
print(arguments.callee.name);
2929
let builder = new WasmModuleBuilder();
3030
let g = builder.addGlobal(kWasmExnRef, false, false);
31-
builder.addFunction('push_and_return_exnref', kSig_e_v)
32-
.addBody([kExprGlobalGet, g.index])
31+
builder.addFunction('push_and_check_exnref', kSig_i_v)
32+
.addBody([
33+
kExprGlobalGet, g.index,
34+
kExprRefIsNull, kExnRefCode,
35+
])
3336
.exportFunc();
3437
let instance = builder.instantiate();
3538

36-
assertEquals(null, instance.exports.push_and_return_exnref());
39+
assertEquals(1, instance.exports.push_and_check_exnref());
3740
})();
3841

3942
// Test custom initialization index for a global "exnref" variable.
@@ -44,8 +47,16 @@ let kSig_e_v = makeSig([], [kWasmExnRef]);
4447
builder.addFunction('push_and_return_exnref', kSig_e_v)
4548
.addBody([kExprGlobalGet, g_index])
4649
.exportFunc();
47-
let exception = { x: "my fancy exception" };
48-
let instance = builder.instantiate({ "m": { "exn": exception }});
50+
assertThrows(() => builder.instantiate({ "m": { "exn": {} }}), WebAssembly.LinkError);
51+
assertThrows(() => builder.instantiate({ "m": { "exn": null }}), WebAssembly.LinkError);
52+
})();
4953

50-
assertSame(exception, instance.exports.push_and_return_exnref());
54+
(function TestGlobalExnRefJsApi() {
55+
print(arguments.callee.name);
56+
57+
let builder = new WasmModuleBuilder();
58+
let g_index = builder.addGlobal(kWasmExnRef, true, false).exportAs('g');
59+
let instance = builder.instantiate();
60+
assertThrows(() => new WebAssembly.Global({value: "exnref", mutable: true}, null), TypeError);
61+
assertThrows(() => { instance.exports.g.value; }, TypeError);
5162
})();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,11 @@ d8.file.execute("test/mjsunit/wasm/exceptions-utils.js");
611611
kExprEnd,
612612
kExprReturn,
613613
kExprEnd,
614-
kExprGlobalSet, g.index,
614+
kExprThrowRef
615615
]).exportFunc();
616616
let instance = builder.instantiate();
617617

618-
instance.exports.catch_all_ref();
619-
assertTrue(instance.exports.g.value instanceof WebAssembly.Exception);
618+
assertThrows(instance.exports.catch_all_ref, WebAssembly.Exception);
620619
})();
621620

622621
(function TestCatchRefTwoParams() {

0 commit comments

Comments
 (0)