зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
b236e1b9d3
Коммит
692b1f0d35
|
@ -317,16 +317,38 @@ 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);
|
||||
|
||||
// Nothing special about NaN, it coerces just fine
|
||||
assertEq((new WebAssembly.Global({type: "i32", value: NaN})).value, 0);
|
||||
|
||||
{
|
||||
// "value" is enumerable
|
||||
let x = new WebAssembly.Global({type: "i32"});
|
||||
let s = "";
|
||||
for ( let i in x )
|
||||
s = s + i + ",";
|
||||
assertEq(s, "value,");
|
||||
}
|
||||
|
||||
// "value" is defined on the prototype, not on the object
|
||||
assertEq("value" in WebAssembly.Global.prototype, true);
|
||||
|
||||
// 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/);
|
||||
|
||||
{
|
||||
// Misc internal conversions
|
||||
let g = new WebAssembly.Global({type: "i32", value: 42});
|
||||
|
||||
// @@toPrimitive
|
||||
// valueOf
|
||||
assertEq(g - 5, 37);
|
||||
assertEq(String(g), "42");
|
||||
|
||||
// @@toStringTag
|
||||
assertEq(g.toString(), "[object WebAssembly.Global]");
|
||||
}
|
||||
|
||||
{
|
||||
// An exported global should appear as a WebAssembly.Global instance:
|
||||
let i =
|
||||
new WebAssembly.Instance(
|
||||
|
@ -349,4 +371,13 @@ if (typeof WebAssembly.Global === "function") {
|
|||
|
||||
// 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
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче