forked from mirrors/gecko-dev
Bug 1876148 - wasm: Validate accepts feature options. r=yury
WebAssembly.validate can take feature options, like enabling js-string-builtins. This is useful for feature detection. The test is extended to use it. Differential Revision: https://phabricator.services.mozilla.com/D199391
This commit is contained in:
parent
983487232a
commit
82067f477f
3 changed files with 11 additions and 7 deletions
|
|
@ -42,13 +42,13 @@ if (largeArrayBufferSupported()) {
|
|||
}
|
||||
var MaxPagesIn32BitMemory = Math.floor(MaxBytesIn32BitMemory / PageSizeInBytes);
|
||||
|
||||
function wasmEvalText(str, imports) {
|
||||
function wasmEvalText(str, imports, compileOptions) {
|
||||
let binary = wasmTextToBinary(str);
|
||||
let valid = WebAssembly.validate(binary);
|
||||
let valid = WebAssembly.validate(binary, compileOptions);
|
||||
|
||||
let m;
|
||||
try {
|
||||
m = new WebAssembly.Module(binary);
|
||||
m = new WebAssembly.Module(binary, compileOptions);
|
||||
assertEq(valid, true, "failed WebAssembly.validate but still compiled successfully");
|
||||
} catch(e) {
|
||||
if (!e.toString().match(/out of memory/)) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// |jit-test| skip-if: !wasmJSStringBuiltinsEnabled();
|
||||
|
||||
let testModule = wasmTextToBinary(`(module
|
||||
let testModule = `(module
|
||||
(type $arrayMutI16 (array (mut i16)))
|
||||
|
||||
(func
|
||||
|
|
@ -93,7 +93,7 @@ let testModule = wasmTextToBinary(`(module
|
|||
(result i32)
|
||||
)
|
||||
(export "compare" (func 12))
|
||||
)`);
|
||||
)`;
|
||||
|
||||
let {
|
||||
createArrayMutI16,
|
||||
|
|
@ -256,8 +256,8 @@ function assertSameBehavior(funcA, funcB, ...params) {
|
|||
return resultA;
|
||||
}
|
||||
|
||||
let builtinExports = new WebAssembly.Instance(new WebAssembly.Module(testModule, {builtins: ["js-string"]}), {}).exports;
|
||||
let polyfillExports = new WebAssembly.Instance(new WebAssembly.Module(testModule), { 'wasm:js-string': polyFillImports }).exports;
|
||||
let builtinExports = wasmEvalText(testModule, {}, {builtins: ["js-string"]}).exports;
|
||||
let polyfillExports = wasmEvalText(testModule, { 'wasm:js-string': polyFillImports }).exports;
|
||||
|
||||
let testStrings = ["", "a", "1", "ab", "hello, world", "\n", "☺", "☺smiley", String.fromCodePoint(0x10000, 0x10001)];
|
||||
let testCharCodes = [1, 2, 3, 10, 0x7f, 0xff, 0xfffe, 0xffff];
|
||||
|
|
|
|||
|
|
@ -4652,6 +4652,10 @@ static bool WebAssembly_validate(JSContext* cx, unsigned argc, Value* vp) {
|
|||
}
|
||||
|
||||
FeatureOptions options;
|
||||
if (!options.init(cx, callArgs.get(1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UniqueChars error;
|
||||
bool validated = Validate(cx, *bytecode, options, &error);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue