[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/+/1530808
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60341}
This commit is contained in:
Andreas Haas 2019-03-19 15:51:39 +01:00 committed by Commit Bot
parent 979b3a33d7
commit d2542089c7
2 changed files with 9 additions and 2 deletions

View File

@ -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(

View File

@ -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}));