зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1612534 - Switch to explicit (export (func)). r=lth
This commit uses a regex to automatically change exports of indices to specify that they are exporting functions. Differential Revision: https://phabricator.services.mozilla.com/D67250 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f2f90173a4
Коммит
188b68cb4c
|
@ -14,7 +14,7 @@ for (let [type,view] of [['i32','8_u'],['i32','16_u'],['i32',''],['i64','8_u'],[
|
|||
{
|
||||
let text = (shared) => `(module (memory 1 1 ${shared})
|
||||
(func (result ${type}) (${type}.atomic.load${view} (i32.const 0)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
assertEq(valText(text(SHARED)), true);
|
||||
assertEq(valText(text(UNSHARED)), false);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ for (let [type,view] of [['i32','8_u'],['i32','16_u'],['i32',''],['i64','8_u'],[
|
|||
{
|
||||
let text = (shared) => `(module (memory 1 1 ${shared})
|
||||
(func (${type}.atomic.store${view} (i32.const 0) (${type}.const 1)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
assertEq(valText(text(SHARED)), true);
|
||||
assertEq(valText(text(UNSHARED)), false);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ for (let [type,view] of [['i32','8_u'],['i32','16_u'],['i32',''],['i64','8_u'],[
|
|||
let text = (shared) => `(module (memory 1 1 ${shared})
|
||||
(func (result ${type})
|
||||
(${type}.atomic.rmw${view}.cmpxchg (i32.const 0) (${type}.const 1) (${type}.const 2)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
assertEq(valText(text(SHARED)), true);
|
||||
assertEq(valText(text(UNSHARED)), false);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ for (let [type,view] of [['i32','8_u'],['i32','16_u'],['i32',''],['i64','8_u'],[
|
|||
// Operate with appropriately-typed value 1 on address 0
|
||||
let text = (shared) => `(module (memory 1 1 ${shared})
|
||||
(func (result ${type}) (${type}.atomic.rmw${view}.${op} (i32.const 0) (${type}.const 1)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
|
||||
assertEq(valText(text(SHARED)), true);
|
||||
assertEq(valText(text(UNSHARED)), false);
|
||||
|
@ -50,7 +50,7 @@ for (let [type,view] of [['i32','8_u'],['i32','16_u'],['i32',''],['i64','8_u'],[
|
|||
for (let type of ['i32', 'i64']) {
|
||||
let text = (shared) => `(module (memory 1 1 ${shared})
|
||||
(func (result i32) (${type}.atomic.wait (i32.const 0) (${type}.const 1) (i64.const -1)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
assertEq(valText(text(SHARED)), true);
|
||||
assertEq(valText(text(UNSHARED)), false);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ for (let type of ['i32', 'i64']) {
|
|||
for ( let notify of ['wake', 'notify']) {
|
||||
let text = (shared) => `(module (memory 1 1 ${shared})
|
||||
(func (result i32) (atomic.${notify} (i32.const 0) (i32.const 1)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
assertEq(valText(text(SHARED)), true);
|
||||
assertEq(valText(text(UNSHARED)), false);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ for (let [type,align,good] of [['i32',1,false],['i32',2,false],['i32',4,true],['
|
|||
{
|
||||
let text = `(module (memory 1 1 shared)
|
||||
(func (result i32) (${type}.atomic.wait align=${align} (i32.const 0) (${type}.const 1) (i64.const -1)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
assertEq(valText(text), good);
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ for (let [type,align,good] of [['i32',1,false],['i32',2,false],['i32',4,true],['
|
|||
for (let align of [1, 2, 4, 8]) {
|
||||
let text = `(module (memory 1 1 shared)
|
||||
(func (result i32) (atomic.notify align=${align} (i32.const 0) (i32.const 1)))
|
||||
(export "" 0))`;
|
||||
(export "" (func 0)))`;
|
||||
assertEq(valText(text), align == 4);
|
||||
}
|
||||
|
||||
|
@ -472,31 +472,31 @@ BoundsAndAlignment.run();
|
|||
assertErrorMessage(() => wasmEvalText(`(module (memory 1 1 shared)
|
||||
(func (param i32) (result i32)
|
||||
(i32.atomic.wait (local.get 0) (i32.const 1) (i64.const -1)))
|
||||
(export "" 0))`).exports[""](65536),
|
||||
(export "" (func 0)))`).exports[""](65536),
|
||||
RuntimeError, oob);
|
||||
|
||||
assertErrorMessage(() => wasmEvalText(`(module (memory 1 1 shared)
|
||||
(func (param i32) (result i32)
|
||||
(i64.atomic.wait (local.get 0) (i64.const 1) (i64.const -1)))
|
||||
(export "" 0))`).exports[""](65536),
|
||||
(export "" (func 0)))`).exports[""](65536),
|
||||
RuntimeError, oob);
|
||||
|
||||
assertErrorMessage(() => wasmEvalText(`(module (memory 1 1 shared)
|
||||
(func (param i32) (result i32)
|
||||
(i32.atomic.wait (local.get 0) (i32.const 1) (i64.const -1)))
|
||||
(export "" 0))`).exports[""](65501),
|
||||
(export "" (func 0)))`).exports[""](65501),
|
||||
RuntimeError, unaligned);
|
||||
|
||||
assertErrorMessage(() => wasmEvalText(`(module (memory 1 1 shared)
|
||||
(func (param i32) (result i32)
|
||||
(i64.atomic.wait (local.get 0) (i64.const 1) (i64.const -1)))
|
||||
(export "" 0))`).exports[""](65501),
|
||||
(export "" (func 0)))`).exports[""](65501),
|
||||
RuntimeError, unaligned);
|
||||
|
||||
assertErrorMessage(() => wasmEvalText(`(module (memory 1 1 shared)
|
||||
(func (param i32) (result i32)
|
||||
(atomic.notify (local.get 0) (i32.const 1)))
|
||||
(export "" 0))`).exports[""](65536),
|
||||
(export "" (func 0)))`).exports[""](65536),
|
||||
RuntimeError, oob);
|
||||
|
||||
// Minimum run-time alignment for NOTIFY is 4
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var code = `(module
|
||||
(import $i "env" "test")
|
||||
(func $t (call $i))
|
||||
(export "test" $t)
|
||||
(export "test" (func $t))
|
||||
)`;
|
||||
var mod = wasmEvalText(code, {
|
||||
env: {
|
||||
|
|
|
@ -16,7 +16,7 @@ function gen(base, offset) {
|
|||
(data (i32.const 65528) "aaaaaaaa")
|
||||
(func (result i32)
|
||||
(i32.load offset=${offset} (i32.const ${base})))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
}
|
||||
|
||||
// Memory is two pages but minimum memory is one page, so accesses across
|
||||
|
@ -33,7 +33,7 @@ function gen2(base, offset) {
|
|||
(i32.store (i32.const 80000) (i32.const 0x61616161))
|
||||
(i32.store (i32.const 120000) (i32.const 0x61616161))
|
||||
(i32.load offset=${offset} (i32.const ${base})))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
}
|
||||
|
||||
// Access the first page.
|
||||
|
|
|
@ -21,7 +21,7 @@ function testEqzBrIf(value, type, untaken, taken, expected) {
|
|||
(br_if $b (${type}.eqz (local.get 0)))
|
||||
(local.set 1 (i32.const ${untaken})))
|
||||
(local.get 1))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
assertEq(f(), expected);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ function testCmpBrIf(value, type, untaken, taken, expected) {
|
|||
(br_if $b (${type}.eq (local.get 0) (${type}.const ${value})))
|
||||
(local.set 1 (i32.const ${untaken})))
|
||||
(local.get 1))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
assertEq(f(), expected);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ function testEqzSelect(value, type, iftrue, iffalse, expected) {
|
|||
(select (i32.const ${iftrue})
|
||||
(i32.const ${iffalse})
|
||||
(${type}.eqz (local.get 0))))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
assertEq(f(), expected);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ function testCmpSelect(value, type, iftrue, iffalse, expected) {
|
|||
(select (i32.const ${iftrue})
|
||||
(i32.const ${iffalse})
|
||||
(${type}.eq (local.get 0) (${type}.const ${value}))))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
assertEq(f(), expected);
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ function testEqzIf(value, type, trueBranch, falseBranch, expected) {
|
|||
(local.set 1 (i32.const ${trueBranch}))
|
||||
(local.set 1 (i32.const ${falseBranch})))
|
||||
(local.get 1))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
assertEq(f(), expected);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ function testCmpIf(value, type, trueBranch, falseBranch, expected) {
|
|||
(local.set 1 (i32.const ${trueBranch}))
|
||||
(local.set 1 (i32.const ${falseBranch})))
|
||||
(local.get 1))
|
||||
(export "f" 0))`).exports["f"];
|
||||
(export "f" (func 0)))`).exports["f"];
|
||||
assertEq(f(), expected);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ assertEq(Object.getOwnPropertyNames(o).length, 0);
|
|||
var o = wasmEvalText('(module (func))').exports;
|
||||
assertEq(Object.getOwnPropertyNames(o).length, 0);
|
||||
|
||||
var o = wasmEvalText('(module (func) (export "a" 0))').exports;
|
||||
var o = wasmEvalText('(module (func) (export "a" (func 0)))').exports;
|
||||
var names = Object.getOwnPropertyNames(o);
|
||||
assertEq(names.length, 1);
|
||||
assertEq(names[0], 'a');
|
||||
|
@ -23,35 +23,35 @@ assertEq(desc.enumerable, true);
|
|||
assertEq(desc.configurable, false);
|
||||
assertEq(desc.value(), undefined);
|
||||
|
||||
wasmValidateText('(module (func) (func) (export "a" 0))');
|
||||
wasmValidateText('(module (func) (func) (export "a" 1))');
|
||||
wasmValidateText('(module (func $a) (func $b) (export "a" $a) (export "b" $b))');
|
||||
wasmValidateText('(module (func $a) (func $b) (export "a" $a) (export "b" $b))');
|
||||
wasmValidateText('(module (func) (func) (export "a" (func 0)))');
|
||||
wasmValidateText('(module (func) (func) (export "a" (func 1)))');
|
||||
wasmValidateText('(module (func $a) (func $b) (export "a" (func $a)) (export "b" (func $b)))');
|
||||
wasmValidateText('(module (func $a) (func $b) (export "a" (func $a)) (export "b" (func $b)))');
|
||||
|
||||
wasmFailValidateText('(module (func) (export "a" 1))', /exported function index out of bounds/);
|
||||
wasmFailValidateText('(module (func) (func) (export "a" 2))', /exported function index out of bounds/);
|
||||
wasmFailValidateText('(module (func) (export "a" (func 1)))', /exported function index out of bounds/);
|
||||
wasmFailValidateText('(module (func) (func) (export "a" (func 2)))', /exported function index out of bounds/);
|
||||
|
||||
var o = wasmEvalText('(module (func) (export "a" 0) (export "b" 0))').exports;
|
||||
var o = wasmEvalText('(module (func) (export "a" (func 0)) (export "b" (func 0)))').exports;
|
||||
assertEq(Object.getOwnPropertyNames(o).sort().toString(), "a,b");
|
||||
assertEq(o.a.name, "0");
|
||||
assertEq(o.b.name, "0");
|
||||
assertEq(o.a === o.b, true);
|
||||
|
||||
var o = wasmEvalText('(module (func) (func) (export "a" 0) (export "b" 1))').exports;
|
||||
var o = wasmEvalText('(module (func) (func) (export "a" (func 0)) (export "b" (func 1)))').exports;
|
||||
assertEq(Object.getOwnPropertyNames(o).sort().toString(), "a,b");
|
||||
assertEq(o.a.name, "0");
|
||||
assertEq(o.b.name, "1");
|
||||
assertEq(o.a === o.b, false);
|
||||
|
||||
var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" 0) (export "b" 1))').exports;
|
||||
var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" (func 0)) (export "b" (func 1)))').exports;
|
||||
assertEq(o.a(), 1);
|
||||
assertEq(o.b(), 2);
|
||||
var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" 1) (export "b" 0))').exports;
|
||||
var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" (func 1)) (export "b" (func 0)))').exports;
|
||||
assertEq(o.a(), 2);
|
||||
assertEq(o.b(), 1);
|
||||
|
||||
wasmFailValidateText('(module (func) (export "a" 0) (export "a" 0))', /duplicate export/);
|
||||
wasmFailValidateText('(module (func) (func) (export "a" 0) (export "a" 1))', /duplicate export/);
|
||||
wasmFailValidateText('(module (func) (export "a" (func 0)) (export "a" (func 0)))', /duplicate export/);
|
||||
wasmFailValidateText('(module (func) (func) (export "a" (func 0)) (export "a" (func 1)))', /duplicate export/);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// signatures
|
||||
|
@ -136,7 +136,7 @@ var buf = wasmEvalText('(module (memory 1) (export "memory" memory))').exports.m
|
|||
assertEq(buf instanceof ArrayBuffer, true);
|
||||
assertEq(buf.byteLength, 65536);
|
||||
|
||||
var obj = wasmEvalText('(module (memory 1) (func (result i32) (i32.const 42)) (func (nop)) (export "memory" memory) (export "b" 0) (export "c" 1))').exports;
|
||||
var obj = wasmEvalText('(module (memory 1) (func (result i32) (i32.const 42)) (func (nop)) (export "memory" memory) (export "b" (func 0)) (export "c" (func 1)))').exports;
|
||||
assertEq(obj.memory.buffer instanceof ArrayBuffer, true);
|
||||
assertEq(obj.b instanceof Function, true);
|
||||
assertEq(obj.c instanceof Function, true);
|
||||
|
@ -165,10 +165,10 @@ assertEq(new Uint8Array(buf)[65535], 'c'.charCodeAt(0));
|
|||
// ----------------------------------------------------------------------------
|
||||
// locals
|
||||
|
||||
assertEq(wasmEvalText('(module (func (param i32) (result i32) (local.get 0)) (export "" 0))').exports[""](), 0);
|
||||
assertEq(wasmEvalText('(module (func (param i32) (result i32) (local.get 0)) (export "" 0))').exports[""](42), 42);
|
||||
assertEq(wasmEvalText('(module (func (param i32) (param i32) (result i32) (local.get 0)) (export "" 0))').exports[""](42, 43), 42);
|
||||
assertEq(wasmEvalText('(module (func (param i32) (param i32) (result i32) (local.get 1)) (export "" 0))').exports[""](42, 43), 43);
|
||||
assertEq(wasmEvalText('(module (func (param i32) (result i32) (local.get 0)) (export "" (func 0)))').exports[""](), 0);
|
||||
assertEq(wasmEvalText('(module (func (param i32) (result i32) (local.get 0)) (export "" (func 0)))').exports[""](42), 42);
|
||||
assertEq(wasmEvalText('(module (func (param i32) (param i32) (result i32) (local.get 0)) (export "" (func 0)))').exports[""](42, 43), 42);
|
||||
assertEq(wasmEvalText('(module (func (param i32) (param i32) (result i32) (local.get 1)) (export "" (func 0)))').exports[""](42, 43), 43);
|
||||
|
||||
wasmFailValidateText('(module (func (local.get 0)))', /local.get index out of range/);
|
||||
wasmFailValidateText('(module (func (result f32) (local i32) (local.get 0)))', mismatchError("i32", "f32"));
|
||||
|
@ -179,9 +179,9 @@ wasmFailValidateText('(module (func (result i32) (param i32) (local f32) (local.
|
|||
wasmValidateText('(module (func (local i32)))');
|
||||
wasmValidateText('(module (func (local i32) (local f32)))');
|
||||
|
||||
wasmFullPass('(module (func (result i32) (local i32) (local.get 0)) (export "run" 0))', 0);
|
||||
wasmFullPass('(module (func (result i32) (param i32) (local f32) (local.get 0)) (export "run" 0))', 0);
|
||||
wasmFullPass('(module (func (result f32) (param i32) (local f32) (local.get 1)) (export "run" 0))', 0);
|
||||
wasmFullPass('(module (func (result i32) (local i32) (local.get 0)) (export "run" (func 0)))', 0);
|
||||
wasmFullPass('(module (func (result i32) (param i32) (local f32) (local.get 0)) (export "run" (func 0)))', 0);
|
||||
wasmFullPass('(module (func (result f32) (param i32) (local f32) (local.get 1)) (export "run" (func 0)))', 0);
|
||||
|
||||
wasmFailValidateText('(module (func (local.set 0 (i32.const 0))))', /local.set index out of range/);
|
||||
wasmFailValidateText('(module (func (local f32) (local.set 0 (i32.const 0))))', mismatchError("i32", "f32"));
|
||||
|
@ -193,32 +193,32 @@ wasmValidateText('(module (func (local i32) (local.set 0 (i32.const 0))))');
|
|||
wasmValidateText('(module (func (local i32) (local f32) (local.set 0 (local.get 0))))');
|
||||
wasmValidateText('(module (func (local i32) (local f32) (local.set 1 (local.get 1))))');
|
||||
|
||||
wasmFullPass('(module (func (result i32) (local i32) (tee_local 0 (i32.const 42))) (export "run" 0))', 42);
|
||||
wasmFullPass('(module (func (result i32) (local i32) (tee_local 0 (local.get 0))) (export "run" 0))', 0);
|
||||
wasmFullPass('(module (func (result i32) (local i32) (tee_local 0 (i32.const 42))) (export "run" (func 0)))', 42);
|
||||
wasmFullPass('(module (func (result i32) (local i32) (tee_local 0 (local.get 0))) (export "run" (func 0)))', 0);
|
||||
|
||||
wasmFullPass('(module (func (param $a i32) (result i32) (local.get $a)) (export "run" 0))', 0);
|
||||
wasmFullPass('(module (func (param $a i32) (local $b i32) (result i32) (block (result i32) (local.set $b (local.get $a)) (local.get $b))) (export "run" 0))', 42, {}, 42);
|
||||
wasmFullPass('(module (func (param $a i32) (result i32) (local.get $a)) (export "run" (func 0)))', 0);
|
||||
wasmFullPass('(module (func (param $a i32) (local $b i32) (result i32) (block (result i32) (local.set $b (local.get $a)) (local.get $b))) (export "run" (func 0)))', 42, {}, 42);
|
||||
|
||||
wasmValidateText('(module (func (local i32) (local $a f32) (local.set 0 (i32.const 1)) (local.set $a (f32.const nan))))');
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// blocks
|
||||
|
||||
wasmFullPass('(module (func (block )) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block )) (export "run" (func 0)))', undefined);
|
||||
|
||||
wasmFailValidateText('(module (func (result i32) (block )))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (result i32) (block (block ))))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (local i32) (local.set 0 (block ))))', emptyStackError);
|
||||
|
||||
wasmFullPass('(module (func (block (block ))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (i32.const 42))) (export "run" 0))', 42);
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (block (result i32) (i32.const 42)))) (export "run" 0))', 42);
|
||||
wasmFullPass('(module (func (block (block ))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (i32.const 42))) (export "run" (func 0)))', 42);
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (block (result i32) (i32.const 42)))) (export "run" (func 0)))', 42);
|
||||
wasmFailValidateText('(module (func (result f32) (block (result i32) (i32.const 0))))', mismatchError("i32", "f32"));
|
||||
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (drop (i32.const 13)) (block (result i32) (i32.const 42)))) (export "run" 0))', 42);
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (drop (i32.const 13)) (block (result i32) (i32.const 42)))) (export "run" (func 0)))', 42);
|
||||
wasmFailValidateText('(module (func (result f32) (param f32) (block (result i32) (drop (local.get 0)) (i32.const 0))))', mismatchError("i32", "f32"));
|
||||
|
||||
wasmFullPass('(module (func (result i32) (local i32) (local.set 0 (i32.const 42)) (local.get 0)) (export "run" 0))', 42);
|
||||
wasmFullPass('(module (func (result i32) (local i32) (local.set 0 (i32.const 42)) (local.get 0)) (export "run" (func 0)))', 42);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// calls
|
||||
|
@ -232,9 +232,9 @@ wasmFailValidateText('(module (func (nop)) (func (call 3)))', /callee index out
|
|||
wasmValidateText('(module (func (nop)) (func (call 0)))');
|
||||
wasmValidateText('(module (func (param i32) (nop)) (func (call 0 (i32.const 0))))');
|
||||
|
||||
wasmFullPass('(module (func (result i32) (i32.const 42)) (func (result i32) (call 0)) (export "run" 1))', 42);
|
||||
assertThrowsInstanceOf(() => wasmEvalText('(module (func (call 0)) (export "" 0))').exports[""](), InternalError);
|
||||
assertThrowsInstanceOf(() => wasmEvalText('(module (func (call 1)) (func (call 0)) (export "" 0))').exports[""](), InternalError);
|
||||
wasmFullPass('(module (func (result i32) (i32.const 42)) (func (result i32) (call 0)) (export "run" (func 1)))', 42);
|
||||
assertThrowsInstanceOf(() => wasmEvalText('(module (func (call 0)) (export "" (func 0)))').exports[""](), InternalError);
|
||||
assertThrowsInstanceOf(() => wasmEvalText('(module (func (call 1)) (func (call 0)) (export "" (func 0)))').exports[""](), InternalError);
|
||||
|
||||
wasmValidateText('(module (func (param i32 f32)) (func (call 0 (i32.const 0) (f32.const nan))))');
|
||||
wasmFailValidateText('(module (func (param i32 f32)) (func (call 0 (i32.const 0) (i32.const 0))))', mismatchError("i32", "f32"));
|
||||
|
@ -248,10 +248,10 @@ wasmEvalText('(module (import "" "a") (func (call 0)))', {"":{a:()=>{}}});
|
|||
wasmEvalText('(module (import "" "a" (param i32)) (func (call 0 (i32.const 0))))', {"":{a:()=>{}}});
|
||||
|
||||
function checkF32CallImport(v) {
|
||||
wasmFullPass('(module (import "" "a" (result f32)) (func (result f32) (call 0)) (export "run" 1))',
|
||||
wasmFullPass('(module (import "" "a" (result f32)) (func (result f32) (call 0)) (export "run" (func 1)))',
|
||||
Math.fround(v),
|
||||
{"":{a:()=>{ return v; }}});
|
||||
wasmFullPass('(module (import "" "a" (param f32)) (func (param f32) (call 0 (local.get 0))) (export "run" 1))',
|
||||
wasmFullPass('(module (import "" "a" (param f32)) (func (param f32) (call 0 (local.get 0))) (export "run" (func 1)))',
|
||||
undefined,
|
||||
{"":{a:x=>{ assertEq(Math.fround(v), x); }}},
|
||||
v);
|
||||
|
@ -263,28 +263,28 @@ checkF32CallImport(-0);
|
|||
checkF32CallImport(Math.pow(2, 32) - 1);
|
||||
|
||||
var counter = 0;
|
||||
var f = wasmEvalText('(module (import "" "inc") (func (call 0)) (export "" 1))', {"":{inc:()=>counter++}}).exports[""];
|
||||
var g = wasmEvalText('(module (import "" "f") (func (block (call 0) (call 0))) (export "" 1))', {"":{f}}).exports[""];
|
||||
var f = wasmEvalText('(module (import "" "inc") (func (call 0)) (export "" (func 1)))', {"":{inc:()=>counter++}}).exports[""];
|
||||
var g = wasmEvalText('(module (import "" "f") (func (block (call 0) (call 0))) (export "" (func 1)))', {"":{f}}).exports[""];
|
||||
f();
|
||||
assertEq(counter, 1);
|
||||
g();
|
||||
assertEq(counter, 3);
|
||||
|
||||
var f = wasmEvalText('(module (import "" "callf") (func (call 0)) (export "" 1))', {"":{callf:()=>f()}}).exports[""];
|
||||
var f = wasmEvalText('(module (import "" "callf") (func (call 0)) (export "" (func 1)))', {"":{callf:()=>f()}}).exports[""];
|
||||
assertThrowsInstanceOf(() => f(), InternalError);
|
||||
|
||||
var f = wasmEvalText('(module (import "" "callg") (func (call 0)) (export "" 1))', {"":{callg:()=>g()}}).exports[""];
|
||||
var g = wasmEvalText('(module (import "" "callf") (func (call 0)) (export "" 1))', {"":{callf:()=>f()}}).exports[""];
|
||||
var f = wasmEvalText('(module (import "" "callg") (func (call 0)) (export "" (func 1)))', {"":{callg:()=>g()}}).exports[""];
|
||||
var g = wasmEvalText('(module (import "" "callf") (func (call 0)) (export "" (func 1)))', {"":{callf:()=>f()}}).exports[""];
|
||||
assertThrowsInstanceOf(() => f(), InternalError);
|
||||
|
||||
var code = '(module (import "" "one" (result i32)) (import "" "two" (result i32)) (func (result i32) (i32.const 3)) (func (result i32) (i32.const 4)) (func (result i32) BODY) (export "run" 4))';
|
||||
var code = '(module (import "" "one" (result i32)) (import "" "two" (result i32)) (func (result i32) (i32.const 3)) (func (result i32) (i32.const 4)) (func (result i32) BODY) (export "run" (func 4)))';
|
||||
var imports = {"":{one:()=>1, two:()=>2}};
|
||||
wasmFullPass(code.replace('BODY', '(call 0)'), 1, imports);
|
||||
wasmFullPass(code.replace('BODY', '(call 1)'), 2, imports);
|
||||
wasmFullPass(code.replace('BODY', '(call 2)'), 3, imports);
|
||||
wasmFullPass(code.replace('BODY', '(call 3)'), 4, imports);
|
||||
|
||||
wasmFullPass(`(module (import "" "evalcx" (param i32) (result i32)) (func (result i32) (call 0 (i32.const 0))) (export "run" 1))`, 0, {"":{evalcx}});
|
||||
wasmFullPass(`(module (import "" "evalcx" (param i32) (result i32)) (func (result i32) (call 0 (i32.const 0))) (export "run" (func 1)))`, 0, {"":{evalcx}});
|
||||
|
||||
if (typeof evaluate === 'function')
|
||||
evaluate(`new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module)'))) `, { fileName: null });
|
||||
|
@ -305,9 +305,9 @@ var {v2i, i2i, i2v} = wasmEvalText(`(module
|
|||
(func (param i32) (result i32) (call_indirect (type 0) (local.get 0)))
|
||||
(func (param i32) (param i32) (result i32) (call_indirect (type 1) (local.get 1) (local.get 0)))
|
||||
(func (param i32) (call_indirect (type 2) (i32.const 0) (local.get 0)))
|
||||
(export "v2i" 6)
|
||||
(export "i2i" 7)
|
||||
(export "i2v" 8)
|
||||
(export "v2i" (func 6))
|
||||
(export "i2i" (func 7))
|
||||
(export "i2v" (func 8))
|
||||
)`).exports;
|
||||
|
||||
const signatureMismatch = /indirect call signature mismatch/;
|
||||
|
@ -345,7 +345,7 @@ assertErrorMessage(() => i2v(5), Error, signatureMismatch);
|
|||
(func $b (result i32) (i32.const 0))
|
||||
(table funcref (elem $a $b))
|
||||
(func $bar (call_indirect (type $v2v) (i32.const 0)))
|
||||
(export "run" $bar)
|
||||
(export "run" (func $bar))
|
||||
)`,
|
||||
undefined,
|
||||
{"":{f:() => { stack = new Error().stack }}}
|
||||
|
@ -375,13 +375,13 @@ wasmValidateText('(module (import $bar "" "a") (func (call $bar)) (func $foo (no
|
|||
|
||||
wasmFailValidateText('(module (func (select (i32.const 0) (i32.const 0) (f32.const 0))))', mismatchError("f32", "i32"));
|
||||
|
||||
wasmFailValidateText('(module (func (select (i32.const 0) (f32.const 0) (i32.const 0))) (export "" 0))', /select operand types must match/);
|
||||
wasmFailValidateText('(module (func (select (block ) (i32.const 0) (i32.const 0))) (export "" 0))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (select (return) (i32.const 0) (i32.const 0))) (export "" 0))', unusedValuesError);
|
||||
assertEq(wasmEvalText('(module (func (drop (select (return) (i32.const 0) (i32.const 0)))) (export "" 0))').exports[""](), undefined);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (i32.add (i32.const 0) (select (return (i32.const 42)) (i32.const 0) (i32.const 0)))) (export "" 0))').exports[""](), 42);
|
||||
wasmFailValidateText('(module (func (select (if (result i32) (i32.const 1) (i32.const 0) (f32.const 0)) (i32.const 0) (i32.const 0))) (export "" 0))', mismatchError("f32", "i32"));
|
||||
wasmFailValidateText('(module (func) (func (select (call 0) (call 0) (i32.const 0))) (export "" 0))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (select (i32.const 0) (f32.const 0) (i32.const 0))) (export "" (func 0)))', /select operand types must match/);
|
||||
wasmFailValidateText('(module (func (select (block ) (i32.const 0) (i32.const 0))) (export "" (func 0)))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (select (return) (i32.const 0) (i32.const 0))) (export "" (func 0)))', unusedValuesError);
|
||||
assertEq(wasmEvalText('(module (func (drop (select (return) (i32.const 0) (i32.const 0)))) (export "" (func 0)))').exports[""](), undefined);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (i32.add (i32.const 0) (select (return (i32.const 42)) (i32.const 0) (i32.const 0)))) (export "" (func 0)))').exports[""](), 42);
|
||||
wasmFailValidateText('(module (func (select (if (result i32) (i32.const 1) (i32.const 0) (f32.const 0)) (i32.const 0) (i32.const 0))) (export "" (func 0)))', mismatchError("f32", "i32"));
|
||||
wasmFailValidateText('(module (func) (func (select (call 0) (call 0) (i32.const 0))) (export "" (func 0)))', emptyStackError);
|
||||
|
||||
(function testSideEffects() {
|
||||
|
||||
|
@ -405,7 +405,7 @@ var f = wasmEvalText(`
|
|||
(local.get 0)
|
||||
)
|
||||
)
|
||||
(export "" 2)
|
||||
(export "" (func 2))
|
||||
)
|
||||
`, imports).exports[""];
|
||||
|
||||
|
@ -450,7 +450,7 @@ function testSelect(type, trueVal, falseVal) {
|
|||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)
|
||||
`, imports).exports[""];
|
||||
|
||||
|
@ -468,7 +468,7 @@ function testSelect(type, trueVal, falseVal) {
|
|||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)
|
||||
`, imports).exports[""];
|
||||
|
||||
|
@ -486,7 +486,7 @@ function testSelect(type, trueVal, falseVal) {
|
|||
(local.get 0)
|
||||
)
|
||||
)
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)
|
||||
`, imports).exports[""];
|
||||
|
||||
|
@ -503,7 +503,7 @@ function testSelect(type, trueVal, falseVal) {
|
|||
(local.get 0)
|
||||
)
|
||||
)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`,
|
||||
trueJS,
|
||||
imports,
|
||||
|
@ -530,7 +530,7 @@ wasmAssert(`
|
|||
(local.get 0)
|
||||
)
|
||||
)
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`, [
|
||||
{ type: 'i64', func: '$f', args: ['i32.const 0'], expected: '0x12345678deadc0de' },
|
||||
{ type: 'i64', func: '$f', args: ['i32.const 1'], expected: '0xc0010ff08badf00d' },
|
||||
|
|
|
@ -74,7 +74,7 @@ function loadTwiceModule(type, ext, offset, align) {
|
|||
${align != 0 ? 'align=' + align : ''}
|
||||
(local.get 1)
|
||||
)
|
||||
) (export "" 0))`
|
||||
) (export "" (func 0)))`
|
||||
).exports[""];
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ function loadTwiceSameBasePlusConstModule(type, ext, offset, align, addConst) {
|
|||
${align != 0 ? 'align=' + align : ''}
|
||||
(i32.add (local.get 0) (i32.const ${addConst}))
|
||||
)
|
||||
) (export "" 0))`
|
||||
) (export "" (func 0)))`
|
||||
).exports[""];
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ function loadTwiceSameBasePlusNonConstModule(type, ext, offset, align) {
|
|||
${align != 0 ? 'align=' + align : ''}
|
||||
(i32.add (local.get 0) (local.get 1))
|
||||
)
|
||||
) (export "" 0))`
|
||||
) (export "" (func 0)))`
|
||||
).exports[""];
|
||||
}
|
||||
|
||||
|
|
|
@ -4,5 +4,5 @@ wasmFullPass(`(module
|
|||
(if (i32.eq (memory.grow (i32.const 16384)) (i32.const -1)) (return (i32.const 42)))
|
||||
(i32.store (i32.const 1073807356) (i32.const 42))
|
||||
(i32.load (i32.const 1073807356)))
|
||||
(export "run" $test)
|
||||
(export "run" (func $test))
|
||||
)`, 42);
|
||||
|
|
|
@ -112,7 +112,7 @@ function testImportExport() {
|
|||
var f1 = wasmEvalText(
|
||||
`(module
|
||||
(import "i64" "func" (param i64))
|
||||
(export "f" 0)
|
||||
(export "f" (func 0))
|
||||
)`,
|
||||
{
|
||||
i64: {
|
||||
|
@ -126,7 +126,7 @@ function testImportExport() {
|
|||
var f2 = wasmEvalText(
|
||||
`(module
|
||||
(import "i64" "func" (param i64) (result i64))
|
||||
(export "f" 0)
|
||||
(export "f" (func 0))
|
||||
)`,
|
||||
{
|
||||
i64: {
|
||||
|
@ -156,7 +156,7 @@ function testImportExport() {
|
|||
var f4 = wasmEvalText(
|
||||
`(module
|
||||
(import "i64" "func" (result i64))
|
||||
(export "f" 0)
|
||||
(export "f" (func 0))
|
||||
)`,
|
||||
{ i64: { func() {} } }
|
||||
).exports.f;
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
// Test i64 signature failures.
|
||||
|
||||
var f = wasmEvalText('(module (func (param i64) (result i32) (i32.const 123)) (export "" 0))').exports[""];
|
||||
var f = wasmEvalText('(module (func (param i64) (result i32) (i32.const 123)) (export "" (func 0)))').exports[""];
|
||||
assertErrorMessage(f, TypeError, /i64/);
|
||||
var f = wasmEvalText('(module (func (param i32) (result i64) (i64.const 123)) (export "" 0))').exports[""];
|
||||
var f = wasmEvalText('(module (func (param i32) (result i64) (i64.const 123)) (export "" (func 0)))').exports[""];
|
||||
assertErrorMessage(f, TypeError, /i64/);
|
||||
|
||||
var f = wasmEvalText('(module (import $imp "a" "b" (param i64) (result i32)) (func $f (result i32) (call $imp (i64.const 0))) (export "" $f))', {a:{b:()=>{}}}).exports[""];
|
||||
var f = wasmEvalText('(module (import $imp "a" "b" (param i64) (result i32)) (func $f (result i32) (call $imp (i64.const 0))) (export "" (func $f)))', {a:{b:()=>{}}}).exports[""];
|
||||
assertErrorMessage(f, TypeError, /i64/);
|
||||
var f = wasmEvalText('(module (import $imp "a" "b" (result i64)) (func $f (result i64) (call $imp)) (export "" $f))', {a:{b:()=>{}}}).exports[""];
|
||||
var f = wasmEvalText('(module (import $imp "a" "b" (result i64)) (func $f (result i64) (call $imp)) (export "" (func $f)))', {a:{b:()=>{}}}).exports[""];
|
||||
assertErrorMessage(f, TypeError, /i64/);
|
||||
|
||||
// Import and export related tests.
|
||||
|
@ -32,15 +32,15 @@ i = wasmEvalText('(module (func (export "f") (param i32) (result i64) (i64.const
|
|||
assertErrorMessage(() => i.f({ valueOf() { sideEffect = true; return 42; } }), TypeError, 'cannot pass i64 to or from JS');
|
||||
assertEq(sideEffect, false);
|
||||
|
||||
i = wasmEvalText('(module (import "i64" "func" (param i64)) (export "f" 0))', { i64: { func() {} } }).exports;
|
||||
i = wasmEvalText('(module (import "i64" "func" (param i64)) (export "f" (func 0)))', { i64: { func() {} } }).exports;
|
||||
assertErrorMessage(() => i.f({ valueOf() { sideEffect = true; return 42; } }), TypeError, 'cannot pass i64 to or from JS');
|
||||
assertEq(sideEffect, false);
|
||||
|
||||
i = wasmEvalText('(module (import "i64" "func" (param i32) (param i64)) (export "f" 0))', { i64: { func() {} } }).exports;
|
||||
i = wasmEvalText('(module (import "i64" "func" (param i32) (param i64)) (export "f" (func 0)))', { i64: { func() {} } }).exports;
|
||||
assertErrorMessage(() => i.f({ valueOf() { sideEffect = true; return 42; } }, 0), TypeError, 'cannot pass i64 to or from JS');
|
||||
assertEq(sideEffect, false);
|
||||
|
||||
i = wasmEvalText('(module (import "i64" "func" (result i64)) (export "f" 0))', { i64: { func() {} } }).exports;
|
||||
i = wasmEvalText('(module (import "i64" "func" (result i64)) (export "f" (func 0)))', { i64: { func() {} } }).exports;
|
||||
assertErrorMessage(() => i.f({ valueOf() { sideEffect = true; return 42; } }), TypeError, 'cannot pass i64 to or from JS');
|
||||
assertEq(sideEffect, false);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ var o = wasmEvalText('(module (func))\n;; end');
|
|||
var o = wasmEvalText('(module (func))\n;; end');
|
||||
var o = wasmEvalText(';;start\n(module (func))');
|
||||
var o = wasmEvalText('(module (func ;; middle\n))');
|
||||
var o = wasmEvalText('(module (func) ;; middle\n (export "a" 0))').exports;
|
||||
var o = wasmEvalText('(module (func) ;; middle\n (export "a" (func 0)))').exports;
|
||||
assertEq(Object.getOwnPropertyNames(o)[0], "a");
|
||||
|
||||
// multi-line comments
|
||||
|
@ -18,7 +18,7 @@ var o = wasmEvalText('(module (func))\n(;;)');
|
|||
var o = wasmEvalText('(;start;)(module (func))');
|
||||
var o = wasmEvalText('(;start;)\n(module (func))');
|
||||
var o = wasmEvalText('(module (func (; middle\n multi\n;)))');
|
||||
var o = wasmEvalText('(module (func)(;middle;)(export "a" 0))').exports;
|
||||
var o = wasmEvalText('(module (func)(;middle;)(export "a" (func 0)))').exports;
|
||||
assertEq(Object.getOwnPropertyNames(o)[0], "a");
|
||||
|
||||
// nested comments
|
||||
|
|
|
@ -12,7 +12,7 @@ var code = `(module
|
|||
(param f32)
|
||||
${expr}
|
||||
)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`;
|
||||
|
||||
try {
|
||||
|
|
|
@ -2,11 +2,11 @@ function testConst(type, str, expected) {
|
|||
if (type === 'i64')
|
||||
wasmFullPassI64(`(module (func $run (result i64) (i64.const ${str})))`, expected);
|
||||
else
|
||||
wasmFullPass(`(module (func (result ${type}) (${type}.const ${str})) (export "run" 0))`, expected);
|
||||
wasmFullPass(`(module (func (result ${type}) (${type}.const ${str})) (export "run" (func 0)))`, expected);
|
||||
}
|
||||
|
||||
function testConstError(type, str) {
|
||||
assertErrorMessage(() => wasmEvalText(`(module (func (result ${type}) (${type}.const ${str})) (export "" 0))`).exports[""](), Error, /parsing wasm text/);
|
||||
assertErrorMessage(() => wasmEvalText(`(module (func (result ${type}) (${type}.const ${str})) (export "" (func 0)))`).exports[""](), Error, /parsing wasm text/);
|
||||
}
|
||||
|
||||
testConst('i32', '0', 0);
|
||||
|
|
|
@ -7,22 +7,22 @@ const RuntimeError = WebAssembly.RuntimeError;
|
|||
wasmFailValidateText('(module (func (local f32) (if (local.get 0) (i32.const 1))))', mismatchError("f32", "i32"));
|
||||
wasmFailValidateText('(module (func (local f32) (if (local.get 0) (i32.const 1) (i32.const 0))))', mismatchError("f32", "i32"));
|
||||
wasmFailValidateText('(module (func (local f64) (if (local.get 0) (i32.const 1) (i32.const 0))))', mismatchError("f64", "i32"));
|
||||
wasmEvalText('(module (func (local i32) (if (local.get 0) (nop))) (export "" 0))');
|
||||
wasmEvalText('(module (func (local i32) (if (local.get 0) (nop) (nop))) (export "" 0))');
|
||||
wasmEvalText('(module (func (local i32) (if (local.get 0) (nop))) (export "" (func 0)))');
|
||||
wasmEvalText('(module (func (local i32) (if (local.get 0) (nop) (nop))) (export "" (func 0)))');
|
||||
|
||||
// Expression values types are consistent
|
||||
// Also test that we support (result t) for `if`
|
||||
wasmFailValidateText('(module (func (result i32) (local f32) (if (result f32) (i32.const 42) (local.get 0) (i32.const 0))))', mismatchError("i32", "f32"));
|
||||
wasmFailValidateText('(module (func (result i32) (local f64) (if (result i32) (i32.const 42) (i32.const 0) (local.get 0))))', mismatchError("f64", "i32"));
|
||||
wasmFailValidateText('(module (func (result i64) (if (result i64) (i32.const 0) (i32.const 1) (i32.const 2))))', mismatchError("i32", "i64"));
|
||||
assertEq(wasmEvalText('(module (func (result i32) (if (result i32) (i32.const 42) (i32.const 1) (i32.const 2))) (export "" 0))').exports[""](), 1);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (if (result i32) (i32.const 0) (i32.const 1) (i32.const 2))) (export "" 0))').exports[""](), 2);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (if (result i32) (i32.const 42) (i32.const 1) (i32.const 2))) (export "" (func 0)))').exports[""](), 1);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (if (result i32) (i32.const 0) (i32.const 1) (i32.const 2))) (export "" (func 0)))').exports[""](), 2);
|
||||
|
||||
// Even if we don't yield, sub expressions types still have to match.
|
||||
wasmFailValidateText('(module (func (param f32) (if (result i32) (i32.const 42) (i32.const 1) (local.get 0))) (export "" 0))', mismatchError('f32', 'i32'));
|
||||
wasmFailValidateText('(module (func (if (result i32) (i32.const 42) (i32.const 1) (i32.const 0))) (export "" 0))', /unused values not explicitly dropped by end of block/);
|
||||
wasmFullPass('(module (func (drop (if (result i32) (i32.const 42) (i32.const 1) (i32.const 0)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (param f32) (if (i32.const 42) (drop (i32.const 1)) (drop (local.get 0)))) (export "run" 0))', undefined, {}, 13.37);
|
||||
wasmFailValidateText('(module (func (param f32) (if (result i32) (i32.const 42) (i32.const 1) (local.get 0))) (export "" (func 0)))', mismatchError('f32', 'i32'));
|
||||
wasmFailValidateText('(module (func (if (result i32) (i32.const 42) (i32.const 1) (i32.const 0))) (export "" (func 0)))', /unused values not explicitly dropped by end of block/);
|
||||
wasmFullPass('(module (func (drop (if (result i32) (i32.const 42) (i32.const 1) (i32.const 0)))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (param f32) (if (i32.const 42) (drop (i32.const 1)) (drop (local.get 0)))) (export "run" (func 0)))', undefined, {}, 13.37);
|
||||
|
||||
// Sub-expression values are returned
|
||||
// Also test that we support (result t) for `block`
|
||||
|
@ -46,7 +46,7 @@ wasmFullPass(`(module
|
|||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`, 2);
|
||||
|
||||
// The if (resp. else) branch is taken iff the condition is true (resp. false)
|
||||
|
@ -62,7 +62,7 @@ wasmFullPass(`(module
|
|||
(call 0)
|
||||
)
|
||||
)
|
||||
(export "run" 1)
|
||||
(export "run" (func 1))
|
||||
)`, 1, imports);
|
||||
assertEq(counter, 0);
|
||||
|
||||
|
@ -76,7 +76,7 @@ wasmFullPass(`(module
|
|||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(export "run" 1)
|
||||
(export "run" (func 1))
|
||||
)`, 1, imports);
|
||||
assertEq(counter, 0);
|
||||
|
||||
|
@ -88,7 +88,7 @@ wasmFullPass(`(module
|
|||
(drop (call 0))
|
||||
)
|
||||
)
|
||||
(export "run" 1)
|
||||
(export "run" (func 1))
|
||||
)`, undefined, imports);
|
||||
assertEq(counter, 0);
|
||||
|
||||
|
@ -100,7 +100,7 @@ assertEq(wasmEvalText(`(module
|
|||
(drop (call 0))
|
||||
)
|
||||
)
|
||||
(export "" 1)
|
||||
(export "" (func 1))
|
||||
)`, imports).exports[""](), undefined);
|
||||
assertEq(counter, 1);
|
||||
|
||||
|
@ -113,7 +113,7 @@ wasmFullPass(`(module
|
|||
(br 0 (i32.const 1))
|
||||
)
|
||||
)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`, 1);
|
||||
assertEq(counter, 1);
|
||||
|
||||
|
@ -124,7 +124,7 @@ wasmFullPass(`(module
|
|||
(br 0)
|
||||
)
|
||||
)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`, undefined);
|
||||
assertEq(counter, 1);
|
||||
|
||||
|
@ -152,7 +152,7 @@ wasmFullPass(`(module
|
|||
(call 0)
|
||||
)
|
||||
)
|
||||
(export "run" 1)
|
||||
(export "run" (func 1))
|
||||
)`, 42, imports);
|
||||
assertEq(counter, 0);
|
||||
|
||||
|
@ -169,20 +169,20 @@ wasmEvalText('(module (func (if (i32.const 1) (drop (i32.const 0)) (if (i32.cons
|
|||
// ----------------------------------------------------------------------------
|
||||
// return
|
||||
|
||||
wasmFullPass('(module (func (return)) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (return (i32.const 1))) (export "run" 0))', 1);
|
||||
wasmFailValidateText('(module (func (if (return) (i32.const 0))) (export "run" 0))', unusedValuesError);
|
||||
wasmFailValidateText('(module (func (result i32) (return)) (export "" 0))', emptyStackError);
|
||||
wasmFullPass('(module (func (return (i32.const 1))) (export "run" 0))', undefined);
|
||||
wasmFailValidateText('(module (func (result f32) (return (i32.const 1))) (export "" 0))', mismatchError("i32", "f32"));
|
||||
wasmFailValidateText('(module (func (result i32) (return)) (export "" 0))', emptyStackError);
|
||||
wasmFullPass('(module (func (return)) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (return (i32.const 1))) (export "run" (func 0)))', 1);
|
||||
wasmFailValidateText('(module (func (if (return) (i32.const 0))) (export "run" (func 0)))', unusedValuesError);
|
||||
wasmFailValidateText('(module (func (result i32) (return)) (export "" (func 0)))', emptyStackError);
|
||||
wasmFullPass('(module (func (return (i32.const 1))) (export "run" (func 0)))', undefined);
|
||||
wasmFailValidateText('(module (func (result f32) (return (i32.const 1))) (export "" (func 0)))', mismatchError("i32", "f32"));
|
||||
wasmFailValidateText('(module (func (result i32) (return)) (export "" (func 0)))', emptyStackError);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// br / br_if
|
||||
|
||||
wasmFailValidateText('(module (func (result i32) (block (br 0))) (export "" 0))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (result i32) (br 0)) (export "" 0))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (result i32) (block (br_if 0 (i32.const 0)))) (export "" 0))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (result i32) (block (br 0))) (export "" (func 0)))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (result i32) (br 0)) (export "" (func 0)))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (result i32) (block (br_if 0 (i32.const 0)))) (export "" (func 0)))', emptyStackError);
|
||||
|
||||
const DEPTH_OUT_OF_BOUNDS = /branch depth exceeds current nesting level/;
|
||||
|
||||
|
@ -205,19 +205,19 @@ wasmFailValidateText(`(module (func (result i32)
|
|||
i32.const 2
|
||||
end
|
||||
end
|
||||
) (export "" 0))`, unusedValuesError);
|
||||
) (export "" (func 0)))`, unusedValuesError);
|
||||
|
||||
wasmFullPass(`(module (func (block $out (br_if $out (br 0)))) (export "run" 0))`, undefined);
|
||||
wasmFullPass(`(module (func (block $out (br_if $out (br 0)))) (export "run" (func 0)))`, undefined);
|
||||
|
||||
wasmFullPass('(module (func (br 0)) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block (br 0))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block $l (br $l))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (br 0)) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block (br 0))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block $l (br $l))) (export "run" (func 0)))', undefined);
|
||||
|
||||
wasmFullPass('(module (func (block (block (br 1)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block $l (block (br $l)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block (block (br 1)))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block $l (block (br $l)))) (export "run" (func 0)))', undefined);
|
||||
|
||||
wasmFullPass('(module (func (block $l (block $m (br $l)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block $l (block $m (br $m)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block $l (block $m (br $l)))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block $l (block $m (br $m)))) (export "run" (func 0)))', undefined);
|
||||
|
||||
wasmFullPass(`(module (func (result i32)
|
||||
(block
|
||||
|
@ -225,7 +225,7 @@ wasmFullPass(`(module (func (result i32)
|
|||
(return (i32.const 0))
|
||||
)
|
||||
(return (i32.const 1))
|
||||
) (export "run" 0))`, 1);
|
||||
) (export "run" (func 0)))`, 1);
|
||||
|
||||
wasmFullPass(`(module (func (result i32)
|
||||
(block
|
||||
|
@ -236,7 +236,7 @@ wasmFullPass(`(module (func (result i32)
|
|||
(return (i32.const 1))
|
||||
)
|
||||
(return (i32.const 2))
|
||||
) (export "run" 0))`, 1);
|
||||
) (export "run" (func 0)))`, 1);
|
||||
|
||||
wasmFullPass(`(module (func (result i32)
|
||||
(block $outer
|
||||
|
@ -247,7 +247,7 @@ wasmFullPass(`(module (func (result i32)
|
|||
(return (i32.const 1))
|
||||
)
|
||||
(return (i32.const 2))
|
||||
) (export "run" 0))`, 1);
|
||||
) (export "run" (func 0)))`, 1);
|
||||
|
||||
var notcalled = false;
|
||||
var called = false;
|
||||
|
@ -264,7 +264,7 @@ wasmFullPass(`(module
|
|||
(call 0)
|
||||
)
|
||||
(call 1)
|
||||
) (export "run" 2))`, undefined, imports);
|
||||
) (export "run" (func 2)))`, undefined, imports);
|
||||
assertEq(notcalled, false);
|
||||
assertEq(called, true);
|
||||
|
||||
|
@ -277,7 +277,7 @@ wasmFullPass(`(module (func
|
|||
drop
|
||||
)
|
||||
(return)
|
||||
) (export "run" 0))`, undefined);
|
||||
) (export "run" (func 0)))`, undefined);
|
||||
|
||||
wasmFullPass(`(module (func (result i32)
|
||||
(block
|
||||
|
@ -288,13 +288,13 @@ wasmFullPass(`(module (func (result i32)
|
|||
)
|
||||
)
|
||||
(return (i32.const 1))
|
||||
) (export "run" 0))`, 1);
|
||||
) (export "run" (func 0)))`, 1);
|
||||
|
||||
wasmFullPass('(module (func (br_if 0 (i32.const 1))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (br_if 0 (i32.const 0))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block (br_if 0 (i32.const 1)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block (br_if 0 (i32.const 0)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block $l (br_if $l (i32.const 1)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (br_if 0 (i32.const 1))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (br_if 0 (i32.const 0))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block (br_if 0 (i32.const 1)))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block (br_if 0 (i32.const 0)))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block $l (br_if $l (i32.const 1)))) (export "run" (func 0)))', undefined);
|
||||
|
||||
var isNonZero = wasmEvalText(`(module (func (result i32) (param i32)
|
||||
(block
|
||||
|
@ -302,7 +302,7 @@ var isNonZero = wasmEvalText(`(module (func (result i32) (param i32)
|
|||
(return (i32.const 0))
|
||||
)
|
||||
(return (i32.const 1))
|
||||
) (export "" 0))`).exports[""];
|
||||
) (export "" (func 0)))`).exports[""];
|
||||
|
||||
assertEq(isNonZero(0), 0);
|
||||
assertEq(isNonZero(1), 1);
|
||||
|
@ -315,74 +315,74 @@ wasmFailValidateText('(module (func (result i32) (br 0 (f32.const 42))))', misma
|
|||
wasmFailValidateText('(module (func (result i32) (block (br 0))))', emptyStackError);
|
||||
wasmFailValidateText('(module (func (result i32) (block (result f32) (br 0 (f32.const 42)))))', mismatchError("f32", "i32"));
|
||||
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (if (result i32) (local.get 0) (br 0 (i32.const 42))))) (export "" 0))`, /if without else with a result value/);
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (br 0 (f32.const 42)))) (export "" 0))`, mismatchError("f32", "i32"));
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (if (result i32) (local.get 0) (br 0 (i32.const 42))))) (export "" (func 0)))`, /if without else with a result value/);
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (br 0 (f32.const 42)))) (export "" (func 0)))`, mismatchError("f32", "i32"));
|
||||
|
||||
wasmFullPass('(module (func (result i32) (br 0 (i32.const 42)) (i32.const 13)) (export "run" 0))', 42);
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (br 0 (i32.const 42)) (i32.const 13))) (export "run" 0))', 42);
|
||||
wasmFullPass('(module (func (result i32) (br 0 (i32.const 42)) (i32.const 13)) (export "run" (func 0)))', 42);
|
||||
wasmFullPass('(module (func (result i32) (block (result i32) (br 0 (i32.const 42)) (i32.const 13))) (export "run" (func 0)))', 42);
|
||||
|
||||
wasmFailValidateText('(module (func) (func (block (result i32) (br 0 (call 0)) (i32.const 13))) (export "" 0))', emptyStackError);
|
||||
wasmFailValidateText('(module (func) (func (block (result i32) (br_if 0 (call 0) (i32.const 1)) (i32.const 13))) (export "" 0))', emptyStackError);
|
||||
wasmFailValidateText('(module (func) (func (block (result i32) (br 0 (call 0)) (i32.const 13))) (export "" (func 0)))', emptyStackError);
|
||||
wasmFailValidateText('(module (func) (func (block (result i32) (br_if 0 (call 0) (i32.const 1)) (i32.const 13))) (export "" (func 0)))', emptyStackError);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (i32.const 43))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (i32.const 43))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 43);
|
||||
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (result i32) (if (result i32) (local.get 0) (br 0 (i32.const 42))) (i32.const 43))) (export "" 0))`, /if without else with a result value/);
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (result i32) (if (result i32) (local.get 0) (br 0 (i32.const 42))) (i32.const 43))) (export "" (func 0)))`, /if without else with a result value/);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (br 1 (i32.const 42))) (i32.const 43))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (br 1 (i32.const 42))) (i32.const 43))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 42);
|
||||
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (br_if 0 (i32.const 42) (local.get 0)) (i32.const 43))) (export "" 0))`, /unused values not explicitly dropped by end of block/);
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (br_if 0 (i32.const 42) (local.get 0)) (i32.const 43))) (export "" (func 0)))`, /unused values not explicitly dropped by end of block/);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (drop (br_if 0 (i32.const 42) (local.get 0))) (i32.const 43))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (drop (br_if 0 (i32.const 42) (local.get 0))) (i32.const 43))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 42);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (br 0 (i32.const 43)))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (br 0 (i32.const 43)))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 43);
|
||||
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (result i32) (if (result i32) (local.get 0) (br 0 (i32.const 42))) (br 0 (i32.const 43)))) (export "" 0))`, /if without else with a result value/);
|
||||
wasmFailValidateText(`(module (func (result i32) (param i32) (block (result i32) (if (result i32) (local.get 0) (br 0 (i32.const 42))) (br 0 (i32.const 43)))) (export "" (func 0)))`, /if without else with a result value/);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (if (local.get 0) (br 1 (i32.const 42))) (br 0 (i32.const 43))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (if (local.get 0) (br 1 (i32.const 42))) (br 0 (i32.const 43))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 42);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (br 1 (i32.const 42))) (br 0 (i32.const 43)))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (if (local.get 0) (br 1 (i32.const 42))) (br 0 (i32.const 43)))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 42);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (br_if 0 (i32.const 42) (local.get 0)) (br 0 (i32.const 43))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (br_if 0 (i32.const 42) (local.get 0)) (br 0 (i32.const 43))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 42);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (br_if 0 (i32.const 42) (local.get 0)) (br 0 (i32.const 43)))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32) (block (result i32) (br_if 0 (i32.const 42) (local.get 0)) (br 0 (i32.const 43)))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 43);
|
||||
assertEq(f(1), 42);
|
||||
|
||||
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (if (local.get 0) (drop (i32.const 99))) (i32.const -1)))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (if (local.get 0) (drop (i32.const 99))) (i32.const -1)))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 0);
|
||||
assertEq(f(1), 0);
|
||||
|
||||
wasmFailValidateText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (if (result i32) (local.get 0) (br 0 (i32.const 99))) (i32.const -1)))) (export "" 0))`, /if without else with a result value/);
|
||||
wasmFailValidateText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (if (result i32) (local.get 0) (br 0 (i32.const 99))) (i32.const -1)))) (export "" (func 0)))`, /if without else with a result value/);
|
||||
|
||||
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (if (local.get 0) (br 1 (i32.const 99))) (i32.const -1)))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (if (local.get 0) (br 1 (i32.const 99))) (i32.const -1)))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 0);
|
||||
assertEq(f(1), 100);
|
||||
|
||||
wasmFailValidateText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (br_if 0 (i32.const 99) (local.get 0)) (i32.const -1)))) (export "" 0))`, /unused values not explicitly dropped by end of block/);
|
||||
wasmFailValidateText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (br_if 0 (i32.const 99) (local.get 0)) (i32.const -1)))) (export "" (func 0)))`, /unused values not explicitly dropped by end of block/);
|
||||
|
||||
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (drop (br_if 0 (i32.const 99) (local.get 0))) (i32.const -1)))) (export "" 0))`).exports[""];
|
||||
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block (result i32) (drop (br_if 0 (i32.const 99) (local.get 0))) (i32.const -1)))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(f(0), 0);
|
||||
assertEq(f(1), 100);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (block (result i32) (br 0 (return (i32.const 42))) (i32.const 0))) (export "run" 0))`, 42);
|
||||
wasmFullPass(`(module (func (result i32) (block (result i32) (return (br 0 (i32.const 42))))) (export "run" 0))`, 42);
|
||||
wasmFullPass(`(module (func (result i32) (block (result i32) (return (br 0 (i32.const 42))) (i32.const 0))) (export "run" 0))`, 42);
|
||||
wasmFullPass(`(module (func (result i32) (block (result i32) (br 0 (return (i32.const 42))) (i32.const 0))) (export "run" (func 0)))`, 42);
|
||||
wasmFullPass(`(module (func (result i32) (block (result i32) (return (br 0 (i32.const 42))))) (export "run" (func 0)))`, 42);
|
||||
wasmFullPass(`(module (func (result i32) (block (result i32) (return (br 0 (i32.const 42))) (i32.const 0))) (export "run" (func 0)))`, 42);
|
||||
|
||||
wasmFullPass(`(module (func (result f32) (drop (block (result i32) (br 0 (i32.const 0)))) (block (result f32) (br 0 (f32.const 42)))) (export "run" 0))`, 42);
|
||||
wasmFullPass(`(module (func (result f32) (drop (block (result i32) (br 0 (i32.const 0)))) (block (result f32) (br 0 (f32.const 42)))) (export "run" (func 0)))`, 42);
|
||||
|
||||
var called = 0;
|
||||
var imports = {
|
||||
|
@ -408,16 +408,16 @@ var f = wasmEvalText(`(module
|
|||
)
|
||||
(i32.const 42)
|
||||
)
|
||||
(export "" 2))`, imports).exports[""];
|
||||
(export "" (func 2)))`, imports).exports[""];
|
||||
assertEq(f(0), 42);
|
||||
assertEq(called, -1);
|
||||
assertEq(f(1), 42);
|
||||
assertEq(called, 0);
|
||||
|
||||
// br/br_if and loop
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (loop $out $in i32 (br $out (local.get 0)))) (export "run" 0))`, 1, {}, 1);
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (loop $in i32 (br 1 (local.get 0)))) (export "run" 0))`, 1, {}, 1);
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (block $out i32 (loop $in i32 (br $out (local.get 0))))) (export "run" 0))`, 1, {}, 1);
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (loop $out $in i32 (br $out (local.get 0)))) (export "run" (func 0)))`, 1, {}, 1);
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (loop $in i32 (br 1 (local.get 0)))) (export "run" (func 0)))`, 1, {}, 1);
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (block $out i32 (loop $in i32 (br $out (local.get 0))))) (export "run" (func 0)))`, 1, {}, 1);
|
||||
|
||||
wasmFailValidateText(`(module (func (param i32) (result i32)
|
||||
(loop $out $in
|
||||
|
@ -427,7 +427,7 @@ wasmFailValidateText(`(module (func (param i32) (result i32)
|
|||
(if (local.get 0) (br $in))
|
||||
(i32.const 7)
|
||||
)
|
||||
) (export "" 0))`, /unused values not explicitly dropped by end of block/);
|
||||
) (export "" (func 0)))`, /unused values not explicitly dropped by end of block/);
|
||||
|
||||
wasmFullPass(`(module
|
||||
(func
|
||||
|
@ -444,7 +444,7 @@ wasmFullPass(`(module
|
|||
)
|
||||
)
|
||||
)
|
||||
(export "run" 0))`, 7);
|
||||
(export "run" (func 0)))`, 7);
|
||||
|
||||
wasmFullPass(`(module
|
||||
(func
|
||||
|
@ -458,23 +458,23 @@ wasmFullPass(`(module
|
|||
)
|
||||
)
|
||||
)
|
||||
(export "run" 0))`, 7);
|
||||
(export "run" (func 0)))`, 7);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// loop
|
||||
|
||||
wasmFailValidateText('(module (func (loop (br 2))))', DEPTH_OUT_OF_BOUNDS);
|
||||
|
||||
wasmFailValidateText('(module (func (result i32) (drop (loop (i32.const 2))) (i32.const 1)) (export "" 0))', /unused values not explicitly dropped by end of block/);
|
||||
wasmFullPass('(module (func (loop)) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (loop (drop (i32.const 2))) (i32.const 1)) (export "run" 0))', 1);
|
||||
wasmFailValidateText('(module (func (result i32) (drop (loop (i32.const 2))) (i32.const 1)) (export "" (func 0)))', /unused values not explicitly dropped by end of block/);
|
||||
wasmFullPass('(module (func (loop)) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (loop (drop (i32.const 2))) (i32.const 1)) (export "run" (func 0)))', 1);
|
||||
|
||||
wasmFullPass('(module (func (loop (br 1))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (loop $a (br 1))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (loop $a (br_if $a (i32.const 0)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (loop $a $b (br $a))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (block $a (loop $b (br $a)))) (export "run" 0))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (loop i32 (i32.const 1))) (export "run" 0))', 1);
|
||||
wasmFullPass('(module (func (loop (br 1))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (loop $a (br 1))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (loop $a (br_if $a (i32.const 0)))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (loop $a $b (br $a))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (block $a (loop $b (br $a)))) (export "run" (func 0)))', undefined);
|
||||
wasmFullPass('(module (func (result i32) (loop i32 (i32.const 1))) (export "run" (func 0)))', 1);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(loop
|
||||
|
@ -487,7 +487,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
(br $continue)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(block
|
||||
|
@ -503,7 +503,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(loop
|
||||
|
@ -516,7 +516,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
(br $continue)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(block
|
||||
|
@ -532,7 +532,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(loop
|
||||
|
@ -544,7 +544,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(block
|
||||
|
@ -559,7 +559,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(loop
|
||||
|
@ -575,7 +575,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
(return (i32.const 42))
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(block
|
||||
|
@ -594,7 +594,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(loop
|
||||
|
@ -609,7 +609,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
(br $break)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (local i32)
|
||||
(block
|
||||
|
@ -627,7 +627,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
|
|||
)
|
||||
)
|
||||
(return (local.get 0))
|
||||
) (export "run" 0))`, 6);
|
||||
) (export "run" (func 0)))`, 6);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// br_table
|
||||
|
@ -648,7 +648,7 @@ wasmFullPass(`(module (func (result i32) (param i32)
|
|||
(return (i32.const 0))
|
||||
)
|
||||
(return (i32.const 1))
|
||||
) (export "run" 0))`, 1);
|
||||
) (export "run" (func 0)))`, 1);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (param i32)
|
||||
(block $default
|
||||
|
@ -656,7 +656,7 @@ wasmFullPass(`(module (func (result i32) (param i32)
|
|||
(return (i32.const 0))
|
||||
)
|
||||
(return (i32.const 2))
|
||||
) (export "run" 0))`, 1);
|
||||
) (export "run" (func 0)))`, 1);
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (param i32)
|
||||
(block $outer
|
||||
|
@ -667,7 +667,7 @@ wasmFullPass(`(module (func (result i32) (param i32)
|
|||
(return (i32.const 1))
|
||||
)
|
||||
(return (i32.const 2))
|
||||
) (export "run" 0))`, 1);
|
||||
) (export "run" (func 0)))`, 1);
|
||||
|
||||
var f = wasmEvalText(`(module (func (result i32) (param i32)
|
||||
(block $0
|
||||
|
@ -682,7 +682,7 @@ var f = wasmEvalText(`(module (func (result i32) (param i32)
|
|||
)
|
||||
)
|
||||
(return (i32.const 0))
|
||||
) (export "" 0))`).exports[""];
|
||||
) (export "" (func 0)))`).exports[""];
|
||||
|
||||
assertEq(f(-2), -1);
|
||||
assertEq(f(-1), -1);
|
||||
|
@ -705,9 +705,9 @@ wasmFailValidateText(`(module
|
|||
(br $outer (i32.const 42))
|
||||
)
|
||||
)
|
||||
(export "" 0))`, mismatchError("i32", "f32"));
|
||||
(export "" (func 0)))`, mismatchError("i32", "f32"));
|
||||
|
||||
wasmFullPass(`(module (func (result i32) (block $default i32 (br_table $default (i32.const 42) (i32.const 1)))) (export "run" 0))`, 42);
|
||||
wasmFullPass(`(module (func (result i32) (block $default i32 (br_table $default (i32.const 42) (i32.const 1)))) (export "run" (func 0)))`, 42);
|
||||
|
||||
var f = wasmEvalText(`(module (func (param i32) (result i32)
|
||||
(i32.add
|
||||
|
@ -722,7 +722,7 @@ var f = wasmEvalText(`(module (func (param i32) (result i32)
|
|||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
) (export "" 0))`).exports[""];
|
||||
) (export "" (func 0)))`).exports[""];
|
||||
|
||||
assertEq(f(0), 5);
|
||||
assertEq(f(1), 2);
|
||||
|
@ -734,8 +734,8 @@ assertEq(f(4), 13);
|
|||
// unreachable
|
||||
|
||||
const UNREACHABLE = /unreachable/;
|
||||
assertErrorMessage(wasmEvalText(`(module (func (unreachable)) (export "" 0))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (if (unreachable) (nop))) (export "" 0))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (block (br_if 0 (unreachable)))) (export "" 0))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (block (br_table 0 (unreachable)))) (export "" 0))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (result i32) (i32.add (i32.const 0) (unreachable))) (export "" 0))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (unreachable)) (export "" (func 0)))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (if (unreachable) (nop))) (export "" (func 0)))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (block (br_if 0 (unreachable)))) (export "" (func 0)))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (block (br_table 0 (unreachable)))) (export "" (func 0)))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (result i32) (i32.add (i32.const 0) (unreachable))) (export "" (func 0)))`).exports[""], RuntimeError, UNREACHABLE);
|
||||
|
|
|
@ -26,7 +26,7 @@ function testConversion0(resultType, opcode, paramType, op, expect) {
|
|||
wasmFullPass(`(module
|
||||
(func (param ${paramType}) (result ${resultType})
|
||||
(${opcode} (local.get 0)))
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`, expect, {}, op);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ function testTrap(resultType, opcode, paramType, op) {
|
|||
call 0
|
||||
drop
|
||||
)
|
||||
(export "" 1)
|
||||
(export "" (func 1))
|
||||
)`).exports[""];
|
||||
|
||||
let expectedError = op === 'nan' ? /invalid conversion to integer/ : /integer overflow/;
|
||||
|
@ -366,5 +366,5 @@ testConversion('f32', 'demote', 'f64', 40.1, 40.099998474121094);
|
|||
testConversion('f64', 'promote', 'f32', 40.1, 40.099998474121094);
|
||||
|
||||
// Non-canonical NaNs.
|
||||
wasmFullPass('(module (func (result i32) (i32.reinterpret/f32 (f32.demote/f64 (f64.const -nan:0x4444444444444)))) (export "run" 0))', -0x1dddde);
|
||||
wasmFullPass('(module (func (result i32) (local i64) (local.set 0 (i64.reinterpret/f64 (f64.promote/f32 (f32.const -nan:0x222222)))) (i32.xor (i32.wrap/i64 (local.get 0)) (i32.wrap/i64 (i64.shr_u (local.get 0) (i64.const 32))))) (export "run" 0))', -0x4003bbbc);
|
||||
wasmFullPass('(module (func (result i32) (i32.reinterpret/f32 (f32.demote/f64 (f64.const -nan:0x4444444444444)))) (export "run" (func 0)))', -0x1dddde);
|
||||
wasmFullPass('(module (func (result i32) (local i64) (local.set 0 (i64.reinterpret/f64 (f64.promote/f32 (f32.const -nan:0x222222)))) (i32.xor (i32.wrap/i64 (local.get 0)) (i32.wrap/i64 (i64.shr_u (local.get 0) (i64.const 32))))) (export "run" (func 0)))', -0x4003bbbc);
|
||||
|
|
|
@ -6,7 +6,7 @@ wasmFullPass(`
|
|||
(func $f1)
|
||||
(elem declared $f1)
|
||||
(func $run)
|
||||
(export "run" $run)
|
||||
(export "run" (func $run))
|
||||
)
|
||||
`);
|
||||
|
||||
|
@ -47,6 +47,6 @@ wasmAssert(`
|
|||
table.get 0
|
||||
ref.is_null
|
||||
)
|
||||
(export "at" $at)
|
||||
(export "at" (func $at))
|
||||
)
|
||||
`, [{type: 'i32', func: '$at', args: ['i32.const 0'], expected: '1'}]);
|
||||
|
|
|
@ -7,7 +7,7 @@ for (let type of ['i32', 'f32', 'f64']) {
|
|||
(block)
|
||||
drop
|
||||
)
|
||||
(export "test" $test)
|
||||
(export "test" (func $test))
|
||||
)
|
||||
`).exports.test(0x1337abc0, 0xffffffff), 0x1337abc0);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ assertEq(wasmEvalText(`
|
|||
drop
|
||||
drop
|
||||
)
|
||||
(export "test" $test)
|
||||
(export "test" (func $test))
|
||||
)
|
||||
`).exports.test(0x1337abc0, 0xffffffff), 0x1337abc0);
|
||||
|
||||
|
@ -38,7 +38,7 @@ wasmAssert(`
|
|||
(block)
|
||||
drop
|
||||
)
|
||||
(export "test" $test)
|
||||
(export "test" (func $test))
|
||||
)
|
||||
`, [
|
||||
{ type: 'i64', func: '$test', args: ['(i64.const 0x1337abc0)', '(i64.const -1)'], expected: '0x1337abc0' }
|
||||
|
|
|
@ -15,5 +15,5 @@ assertEq(wasmEvalText(`(module
|
|||
(local.get 1)
|
||||
)
|
||||
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`).exports[""](10), 3628800);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
wasmFullPass(
|
||||
`(module
|
||||
(func atomic.fence)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`);
|
||||
|
||||
// Test that `atomic.fence` works with non-shared memory
|
||||
|
@ -12,7 +12,7 @@ wasmFullPass(
|
|||
`(module
|
||||
(memory 1)
|
||||
(func atomic.fence)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`);
|
||||
|
||||
// Test that `atomic.fence` works with shared memory
|
||||
|
@ -20,5 +20,5 @@ wasmFullPass(
|
|||
`(module
|
||||
(memory 1 1 shared)
|
||||
(func atomic.fence)
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`);
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
wasmFullPass('(module (func (result f32) (f32.const -1)) (export "run" 0))', -1);
|
||||
wasmFullPass('(module (func (result f32) (f32.const 1)) (export "run" 0))', 1);
|
||||
wasmFullPass('(module (func (result f64) (f64.const -2)) (export "run" 0))', -2);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 2)) (export "run" 0))', 2);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 4294967296)) (export "run" 0))', 4294967296);
|
||||
wasmFullPass('(module (func (result f32) (f32.const 1.5)) (export "run" 0))', 1.5);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 2.5)) (export "run" 0))', 2.5);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 10e2)) (export "run" 0))', 10e2);
|
||||
wasmFullPass('(module (func (result f32) (f32.const 10e2)) (export "run" 0))', 10e2);
|
||||
wasmFullPass('(module (func (result f64) (f64.const -0x8000000000000000)) (export "run" 0))', -0x8000000000000000);
|
||||
wasmFullPass('(module (func (result f64) (f64.const -9223372036854775808)) (export "run" 0))', -9223372036854775808);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 1797693134862315708145274e284)) (export "run" 0))', 1797693134862315708145274e284);
|
||||
wasmFullPass('(module (func (result f32) (f32.const -1)) (export "run" (func 0)))', -1);
|
||||
wasmFullPass('(module (func (result f32) (f32.const 1)) (export "run" (func 0)))', 1);
|
||||
wasmFullPass('(module (func (result f64) (f64.const -2)) (export "run" (func 0)))', -2);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 2)) (export "run" (func 0)))', 2);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 4294967296)) (export "run" (func 0)))', 4294967296);
|
||||
wasmFullPass('(module (func (result f32) (f32.const 1.5)) (export "run" (func 0)))', 1.5);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 2.5)) (export "run" (func 0)))', 2.5);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 10e2)) (export "run" (func 0)))', 10e2);
|
||||
wasmFullPass('(module (func (result f32) (f32.const 10e2)) (export "run" (func 0)))', 10e2);
|
||||
wasmFullPass('(module (func (result f64) (f64.const -0x8000000000000000)) (export "run" (func 0)))', -0x8000000000000000);
|
||||
wasmFullPass('(module (func (result f64) (f64.const -9223372036854775808)) (export "run" (func 0)))', -9223372036854775808);
|
||||
wasmFullPass('(module (func (result f64) (f64.const 1797693134862315708145274e284)) (export "run" (func 0)))', 1797693134862315708145274e284);
|
||||
|
||||
function testUnary(type, opcode, op, expect) {
|
||||
wasmFullPass('(module (func (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0))) (export "run" 0))',
|
||||
wasmFullPass('(module (func (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0))) (export "run" (func 0)))',
|
||||
expect,
|
||||
{},
|
||||
op);
|
||||
}
|
||||
|
||||
function testBinary(type, opcode, lhs, rhs, expect) {
|
||||
wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" 0))',
|
||||
wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" (func 0)))',
|
||||
expect,
|
||||
{},
|
||||
lhs, rhs);
|
||||
}
|
||||
|
||||
function testComparison(type, opcode, lhs, rhs, expect) {
|
||||
wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result i32) (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" 0))',
|
||||
wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result i32) (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" (func 0)))',
|
||||
expect,
|
||||
{},
|
||||
lhs, rhs);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
wasmFullPass(`(module
|
||||
(func $test (result i32) (param i32) (param i32) (i32.add (local.get 0) (local.get 1)))
|
||||
(func $run (result i32) (call $test (i32.const 1) (i32.const ${Math.pow(2, 31) - 1})))
|
||||
(export "run" $run)
|
||||
(export "run" (func $run))
|
||||
)`, -Math.pow(2, 31));
|
||||
|
||||
wasmFullPass(`(module
|
||||
|
@ -17,7 +17,7 @@ wasmFullPass(`(module
|
|||
i32.add
|
||||
)
|
||||
(func) (func) (func)
|
||||
(export "run" 0))`, 43);
|
||||
(export "run" (func 0)))`, 43);
|
||||
|
||||
wasmFullPass(`
|
||||
(module
|
||||
|
@ -43,7 +43,7 @@ wasmFullPass(`(module
|
|||
global.get $imm_local_2
|
||||
i32.add
|
||||
)
|
||||
(export "run" $get)
|
||||
(export "run" (func $get))
|
||||
)`, 13 + 42 + 37 + 42, { globals: {x: 42} });
|
||||
|
||||
// Memory.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
(function() {
|
||||
let g = newGlobal({newCompartment: true});
|
||||
let dbg = new Debugger(g);
|
||||
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func (result anyref) (param anyref) local.get 0) (export "" 0))')));`);
|
||||
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func (result anyref) (param anyref) local.get 0) (export "" (func 0)))')));`);
|
||||
})();
|
||||
|
||||
(function() {
|
||||
|
|
|
@ -13,7 +13,7 @@ wasmFullPass(`
|
|||
ref.func $run
|
||||
ref.is_null
|
||||
)
|
||||
(export "run" $run)
|
||||
(export "run" (func $run))
|
||||
)
|
||||
`, 0);
|
||||
|
||||
|
@ -23,7 +23,7 @@ wasmFullPass(`
|
|||
(module
|
||||
(elem declared $f1)
|
||||
(func $f1 (result funcref) ref.func $f1)
|
||||
(export "f1" $f1)
|
||||
(export "f1" (func $f1))
|
||||
)
|
||||
`).exports;
|
||||
assertEq(f1(), f1);
|
||||
|
@ -36,8 +36,8 @@ wasmFullPass(`
|
|||
(elem declared $f1)
|
||||
(func $f1)
|
||||
(func $f2 (result funcref) ref.func $f1)
|
||||
(export "f1" $f1)
|
||||
(export "f2" $f2)
|
||||
(export "f1" (func $f1))
|
||||
(export "f2" (func $f2))
|
||||
)
|
||||
`).exports;
|
||||
assertEq(f2(), f1);
|
||||
|
@ -49,7 +49,7 @@ wasmFullPass(`
|
|||
(module
|
||||
(elem declared $f1)
|
||||
(func $f1)
|
||||
(export "f1" $f1)
|
||||
(export "f1" (func $f1))
|
||||
)
|
||||
`);
|
||||
let i2 = wasmEvalText(`
|
||||
|
@ -57,8 +57,8 @@ wasmFullPass(`
|
|||
(import $f1 "" "f1" (func))
|
||||
(elem declared $f1)
|
||||
(func $f2 (result funcref) ref.func $f1)
|
||||
(export "f1" $f1)
|
||||
(export "f2" $f2)
|
||||
(export "f1" (func $f1))
|
||||
(export "f2" (func $f2))
|
||||
)
|
||||
`, {"": i1.exports});
|
||||
|
||||
|
@ -103,7 +103,7 @@ assertEq(validFuncRefText('(elem anyref (ref.func $referenced))', 'anyref') inst
|
|||
assertErrorMessage(() => validFuncRefText('(start $referenced)', 'funcref'),
|
||||
WebAssembly.CompileError,
|
||||
/function index is not in an element segment/);
|
||||
assertErrorMessage(() => validFuncRefText('(export "referenced" $referenced)', 'funcref'),
|
||||
assertErrorMessage(() => validFuncRefText('(export "referenced" (func $referenced))', 'funcref'),
|
||||
WebAssembly.CompileError,
|
||||
/function index is not in an element segment/);
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ function testInner(type, initialValue, nextValue, coercion)
|
|||
|
||||
(func $get_cst (result ${type}) (global.get 1))
|
||||
|
||||
(export "get" $get)
|
||||
(export "get_cst" $get_cst)
|
||||
(export "get" (func $get))
|
||||
(export "get_cst" (func $get_cst))
|
||||
|
||||
(export "set" $set)
|
||||
(export "set" (func $set))
|
||||
)`).exports;
|
||||
|
||||
assertEq(module.get(), coercion(initialValue));
|
||||
|
@ -68,11 +68,11 @@ var module = wasmEvalText(`(module
|
|||
${get_set(3, 'f64')}
|
||||
${get_set(4, 'i32')}
|
||||
|
||||
(export "get0" $get_0) (export "set0" $set_0)
|
||||
(export "get1" $get_1) (export "set1" $set_1)
|
||||
(export "get2" $get_2) (export "set2" $set_2)
|
||||
(export "get3" $get_3) (export "set3" $set_3)
|
||||
(export "get4" $get_4) (export "set4" $set_4)
|
||||
(export "get0" (func $get_0)) (export "set0" (func $set_0))
|
||||
(export "get1" (func $get_1)) (export "set1" (func $set_1))
|
||||
(export "get2" (func $get_2)) (export "set2" (func $set_2))
|
||||
(export "get3" (func $get_3)) (export "set3" (func $set_3))
|
||||
(export "get4" (func $get_4)) (export "set4" (func $set_4))
|
||||
)`).exports;
|
||||
|
||||
let values = [42, 10, Math.fround(13.37), 13.37, -18];
|
||||
|
@ -98,7 +98,7 @@ module = wasmEvalText(`(module
|
|||
(table (export "tbl") 4 funcref)
|
||||
(elem (global.get 0) $f)
|
||||
(func $f)
|
||||
(export "f" $f)
|
||||
(export "f" (func $f))
|
||||
)`, {
|
||||
globals: {
|
||||
a: 1
|
||||
|
@ -110,7 +110,7 @@ assertEq(module.f, module.tbl.get(1));
|
|||
module = wasmEvalText(`(module
|
||||
(import $g "globals" "x" (global i32))
|
||||
(func $get (result i32) (global.get $g))
|
||||
(export "getter" $get)
|
||||
(export "getter" (func $get))
|
||||
(export "value" global 0)
|
||||
)`, { globals: {x: 42} }).exports;
|
||||
|
||||
|
@ -196,11 +196,11 @@ function testInitExpr(type, initialValue, nextValue, coercion, assertFunc = asse
|
|||
|
||||
(func $get_cst (result ${type}) (global.get 2))
|
||||
|
||||
(export "get0" $get0)
|
||||
(export "get1" $get1)
|
||||
(export "get_cst" $get_cst)
|
||||
(export "get0" (func $get0))
|
||||
(export "get1" (func $get1))
|
||||
(export "get_cst" (func $get_cst))
|
||||
|
||||
(export "set1" $set1)
|
||||
(export "set1" (func $set1))
|
||||
(export "global_imm" (global $glob_imm))
|
||||
)`, {
|
||||
globals: {
|
||||
|
@ -237,9 +237,9 @@ wasmAssert(`(module
|
|||
(func $get (result i64) (global.get 0))
|
||||
(func $set (param i64) (global.set 0 (local.get 0)))
|
||||
(func $get_cst (result i64) (global.get 1))
|
||||
(export "get" $get)
|
||||
(export "get_cst" $get_cst)
|
||||
(export "set" $set)
|
||||
(export "get" (func $get))
|
||||
(export "get_cst" (func $get_cst))
|
||||
(export "set" (func $set))
|
||||
)`, [
|
||||
{type: 'i64', func: '$get', expected: initialValue},
|
||||
{type: 'i64', func: '$set', args: [`i64.const ${nextValue}`]},
|
||||
|
|
|
@ -36,7 +36,7 @@ function linearModule(min, max, ops, current_memory, grow_memory) {
|
|||
(func (result i32)
|
||||
(drop ` + opsText + `)
|
||||
(${current_memory})
|
||||
) (export "run" 0))`;
|
||||
) (export "run" (func 0)))`;
|
||||
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -3,43 +3,43 @@
|
|||
|
||||
var module = new WebAssembly.Module(wasmTextToBinary(`(module
|
||||
(import $vv "env" "v_v")
|
||||
(export "v_v" $vv)
|
||||
(export "v_v" (func $vv))
|
||||
|
||||
(import $vi "env" "v_i" (param i32))
|
||||
(export "v_i" $vi)
|
||||
(export "v_i" (func $vi))
|
||||
|
||||
(import $vI "env" "v_I" (param i64))
|
||||
(export "v_I" $vI)
|
||||
(export "v_I" (func $vI))
|
||||
|
||||
(import $vf "env" "v_f" (param f32))
|
||||
(export "v_f" $vf)
|
||||
(export "v_f" (func $vf))
|
||||
|
||||
(import $mem "env" "memory" (memory 0))
|
||||
(export "mem" (memory $mem))
|
||||
|
||||
(import $vd "env" "v_d" (param f64))
|
||||
(export "v_d" $vd)
|
||||
(export "v_d" (func $vd))
|
||||
|
||||
(import $vfd "env" "v_fd" (param f32) (param f64))
|
||||
(export "v_fd" $vfd)
|
||||
(export "v_fd" (func $vfd))
|
||||
|
||||
(import $vIfifd "env" "v_Ififd" (param i64) (param f32) (param i32) (param f32) (param f64))
|
||||
(export "v_Ififd" $vIfifd)
|
||||
(export "v_Ififd" (func $vIfifd))
|
||||
|
||||
(import $iv "env" "i_v" (result i32))
|
||||
(export "i_v" $iv)
|
||||
(export "i_v" (func $iv))
|
||||
|
||||
(import $Ii "env" "I_i" (result i64) (param i32))
|
||||
(export "I_i" $Ii)
|
||||
(export "I_i" (func $Ii))
|
||||
|
||||
(import $table "env" "table" (table 0 funcref))
|
||||
(export "table" (table $table))
|
||||
|
||||
(import $fd "env" "f_d" (result f32) (param f64))
|
||||
(export "f_d" $fd)
|
||||
(export "f_d" (func $fd))
|
||||
|
||||
(import $dffd "env" "d_ffd" (result f64) (param f32) (param f32) (param f64))
|
||||
(export "d_ffd" $dffd)
|
||||
(export "d_ffd" (func $dffd))
|
||||
)`));
|
||||
|
||||
for (let desc of WebAssembly.Module.imports(module)) {
|
||||
|
|
|
@ -110,7 +110,7 @@ wasmFailValidateText('(module (import "a" "b" (table 2 1 funcref)))', /maximum l
|
|||
|
||||
// Import wasm-wasm type mismatch
|
||||
|
||||
var e = wasmEvalText('(module (func $i2v (param i32)) (export "i2v" $i2v) (func $f2v (param f32)) (export "f2v" $f2v))').exports;
|
||||
var e = wasmEvalText('(module (func $i2v (param i32)) (export "i2v" (func $i2v)) (func $f2v (param f32)) (export "f2v" (func $f2v)))').exports;
|
||||
var i2vm = new Module(wasmTextToBinary('(module (import "a" "b" (param i32)))'));
|
||||
var f2vm = new Module(wasmTextToBinary('(module (import "a" "b" (param f32)))'));
|
||||
assertEq(new Instance(i2vm, {a:{b:e.i2v}}) instanceof Instance, true);
|
||||
|
@ -178,12 +178,12 @@ var code = wasmTextToBinary('(module)');
|
|||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).length, 0);
|
||||
|
||||
var code = wasmTextToBinary('(module (func) (export "foo" 0))');
|
||||
var code = wasmTextToBinary('(module (func) (export "foo" (func 0)))');
|
||||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).join(), "foo");
|
||||
assertEq(e.foo(), undefined);
|
||||
|
||||
var code = wasmTextToBinary('(module (func) (export "foo" 0) (export "bar" 0))');
|
||||
var code = wasmTextToBinary('(module (func) (export "foo" (func 0)) (export "bar" (func 0)))');
|
||||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).join(), "foo,bar");
|
||||
assertEq(e.foo(), undefined);
|
||||
|
@ -201,7 +201,7 @@ assertEq(e.foo, e.bar);
|
|||
assertEq(e.foo instanceof Memory, true);
|
||||
assertEq(e.foo.buffer.byteLength, 64*1024);
|
||||
|
||||
var code = wasmTextToBinary('(module (memory 1 1) (func) (export "foo" 0) (export "bar" memory))');
|
||||
var code = wasmTextToBinary('(module (memory 1 1) (func) (export "foo" (func 0)) (export "bar" memory))');
|
||||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).join(), "foo,bar");
|
||||
assertEq(e.foo(), undefined);
|
||||
|
@ -209,7 +209,7 @@ assertEq(e.bar instanceof Memory, true);
|
|||
assertEq(e.bar instanceof Memory, true);
|
||||
assertEq(e.bar.buffer.byteLength, 64*1024);
|
||||
|
||||
var code = wasmTextToBinary('(module (memory 1 1) (func) (export "bar" memory) (export "foo" 0))');
|
||||
var code = wasmTextToBinary('(module (memory 1 1) (func) (export "bar" memory) (export "foo" (func 0)))');
|
||||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).join(), "bar,foo");
|
||||
assertEq(e.foo(), undefined);
|
||||
|
@ -235,7 +235,7 @@ assertEq(e.t2 instanceof Table, true);
|
|||
assertEq(e.t1, e.t2);
|
||||
assertEq(e.t1.length, 2);
|
||||
|
||||
var code = wasmTextToBinary('(module (table 2 funcref) (memory 1 1) (func) (export "t" table) (export "m" memory) (export "f" 0))');
|
||||
var code = wasmTextToBinary('(module (table 2 funcref) (memory 1 1) (func) (export "t" table) (export "m" memory) (export "f" (func 0)))');
|
||||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).join(), "t,m,f");
|
||||
assertEq(e.f(), undefined);
|
||||
|
@ -243,7 +243,7 @@ assertEq(e.t instanceof Table, true);
|
|||
assertEq(e.m instanceof Memory, true);
|
||||
assertEq(e.t.length, 2);
|
||||
|
||||
var code = wasmTextToBinary('(module (table 1 funcref) (memory 1 1) (func) (export "m" memory) (export "f" 0) (export "t" table))');
|
||||
var code = wasmTextToBinary('(module (table 1 funcref) (memory 1 1) (func) (export "m" memory) (export "f" (func 0)) (export "t" table))');
|
||||
var e = new Instance(new Module(code)).exports;
|
||||
assertEq(Object.keys(e).join(), "m,f,t");
|
||||
assertEq(e.f(), undefined);
|
||||
|
@ -267,11 +267,11 @@ var text = `(module
|
|||
(table 4 funcref)
|
||||
(elem (i32.const 0) $f)
|
||||
(elem (i32.const 2) $g)
|
||||
(export "f1" $f)
|
||||
(export "f1" (func $f))
|
||||
(export "tbl1" table)
|
||||
(export "f2" $f)
|
||||
(export "f2" (func $f))
|
||||
(export "tbl2" table)
|
||||
(export "f3" $h)
|
||||
(export "f3" (func $h))
|
||||
(func (export "run") (result i32) (call_indirect (type 0) (i32.const 2)))
|
||||
)`;
|
||||
wasmFullPass(text, 2);
|
||||
|
@ -301,10 +301,10 @@ assertEq(e.tbl1.get(0), e.tbl1.get(3));
|
|||
|
||||
var args;
|
||||
var m = new Module(wasmTextToBinary(`(module
|
||||
(export "a" $a) (import $a "" "a" (param f32))
|
||||
(export "b" $b) (import $b "" "b" (param i32) (result i32))
|
||||
(export "c" $c) (import $c "" "c" (result i32))
|
||||
(export "d" $d) (import $d "" "d")
|
||||
(export "a" (func $a)) (import $a "" "a" (param f32))
|
||||
(export "b" (func $b)) (import $b "" "b" (param i32) (result i32))
|
||||
(export "c" (func $c)) (import $c "" "c" (result i32))
|
||||
(export "d" (func $d)) (import $d "" "d")
|
||||
)`));
|
||||
var js = function() { args = arguments; return 42 }
|
||||
var e = new Instance(m, {"":{a:js, b:js, c:js, d:js}}).exports;
|
||||
|
@ -347,7 +347,7 @@ var e = new Instance(new Module(code), {a:{b:tbl}}).exports;
|
|||
assertEq(tbl, e.foo);
|
||||
assertEq(tbl, e.bar);
|
||||
|
||||
var code = wasmTextToBinary('(module (import "a" "b" (table 2 2 funcref)) (func $foo) (elem (i32.const 0) $foo) (export "foo" $foo))');
|
||||
var code = wasmTextToBinary('(module (import "a" "b" (table 2 2 funcref)) (func $foo) (elem (i32.const 0) $foo) (export "foo" (func $foo)))');
|
||||
var tbl = new Table({initial:2, maximum:2, element:"funcref"});
|
||||
var e1 = new Instance(new Module(code), {a:{b:tbl}}).exports;
|
||||
assertEq(e1.foo, tbl.get(0));
|
||||
|
@ -365,13 +365,13 @@ var m = new Module(wasmTextToBinary(`(module
|
|||
(import $bar "" "bar" (result i32))
|
||||
(func $baz (result i32) (i32.const 13))
|
||||
(elem (i32.const 0) $foo $bar $baz)
|
||||
(export "foo" $foo)
|
||||
(export "bar" $bar)
|
||||
(export "baz" $baz)
|
||||
(export "foo" (func $foo))
|
||||
(export "bar" (func $bar))
|
||||
(export "baz" (func $baz))
|
||||
(export "tbl" table)
|
||||
)`));
|
||||
var jsFun = () => 83;
|
||||
var wasmFun = new Instance(new Module(wasmTextToBinary('(module (func (result i32) (i32.const 42)) (export "foo" 0))'))).exports.foo;
|
||||
var wasmFun = new Instance(new Module(wasmTextToBinary('(module (func (result i32) (i32.const 42)) (export "foo" (func 0)))'))).exports.foo;
|
||||
var e1 = new Instance(m, {"":{foo:jsFun, bar:wasmFun}}).exports;
|
||||
assertEq(jsFun === e1.foo, false);
|
||||
assertEq(wasmFun, e1.bar);
|
||||
|
@ -412,15 +412,15 @@ assertEq(e4.baz, e4.tbl.get(2));
|
|||
|
||||
// i64 is fully allowed for imported wasm functions
|
||||
|
||||
var code1 = wasmTextToBinary('(module (func $exp (param i64) (result i64) (i64.add (local.get 0) (i64.const 10))) (export "exp" $exp))');
|
||||
var code1 = wasmTextToBinary('(module (func $exp (param i64) (result i64) (i64.add (local.get 0) (i64.const 10))) (export "exp" (func $exp)))');
|
||||
var e1 = new Instance(new Module(code1)).exports;
|
||||
var code2 = wasmTextToBinary('(module (import $i "a" "b" (param i64) (result i64)) (func $f (result i32) (i32.wrap/i64 (call $i (i64.const 42)))) (export "f" $f))');
|
||||
var code2 = wasmTextToBinary('(module (import $i "a" "b" (param i64) (result i64)) (func $f (result i32) (i32.wrap/i64 (call $i (i64.const 42)))) (export "f" (func $f)))');
|
||||
var e2 = new Instance(new Module(code2), {a:{b:e1.exp}}).exports;
|
||||
assertEq(e2.f(), 52);
|
||||
|
||||
// Non-existent export errors
|
||||
|
||||
wasmFailValidateText('(module (export "a" 0))', /exported function index out of bounds/);
|
||||
wasmFailValidateText('(module (export "a" (func 0)))', /exported function index out of bounds/);
|
||||
wasmFailValidateText('(module (export "a" global 0))', /exported global index out of bounds/);
|
||||
wasmFailValidateText('(module (export "a" memory))', /exported memory index out of bounds/);
|
||||
wasmFailValidateText('(module (export "a" table))', /exported table index out of bounds/);
|
||||
|
@ -439,7 +439,7 @@ var m = new Module(wasmTextToBinary(`
|
|||
(data (i32.const 100) "\\0c\\0d")
|
||||
(func $get (param $p i32) (result i32)
|
||||
(i32.load8_u (local.get $p)))
|
||||
(export "get" $get))
|
||||
(export "get" (func $get)))
|
||||
`));
|
||||
var mem = new Memory({initial:1, maximum:1});
|
||||
var {get} = new Instance(m, {a:{b:mem}}).exports;
|
||||
|
@ -500,8 +500,8 @@ var m = new Module(wasmTextToBinary(`
|
|||
(elem (i32.const 0) $f)
|
||||
(data (global.get $memOff) "\\02")
|
||||
(elem (global.get $tblOff) $g)
|
||||
(export "f" $f)
|
||||
(export "g" $g))
|
||||
(export "f" (func $f))
|
||||
(export "g" (func $g)))
|
||||
`));
|
||||
|
||||
// Active segments are applied in order (this is observable if they overlap).
|
||||
|
@ -646,15 +646,15 @@ assertEq(tbl.get(3)(), undefined);
|
|||
|
||||
// Cross-instance calls
|
||||
|
||||
var i1 = new Instance(new Module(wasmTextToBinary(`(module (func) (func (param i32) (result i32) (i32.add (local.get 0) (i32.const 1))) (func) (export "f" 1))`)));
|
||||
var i2 = new Instance(new Module(wasmTextToBinary(`(module (import $imp "a" "b" (param i32) (result i32)) (func $g (result i32) (call $imp (i32.const 13))) (export "g" $g))`)), {a:{b:i1.exports.f}});
|
||||
var i1 = new Instance(new Module(wasmTextToBinary(`(module (func) (func (param i32) (result i32) (i32.add (local.get 0) (i32.const 1))) (func) (export "f" (func 1)))`)));
|
||||
var i2 = new Instance(new Module(wasmTextToBinary(`(module (import $imp "a" "b" (param i32) (result i32)) (func $g (result i32) (call $imp (i32.const 13))) (export "g" (func $g)))`)), {a:{b:i1.exports.f}});
|
||||
assertEq(i2.exports.g(), 14);
|
||||
|
||||
var i1 = new Instance(new Module(wasmTextToBinary(`(module
|
||||
(memory 1 1)
|
||||
(data (i32.const 0) "\\42")
|
||||
(func $f (result i32) (i32.load (i32.const 0)))
|
||||
(export "f" $f)
|
||||
(export "f" (func $f))
|
||||
)`)));
|
||||
var i2 = new Instance(new Module(wasmTextToBinary(`(module
|
||||
(import $imp "a" "b" (result i32))
|
||||
|
@ -665,7 +665,7 @@ var i2 = new Instance(new Module(wasmTextToBinary(`(module
|
|||
(func $def (result i32) (i32.load (i32.const 0)))
|
||||
(type $v2i (func (result i32)))
|
||||
(func $call (param i32) (result i32) (call_indirect (type $v2i) (local.get 0)))
|
||||
(export "call" $call)
|
||||
(export "call" (func $call))
|
||||
)`)), {a:{b:i1.exports.f}});
|
||||
assertEq(i2.exports.call(0), 0x42);
|
||||
assertEq(i2.exports.call(1), 0x13);
|
||||
|
@ -682,7 +682,7 @@ var m = new Module(wasmTextToBinary(`(module
|
|||
(i32.add
|
||||
(i32.load (i32.const 0))
|
||||
(call $next))))
|
||||
(export "call" $call)
|
||||
(export "call" (func $call))
|
||||
)`));
|
||||
var e = {call:() => 1000};
|
||||
for (var i = 0; i < 10; i++)
|
||||
|
@ -797,8 +797,8 @@ assertEq(e.call(), 1090);
|
|||
(i32.add (memory.size) (call $imp1))
|
||||
(memory.size))
|
||||
(call $imp2)))
|
||||
(export "impstub" $imp1)
|
||||
(export "test" $test))
|
||||
(export "impstub" (func $imp1))
|
||||
(export "test" (func $test)))
|
||||
`)), {a:{m:g.mem, f1:g.f1, f2:g.Math.abs}});
|
||||
|
||||
for (var i = 0; i < 20; i++) {
|
||||
|
@ -812,7 +812,7 @@ assertEq(e.call(), 1090);
|
|||
(import $imp "a" "othertest" (result i32))
|
||||
(import "a" "m" (memory 1))
|
||||
(func (result i32) (i32.add (call $imp) (memory.size)))
|
||||
(export "test" 1))
|
||||
(export "test" (func 1)))
|
||||
`;
|
||||
g.i1 = i1;
|
||||
g.evaluate("i2 = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`" + src + "`)), {a:{m:mem,othertest:i1.exports.test}})");
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
const Module = WebAssembly.Module;
|
||||
const Instance = WebAssembly.Instance;
|
||||
|
||||
const m1 = new Module(wasmTextToBinary(`(module (func $f) (export "f" $f))`));
|
||||
const m2 = new Module(wasmTextToBinary(`(module (import "a" "f") (func $f) (export "g" $f))`));
|
||||
const m1 = new Module(wasmTextToBinary(`(module (func $f) (export "f" (func $f)))`));
|
||||
const m2 = new Module(wasmTextToBinary(`(module (import "a" "f") (func $f) (export "g" (func $f)))`));
|
||||
|
||||
// Imported instance objects should stay alive as long as any importer is alive.
|
||||
resetFinalizeCount();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
assertEq(wasmEvalText('(module (func (result i32) (i32.const -1)) (export "" 0))').exports[""](), -1);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (i32.const -2147483648)) (export "" 0))').exports[""](), -2147483648);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (i32.const 4294967295)) (export "" 0))').exports[""](), -1);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (i32.const -1)) (export "" (func 0)))').exports[""](), -1);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (i32.const -2147483648)) (export "" (func 0)))').exports[""](), -2147483648);
|
||||
assertEq(wasmEvalText('(module (func (result i32) (i32.const 4294967295)) (export "" (func 0)))').exports[""](), -1);
|
||||
|
||||
function testUnary(type, opcode, op, expect) {
|
||||
if (type === 'i64') {
|
||||
|
@ -11,9 +11,9 @@ function testUnary(type, opcode, op, expect) {
|
|||
return;
|
||||
}
|
||||
// Test with constant
|
||||
wasmFullPass(`(module (func (result ${type}) (${type}.${opcode} (${type}.const ${op}))) (export "run" 0))`, expect);
|
||||
wasmFullPass(`(module (func (result ${type}) (${type}.${opcode} (${type}.const ${op}))) (export "run" (func 0)))`, expect);
|
||||
// Test with param
|
||||
wasmFullPass(`(module (func (param ${type}) (result ${type}) (${type}.${opcode} (local.get 0))) (export "run" 0))`, expect, {}, op);
|
||||
wasmFullPass(`(module (func (param ${type}) (result ${type}) (${type}.${opcode} (local.get 0))) (export "run" (func 0)))`, expect, {}, op);
|
||||
}
|
||||
|
||||
function testBinary64(opcode, lhs, rhs, expect) {
|
||||
|
@ -27,15 +27,15 @@ function testBinary64(opcode, lhs, rhs, expect) {
|
|||
}
|
||||
|
||||
function testBinary32(opcode, lhs, rhs, expect) {
|
||||
wasmFullPass(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "run" 0))`, expect, {}, lhs, rhs);
|
||||
wasmFullPass(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "run" (func 0)))`, expect, {}, lhs, rhs);
|
||||
// The same, but now the RHS is a constant.
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (i32.${opcode} (local.get 0) (i32.const ${rhs}))) (export "run" 0))`, expect, {}, lhs);
|
||||
wasmFullPass(`(module (func (param i32) (result i32) (i32.${opcode} (local.get 0) (i32.const ${rhs}))) (export "run" (func 0)))`, expect, {}, lhs);
|
||||
// LHS and RHS are constants.
|
||||
wasmFullPass(`(module (func (result i32) (i32.${opcode} (i32.const ${lhs}) (i32.const ${rhs}))) (export "run" 0))`, expect);
|
||||
wasmFullPass(`(module (func (result i32) (i32.${opcode} (i32.const ${lhs}) (i32.const ${rhs}))) (export "run" (func 0)))`, expect);
|
||||
}
|
||||
|
||||
function testComparison32(opcode, lhs, rhs, expect) {
|
||||
wasmFullPass(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "run" 0))`, expect, {}, lhs, rhs);
|
||||
wasmFullPass(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "run" (func 0)))`, expect, {}, lhs, rhs);
|
||||
}
|
||||
function testComparison64(opcode, lhs, rhs, expect) {
|
||||
let lsrc = `i64.const ${lhs}`;
|
||||
|
@ -48,7 +48,7 @@ function testComparison64(opcode, lhs, rhs, expect) {
|
|||
i64.const ${rhs}
|
||||
call $cmp
|
||||
)
|
||||
(export "run" $assert))`, expect);
|
||||
(export "run" (func $assert)))`, expect);
|
||||
|
||||
// Also test `if`, for the compare-and-branch path.
|
||||
wasmFullPass(`(module
|
||||
|
@ -61,23 +61,23 @@ function testComparison64(opcode, lhs, rhs, expect) {
|
|||
i64.const ${rhs}
|
||||
call $cmp
|
||||
)
|
||||
(export "run" $assert))`, expect);
|
||||
(export "run" (func $assert)))`, expect);
|
||||
}
|
||||
|
||||
function testI64Eqz(input, expect) {
|
||||
wasmFullPass(`(module (func (result i32) (i64.eqz (i64.const ${input}))) (export "run" 0))`, expect, {});
|
||||
wasmFullPass(`(module (func (result i32) (i64.eqz (i64.const ${input}))) (export "run" (func 0)))`, expect, {});
|
||||
wasmFullPass(`(module
|
||||
(func (param i64) (result i32) (i64.eqz (local.get 0)))
|
||||
(func $assert (result i32) (i64.const ${input}) (call 0))
|
||||
(export "run" $assert))`, expect);
|
||||
(export "run" (func $assert)))`, expect);
|
||||
}
|
||||
|
||||
function testTrap32(opcode, lhs, rhs, expect) {
|
||||
assertErrorMessage(() => wasmEvalText(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "" 0))`).exports[""](lhs, rhs), Error, expect);
|
||||
assertErrorMessage(() => wasmEvalText(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "" (func 0)))`).exports[""](lhs, rhs), Error, expect);
|
||||
// The same, but now the RHS is a constant.
|
||||
assertErrorMessage(() => wasmEvalText(`(module (func (param i32) (result i32) (i32.${opcode} (local.get 0) (i32.const ${rhs}))) (export "" 0))`).exports[""](lhs), Error, expect);
|
||||
assertErrorMessage(() => wasmEvalText(`(module (func (param i32) (result i32) (i32.${opcode} (local.get 0) (i32.const ${rhs}))) (export "" (func 0)))`).exports[""](lhs), Error, expect);
|
||||
// LHS and RHS are constants.
|
||||
assertErrorMessage(wasmEvalText(`(module (func (result i32) (i32.${opcode} (i32.const ${lhs}) (i32.const ${rhs}))) (export "" 0))`).exports[""], Error, expect);
|
||||
assertErrorMessage(wasmEvalText(`(module (func (result i32) (i32.${opcode} (i32.const ${lhs}) (i32.const ${rhs}))) (export "" (func 0)))`).exports[""], Error, expect);
|
||||
}
|
||||
|
||||
function testTrap64(opcode, lhs, rhs, expect) {
|
||||
|
@ -174,7 +174,7 @@ if (getJitCompilerOptions()["ion.warmup.trigger"] === 0)
|
|||
gc();
|
||||
|
||||
// Test MTest's GVN branch inversion.
|
||||
var testTrunc = wasmEvalText(`(module (func (param f32) (result i32) (if (result i32) (i32.eqz (i32.trunc_s/f32 (local.get 0))) (i32.const 0) (i32.const 1))) (export "" 0))`).exports[""];
|
||||
var testTrunc = wasmEvalText(`(module (func (param f32) (result i32) (if (result i32) (i32.eqz (i32.trunc_s/f32 (local.get 0))) (i32.const 0) (i32.const 1))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(testTrunc(0), 0);
|
||||
assertEq(testTrunc(13.37), 1);
|
||||
|
||||
|
@ -372,7 +372,7 @@ wasmAssert(`(module (func $run (param i64) (result i64) (local i64) (local.set 1
|
|||
[{ type: 'i64', func: '$run', args: ['i64.const 2'], expected: 2048}]);
|
||||
|
||||
// Test MTest's GVN branch inversion.
|
||||
var testTrunc = wasmEvalText(`(module (func (param f32) (result i32) (if (result i32) (i64.eqz (i64.trunc_s/f32 (local.get 0))) (i32.const 0) (i32.const 1))) (export "" 0))`).exports[""];
|
||||
var testTrunc = wasmEvalText(`(module (func (param f32) (result i32) (if (result i32) (i64.eqz (i64.trunc_s/f32 (local.get 0))) (i32.const 0) (i32.const 1))) (export "" (func 0)))`).exports[""];
|
||||
assertEq(testTrunc(0), 0);
|
||||
assertEq(testTrunc(13.37), 1);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ g.parent = this;
|
|||
g.eval("Debugger(parent).onExceptionUnwind = function () {};");
|
||||
lfModule = new WebAssembly.Module(wasmTextToBinary(`
|
||||
(module
|
||||
(export "f" $func0)
|
||||
(export "f" (func $func0))
|
||||
(func $func0 (result i32)
|
||||
i32.const -1
|
||||
)
|
||||
|
|
|
@ -56,7 +56,7 @@ setJitCompilerOption("ion.warmup.trigger", 10);
|
|||
|
||||
var e = wasmEvalText(`(module
|
||||
(import $a "" "a" (param i32 f64) (result f64))
|
||||
(export "a" $a)
|
||||
(export "a" (func $a))
|
||||
)`, {"":{a:(a,b)=>a+b}}).exports;
|
||||
for (var i = 0; i < 100; i++)
|
||||
assertEq(e.a(1.5, 2.5), 3.5);
|
||||
|
|
|
@ -6,13 +6,13 @@ var i = wasmEvalText(
|
|||
(i32.load8_u (local.get $base))
|
||||
(i32.load8_u offset=1 (local.get $base)))
|
||||
)
|
||||
(export "off1" $off1)
|
||||
(export "off1" (func $off1))
|
||||
(func $off2 (param $base i32) (result i32)
|
||||
(i32.add
|
||||
(i32.load8_u offset=1 (local.get $base))
|
||||
(i32.load8_u offset=2 (local.get $base)))
|
||||
)
|
||||
(export "off2" $off2)
|
||||
(export "off2" (func $off2))
|
||||
)`).exports;
|
||||
assertEq(i.off1(0), 3);
|
||||
assertEq(i.off1(1), 5);
|
||||
|
|
|
@ -14,7 +14,7 @@ function loadModuleSrc(type, ext, offset, align, drop = false) {
|
|||
(local.get 0)
|
||||
)
|
||||
${maybeDrop}
|
||||
) (export "" 0))`;
|
||||
) (export "" (func 0)))`;
|
||||
}
|
||||
function loadModule(type, ext, offset, align, drop = false) {
|
||||
return wasmEvalText(loadModuleSrc(type, ext, offset, align, drop)).exports[""];
|
||||
|
@ -33,14 +33,14 @@ function storeModuleSrc(type, ext, offset, align) {
|
|||
(local.get 0)
|
||||
(local.get 1)
|
||||
)
|
||||
) (export "store" 0)
|
||||
) (export "store" (func 0))
|
||||
(func $load (param i32) (result ${type})
|
||||
(${type}.load${load_ext}
|
||||
offset=${offset}
|
||||
${align != 0 ? 'align=' + align : ''}
|
||||
(local.get 0)
|
||||
)
|
||||
) (export "load" 1))`;
|
||||
) (export "load" (func 1)))`;
|
||||
}
|
||||
function storeModule(type, ext, offset, align) {
|
||||
return wasmEvalText(storeModuleSrc(type, ext, offset, align)).exports;
|
||||
|
@ -59,14 +59,14 @@ function storeModuleCstSrc(type, ext, offset, align, value) {
|
|||
(local.get 0)
|
||||
(${type}.const ${value})
|
||||
)
|
||||
) (export "store" 0)
|
||||
) (export "store" (func 0))
|
||||
(func $load (param i32) (result ${type})
|
||||
(${type}.load${load_ext}
|
||||
offset=${offset}
|
||||
${align != 0 ? 'align=' + align : ''}
|
||||
(local.get 0)
|
||||
)
|
||||
) (export "load" 1))`;
|
||||
) (export "load" (func 1)))`;
|
||||
}
|
||||
function storeModuleCst(type, ext, offset, align, value) {
|
||||
return wasmEvalText(storeModuleCstSrc(type, ext, offset, align, value)).exports;
|
||||
|
@ -122,11 +122,11 @@ function testStoreOOB(type, ext, base, offset, align, value) {
|
|||
}
|
||||
|
||||
function badLoadModule(type, ext) {
|
||||
wasmFailValidateText( `(module (func (param i32) (${type}.load${ext} (local.get 0))) (export "" 0))`, /can't touch memory/);
|
||||
wasmFailValidateText( `(module (func (param i32) (${type}.load${ext} (local.get 0))) (export "" (func 0)))`, /can't touch memory/);
|
||||
}
|
||||
|
||||
function badStoreModule(type, ext) {
|
||||
wasmFailValidateText(`(module (func (param i32) (${type}.store${ext} (local.get 0) (${type}.const 0))) (export "" 0))`, /can't touch memory/);
|
||||
wasmFailValidateText(`(module (func (param i32) (${type}.store${ext} (local.get 0) (${type}.const 0))) (export "" (func 0)))`, /can't touch memory/);
|
||||
}
|
||||
|
||||
// Can't touch memory.
|
||||
|
@ -337,7 +337,7 @@ for (var foldOffsets = 0; foldOffsets <= 1; foldOffsets++) {
|
|||
)
|
||||
)
|
||||
)
|
||||
) (export "" 0))`
|
||||
) (export "" (func 0)))`
|
||||
).exports[""](1), 50464523);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ function assertSameBitPattern(from, to, offset) {
|
|||
f32[0] = NaN;
|
||||
f32[0] = f32[0]; // Force canonicalization.
|
||||
|
||||
f32[1] = wasmEvalText('(module (func (result f32) (f32.const nan:0x123456)) (export "" 0))').exports[""]();
|
||||
f32[1] = wasmEvalText('(module (func (result f32) (f32.const nan:0x123456)) (export "" (func 0)))').exports[""]();
|
||||
assertSameBitPattern(0, 4, 4);
|
||||
|
||||
var checkBitPatterns = {
|
||||
|
@ -27,14 +27,14 @@ var checkBitPatterns = {
|
|||
}
|
||||
}
|
||||
|
||||
wasmEvalText('(module (import "" "float32" (param f32)) (func (call 0 (f32.const nan:0x123456))) (export "" 0))', checkBitPatterns).exports[""]();
|
||||
wasmEvalText('(module (import "" "float32" (param f32)) (func (call 0 (f32.const nan:0x123456))) (export "" (func 0)))', checkBitPatterns).exports[""]();
|
||||
|
||||
f64[0] = NaN;
|
||||
f64[0] = f64[0]; // Force canonicalization.
|
||||
f64[1] = wasmEvalText('(module (func (result f64) (f64.const nan:0x123456)) (export "" 0))').exports[""]();
|
||||
f64[1] = wasmEvalText('(module (func (result f64) (f64.const nan:0x123456)) (export "" (func 0)))').exports[""]();
|
||||
assertSameBitPattern(0, 8, 8);
|
||||
|
||||
wasmEvalText('(module (import "" "float64" (param f64)) (func (call 0 (f64.const nan:0x123456))) (export "" 0))', checkBitPatterns).exports[""]();
|
||||
wasmEvalText('(module (import "" "float64" (param f64)) (func (call 0 (f64.const nan:0x123456))) (export "" (func 0)))', checkBitPatterns).exports[""]();
|
||||
|
||||
// SANITY CHECKS
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ function test(code, importObj, expectedStacks)
|
|||
test(
|
||||
`(module
|
||||
(func (result i32) (i32.const 42))
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`,
|
||||
{},
|
||||
["", ">", "0,>", ">", ""]);
|
||||
|
@ -35,7 +35,7 @@ test(
|
|||
`(module
|
||||
(func (result i32) (i32.add (call 1) (i32.const 1)))
|
||||
(func (result i32) (i32.const 42))
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`,
|
||||
{},
|
||||
["", ">", "0,>", "1,0,>", "0,>", ">", ""]);
|
||||
|
@ -45,7 +45,7 @@ test(
|
|||
(func $foo (call_indirect (type 0) (i32.const 0)))
|
||||
(func $bar)
|
||||
(table funcref (elem $bar))
|
||||
(export "" $foo)
|
||||
(export "" (func $foo))
|
||||
)`,
|
||||
{},
|
||||
["", ">", "0,>", "1,0,>", "0,>", ">", ""]);
|
||||
|
@ -55,7 +55,7 @@ test(
|
|||
(import $foo "" "foo")
|
||||
(table funcref (elem $foo))
|
||||
(func $bar (call_indirect (type 0) (i32.const 0)))
|
||||
(export "" $bar)
|
||||
(export "" (func $bar))
|
||||
)`,
|
||||
{"":{foo:()=>{}}},
|
||||
["", ">", "1,>", "0,1,>", "<,0,1,>", "0,1,>", "1,>", ">", ""]);
|
||||
|
@ -152,7 +152,7 @@ for (let type of ['f32', 'f64']) {
|
|||
(func $foo (call_indirect (type $bad) (i32.const 1) (i32.const 0)))
|
||||
(func $bar (type $good))
|
||||
(table funcref (elem $bar))
|
||||
(export "" $foo)
|
||||
(export "" (func $foo))
|
||||
)`,
|
||||
WebAssembly.RuntimeError,
|
||||
["", ">", "0,>", "1,0,>", ">", "", ">", ""]);
|
||||
|
@ -163,7 +163,7 @@ for (let type of ['f32', 'f64']) {
|
|||
var e = wasmEvalText(`
|
||||
(module
|
||||
(func $foo (result i32) (i32.const 42))
|
||||
(export "foo" $foo)
|
||||
(export "foo" (func $foo))
|
||||
(func $bar (result i32) (i32.const 13))
|
||||
(table 10 funcref)
|
||||
(elem (i32.const 0) $foo $bar)
|
||||
|
@ -207,7 +207,7 @@ for (let type of ['f32', 'f64']) {
|
|||
(elem (i32.const 2) $bar)
|
||||
(func $bar (result i32) (i32.const 99))
|
||||
(func $baz (param $i i32) (result i32) (call_indirect (type $v2i) (local.get $i)))
|
||||
(export "baz" $baz)
|
||||
(export "baz" (func $baz))
|
||||
)`, {a:{b:e.tbl}}).exports;
|
||||
|
||||
enableGeckoProfiling();
|
||||
|
@ -233,12 +233,12 @@ for (let type of ['f32', 'f64']) {
|
|||
// Optimized wasm->wasm import.
|
||||
var m1 = new Module(wasmTextToBinary(`(module
|
||||
(func $foo (result i32) (i32.const 42))
|
||||
(export "foo" $foo)
|
||||
(export "foo" (func $foo))
|
||||
)`));
|
||||
var m2 = new Module(wasmTextToBinary(`(module
|
||||
(import $foo "a" "foo" (result i32))
|
||||
(func $bar (result i32) (call $foo))
|
||||
(export "bar" $bar)
|
||||
(export "bar" (func $bar))
|
||||
)`));
|
||||
|
||||
// Instantiate while not active:
|
||||
|
|
|
@ -30,5 +30,5 @@ wasmEvalText(`(module
|
|||
drop
|
||||
drop
|
||||
)
|
||||
(export "run" $run)
|
||||
(export "run" (func $run))
|
||||
)`);
|
||||
|
|
|
@ -12,5 +12,5 @@ wasmEvalText(
|
|||
drop
|
||||
i64.const 2
|
||||
end)
|
||||
(export "run" $run))`
|
||||
(export "run" (func $run)))`
|
||||
);
|
||||
|
|
|
@ -13,4 +13,4 @@ wasmEvalText(`
|
|||
(drop (block (result f64)
|
||||
(drop (br_if 0 (f64.const 1) (f64.eq (f64.const 1) (f64.const 0))))
|
||||
(drop (br 0 (f64.const 2))))))
|
||||
(export "run" $run))`);
|
||||
(export "run" (func $run)))`);
|
||||
|
|
|
@ -6,7 +6,7 @@ var f = wasmEvalText(`(module (func (result i32) (param i32)
|
|||
(block $default
|
||||
(br_table $0 $1 $2 $default (local.get 0))))))
|
||||
(return (i32.const 0)))
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`).exports[""];
|
||||
|
||||
f(0);
|
||||
|
|
|
@ -61,6 +61,6 @@ var o = wasmEvalText(
|
|||
(i32.add (i32.const 29) (i32.const 30))
|
||||
(br_if $b (i32.const 31) (i32.const 1)))))))))))))))))))
|
||||
(return (local.get $v3)))
|
||||
(export "a" 0))`).exports;
|
||||
(export "a" (func 0)))`).exports;
|
||||
|
||||
assertEq(o["a"](), 0xEEFDEADB|0);
|
||||
|
|
|
@ -7,6 +7,6 @@ var src =
|
|||
i32.const 1
|
||||
br_if 0
|
||||
unreachable)
|
||||
(export "run" 0))`;
|
||||
(export "run" (func 0)))`;
|
||||
|
||||
wasmFullPass(src, 0);
|
||||
|
|
|
@ -12,6 +12,6 @@ assertEq(wasmEvalText(`
|
|||
local.get $p
|
||||
br_if 0
|
||||
)
|
||||
(export "f" $f)
|
||||
(export "f" (func $f))
|
||||
)
|
||||
`).exports.f(42), undefined);
|
||||
|
|
|
@ -17,7 +17,7 @@ var m = new Module(wasmTextToBinary(`(module
|
|||
var jsFun = () => 83;
|
||||
var wasmFun = new Instance(
|
||||
new Module(
|
||||
wasmTextToBinary('(module (func (result i32) (i32.const 42)) (export "foo" 0))')
|
||||
wasmTextToBinary('(module (func (result i32) (i32.const 42)) (export "foo" (func 0)))')
|
||||
)
|
||||
).exports.foo;
|
||||
var e1 = new Instance(m, {
|
||||
|
|
|
@ -21,7 +21,7 @@ function f(x, initFunc) {
|
|||
})
|
||||
};
|
||||
try {
|
||||
f('(module (funcnopnop)(export "" 0))',
|
||||
f('(module (funcnopnop)(export "" (func 0)))',
|
||||
function({
|
||||
wasmScript,
|
||||
breakpoints
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { g } = wasmEvalText(`(module (func $f) (export "g" $f))`).exports;
|
||||
const { g } = wasmEvalText(`(module (func $f) (export "g" (func $f)))`).exports;
|
||||
|
||||
function testCaller() {
|
||||
return g.caller;
|
||||
|
|
|
@ -21,7 +21,7 @@ processModule(mod);
|
|||
processModule(mod);
|
||||
|
||||
mod = new WebAssembly.Module(wasmTextToBinary(`
|
||||
(module (export "func_0" $func1) (func $func1))
|
||||
(module (export "func_0" (func $func1)) (func $func1))
|
||||
`));
|
||||
|
||||
processModule(mod);
|
||||
|
|
|
@ -8,7 +8,7 @@ g.eval("(" + function() {
|
|||
o = {};
|
||||
|
||||
let { exports } = wasmEvalText(`
|
||||
(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" $start))
|
||||
(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" (func $start)))
|
||||
`, {
|
||||
"": {
|
||||
inc: function() { o = o.p; }
|
||||
|
|
|
@ -10,7 +10,7 @@ g.eval("(" + function() {
|
|||
let o = {};
|
||||
|
||||
let func = wasmEvalText(`
|
||||
(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" $start))
|
||||
(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" (func $start)))
|
||||
`, { "": { inc: function() { o = o.set; } } }).exports[""];
|
||||
|
||||
assertErrorMessage(func, TypeError, /is undefined/);
|
||||
|
|
|
@ -18,9 +18,9 @@ var letext =`(module
|
|||
(type $type1 (func (param i32) (result i64)))
|
||||
(type $type2 (func (result i32)))
|
||||
(memory 1)
|
||||
(export "store" $func0)
|
||||
(export "load" $func1)
|
||||
(export "assert_0" $func2)
|
||||
(export "store" (func $func0))
|
||||
(export "load" (func $func1))
|
||||
(export "assert_0" (func $func2))
|
||||
(func $func0 (param $var0 i32) (param $var1 i64)
|
||||
local.get $var0
|
||||
local.get $var1
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
wasmFailValidateText(`(module
|
||||
(func (result i32) (param i32)
|
||||
(loop (if (i32.const 0) (br 0)) (local.get 0)))
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`, /unused values not explicitly dropped by end of block/);
|
||||
|
||||
wasmFailValidateText(`(module
|
||||
(func (param i32)
|
||||
(loop (if (i32.const 0) (br 0)) (local.get 0)))
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`, /unused values not explicitly dropped by end of block/);
|
||||
|
||||
wasmFailValidateText(`(module
|
||||
(func (result i32) (param i32)
|
||||
(loop (if (i32.const 0) (br 0)) (drop (local.get 0))))
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`, emptyStackError);
|
||||
|
||||
assertEq(wasmEvalText(`(module
|
||||
(func (result i32) (param i32)
|
||||
(loop (if (i32.const 0) (br 0))) (local.get 0))
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`).exports[""](42), 42);
|
||||
|
||||
wasmEvalText(`(module (func $func$0
|
||||
|
@ -77,7 +77,7 @@ wasmEvalText(`
|
|||
)
|
||||
)
|
||||
|
||||
(export "" 1)
|
||||
(export "" (func 1))
|
||||
)
|
||||
`).exports[""]();
|
||||
|
||||
|
@ -97,7 +97,7 @@ wasmEvalText(`
|
|||
(call 0 (i32.const 42))
|
||||
(br $b (i32.const 10)))))
|
||||
(i32.const 44))))
|
||||
(export "foo" 4))
|
||||
(export "foo" (func 4)))
|
||||
`, {
|
||||
check: {
|
||||
one(x) {
|
||||
|
@ -118,7 +118,7 @@ assertEq(wasmEvalText(`(module (func
|
|||
(i32.const 3)
|
||||
)
|
||||
drop
|
||||
) (export "" 0))`).exports[""](), undefined);
|
||||
) (export "" (func 0)))`).exports[""](), undefined);
|
||||
|
||||
wasmEvalText(`(module (func (result i32)
|
||||
(return (i32.const 0))
|
||||
|
|
|
@ -33,6 +33,6 @@ for (let body of bodies) {
|
|||
br $top
|
||||
end
|
||||
)
|
||||
(export "run" $f)
|
||||
(export "run" (func $f))
|
||||
)`, 42, {}, 42);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
function foo() {
|
||||
var g = newGlobal({sameZoneAs: this});
|
||||
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
|
||||
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
|
||||
}
|
||||
oomTest(foo);
|
||||
|
|
|
@ -10,5 +10,5 @@ assertEq(wasmEvalText(`(module
|
|||
)
|
||||
)
|
||||
)
|
||||
(export "" 0)
|
||||
(export "" (func 0))
|
||||
)`).exports[""](), 121);
|
||||
|
|
|
@ -13,4 +13,4 @@ wasmEvalText(
|
|||
(local.set $var0 (i64.mul (i64.const 2) (local.get $var0))))
|
||||
(tee_local $var0 (i64.add (i64.const 4) (local.get $var0))))
|
||||
(i64.const 1))))
|
||||
(export "" 0))`);
|
||||
(export "" (func 0)))`);
|
||||
|
|
|
@ -5,7 +5,7 @@ g.eval(`(function() {
|
|||
})()`);
|
||||
|
||||
var module = new WebAssembly.Module(wasmTextToBinary(`
|
||||
(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" $start))
|
||||
(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" (func $start)))
|
||||
`));
|
||||
|
||||
var imports = {
|
||||
|
|
|
@ -11,7 +11,7 @@ var m1 = wasmEvalText(
|
|||
)
|
||||
drop
|
||||
)
|
||||
(export "" 0))`).exports[""];
|
||||
(export "" (func 0)))`).exports[""];
|
||||
|
||||
try {
|
||||
m1();
|
||||
|
@ -31,7 +31,7 @@ var m2 = wasmEvalText(
|
|||
)
|
||||
drop
|
||||
)
|
||||
(export "" 0))`).exports[""];
|
||||
(export "" (func 0)))`).exports[""];
|
||||
|
||||
try {
|
||||
m2();
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
wasmEvalText(
|
||||
`(module
|
||||
(type $type0 (func (result i32)))
|
||||
(export "" $func0)
|
||||
(export "" (func $func0))
|
||||
(func $func0 (result i32)
|
||||
(i32.shr_s (i32.const -40) (i32.const 34))))`);
|
||||
|
|
|
@ -11,7 +11,7 @@ assertEq(wasmEvalText(
|
|||
i32.shr_u
|
||||
(i32.const 10000)
|
||||
i32.rem_s)
|
||||
(export "f" 0))`).exports.f(), -1);
|
||||
(export "f" (func 0)))`).exports.f(), -1);
|
||||
|
||||
// Ditto for int64
|
||||
|
||||
|
@ -36,7 +36,7 @@ assertEq(wasmEvalText(
|
|||
i32.shl
|
||||
(i32.const 10000)
|
||||
i32.rem_u)
|
||||
(export "f" 0))`).exports.f(), 7295);
|
||||
(export "f" (func 0)))`).exports.f(), 7295);
|
||||
|
||||
// 0x80000000 is really -0x80000000 so the result of signed division shall be
|
||||
// negative.
|
||||
|
@ -49,7 +49,7 @@ assertEq(wasmEvalText(
|
|||
i32.shr_u
|
||||
(i32.const 10000)
|
||||
i32.div_s)
|
||||
(export "f" 0))`).exports.f(), -214748);
|
||||
(export "f" (func 0)))`).exports.f(), -214748);
|
||||
|
||||
assertEq(wasmEvalText(
|
||||
`(module
|
||||
|
@ -59,7 +59,7 @@ assertEq(wasmEvalText(
|
|||
i32.shr_u
|
||||
(i32.const -10000)
|
||||
i32.div_s)
|
||||
(export "f" 0))`).exports.f(), 214748);
|
||||
(export "f" (func 0)))`).exports.f(), 214748);
|
||||
|
||||
// And the result of unsigned division shall be positive.
|
||||
|
||||
|
@ -71,5 +71,5 @@ assertEq(wasmEvalText(
|
|||
i32.shr_u
|
||||
(i32.const 10000)
|
||||
i32.div_u)
|
||||
(export "f" 0))`).exports.f(), 214748);
|
||||
(export "f" (func 0)))`).exports.f(), 214748);
|
||||
|
||||
|
|
|
@ -49,5 +49,5 @@ assertEq(wasmEvalText(`(module
|
|||
(local.get $l)
|
||||
)
|
||||
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
|
||||
(export "test" 0)
|
||||
(export "test" (func 0))
|
||||
)`).exports["test"](3), 6);
|
||||
|
|
|
@ -6,7 +6,7 @@ wasmEvalText(
|
|||
`(module
|
||||
(func $func0 (result i32) ${locals()}
|
||||
(i32.const 0))
|
||||
(export "" 0))`);
|
||||
(export "" (func 0)))`);
|
||||
|
||||
} catch (e) {
|
||||
// The wasm baseline compiler throws OOM on too-large frames, so
|
||||
|
|
|
@ -23,7 +23,7 @@ wasmFullPass(`(module
|
|||
(i32.add
|
||||
(i32.load (i32.const 65532))
|
||||
(i32.load (i32.const 6553596)))))
|
||||
(export "run" $test)
|
||||
(export "run" (func $test))
|
||||
)`, 111);
|
||||
|
||||
// Grow during import call:
|
||||
|
@ -31,7 +31,7 @@ var exports = wasmEvalText(`(module
|
|||
(import $imp "" "imp")
|
||||
(memory 1)
|
||||
(func $grow (drop (memory.grow (i32.const 99))))
|
||||
(export "grow" $grow)
|
||||
(export "grow" (func $grow))
|
||||
(func $test (result i32)
|
||||
(i32.store (i32.const 0) (i32.const 1))
|
||||
(i32.store (i32.const 65532) (i32.const 10))
|
||||
|
@ -42,7 +42,7 @@ var exports = wasmEvalText(`(module
|
|||
(i32.add
|
||||
(i32.load (i32.const 65532))
|
||||
(i32.load (i32.const 6553596)))))
|
||||
(export "test" $test)
|
||||
(export "test" (func $test))
|
||||
)`, {"":{imp() { exports.grow() }}}).exports;
|
||||
|
||||
setJitCompilerOption("baseline.warmup.trigger", 2);
|
||||
|
@ -59,7 +59,7 @@ var exports1 = wasmEvalText(`(module
|
|||
(i32.store (i32.const 65532) (i32.const 10))
|
||||
(drop (memory.grow (i32.const 99)))
|
||||
(i32.store (i32.const 6553596) (i32.const 100)))
|
||||
(export "grow" $grow)
|
||||
(export "grow" (func $grow))
|
||||
)`, {"":{mem}}).exports;
|
||||
var exports2 = wasmEvalText(`(module
|
||||
(import "" "tbl" (table 1 funcref))
|
||||
|
@ -73,7 +73,7 @@ var exports2 = wasmEvalText(`(module
|
|||
(i32.add
|
||||
(i32.load (i32.const 65532))
|
||||
(i32.load (i32.const 6553596)))))
|
||||
(export "test" $test)
|
||||
(export "test" (func $test))
|
||||
)`, {"":{tbl, mem}}).exports;
|
||||
tbl.set(0, exports1.grow);
|
||||
assertEq(exports2.test(), 111);
|
||||
|
@ -85,13 +85,13 @@ new Int32Array(mem.buffer)[0] = 42;
|
|||
var mod = new Module(wasmTextToBinary(`(module
|
||||
(import "" "mem" (memory 1))
|
||||
(func $gm (param i32) (result i32) (memory.grow (local.get 0)))
|
||||
(export "grow_memory" $gm)
|
||||
(export "grow_memory" (func $gm))
|
||||
(func $cm (result i32) (memory.size))
|
||||
(export "current_memory" $cm)
|
||||
(export "current_memory" (func $cm))
|
||||
(func $ld (param i32) (result i32) (i32.load (local.get 0)))
|
||||
(export "load" $ld)
|
||||
(export "load" (func $ld))
|
||||
(func $st (param i32) (param i32) (i32.store (local.get 0) (local.get 1)))
|
||||
(export "store" $st)
|
||||
(export "store" (func $st))
|
||||
)`));
|
||||
var exp1 = new Instance(mod, {"":{mem}}).exports;
|
||||
var exp2 = new Instance(mod, {"":{mem}}).exports;
|
||||
|
@ -145,8 +145,8 @@ var exports = wasmEvalText(`(module
|
|||
(func $one (result i32) (i32.const 1))
|
||||
(elem (i32.const 0) $one)
|
||||
(func $two (result i32) (i32.const 2))
|
||||
(export "test" $test)
|
||||
(export "two" $two)
|
||||
(export "test" (func $test))
|
||||
(export "two" (func $two))
|
||||
)`, {"":{grow() { exports.tbl.grow(1); exports.tbl.set(1, exports.two) }}}).exports;
|
||||
|
||||
setJitCompilerOption("baseline.warmup.trigger", 2);
|
||||
|
@ -159,7 +159,7 @@ assertEq(exports.tbl.length, 11);
|
|||
var exports1 = wasmEvalText(`(module
|
||||
(import $grow "" "grow")
|
||||
(func $exp (call $grow))
|
||||
(export "exp" $exp)
|
||||
(export "exp" (func $exp))
|
||||
)`, {"":{grow() { exports2.tbl.grow(1); exports2.tbl.set(2, exports2.eleven) }}}).exports;
|
||||
var exports2 = wasmEvalText(`(module
|
||||
(type $v2v (func))
|
||||
|
@ -177,8 +177,8 @@ var exports2 = wasmEvalText(`(module
|
|||
(elem (i32.const 1) $ten)
|
||||
(func $eleven (result i32) (i32.const 11))
|
||||
(export "tbl" table)
|
||||
(export "test" $test)
|
||||
(export "eleven" $eleven)
|
||||
(export "test" (func $test))
|
||||
(export "eleven" (func $eleven))
|
||||
)`, {"":{imp:exports1.exp}}).exports;
|
||||
assertEq(exports2.test(), 21);
|
||||
|
||||
|
@ -186,11 +186,11 @@ assertEq(exports2.test(), 21);
|
|||
|
||||
var src = wasmEvalText(`(module
|
||||
(func $one (result i32) (i32.const 1))
|
||||
(export "one" $one)
|
||||
(export "one" (func $one))
|
||||
(func $two (result i32) (i32.const 2))
|
||||
(export "two" $two)
|
||||
(export "two" (func $two))
|
||||
(func $three (result i32) (i32.const 3))
|
||||
(export "three" $three)
|
||||
(export "three" (func $three))
|
||||
)`).exports;
|
||||
var tbl = new Table({element:"funcref", initial:1});
|
||||
tbl.set(0, src.one);
|
||||
|
@ -199,7 +199,7 @@ var mod = new Module(wasmTextToBinary(`(module
|
|||
(type $v2i (func (result i32)))
|
||||
(table (import "" "tbl") 1 funcref)
|
||||
(func $ci (param i32) (result i32) (call_indirect (type $v2i) (local.get 0)))
|
||||
(export "call_indirect" $ci)
|
||||
(export "call_indirect" (func $ci))
|
||||
)`));
|
||||
var exp1 = new Instance(mod, {"":{tbl}}).exports;
|
||||
var exp2 = new Instance(mod, {"":{tbl}}).exports;
|
||||
|
|
|
@ -63,5 +63,5 @@ wasmFullPass(` (module
|
|||
|
||||
(func $returnVoid)
|
||||
|
||||
(export "run" 0)
|
||||
(export "run" (func 0))
|
||||
)`, 33);
|
||||
|
|
|
@ -15,7 +15,7 @@ assertEq(count, 1);
|
|||
assertEq(Object.keys(exports).length, 0);
|
||||
|
||||
count = 0;
|
||||
exports = wasmEvalText(`(module (import "" "inc") (func $start (call 0)) (start $start) (export "" 0))`, { "":{inc} }).exports;
|
||||
exports = wasmEvalText(`(module (import "" "inc") (func $start (call 0)) (start $start) (export "" (func 0)))`, { "":{inc} }).exports;
|
||||
assertEq(count, 1);
|
||||
assertEq(typeof exports[""], 'function');
|
||||
assertEq(exports[""](), undefined);
|
||||
|
@ -26,7 +26,7 @@ const Module = WebAssembly.Module;
|
|||
const Instance = WebAssembly.Instance;
|
||||
|
||||
count = 0;
|
||||
const m = new Module(wasmTextToBinary('(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" $start))'));
|
||||
const m = new Module(wasmTextToBinary('(module (import $imp "" "inc") (func) (func $start (call $imp)) (start $start) (export "" (func $start)))'));
|
||||
assertEq(count, 0);
|
||||
|
||||
assertErrorMessage(() => new Instance(m), TypeError, /second argument must be an object/);
|
||||
|
|
|
@ -2,7 +2,7 @@ var exp = wasmEvalText(`(module
|
|||
(memory 1)
|
||||
(export "mem" memory)
|
||||
(func $f (result i32) (i32.load (i32.const 0)))
|
||||
(export "f" $f)
|
||||
(export "f" (func $f))
|
||||
)`).exports;
|
||||
|
||||
var ab = exp.mem.buffer;
|
||||
|
|
|
@ -7,7 +7,7 @@ const Instance = WebAssembly.Instance;
|
|||
const Table = WebAssembly.Table;
|
||||
const RuntimeError = WebAssembly.RuntimeError;
|
||||
|
||||
var caller = `(type $v2i (func (result i32))) (func $call (param $i i32) (result i32) (call_indirect (type $v2i) (local.get $i))) (export "call" $call)`
|
||||
var caller = `(type $v2i (func (result i32))) (func $call (param $i i32) (result i32) (call_indirect (type $v2i) (local.get $i))) (export "call" (func $call))`
|
||||
var callee = i => `(func $f${i} (type $v2i) (i32.const ${i}))`;
|
||||
|
||||
// A table should not hold exported functions alive and exported functions
|
||||
|
@ -98,7 +98,7 @@ assertEq(finalizeCount(), 2);
|
|||
|
||||
// Before initialization, a table is not bound to any instance.
|
||||
resetFinalizeCount();
|
||||
var i = wasmEvalText(`(module (func $f0 (result i32) (i32.const 0)) (export "f0" $f0))`);
|
||||
var i = wasmEvalText(`(module (func $f0 (result i32) (i32.const 0)) (export "f0" (func $f0)))`);
|
||||
var t = new Table({initial:4, element:"funcref"});
|
||||
i.edge = makeFinalizeObserver();
|
||||
t.edge = makeFinalizeObserver();
|
||||
|
@ -114,7 +114,7 @@ assertEq(finalizeCount(), 2);
|
|||
// When a Table is created (uninitialized) and then first assigned, it keeps the
|
||||
// first element's Instance alive (as above).
|
||||
resetFinalizeCount();
|
||||
var i = wasmEvalText(`(module (func $f (result i32) (i32.const 42)) (export "f" $f))`);
|
||||
var i = wasmEvalText(`(module (func $f (result i32) (i32.const 42)) (export "f" (func $f)))`);
|
||||
var f = i.exports.f;
|
||||
var t = new Table({initial:1, element:"funcref"});
|
||||
i.edge = makeFinalizeObserver();
|
||||
|
@ -144,8 +144,8 @@ assertEq(finalizeCount(), 3);
|
|||
// Once all of an instance's elements in a Table have been clobbered, the
|
||||
// Instance should not be reachable.
|
||||
resetFinalizeCount();
|
||||
var i1 = wasmEvalText(`(module (func $f1 (result i32) (i32.const 13)) (export "f1" $f1))`);
|
||||
var i2 = wasmEvalText(`(module (func $f2 (result i32) (i32.const 42)) (export "f2" $f2))`);
|
||||
var i1 = wasmEvalText(`(module (func $f1 (result i32) (i32.const 13)) (export "f1" (func $f1)))`);
|
||||
var i2 = wasmEvalText(`(module (func $f2 (result i32) (i32.const 42)) (export "f2" (func $f2)))`);
|
||||
var f1 = i1.exports.f1;
|
||||
var f2 = i2.exports.f2;
|
||||
var t = new Table({initial:2, element:"funcref"});
|
||||
|
@ -194,7 +194,7 @@ var i = wasmEvalText(
|
|||
`(module
|
||||
(import $imp "a" "b" (result i32))
|
||||
(func $f (param i32) (result i32) (call $imp))
|
||||
(export "f" $f)
|
||||
(export "f" (func $f))
|
||||
)`,
|
||||
{a:{b:runTest}}
|
||||
);
|
||||
|
@ -208,7 +208,7 @@ var m = new Module(wasmTextToBinary(`(module
|
|||
(i32.add
|
||||
(i32.const 1)
|
||||
(call_indirect (type $i2i) (local.get $i) (local.get $i))))
|
||||
(export "f" $f)
|
||||
(export "f" (func $f))
|
||||
)`));
|
||||
for (var i = 1; i < N; i++) {
|
||||
var inst = new Instance(m, {a:{b:tbl}});
|
||||
|
|
|
@ -2,8 +2,8 @@ const Module = WebAssembly.Module;
|
|||
const Instance = WebAssembly.Instance;
|
||||
const Table = WebAssembly.Table;
|
||||
|
||||
var i42 = new Instance(new Module(wasmTextToBinary(`(module (func (result i32) (i32.const 42)) (export "f" 0))`)));
|
||||
var i13 = new Instance(new Module(wasmTextToBinary(`(module (func (result i32) (i32.const 13)) (export "f" 0))`)));
|
||||
var i42 = new Instance(new Module(wasmTextToBinary(`(module (func (result i32) (i32.const 42)) (export "f" (func 0)))`)));
|
||||
var i13 = new Instance(new Module(wasmTextToBinary(`(module (func (result i32) (i32.const 13)) (export "f" (func 0)))`)));
|
||||
var t = new Table({element:"funcref", initial:1});
|
||||
t.set(0, i42.exports.f);
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ var tbl = new Table({initial:50, element:"funcref"});
|
|||
assertEq(new Instance(m, {globals:{a:20, table:tbl}}) instanceof Instance, true);
|
||||
assertSegmentFitError(() => new Instance(m, {globals:{a:50, table:tbl}}));
|
||||
|
||||
var caller = `(type $v2i (func (result i32))) (func $call (param $i i32) (result i32) (call_indirect (type $v2i) (local.get $i))) (export "call" $call)`
|
||||
var caller = `(type $v2i (func (result i32))) (func $call (param $i i32) (result i32) (call_indirect (type $v2i) (local.get $i))) (export "call" (func $call))`
|
||||
var callee = i => `(func $f${i} (type $v2i) (i32.const ${i}))`;
|
||||
|
||||
var call = wasmEvalText(`(module (table 10 funcref) ${callee(0)} ${caller})`).exports.call;
|
||||
|
@ -125,14 +125,14 @@ assertEq(tbl.get(0)(), 0);
|
|||
assertEq(tbl.get(1)(), 1);
|
||||
assertEq(tbl.get(2)(), 2);
|
||||
|
||||
var exp1 = wasmEvalText(`(module (table 10 funcref) (export "tbl" table) (elem (i32.const 0) $f0 $f0) ${callee(0)} (export "f0" $f0) ${caller})`).exports
|
||||
var exp1 = wasmEvalText(`(module (table 10 funcref) (export "tbl" table) (elem (i32.const 0) $f0 $f0) ${callee(0)} (export "f0" (func $f0)) ${caller})`).exports
|
||||
assertEq(exp1.tbl.get(0), exp1.f0);
|
||||
assertEq(exp1.tbl.get(1), exp1.f0);
|
||||
assertEq(exp1.tbl.get(2), null);
|
||||
assertEq(exp1.call(0), 0);
|
||||
assertEq(exp1.call(1), 0);
|
||||
assertErrorMessage(() => exp1.call(2), RuntimeError, /indirect call to null/);
|
||||
var exp2 = wasmEvalText(`(module (import "a" "b" (table 10 funcref)) (export "tbl" table) (elem (i32.const 1) $f1 $f1) ${callee(1)} (export "f1" $f1) ${caller})`, {a:{b:exp1.tbl}}).exports
|
||||
var exp2 = wasmEvalText(`(module (import "a" "b" (table 10 funcref)) (export "tbl" table) (elem (i32.const 1) $f1 $f1) ${callee(1)} (export "f1" (func $f1)) ${caller})`, {a:{b:exp1.tbl}}).exports
|
||||
assertEq(exp1.tbl, exp2.tbl);
|
||||
assertEq(exp2.tbl.get(0), exp1.f0);
|
||||
assertEq(exp2.tbl.get(1), exp2.f1);
|
||||
|
@ -145,9 +145,9 @@ assertEq(exp2.call(1), 1);
|
|||
assertEq(exp2.call(2), 1);
|
||||
|
||||
var tbl = new Table({initial:3, element:"funcref"});
|
||||
var e1 = wasmEvalText(`(module (func $f (result i32) (i32.const 42)) (export "f" $f))`).exports;
|
||||
var e2 = wasmEvalText(`(module (func $g (result f32) (f32.const 10)) (export "g" $g))`).exports;
|
||||
var e3 = wasmEvalText(`(module (func $h (result i32) (i32.const 13)) (export "h" $h))`).exports;
|
||||
var e1 = wasmEvalText(`(module (func $f (result i32) (i32.const 42)) (export "f" (func $f)))`).exports;
|
||||
var e2 = wasmEvalText(`(module (func $g (result f32) (f32.const 10)) (export "g" (func $g)))`).exports;
|
||||
var e3 = wasmEvalText(`(module (func $h (result i32) (i32.const 13)) (export "h" (func $h)))`).exports;
|
||||
tbl.set(0, e1.f);
|
||||
tbl.set(1, e2.g);
|
||||
tbl.set(2, e3.h);
|
||||
|
@ -176,7 +176,7 @@ var m = new Module(wasmTextToBinary(`(module
|
|||
(else
|
||||
(local.set $i (i32.sub (local.get $i) (i32.const 1)))
|
||||
(call_indirect (type $i2i) (local.get $i) (local.get $i)))))))
|
||||
(export "call" $call)
|
||||
(export "call" (func $call))
|
||||
)`));
|
||||
var failTime = false;
|
||||
var tbl = new Table({initial:10, element:"funcref"});
|
||||
|
@ -206,7 +206,7 @@ var call = wasmEvalText(`(module
|
|||
(func $b (type $v2i2) (i32.const 1))
|
||||
(func $c (type $i2v))
|
||||
(func $call (param i32) (result i32) (call_indirect (type $v2i1) (local.get 0)))
|
||||
(export "call" $call)
|
||||
(export "call" (func $call))
|
||||
)`).exports.call;
|
||||
assertEq(call(0), 0);
|
||||
assertEq(call(1), 1);
|
||||
|
@ -230,7 +230,7 @@ var call = wasmEvalText(`(module
|
|||
(func $g (type $G) (local.get 13))
|
||||
(func $call (param i32) (result i32)
|
||||
(call_indirect (type $A) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 42) (local.get 0)))
|
||||
(export "call" $call)
|
||||
(export "call" (func $call))
|
||||
)`).exports.call;
|
||||
assertEq(call(0), 42);
|
||||
for (var i = 1; i < 7; i++)
|
||||
|
@ -265,7 +265,7 @@ assertEq(tbl.get(0).foo, 42);
|
|||
(import "a" "m" (memory 1))
|
||||
(type $v2i (func (result i32)))
|
||||
(func $call (param $i i32) (result i32) (i32.add (call_indirect (type $v2i) (local.get $i)) (memory.size)))
|
||||
(export "call" $call))
|
||||
(export "call" (func $call)))
|
||||
`)), {a:{t:g.tbl,m:g.mem}}).exports.call;
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
|
|
|
@ -8,7 +8,7 @@ assertErrorMessage(() => wasmEvalText('(moduler'), SyntaxError, parsingError);
|
|||
assertErrorMessage(() => wasmEvalText('(module (func) (export "a'), SyntaxError, parsingError);
|
||||
assertErrorMessage(() => wasmEvalText('(module (func (local $a i32) (param $b f32)))'), SyntaxError, parsingError);
|
||||
|
||||
assertErrorMessage(() => wasmEvalText('(module (func $a) (func) (export "a" $a) (export "b" $b))'), SyntaxError, /Function label '\$b' not found/);
|
||||
assertErrorMessage(() => wasmEvalText('(module (func $a) (func) (export "a" (func $a)) (export "b" (func $b)))'), SyntaxError, /Function label '\$b' not found/);
|
||||
assertErrorMessage(() => wasmEvalText('(module (import $foo "a" "b") (import $foo "a" "b"))'), SyntaxError, /duplicate function import/);
|
||||
assertErrorMessage(() => wasmEvalText('(module (func $foo) (func $foo))'), SyntaxError, /duplicate function/);
|
||||
assertErrorMessage(() => wasmEvalText('(module (func (param $a i32) (local $a i32)))'), SyntaxError, /duplicate var/);
|
||||
|
|
|
@ -15,8 +15,8 @@ assertErrorMessage(() => validate({ valueOf: () => new ArrayBuffer(65536) }), Er
|
|||
|
||||
assertEq(validate(wasmTextToBinary(`(module)`)), true);
|
||||
|
||||
assertEq(validate(wasmTextToBinary(`(module (export "run" 0))`)), false);
|
||||
assertEq(validate(wasmTextToBinary(`(module (func) (export "run" 0))`)), true);
|
||||
assertEq(validate(wasmTextToBinary(`(module (export "run" (func 0)))`)), false);
|
||||
assertEq(validate(wasmTextToBinary(`(module (func) (export "run" (func 0)))`)), true);
|
||||
|
||||
// Feature-testing proof-of-concept.
|
||||
assertEq(validate(wasmTextToBinary(`(module (memory 1) (func (result i32) (memory.size)))`)), true);
|
||||
|
|
Загрузка…
Ссылка в новой задаче