[wasm] Allow WebAssembly.Global.value.set to be called with undefined

A spec test (wasm-js/global/value-get-set) requires
WebAssembly.Global.value.set to throw an exception if it is called with
0 arguments. The implementation in V8, however, just checked if the
first parameter is `undefined`. This implementation indeed threw an
exception if 0 arguments were provided, but it also threw an exception
when `undefined` is provided as a parameter. This, however, violates
the spec, because globals can be reset to `undefined`.

With this CL we replace the checking for `undefined` by checking the
length of the arguments that get provided.

R=ecmziegler@chromium.org

Bug: chromium:1211342
Change-Id: Ic87a0b369dea3e49eddb8f71f2c29dc6a8f5f558
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2940901
Reviewed-by: Emanuel Ziegler <ecmziegler@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74982}
This commit is contained in:
Andreas Haas 2021-06-07 15:03:19 +02:00 committed by V8 LUCI CQ
parent ce1366a2df
commit ad9384560f
3 changed files with 19 additions and 2 deletions

View File

@ -1885,7 +1885,7 @@ void WebAssemblyGlobalSetValue(
thrower.TypeError("Can't set the value of an immutable global."); thrower.TypeError("Can't set the value of an immutable global.");
return; return;
} }
if (args[0]->IsUndefined()) { if (args.Length() == 0) {
thrower.TypeError("Argument 0 is required"); thrower.TypeError("Argument 0 is required");
return; return;
} }

View File

@ -249,7 +249,7 @@ function dummy_func() {
} }
TestGlobal(null); TestGlobal(null);
assertThrows(() => TestGlobal(undefined), TypeError); TestGlobal(undefined);
TestGlobal(1663); TestGlobal(1663);
TestGlobal("testmyglobal"); TestGlobal("testmyglobal");
TestGlobal({ a: 11 }); TestGlobal({ a: 11 });

View File

@ -206,3 +206,20 @@ TestGlobalIndexSpace(kWasmF64, 12345.678);
assertEquals(9, get(1)); assertEquals(9, get(1));
})(); })();
(function testAssignUndefinedToGlobal() {
print(arguments.callee.name);
let i32_global = new WebAssembly.Global({mutable: true, value: 'i32'});
i32_global.value = undefined;
assertSame(0, i32_global.value);
let i64_global = new WebAssembly.Global({mutable: true, value: 'i64'});
assertThrows(() => {
i64_global.value = undefined;
}, TypeError);
let f32_global = new WebAssembly.Global({mutable: true, value: 'f32'});
f32_global.value = undefined;
assertSame(NaN, f32_global.value);
let f64_global = new WebAssembly.Global({mutable: true, value: 'f64'});
f64_global.value = undefined;
assertSame(NaN, f64_global.value);
})();