Commit ad938456 authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[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/+/2940901Reviewed-by: 's avatarEmanuel Ziegler <ecmziegler@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74982}
parent ce1366a2
......@@ -1885,7 +1885,7 @@ void WebAssemblyGlobalSetValue(
thrower.TypeError("Can't set the value of an immutable global.");
return;
}
if (args[0]->IsUndefined()) {
if (args.Length() == 0) {
thrower.TypeError("Argument 0 is required");
return;
}
......
......@@ -249,7 +249,7 @@ function dummy_func() {
}
TestGlobal(null);
assertThrows(() => TestGlobal(undefined), TypeError);
TestGlobal(undefined);
TestGlobal(1663);
TestGlobal("testmyglobal");
TestGlobal({ a: 11 });
......
......@@ -206,3 +206,20 @@ TestGlobalIndexSpace(kWasmF64, 12345.678);
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);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment