Commit 88efb908 authored by Asumu Takikawa's avatar Asumu Takikawa
Browse files

Bug 1511958 - Implement i64<>JavaScript's BigInt conversions proposal (part 6,...

Bug 1511958 - Implement i64<>JavaScript's BigInt conversions proposal (part 6, wasm global tests) r=lth

This is part 6 of a series of revs that split up D41710 (to implement the Wasm I64 to BigInt conversion proposal) into smaller revs.

The rev adds tests for wasm global handling with the Wasm to JS interface.

Differential Revision: https://phabricator.services.mozilla.com/D55902

--HG--
extra : moz-landing-system : lando
parent 8c1628c4
......@@ -195,9 +195,214 @@ function testMixedArgs() {
});
}
function testGlobalImport() {
var exports = wasmEvalText(
`(module
(import "g" "a" (global $a i64))
(import "g" "b" (global $b i64))
(import "g" "c" (global $c i64))
(export "a" (global $a))
(export "b" (global $b))
(export "c" (global $c))
)`,
{ g: { a: 1n, b: 2n ** 63n, c: "123" } }
).exports;
testWithJit(() => {
assertEq(exports.a.value, 1n);
assertEq(exports.b.value, -(2n ** 63n));
assertEq(exports.c.value, 123n);
});
}
function testMutableGlobalImport() {
var exports = wasmEvalText(
`(module
(import "g" "a" (global $a (mut i64)))
(import "g" "b" (global $b (mut i64)))
(export "a" (global $a))
(export "b" (global $b))
)`,
{
g: {
a: new WebAssembly.Global({ value: "i64", mutable: true }, 1n),
b: new WebAssembly.Global({ value: "i64", mutable: true }, "2"),
},
}
).exports;
testWithJit(() => {
assertEq(exports.a.value, 1n);
assertEq(exports.b.value, 2n);
});
}
function testMutableGlobalImportLiteral() {
assertErrorMessage(
() =>
wasmEvalText(
`(module
(import "g" "a" (global $a (mut i64)))
)`,
{ g: { a: 1n } }
),
WebAssembly.LinkError,
"imported global mutability mismatch"
);
}
function testGlobalBadImportLiteral() {
assertErrorMessage(
() =>
wasmEvalText(
`(module
(import "g" "a" (global $a i64))
(export "a" (global $a))
)`,
{ g: { a: 1 } }
),
WebAssembly.LinkError,
"import object field 'a' is not a BigInt"
);
assertErrorMessage(
() =>
wasmEvalText(
`(module
(import "g" "a" (global $a i64))
(export "a" (global $a))
)`,
{ g: { a: "foo" } }
),
SyntaxError,
"invalid BigInt syntax"
);
}
// This exercises error code paths that can be taken when
// HasI64BigIntSupport() is true, though the test does not directly deal
// with I64 types.
function testGlobalBadImportNumber() {
assertErrorMessage(
() =>
wasmEvalText(
`(module
(import "g" "a" (global $a i32))
(export "a" (global $a))
)`,
{ g: { a: 1n } }
),
WebAssembly.LinkError,
"import object field 'a' is not a Number"
);
assertErrorMessage(
() =>
wasmEvalText(
`(module
(import "g" "a" (global $a i32))
(export "a" (global $a))
)`,
{ g: { a: "foo" } }
),
WebAssembly.LinkError,
"import object field 'a' is not a Number"
);
}
function testI64Global() {
var global = new WebAssembly.Global({ value: "i64", mutable: true });
assertEq(global.value, 0n); // initial value
global.value = 123n;
assertEq(global.value, 123n);
global.value = 2n ** 63n;
assertEq(global.value, -(2n ** 63n));
global.value = "123";
assertEq(global.value, 123n);
}
function testI64GlobalValueOf() {
var argument = { value: "i64" };
// as literal
var global = new WebAssembly.Global(argument, {
valueOf() {
return 123n;
},
});
assertEq(global.value, 123n);
// as string
var global2 = new WebAssembly.Global(argument, {
valueOf() {
return "123";
},
});
assertEq(global.value, 123n);
}
function testGlobalI64ValueWrongType() {
var argument = { value: "i64" };
assertErrorMessage(
() => new WebAssembly.Global(argument, 666),
TypeError,
"not a BigInt"
);
assertErrorMessage(
() => new WebAssembly.Global(argument, "foo"),
SyntaxError,
"invalid BigInt syntax"
);
assertErrorMessage(
() =>
new WebAssembly.Global(argument, {
valueOf() {
return 5;
},
}),
TypeError,
"not a BigInt"
);
}
function testGlobalI64SetWrongType() {
var global = new WebAssembly.Global({ value: "i64", mutable: true });
assertErrorMessage(() => (global.value = 1), TypeError, "not a BigInt");
assertErrorMessage(
() => (global.value = "foo"),
SyntaxError,
"invalid BigInt syntax"
);
assertErrorMessage(
() =>
(global.value = {
valueOf() {
return 5;
},
}),
TypeError,
"not a BigInt"
);
}
testRet();
testId();
testIdPlus();
testManyArgs();
testImportExport();
testMixedArgs();
testGlobalImport();
testMutableGlobalImport();
testMutableGlobalImportLiteral();
testGlobalBadImportLiteral();
testGlobalBadImportNumber();
testI64Global();
testI64GlobalValueOf();
testGlobalI64ValueWrongType();
testGlobalI64SetWrongType();
Supports Markdown
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