Commit d2542089 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Don't allow anyref globals when anyref is not enabled

R=mstarzinger@chromium.org

Bug: v8:7581
Change-Id: I93044dc0065d1d0146ec9b5190e50ca63ce94f4e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1530808Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60341}
parent 979b3a33
......@@ -1192,6 +1192,7 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Local<v8::String> string;
if (!value->ToString(context).ToLocal(&string)) return;
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
if (string->StringEquals(v8_str(isolate, "i32"))) {
type = i::wasm::kWasmI32;
} else if (string->StringEquals(v8_str(isolate, "f32"))) {
......@@ -1200,9 +1201,11 @@ void WebAssemblyGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
type = i::wasm::kWasmI64;
} else if (string->StringEquals(v8_str(isolate, "f64"))) {
type = i::wasm::kWasmF64;
} else if (string->StringEquals(v8_str(isolate, "anyref"))) {
} else if (enabled_features.anyref &&
string->StringEquals(v8_str(isolate, "anyref"))) {
type = i::wasm::kWasmAnyRef;
} else if (string->StringEquals(v8_str(isolate, "anyfunc"))) {
} else if (enabled_features.anyref &&
string->StringEquals(v8_str(isolate, "anyfunc"))) {
type = i::wasm::kWasmAnyFunc;
} else {
thrower.TypeError(
......
......@@ -21,6 +21,10 @@ function assertGlobalIsValid(global) {
assertThrows(() => new WebAssembly.Global({}), TypeError);
assertThrows(() => new WebAssembly.Global({value: 'foo'}), TypeError);
assertThrows(() => new WebAssembly.Global({value: 'i128'}), TypeError);
// Without --experimental-wasm-anyref, globals of type {anyref} and {anyfunc}
// are not allowed.
assertThrows(() => new WebAssembly.Global({value: 'anyref'}), TypeError);
assertThrows(() => new WebAssembly.Global({value: 'anyfunc'}), TypeError);
for (let type of ['i32', 'f32', 'f64', 'i64']) {
assertGlobalIsValid(new WebAssembly.Global({value: type}));
......
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