Bug 1412238 - WebAssembly.Global semantics adjustments. r=luke

Track some spec changes: WebAssembly.Global has valueOf, not
toPrimitive, and the value accessor is enumerable.

Also fix two moz.build files that did not get fixed when we allowed
the experiment with WebAssembly.Global to continue on early beta.

--HG--
extra : rebase_source : 3aee04ce3bb4de8cbcb7b7d37727547bf1d5f16b
This commit is contained in:
Lars T Hansen 2018-02-06 15:48:23 +01:00
Родитель b236e1b9d3
Коммит 692b1f0d35
4 изменённых файлов: 62 добавлений и 28 удалений

Просмотреть файл

@ -317,36 +317,67 @@ if (typeof WebAssembly.Global === "function") {
assertEq((new WebAssembly.Global({type: "i32", value: 3.14})).value, 3);
assertEq((new WebAssembly.Global({type: "f32", value: { valueOf: () => 33.5 }})).value, 33.5);
// Misc internal conversions
let g = new WebAssembly.Global({type: "i32", value: 42});
// Nothing special about NaN, it coerces just fine
assertEq((new WebAssembly.Global({type: "i32", value: NaN})).value, 0);
// @@toPrimitive
assertEq(g - 5, 37);
assertEq(String(g), "42");
{
// "value" is enumerable
let x = new WebAssembly.Global({type: "i32"});
let s = "";
for ( let i in x )
s = s + i + ",";
assertEq(s, "value,");
}
// @@toStringTag
assertEq(g.toString(), "[object WebAssembly.Global]");
// "value" is defined on the prototype, not on the object
assertEq("value" in WebAssembly.Global.prototype, true);
// An exported global should appear as a WebAssembly.Global instance:
let i =
new WebAssembly.Instance(
new WebAssembly.Module(
wasmTextToBinary(`(module (global (export "g") i32 (i32.const 42)))`)));
// Can't set the value of an immutable global
assertErrorMessage(() => (new WebAssembly.Global({type: "i32"})).value = 10,
TypeError,
/can't set value of immutable global/);
assertEq(typeof i.exports.g, "object");
assertEq(i.exports.g instanceof WebAssembly.Global, true);
{
// Misc internal conversions
let g = new WebAssembly.Global({type: "i32", value: 42});
// An exported global can be imported into another instance even if
// it is an object:
let j =
new WebAssembly.Instance(
new WebAssembly.Module(
wasmTextToBinary(`(module
(global (import "" "g") i32)
(func (export "f") (result i32)
(get_global 0)))`)),
{ "": { "g": i.exports.g }});
// valueOf
assertEq(g - 5, 37);
// And when it is then accessed it has the right value:
assertEq(j.exports.f(), 42);
// @@toStringTag
assertEq(g.toString(), "[object WebAssembly.Global]");
}
{
// An exported global should appear as a WebAssembly.Global instance:
let i =
new WebAssembly.Instance(
new WebAssembly.Module(
wasmTextToBinary(`(module (global (export "g") i32 (i32.const 42)))`)));
assertEq(typeof i.exports.g, "object");
assertEq(i.exports.g instanceof WebAssembly.Global, true);
// An exported global can be imported into another instance even if
// it is an object:
let j =
new WebAssembly.Instance(
new WebAssembly.Module(
wasmTextToBinary(`(module
(global (import "" "g") i32)
(func (export "f") (result i32)
(get_global 0)))`)),
{ "": { "g": i.exports.g }});
// And when it is then accessed it has the right value:
assertEq(j.exports.f(), 42);
}
// TEST THIS LAST
// "value" is deletable
assertEq(delete WebAssembly.Global.prototype.value, true);
assertEq("value" in WebAssembly.Global.prototype, false);
// ADD NO MORE TESTS HERE!
}

Просмотреть файл

@ -156,6 +156,7 @@ if CONFIG['JS_BUILD_BINAST'] and CONFIG['JS_STANDALONE']:
DEFINES['EXPORT_JS_API'] = True
DEFINES['ENABLE_WASM_GLOBAL'] = True
LOCAL_INCLUDES += [
'!..',

Просмотреть файл

@ -18,6 +18,7 @@ UNIFIED_SOURCES += [
]
DEFINES['EXPORT_JS_API'] = True
DEFINES['ENABLE_WASM_GLOBAL'] = True
# Also set in ../moz.build
DEFINES['ENABLE_SHARED_ARRAY_BUFFER'] = True

Просмотреть файл

@ -2154,13 +2154,14 @@ WasmGlobalObject::valueSetter(JSContext* cx, unsigned argc, Value* vp)
const JSPropertySpec WasmGlobalObject::properties[] =
{
JS_PSGS("value", WasmGlobalObject::valueGetter, WasmGlobalObject::valueSetter, 0),
JS_PSGS("value", WasmGlobalObject::valueGetter, WasmGlobalObject::valueSetter,
JSPROP_ENUMERATE),
JS_PS_END
};
const JSFunctionSpec WasmGlobalObject::methods[] =
{
JS_SYM_FN(toPrimitive, WasmGlobalObject::valueGetter, 1, JSPROP_READONLY),
JS_FN(js_valueOf_str, WasmGlobalObject::valueGetter, 0, 0),
JS_FS_END
};