Backed out 16 changesets (bug 1612534) for spidermonkey build bustages in /builds/worker/workspace/build/src/js/src/wasm/WasmTesting.h CLOSED TREE

Backed out changeset 65b06190327e (bug 1612534)
Backed out changeset 96a3dca92600 (bug 1612534)
Backed out changeset 10b08f0d8d1c (bug 1612534)
Backed out changeset 812aeb578b38 (bug 1612534)
Backed out changeset 1f671f8eb9e4 (bug 1612534)
Backed out changeset 22c65750be93 (bug 1612534)
Backed out changeset 3724851a0720 (bug 1612534)
Backed out changeset d7e96dba0889 (bug 1612534)
Backed out changeset c550399af2a8 (bug 1612534)
Backed out changeset 6ad16f01837d (bug 1612534)
Backed out changeset 7e2f866b6e94 (bug 1612534)
Backed out changeset a72c64deac11 (bug 1612534)
Backed out changeset 3af7b2e5ef1f (bug 1612534)
Backed out changeset 3fc498a2bb3c (bug 1612534)
Backed out changeset f1950c23749c (bug 1612534)
Backed out changeset d2f2c94dca9e (bug 1612534)
This commit is contained in:
Stefan Hindli 2020-03-19 00:03:42 +02:00
Родитель e310487b92
Коммит 8393d12b96
278 изменённых файлов: 10634 добавлений и 14988 удалений

37
Cargo.lock сгенерированный
Просмотреть файл

@ -2127,7 +2127,6 @@ dependencies = [
"mozglue-static",
"mozilla-central-workspace-hack",
"smoosh",
"wasm-rust",
]
[[package]]
@ -2179,12 +2178,6 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
[[package]]
name = "leb128"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a"
[[package]]
name = "libc"
version = "0.2.59"
@ -4675,9 +4668,9 @@ checksum = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
[[package]]
name = "unicode-width"
version = "0.1.7"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
checksum = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
[[package]]
name = "unicode-xid"
@ -4800,38 +4793,12 @@ dependencies = [
"urlencoding",
]
[[package]]
name = "wasm-rust"
version = "0.1.0"
dependencies = [
"wasmparser",
"wat",
]
[[package]]
name = "wasmparser"
version = "0.48.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "073da89bf1c84db000dd68ce660c1b4a08e3a2d28fd1e3394ab9e7abdde4a0f8"
[[package]]
name = "wast"
version = "11.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df4d67ba9266f4fcaf2e8a1afadc5e2a959e51aecc07b1ecbdf85a6ddaf08bde"
dependencies = [
"leb128",
]
[[package]]
name = "wat"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a9400dc1c8512087b2d974b1b9b0a6c4e6e26e7e8acf629e3e351165a1ed301"
dependencies = [
"wast",
]
[[package]]
name = "webdriver"
version = "0.40.2"

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

@ -91,7 +91,7 @@
#include "wasm/WasmJS.h"
#include "wasm/WasmModule.h"
#include "wasm/WasmSignalHandlers.h"
#include "wasm/WasmTesting.h"
#include "wasm/WasmTextToBinary.h"
#include "wasm/WasmTypes.h"
#include "debugger/DebugAPI-inl.h"
@ -917,12 +917,26 @@ static bool WasmTextToBinary(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
bool withOffsets = false;
if (args.hasDefined(1)) {
if (!args[1].isBoolean()) {
ReportUsageErrorASCII(cx, callee,
"Second argument, if present, must be a boolean");
return false;
}
withOffsets = ToBoolean(args[1]);
}
uintptr_t stackLimit = GetNativeStackLimit(cx);
wasm::Bytes bytes;
UniqueChars error;
if (!wasm::TextToBinary(twoByteChars.twoByteChars(), textLen, &bytes,
&error)) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_TEXT_FAIL,
error.get() ? error.get() : "out of memory");
wasm::Uint32Vector offsets;
if (!wasm::TextToBinary(twoByteChars.twoByteChars(), textLen, stackLimit,
&bytes, &offsets, &error)) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
JSMSG_WASM_TEXT_FAIL,
error.get() ? error.get() : "out of memory");
return false;
}
@ -934,38 +948,21 @@ static bool WasmTextToBinary(JSContext* cx, unsigned argc, Value* vp) {
memcpy(binary->as<TypedArrayObject>().dataPointerUnshared(), bytes.begin(),
bytes.length());
args.rval().setObject(*binary);
return true;
}
if (!withOffsets) {
args.rval().setObject(*binary);
return true;
}
static bool WasmCodeOffsets(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
RootedObject callee(cx, &args.callee());
if (!args.requireAtLeast(cx, "wasmCodeOffsets", 1)) {
RootedObject obj(cx, JS_NewPlainObject(cx));
if (!obj) {
return false;
}
if (!args.get(0).isObject()) {
JS_ReportErrorASCII(cx, "argument is not an object");
constexpr unsigned propAttrs = JSPROP_ENUMERATE;
if (!JS_DefineProperty(cx, obj, "binary", binary, propAttrs)) {
return false;
}
SharedMem<uint8_t*> bytes;
size_t byteLength;
JSObject* bufferObject = &args[0].toObject();
JSObject* unwrappedBufferObject = CheckedUnwrapStatic(bufferObject);
if (!unwrappedBufferObject ||
!IsBufferSource(unwrappedBufferObject, &bytes, &byteLength)) {
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr,
JSMSG_WASM_BAD_BUF_ARG);
return false;
}
wasm::Uint32Vector offsets;
wasm::CodeOffsets(bytes.unwrap(), byteLength, &offsets);
RootedObject jsOffsets(cx, JS::NewArrayObject(cx, offsets.length()));
if (!jsOffsets) {
return false;
@ -977,7 +974,11 @@ static bool WasmCodeOffsets(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
}
args.rval().setObject(*jsOffsets);
if (!JS_DefineProperty(cx, obj, "offsets", jsOffsets, propAttrs)) {
return false;
}
args.rval().setObject(*obj);
return true;
}
@ -6714,11 +6715,6 @@ gc::ZealModeHelpText),
"wasmTextToBinary(str)",
" Translates the given text wasm module into its binary encoding."),
JS_FN_HELP("wasmCodeOffsets", WasmCodeOffsets, 1, 0,
"wasmCodeOffsets(binary)",
" Decodes the given wasm binary to find the offsets of every instruction in the"
" code section."),
JS_FN_HELP("wasmExtractCode", WasmExtractCode, 1, 0,
"wasmExtractCode(module[, tier])",
" Extracts generated machine code from WebAssembly.Module. The tier is a string,\n"

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

@ -24,7 +24,6 @@ const startId = 8;
const elemId = 9;
const codeId = 10;
const dataId = 11;
const dataCountId = 12;
const gcFeatureOptInId = 42;
// User-defined section names
@ -342,12 +341,6 @@ function dataSection(segmentArrays) {
return { name: dataId, body };
}
function dataCountSection(count) {
var body = [];
body.push(...varU32(count));
return { name: dataCountId, body };
}
function elemSection(elemArrays) {
var body = [];
body.push(...varU32(elemArrays.length));

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

@ -65,9 +65,9 @@ const unusedValuesError = /unused values not explicitly dropped by end of block/
function jsify(wasmVal) {
if (wasmVal === 'nan')
return NaN;
if (wasmVal === 'inf')
if (wasmVal === 'infinity')
return Infinity;
if (wasmVal === '-inf')
if (wasmVal === '-infinity')
return Infinity;
if (wasmVal === '-0')
return -0;

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

@ -158,13 +158,13 @@ assertEq(g(), 0);
if (wasmIsSupported()) {
var h = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`(module
(import "imp" "f" (func $f (param i32) (result i32)))
(import $f "imp" "f" (param i32) (result i32))
(func $h (result i32) (call $f (i32.const 1)))
(export "h" (func $h))
(export "h" $h)
)`)), {imp:{f}}).exports.h;
assertEq(h(), 0);
var i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`(module (func $i) (export "i" (func $i)))`))).exports.i
var i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`(module (func $i) (export "i" $i))`))).exports.i
var j = asmLink(asmCompile('glob', 'ffis', USE_ASM + 'var i = ffis.i; function j() { return i(1)|0; } return j'), null, {i});
assertEq(j(), 0);
}

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

@ -14,5 +14,5 @@ dbg.onNewScript = (script) => {
g.eval(`(() => {})()`);
assertEq(gotScript.format, "js");
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
assertEq(gotScript.format, "wasm");

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

@ -6,5 +6,5 @@ var dbg = new Debugger(g);
dbg.onNewScript = (function(script) {
s = script;
})
g.eval(`new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
s.source;

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

@ -5,7 +5,7 @@ if (!wasmDebuggingIsSupported())
let module = new WebAssembly.Module(wasmTextToBinary(`
(module
(import "global" "func" (func))
(import "global" "func")
(func (export "test")
call 0 ;; calls the import, which is func #0
)

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

@ -11,14 +11,14 @@ g.eval("Debugger(parent).onExceptionUnwind = function () {};");
let module = new WebAssembly.Module(wasmTextToBinary(`
(module
(import "a" "b" (func $imp (result i32)))
(import $imp "a" "b" (result i32))
(memory 1 1)
(table 2 2 anyfunc)
(elem (i32.const 0) $imp $def)
(func $def (result i32) (i32.load (i32.const 0)))
(type $v2i (func (result i32)))
(func $call (param i32) (result i32) (call_indirect (type $v2i) (get_local 0)))
(export "call" (func $call))
(func $call (param i32) (result i32) (call_indirect $v2i (get_local 0)))
(export "call" $call)
)
`));

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

@ -5,7 +5,7 @@ if (!wasmDebuggingIsSupported())
var module = new WebAssembly.Module(wasmTextToBinary(`
(module
(import "global" "func" (func (result i32)))
(import "global" "func" (result i32))
(func (export "func_0") (result i32)
call 0 ;; calls the import, which is func #0
)

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

@ -3,7 +3,7 @@
// Tests that wasm module scripts are available via findScripts.
var g = newGlobal({newCompartment: true});
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
function isWasm(script) { return script.format === "wasm"; }
@ -13,7 +13,7 @@ assertEq(foundScripts1.length, 1);
var found = foundScripts1[0];
// Add another module, we should be able to find it via findScripts.
g.eval(`o2 = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "a" (func 0)))')));`);
g.eval(`o2 = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "a" 0))')));`);
var foundScripts2 = dbg.findScripts().filter(isWasm);
assertEq(foundScripts2.length, 2);

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

@ -10,11 +10,11 @@ dbg.onNewScript = (script) => {
gotScript = script;
}
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
assertEq(gotScript.format, "wasm");
var gotScript2 = gotScript;
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "a" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "a" 0))')));`);
assertEq(gotScript.format, "wasm");
// The two wasm Debugger.Scripts are distinct.

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

@ -12,7 +12,7 @@ dbg.onNewScript = (script) => {
s = script;
}
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
assertEq(s.format, "wasm");
var source = s.source;

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

@ -12,7 +12,7 @@ dbg.onNewScript = (script) => {
s = script;
}
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
assertEq(s.format, "wasm");
assertThrowsInstanceOf(() => s.displayName, Error);

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

@ -26,7 +26,7 @@ var m = new WebAssembly.Instance(new WebAssembly.Module(wasm), lib);`);
// of the frame and environment properties.
var onEnterFrameCalled, onLeaveFrameCalled, onExceptionUnwindCalled, testComplete;
runWasmWithDebugger(
'(module (func (result i32) (i32.const 42)) (export "test" (func 0)))', undefined,
'(module (func (result i32) (i32.const 42)) (export "test" 0))', undefined,
function (dbg) {
var wasmScript = dbg.findScripts().filter(s => s.format == 'wasm')[0];
assertEq(!!wasmScript, true);
@ -73,7 +73,7 @@ runWasmWithDebugger(
// Checking the dbg.getNewestFrame() and frame.older.
runWasmWithDebugger(
'(module (import "env" "ex" (func $fn1)) (func $fn2 (call $fn1)) (export "test" (func $fn2)))',
'(module (import $fn1 "env" "ex") (func $fn2 (call $fn1)) (export "test" $fn2))',
'{env: { ex: () => { }}}',
function (dbg) {
onEnterFrameCalled = 0;
@ -115,7 +115,7 @@ runWasmWithDebugger(
// Checking if we can enumerate frames and find 'wasmcall' one.
runWasmWithDebugger(
'(module (import "env" "ex" (func $fn1)) (func $fn2 (call $fn1)) (export "test" (func $fn2)))',
'(module (import $fn1 "env" "ex") (func $fn2 (call $fn1)) (export "test" $fn2))',
'{env: { ex: () => { debugger; }}}',
function (dbg) {
testComplete = false;
@ -135,7 +135,7 @@ runWasmWithDebugger(
// Checking if onPop works without onEnterFrame handler.
runWasmWithDebugger(
'(module (import "env" "ex" (func $fn1)) (func $fn2 (call $fn1)) (export "test" (func $fn2)))',
'(module (import $fn1 "env" "ex") (func $fn2 (call $fn1)) (export "test" $fn2))',
'{env: { ex: () => { debugger; }}}',
function (dbg) {
onLeaveFrameCalled = 0;
@ -155,7 +155,7 @@ runWasmWithDebugger(
// Checking if function return values are not changed.
runWasmWithDebugger(
'(module (func (result f64) (f64.const 0.42)) (export "test" (func 0)))', undefined,
'(module (func (result f64) (f64.const 0.42)) (export "test" 0))', undefined,
function (dbg) {
dbg.onEnterFrame = function (frame) {
dbg.onPop = function () {};
@ -167,7 +167,7 @@ runWasmWithDebugger(
}
);
runWasmWithDebugger(
'(module (func (result f32) (f32.const 4.25)) (export "test" (func 0)))', undefined,
'(module (func (result f32) (f32.const 4.25)) (export "test" 0))', undefined,
function (dbg) {
dbg.onEnterFrame = function (frame) {
dbg.onPop = function () {};
@ -182,7 +182,7 @@ runWasmWithDebugger(
// Checking if onEnterFrame/onExceptionUnwind work during exceptions --
// `unreachable` causes wasm to throw WebAssembly.RuntimeError exception.
runWasmWithDebugger(
'(module (func (unreachable)) (export "test" (func 0)))', undefined,
'(module (func (unreachable)) (export "test" 0))', undefined,
function (dbg) {
onEnterFrameCalled = 0;
onLeaveFrameCalled = 0;
@ -210,7 +210,7 @@ runWasmWithDebugger(
// Checking if onEnterFrame/onExceptionUnwind work during exceptions
// originated in the JavaScript import call.
runWasmWithDebugger(
'(module (import "env" "ex" (func $fn1)) (func $fn2 (call $fn1)) (export "test" (func $fn2)))',
'(module (import $fn1 "env" "ex") (func $fn2 (call $fn1)) (export "test" $fn2))',
'{env: { ex: () => { throw new Error(); }}}',
function (dbg) {
onEnterFrameCalled = 0;
@ -238,7 +238,7 @@ runWasmWithDebugger(
// Checking throwing in the handler.
runWasmWithDebugger(
'(module (func (unreachable)) (export "test" (func 0)))', undefined,
'(module (func (unreachable)) (export "test" 0))', undefined,
function (dbg) {
dbg.uncaughtExceptionHook = function (value) {
assertEq(value instanceof Error, true);
@ -254,7 +254,7 @@ runWasmWithDebugger(
}
);
runWasmWithDebugger(
'(module (func (unreachable)) (export "test" (func 0)))', undefined,
'(module (func (unreachable)) (export "test" 0))', undefined,
function (dbg) {
dbg.uncaughtExceptionHook = function (value) {
assertEq(value instanceof Error, true);
@ -274,7 +274,7 @@ runWasmWithDebugger(
// Checking resumption values for JS_THROW.
runWasmWithDebugger(
'(module (func (nop)) (export "test" (func 0)))', undefined,
'(module (func (nop)) (export "test" 0))', undefined,
function (dbg, g) {
dbg.onEnterFrame = function (frame) {
if (frame.type !== "wasmcall") return;
@ -286,7 +286,7 @@ runWasmWithDebugger(
}
);
runWasmWithDebugger(
'(module (func (nop)) (export "test" (func 0)))', undefined,
'(module (func (nop)) (export "test" 0))', undefined,
function (dbg, g) {
dbg.onEnterFrame = function (frame) {
if (frame.type !== "wasmcall") return;
@ -302,7 +302,7 @@ runWasmWithDebugger(
// Checking resumption values for JS_RETURN (not implemented by wasm baseline).
runWasmWithDebugger(
'(module (func (unreachable)) (export "test" (func 0)))', undefined,
'(module (func (unreachable)) (export "test" 0))', undefined,
function (dbg) {
dbg.onEnterFrame = function (frame) {
if (frame.type !== "wasmcall") return;
@ -315,7 +315,7 @@ runWasmWithDebugger(
}
);
runWasmWithDebugger(
'(module (func (unreachable)) (export "test" (func 0)))', undefined,
'(module (func (unreachable)) (export "test" 0))', undefined,
function (dbg) {
dbg.onEnterFrame = function (frame) {
if (frame.type !== "wasmcall") return;

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

@ -8,7 +8,7 @@ load(libdir + "wasm.js");
var offsets;
wasmRunWithDebugger(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
undefined,
function ({dbg}) {
offsets = [];

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

@ -47,7 +47,7 @@ function monitorLocalValues(wast, lib, expected) {
}
monitorLocalValues(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
undefined,
[{}]
);

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

@ -6,8 +6,8 @@ var g = newGlobal({newCompartment: true});
var dbg = new Debugger(g);
g.eval(`
function initWasm(s) { return new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(s))); }
o1 = initWasm('(module (func) (export "" (func 0)))');
o2 = initWasm('(module (func) (func) (export "" (func 1)))');
o1 = initWasm('(module (func) (export "" 0))');
o2 = initWasm('(module (func) (func) (export "" 1))');
`);
function isWasm(script) { return script.format === "wasm"; }

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

@ -13,7 +13,7 @@ dbg.onNewScript = (script) => {
s = script;
}
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
assertEq(s.format, "wasm");
var source = s.source;
@ -21,7 +21,7 @@ var source = s.source;
// The text is never generated with the native Debugger API.
assertEq(source.text.includes('module'), false);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" 0))')));`);
assertEq(s.format, "wasm");
var source2 = s.source;
@ -29,4 +29,4 @@ var source2 = s.source;
// The text is predefined if wasm binary sources are enabled.
assertEq(source2.text, '[debugger missing wasm binary-to-text conversion]');
// The binary contains Uint8Array which is equal to wasm bytecode;
arraysEqual(source2.binary, wasmTextToBinary('(module (func) (export "" (func 0)))'));
arraysEqual(source2.binary, wasmTextToBinary('(module (func) (export "" 0))'));

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

@ -8,12 +8,10 @@ function runTest(wast, initFunc, doneFunc) {
let dbg = new Debugger(g);
g.eval(`
var b = wasmTextToBinary('${wast}');
var m = new WebAssembly.Instance(new WebAssembly.Module(b));
var breakpoints = wasmCodeOffsets(b);
`);
var { binary, offsets } = wasmTextToBinary('${wast}', /* offsets */ true);
var m = new WebAssembly.Instance(new WebAssembly.Module(binary));`);
var { breakpoints } = g;
var { offsets } = g;
var wasmScript = dbg.findScripts().filter(s => s.format == 'wasm')[0];
@ -21,7 +19,7 @@ var breakpoints = wasmCodeOffsets(b);
dbg,
wasmScript,
g,
breakpoints
breakpoints: offsets
});
let result, error;
@ -45,9 +43,8 @@ var onBreakpointCalled;
// Checking if we can stop at specified breakpoint.
runTest(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
function ({wasmScript, breakpoints}) {
print(`${JSON.stringify(breakpoints)}`);
assertEq(breakpoints.length, 3);
assertEq(breakpoints[0] > 0, true);
// Checking if breakpoints offsets are in ascending order.
@ -71,7 +68,7 @@ runTest(
// Checking if we can remove breakpoint one by one.
runTest(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
function ({wasmScript, breakpoints}) {
onBreakpointCalled = 0;
var handlers = [];
@ -94,7 +91,7 @@ runTest(
// Checking if we can remove breakpoint one by one from a breakpoint handler.
runTest(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
function ({wasmScript, breakpoints}) {
onBreakpointCalled = 0;
var handlers = [];
@ -119,7 +116,7 @@ runTest(
// but onStep will still work.
var onStepCalled;
runTest(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
function ({dbg, wasmScript, breakpoints}) {
onBreakpointCalled = 0;
onStepCalled = [];
@ -151,7 +148,7 @@ runTest(
// Checking if we can remove all breakpoints.
runTest(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
function ({wasmScript, breakpoints}) {
onBreakpointCalled = 0;
breakpoints.forEach(function (offset, i) {
@ -173,7 +170,7 @@ runTest(
// Checking if breakpoints are removed after debugger has been detached.
runTest(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
function ({dbg, wasmScript, g, breakpoints}) {
onBreakpointCalled = 0;
breakpoints.forEach(function (offset, i) {

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

@ -8,7 +8,7 @@ wasmRunWithDebugger(
(global (mut f64) (f64.const 0.5))\
(global f32 (f32.const 3.5))\
(func (param i32) (local f64) (f64.const 1.0) (tee_local 1) (set_global 0) (nop))\
(export "test" (func 0))\
(export "test" 0)\
(data (i32.const 0) "Abc\\x2A"))',
undefined,
function ({dbg}) {

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

@ -13,7 +13,7 @@ dbg.onExceptionUnwind = (frame, value) => {
sandbox.innerCode = wasmTextToBinary(`(module
(import "imports" "tbl" (table 1 anyfunc))
(import "imports" "setNull" (func $setNull))
(import $setNull "imports" "setNull" (func))
(func $trap
call $setNull
unreachable
@ -25,7 +25,7 @@ sandbox.outerCode = wasmTextToBinary(`(module
(type $v2v (func))
(func (export "run")
i32.const 0
call_indirect (type $v2v)
call_indirect $v2v
)
)`);

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

@ -52,12 +52,12 @@ function appendSourceMappingURL(wasmBytes, url) {
g.toWasm = (wast, url) => appendSourceMappingURL(wasmTextToBinary(wast), url);
// The sourceMappingURL section is not present
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "" 0))')));`);
assertEq(gotScript.format, "wasm");
assertEq(gotScript.source.sourceMapURL, null);
// The sourceMappingURL section is present
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "a" (func 0)))', 'http://example.org/test')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "a" 0))', 'http://example.org/test')));`);
assertEq(gotScript.format, "wasm");
assertEq(gotScript.source.sourceMapURL, 'http://example.org/test');
@ -67,6 +67,6 @@ assertThrowsInstanceOf(() => gotScript.source.sourceMapURL = 'foo', Error);
// The sourceMappingURL section is present, and is still available when wasm
// binary source is disabled.
dbg.allowWasmBinarySource = false;
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "a" (func 0)))', 'http://example.org/test2')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "a" 0))', 'http://example.org/test2')));`);
assertEq(gotScript.format, "wasm");
assertEq(gotScript.source.sourceMapURL, 'http://example.org/test2');

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

@ -7,7 +7,7 @@ load(libdir + "wasm.js");
// Checking if we stop at every wasm instruction during step.
var onEnterFrameCalled, onLeaveFrameCalled, onStepCalled;
wasmRunWithDebugger(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
undefined,
function ({dbg}) {
onEnterFrameCalled = 0;
@ -38,7 +38,7 @@ wasmRunWithDebugger(
// Checking if step mode was disabled after debugger has been detached.
wasmRunWithDebugger(
'(module (func (nop) (nop)) (export "test" (func 0)))',
'(module (func (nop) (nop)) (export "test" 0))',
undefined,
function ({dbg, g}) {
onEnterFrameCalled = 0;

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

@ -10,19 +10,19 @@ let SHARED = 'shared';
let UNSHARED = '';
let sharedError = 'memory with atomic operations without shared memory';
for (let [type,width,view] of [['i32','8', '_u'],['i32','16','_u'],['i32','',''],['i64','8','_u'],['i64','16','_u'],['i64','32','_u'],['i64','','']]) {
for (let [type,view] of [['i32','8_u'],['i32','16_u'],['i32',''],['i64','8_u'],['i64','16_u'],['i64','32_u'],['i64','']]) {
{
let text = (shared) => `(module (memory 1 1 ${shared})
(func (result ${type}) (${type}.atomic.load${width}${view} (i32.const 0)))
(export "" (func 0)))`;
(func (result ${type}) (${type}.atomic.load${view} (i32.const 0)))
(export "" 0))`;
assertEq(valText(text(SHARED)), true);
assertEq(valText(text(UNSHARED)), false);
}
{
let text = (shared) => `(module (memory 1 1 ${shared})
(func (${type}.atomic.store${width} (i32.const 0) (${type}.const 1)))
(export "" (func 0)))`;
(func (${type}.atomic.store${view} (i32.const 0) (${type}.const 1)))
(export "" 0))`;
assertEq(valText(text(SHARED)), true);
assertEq(valText(text(UNSHARED)), false);
}
@ -30,8 +30,8 @@ for (let [type,width,view] of [['i32','8', '_u'],['i32','16','_u'],['i32','','']
{
let text = (shared) => `(module (memory 1 1 ${shared})
(func (result ${type})
(${type}.atomic.rmw${width}.cmpxchg${view} (i32.const 0) (${type}.const 1) (${type}.const 2)))
(export "" (func 0)))`;
(${type}.atomic.rmw${view}.cmpxchg (i32.const 0) (${type}.const 1) (${type}.const 2)))
(export "" 0))`;
assertEq(valText(text(SHARED)), true);
assertEq(valText(text(UNSHARED)), false);
}
@ -39,8 +39,8 @@ for (let [type,width,view] of [['i32','8', '_u'],['i32','16','_u'],['i32','','']
for (let op of ['add','and','or','sub','xor','xchg']) {
// Operate with appropriately-typed value 1 on address 0
let text = (shared) => `(module (memory 1 1 ${shared})
(func (result ${type}) (${type}.atomic.rmw${width}.${op}${view} (i32.const 0) (${type}.const 1)))
(export "" (func 0)))`;
(func (result ${type}) (${type}.atomic.rmw${view}.${op} (i32.const 0) (${type}.const 1)))
(export "" 0))`;
assertEq(valText(text(SHARED)), true);
assertEq(valText(text(UNSHARED)), false);
@ -50,16 +50,19 @@ for (let [type,width,view] of [['i32','8', '_u'],['i32','16','_u'],['i32','','']
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 "" (func 0)))`;
(export "" 0))`;
assertEq(valText(text(SHARED)), true);
assertEq(valText(text(UNSHARED)), false);
}
let text = (shared) => `(module (memory 1 1 ${shared})
(func (result i32) (atomic.notify (i32.const 0) (i32.const 1)))
(export "" (func 0)))`;
assertEq(valText(text(SHARED)), true);
assertEq(valText(text(UNSHARED)), false);
// 'wake' remains a backwards-compatible alias for 'notify'
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))`;
assertEq(valText(text(SHARED)), true);
assertEq(valText(text(UNSHARED)), false);
}
// Required explicit alignment for WAIT is the size of the datum
@ -68,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 "" (func 0)))`;
(export "" 0))`;
assertEq(valText(text), good);
}
@ -77,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 "" (func 0)))`;
(export "" 0))`;
assertEq(valText(text), align == 4);
}
@ -165,14 +168,14 @@ function widen(TA, value, complement = true) {
var RMWOperation =
{
loadStoreModule(type, width, view, address, operand) {
loadStoreModule(type, view, address, operand) {
let bin = wasmTextToBinary(
`(module
(memory (import "" "memory") 1 1 shared)
(func (export "st") (param i32)
(${type}.atomic.store${width} ${address} ${operand}))
(${type}.atomic.store${view} ${address} ${operand}))
(func $ld (param i32) (result ${type})
(${type}.atomic.load${width}${view} ${address}))
(${type}.atomic.load${view} ${address}))
(func (export "ld") (param i32) (result i32)
(${type}.eq (call $ld (local.get 0)) ${operand})))`);
let mod = new WebAssembly.Module(bin);
@ -181,12 +184,12 @@ var RMWOperation =
return [mem, ins.exports.ld, ins.exports.st];
},
opModuleEffect(type, width, view, address, op, operand, ignored) {
opModuleEffect(type, view, address, op, operand, ignored) {
let bin = wasmTextToBinary(
`(module
(memory (import "" "memory") 1 1 shared)
(func (export "f") (param i32) (result i32)
(drop (${type}.atomic.rmw${width}.${op}${view} ${address} ${operand}))
(drop (${type}.atomic.rmw${view}.${op} ${address} ${operand}))
(i32.const 1)))`);
let mod = new WebAssembly.Module(bin);
let mem = new WebAssembly.Memory({initial: 1, maximum: 1, shared: true});
@ -194,12 +197,12 @@ var RMWOperation =
return [mem, ins.exports.f];
},
opModuleReturned(type, width, view, address, op, operand, expected) {
opModuleReturned(type, view, address, op, operand, expected) {
let bin = wasmTextToBinary(
`(module
(memory (import "" "memory") 1 1 shared)
(func $_f (param i32) (result ${type})
(${type}.atomic.rmw${width}.${op}${view} ${address} ${operand}))
(${type}.atomic.rmw${view}.${op} ${address} ${operand}))
(func (export "f") (param i32) (result i32)
(${type}.eq (call $_f (local.get 0)) (${type}.const ${expected}))))`);
let mod = new WebAssembly.Module(bin);
@ -208,24 +211,24 @@ var RMWOperation =
return [mem, ins.exports.f];
},
cmpxchgModuleEffect(type, width, view, address, operand1, operand2, ignored) {
cmpxchgModuleEffect(type, view, address, operand1, operand2, ignored) {
let bin = wasmTextToBinary(
`(module
(memory (import "" "memory") 1 1 shared)
(func (export "f") (param i32)
(drop (${type}.atomic.rmw${width}.cmpxchg${view} ${address} ${operand1} ${operand2}))))`);
(drop (${type}.atomic.rmw${view}.cmpxchg ${address} ${operand1} ${operand2}))))`);
let mod = new WebAssembly.Module(bin);
let mem = new WebAssembly.Memory({initial: 1, maximum: 1, shared: true});
let ins = new WebAssembly.Instance(mod, {"": {memory: mem}});
return [mem, ins.exports.f];
},
cmpxchgModuleReturned(type, width, view, address, operand1, operand2, expected) {
cmpxchgModuleReturned(type, view, address, operand1, operand2, expected) {
let bin = wasmTextToBinary(
`(module
(memory (import "" "memory") 1 1 shared)
(func $_f (param i32) (result ${type})
(${type}.atomic.rmw${width}.cmpxchg${view} ${address} ${operand1} ${operand2}))
(${type}.atomic.rmw${view}.cmpxchg ${address} ${operand1} ${operand2}))
(func (export "f") (param i32) (result i32)
(${type}.eq (call $_f (local.get 0)) (${type}.const ${expected}))))`);
let mod = new WebAssembly.Module(bin);
@ -247,10 +250,10 @@ var RMWOperation =
const OPD2 = 42; // Sometimes we'll put another operand here
for ( let [type, variations] of
[["i32", [[Uint8Array,"8", "_u"], [Uint16Array,"16", "_u"], [Uint32Array,"",""]]],
["i64", [[Uint8Array,"8","_u"], [Uint16Array,"16","_u"], [Uint32Array,"32","_u"], [Uint64Array,"",""]]]] )
[["i32", [[Uint8Array,"8_u"], [Uint16Array,"16_u"], [Uint32Array,""]]],
["i64", [[Uint8Array,"8_u"], [Uint16Array,"16_u"], [Uint32Array,"32_u"], [Uint64Array,""]]]] )
{
for ( let [TA, width, view] of variations )
for ( let [TA, view] of variations )
{
for ( let addr of [`(i32.const ${LOC * TA.BYTES_PER_ELEMENT})`,
`(local.get 0)`] )
@ -259,9 +262,9 @@ var RMWOperation =
{
let [opd_str, opd_num] = widen(TA, operand);
for ( let rhs of [`(${type}.const ${opd_str})`,
`(${type}.load${width}${view} (i32.const ${OPD1 * TA.BYTES_PER_ELEMENT}))`] )
`(${type}.load${view} (i32.const ${OPD1 * TA.BYTES_PER_ELEMENT}))`] )
{
let [mem, ld, st] = this.loadStoreModule(type, width, view, addr, rhs);
let [mem, ld, st] = this.loadStoreModule(type, view, addr, rhs);
let array = new TA(mem.buffer);
array.write(OPD1, opd_num);
array.write(LOC, initial);
@ -286,11 +289,11 @@ var RMWOperation =
let [opd_str, opd_num] = widen(TA, operand, complement);
let [exp_str, exp_num] = widen(TA, expected, complement);
for ( let rhs of [`(${type}.const ${opd_str})`,
`(${type}.load${width}${view} (i32.const ${OPD1 * TA.BYTES_PER_ELEMENT}))`] )
`(${type}.load${view} (i32.const ${OPD1 * TA.BYTES_PER_ELEMENT}))`] )
{
for ( let [generateIt, checkIt] of [["opModuleEffect", false], ["opModuleReturned", true]] )
{
let [mem, f] = this[generateIt](type, width, view, addr, op, rhs, ini_str);
let [mem, f] = this[generateIt](type, view, addr, op, rhs, ini_str);
let array = new TA(mem.buffer);
array.write(OPD1, opd_num);
array.write(LOC, ini_num);
@ -311,14 +314,14 @@ var RMWOperation =
let [opd2_str, opd2_num] = widen(TA, operand2);
let [exp_str, exp_num] = widen(TA, expected);
for ( let op1 of [`(${type}.const ${opd1_str})`,
`(${type}.load${width}${view} (i32.const ${OPD1 * TA.BYTES_PER_ELEMENT}))`] )
`(${type}.load${view} (i32.const ${OPD1 * TA.BYTES_PER_ELEMENT}))`] )
{
for ( let op2 of [`(${type}.const ${opd2_str})`,
`(${type}.load${width}${view} (i32.const ${OPD2 * TA.BYTES_PER_ELEMENT}))`] )
`(${type}.load${view} (i32.const ${OPD2 * TA.BYTES_PER_ELEMENT}))`] )
{
for ( let [generateIt, checkIt] of [["cmpxchgModuleEffect", false], ["cmpxchgModuleReturned", true]] )
{
let [mem, f] = this[generateIt](type, width, view, addr, op1, op2, ini_str);
let [mem, f] = this[generateIt](type, view, addr, op1, op2, ini_str);
let array = new TA(mem.buffer);
array.write(OPD1, opd1_num);
array.write(OPD2, opd2_num);
@ -361,71 +364,71 @@ function assertNum(a, b) {
var BoundsAndAlignment =
{
loadModule(type, view, width, offset) {
loadModule(type, ext, offset) {
return wasmEvalText(
`(module
(memory 1 1 shared)
(func $0 (param i32) (result ${type})
(${type}.atomic.load${width}${view} offset=${offset} (local.get 0)))
(${type}.atomic.load${ext} offset=${offset} (local.get 0)))
(func (export "f") (param i32)
(drop (call $0 (local.get 0)))))
`).exports.f;
},
loadModuleIgnored(type, view, width, offset) {
loadModuleIgnored(type, ext, offset) {
return wasmEvalText(
`(module
(memory 1 1 shared)
(func (export "f") (param i32)
(drop (${type}.atomic.load${width}${view} offset=${offset} (local.get 0)))))
(drop (${type}.atomic.load${ext} offset=${offset} (local.get 0)))))
`).exports.f;
},
storeModule(type, view, width, offset) {
storeModule(type, ext, offset) {
return wasmEvalText(
`(module
(memory 1 1 shared)
(func (export "f") (param i32)
(${type}.atomic.store${width} offset=${offset} (local.get 0) (${type}.const 37))))
(${type}.atomic.store${ext} offset=${offset} (local.get 0) (${type}.const 37))))
`).exports.f;
},
opModule(type, view, width, offset, op) {
opModule(type, ext, offset, op) {
return wasmEvalText(
`(module
(memory 1 1 shared)
(func $0 (param i32) (result ${type})
(${type}.atomic.rmw${width}.${op}${view} offset=${offset} (local.get 0) (${type}.const 37)))
(${type}.atomic.rmw${ext}.${op} offset=${offset} (local.get 0) (${type}.const 37)))
(func (export "f") (param i32)
(drop (call $0 (local.get 0)))))
`).exports.f;
},
opModuleForEffect(type, view, width, offset, op) {
opModuleForEffect(type, ext, offset, op) {
return wasmEvalText(
`(module
(memory 1 1 shared)
(func (export "f") (param i32)
(drop (${type}.atomic.rmw${width}.${op}${view} offset=${offset} (local.get 0) (${type}.const 37)))))
(drop (${type}.atomic.rmw${ext}.${op} offset=${offset} (local.get 0) (${type}.const 37)))))
`).exports.f;
},
cmpxchgModule(type, view, width, offset) {
cmpxchgModule(type, ext, offset) {
return wasmEvalText(
`(module
(memory 1 1 shared)
(func $0 (param i32) (result ${type})
(${type}.atomic.rmw${width}.cmpxchg${view} offset=${offset} (local.get 0) (${type}.const 37) (${type}.const 42)))
(${type}.atomic.rmw${ext}.cmpxchg offset=${offset} (local.get 0) (${type}.const 37) (${type}.const 42)))
(func (export "f") (param i32)
(drop (call $0 (local.get 0)))))
`).exports.f;
},
run() {
for ( let [type, variations] of [["i32", [["8","_u", 1], ["16","_u", 2], ["","", 4]]],
["i64", [["8","_u",1], ["16","_u",2], ["32","_u",4], ["","",8]]]] )
for ( let [type, variations] of [["i32", [["8_u", 1], ["16_u", 2], ["", 4]]],
["i64", [["8_u",1], ["16_u",2], ["32_u",4], ["",8]]]] )
{
for ( let [width,view,size] of variations )
for ( let [ext,size] of variations )
{
// Aligned but out-of-bounds
let addrs = [[65536, 0, oob], [65536*2, 0, oob], [65532, 4, oob],
@ -448,14 +451,14 @@ var BoundsAndAlignment =
for ( let [ base, offset, re ] of addrs )
{
assertErrorMessage(() => this.loadModule(type, view, width, offset)(base), RuntimeError, re);
assertErrorMessage(() => this.loadModuleIgnored(type, view, width, offset)(base), RuntimeError, re);
assertErrorMessage(() => this.storeModule(type, view, width, offset)(base), RuntimeError, re);
assertErrorMessage(() => this.loadModule(type, ext, offset)(base), RuntimeError, re);
assertErrorMessage(() => this.loadModuleIgnored(type, ext, offset)(base), RuntimeError, re);
assertErrorMessage(() => this.storeModule(type, ext, offset)(base), RuntimeError, re);
for ( let op of [ "add", "sub", "and", "or", "xor", "xchg" ]) {
assertErrorMessage(() => this.opModule(type, view, width, offset, op)(base), RuntimeError, re);
assertErrorMessage(() => this.opModuleForEffect(type, view, width, offset, op)(base), RuntimeError, re);
assertErrorMessage(() => this.opModule(type, ext, offset, op)(base), RuntimeError, re);
assertErrorMessage(() => this.opModuleForEffect(type, ext, offset, op)(base), RuntimeError, re);
}
assertErrorMessage(() => this.cmpxchgModule(type, view, width, offset)(base), RuntimeError, re);
assertErrorMessage(() => this.cmpxchgModule(type, ext, offset)(base), RuntimeError, re);
}
}
}
@ -469,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 "" (func 0)))`).exports[""](65536),
(export "" 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 "" (func 0)))`).exports[""](65536),
(export "" 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 "" (func 0)))`).exports[""](65501),
(export "" 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 "" (func 0)))`).exports[""](65501),
(export "" 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 "" (func 0)))`).exports[""](65536),
(export "" 0))`).exports[""](65536),
RuntimeError, oob);
// Minimum run-time alignment for NOTIFY is 4
@ -511,7 +514,7 @@ assertErrorMessage(() => wasmEvalText(`(module
(func (export "main")
i32.const 1
i32.const 2816
i32.atomic.rmw16.xchg_u align=2
i32.atomic.rmw16_u.xchg align=2
i32.load16_s offset=83 align=1
drop
)

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

@ -194,8 +194,7 @@ function makeModule(id) {
return ((val << (pos * VALSHIFT)) + 0x100000000).toString(16).substring(1);
}
let width = bits < 32 ? '' + bits : '';
let view = bits < 32 ? '_u' : '';
let tag = bits < 32 ? bits + '_u' : '';
let prefix = bits == 64 ? 'i64' : 'i32';
return `
(func ${name} (param $barrierValue i32) (result i32)
@ -206,7 +205,7 @@ function makeModule(id) {
(if (local.get $n)
(block
${isMaster ? `;; Init
(${prefix}.atomic.store${width} ${loc} (${prefix}.const ${distribute(initial)}))` : ``}
(${prefix}.atomic.store${tag} ${loc} (${prefix}.const ${distribute(initial)}))` : ``}
${barrier}
${(() => {
@ -217,7 +216,7 @@ ${(() => {
// we would avoid fences in that case.
if (op.match(/cmpxchg/)) {
s += `(loop $doit
(local.set $tmp (${prefix}.atomic.load${width}${view} ${loc}))
(local.set $tmp (${prefix}.atomic.load${tag} ${loc}))
(br_if $doit (i32.eqz
(${prefix}.eq
(local.get $tmp)
@ -231,7 +230,7 @@ ${(() => {
return s
})()}
(loop $wait_done
(br_if $wait_done (${prefix}.ne (${prefix}.atomic.load${width}${view} ${loc}) (${prefix}.const ${distribute(expected)}))))
(br_if $wait_done (${prefix}.ne (${prefix}.atomic.load${tag} ${loc}) (${prefix}.const ${distribute(expected)}))))
${barrier}
(local.set $n (i32.sub (local.get $n) (i32.const 1)))
(br $outer))))
@ -271,21 +270,21 @@ ${(() => {
return `
(module
(import "" "memory" (memory 1 1 shared))
(import "" "print" (func $print (param i32)))
(import $print "" "print" (param i32))
${makeLoop(8, "$test_add8", "i32.atomic.rmw8.add_u", ADDLOC, ADDINIT, ADDVAL[id], ADDRESULT)}
${makeLoop(8, "$test_sub8", "i32.atomic.rmw8.sub_u", SUBLOC, SUBINIT, SUBVAL[id], SUBRESULT)}
${makeLoop(8, "$test_and8", "i32.atomic.rmw8.and_u", ANDLOC, ANDINIT, ANDVAL[id], ANDRESULT)}
${makeLoop(8, "$test_or8", "i32.atomic.rmw8.or_u", ORLOC, ORINIT, ORVAL[id], ORRESULT)}
${makeLoop(8, "$test_xor8", "i32.atomic.rmw8.xor_u", XORLOC, XORINIT, XORVAL[id], XORRESULT)}
${makeLoop(8, "$test_cmpxchg8", "i32.atomic.rmw8.cmpxchg_u", CMPXCHGLOC, CMPXCHGINIT, CMPXCHGVAL[id], CMPXCHGRESULT)}
${makeLoop(8, "$test_add8", "i32.atomic.rmw8_u.add", ADDLOC, ADDINIT, ADDVAL[id], ADDRESULT)}
${makeLoop(8, "$test_sub8", "i32.atomic.rmw8_u.sub", SUBLOC, SUBINIT, SUBVAL[id], SUBRESULT)}
${makeLoop(8, "$test_and8", "i32.atomic.rmw8_u.and", ANDLOC, ANDINIT, ANDVAL[id], ANDRESULT)}
${makeLoop(8, "$test_or8", "i32.atomic.rmw8_u.or", ORLOC, ORINIT, ORVAL[id], ORRESULT)}
${makeLoop(8, "$test_xor8", "i32.atomic.rmw8_u.xor", XORLOC, XORINIT, XORVAL[id], XORRESULT)}
${makeLoop(8, "$test_cmpxchg8", "i32.atomic.rmw8_u.cmpxchg", CMPXCHGLOC, CMPXCHGINIT, CMPXCHGVAL[id], CMPXCHGRESULT)}
${makeLoop(16, "$test_add16", "i32.atomic.rmw16.add_u", ADDLOC, ADDINIT, ADDVAL[id], ADDRESULT)}
${makeLoop(16, "$test_sub16", "i32.atomic.rmw16.sub_u", SUBLOC, SUBINIT, SUBVAL[id], SUBRESULT)}
${makeLoop(16, "$test_and16", "i32.atomic.rmw16.and_u", ANDLOC, ANDINIT, ANDVAL[id], ANDRESULT)}
${makeLoop(16, "$test_or16", "i32.atomic.rmw16.or_u", ORLOC, ORINIT, ORVAL[id], ORRESULT)}
${makeLoop(16, "$test_xor16", "i32.atomic.rmw16.xor_u", XORLOC, XORINIT, XORVAL[id], XORRESULT)}
${makeLoop(16, "$test_cmpxchg16", "i32.atomic.rmw16.cmpxchg_u", CMPXCHGLOC, CMPXCHGINIT, CMPXCHGVAL[id], CMPXCHGRESULT)}
${makeLoop(16, "$test_add16", "i32.atomic.rmw16_u.add", ADDLOC, ADDINIT, ADDVAL[id], ADDRESULT)}
${makeLoop(16, "$test_sub16", "i32.atomic.rmw16_u.sub", SUBLOC, SUBINIT, SUBVAL[id], SUBRESULT)}
${makeLoop(16, "$test_and16", "i32.atomic.rmw16_u.and", ANDLOC, ANDINIT, ANDVAL[id], ANDRESULT)}
${makeLoop(16, "$test_or16", "i32.atomic.rmw16_u.or", ORLOC, ORINIT, ORVAL[id], ORRESULT)}
${makeLoop(16, "$test_xor16", "i32.atomic.rmw16_u.xor", XORLOC, XORINIT, XORVAL[id], XORRESULT)}
${makeLoop(16, "$test_cmpxchg16", "i32.atomic.rmw16_u.cmpxchg", CMPXCHGLOC, CMPXCHGINIT, CMPXCHGVAL[id], CMPXCHGRESULT)}
${makeLoop(32, "$test_add", "i32.atomic.rmw.add", ADDLOC, ADDINIT, ADDVAL[id], ADDRESULT)}
${makeLoop(32, "$test_sub", "i32.atomic.rmw.sub", SUBLOC, SUBINIT, SUBVAL[id], SUBRESULT)}

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

@ -1,7 +1,7 @@
var code = `(module
(import "env" "test" (func $i))
(import $i "env" "test")
(func $t (call $i))
(export "test" (func $t))
(export "test" $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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))`).exports["f"];
(export "f" 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" (func 0)))').exports;
var o = wasmEvalText('(module (func) (export "a" 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" (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)))');
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))');
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/);
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/);
var o = wasmEvalText('(module (func) (export "a" (func 0)) (export "b" (func 0)))').exports;
var o = wasmEvalText('(module (func) (export "a" 0) (export "b" 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" (func 0)) (export "b" (func 1)))').exports;
var o = wasmEvalText('(module (func) (func) (export "a" 0) (export "b" 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" (func 0)) (export "b" (func 1)))').exports;
var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" 0) (export "b" 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" (func 1)) (export "b" (func 0)))').exports;
var o = wasmEvalText('(module (func (result i32) (i32.const 1)) (func (result i32) (i32.const 2)) (export "a" 1) (export "b" 0))').exports;
assertEq(o.a(), 2);
assertEq(o.b(), 1);
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/);
wasmFailValidateText('(module (func) (export "a" 0) (export "a" 0))', /duplicate export/);
wasmFailValidateText('(module (func) (func) (export "a" 0) (export "a" 1))', /duplicate export/);
// ----------------------------------------------------------------------------
// signatures
@ -63,7 +63,7 @@ wasmValidateText('(module (func (nop)))');
wasmValidateText('(module (func (result i32) (i32.const 42)))');
wasmValidateText('(module (func (param i32)))');
wasmValidateText('(module (func (param i32) (result i32) (i32.const 42)))');
wasmValidateText('(module (func (param i32) (result i32) (i32.const 42)))');
wasmValidateText('(module (func (result i32) (param i32) (i32.const 42)))');
wasmValidateText('(module (func (param f32)))');
wasmValidateText('(module (func (param f64)))');
@ -82,13 +82,13 @@ wasmFullPassI64('(module (func $run (param i64) (result i64) (i64.add (local.get
const noImportObj = "second argument must be an object";
assertErrorMessage(() => wasmEvalText('(module (import "a" "b" (func)))', 1), TypeError, noImportObj);
assertErrorMessage(() => wasmEvalText('(module (import "a" "b" (func)))', null), TypeError, noImportObj);
assertErrorMessage(() => wasmEvalText('(module (import "a" "b"))', 1), TypeError, noImportObj);
assertErrorMessage(() => wasmEvalText('(module (import "a" "b"))', null), TypeError, noImportObj);
const notObject = /import object field '\w*' is not an Object/;
const notFunction = /import object field '\w*' is not a Function/;
var code = '(module (import "a" "b" (func)))';
var code = '(module (import "a" "b"))';
assertErrorMessage(() => wasmEvalText(code), TypeError, noImportObj);
assertErrorMessage(() => wasmEvalText(code, {}), TypeError, notObject);
assertErrorMessage(() => wasmEvalText(code, {a:1}), TypeError, notObject);
@ -96,23 +96,23 @@ assertErrorMessage(() => wasmEvalText(code, {a:{}}), LinkError, notFunction);
assertErrorMessage(() => wasmEvalText(code, {a:{b:1}}), LinkError, notFunction);
wasmEvalText(code, {a:{b:()=>{}}});
var code = '(module (import "" "b" (func)))';
var code = '(module (import "" "b"))';
wasmEvalText(code, {"":{b:()=>{}}});
var code = '(module (import "a" "" (func)))';
var code = '(module (import "a" ""))';
assertErrorMessage(() => wasmEvalText(code), TypeError, noImportObj);
assertErrorMessage(() => wasmEvalText(code, {}), TypeError, notObject);
assertErrorMessage(() => wasmEvalText(code, {a:1}), TypeError, notObject);
wasmEvalText(code, {a:{"":()=>{}}});
var code = '(module (import "a" "" (func)) (import "b" "c" (func)) (import "c" "" (func)))';
var code = '(module (import "a" "") (import "b" "c") (import "c" ""))';
assertErrorMessage(() => wasmEvalText(code, {a:()=>{}, b:{c:()=>{}}, c:{}}), LinkError, notFunction);
wasmEvalText(code, {a:{"":()=>{}}, b:{c:()=>{}}, c:{"":()=>{}}});
wasmEvalText('(module (import "a" "" (func (result i32))))', {a:{"":()=>{}}});
wasmEvalText('(module (import "a" "" (func (result f32))))', {a:{"":()=>{}}});
wasmEvalText('(module (import "a" "" (func (result f64))))', {a:{"":()=>{}}});
wasmEvalText('(module (import "a" "" (func $foo (result f64))))', {a:{"":()=>{}}});
wasmEvalText('(module (import "a" "" (result i32)))', {a:{"":()=>{}}});
wasmEvalText('(module (import "a" "" (result f32)))', {a:{"":()=>{}}});
wasmEvalText('(module (import "a" "" (result f64)))', {a:{"":()=>{}}});
wasmEvalText('(module (import $foo "a" "" (result f64)))', {a:{"":()=>{}}});
// ----------------------------------------------------------------------------
// memory
@ -132,11 +132,11 @@ try {
assertEq(String(e).indexOf("out of memory") !== -1, true);
}
var buf = wasmEvalText('(module (memory 1) (export "memory" (memory 0)))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (export "memory" memory))').exports.memory.buffer;
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 0)) (export "b" (func 0)) (export "c" (func 1)))').exports;
var obj = wasmEvalText('(module (memory 1) (func (result i32) (i32.const 42)) (func (nop)) (export "memory" memory) (export "b" 0) (export "c" 1))').exports;
assertEq(obj.memory.buffer instanceof ArrayBuffer, true);
assertEq(obj.b instanceof Function, true);
assertEq(obj.c instanceof Function, true);
@ -144,44 +144,44 @@ assertEq(obj.memory.buffer.byteLength, 65536);
assertEq(obj.b(), 42);
assertEq(obj.c(), undefined);
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "") (export "memory" (memory 0)))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 0);
var buf = wasmEvalText('(module (memory 1) (data (i32.const 65536) "") (export "memory" (memory 0)))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 65536) "") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 0);
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "a") (export "memory" (memory 0)))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "a") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "a") (data (i32.const 2) "b") (export "memory" (memory 0)))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "a") (data (i32.const 2) "b") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));
assertEq(new Uint8Array(buf)[1], 0);
assertEq(new Uint8Array(buf)[2], 'b'.charCodeAt(0));
var buf = wasmEvalText('(module (memory 1) (data (i32.const 65535) "c") (export "memory" (memory 0)))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 65535) "c") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 0);
assertEq(new Uint8Array(buf)[65535], 'c'.charCodeAt(0));
// ----------------------------------------------------------------------------
// locals
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);
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);
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"));
wasmFailValidateText('(module (func (result i32) (local f32) (local.get 0)))', mismatchError("f32", "i32"));
wasmFailValidateText('(module (func (param i32) (result f32) (local f32) (local.get 0)))', mismatchError("i32", "f32"));
wasmFailValidateText('(module (func (param i32) (result i32) (local f32) (local.get 1)))', mismatchError("f32", "i32"));
wasmFailValidateText('(module (func (result f32) (param i32) (local f32) (local.get 0)))', mismatchError("i32", "f32"));
wasmFailValidateText('(module (func (result i32) (param i32) (local f32) (local.get 1)))', mismatchError("f32", "i32"));
wasmValidateText('(module (func (local i32)))');
wasmValidateText('(module (func (local i32) (local f32)))');
wasmFullPass('(module (func (result i32) (local i32) (local.get 0)) (export "run" (func 0)))', 0);
wasmFullPass('(module (func (param i32) (result i32) (local f32) (local.get 0)) (export "run" (func 0)))', 0);
wasmFullPass('(module (func (param i32) (result f32) (local f32) (local.get 1)) (export "run" (func 0)))', 0);
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);
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" (func 0)))', 42);
wasmFullPass('(module (func (result i32) (local i32) (tee_local 0 (local.get 0))) (export "run" (func 0)))', 0);
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 (param $a i32) (result i32) (local.get $a)) (export "run" (func 0)))', 0);
wasmFullPass('(module (func (param $a i32) (result i32) (local $b i32) (block (result i32) (local.set $b (local.get $a)) (local.get $b))) (export "run" (func 0)))', 42, {}, 42);
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 i32 (local.set $b (local.get $a)) (local.get $b))) (export "run" 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" (func 0)))', undefined);
wasmFullPass('(module (func (block )) (export "run" 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" (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 (block (block ))) (export "run" 0))', undefined);
wasmFullPass('(module (func (result i32) (block i32 (i32.const 42))) (export "run" 0))', 42);
wasmFullPass('(module (func (result i32) (block i32 (block i32 (i32.const 42)))) (export "run" 0))', 42);
wasmFailValidateText('(module (func (result f32) (block 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" (func 0)))', 42);
wasmFailValidateText('(module (func (param f32) (result f32) (block (result i32) (drop (local.get 0)) (i32.const 0))))', mismatchError("i32", "f32"));
wasmFullPass('(module (func (result i32) (block i32 (drop (i32.const 13)) (block i32 (i32.const 42)))) (export "run" 0))', 42);
wasmFailValidateText('(module (func (result f32) (param f32) (block 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" (func 0)))', 42);
wasmFullPass('(module (func (result i32) (local i32) (local.set 0 (i32.const 42)) (local.get 0)) (export "run" 0))', 42);
// ----------------------------------------------------------------------------
// calls
@ -232,26 +232,26 @@ 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" (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);
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);
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"));
wasmFailValidateText('(module (import "a" "" (func)) (func (call 0 (i32.const 0))))', unusedValuesError);
wasmFailValidateText('(module (import "a" "" (func (param i32))) (func (call 0)))', emptyStackError);
wasmFailValidateText('(module (import "a" "" (func (param f32))) (func (call 0 (i32.const 0))))', mismatchError("i32", "f32"));
wasmFailValidateText('(module (import "a" "") (func (call 0 (i32.const 0))))', unusedValuesError);
wasmFailValidateText('(module (import "a" "" (param i32)) (func (call 0)))', emptyStackError);
wasmFailValidateText('(module (import "a" "" (param f32)) (func (call 0 (i32.const 0))))', mismatchError("i32", "f32"));
assertErrorMessage(() => wasmEvalText('(module (import "a" "" (func)) (func (call 1)))'), TypeError, noImportObj);
wasmEvalText('(module (import "" "a" (func)) (func (call 0)))', {"":{a:()=>{}}});
wasmEvalText('(module (import "" "a" (func (param i32))) (func (call 0 (i32.const 0))))', {"":{a:()=>{}}});
assertErrorMessage(() => wasmEvalText('(module (import "a" "") (func (call 1)))'), TypeError, noImportObj);
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" (func (result f32))) (func (result f32) (call 0)) (export "run" (func 1)))',
wasmFullPass('(module (import "" "a" (result f32)) (func (result f32) (call 0)) (export "run" 1))',
Math.fround(v),
{"":{a:()=>{ return v; }}});
wasmFullPass('(module (import "" "a" (func (param f32))) (func (param f32) (call 0 (local.get 0))) (export "run" (func 1)))',
wasmFullPass('(module (import "" "a" (param f32)) (func (param f32) (call 0 (local.get 0))) (export "run" 1))',
undefined,
{"":{a:x=>{ assertEq(Math.fround(v), x); }}},
v);
@ -263,33 +263,33 @@ checkF32CallImport(-0);
checkF32CallImport(Math.pow(2, 32) - 1);
var counter = 0;
var f = wasmEvalText('(module (import "" "inc" (func)) (func (call 0)) (export "" (func 1)))', {"":{inc:()=>counter++}}).exports[""];
var g = wasmEvalText('(module (import "" "f" (func)) (func (block (call 0) (call 0))) (export "" (func 1)))', {"":{f}}).exports[""];
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[""];
f();
assertEq(counter, 1);
g();
assertEq(counter, 3);
var f = wasmEvalText('(module (import "" "callf" (func)) (func (call 0)) (export "" (func 1)))', {"":{callf:()=>f()}}).exports[""];
var f = wasmEvalText('(module (import "" "callf") (func (call 0)) (export "" 1))', {"":{callf:()=>f()}}).exports[""];
assertThrowsInstanceOf(() => f(), InternalError);
var f = wasmEvalText('(module (import "" "callg" (func)) (func (call 0)) (export "" (func 1)))', {"":{callg:()=>g()}}).exports[""];
var g = wasmEvalText('(module (import "" "callf" (func)) (func (call 0)) (export "" (func 1)))', {"":{callf:()=>f()}}).exports[""];
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[""];
assertThrowsInstanceOf(() => f(), InternalError);
var code = '(module (import "" "one" (func (result i32))) (import "" "two" (func (result i32))) (func (result i32) (i32.const 3)) (func (result i32) (i32.const 4)) (func (result i32) BODY) (export "run" (func 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" 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" (func (param i32) (result i32))) (func (result i32) (call 0 (i32.const 0))) (export "run" (func 1)))`, 0, {"":{evalcx}});
wasmFullPass(`(module (import "" "evalcx" (param i32) (result i32)) (func (result i32) (call 0 (i32.const 0))) (export "run" 1))`, 0, {"":{evalcx}});
if (typeof evaluate === 'function')
evaluate(`new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module)'))) `, { fileName: null });
wasmFailValidateText(`(module (type $t (func)) (func (call_indirect (type $t) (i32.const 0))))`, /can't call_indirect without a table/);
wasmFailValidateText(`(module (type $t (func)) (func (call_indirect $t (i32.const 0))))`, /can't call_indirect without a table/);
var {v2i, i2i, i2v} = wasmEvalText(`(module
(type (func (result i32)))
@ -302,12 +302,12 @@ var {v2i, i2i, i2v} = wasmEvalText(`(module
(func (type 1) (i32.add (local.get 0) (i32.const 3)))
(func (type 1) (i32.add (local.get 0) (i32.const 4)))
(table funcref (elem 0 1 2 3 4 5))
(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" (func 6))
(export "i2i" (func 7))
(export "i2v" (func 8))
(func (param i32) (result i32) (call_indirect 0 (local.get 0)))
(func (param i32) (param i32) (result i32) (call_indirect 1 (local.get 1) (local.get 0)))
(func (param i32) (call_indirect 2 (i32.const 0) (local.get 0)))
(export "v2i" 6)
(export "i2i" 7)
(export "i2v" 8)
)`).exports;
const signatureMismatch = /indirect call signature mismatch/;
@ -340,12 +340,12 @@ assertErrorMessage(() => i2v(5), Error, signatureMismatch);
wasmFullPass(
`(module
(type $v2v (func))
(import "" "f" (func $foo))
(import $foo "" "f")
(func $a (call $foo))
(func $b (result i32) (i32.const 0))
(table funcref (elem $a $b))
(func $bar (call_indirect (type $v2v) (i32.const 0)))
(export "run" (func $bar))
(func $bar (call_indirect $v2v (i32.const 0)))
(export "run" $bar)
)`,
undefined,
{"":{f:() => { stack = new Error().stack }}}
@ -368,20 +368,20 @@ for (bad of [6, 7, 100, Math.pow(2,31)-1, Math.pow(2,31), Math.pow(2,31)+1, Math
wasmValidateText('(module (func $foo (nop)) (func (call $foo)))');
wasmValidateText('(module (func (call $foo)) (func $foo (nop)))');
wasmValidateText('(module (import "" "a" (func $bar)) (func (call $bar)) (func $foo (nop)))');
wasmValidateText('(module (import $bar "" "a") (func (call $bar)) (func $foo (nop)))');
// ----------------------------------------------------------------------------
// select
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 "" (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);
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 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);
(function testSideEffects() {
@ -396,16 +396,16 @@ var imports = {"": {
// Test that side-effects are applied on both branches.
var f = wasmEvalText(`
(module
(import "" "ifTrue" (func (result i32)))
(import "" "ifFalse" (func (result i32)))
(func (param i32) (result i32)
(import "" "ifTrue" (result i32))
(import "" "ifFalse" (result i32))
(func (result i32) (param i32)
(select
(call 0)
(call 1)
(local.get 0)
)
)
(export "" (func 2))
(export "" 2)
)
`, imports).exports[""];
@ -443,14 +443,14 @@ function testSelect(type, trueVal, falseVal) {
// Always true condition
var alwaysTrue = wasmEvalText(`
(module
(func (param i32) (result ${type})
(func (result ${type}) (param i32)
(select
(${type}.const ${trueVal})
(${type}.const ${falseVal})
(i32.const 1)
)
)
(export "" (func 0))
(export "" 0)
)
`, imports).exports[""];
@ -461,14 +461,14 @@ function testSelect(type, trueVal, falseVal) {
// Always false condition
var alwaysFalse = wasmEvalText(`
(module
(func (param i32) (result ${type})
(func (result ${type}) (param i32)
(select
(${type}.const ${trueVal})
(${type}.const ${falseVal})
(i32.const 0)
)
)
(export "" (func 0))
(export "" 0)
)
`, imports).exports[""];
@ -479,14 +479,14 @@ function testSelect(type, trueVal, falseVal) {
// Variable condition
var f = wasmEvalText(`
(module
(func (param i32) (result ${type})
(func (result ${type}) (param i32)
(select
(${type}.const ${trueVal})
(${type}.const ${falseVal})
(local.get 0)
)
)
(export "" (func 0))
(export "" 0)
)
`, imports).exports[""];
@ -496,14 +496,14 @@ function testSelect(type, trueVal, falseVal) {
wasmFullPass(`
(module
(func (param i32) (result ${type})
(func (result ${type}) (param i32)
(select
(${type}.const ${trueVal})
(${type}.const ${falseVal})
(local.get 0)
)
)
(export "run" (func 0))
(export "run" 0)
)`,
trueJS,
imports,
@ -514,23 +514,23 @@ testSelect('i32', 13, 37);
testSelect('i32', Math.pow(2, 31) - 1, -Math.pow(2, 31));
testSelect('f32', Math.fround(13.37), Math.fround(19.89));
testSelect('f32', 'inf', '-0');
testSelect('f32', 'infinity', '-0');
testSelect('f32', 'nan', Math.pow(2, -31));
testSelect('f64', 13.37, 19.89);
testSelect('f64', 'inf', '-0');
testSelect('f64', 'infinity', '-0');
testSelect('f64', 'nan', Math.pow(2, -31));
wasmAssert(`
(module
(func $f (param i32) (result i64)
(func $f (result i64) (param i32)
(select
(i64.const 0xc0010ff08badf00d)
(i64.const 0x12345678deadc0de)
(local.get 0)
)
)
(export "" (func 0))
(export "" 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 "" (func 0)))`
) (export "" 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 "" (func 0)))`
) (export "" 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 "" (func 0)))`
) (export "" 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" (func $test))
(export "run" $test)
)`, 42);

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

@ -111,8 +111,8 @@ function testManyArgs() {
function testImportExport() {
var f1 = wasmEvalText(
`(module
(import "i64" "func" (func (param i64)))
(export "f" (func 0))
(import "i64" "func" (param i64))
(export "f" 0)
)`,
{
i64: {
@ -125,8 +125,8 @@ function testImportExport() {
var f2 = wasmEvalText(
`(module
(import "i64" "func" (func (param i64) (result i64)))
(export "f" (func 0))
(import "i64" "func" (param i64) (result i64))
(export "f" 0)
)`,
{
i64: {
@ -139,7 +139,7 @@ function testImportExport() {
var f3 = wasmEvalText(
`(module
(import "" "i64" (func $i64 (param i64) (result i64)))
(import $i64 "" "i64" (param i64) (result i64))
(func (export "f") (param i64) (result i64)
(get_local 0)
(call $i64))
@ -155,8 +155,8 @@ function testImportExport() {
var f4 = wasmEvalText(
`(module
(import "i64" "func" (func (result i64)))
(export "f" (func 0))
(import "i64" "func" (result i64))
(export "f" 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 "" (func 0)))').exports[""];
var f = wasmEvalText('(module (func (param i64) (result i32) (i32.const 123)) (export "" 0))').exports[""];
assertErrorMessage(f, TypeError, /i64/);
var f = wasmEvalText('(module (func (param i32) (result i64) (i64.const 123)) (export "" (func 0)))').exports[""];
var f = wasmEvalText('(module (func (param i32) (result i64) (i64.const 123)) (export "" 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 "" (func $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 "" $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 "" (func $f)))', {a:{b:()=>{}}}).exports[""];
var f = wasmEvalText('(module (import $imp "a" "b" (result i64)) (func $f (result i64) (call $imp)) (export "" $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" (func 0)))', { i64: { func() {} } }).exports;
i = wasmEvalText('(module (import "i64" "func" (param i64)) (export "f" 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" (func 0)))', { i64: { func() {} } }).exports;
i = wasmEvalText('(module (import "i64" "func" (param i32) (param i64)) (export "f" 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" (func 0)))', { i64: { func() {} } }).exports;
i = wasmEvalText('(module (import "i64" "func" (result i64)) (export "f" 0))', { i64: { func() {} } }).exports;
assertErrorMessage(() => i.f({ valueOf() { sideEffect = true; return 42; } }), TypeError, 'cannot pass i64 to or from JS');
assertEq(sideEffect, false);

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

@ -52,11 +52,11 @@
ex = wasmEvalText(
`(module
(import "a" "ffi" (func $ffi (param i64) (result i64)))
(import "a" "ffi2" (func $ffi2
(import $ffi "a" "ffi" (param i64) (result i64))
(import $ffi2 "a" "ffi2"
(param i64 i32 i32 i32 i32 i32 i32)
(result i64)))
(import "a" "ffi3" (func $ffi3 (param i64 i64 i64 i64) (result i64)))
(result i64))
(import $ffi3 "a" "ffi3" (param i64 i64 i64 i64) (result i64))
(func (export "callffi") (param i64) (result i64)
local.get 0

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

@ -13,8 +13,8 @@ function unary(name) {
let f64 = Math[name];
let i = wasmEvalText(`(module
(import "math" "func" (func $f32 (param f32) (result f32)))
(import "math" "func" (func $f64 (param f64) (result f64)))
(import $f32 "math" "func" (param f32) (result f32))
(import $f64 "math" "func" (param f64) (result f64))
(table $t 10 funcref)
(type $f_f (func (param f32) (result f32)))
@ -28,7 +28,7 @@ function unary(name) {
(func (export "f32_t") (param f32) (result f32)
local.get 0
i32.const 0
call_indirect (type $f_f)
call_indirect $f_f
)
(func (export "f64") (param f64) (result f64)
local.get 0
@ -37,7 +37,7 @@ function unary(name) {
(func (export "f64_t") (param f64) (result f64)
local.get 0
i32.const 1
call_indirect (type $d_d)
call_indirect $d_d
)
)`, imports).exports;
@ -62,8 +62,8 @@ function binary(name) {
let f64 = Math[name];
let i = wasmEvalText(`(module
(import "math" "func" (func $f32 (param f32) (param f32) (result f32)))
(import "math" "func" (func $f64 (param f64) (param f64) (result f64)))
(import $f32 "math" "func" (param f32) (param f32) (result f32))
(import $f64 "math" "func" (param f64) (param f64) (result f64))
(table $t 10 funcref)
(type $ff_f (func (param f32) (param f32) (result f32)))
@ -79,7 +79,7 @@ function binary(name) {
local.get 0
local.get 1
i32.const 0
call_indirect (type $ff_f)
call_indirect $ff_f
)
(func (export "f64") (param f64) (param f64) (result f64)
local.get 0
@ -90,7 +90,7 @@ function binary(name) {
local.get 0
local.get 1
i32.const 1
call_indirect (type $dd_d)
call_indirect $dd_d
)
)`, imports).exports;

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

@ -71,7 +71,7 @@ testCached(
(func $t4 (type $T) (i32.const 40))
(table funcref (elem $t1 $t2 $t3 $t4))
(func (export "run") (param i32) (result i32)
(call_indirect (type $T) (local.get 0))))`,
(call_indirect $T (local.get 0))))`,
{'':{ t1() { return 10 }, t2() { return 20 } }},
i => {
assertEq(i.exports.run(0), 10);

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

@ -1,5 +1,5 @@
// sanity check
assertErrorMessage(() => wasmEvalText(''), SyntaxError, /wasm text error/);
assertErrorMessage(() => wasmEvalText(''), SyntaxError, /parsing wasm text/);
// single line comment
var o = wasmEvalText('(module (func)) ;; end');
@ -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" (func 0)))').exports;
var o = wasmEvalText('(module (func) ;; middle\n (export "a" 0))').exports;
assertEq(Object.getOwnPropertyNames(o)[0], "a");
// multi-line comments
@ -18,14 +18,14 @@ 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" (func 0)))').exports;
var o = wasmEvalText('(module (func)(;middle;)(export "a" 0))').exports;
assertEq(Object.getOwnPropertyNames(o)[0], "a");
// nested comments
var o = wasmEvalText('(module (;nested(;comment;);)(func (;;;;)))');
var o = wasmEvalText(';;;;;;;;;;\n(module ;;(;n \n(func (;\n;;;)))');
assertErrorMessage(() => wasmEvalText(';; only comment'), SyntaxError, /wasm text error/);
assertErrorMessage(() => wasmEvalText(';; only comment\n'), SyntaxError, /wasm text error/);
assertErrorMessage(() => wasmEvalText('(; only comment ;)'), SyntaxError, /wasm text error/);
assertErrorMessage(() => wasmEvalText(';; only comment\n'), SyntaxError, /wasm text error/);
assertErrorMessage(() => wasmEvalText(';; only comment'), SyntaxError, /parsing wasm text/);
assertErrorMessage(() => wasmEvalText(';; only comment\n'), SyntaxError, /parsing wasm text/);
assertErrorMessage(() => wasmEvalText('(; only comment ;)'), SyntaxError, /parsing wasm text/);
assertErrorMessage(() => wasmEvalText(';; only comment\n'), SyntaxError, /parsing wasm text/);

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

@ -8,11 +8,11 @@ for (var i = 1000; i --> 0; ) {
var code = `(module
(func
(param f32)
(result f32)
(param f32)
${expr}
)
(export "run" (func 0))
(export "run" 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" (func 0)))`, expected);
wasmFullPass(`(module (func (result ${type}) (${type}.const ${str})) (export "run" 0))`, expected);
}
function testConstError(type, str) {
assertErrorMessage(() => wasmEvalText(`(module (func (result ${type}) (${type}.const ${str})) (export "" (func 0)))`).exports[""](), Error, /wasm text error/);
assertErrorMessage(() => wasmEvalText(`(module (func (result ${type}) (${type}.const ${str})) (export "" 0))`).exports[""](), Error, /parsing wasm text/);
}
testConst('i32', '0', 0);
@ -72,9 +72,9 @@ testConst('f32', '-0x0.0', -0.0);
testConst('f32', '-0x0', -0.0);
testConst('f32', '0x0.0p0', 0.0);
testConst('f32', '-0x0.0p0', -0.0);
testConst('f32', 'inf', Infinity);
testConst('f32', '-inf', -Infinity);
testConst('f32', '+inf', Infinity);
testConst('f32', 'infinity', Infinity);
testConst('f32', '-infinity', -Infinity);
testConst('f32', '+infinity', Infinity);
testConst('f32', 'nan', NaN);
//testConst('f32', '-nan', NaN); // TODO: NYI
testConst('f32', '+nan', NaN);
@ -100,8 +100,8 @@ testConst('f32', '0x1p-147', 5.605193857299268e-45);
testConst('f32', '0x1p-126', 1.1754943508222875e-38);
testConst('f32', '0x0.1fffffep+131', 3.4028234663852886e+38);
testConst('f32', '0x1.fffffep+127', 3.4028234663852886e+38);
testConstError('f32', '0x2.0p+127');
testConstError('f32', '0x1.fffffep+128');
testConst('f32', '0x2.0p+127', Infinity);
testConst('f32', '0x1.fffffep+128', Infinity);
testConst('f32', '0x0.1fffffep+128', 4.2535293329816107e+37);
testConst('f32', '0x1p2', 4);
testConst('f32', '0x10p2', 64);
@ -114,7 +114,7 @@ testConst('f32', '-0x1p+3', -8);
testConst('f32', '0x3p-2', .75);
testConst('f32', '-0x76.54p-32', -2.7550413506105542e-8);
testConst('f32', '0xf.ffffffffffffffffp+123', 170141183460469231731687303715884105728);
testConstError('f32', '0xf.ffffffffffffffffp+124');
testConst('f32', '0xf.ffffffffffffffffp+124', Infinity);
testConst('f32', '1.1754943508222875e-38', 1.1754943508222875e-38);
testConst('f32', '3.4028234663852886e+38', 3.4028234663852886e+38);
testConst('f32', '1.1754943508222875e-35', 1.1754943508222875e-35);
@ -139,7 +139,7 @@ testConst('f32', '-5.066758603788912e-7', -5.066758603788912e-7);
testConst('f32', '1.875000e-01', 1.875000e-01);
testConst('f32', '-0x1.b021fb98e9a17p-104', -8.322574059965897e-32);
testConst('f32', '0x1.08de5bf3f784cp-129', 1.5202715065429227e-39);
testConstError('f32', '0x1.d50b969fbbfb3p+388');
testConst('f32', '0x1.d50b969fbbfb3p+388', Infinity);
testConst('f32', '0x3434.2p4', 2.138260e+05);
testConst('f32', '0x1434.2p-120', 3.891074380317903e-33);
testConst('f32', '-0x0434.234p43', -9465807272673280);
@ -158,9 +158,9 @@ testConst('f64', '-0x0.0', -0.0);
testConst('f64', '-0x0', -0.0);
testConst('f64', '0x0.0p0', 0.0);
testConst('f64', '-0x0.0p0', -0.0);
testConst('f64', 'inf', Infinity);
testConst('f64', '-inf', -Infinity);
testConst('f64', '+inf', Infinity);
testConst('f64', 'infinity', Infinity);
testConst('f64', '-infinity', -Infinity);
testConst('f64', '+infinity', Infinity);
testConst('f64', 'nan', NaN);
//testConst('f64', '-nan', NaN); // TODO: NYI
testConst('f64', '+nan', NaN);

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

@ -7,33 +7,33 @@ 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 "" (func 0)))');
wasmEvalText('(module (func (local i32) (if (local.get 0) (nop) (nop))) (export "" (func 0)))');
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))');
// 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 i32) (local f32) (if f32 (i32.const 42) (local.get 0) (i32.const 0))))', mismatchError("i32", "f32"));
wasmFailValidateText('(module (func (result i32) (local f64) (if 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 "" (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);
assertEq(wasmEvalText('(module (func (result i32) (if 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);
// 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 "" (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);
wasmFailValidateText('(module (func (param f32) (if i32 (i32.const 42) (i32.const 1) (local.get 0))) (export "" 0))', mismatchError('f32', 'i32'));
wasmFailValidateText('(module (func (if 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 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);
// Sub-expression values are returned
// Also test that we support (result t) for `block`
wasmFullPass(`(module
(func
(result i32)
(if (result i32)
(if i32
(i32.const 42)
(block (result i32)
(block i32
(
if (result i32)
if i32
(block (result i32)
(drop (i32.const 3))
(drop (i32.const 5))
@ -46,74 +46,74 @@ wasmFullPass(`(module
(i32.const 0)
)
)
(export "run" (func 0))
(export "run" 0)
)`, 2);
// The if (resp. else) branch is taken iff the condition is true (resp. false)
counter = 0;
var imports = { "":{inc() { counter++ }} };
wasmFullPass(`(module
(import "" "inc" (func (result i32)))
(import "" "inc" (result i32))
(func
(result i32)
(if (result i32)
(if i32
(i32.const 42)
(i32.const 1)
(call 0)
)
)
(export "run" (func 1))
(export "run" 1)
)`, 1, imports);
assertEq(counter, 0);
wasmFullPass(`(module
(import "" "inc" (func (result i32)))
(import "" "inc" (result i32))
(func
(result i32)
(if (result i32)
(if i32
(i32.const 0)
(call 0)
(i32.const 1)
)
)
(export "run" (func 1))
(export "run" 1)
)`, 1, imports);
assertEq(counter, 0);
wasmFullPass(`(module
(import "" "inc" (func (result i32)))
(import "" "inc" (result i32))
(func
(if
(i32.const 0)
(drop (call 0))
)
)
(export "run" (func 1))
(export "run" 1)
)`, undefined, imports);
assertEq(counter, 0);
assertEq(wasmEvalText(`(module
(import "" "inc" (func (result i32)))
(import "" "inc" (result i32))
(func
(if
(i32.const 1)
(drop (call 0))
)
)
(export "" (func 1))
(export "" 1)
)`, imports).exports[""](), undefined);
assertEq(counter, 1);
wasmFullPass(`(module
(func
(result i32)
(if (result i32)
(if i32
(i32.const 0)
(br 0 (i32.const 0))
(br 0 (i32.const 1))
)
)
(export "run" (func 0))
(export "run" 0)
)`, 1);
assertEq(counter, 1);
@ -124,23 +124,23 @@ wasmFullPass(`(module
(br 0)
)
)
(export "run" (func 0))
(export "run" 0)
)`, undefined);
assertEq(counter, 1);
// One can chain if with if/if
counter = 0;
wasmFullPass(`(module
(import "" "inc" (func (result i32)))
(import "" "inc" (result i32))
(func
(result i32)
(if (result i32)
(if i32
(i32.const 1)
(if (result i32)
(if i32
(i32.const 2)
(if (result i32)
(if i32
(i32.const 3)
(if (result i32)
(if i32
(i32.const 0)
(call 0)
(i32.const 42)
@ -152,37 +152,37 @@ wasmFullPass(`(module
(call 0)
)
)
(export "run" (func 1))
(export "run" 1)
)`, 42, imports);
assertEq(counter, 0);
// "if" doesn't return an expression value
wasmFailValidateText('(module (func (result i32) (if (result i32) (i32.const 42) (i32.const 0))))', /if without else with a result value/);
wasmFailValidateText('(module (func (result i32) (if (result i32) (i32.const 42) (drop (i32.const 0)))))', emptyStackError);
wasmFailValidateText('(module (func (result i32) (if (result i32) (i32.const 1) (i32.const 0) (if (result i32) (i32.const 1) (i32.const 1)))))', /if without else with a result value/);
wasmFailValidateText('(module (func (result i32) (if (result i32) (i32.const 1) (drop (i32.const 0)) (if (i32.const 1) (drop (i32.const 1))))))', emptyStackError);
wasmFailValidateText('(module (func (if (result i32) (i32.const 1) (i32.const 0) (if (result i32) (i32.const 1) (i32.const 1)))))', /if without else with a result value/);
wasmFailValidateText('(module (func (if (result i32) (i32.const 1) (i32.const 0) (if (i32.const 1) (drop (i32.const 1))))))', emptyStackError);
wasmFailValidateText('(module (func (if (i32.const 1) (drop (i32.const 0)) (if (result i32) (i32.const 1) (i32.const 1)))))', /if without else with a result value/);
wasmFailValidateText('(module (func (result i32) (if i32 (i32.const 42) (i32.const 0))))', /if without else with a result value/);
wasmFailValidateText('(module (func (result i32) (if i32 (i32.const 42) (drop (i32.const 0)))))', emptyStackError);
wasmFailValidateText('(module (func (result i32) (if i32 (i32.const 1) (i32.const 0) (if i32 (i32.const 1) (i32.const 1)))))', /if without else with a result value/);
wasmFailValidateText('(module (func (result i32) (if i32 (i32.const 1) (drop (i32.const 0)) (if (i32.const 1) (drop (i32.const 1))))))', emptyStackError);
wasmFailValidateText('(module (func (if i32 (i32.const 1) (i32.const 0) (if i32 (i32.const 1) (i32.const 1)))))', /if without else with a result value/);
wasmFailValidateText('(module (func (if i32 (i32.const 1) (i32.const 0) (if (i32.const 1) (drop (i32.const 1))))))', emptyStackError);
wasmFailValidateText('(module (func (if (i32.const 1) (drop (i32.const 0)) (if i32 (i32.const 1) (i32.const 1)))))', /if without else with a result value/);
wasmEvalText('(module (func (if (i32.const 1) (drop (i32.const 0)) (if (i32.const 1) (drop (i32.const 1))))))');
// ----------------------------------------------------------------------------
// return
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);
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);
// ----------------------------------------------------------------------------
// br / br_if
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);
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);
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 "" (func 0)))`, unusedValuesError);
) (export "" 0))`, unusedValuesError);
wasmFullPass(`(module (func (block $out (br_if $out (br 0)))) (export "run" (func 0)))`, undefined);
wasmFullPass(`(module (func (block $out (br_if $out (br 0)))) (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 (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 (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 (block (br 1)))) (export "run" 0))', undefined);
wasmFullPass('(module (func (block $l (block (br $l)))) (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 (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 (result i32)
(block
@ -225,7 +225,7 @@ wasmFullPass(`(module (func (result i32)
(return (i32.const 0))
)
(return (i32.const 1))
) (export "run" (func 0)))`, 1);
) (export "run" 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" (func 0)))`, 1);
) (export "run" 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" (func 0)))`, 1);
) (export "run" 0))`, 1);
var notcalled = false;
var called = false;
@ -256,15 +256,15 @@ var imports = {"": {
called() {called = true}
}};
wasmFullPass(`(module
(import "" "notcalled" (func))
(import "" "called" (func))
(import "" "notcalled")
(import "" "called")
(func
(block
(return (br 0))
(call 0)
)
(call 1)
) (export "run" (func 2)))`, undefined, imports);
) (export "run" 2))`, undefined, imports);
assertEq(notcalled, false);
assertEq(called, true);
@ -277,7 +277,7 @@ wasmFullPass(`(module (func
drop
)
(return)
) (export "run" (func 0)))`, undefined);
) (export "run" 0))`, undefined);
wasmFullPass(`(module (func (result i32)
(block
@ -288,21 +288,21 @@ wasmFullPass(`(module (func (result i32)
)
)
(return (i32.const 1))
) (export "run" (func 0)))`, 1);
) (export "run" 0))`, 1);
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);
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);
var isNonZero = wasmEvalText(`(module (func (param i32) (result i32)
var isNonZero = wasmEvalText(`(module (func (result i32) (param i32)
(block
(br_if 0 (local.get 0))
(return (i32.const 0))
)
(return (i32.const 1))
) (export "" (func 0)))`).exports[""];
) (export "" 0))`).exports[""];
assertEq(isNonZero(0), 0);
assertEq(isNonZero(1), 1);
@ -313,76 +313,76 @@ assertEq(isNonZero(-1), 1);
wasmFailValidateText('(module (func (result i32) (br 0)))', emptyStackError);
wasmFailValidateText('(module (func (result i32) (br 0 (f32.const 42))))', mismatchError("f32", "i32"));
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) (block f32 (br 0 (f32.const 42)))))', mismatchError("f32", "i32"));
wasmFailValidateText(`(module (func (param i32) (result 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 (param i32) (result i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (br 0 (f32.const 42)))) (export "" (func 0)))`, mismatchError("f32", "i32"));
wasmFailValidateText(`(module (func (result i32) (param i32) (block (if 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 i32 (if (local.get 0) (drop (i32.const 42))) (br 0 (f32.const 42)))) (export "" 0))`, mismatchError("f32", "i32"));
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);
wasmFullPass('(module (func (result i32) (br 0 (i32.const 42)) (i32.const 13)) (export "run" 0))', 42);
wasmFullPass('(module (func (result i32) (block i32 (br 0 (i32.const 42)) (i32.const 13))) (export "run" 0))', 42);
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);
wasmFailValidateText('(module (func) (func (block i32 (br 0 (call 0)) (i32.const 13))) (export "" 0))', emptyStackError);
wasmFailValidateText('(module (func) (func (block i32 (br_if 0 (call 0) (i32.const 1)) (i32.const 13))) (export "" 0))', emptyStackError);
var f = wasmEvalText(`(module (func (param i32) (result i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (i32.const 43))) (export "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (result i32) (param i32) (block i32 (if (local.get 0) (drop (i32.const 42))) (i32.const 43))) (export "" 0))`).exports[""];
assertEq(f(0), 43);
assertEq(f(1), 43);
wasmFailValidateText(`(module (func (param i32) (result 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/);
wasmFailValidateText(`(module (func (result i32) (param i32) (block i32 (if i32 (local.get 0) (br 0 (i32.const 42))) (i32.const 43))) (export "" 0))`, /if without else with a result value/);
var f = wasmEvalText(`(module (func (param i32) (result i32) (block (result i32) (if (local.get 0) (br 1 (i32.const 42))) (i32.const 43))) (export "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (result i32) (param i32) (block i32 (if (local.get 0) (br 1 (i32.const 42))) (i32.const 43))) (export "" 0))`).exports[""];
assertEq(f(0), 43);
assertEq(f(1), 42);
wasmFailValidateText(`(module (func (param i32) (result 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/);
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/);
var f = wasmEvalText(`(module (func (param i32) (result i32) (block (result i32) (drop (br_if 0 (i32.const 42) (local.get 0))) (i32.const 43))) (export "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (result i32) (param i32) (block i32 (drop (br_if 0 (i32.const 42) (local.get 0))) (i32.const 43))) (export "" 0))`).exports[""];
assertEq(f(0), 43);
assertEq(f(1), 42);
var f = wasmEvalText(`(module (func (param i32) (result i32) (block (result i32) (if (local.get 0) (drop (i32.const 42))) (br 0 (i32.const 43)))) (export "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (result i32) (param i32) (block i32 (if (local.get 0) (drop (i32.const 42))) (br 0 (i32.const 43)))) (export "" 0))`).exports[""];
assertEq(f(0), 43);
assertEq(f(1), 43);
wasmFailValidateText(`(module (func (param i32) (result 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/);
wasmFailValidateText(`(module (func (result i32) (param i32) (block i32 (if i32 (local.get 0) (br 0 (i32.const 42))) (br 0 (i32.const 43)))) (export "" 0))`, /if without else with a result value/);
var f = wasmEvalText(`(module (func (param i32) (result i32) (if (local.get 0) (br 1 (i32.const 42))) (br 0 (i32.const 43))) (export "" (func 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 "" 0))`).exports[""];
assertEq(f(0), 43);
assertEq(f(1), 42);
var f = wasmEvalText(`(module (func (param i32) (result i32) (block (result i32) (if (local.get 0) (br 1 (i32.const 42))) (br 0 (i32.const 43)))) (export "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (result i32) (param i32) (block i32 (if (local.get 0) (br 1 (i32.const 42))) (br 0 (i32.const 43)))) (export "" 0))`).exports[""];
assertEq(f(0), 43);
assertEq(f(1), 42);
var f = wasmEvalText(`(module (func (param i32) (result i32) (br_if 0 (i32.const 42) (local.get 0)) (br 0 (i32.const 43))) (export "" (func 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 "" 0))`).exports[""];
assertEq(f(0), 43);
assertEq(f(1), 42);
var f = wasmEvalText(`(module (func (param i32) (result i32) (block (result i32) (br_if 0 (i32.const 42) (local.get 0)) (br 0 (i32.const 43)))) (export "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (result i32) (param i32) (block i32 (br_if 0 (i32.const 42) (local.get 0)) (br 0 (i32.const 43)))) (export "" 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 "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block i32 (if (local.get 0) (drop (i32.const 99))) (i32.const -1)))) (export "" 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 "" (func 0)))`, /if without else with a result value/);
wasmFailValidateText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block i32 (if i32 (local.get 0) (br 0 (i32.const 99))) (i32.const -1)))) (export "" 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 "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block i32 (if (local.get 0) (br 1 (i32.const 99))) (i32.const -1)))) (export "" 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 "" (func 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 "" 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 "" (func 0)))`).exports[""];
var f = wasmEvalText(`(module (func (param i32) (result i32) (i32.add (i32.const 1) (block i32 (drop (br_if 0 (i32.const 99) (local.get 0))) (i32.const -1)))) (export "" 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" (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 i32) (block i32 (br 0 (return (i32.const 42))) (i32.const 0))) (export "run" 0))`, 42);
wasmFullPass(`(module (func (result i32) (block i32 (return (br 0 (i32.const 42))))) (export "run" 0))`, 42);
wasmFullPass(`(module (func (result i32) (block i32 (return (br 0 (i32.const 42))) (i32.const 0))) (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);
wasmFullPass(`(module (func (result f32) (drop (block i32 (br 0 (i32.const 0)))) (block f32 (br 0 (f32.const 42)))) (export "run" 0))`, 42);
var called = 0;
var imports = {
@ -392,8 +392,8 @@ var imports = {
}
}
var f = wasmEvalText(`(module
(import "sideEffects" "ifTrue" (func (param i32)))
(import "sideEffects" "ifFalse" (func (param i32)))
(import "sideEffects" "ifTrue" (param i32))
(import "sideEffects" "ifFalse" (param i32))
(func
(param i32) (result i32)
(block $outer
@ -408,35 +408,33 @@ var f = wasmEvalText(`(module
)
(i32.const 42)
)
(export "" (func 2)))`, imports).exports[""];
(export "" 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) (block $out (result i32) (loop $in (result i32) (br $out (local.get 0))))) (export "run" (func 0)))`, 1, {}, 1);
wasmFullPass(`(module (func (param i32) (result i32) (loop $in (result i32) (br 1 (local.get 0)))) (export "run" (func 0)))`, 1, {}, 1);
wasmFullPass(`(module (func (param i32) (result i32) (block $out (result i32) (loop $in (result i32) (br $out (local.get 0))))) (export "run" (func 0)))`, 1, {}, 1);
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);
wasmFailValidateText(`(module (func (param i32) (result i32)
(block $out
(loop $in
(if (local.get 0) (br $in (i32.const 1)))
(if (local.get 0) (br $in (f32.const 2)))
(if (local.get 0) (br $in (f64.const 3)))
(if (local.get 0) (br $in))
(i32.const 7)
)
(loop $out $in
(if (local.get 0) (br $in (i32.const 1)))
(if (local.get 0) (br $in (f32.const 2)))
(if (local.get 0) (br $in (f64.const 3)))
(if (local.get 0) (br $in))
(i32.const 7)
)
) (export "" (func 0)))`, /unused values not explicitly dropped by end of block/);
) (export "" 0))`, /unused values not explicitly dropped by end of block/);
wasmFullPass(`(module
(func
(result i32)
(local i32)
(block $out (result i32)
(loop $in (result i32)
(block $out i32
(loop $in i32
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
(if
(i32.ge_s (local.get 0) (i32.const 7))
@ -446,36 +444,50 @@ wasmFullPass(`(module
)
)
)
(export "run" (func 0)))`, 7);
(export "run" 0))`, 7);
wasmFullPass(`(module
(func
(result i32)
(local i32)
(block $out (result i32)
(loop $in (result i32)
(block $out i32
(loop $in i32
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
(br_if $out (local.get 0) (i32.ge_s (local.get 0) (i32.const 7)))
(br $in)
)
)
)
(export "run" (func 0)))`, 7);
(export "run" 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 "" (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);
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);
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 (block $a (loop $b (br $a)))) (export "run" (func 0)))', undefined);
wasmFullPass('(module (func (result i32) (loop (result i32) (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 (result i32) (local i32)
(loop
$break $continue
(if
(i32.gt_u (local.get 0) (i32.const 5))
(br $break)
)
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
(br $continue)
)
(return (local.get 0))
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(block
@ -491,7 +503,20 @@ wasmFullPass(`(module (func (result i32) (local i32)
)
)
(return (local.get 0))
) (export "run" (func 0)))`, 6);
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(loop
$break $continue
(br_if
$break
(i32.gt_u (local.get 0) (i32.const 5))
)
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
(br $continue)
)
(return (local.get 0))
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(block
@ -507,7 +532,19 @@ wasmFullPass(`(module (func (result i32) (local i32)
)
)
(return (local.get 0))
) (export "run" (func 0)))`, 6);
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(loop
$break $continue
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
(br_if
$continue
(i32.le_u (local.get 0) (i32.const 5))
)
)
(return (local.get 0))
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(block
@ -522,7 +559,23 @@ wasmFullPass(`(module (func (result i32) (local i32)
)
)
(return (local.get 0))
) (export "run" (func 0)))`, 6);
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(loop
$break $continue
(br_if
$break
(i32.gt_u (local.get 0) (i32.const 5))
)
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
(loop
(br $continue)
)
(return (i32.const 42))
)
(return (local.get 0))
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(block
@ -541,7 +594,22 @@ wasmFullPass(`(module (func (result i32) (local i32)
)
)
(return (local.get 0))
) (export "run" (func 0)))`, 6);
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(loop
$break $continue
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
(loop
(br_if
$continue
(i32.le_u (local.get 0) (i32.const 5))
)
)
(br $break)
)
(return (local.get 0))
) (export "run" 0))`, 6);
wasmFullPass(`(module (func (result i32) (local i32)
(block
@ -559,7 +627,7 @@ wasmFullPass(`(module (func (result i32) (local i32)
)
)
(return (local.get 0))
) (export "run" (func 0)))`, 6);
) (export "run" 0))`, 6);
// ----------------------------------------------------------------------------
// br_table
@ -574,23 +642,23 @@ wasmFailValidateText('(module (func (loop (br_table 2 0 (i32.const 0)))))', DEPT
wasmFailValidateText('(module (func (loop (br_table 0 2 (i32.const 0)))))', DEPTH_OUT_OF_BOUNDS);
wasmFailValidateText('(module (func (loop (br_table 0 (f32.const 0)))))', mismatchError("f32", "i32"));
wasmFullPass(`(module (func (param i32) (result i32)
wasmFullPass(`(module (func (result i32) (param i32)
(block $default
(br_table $default (local.get 0))
(return (i32.const 0))
)
(return (i32.const 1))
) (export "run" (func 0)))`, 1);
) (export "run" 0))`, 1);
wasmFullPass(`(module (func (param i32) (result i32)
wasmFullPass(`(module (func (result i32) (param i32)
(block $default
(br_table $default (return (i32.const 1)))
(return (i32.const 0))
)
(return (i32.const 2))
) (export "run" (func 0)))`, 1);
) (export "run" 0))`, 1);
wasmFullPass(`(module (func (param i32) (result i32)
wasmFullPass(`(module (func (result i32) (param i32)
(block $outer
(block $inner
(br_table $inner (local.get 0))
@ -599,9 +667,9 @@ wasmFullPass(`(module (func (param i32) (result i32)
(return (i32.const 1))
)
(return (i32.const 2))
) (export "run" (func 0)))`, 1);
) (export "run" 0))`, 1);
var f = wasmEvalText(`(module (func (param i32) (result i32)
var f = wasmEvalText(`(module (func (result i32) (param i32)
(block $0
(block $1
(block $2
@ -614,7 +682,7 @@ var f = wasmEvalText(`(module (func (param i32) (result i32)
)
)
(return (i32.const 0))
) (export "" (func 0)))`).exports[""];
) (export "" 0))`).exports[""];
assertEq(f(-2), -1);
assertEq(f(-1), -1);
@ -624,28 +692,28 @@ assertEq(f(2), 2);
assertEq(f(3), -1);
// br_table with values
wasmFailValidateText('(module (func (result i32) (block (result i32) (br_table 0 (i32.const 0)))))', emptyStackError);
wasmFailValidateText('(module (func (result i32) (block (result i32) (br_table 0 (f32.const 0) (i32.const 0)))))', mismatchError("f32", "i32"));
wasmFailValidateText('(module (func (result i32) (block i32 (br_table 0 (i32.const 0)))))', emptyStackError);
wasmFailValidateText('(module (func (result i32) (block i32 (br_table 0 (f32.const 0) (i32.const 0)))))', mismatchError("f32", "i32"));
wasmFailValidateText(`(module
(func
(result i32)
(block $outer (result f32)
(block $inner (result f32)
(block $outer f32
(block $inner f32
(br_table $outer $inner (f32.const 13.37) (i32.const 1))
)
(br $outer (i32.const 42))
)
)
(export "" (func 0)))`, mismatchError("i32", "f32"));
(export "" 0))`, mismatchError("i32", "f32"));
wasmFullPass(`(module (func (result i32) (block $default (result i32) (br_table $default (i32.const 42) (i32.const 1)))) (export "run" (func 0)))`, 42);
wasmFullPass(`(module (func (result i32) (block $default i32 (br_table $default (i32.const 42) (i32.const 1)))) (export "run" 0))`, 42);
var f = wasmEvalText(`(module (func (param i32) (result i32)
(i32.add
(block $1 (result i32)
(drop (block $0 (result i32)
(drop (block $default (result i32)
(block $1 i32
(drop (block $0 i32
(drop (block $default i32
(br_table $0 $1 $default (local.get 0) (local.get 0))
))
(tee_local 0 (i32.mul (i32.const 2) (local.get 0)))
@ -654,7 +722,7 @@ var f = wasmEvalText(`(module (func (param i32) (result i32)
)
(i32.const 1)
)
) (export "" (func 0)))`).exports[""];
) (export "" 0))`).exports[""];
assertEq(f(0), 5);
assertEq(f(1), 2);
@ -666,8 +734,8 @@ assertEq(f(4), 13);
// unreachable
const UNREACHABLE = /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);
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);

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

@ -26,7 +26,7 @@ function testConversion0(resultType, opcode, paramType, op, expect) {
wasmFullPass(`(module
(func (param ${paramType}) (result ${resultType})
(${opcode} (local.get 0)))
(export "run" (func 0))
(export "run" 0)
)`, expect, {}, op);
}
@ -68,7 +68,7 @@ function testTrap(resultType, opcode, paramType, op) {
call 0
drop
)
(export "" (func 1))
(export "" 1)
)`).exports[""];
let expectedError = op === 'nan' ? /invalid conversion to integer/ : /integer overflow/;
@ -216,26 +216,26 @@ testConversion('i64', 'trunc_u', 'f32', 18446742974197923840.0, "0xffffff0000000
testTrap('i64', 'trunc_s', 'f64', 9223372036854776000.0);
testTrap('i64', 'trunc_s', 'f64', -9223372036854778000.0);
testTrap('i64', 'trunc_s', 'f64', "nan");
testTrap('i64', 'trunc_s', 'f64', "inf");
testTrap('i64', 'trunc_s', 'f64', "-inf");
testTrap('i64', 'trunc_s', 'f64', "infinity");
testTrap('i64', 'trunc_s', 'f64', "-infinity");
testTrap('i64', 'trunc_u', 'f64', -1);
testTrap('i64', 'trunc_u', 'f64', 18446744073709551616.0);
testTrap('i64', 'trunc_u', 'f64', "nan");
testTrap('i64', 'trunc_u', 'f64', "inf");
testTrap('i64', 'trunc_u', 'f64', "-inf");
testTrap('i64', 'trunc_u', 'f64', "infinity");
testTrap('i64', 'trunc_u', 'f64', "-infinity");
testTrap('i64', 'trunc_s', 'f32', 9223372036854776000.0);
testTrap('i64', 'trunc_s', 'f32', -9223372586610630000.0);
testTrap('i64', 'trunc_s', 'f32', "nan");
testTrap('i64', 'trunc_s', 'f32', "inf");
testTrap('i64', 'trunc_s', 'f32', "-inf");
testTrap('i64', 'trunc_s', 'f32', "infinity");
testTrap('i64', 'trunc_s', 'f32', "-infinity");
testTrap('i64', 'trunc_u', 'f32', 18446744073709551616.0);
testTrap('i64', 'trunc_u', 'f32', -1);
testTrap('i64', 'trunc_u', 'f32', "nan");
testTrap('i64', 'trunc_u', 'f32', "inf");
testTrap('i64', 'trunc_u', 'f32', "-inf");
testTrap('i64', 'trunc_u', 'f32', "infinity");
testTrap('i64', 'trunc_u', 'f32', "-infinity");
testConversion('i64', 'reinterpret', 'f64', 40.09999999999968, "0x40440ccccccccca0");
testConversion('f64', 'reinterpret', 'i64', "0x40440ccccccccca0", 40.09999999999968);
@ -273,26 +273,26 @@ testConversion('i32', 'trunc_u:sat', 'f64', p(2, 32), -1);
testConversion('i64', 'trunc_s:sat', 'f64', 9223372036854776000.0, s64max);
testConversion('i64', 'trunc_s:sat', 'f64', -9223372036854778000.0, s64min);
testConversion('i64', 'trunc_s:sat', 'f64', 'nan', '0');
testConversion('i64', 'trunc_s:sat', 'f64', 'inf', s64max);
testConversion('i64', 'trunc_s:sat', 'f64', '-inf', s64min);
testConversion('i64', 'trunc_s:sat', 'f64', 'infinity', s64max);
testConversion('i64', 'trunc_s:sat', 'f64', '-infinity', s64min);
testConversion('i64', 'trunc_u:sat', 'f64', -1, '0');
testConversion('i64', 'trunc_u:sat', 'f64', 18446744073709551616.0, u64max);
testConversion('i64', 'trunc_u:sat', 'f64', 'nan', '0');
testConversion('i64', 'trunc_u:sat', 'f64', 'inf', u64max);
testConversion('i64', 'trunc_u:sat', 'f64', '-inf', '0');
testConversion('i64', 'trunc_u:sat', 'f64', 'infinity', u64max);
testConversion('i64', 'trunc_u:sat', 'f64', '-infinity', '0');
testConversion('i64', 'trunc_s:sat', 'f32', 9223372036854776000.0, s64max);
testConversion('i64', 'trunc_s:sat', 'f32', -9223372586610630000.0, s64min);
testConversion('i64', 'trunc_s:sat', 'f32', 'nan', '0');
testConversion('i64', 'trunc_s:sat', 'f32', 'inf', s64max);
testConversion('i64', 'trunc_s:sat', 'f32', '-inf', s64min);
testConversion('i64', 'trunc_s:sat', 'f32', 'infinity', s64max);
testConversion('i64', 'trunc_s:sat', 'f32', '-infinity', s64min);
testConversion('i64', 'trunc_u:sat', 'f32', 18446744073709551616.0, u64max);
testConversion('i64', 'trunc_u:sat', 'f32', -1, '0');
testConversion('i64', 'trunc_u:sat', 'f32', 'nan', '0');
testConversion('i64', 'trunc_u:sat', 'f32', 'inf', u64max);
testConversion('i64', 'trunc_u:sat', 'f32', '-inf', '0');
testConversion('i64', 'trunc_u:sat', 'f32', 'infinity', u64max);
testConversion('i64', 'trunc_u:sat', 'f32', '-infinity', '0');
testSignExtension('i32', 'extend8_s', 'i32', 0x7F, 0x7F);
testSignExtension('i32', 'extend8_s', 'i32', 0x80, -0x80);
@ -312,8 +312,8 @@ testConversion('i32', 'trunc_s', 'f32', p(2, 31) - 128, p(2, 31) - 128); // last
testConversion('i32', 'trunc_s', 'f32', -p(2, 31), -p(2,31)); // last f32 value exactly representable > -2**31 - 1.
testTrap('i32', 'trunc_s', 'f32', 'nan');
testTrap('i32', 'trunc_s', 'f32', 'inf');
testTrap('i32', 'trunc_s', 'f32', '-inf');
testTrap('i32', 'trunc_s', 'f32', 'infinity');
testTrap('i32', 'trunc_s', 'f32', '-infinity');
testTrap('i32', 'trunc_s', 'f32', p(2, 31));
testTrap('i32', 'trunc_s', 'f32', -p(2,31) - 256);
@ -323,8 +323,8 @@ testConversion('i32', 'trunc_s', 'f64', -p(2,31) - 0.999, -p(2,31)); // example
// f64:
testTrap('i32', 'trunc_s', 'f64', 'nan');
testTrap('i32', 'trunc_s', 'f64', 'inf');
testTrap('i32', 'trunc_s', 'f64', '-inf');
testTrap('i32', 'trunc_s', 'f64', 'infinity');
testTrap('i32', 'trunc_s', 'f64', '-infinity');
testTrap('i32', 'trunc_s', 'f64', p(2,31));
testTrap('i32', 'trunc_s', 'f64', -p(2,31) - 1);
@ -336,8 +336,8 @@ testConversion('i32', 'trunc_u', 'f32', p(2,32) - 256, (p(2,32) - 256)|0); // la
testConversion('i32', 'trunc_u', 'f32', -0.99, 0); // example value near the bottom.
testTrap('i32', 'trunc_u', 'f32', 'nan');
testTrap('i32', 'trunc_u', 'f32', 'inf');
testTrap('i32', 'trunc_u', 'f32', '-inf');
testTrap('i32', 'trunc_u', 'f32', 'infinity');
testTrap('i32', 'trunc_u', 'f32', '-infinity');
testTrap('i32', 'trunc_u', 'f32', -1);
testTrap('i32', 'trunc_u', 'f32', p(2,32));
@ -347,8 +347,8 @@ testConversion('i32', 'trunc_u', 'f64', p(2,32) - 0.001, (p(2,32) - 1)|0); // ex
testConversion('i32', 'trunc_u', 'f64', -0.99999, 0); // example value near the bottom.
testTrap('i32', 'trunc_u', 'f64', 'nan');
testTrap('i32', 'trunc_u', 'f64', 'inf');
testTrap('i32', 'trunc_u', 'f64', '-inf');
testTrap('i32', 'trunc_u', 'f64', 'infinity');
testTrap('i32', 'trunc_u', 'f64', '-infinity');
testTrap('i32', 'trunc_u', 'f64', -1);
testTrap('i32', 'trunc_u', 'f64', p(2,32));
@ -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" (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);
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);

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

@ -4,20 +4,20 @@
wasmFullPass(`
(module
(func $f1)
(elem declare $f1)
(elem declared $f1)
(func $run)
(export "run" (func $run))
(export "run" $run)
)
`);
// Declared segments cannot use ref.null
assertThrowsInstanceOf(() => {
new WebAssembly.Module(wasmTextToBinary(`
wasmTextToBinary(`
(module
(elem declare (ref.null))
(elem declared (ref.null))
)
`))
}, WebAssembly.CompileError);
`)
}, SyntaxError);
// Declared segments cannot be used by bulk-memory operations
function test(ins) {
@ -26,7 +26,7 @@ function test(ins) {
(module
(func $f1)
(table 1 1 funcref)
(elem declare $f1)
(elem declared $f1)
(func $start ${ins})
(start $start)
)
@ -41,12 +41,12 @@ wasmAssert(`
(module
(func $f1)
(table 1 1 funcref)
(elem declare $f1)
(elem declared $f1)
(func $at (param i32) (result i32)
local.get 0
table.get 0
ref.is_null
)
(export "at" (func $at))
(export "at" $at)
)
`, [{type: 'i32', func: '$at', args: ['i32.const 0'], expected: '1'}]);

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

@ -1,20 +1,20 @@
for (let type of ['i32', 'f32', 'f64']) {
assertEq(wasmEvalText(`
(module
(func $test (param $p ${type}) (param $p2 ${type}) (result ${type})
(func $test (result ${type}) (param $p ${type}) (param $p2 ${type})
local.get $p
local.get $p2
(block)
drop
)
(export "test" (func $test))
(export "test" $test)
)
`).exports.test(0x1337abc0, 0xffffffff), 0x1337abc0);
}
assertEq(wasmEvalText(`
(module
(func $test (param $p i32) (param $p2 f32) (param $p3 f64) (param $p4 i32) (result i32)
(func $test (result i32) (param $p i32) (param $p2 f32) (param $p3 f64) (param $p4 i32)
local.get $p
local.get $p2
local.get $p3
@ -26,19 +26,19 @@ assertEq(wasmEvalText(`
drop
drop
)
(export "test" (func $test))
(export "test" $test)
)
`).exports.test(0x1337abc0, 0xffffffff), 0x1337abc0);
wasmAssert(`
(module
(func $test (param $p i64) (param $p2 i64) (result i64)
(func $test (result i64) (param $p i64) (param $p2 i64)
local.get $p
local.get $p2
(block)
drop
)
(export "test" (func $test))
(export "test" $test)
)
`, [
{ type: 'i64', func: '$test', args: ['(i64.const 0x1337abc0)', '(i64.const -1)'], expected: '0x1337abc0' }

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

@ -106,9 +106,9 @@ test(I64TruncSF32Code, '(module (func (drop (i64.trunc_s/f32 (f32.const nan))))
test(I64TruncSF64Code, '(module (func (drop (i64.trunc_s/f64 (f64.const nan)))) (start 0))', RuntimeError, /invalid conversion to integer/);
test(I64TruncUF32Code, '(module (func (drop (i64.trunc_u/f32 (f32.const nan)))) (start 0))', RuntimeError, /invalid conversion to integer/);
test(I64TruncUF64Code, '(module (func (drop (i64.trunc_u/f64 (f64.const nan)))) (start 0))', RuntimeError, /invalid conversion to integer/);
test(CallIndirectCode, '(module (table 1 funcref) (func (call_indirect (type 0) (i32.const 0))) (start 0))', RuntimeError, /indirect call to null/);
test(CallIndirectCode, '(module (table 1 funcref) (func (call_indirect (type 0) (i32.const 1))) (start 0))', RuntimeError, /index out of bounds/);
test(CallIndirectCode, '(module (table funcref (elem $blah)) (func (call_indirect (type 0) (i32.const 0))) (func $blah (param i32)) (start 0))', RuntimeError, /indirect call signature mismatch/);
test(CallIndirectCode, '(module (table 1 funcref) (func (call_indirect 0 (i32.const 0))) (start 0))', RuntimeError, /indirect call to null/);
test(CallIndirectCode, '(module (table 1 funcref) (func (call_indirect 0 (i32.const 1))) (start 0))', RuntimeError, /index out of bounds/);
test(CallIndirectCode, '(module (table funcref (elem $blah)) (func (call_indirect 0 (i32.const 0))) (func $blah (param i32)) (start 0))', RuntimeError, /indirect call signature mismatch/);
testLoad(I32Load8S, 'i32.load8_s', 1, RuntimeError, /index out of bounds/);
testLoad(I32Load8U, 'i32.load8_u', 1, RuntimeError, /index out of bounds/);
testLoad(I32Load16S, 'i32.load16_s', 2, RuntimeError, /index out of bounds/);
@ -146,7 +146,7 @@ var {stack, binary} = test(UnreachableCode, `(module
(func $b call $a)
(func $c call $b)
(table funcref (elem $c))
(func $d (call_indirect (type $v2v) (i32.const 0)))
(func $d (call_indirect $v2v (i32.const 0)))
(func $e call $d)
(start $e)
)`, RuntimeError, /unreachable executed/);
@ -177,4 +177,4 @@ function testCompileError(opcode, text) {
testCompileError(CallCode, '(module (func $f (param i32)) (func $g call $f))');
testCompileError(I32AddCode, '(module (func (i32.add (i32.const 1) (f32.const 1))))');
testCompileError(EndCode, '(module (func (block (result i32))))');
testCompileError(EndCode, '(module (func (block i32)))');

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

@ -15,5 +15,5 @@ assertEq(wasmEvalText(`(module
(local.get 1)
)
(export "" (func 0))
(export "" 0)
)`).exports[""](10), 3628800);

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

@ -4,7 +4,7 @@
wasmFullPass(
`(module
(func atomic.fence)
(export "run" (func 0))
(export "run" 0)
)`);
// Test that `atomic.fence` works with non-shared memory
@ -12,7 +12,7 @@ wasmFullPass(
`(module
(memory 1)
(func atomic.fence)
(export "run" (func 0))
(export "run" 0)
)`);
// Test that `atomic.fence` works with shared memory
@ -20,5 +20,5 @@ wasmFullPass(
`(module
(memory 1 1 shared)
(func atomic.fence)
(export "run" (func 0))
(export "run" 0)
)`);

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

@ -1,32 +1,32 @@
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);
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);
function testUnary(type, opcode, op, expect) {
wasmFullPass('(module (func (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0))) (export "run" (func 0)))',
wasmFullPass('(module (func (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0))) (export "run" 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" (func 0)))',
wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result ' + type + ') (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" 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" (func 0)))',
wasmFullPass('(module (func (param ' + type + ') (param ' + type + ') (result i32) (' + type + '.' + opcode + ' (local.get 0) (local.get 1))) (export "run" 0))',
expect,
{},
lhs, rhs);

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

@ -1,7 +1,7 @@
wasmFullPass(`(module
(func $test (param i32) (param i32) (result i32) (i32.add (local.get 0) (local.get 1)))
(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" (func $run))
(export "run" $run)
)`, -Math.pow(2, 31));
wasmFullPass(`(module
@ -17,7 +17,7 @@ wasmFullPass(`(module
i32.add
)
(func) (func) (func)
(export "run" (func 0)))`, 43);
(export "run" 0))`, 43);
wasmFullPass(`
(module
@ -28,7 +28,7 @@ wasmFullPass(`
// Global section.
wasmFullPass(`(module
(import "globals" "x" (global $imported i32))
(import $imported "globals" "x" (global i32))
(global $mut_local (mut i32) (i32.const 0))
(global $imm_local i32 (i32.const 37))
(global $imm_local_2 i32 (global.get 0))
@ -43,7 +43,7 @@ wasmFullPass(`(module
global.get $imm_local_2
i32.add
)
(export "run" (func $get))
(export "run" $get)
)`, 13 + 42 + 37 + 42, { globals: {x: 42} });
// Memory.
@ -66,7 +66,7 @@ wasmFullPass(`(module
i32.const 1
i32.load offset=2
)
(export "mem" (memory 0))
(export "mem" memory)
)`, 0x050403, {"": {memory}});
// Tables.
@ -80,7 +80,7 @@ wasmFullPass(`(module
(elem (i32.const 2) $foo)
(func (export "run") (param i32) (result i32)
local.get 0
call_indirect (type $t)
call_indirect $t
)
)`, 3, {}, 0);
@ -96,7 +96,7 @@ wasmFullPass(`(module
(elem (i32.const 2) $foo)
(func (export "run") (param i32) (result i32)
local.get 0
call_indirect (type $t)
call_indirect $t
)
)`, 3, {"":{table}}, 0);
@ -123,7 +123,7 @@ for (let [p, result] of [
[42, 4]
]) {
wasmFullPass(`(module
(func (export "run") (param $p i32) (result i32) (local $n i32)
(func (export "run") (result i32) (param $p i32) (local $n i32)
i32.const 0
local.set $n
block $c block $b block $a

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

@ -59,7 +59,7 @@ for (let v of VALUES)
let g = new WebAssembly.Global({value: "anyref"}, v);
let ins = wasmEvalText(
`(module
(import "m" "g" (global $glob anyref))
(import $glob "m" "g" (global anyref))
(func (export "f") (result anyref)
(global.get $glob)))`,
{m:{g}});
@ -73,7 +73,7 @@ for (let v of VALUES)
let g = new WebAssembly.Global({value: "anyref", mutable: true});
let ins = wasmEvalText(
`(module
(import "m" "g" (global $glob (mut anyref)))
(import $glob "m" "g" (global (mut anyref)))
(func (export "f") (param $v anyref)
(global.set $glob (local.get $v))))`,
{m:{g}});
@ -111,7 +111,7 @@ for (let v of VALUES)
let t = new WebAssembly.Table({element: "anyref", initial: 10});
let ins = wasmEvalText(
`(module
(import "m" "t" (table $t 10 anyref))
(import $t "m" "t" (table 10 anyref))
(func (export "f") (param $v anyref)
(table.set $t (i32.const 3) (local.get $v))))`,
{m:{t}});
@ -126,7 +126,7 @@ for (let v of VALUES)
let t = new WebAssembly.Table({element: "anyref", initial: 10});
let ins = wasmEvalText(
`(module
(import "m" "t" (table $t 10 anyref))
(import $t "m" "t" (table 10 anyref))
(func (export "f") (result anyref)
(table.get $t (i32.const 3))))`,
{m:{t}});
@ -143,8 +143,8 @@ for (let v of VALUES)
let receiver = function (w) { assertEq(w, v); };
let ins = wasmEvalText(
`(module
(import "m" "returner" (func $returner (result anyref)))
(import "m" "receiver" (func $receiver (param anyref)))
(import $returner "m" "returner" (func (result anyref)))
(import $receiver "m" "receiver" (func (param anyref)))
(func (export "test_returner") (result anyref)
(call $returner))
(func (export "test_receiver") (param $v anyref)

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

@ -54,8 +54,8 @@ function js_anyref_stackarg(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, p) {
var ins1 = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(
`(module
(import "" "f" (func $f (param anyref)))
(import "" "g" (func $g (param i32) (param i32) (param i32) (param i32) (param i32)
(import $f "" "f" (func (param anyref)))
(import $g "" "g" (func (param i32) (param i32) (param i32) (param i32) (param i32)
(param i32) (param i32) (param i32) (param i32) (param i32)
(param anyref)))
(func (export "run1") (param anyref) (result anyref)
@ -97,8 +97,8 @@ function js_returns_anyref(p) {
var ins2 = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(
`(module
(import "" "f" (func $f (result anyref)))
(import "" "g" (func $g (param anyref)))
(import $f "" "f" (func (result anyref)))
(import $g "" "g" (func (param anyref)))
(func (export "run1") (result anyref)
(local $tmp anyref)
(local.set $tmp (call $f))

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

@ -9,7 +9,7 @@ let { exports } = wasmEvalText(`(module
(ref.eq (local.get $a) (local.get $b)))
(func (export "ref_eq_for_control") (param $a anyref) (param $b anyref) (result f64)
(if (result f64) (ref.eq (local.get $a) (local.get $b))
(if f64 (ref.eq (local.get $a) (local.get $b))
(f64.const 5.0)
(f64.const 3.0))))`);

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

@ -41,10 +41,10 @@ let simpleTests = [
"(module (func $test (local anyref)))",
"(module (func $test (param anyref)))",
"(module (func $test (result anyref) (ref.null)))",
"(module (func $test (block (result anyref) (unreachable)) unreachable))",
"(module (func $test (result i32) (local anyref) (ref.is_null (local.get 0))))",
`(module (import "a" "b" (func (param anyref))))`,
`(module (import "a" "b" (func (result anyref))))`,
"(module (func $test (block anyref (unreachable)) unreachable))",
"(module (func $test (local anyref) (result i32) (ref.is_null (local.get 0))))",
`(module (import "a" "b" (param anyref)))`,
`(module (import "a" "b" (result anyref)))`,
`(module (global anyref (ref.null)))`,
`(module (global (mut anyref) (ref.null)))`,
];
@ -62,7 +62,7 @@ let { exports } = wasmEvalText(`(module
ref.is_null
)
(func $sum (param i32) (result i32)
(func $sum (result i32) (param i32)
local.get 0
i32.const 42
i32.add
@ -94,19 +94,19 @@ assertEq(exports.is_null_local(), 1);
// Anyref param and result in wasm functions.
exports = wasmEvalText(`(module
(func (export "is_null") (param $ref anyref) (result i32)
(func (export "is_null") (result i32) (param $ref anyref)
local.get $ref
ref.is_null
)
(func (export "ref_or_null") (param $ref anyref) (param $selector i32) (result anyref)
(func (export "ref_or_null") (result anyref) (param $ref anyref) (param $selector i32)
local.get $ref
ref.null
local.get $selector
select (result anyref)
)
(func $recursive (export "nested") (param $ref anyref) (param $i i32) (result anyref)
(func $recursive (export "nested") (result anyref) (param $ref anyref) (param $i i32)
;; i == 10 => ret $ref
local.get $i
i32.const 10
@ -173,11 +173,11 @@ function assertJoin(body) {
assertEq(val.i, -1);
}
assertJoin("(block (result anyref) local.get $ref)");
assertJoin("(block $out (result anyref) local.get $ref br $out)");
assertJoin("(loop (result anyref) local.get $ref)");
assertJoin("(block anyref local.get $ref)");
assertJoin("(block $out anyref local.get $ref br $out)");
assertJoin("(loop anyref local.get $ref)");
assertJoin(`(block $out (result anyref) (loop $top (result anyref)
assertJoin(`(block $out anyref (loop $top anyref
local.get $i
i32.const 1
i32.add
@ -207,7 +207,7 @@ assertJoin(`(block $out (loop $top
)) unreachable
`);
assertJoin(`(block $out (result anyref) (loop $top
assertJoin(`(block $out anyref (loop $top
local.get $ref
local.get $i
i32.const 1
@ -220,7 +220,7 @@ assertJoin(`(block $out (result anyref) (loop $top
) unreachable)
`);
assertJoin(`(block $out (result anyref) (block $unreachable (result anyref) (loop $top
assertJoin(`(block $out anyref (block $unreachable anyref (loop $top
local.get $ref
local.get $i
i32.const 1
@ -286,8 +286,8 @@ let imports = {
};
exports = wasmEvalText(`(module
(import "funcs" "ret" (func $ret (result anyref)))
(import "funcs" "param" (func $param (param anyref)))
(import $ret "funcs" "ret" (result anyref))
(import $param "funcs" "param" (param anyref))
(func (export "param") (param $x anyref) (param $y anyref)
local.get $y
@ -314,8 +314,8 @@ assertEq(exports.ret(), imports.myBaguette);
// Check lazy stubs generation.
exports = wasmEvalText(`(module
(import "funcs" "mirror" (func $mirror (param anyref) (result anyref)))
(import "funcs" "augment" (func $augment (param anyref) (result anyref)))
(import $mirror "funcs" "mirror" (param anyref) (result anyref))
(import $augment "funcs" "augment" (param anyref) (result anyref))
(global $count_f (mut i32) (i32.const 0))
(global $count_g (mut i32) (i32.const 0))
@ -347,7 +347,7 @@ exports = wasmEvalText(`(module
(func (export "call_indirect") (param $i i32) (param $ref anyref) (result anyref)
local.get $ref
local.get $i
call_indirect (type $table_type)
call_indirect $table_type
)
(func (export "count_f") (result i32) global.get $count_f)

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

@ -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 (param anyref) (result anyref) local.get 0) (export "" (func 0)))')));`);
g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func (result anyref) (param anyref) local.get 0) (export "" 0))')));`);
})();
(function() {
@ -12,7 +12,7 @@
let src = `
(module
(func (export "func") (param $ref anyref) (result anyref)
(func (export "func") (result anyref) (param $ref anyref)
local.get $ref
)
)

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

@ -9,7 +9,7 @@ let simpleTests = [
"(module (func $test (local anyref)))",
"(module (func $test (param anyref)))",
"(module (func $test (result anyref) (ref.null)))",
"(module (func $test (block (result anyref) (unreachable)) unreachable))",
"(module (func $test (block anyref (unreachable)) unreachable))",
"(module (func $test (local anyref) (result i32) (ref.is_null (local.get 0))))",
`(module (import "a" "b" (param anyref)))`,
`(module (import "a" "b" (result anyref)))`,

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

@ -47,8 +47,8 @@ function js_funcref_stackarg(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, p) {
var ins1 = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(
`(module
(import "" "f" (func $f (param funcref)))
(import "" "g" (func $g (param i32) (param i32) (param i32) (param i32) (param i32)
(import $f "" "f" (func (param funcref)))
(import $g "" "g" (func (param i32) (param i32) (param i32) (param i32) (param i32)
(param i32) (param i32) (param i32) (param i32) (param i32)
(param funcref)))
(func (export "run1") (param funcref) (result funcref)

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

@ -18,9 +18,9 @@ wasmFailValidateText(`(module (global (mut funcref) (ref.null)) (func (param any
wasmEvalText(`(module (func (param funcref)) (func (param funcref) (call 0 (local.get 0))))`);
wasmEvalText(`(module (func (param anyref)) (func (param funcref) (call 0 (local.get 0))))`);
wasmFailValidateText(`(module (func (param funcref)) (func (param anyref) (call 0 (local.get 0))))`, typeErr);
wasmEvalText(`(module (func (param funcref) (result funcref) (block (result funcref) (local.get 0) (br 0))))`);
wasmEvalText(`(module (func (param funcref) (result anyref) (block (result anyref) (local.get 0) (br 0))))`);
wasmFailValidateText(`(module (func (param anyref) (result anyref) (block (result funcref) (local.get 0) (br 0))))`, typeErr);
wasmEvalText(`(module (func (param funcref) (result funcref) (block funcref (local.get 0) (br 0))))`);
wasmEvalText(`(module (func (param funcref) (result anyref) (block anyref (local.get 0) (br 0))))`);
wasmFailValidateText(`(module (func (param anyref) (result anyref) (block funcref (local.get 0) (br 0))))`, typeErr);
wasmEvalText(`(module (func (param funcref funcref) (result funcref) (select (result funcref) (local.get 0) (local.get 1) (i32.const 0))))`);
wasmEvalText(`(module (func (param anyref funcref) (result anyref) (select (result anyref) (local.get 0) (local.get 1) (i32.const 0))))`);
wasmEvalText(`(module (func (param funcref anyref) (result anyref) (select (result anyref)(local.get 0) (local.get 1) (i32.const 0))))`);
@ -46,7 +46,7 @@ var run = wasmEvalText(`(module
(func (export "run") (param $a funcref) (param $b funcref) (param $c funcref) (param $test1 i32) (param $test2 i32) (result funcref)
local.get $a
global.set 0
block (result funcref)
block funcref
local.get $b
local.get $test1
br_if 0
@ -79,23 +79,23 @@ var run = wasmEvalText(`(module
end $b0
ref.null
local.get 1
call_indirect (type $t0)
call_indirect $t0
return
end $b1
ref.null
local.get 1
call_indirect (type $t1)
call_indirect $t1
return
end $b2
ref.null
local.get 1
call_indirect (type $t2)
call_indirect $t2
return
end $b3
ref.null
ref.null
local.get 1
call_indirect (type $t3)
call_indirect $t3
return
)
)`).exports.run;

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

@ -15,8 +15,8 @@
var refmod = new WebAssembly.Module(wasmTextToBinary(
`(module
(gc_feature_opt_in 3)
(import "" "tbl" (table $tbl 4 funcref))
(import "" "print" (func $print (param i32)))
(import $tbl "" "tbl" (table 4 funcref))
(import $print "" "print" (func (param i32)))
;; Just a dummy
(type $s (struct (field i32)))
@ -34,17 +34,17 @@ var refmod = new WebAssembly.Module(wasmTextToBinary(
(ref.null))
(func (export "test_h")
(call_indirect (type $htype) (ref.null) (i32.const 2)))
(call_indirect $htype (ref.null) (i32.const 2)))
(func (export "test_i")
(drop (call_indirect (type $itype) (i32.const 3))))
(drop (call_indirect $itype (i32.const 3))))
)`));
var nonrefmod = new WebAssembly.Module(wasmTextToBinary(
`(module
(import "" "tbl" (table $tbl 4 funcref))
(import "" "print" (func $print (param i32)))
(import $tbl "" "tbl" (table 4 funcref))
(import $print "" "print" (func (param i32)))
(type $ftype (func (param i32)))
(type $gtype (func (result i32)))
@ -53,11 +53,11 @@ var nonrefmod = new WebAssembly.Module(wasmTextToBinary(
;; Should fail because of the signature mismatch: parameter
(func (export "test_f")
(call_indirect (type $ftype) (i32.const 37) (i32.const 0)))
(call_indirect $ftype (i32.const 37) (i32.const 0)))
;; Should fail because of the signature mismatch: return value
(func (export "test_g")
(drop (call_indirect (type $gtype) (i32.const 1))))
(drop (call_indirect $gtype (i32.const 1))))
(func $h (param i32)
(call $print (i32.const 2)))

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

@ -29,7 +29,7 @@ let effectful = { valueOf() { effect = true; },
let valueToReturn;
let ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
(module
(import "m" "g" (func $g (result nullref)))
(import $g "m" "g" (func (result nullref)))
(func (export "f")
(call $g)
(drop)))`)),
@ -152,28 +152,28 @@ new WebAssembly.Module(wasmTextToBinary(`
(table $t 10 nullref)
(table $u 10 nullref)
(func (export "f")
(table.copy $u $t (i32.const 0) (i32.const 0) (i32.const 2))))`));
(table.copy $u (i32.const 0) $t (i32.const 0) (i32.const 2))))`));
new WebAssembly.Module(wasmTextToBinary(`
(module
(table $t 10 nullref)
(table $u 10 anyref)
(func (export "f")
(table.copy $u $t (i32.const 0) (i32.const 0) (i32.const 2))))`));
(table.copy $u (i32.const 0) $t (i32.const 0) (i32.const 2))))`));
new WebAssembly.Module(wasmTextToBinary(`
(module
(table $t 10 nullref)
(table $u 10 funcref)
(func (export "f")
(table.copy $u $t (i32.const 0) (i32.const 0) (i32.const 2))))`));
(table.copy $u (i32.const 0) $t (i32.const 0) (i32.const 2))))`));
assertErrorMessage(() => new WebAssembly.Module(wasmTextToBinary(`
(module
(table $t 10 anyref)
(table $u 10 nullref)
(func (export "f")
(table.copy $u $t (i32.const 0) (i32.const 0) (i32.const 2))))`)),
(table.copy $u (i32.const 0) $t (i32.const 0) (i32.const 2))))`)),
WebAssembly.CompileError,
/expression has type anyref but expected nullref/);

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

@ -8,12 +8,12 @@ const v2vSigSection = sigSection([v2vSig]);
// 'ref.func' parses, validates and returns a non-null value
wasmFullPass(`
(module
(elem declare $run)
(elem declared $run)
(func $run (result i32)
ref.func $run
ref.is_null
)
(export "run" (func $run))
(export "run" $run)
)
`, 0);
@ -21,9 +21,9 @@ wasmFullPass(`
{
let {f1} = wasmEvalText(`
(module
(elem declare $f1)
(elem declared $f1)
(func $f1 (result funcref) ref.func $f1)
(export "f1" (func $f1))
(export "f1" $f1)
)
`).exports;
assertEq(f1(), f1);
@ -33,11 +33,11 @@ wasmFullPass(`
{
let {f1, f2} = wasmEvalText(`
(module
(elem declare $f1)
(elem declared $f1)
(func $f1)
(func $f2 (result funcref) ref.func $f1)
(export "f1" (func $f1))
(export "f2" (func $f2))
(export "f1" $f1)
(export "f2" $f2)
)
`).exports;
assertEq(f2(), f1);
@ -47,18 +47,18 @@ wasmFullPass(`
{
let i1 = wasmEvalText(`
(module
(elem declare $f1)
(elem declared $f1)
(func $f1)
(export "f1" (func $f1))
(export "f1" $f1)
)
`);
let i2 = wasmEvalText(`
(module
(import "" "f1" (func $f1))
(elem declare $f1)
(import $f1 "" "f1" (func))
(elem declared $f1)
(func $f2 (result funcref) ref.func $f1)
(export "f1" (func $f1))
(export "f2" (func $f2))
(export "f1" $f1)
(export "f2" $f2)
)
`, {"": i1.exports});
@ -93,7 +93,7 @@ assertErrorMessage(() => validFuncRefText('', 'funcref'), WebAssembly.CompileErr
// referenced function can be forward declared via segments
assertEq(validFuncRefText('(elem 0 (i32.const 0) func $referenced)', 'funcref') instanceof WebAssembly.Instance, true);
assertEq(validFuncRefText('(elem func $referenced)', 'funcref') instanceof WebAssembly.Instance, true);
assertEq(validFuncRefText('(elem declare $referenced)', 'funcref') instanceof WebAssembly.Instance, true);
assertEq(validFuncRefText('(elem declared $referenced)', 'funcref') instanceof WebAssembly.Instance, true);
// also when the segment is passive or active 'anyref'
assertEq(validFuncRefText('(elem 0 (i32.const 0) anyref (ref.func $referenced))', 'anyref') instanceof WebAssembly.Instance, true);
@ -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" (func $referenced))', 'funcref'),
assertErrorMessage(() => validFuncRefText('(export "referenced" $referenced)', 'funcref'),
WebAssembly.CompileError,
/function index is not in an element segment/);
@ -144,8 +144,8 @@ assertErrorMessage(() => new WebAssembly.Module(
var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
(module
(import "m" "f" (func $f (param i32) (result i32)))
(elem declare $f)
(import $f "m" "f" (func (param i32) (result i32)))
(elem declared $f)
(table 1 funcref)
(func (export "f")
(table.set 0 (i32.const 0) (ref.func $f))))`)),

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

@ -88,7 +88,7 @@
let bin = wasmTextToBinary(
`(module
(gc_feature_opt_in 3)
(import "" "g" (global $g anyref))
(import $g "" "g" (global anyref))
(global $glob anyref (global.get $g))
(func (export "get") (result anyref)
(global.get $glob)))`);

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

@ -83,13 +83,13 @@ assertErrorMessage(() => wasmCompile(
`(module
(gc_feature_opt_in 3)
(type $box (struct (field $x i32)))
(import "m" "f" (func (param (ref $box)))))`),
(import "m" "f" (param (ref $box))))`),
WebAssembly.CompileError,
/cannot expose indexed reference type/);
assertEq(typeof wasmCompile(
`(module
(import "m" "f" (func (param anyref))))`),
(import "m" "f" (param anyref)))`),
"object");
// Imported function can't return ref type, but anyref is OK.
@ -98,13 +98,13 @@ assertErrorMessage(() => wasmCompile(
`(module
(gc_feature_opt_in 3)
(type $box (struct (field $x i32)))
(import "m" "f" (func (param i32) (result (ref $box)))))`),
(import "m" "f" (param i32) (result (ref $box))))`),
WebAssembly.CompileError,
/cannot expose indexed reference type/);
assertEq(typeof wasmCompile(
`(module
(import "m" "f" (func (param i32) (result anyref))))`),
(import "m" "f" (param i32) (result anyref)))`),
"object");
// Imported global can't be of Ref type (irrespective of mutability), though anyref is OK.
@ -244,7 +244,7 @@ assertErrorMessage(() => wasmCompile(
(type $fn (func (param (ref $box))))
(table (export "tbl") 1 funcref)
(func (param i32)
(call_indirect (type $fn) (ref.null) (local.get 0))))`),
(call_indirect $fn (ref.null) (local.get 0))))`),
WebAssembly.CompileError,
/cannot expose indexed reference type/);
@ -255,7 +255,7 @@ assertErrorMessage(() => wasmCompile(
(type $fn (func (result (ref $box))))
(table (export "tbl") 1 funcref)
(func (param i32) (result (ref $box))
(call_indirect (type $fn) (local.get 0))))`),
(call_indirect $fn (local.get 0))))`),
WebAssembly.CompileError,
/cannot expose indexed reference type/);
@ -264,7 +264,7 @@ assertEq(typeof wasmCompile(
(type $fn (func (param anyref)))
(table (export "tbl") 1 funcref)
(func (param i32)
(call_indirect (type $fn) (ref.null) (local.get 0))))`),
(call_indirect $fn (ref.null) (local.get 0))))`),
"object");
assertEq(typeof wasmCompile(
@ -272,7 +272,7 @@ assertEq(typeof wasmCompile(
(type $fn (func (result anyref)))
(table (export "tbl") 1 funcref)
(func (param i32) (result anyref)
(call_indirect (type $fn) (local.get 0))))`),
(call_indirect $fn (local.get 0))))`),
"object");
// Can't call via imported table with type that is exposed for Ref, though anyref is OK.
@ -284,7 +284,7 @@ assertErrorMessage(() => wasmCompile(
(type $fn (func (param (ref $box))))
(import "m" "tbl" (table 1 funcref))
(func (param i32)
(call_indirect (type $fn) (ref.null) (local.get 0))))`),
(call_indirect $fn (ref.null) (local.get 0))))`),
WebAssembly.CompileError,
/cannot expose indexed reference type/);
@ -295,7 +295,7 @@ assertErrorMessage(() => wasmCompile(
(type $fn (func (result (ref $box))))
(import "m" "tbl" (table 1 funcref))
(func (param i32) (result (ref $box))
(call_indirect (type $fn) (local.get 0))))`),
(call_indirect $fn (local.get 0))))`),
WebAssembly.CompileError,
/cannot expose indexed reference type/);
@ -304,7 +304,7 @@ assertEq(typeof wasmCompile(
(type $fn (func (param anyref)))
(import "m" "tbl" (table 1 funcref))
(func (param i32)
(call_indirect (type $fn) (ref.null) (local.get 0))))`),
(call_indirect $fn (ref.null) (local.get 0))))`),
"object");
assertEq(typeof wasmCompile(
@ -312,7 +312,7 @@ assertEq(typeof wasmCompile(
(type $fn (func (result anyref)))
(import "m" "tbl" (table 1 funcref))
(func (param i32) (result anyref)
(call_indirect (type $fn) (local.get 0))))`),
(call_indirect $fn (local.get 0))))`),
"object");
// We can call via a private table with a type that is exposed for Ref.
@ -327,7 +327,7 @@ assertEq(typeof wasmCompile(
(elem (i32.const 0) $f1)
(func $f1 (param (ref $box)) (result i32) (i32.const 37))
(func (export "f") (param i32) (result i32)
(call_indirect (type $fn) (ref.null) (local.get 0))))`);
(call_indirect $fn (ref.null) (local.get 0))))`);
let i = new WebAssembly.Instance(m).exports;
assertEq(i.f(0), 37);
}

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

@ -24,9 +24,9 @@ function checkInvalid(body, errorMessage) {
`(module
(gc_feature_opt_in 3)
(import "" "print_lp" (func $print_lp))
(import "" "print_rp" (func $print_rp))
(import "" "print_int" (func $print_int (param i32)))
(import $print_lp "" "print_lp" (func))
(import $print_rp "" "print_rp" (func))
(import $print_int "" "print_int" (func (param i32)))
(type $wabbit (struct
(field $x (mut i32))
@ -44,9 +44,9 @@ function checkInvalid(body, errorMessage) {
(local $tmp i32)
(local.set $tmp (global.get $k))
(global.set $k (i32.add (local.get $tmp) (i32.const 1)))
(if (result (ref $wabbit)) (i32.le_s (local.get $n) (i32.const 2))
(if (ref $wabbit) (i32.le_s (local.get $n) (i32.const 2))
(struct.new $wabbit (local.get $tmp) (ref.null) (ref.null))
(block (result (ref $wabbit))
(block (ref $wabbit)
(struct.new $wabbit
(local.get $tmp)
(call $make (i32.sub (local.get $n) (i32.const 1)))
@ -56,7 +56,7 @@ function checkInvalid(body, errorMessage) {
(call $accum (global.get $g)))
(func $accum (param $w (ref $wabbit)) (result i32)
(if (result i32) (ref.is_null (local.get $w))
(if i32 (ref.is_null (local.get $w))
(i32.const 0)
(i32.add (struct.get $wabbit 0 (local.get $w))
(i32.sub (call $accum (struct.get $wabbit 1 (local.get $w)))
@ -400,8 +400,8 @@ assertErrorMessage(() => wasmEvalText(
(type $node (struct (field i32)))
(func $f (param $p (ref $node)) (result anyref)
(struct.narrow i32 anyref (local.get 0))))`),
WebAssembly.CompileError,
/invalid reference type/);
SyntaxError,
/struct.narrow requires ref type/);
assertErrorMessage(() => wasmEvalText(
`(module
@ -409,8 +409,8 @@ assertErrorMessage(() => wasmEvalText(
(type $node (struct (field i32)))
(func $f (param $p (ref $node)) (result anyref)
(struct.narrow anyref i32 (local.get 0))))`),
WebAssembly.CompileError,
/invalid reference type/);
SyntaxError,
/struct.narrow requires ref type/);
// source and target types must be ref types: binary format

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

@ -37,8 +37,8 @@ var bin = wasmTextToBinary(
(local.set $l (call $cdr (local.get $p)))
;; TODO: eventually also a test with global.get
;; blocks and if with result type
(block (result (ref $cons))
(if (result (ref $cons)) (i32.eqz (i32.const 0))
(block (ref $cons)
(if (ref $cons) (i32.eqz (i32.const 0))
(unreachable)
(ref.null))))
@ -92,7 +92,7 @@ assertErrorMessage(() => wasmEvalText(`
(gc_feature_opt_in 3)
(func (param (ref $odd)) (unreachable)))
`),
SyntaxError, /failed to find type/);
SyntaxError, /Type label.*not found/);
// Ref type mismatch in parameter is allowed through the prefix rule
// but not if the structs are incompatible.
@ -193,7 +193,7 @@ assertErrorMessage(() => wasmEvalText(`
(type $x (func (param i32)))
(func $f (param (ref $x)) (unreachable)))
`),
WebAssembly.CompileError, /ref does not reference a struct type/);
SyntaxError, /Type label.*not found/);
assertErrorMessage(() => wasmEvalText(`
(module

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

@ -17,19 +17,19 @@ const {Module,Instance} = WebAssembly;
let t =
`(module
(import "" "check3" (func $check3 (param anyref) (param anyref) (param anyref)))
(import $check3 "" "check3" (func (param anyref) (param anyref) (param anyref)))
(type $typeOfFn0
(func (param i32) (param anyref) (param i32)
(param anyref) (param anyref) (param i32) (result i32)))
(func (result i32) (param i32) (param anyref) (param i32)
(param anyref) (param anyref) (param i32)))
(table 1 1 funcref)
(elem (i32.const 0) $fn0)
(import "" "alloc" (func $alloc (result anyref)))
(import $alloc "" "alloc" (func (result anyref)))
;; -- fn 0
(func $fn0 (export "fn0")
(param $arg1 i32) (param $arg2 anyref) (param $arg3 i32)
(param $arg4 anyref) (param $arg5 anyref) (param $arg6 i32) (result i32)
(result i32) (param $arg1 i32) (param $arg2 anyref) (param $arg3 i32)
(param $arg4 anyref) (param $arg5 anyref) (param $arg6 i32)
(call $alloc)
drop
(i32.add (i32.add (local.get $arg1) (local.get $arg3)) (local.get $arg6))
@ -43,13 +43,13 @@ let t =
(func $fn1 (export "fn1") (param $arg1 anyref) (result i32)
(local $i i32)
(loop (result i32)
(loop i32
;; call direct 0
(call $fn0 (i32.const 10) (local.get $arg1) (i32.const 12)
(local.get $arg1) (local.get $arg1) (i32.const 15))
;; call indirect 0
(call_indirect (type $typeOfFn0)
(call_indirect $typeOfFn0
(i32.const 10) (local.get $arg1) (i32.const 12)
(local.get $arg1) (local.get $arg1) (i32.const 15)
(i32.const 0)) ;; table index

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

@ -29,19 +29,19 @@ const DEBUG = false;
let t =
`(module
(type $typeOfFn0
(func (param i32) (param anyref) (param i32)
(param anyref) (param anyref) (param i32) (result i32)))
(func (result i32) (param i32) (param anyref) (param i32)
(param anyref) (param anyref) (param i32)))
(table 1 1 funcref)
(elem (i32.const 0) $fn0)
(import "" "alloc" (func $alloc (result anyref)))
(import "" "quitp" (func $quitp (result i32)))
(import "" "check3" (func $check3 (param anyref) (param anyref) (param anyref)))
(import $alloc "" "alloc" (func (result anyref)))
(import $quitp "" "quitp" (func (result i32)))
(import $check3 "" "check3" (func (param anyref) (param anyref) (param anyref)))
;; -- fn 0
(func $fn0 (export "fn0")
(param $arg1 i32) (param $arg2 anyref) (param $arg3 i32)
(param $arg4 anyref) (param $arg5 anyref) (param $arg6 i32) (result i32)
(result i32) (param $arg1 i32) (param $arg2 anyref) (param $arg3 i32)
(param $arg4 anyref) (param $arg5 anyref) (param $arg6 i32)
(local $i i32)
;; spinloop to waste time
@ -59,13 +59,13 @@ let t =
;; -- fn 1
(func $fn1 (export "fn1") (param $arg1 anyref) (result i32)
(loop (result i32)
(loop i32
;; call direct to $fn0
(call $fn0 (i32.const 10) (local.get $arg1) (i32.const 12)
(local.get $arg1) (local.get $arg1) (i32.const 15))
;; call indirect to table index 0, which is $fn0
(call_indirect (type $typeOfFn0)
(call_indirect $typeOfFn0
(i32.const 10) (local.get $arg1) (i32.const 12)
(local.get $arg1) (local.get $arg1) (i32.const 15)
(i32.const 0)) ;; table index

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

@ -24,16 +24,16 @@ const DEBUG = false;
let t =
`(module
(import "" "mkCons" (func $mkCons (param anyref) (param anyref) (result anyref)))
(import "" "mkBoxedInt" (func $mkBoxedInt (result anyref)))
(import $mkCons "" "mkCons" (func (result anyref)
(param anyref) (param anyref)))
(import $mkBoxedInt "" "mkBoxedInt" (func (result anyref)))
(func $mkNil (result anyref)
ref.null
)
(func $mkConsIgnoringScalar
(func $mkConsIgnoringScalar (result anyref)
(param $hd anyref) (param i32) (param $tl anyref)
(result anyref)
(local.get $hd)
(local.get $tl)
call $mkCons

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

@ -22,8 +22,8 @@ function visit(aStuff) {
let bin = wasmTextToBinary(
`
(module
(import "" "allocate" (func $allocate (param i32) (result anyref)))
(import "" "visit" (func $visit (param anyref) (result i32)))
(import $allocate "" "allocate" (func (result anyref) (param i32)))
(import $visit "" "visit" (func (result i32) (param anyref)))
;; A function with many params and locals, most of which are ref-typed.
;; The purpose of having so many is to defeat any reasonable attempt at
@ -32,10 +32,10 @@ let bin = wasmTextToBinary(
;; vs what the stackmap claims the layout to be.
(func $manyParamsAndLocals (export "manyParamsAndLocals")
(result i32)
(param $p1 anyref) (param $p2 i32) (param $p3 anyref)
(param $p4 anyref) (param $p5 anyref) (param $p6 anyref)
(param $p7 anyref) (param $p8 anyref) (param $p9 i32)
(result i32)
(local $l1 anyref) (local $l2 anyref) (local $l3 anyref)
(local $l4 i32) (local $l5 anyref) (local $l6 i32)
(local $l7 anyref) (local $l8 anyref) (local $l9 anyref)

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

@ -44,7 +44,7 @@ var bin = wasmTextToBinary(
(func $x2 (import "m" "x2") (type $f2))
(func (export "hello") (param f64) (param i32) (result f64)
(call_indirect (type $f2) (local.get 0) (local.get 1)))
(call_indirect $f2 (local.get 0) (local.get 1)))
(func $doit (param f64) (result f64)
(f64.sqrt (local.get 0)))
@ -484,7 +484,7 @@ assertErrorMessage(() => wasmTextToBinary(
(type $t (struct (field $x i32)))
)`),
SyntaxError,
/duplicate identifier for field/);
/duplicate field name/);
// negative tests
@ -571,7 +571,7 @@ assertErrorMessage(() => wasmEvalText(`
(type $s (struct (field $x i32)))
(type $s (struct (field $y i32))))
`),
SyntaxError, /duplicate identifier for type/);
SyntaxError, /duplicate type name/);
// Bogus type definition syntax.
@ -580,35 +580,35 @@ assertErrorMessage(() => wasmEvalText(`
(gc_feature_opt_in 3)
(type $s))
`),
SyntaxError, /wasm text error/);
SyntaxError, /parsing wasm text/);
assertErrorMessage(() => wasmEvalText(`
(module
(gc_feature_opt_in 3)
(type $s (field $x i32)))
`),
SyntaxError, /expected `func` or `struct`/);
SyntaxError, /bad type definition/);
assertErrorMessage(() => wasmEvalText(`
(module
(gc_feature_opt_in 3)
(type $s (struct (field $x i31))))
`),
SyntaxError, /wasm text error/);
SyntaxError, /parsing wasm text/);
assertErrorMessage(() => wasmEvalText(`
(module
(gc_feature_opt_in 3)
(type $s (struct (fjeld $x i32))))
`),
SyntaxError, /wasm text error/);
SyntaxError, /parsing wasm text/);
assertErrorMessage(() => wasmEvalText(`
(module
(gc_feature_opt_in 3)
(type $s (struct abracadabra)))
`),
SyntaxError, /wasm text error/);
SyntaxError, /parsing wasm text/);
// Function should not reference struct type: syntactic test

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

@ -91,7 +91,7 @@ new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(
(table 5 funcref)
(elem (table 1) (i32.const 0) func $f1 $f2 $f3 $f4 $f5)
(func (export "f")
(table.copy 0 1 (i32.const 5) (i32.const 0) (i32.const 5))))`)));
(table.copy 0 (i32.const 5) 1 (i32.const 0) (i32.const 5))))`)));
ins.exports.f();
let t = ins.exports.t;
let xs = [];
@ -112,7 +112,7 @@ assertErrorMessage(() => new WebAssembly.Module(wasmTextToBinary(
(table 10 funcref)
(table 10 anyref)
(func (export "f")
(table.copy 0 1 (i32.const 0) (i32.const 0) (i32.const 5))))`)),
(table.copy 0 (i32.const 0) 1 (i32.const 0) (i32.const 5))))`)),
WebAssembly.CompileError,
/expression has type anyref but expected funcref/);
@ -187,7 +187,7 @@ assertErrorMessage(() => new WebAssembly.Module(wasmTextToBinary(
(table 10 anyref)
(type $t (func (param i32) (result i32)))
(func (result i32)
(call_indirect (type $t) (i32.const 37))))`)),
(call_indirect $t (i32.const 37))))`)),
WebAssembly.CompileError,
/indirect calls must go through a table of 'funcref'/);

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

@ -16,8 +16,8 @@ var ins = wasmEvalText(
(table $t1 2 funcref)
(table $t2 2 funcref)
(type $ftype (func (param i32) (result i32)))
(elem (table $t1) (i32.const 0) func $f1 $f2)
(elem (table $t2) (i32.const 0) func $f3 $f4)
(elem $t1 (i32.const 0) func $f1 $f2)
(elem $t2 (i32.const 0) func $f3 $f4)
(func $f1 (param $n i32) (result i32)
(i32.add (local.get $n) (i32.const 1)))
(func $f2 (param $n i32) (result i32)
@ -27,9 +27,9 @@ var ins = wasmEvalText(
(func $f4 (param $n i32) (result i32)
(i32.add (local.get $n) (i32.const 4)))
(func (export "f") (param $fn i32) (param $n i32) (result i32)
(call_indirect $t1 (type $ftype) (local.get $n) (local.get $fn)))
(call_indirect $t1 $ftype (local.get $n) (local.get $fn)))
(func (export "g") (param $fn i32) (param $n i32) (result i32)
(call_indirect $t2 (type $ftype) (local.get $n) (local.get $fn))))`).exports;
(call_indirect $t2 $ftype (local.get $n) (local.get $fn))))`).exports;
assertEq(ins.f(0, 10), 11);
assertEq(ins.f(1, 10), 12);
@ -65,25 +65,25 @@ var ins = wasmEvalText(
(table $t0 (import "m" "t0") 2 funcref)
(type $id_i32_t (func (param i32) (result i32)))
(func $id_i32 (param i32) (result i32) (local.get 0))
(elem (table $t0) (i32.const 1) func $id_i32)
(elem $t0 (i32.const 1) func $id_i32)
(table $t1 (import "m" "t1") 3 anyref)
(table $t2 (import "m" "t2") 4 funcref)
(type $id_f64_t (func (param f64) (result f64)))
(func $id_f64 (param f64) (result f64) (local.get 0))
(elem (table $t2) (i32.const 3) func $id_f64)
(elem $t2 (i32.const 3) func $id_f64)
(table $t3 (import "m" "t3") 5 anyref)
(func (export "f0") (param i32) (result i32)
(call_indirect $t0 (type $id_i32_t) (local.get 0) (i32.const 1)))
(call_indirect $t0 $id_i32_t (local.get 0) (i32.const 1)))
(func (export "f1") (param anyref)
(table.set $t1 (i32.const 2) (local.get 0)))
(func (export "f2") (param f64) (result f64)
(call_indirect $t2 (type $id_f64_t) (local.get 0) (i32.const 3)))
(call_indirect $t2 $id_f64_t (local.get 0) (i32.const 3)))
(func (export "f3")
(table.set $t3 (i32.const 4) (table.get $t1 (i32.const 2)))))`,
@ -133,7 +133,7 @@ var ins = wasmEvalText(
(table $t0 (import "m" "t0") 2 anyref)
(table $t1 (import "m" "t1") 3 anyref)
(func (export "f") (param $dest i32) (param $src i32) (param $len i32)
(table.copy $t1 $t0 (local.get $dest) (local.get $src) (local.get $len))))`,
(table.copy $t1 (local.get $dest) $t0 (local.get $src) (local.get $len))))`,
exp);
exp.m.t0.set(0, {x:0});
@ -178,10 +178,10 @@ assertEq(ins.exports.get(1), values[1]);
// - local tables can be exported and re-imported in another module
var arg = 4;
for (let [a,b,x,y,result,init] of [['$t0', '$t1', '(export "t")', '', arg*13, true],
['$t0', '$t1', '', '(export "t")', arg*13, true],
['$t0', '$t1', '(import "m" "t")', '', arg*13, true],
['$t1', '$t0', '(import "m" "t")', '', arg-11, false]])
for (let [x,y,result,init] of [['(export "t")', '', arg*13, true],
['', '(export "t")', arg*13, true],
['(import "m" "t")', '', arg*13, true],
['', '(import "m" "t")', arg-11, false]])
{
var otherins = wasmEvalText(
`(module
@ -189,21 +189,21 @@ for (let [a,b,x,y,result,init] of [['$t0', '$t1', '(export "t")', '', arg*13, tr
(type $fn1 (func (param i32) (result i32)))
(func $f1 (param $n i32) (result i32)
(i32.sub (local.get $n) (i32.const 11)))
(elem (table $t) (i32.const 1) func $f1))`);
(elem $t (i32.const 1) func $f1))`);
let text =
`(module
(table ${a} ${x} 2 funcref)
(table $t0 ${x} 2 funcref)
(table ${b} ${y} 2 funcref)
(table $t1 ${y} 2 funcref)
(type $fn1 (func (param i32) (result i32)))
(func $f1 (param $n i32) (result i32)
(i32.mul (local.get $n) (i32.const 13)))
${init ? "(elem (table $t1) (i32.const 1) func $f1)" : ""}
${init ? "(elem $t1 (i32.const 1) func $f1)" : ""}
(func (export "f") (param $n i32) (result i32)
(table.copy $t0 $t1 (i32.const 0) (i32.const 0) (i32.const 2))
(call_indirect $t0 (type $fn1) (local.get $n) (i32.const 1))))`;
(table.copy $t0 (i32.const 0) $t1 (i32.const 0) (i32.const 2))
(call_indirect $t0 $fn1 (local.get $n) (i32.const 1))))`;
var ins = wasmEvalText(text, {m: otherins.exports});
assertEq(ins.exports.f(arg), result);
@ -219,8 +219,8 @@ var exp = {m: {t0: tbl, t1:tbl}};
var ins = wasmEvalText(
`(module
(import "m" "t0" (table $t0 1 anyref))
(import "m" "t1" (table $t1 1 anyref))
(import $t0 "m" "t0" (table 1 anyref))
(import $t1 "m" "t1" (table 1 anyref))
(table $t2 (export "t2") 1 funcref)
(func (export "f") (result i32)
(table.grow $t0 (ref.null) (i32.const 1)))
@ -251,7 +251,7 @@ var ins = wasmEvalText(
(func $f1 (param i32) (result i32)
(i32.sub (local.get 0) (i32.const 11)))
(func (export "call") (param i32) (param i32) (result i32)
(call_indirect $t1 (type $ftype) (local.get 1) (local.get 0)))
(call_indirect $t1 $ftype (local.get 1) (local.get 0)))
(func (export "init")
(table.init $t1 0 (i32.const 0) (i32.const 0) (i32.const 2))))`);
@ -279,9 +279,9 @@ var ins = wasmEvalText(
(func (export "f") (param $n f64) (result f64)
(f64.mul (local.get $n) (f64.const 3.25)))
(func (export "do0") (param $i i32) (param $n f64) (result f64)
(call_indirect $t0 (type $ftype) (local.get $n) (local.get $i)))
(call_indirect $t0 $ftype (local.get $n) (local.get $i)))
(func (export "do1") (param $i i32) (param $n f64) (result f64)
(call_indirect $t1 (type $ftype) (local.get $n) (local.get $i))))`,
(call_indirect $t1 $ftype (local.get $n) (local.get $i))))`,
exp);
var ins2 = wasmEvalText(
`(module
@ -289,9 +289,9 @@ var ins2 = wasmEvalText(
(import "m" "t1" (table $t1 2 funcref))
(type $ftype (func (param f64) (result f64)))
(func (export "do0") (param $i i32) (param $n f64) (result f64)
(call_indirect $t0 (type $ftype) (local.get $n) (local.get $i)))
(call_indirect $t0 $ftype (local.get $n) (local.get $i)))
(func (export "do1") (param $i i32) (param $n f64) (result f64)
(call_indirect $t1 (type $ftype) (local.get $n) (local.get $i))))`,
(call_indirect $t1 $ftype (local.get $n) (local.get $i))))`,
exp);
assertEq(tbl.grow(10), 2);
@ -342,7 +342,7 @@ assertErrorMessage(() => wasmEvalText(
(table $t0 2 anyref)
(table $t1 2 anyref)
(func $f (param anyref)
(table.copy 0 2 (i32.const 0) (i32.const 0) (i32.const 2))))`),
(table.copy 0 (i32.const 0) 2 (i32.const 0) (i32.const 2))))`),
WebAssembly.CompileError,
/table index out of range for table.copy/);
@ -351,7 +351,7 @@ assertErrorMessage(() => wasmEvalText(
(table $t0 2 anyref)
(table $t1 2 anyref)
(func $f (param anyref)
(table.copy 2 0 (i32.const 0) (i32.const 0) (i32.const 2))))`),
(table.copy 2 (i32.const 0) 0 (i32.const 0) (i32.const 2))))`),
WebAssembly.CompileError,
/table index out of range for table.copy/);
@ -394,7 +394,7 @@ assertErrorMessage(() => wasmEvalText(
(table $t0 2 funcref)
(type $ft (func (param f64) (result i32)))
(func $f (result i32)
(call_indirect 2 (type $ft) (f64.const 3.14) (i32.const 0))))`),
(call_indirect 2 $ft (f64.const 3.14) (i32.const 0))))`),
WebAssembly.CompileError,
/table index out of range for call_indirect/);
@ -407,7 +407,7 @@ assertErrorMessage(() => wasmEvalText(
(func $f (result i32)
(table.init $t0 (i32.const 0) (i32.const 0) (i32.const 0))))`), // no segment
SyntaxError,
/failed to find elem/);
/expected element segment reference/);
assertErrorMessage(() => wasmEvalText(
`(module
@ -416,7 +416,7 @@ assertErrorMessage(() => wasmEvalText(
(func $f
(table.copy 0 (i32.const 0) (i32.const 0) (i32.const 2))))`), // target without source
SyntaxError,
/expected an identifier/);
/source is required if target is specified/);
assertErrorMessage(() => wasmEvalText(
`(module
@ -425,7 +425,7 @@ assertErrorMessage(() => wasmEvalText(
(func $f
(table.copy (i32.const 0) 0 (i32.const 0) (i32.const 2))))`), // source without target
SyntaxError,
/wasm text error/);
/parsing wasm text/);
// Make sure that dead code doesn't prevent compilation.
wasmEvalText(

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

@ -3,9 +3,9 @@
for ( let prefix of ['', '(table $prefix 0 32 funcref)']) {
let mod = new WebAssembly.Module(wasmTextToBinary(
`(module
(import "m" "item" (func $item (result anyref)))
${prefix}
(table $tbl 0 anyref)
(import $item "m" "item" (func (result anyref)))
(func (export "run") (param $numiters i32)
(local $i i32)
(local $j i32)

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

@ -1,10 +1,9 @@
const { Instance, Module, LinkError } = WebAssembly;
// Locally-defined globals
assertErrorMessage(() => wasmEvalText(`(module (global))`), SyntaxError, /wasm text error/);
// A global field in the text format is valid with an empty expression, but this produces an invalid module
assertErrorMessage(() => wasmEvalText(`(module (global i32))`), WebAssembly.CompileError, /unexpected initializer expression/);
assertErrorMessage(() => wasmEvalText(`(module (global (mut i32)))`), WebAssembly.CompileError, /unexpected initializer expression/);
assertErrorMessage(() => wasmEvalText(`(module (global))`), SyntaxError, /parsing/);
assertErrorMessage(() => wasmEvalText(`(module (global i32))`), SyntaxError, /parsing/);
assertErrorMessage(() => wasmEvalText(`(module (global (mut i32)))`), SyntaxError, /parsing/);
// Initializer expressions.
wasmFailValidateText(`(module (global i32 (f32.const 13.37)))`, /type mismatch/);
@ -26,10 +25,10 @@ function testInner(type, initialValue, nextValue, coercion)
(func $get_cst (result ${type}) (global.get 1))
(export "get" (func $get))
(export "get_cst" (func $get_cst))
(export "get" $get)
(export "get_cst" $get_cst)
(export "set" (func $set))
(export "set" $set)
)`).exports;
assertEq(module.get(), coercion(initialValue));
@ -69,11 +68,11 @@ var module = wasmEvalText(`(module
${get_set(3, 'f64')}
${get_set(4, 'i32')}
(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))
(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)
)`).exports;
let values = [42, 10, Math.fround(13.37), 13.37, -18];
@ -99,7 +98,7 @@ module = wasmEvalText(`(module
(table (export "tbl") 4 funcref)
(elem (global.get 0) $f)
(func $f)
(export "f" (func $f))
(export "f" $f)
)`, {
globals: {
a: 1
@ -109,10 +108,10 @@ assertEq(module.f, module.tbl.get(1));
// Import/export semantics.
module = wasmEvalText(`(module
(import "globals" "x" (global $g i32))
(import $g "globals" "x" (global i32))
(func $get (result i32) (global.get $g))
(export "getter" (func $get))
(export "value" (global 0))
(export "getter" $get)
(export "value" global 0)
)`, { globals: {x: 42} }).exports;
assertEq(module.getter(), 42);
@ -169,8 +168,8 @@ for (let v of [
module = wasmEvalText(`(module
(import "globals" "x" (global i32))
(global i32 (i32.const 1337))
(export "imported" (global 0))
(export "defined" (global 1))
(export "imported" global 0)
(export "defined" global 1)
)`, { globals: {x: 42} }).exports;
assertEq(Number(module.imported), 42);
@ -197,11 +196,11 @@ function testInitExpr(type, initialValue, nextValue, coercion, assertFunc = asse
(func $get_cst (result ${type}) (global.get 2))
(export "get0" (func $get0))
(export "get1" (func $get1))
(export "get_cst" (func $get_cst))
(export "get0" $get0)
(export "get1" $get1)
(export "get_cst" $get_cst)
(export "set1" (func $set1))
(export "set1" $set1)
(export "global_imm" (global $glob_imm))
)`, {
globals: {
@ -238,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" (func $get))
(export "get_cst" (func $get_cst))
(export "set" (func $set))
(export "get" $get)
(export "get_cst" $get_cst)
(export "set" $set)
)`, [
{type: 'i64', func: '$get', expected: initialValue},
{type: 'i64', func: '$set', args: [`i64.const ${nextValue}`]},
@ -353,15 +352,15 @@ wasmAssert(`(module
// When a global is exported twice, the two objects are the same.
let i = wasmEvalText(`(module
(global i32 (i32.const 0))
(export "a" (global 0))
(export "b" (global 0)))`);
(export "a" global 0)
(export "b" global 0))`);
assertEq(i.exports.a, i.exports.b);
// When a global is imported and then exported, the exported object is
// the same as the imported object.
let j = wasmEvalText(`(module
(import "" "a" (global i32))
(export "x" (global 0)))`,
(export "x" global 0))`,
{ "": {a: i.exports.a}});
assertEq(i.exports.a, j.exports.x);
@ -372,8 +371,8 @@ wasmAssert(`(module
let k = wasmEvalText(`(module
(import "" "a" (global i32))
(import "" "b" (global i32))
(export "x" (global 0))
(export "y" (global 1)))`,
(export "x" global 0)
(export "y" global 1))`,
{ "": {a: i.exports.a,
b: i.exports.a}});

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

@ -1,11 +1,11 @@
function linearModule(min, max, ops, current_memory, grow_memory) {
var opsText = ops.map(function (op) {
if (op[0] == "CM") {
res = `(if (result i32) (i32.ne (${current_memory}) (i32.const ${op[1]}))
res = `(if i32 (i32.ne (${current_memory}) (i32.const ${op[1]}))
(i32.load offset=10 (i32.const 4294967295))
(i32.const 0))`
} else if (op[0] == "GM") {
res = `(if (result i32) (i32.ne (${grow_memory} (i32.const ${op[1]})) (i32.const ${op[2]}))
res = `(if i32 (i32.ne (${grow_memory} (i32.const ${op[1]})) (i32.const ${op[2]}))
(i32.load offset=10 (i32.const 4294967295))
(i32.const 0))`
} else if (op[0] == "L") {
@ -36,7 +36,7 @@ function linearModule(min, max, ops, current_memory, grow_memory) {
(func (result i32)
(drop ` + opsText + `)
(${current_memory})
) (export "run" (func 0)))`;
) (export "run" 0))`;
return text;
}

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

@ -2,44 +2,44 @@
// signatures, in the test mode only, for fuzzers.
var module = new WebAssembly.Module(wasmTextToBinary(`(module
(import "env" "v_v" (func $vv))
(export "v_v" (func $vv))
(import $vv "env" "v_v")
(export "v_v" $vv)
(import "env" "v_i" (func $vi (param i32)))
(export "v_i" (func $vi))
(import $vi "env" "v_i" (param i32))
(export "v_i" $vi)
(import "env" "v_I" (func $vI (param i64)))
(export "v_I" (func $vI))
(import $vI "env" "v_I" (param i64))
(export "v_I" $vI)
(import "env" "v_f" (func $vf (param f32)))
(export "v_f" (func $vf))
(import $vf "env" "v_f" (param f32))
(export "v_f" $vf)
(import "env" "memory" (memory $mem 0))
(import $mem "env" "memory" (memory 0))
(export "mem" (memory $mem))
(import "env" "v_d" (func $vd (param f64)))
(export "v_d" (func $vd))
(import $vd "env" "v_d" (param f64))
(export "v_d" $vd)
(import "env" "v_fd" (func $vfd (param f32) (param f64)))
(export "v_fd" (func $vfd))
(import $vfd "env" "v_fd" (param f32) (param f64))
(export "v_fd" $vfd)
(import "env" "v_Ififd" (func $vIfifd (param i64) (param f32) (param i32) (param f32) (param f64)))
(export "v_Ififd" (func $vIfifd))
(import $vIfifd "env" "v_Ififd" (param i64) (param f32) (param i32) (param f32) (param f64))
(export "v_Ififd" $vIfifd)
(import "env" "i_v" (func $iv (result i32)))
(export "i_v" (func $iv))
(import $iv "env" "i_v" (result i32))
(export "i_v" $iv)
(import "env" "I_i" (func $Ii (param i32) (result i64)))
(export "I_i" (func $Ii))
(import $Ii "env" "I_i" (result i64) (param i32))
(export "I_i" $Ii)
(import "env" "table" (table $table 0 funcref))
(import $table "env" "table" (table 0 funcref))
(export "table" (table $table))
(import "env" "f_d" (func $fd (param f64) (result f32)))
(export "f_d" (func $fd))
(import $fd "env" "f_d" (result f32) (param f64))
(export "f_d" $fd)
(import "env" "d_ffd" (func $dffd (param f32) (param f32) (param f64) (result f64)))
(export "d_ffd" (func $dffd))
(import $dffd "env" "d_ffd" (result f64) (param f32) (param f32) (param f64))
(export "d_ffd" $dffd)
)`));
for (let desc of WebAssembly.Module.imports(module)) {

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

@ -44,7 +44,7 @@ assertErrorMessage(() => new Table({initial:10000001, element:"funcref"}), Range
new Table({ initial: 0, maximum: 10000000, element:"funcref" });
assertErrorMessage(() => new Table({initial:0, maximum: 10000001, element:"funcref"}), RangeError, /bad Table maximum size/);
const m1 = new Module(wasmTextToBinary('(module (import "foo" "bar" (func)) (import "baz" "quux" (func)))'));
const m1 = new Module(wasmTextToBinary('(module (import "foo" "bar") (import "baz" "quux"))'));
assertErrorMessage(() => new Instance(m1), TypeError, /second argument must be an object/);
assertErrorMessage(() => new Instance(m1, {foo:null}), TypeError, /import object field 'foo' is not an Object/);
assertErrorMessage(() => new Instance(m1, {foo:{bar:{}}}), LinkError, /import object field 'bar' is not a Function/);
@ -67,7 +67,7 @@ assertEq(new Instance(m2, {x:{y:mem3PageMax3}}) instanceof Instance, true);
assertEq(new Instance(m2, {x:{y:mem2PageMax3}}) instanceof Instance, true);
assertErrorMessage(() => new Instance(m2, {x:{y:mem2PageMax4}}), LinkError, /imported Memory with incompatible maximum size/);
const m3 = new Module(wasmTextToBinary('(module (import "foo" "bar" (memory 1 1)) (import "baz" "quux" (func)))'));
const m3 = new Module(wasmTextToBinary('(module (import "foo" "bar" (memory 1 1)) (import "baz" "quux"))'));
assertErrorMessage(() => new Instance(m3), TypeError, /second argument must be an object/);
assertErrorMessage(() => new Instance(m3, {foo:null}), TypeError, /import object field 'foo' is not an Object/);
assertErrorMessage(() => new Instance(m3, {foo:{bar:{}}}), LinkError, /import object field 'bar' is not a Memory/);
@ -76,7 +76,7 @@ assertErrorMessage(() => new Instance(m3, {foo:{bar:mem1Page}, baz:{quux:mem1Pag
assertErrorMessage(() => new Instance(m3, {foo:{bar:mem1Page}, baz:{quux:()=>{}}}), LinkError, /imported Memory with incompatible maximum size/);
assertEq(new Instance(m3, {foo:{bar:mem1PageMax1}, baz:{quux:()=>{}}}) instanceof Instance, true);
const m4 = new Module(wasmTextToBinary('(module (import "baz" "quux" (func)) (import "foo" "bar" (memory 1 1)))'));
const m4 = new Module(wasmTextToBinary('(module (import "baz" "quux") (import "foo" "bar" (memory 1 1)))'));
assertErrorMessage(() => new Instance(m4), TypeError, /second argument must be an object/);
assertErrorMessage(() => new Instance(m4, {baz:null}), TypeError, /import object field 'baz' is not an Object/);
assertErrorMessage(() => new Instance(m4, {baz:{quux:{}}}), LinkError, /import object field 'quux' is not a Function/);
@ -110,14 +110,14 @@ 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" (func $i2v)) (func $f2v (param f32)) (export "f2v" (func $f2v)))').exports;
var i2vm = new Module(wasmTextToBinary('(module (import "a" "b" (func (param i32))))'));
var f2vm = new Module(wasmTextToBinary('(module (import "a" "b" (func (param f32))))'));
var e = wasmEvalText('(module (func $i2v (param i32)) (export "i2v" $i2v) (func $f2v (param f32)) (export "f2v" $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);
assertErrorMessage(() => new Instance(i2vm, {a:{b:e.f2v}}), LinkError, /imported function 'a.b' signature mismatch/);
assertErrorMessage(() => new Instance(f2vm, {a:{b:e.i2v}}), LinkError, /imported function 'a.b' signature mismatch/);
assertEq(new Instance(f2vm, {a:{b:e.f2v}}) instanceof Instance, true);
var l2vm = new Module(wasmTextToBinary('(module (import "x" "y" (memory 1)) (import "c" "d" (func (param i64))))'));
var l2vm = new Module(wasmTextToBinary('(module (import "x" "y" (memory 1)) (import "c" "d" (param i64)))'));
assertErrorMessage(() => new Instance(l2vm, {x:{y:mem1Page}, c:{d:e.i2v}}), LinkError, /imported function 'c.d' signature mismatch/);
// Import order:
@ -178,30 +178,30 @@ 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" (func 0)))');
var code = wasmTextToBinary('(module (func) (export "foo" 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" (func 0)) (export "bar" (func 0)))');
var code = wasmTextToBinary('(module (func) (export "foo" 0) (export "bar" 0))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "foo,bar");
assertEq(e.foo(), undefined);
assertEq(e.bar(), undefined);
assertEq(e.foo, e.bar);
var code = wasmTextToBinary('(module (memory 1 1) (export "memory" (memory 0)))');
var code = wasmTextToBinary('(module (memory 1 1) (export "memory" memory))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "memory");
var code = wasmTextToBinary('(module (memory 1 1) (export "foo" (memory 0)) (export "bar" (memory 0)))');
var code = wasmTextToBinary('(module (memory 1 1) (export "foo" memory) (export "bar" memory))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "foo,bar");
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" (func 0)) (export "bar" (memory 0)))');
var code = wasmTextToBinary('(module (memory 1 1) (func) (export "foo" 0) (export "bar" memory))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "foo,bar");
assertEq(e.foo(), undefined);
@ -209,25 +209,25 @@ 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 0)) (export "foo" (func 0)))');
var code = wasmTextToBinary('(module (memory 1 1) (func) (export "bar" memory) (export "foo" 0))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "bar,foo");
assertEq(e.foo(), undefined);
assertEq(e.bar.buffer.byteLength, 64*1024);
var code = wasmTextToBinary('(module (memory 1 1) (export "" (memory 0)))');
var code = wasmTextToBinary('(module (memory 1 1) (export "" memory))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).length, 1);
assertEq(String(Object.keys(e)), "");
assertEq(e[""] instanceof Memory, true);
var code = wasmTextToBinary('(module (table 0 funcref) (export "tbl" (table 0)))');
var code = wasmTextToBinary('(module (table 0 funcref) (export "tbl" table))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "tbl");
assertEq(e.tbl instanceof Table, true);
assertEq(e.tbl.length, 0);
var code = wasmTextToBinary('(module (table 2 funcref) (export "t1" (table 0)) (export "t2" (table 0)))');
var code = wasmTextToBinary('(module (table 2 funcref) (export "t1" table) (export "t2" table))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "t1,t2");
assertEq(e.t1 instanceof Table, true);
@ -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 0)) (export "m" (memory 0)) (export "f" (func 0)))');
var code = wasmTextToBinary('(module (table 2 funcref) (memory 1 1) (func) (export "t" table) (export "m" memory) (export "f" 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 0)) (export "f" (func 0)) (export "t" (table 0)))');
var code = wasmTextToBinary('(module (table 1 funcref) (memory 1 1) (func) (export "m" memory) (export "f" 0) (export "t" table))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).join(), "m,f,t");
assertEq(e.f(), undefined);
@ -251,7 +251,7 @@ assertEq(e.t instanceof Table, true);
assertEq(e.m instanceof Memory, true);
+assertEq(e.t.length, 1);
var code = wasmTextToBinary('(module (table 0 funcref) (export "" (table 0)))');
var code = wasmTextToBinary('(module (table 0 funcref) (export "" table))');
var e = new Instance(new Module(code)).exports;
assertEq(Object.keys(e).length, 1);
assertEq(String(Object.keys(e)), "");
@ -267,12 +267,12 @@ var text = `(module
(table 4 funcref)
(elem (i32.const 0) $f)
(elem (i32.const 2) $g)
(export "f1" (func $f))
(export "tbl1" (table 0))
(export "f2" (func $f))
(export "tbl2" (table 0))
(export "f3" (func $h))
(func (export "run") (result i32) (call_indirect (type 0) (i32.const 2)))
(export "f1" $f)
(export "tbl1" table)
(export "f2" $f)
(export "tbl2" table)
(export "f3" $h)
(func (export "run") (result i32) (call_indirect 0 (i32.const 2)))
)`;
wasmFullPass(text, 2);
var e = new Instance(new Module(wasmTextToBinary(text))).exports;
@ -301,10 +301,10 @@ assertEq(e.tbl1.get(0), e.tbl1.get(3));
var args;
var m = new Module(wasmTextToBinary(`(module
(export "a" (func $a)) (import "" "a" (func $a (param f32)))
(export "b" (func $b)) (import "" "b" (func $b (param i32) (result i32)))
(export "c" (func $c)) (import "" "c" (func $c (result i32)))
(export "d" (func $d)) (import "" "d" (func $d))
(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")
)`));
var js = function() { args = arguments; return 42 }
var e = new Instance(m, {"":{a:js, b:js, c:js, d:js}}).exports;
@ -335,19 +335,19 @@ assertEq(args.length, 0);
// Re-exports and Identity:
var code = wasmTextToBinary('(module (import "a" "b" (memory 1 1)) (export "foo" (memory 0)) (export "bar" (memory 0)))');
var code = wasmTextToBinary('(module (import "a" "b" (memory 1 1)) (export "foo" memory) (export "bar" memory))');
var mem = new Memory({initial:1, maximum:1});
var e = new Instance(new Module(code), {a:{b:mem}}).exports;
assertEq(mem, e.foo);
assertEq(mem, e.bar);
var code = wasmTextToBinary('(module (import "a" "b" (table 1 1 funcref)) (export "foo" (table 0)) (export "bar" (table 0)))');
var code = wasmTextToBinary('(module (import "a" "b" (table 1 1 funcref)) (export "foo" table) (export "bar" table))');
var tbl = new Table({initial:1, maximum:1, element:"funcref"});
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" (func $foo)))');
var code = wasmTextToBinary('(module (import "a" "b" (table 2 2 funcref)) (func $foo) (elem (i32.const 0) $foo) (export "foo" $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));
@ -360,18 +360,18 @@ assertEq(tbl.get(0) === e1.foo, false);
assertEq(e1.foo === e2.foo, false);
var m = new Module(wasmTextToBinary(`(module
(import "" "foo" (func $foo (result i32)))
(import "" "bar" (func $bar (result i32)))
(table 3 funcref)
(import $foo "" "foo" (result i32))
(import $bar "" "bar" (result i32))
(func $baz (result i32) (i32.const 13))
(elem (i32.const 0) $foo $bar $baz)
(export "foo" (func $foo))
(export "bar" (func $bar))
(export "baz" (func $baz))
(export "tbl" (table 0))
(export "foo" $foo)
(export "bar" $bar)
(export "baz" $baz)
(export "tbl" table)
)`));
var jsFun = () => 83;
var wasmFun = new Instance(new Module(wasmTextToBinary('(module (func (result i32) (i32.const 42)) (export "foo" (func 0)))'))).exports.foo;
var wasmFun = new Instance(new Module(wasmTextToBinary('(module (func (result i32) (i32.const 42)) (export "foo" 0))'))).exports.foo;
var e1 = new Instance(m, {"":{foo:jsFun, bar:wasmFun}}).exports;
assertEq(jsFun === e1.foo, false);
assertEq(wasmFun, e1.bar);
@ -412,18 +412,18 @@ 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" (func $exp)))');
var code1 = wasmTextToBinary('(module (func $exp (param i64) (result i64) (i64.add (local.get 0) (i64.const 10))) (export "exp" $exp))');
var e1 = new Instance(new Module(code1)).exports;
var code2 = wasmTextToBinary('(module (import "a" "b" (func $i (param i64) (result i64))) (func $f (result i32) (i32.wrap/i64 (call $i (i64.const 42)))) (export "f" (func $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" $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" (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 0)))', /exported memory index out of bounds/);
wasmFailValidateText('(module (export "a" (table 0)))', /exported table index out of bounds/);
wasmFailValidateText('(module (export "a" 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/);
// Default memory/table rules
@ -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" (func $get)))
(export "get" $get))
`));
var mem = new Memory({initial:1, maximum:1});
var {get} = new Instance(m, {a:{b:mem}}).exports;
@ -492,16 +492,16 @@ var m = new Module(wasmTextToBinary(`
(module
(import "a" "mem" (memory 1))
(import "a" "tbl" (table 1 funcref))
(import "a" "memOff" (global $memOff i32))
(import "a" "tblOff" (global $tblOff i32))
(import $memOff "a" "memOff" (global i32))
(import $tblOff "a" "tblOff" (global i32))
(func $f)
(func $g)
(data (i32.const 0) "\\01")
(elem (i32.const 0) $f)
(data (global.get $memOff) "\\02")
(elem (global.get $tblOff) $g)
(export "f" (func $f))
(export "g" (func $g)))
(export "f" $f)
(export "g" $g))
`));
// Active segments are applied in order (this is observable if they overlap).
@ -646,33 +646,33 @@ 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" (func 1)))`)));
var i2 = new Instance(new Module(wasmTextToBinary(`(module (import "a" "b" (func $imp (param i32) (result i32))) (func $g (result i32) (call $imp (i32.const 13))) (export "g" (func $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" 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}});
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" (func $f))
(export "f" $f)
)`)));
var i2 = new Instance(new Module(wasmTextToBinary(`(module
(import "a" "b" (func $imp (result i32)))
(import $imp "a" "b" (result i32))
(memory 1 1)
(data (i32.const 0) "\\13")
(table 2 2 funcref)
(elem (i32.const 0) $imp $def)
(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" (func $call))
(func $call (param i32) (result i32) (call_indirect $v2i (local.get 0)))
(export "call" $call)
)`)), {a:{b:i1.exports.f}});
assertEq(i2.exports.call(0), 0x42);
assertEq(i2.exports.call(1), 0x13);
var m = new Module(wasmTextToBinary(`(module
(import "a" "val" (global $val i32))
(import "a" "next" (func $next (result i32)))
(import $val "a" "val" (global i32))
(import $next "a" "next" (result i32))
(memory 1)
(func $start (i32.store (i32.const 0) (global.get $val)))
(start $start)
@ -682,7 +682,7 @@ var m = new Module(wasmTextToBinary(`(module
(i32.add
(i32.load (i32.const 0))
(call $next))))
(export "call" (func $call))
(export "call" $call)
)`));
var e = {call:() => 1000};
for (var i = 0; i < 10; i++)
@ -721,11 +721,11 @@ assertEq(e.call(), 1090);
};
i = wasmEvalText(`(module
(import "a" "ffi" (func $ffi (param i32) (result i32)))
(import $ffi "a" "ffi" (param i32) (result i32))
(import "a" "sum" (func $missingOneArg (param i32) (param i32) (result i32)))
(import "a" "sum" (func $missingTwoArgs (param i32) (result i32)))
(import "a" "sum" (func $missingThreeArgs (result i32)))
(import $missingOneArg "a" "sum" (param i32) (param i32) (result i32))
(import $missingTwoArgs "a" "sum" (param i32) (result i32))
(import $missingThreeArgs "a" "sum" (result i32))
(func (export "foo") (param i32) (result i32)
local.get 0
@ -788,8 +788,8 @@ assertEq(e.call(), 1090);
// we call it here.
var i1 = new Instance(new Module(wasmTextToBinary(`
(module
(import "a" "f1" (func $imp1 (result i32)))
(import "a" "f2" (func $imp2 (result i32)))
(import $imp1 "a" "f1" (result i32))
(import $imp2 "a" "f2" (result i32))
(import "a" "m" (memory 1))
(func $test (result i32)
(i32.add
@ -797,8 +797,8 @@ assertEq(e.call(), 1090);
(i32.add (memory.size) (call $imp1))
(memory.size))
(call $imp2)))
(export "impstub" (func $imp1))
(export "test" (func $test)))
(export "impstub" $imp1)
(export "test" $test))
`)), {a:{m:g.mem, f1:g.f1, f2:g.Math.abs}});
for (var i = 0; i < 20; i++) {
@ -809,10 +809,10 @@ assertEq(e.call(), 1090);
// Inter-module/inter-realm wasm => wasm calls.
var src = `
(module
(import "a" "othertest" (func $imp (result i32)))
(import $imp "a" "othertest" (result i32))
(import "a" "m" (memory 1))
(func (result i32) (i32.add (call $imp) (memory.size)))
(export "test" (func 1)))
(export "test" 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" (func $f)))`));
const m2 = new Module(wasmTextToBinary(`(module (import "a" "f" (func)) (func $f) (export "g" (func $f)))`));
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))`));
// 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 "" (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);
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);
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" (func 0)))`, expect);
wasmFullPass(`(module (func (result ${type}) (${type}.${opcode} (${type}.const ${op}))) (export "run" 0))`, expect);
// Test with param
wasmFullPass(`(module (func (param ${type}) (result ${type}) (${type}.${opcode} (local.get 0))) (export "run" (func 0)))`, expect, {}, op);
wasmFullPass(`(module (func (param ${type}) (result ${type}) (${type}.${opcode} (local.get 0))) (export "run" 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" (func 0)))`, expect, {}, lhs, rhs);
wasmFullPass(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "run" 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" (func 0)))`, expect, {}, lhs);
wasmFullPass(`(module (func (param i32) (result i32) (i32.${opcode} (local.get 0) (i32.const ${rhs}))) (export "run" 0))`, expect, {}, lhs);
// LHS and RHS are constants.
wasmFullPass(`(module (func (result i32) (i32.${opcode} (i32.const ${lhs}) (i32.const ${rhs}))) (export "run" (func 0)))`, expect);
wasmFullPass(`(module (func (result i32) (i32.${opcode} (i32.const ${lhs}) (i32.const ${rhs}))) (export "run" 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" (func 0)))`, expect, {}, lhs, rhs);
wasmFullPass(`(module (func (param i32) (param i32) (result i32) (i32.${opcode} (local.get 0) (local.get 1))) (export "run" 0))`, expect, {}, lhs, rhs);
}
function testComparison64(opcode, lhs, rhs, expect) {
let lsrc = `i64.const ${lhs}`;
@ -48,12 +48,12 @@ function testComparison64(opcode, lhs, rhs, expect) {
i64.const ${rhs}
call $cmp
)
(export "run" (func $assert)))`, expect);
(export "run" $assert))`, expect);
// Also test `if`, for the compare-and-branch path.
wasmFullPass(`(module
(func $cmp (param i64) (param i64) (result i32)
(if (result i32) (i64.${opcode} (local.get 0) (local.get 1))
(if i32 (i64.${opcode} (local.get 0) (local.get 1))
(i32.const 1)
(i32.const 0)))
(func $assert (result i32)
@ -61,23 +61,23 @@ function testComparison64(opcode, lhs, rhs, expect) {
i64.const ${rhs}
call $cmp
)
(export "run" (func $assert)))`, expect);
(export "run" $assert))`, expect);
}
function testI64Eqz(input, expect) {
wasmFullPass(`(module (func (result i32) (i64.eqz (i64.const ${input}))) (export "run" (func 0)))`, expect, {});
wasmFullPass(`(module (func (result i32) (i64.eqz (i64.const ${input}))) (export "run" 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" (func $assert)))`, expect);
(export "run" $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 "" (func 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 "" 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 "" (func 0)))`).exports[""](lhs), Error, expect);
assertErrorMessage(() => wasmEvalText(`(module (func (param i32) (result i32) (i32.${opcode} (local.get 0) (i32.const ${rhs}))) (export "" 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 "" (func 0)))`).exports[""], Error, expect);
assertErrorMessage(wasmEvalText(`(module (func (result i32) (i32.${opcode} (i32.const ${lhs}) (i32.const ${rhs}))) (export "" 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 "" (func 0)))`).exports[""];
var testTrunc = wasmEvalText(`(module (func (param f32) (result i32) (if i32 (i32.eqz (i32.trunc_s/f32 (local.get 0))) (i32.const 0) (i32.const 1))) (export "" 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 "" (func 0)))`).exports[""];
var testTrunc = wasmEvalText(`(module (func (param f32) (result i32) (if i32 (i64.eqz (i64.trunc_s/f32 (local.get 0))) (i32.const 0) (i32.const 1))) (export "" 0))`).exports[""];
assertEq(testTrunc(0), 0);
assertEq(testTrunc(13.37), 1);

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

@ -1,21 +1,20 @@
let { exports } = wasmEvalText(`(module
(func (export "i32") (param i32) (result i32)
(func (export "i32") (result i32) (param i32)
local.get 0
)
(func (export "f32") (param f32) (result f32)
(func (export "f32") (result f32) (param f32)
local.get 0
)
(func (export "f64") (param f64) (result f64)
(func (export "f64") (result f64) (param f64)
local.get 0
)
(func (export "mixed_args")
(func (export "mixed_args") (result f64)
(param i32) (param i32) (param i32) (param i32) (param i32) ;; 5 i32
(param $f64 f64) ;; 1 f64
(param i32)
(result f64)
local.get $f64
)
)`);
@ -80,10 +79,9 @@ function call(func, coercion, arg) {
// Test high number of arguments.
// All integers.
let {func} = wasmEvalText(`(module
(func (export "func")
(func (export "func") (result i32)
${Array(32).join('(param i32)')}
(param $last i32)
(result i32)
local.get $last
)
)`).exports;
@ -98,10 +96,9 @@ let {func} = wasmEvalText(`(module
// All floats.
func = wasmEvalText(`(module
(func (export "func")
(func (export "func") (result i32)
${Array(32).join('(param f64)')}
(param $last i32)
(result i32)
local.get $last
)
)`).exports.func;
@ -124,10 +121,9 @@ for (let i = 0; i < 32; i++) {
}
func = wasmEvalText(`(module
(func (export "func")
(func (export "func") (result i32)
${Array(32).join('(param f64)')}
(param $last i32)
(result i32)
local.get $last
)
)`).exports.func;

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

@ -4,7 +4,7 @@ g.parent = this;
g.eval("Debugger(parent).onExceptionUnwind = function () {};");
lfModule = new WebAssembly.Module(wasmTextToBinary(`
(module
(export "f" (func $func0))
(export "f" $func0)
(func $func0 (result i32)
i32.const -1
)

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

@ -18,7 +18,7 @@ enableGeckoProfiling();
for (let type of ['i32', 'f32', 'f64']) {
var instance = wasmEvalText(`(module
(func $add (export "add") (param ${type}) (param ${type}) (result ${type})
(func $add (export "add") (result ${type}) (param ${type}) (param ${type})
local.get 0
local.get 1
${type}.add

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

@ -6,7 +6,7 @@ const { assertStackTrace, startProfiling, endProfiling, assertEqPreciseStacks }
enableGeckoProfiling();
let { add } = wasmEvalText(`(module
(func $add (export "add") (param i32) (param i32) (result i32)
(func $add (export "add") (result i32) (param i32) (param i32)
local.get 0
i32.const 42
i32.eq
@ -32,7 +32,7 @@ function main() {
} catch (e) {
assertEq(i, 42);
assertEq(e.message.includes("unreachable"), true);
assertStackTrace(e, ['add', 'main', '']);
assertStackTrace(e, ['wasm-function[0]', 'main', '']);
}
let stack = endProfiling();
assertEqPreciseStacks(stack, [INLINED_CALL_STACK, FAST_ENTRY_STACK, SLOW_ENTRY_STACK]);

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

@ -18,13 +18,13 @@ var imports = {
};
var instance = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`(module
(import "main" "f" (func $main))
(func $lol (export "add") (param i32) (param i32) (result i32)
(import $main "main" "f" (func))
(func $lol (export "add") (result i32) (param i32) (param i32)
local.get 0
local.get 1
call $add
)
(func $add (param i32) (param i32) (result i32)
(func $add (result i32) (param i32) (param i32)
local.get 0
i32.const 5000
i32.eq
@ -81,13 +81,13 @@ var imports = {
};
var instance = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`(module
(import "main" "f" (func $main))
(func $lol (export "add") (param i32) (param i32) (result i32)
(import $main "main" "f" (func))
(func $lol (export "add") (result i32) (param i32) (param i32)
local.get 0
local.get 1
call $add
)
(func $add (param i32) (param i32) (result i32)
(func $add (result i32) (param i32) (param i32)
local.get 0
i32.const 5000
i32.eq

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

@ -8,7 +8,7 @@ const EXCEPTION_ITER = TRIGGER + 5;
for (let type of ['i32', 'f32', 'f64']) {
var instance = wasmEvalText(`(module
(func $add (export "add") (param ${type}) (param ${type}) (result ${type})
(func $add (export "add") (result ${type}) (param ${type}) (param ${type})
local.get 0
local.get 1
${type}.add

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

@ -15,7 +15,7 @@ const EXPECTED_STACKS = [SLOW_ENTRY_STACK, FAST_ENTRY_STACK, INLINED_CALL_STACK]
function main() {
var { table } = wasmEvalText(`(module
(func $add (param i32) (param i32) (result i32)
(func $add (result i32) (param i32) (param i32)
local.get 0
local.get 1
i32.add
@ -35,7 +35,7 @@ function withTier2() {
setJitCompilerOption('wasm.delay-tier2', 1);
var module = new WebAssembly.Module(wasmTextToBinary(`(module
(func $add (param i32) (param i32) (result i32)
(func $add (result i32) (param i32) (param i32)
local.get 0
local.get 1
i32.add

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

@ -2,7 +2,7 @@ var ITERATIONS = 10;
var INNER_ITERATIONS = 100;
let instance = wasmEvalText(`(module
(func (export "add") (param i32) (param i32) (result i32)
(func (export "add") (result i32) (param i32) (param i32)
local.get 0
local.get 1
i32.add

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

@ -11,10 +11,10 @@ function accum(...args) {
}
var e = wasmEvalText(`(module
(import "" "a" (func $a (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)))
(import "" "b" (func $b (param f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32) (result f32)))
(import "" "c" (func $c (param f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64) (result f64)))
(import "" "d" (func $d (param i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32) (result f64)))
(import $a "" "a" (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32))
(import $b "" "b" (param f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32 f32) (result f32))
(import $c "" "c" (param f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64 f64) (result f64))
(import $d "" "d" (param i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32 f64 i32 f32) (result f64))
(func (export "a") (result i32)
i32.const 1 i32.const 2 i32.const 3 i32.const 4 i32.const 5
i32.const 6 i32.const 7 i32.const 8 i32.const 9 i32.const 10
@ -55,8 +55,8 @@ setJitCompilerOption("baseline.warmup.trigger", 5);
setJitCompilerOption("ion.warmup.trigger", 10);
var e = wasmEvalText(`(module
(import "" "a" (func $a (param i32 f64) (result f64)))
(export "a" (func $a))
(import $a "" "a" (param i32 f64) (result f64))
(export "a" $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" (func $off1))
(export "off1" $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" (func $off2))
(export "off2" $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 "" (func 0)))`;
) (export "" 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" (func 0))
) (export "store" 0)
(func $load (param i32) (result ${type})
(${type}.load${load_ext}
offset=${offset}
${align != 0 ? 'align=' + align : ''}
(local.get 0)
)
) (export "load" (func 1)))`;
) (export "load" 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" (func 0))
) (export "store" 0)
(func $load (param i32) (result ${type})
(${type}.load${load_ext}
offset=${offset}
${align != 0 ? 'align=' + align : ''}
(local.get 0)
)
) (export "load" (func 1)))`;
) (export "load" 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 "" (func 0)))`, /can't touch memory/);
wasmFailValidateText( `(module (func (param i32) (${type}.load${ext} (local.get 0))) (export "" 0))`, /can't touch memory/);
}
function badStoreModule(type, ext) {
wasmFailValidateText(`(module (func (param i32) (${type}.store${ext} (local.get 0) (${type}.const 0))) (export "" (func 0)))`, /can't touch memory/);
wasmFailValidateText(`(module (func (param i32) (${type}.store${ext} (local.get 0) (${type}.const 0))) (export "" 0))`, /can't touch memory/);
}
// Can't touch memory.
@ -309,7 +309,7 @@ for (var foldOffsets = 0; foldOffsets <= 1; foldOffsets++) {
(memory 1)
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32) (result i32) (local i32 i32 i32 i32 f32 f64)
(func (param i32) (local i32 i32 i32 i32 f32 f64) (result i32)
(local.set 1 (i32.load8_s offset=4 (local.get 0)))
(local.set 2 (i32.load16_s (local.get 1)))
(i32.store8 offset=4 (local.get 0) (local.get 1))
@ -337,7 +337,7 @@ for (var foldOffsets = 0; foldOffsets <= 1; foldOffsets++) {
)
)
)
) (export "" (func 0)))`
) (export "" 0))`
).exports[""](1), 50464523);
}
@ -466,7 +466,7 @@ new WebAssembly.Module(wasmTextToBinary(`(module (memory 1) (data 0 (offset (i32
new WebAssembly.Module(wasmTextToBinary(`(module (memory 1) (data ""))`));
assertErrorMessage(() => new WebAssembly.Module(wasmTextToBinary(`(module (memory 1) (data 0 ""))`)),
SyntaxError,
/wasm text error/);
/data segment with memory index must have offset/);
assertErrorMessage(() => new WebAssembly.Module(wasmTextToBinary(`(module (memory 1) (data 1 (i32.const 0) ""))`)),
WebAssembly.CompileError,
/memory index must be zero/);
SyntaxError,
/can't handle non-default memory/);

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

@ -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 "" (func 0)))').exports[""]();
f32[1] = wasmEvalText('(module (func (result f32) (f32.const nan:0x123456)) (export "" 0))').exports[""]();
assertSameBitPattern(0, 4, 4);
var checkBitPatterns = {
@ -27,14 +27,14 @@ var checkBitPatterns = {
}
}
wasmEvalText('(module (import "" "float32" (func (param f32))) (func (call 0 (f32.const nan:0x123456))) (export "" (func 0)))', checkBitPatterns).exports[""]();
wasmEvalText('(module (import "" "float32" (param f32)) (func (call 0 (f32.const nan:0x123456))) (export "" 0))', checkBitPatterns).exports[""]();
f64[0] = NaN;
f64[0] = f64[0]; // Force canonicalization.
f64[1] = wasmEvalText('(module (func (result f64) (f64.const nan:0x123456)) (export "" (func 0)))').exports[""]();
f64[1] = wasmEvalText('(module (func (result f64) (f64.const nan:0x123456)) (export "" 0))').exports[""]();
assertSameBitPattern(0, 8, 8);
wasmEvalText('(module (import "" "float64" (func (param f64))) (func (call 0 (f64.const nan:0x123456))) (export "" (func 0)))', checkBitPatterns).exports[""]();
wasmEvalText('(module (import "" "float64" (param f64)) (func (call 0 (f64.const nan:0x123456))) (export "" 0))', checkBitPatterns).exports[""]();
// SANITY CHECKS

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

@ -243,7 +243,7 @@ mem_test("data.drop 1 (i32.const 42)", "",
// init: too many args
mem_test("(memory.init 1 (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1))",
"",
WebAssembly.CompileError, /unused values/);
SyntaxError, /parsing wasm text at/);
// init: too few args
mem_test("(memory.init 1 (i32.const 1) (i32.const 1))", "",
@ -369,7 +369,7 @@ tab_test("elem.drop 1 (i32.const 42)", "",
// init: too many args
tab_test("(table.init 1 (i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1))",
"",
WebAssembly.CompileError, /unused values/);
SyntaxError, /parsing wasm text at/);
// init: too few args
tab_test("(table.init 1 (i32.const 1) (i32.const 1))", "",

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

@ -43,11 +43,11 @@ function gen_tab_impmod_t(insn)
(elem (i32.const 12) 7 5 2 3 6)
(elem func 5 9 2 7 6)
;; -------- Imports --------
(import "a" "if0" (func (result i32))) ;; index 0
(import "a" "if1" (func (result i32)))
(import "a" "if2" (func (result i32)))
(import "a" "if3" (func (result i32)))
(import "a" "if4" (func (result i32))) ;; index 4
(import "a" "if0" (result i32)) ;; index 0
(import "a" "if1" (result i32))
(import "a" "if2" (result i32))
(import "a" "if3" (result i32))
(import "a" "if4" (result i32)) ;; index 4
;; -------- Functions --------
(func (result i32) (i32.const 5)) ;; index 5
(func (result i32) (i32.const 6))
@ -61,7 +61,7 @@ function gen_tab_impmod_t(insn)
;; call the selected table entry, which will either return a value,
;; or will cause an exception.
local.get 0 ;; callIx
call_indirect (type 0) ;; and its return value is our return value.
call_indirect 0 ;; and its return value is our return value.
)
)`;
return t;
@ -260,24 +260,23 @@ mem_test("(memory.init 1 (i32.const 7) (i32.const 0) (i32.const 4)) \n" +
"(memory.copy (i32.const 19) (i32.const 20) (i32.const 5))",
[e,e,3,1,4, 1,e,2,7,1, 8,e,7,e,7, 5,2,7,e,9, e,7,e,8,8, e,e,e,e,e]);
function checkDataCount(count, err) {
let binary = moduleWithSections(
[v2vSigSection,
dataCountSection(count),
dataSection([
{offset: 0, elems: []},
{offset: 0, elems: []},
])
]);
assertErrorMessage(() => new WebAssembly.Module(binary),
WebAssembly.CompileError,
err);
}
// DataCount section is present but value is too low for the number of data segments
checkDataCount(1, /number of data segments does not match declared count/);
assertErrorMessage(() => wasmEvalText(
`(module
(datacount 1)
(data "")
(data ""))`),
WebAssembly.CompileError,
/number of data segments does not match declared count/);
// DataCount section is present but value is too high for the number of data segments
checkDataCount(3, /number of data segments does not match declared count/);
assertErrorMessage(() => wasmEvalText(
`(module
(datacount 3)
(data "")
(data ""))`),
WebAssembly.CompileError,
/number of data segments does not match declared count/);
// DataCount section is not present but memory.init or data.drop uses it
function checkNoDataCount(body, err) {

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

@ -26,7 +26,7 @@ function test(code, importObj, expectedStacks)
test(
`(module
(func (result i32) (i32.const 42))
(export "" (func 0))
(export "" 0)
)`,
{},
["", ">", "0,>", ">", ""]);
@ -35,17 +35,17 @@ test(
`(module
(func (result i32) (i32.add (call 1) (i32.const 1)))
(func (result i32) (i32.const 42))
(export "" (func 0))
(export "" 0)
)`,
{},
["", ">", "0,>", "1,0,>", "0,>", ">", ""]);
test(
`(module
(func $foo (call_indirect (type 0) (i32.const 0)))
(func $foo (call_indirect 0 (i32.const 0)))
(func $bar)
(table funcref (elem $bar))
(export "" (func $foo))
(export "" $foo)
)`,
{},
["", ">", "0,>", "1,0,>", "0,>", ">", ""]);
@ -54,8 +54,8 @@ test(
`(module
(import $foo "" "foo")
(table funcref (elem $foo))
(func $bar (call_indirect (type 0) (i32.const 0)))
(export "" (func $bar))
(func $bar (call_indirect 0 (i32.const 0)))
(export "" $bar)
)`,
{"":{foo:()=>{}}},
["", ">", "1,>", "0,1,>", "<,0,1,>", "0,1,>", "1,>", ">", ""]);
@ -149,10 +149,10 @@ for (let type of ['f32', 'f64']) {
`(module
(type $good (func))
(type $bad (func (param i32)))
(func $foo (call_indirect (type $bad) (i32.const 1) (i32.const 0)))
(func $foo (call_indirect $bad (i32.const 1) (i32.const 0)))
(func $bar (type $good))
(table funcref (elem $bar))
(export "" (func $foo))
(export "" $foo)
)`,
WebAssembly.RuntimeError,
["", ">", "0,>", "1,0,>", ">", "", ">", ""]);
@ -163,11 +163,11 @@ for (let type of ['f32', 'f64']) {
var e = wasmEvalText(`
(module
(func $foo (result i32) (i32.const 42))
(export "foo" (func $foo))
(export "foo" $foo)
(func $bar (result i32) (i32.const 13))
(table 10 funcref)
(elem (i32.const 0) $foo $bar)
(export "tbl" (table 0))
(export "tbl" table)
)`).exports;
assertEq(e.foo(), 42);
assertEq(e.tbl.get(0)(), 42);
@ -206,8 +206,8 @@ for (let type of ['f32', 'f64']) {
(import "a" "b" (table 10 funcref))
(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" (func $baz))
(func $baz (param $i i32) (result i32) (call_indirect $v2i (local.get $i)))
(export "baz" $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" (func $foo))
(export "foo" $foo)
)`));
var m2 = new Module(wasmTextToBinary(`(module
(import $foo "a" "foo" (result i32))
(func $bar (result i32) (call $foo))
(export "bar" (func $bar))
(export "bar" $bar)
)`));
// Instantiate while not active:

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

@ -11,7 +11,7 @@ var bin = wasmTextToBinary(
local.get 0
local.get 0
local.get 0
if (result i32)
if i32
local.get 0
else
local.get 0

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

@ -30,5 +30,5 @@ wasmEvalText(`(module
drop
drop
)
(export "run" (func $run))
(export "run" $run)
)`);

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

@ -5,12 +5,12 @@
wasmEvalText(
`(module
(func $run (param i64) (param i64) (result i64)
block (result i64)
block i64
i64.const 1
(i64.lt_s (local.get 0) (local.get 1))
br_if 0
drop
i64.const 2
end)
(export "run" (func $run)))`
(export "run" $run))`
);

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

@ -10,7 +10,7 @@
wasmEvalText(`
(module
(func $run
(drop (block (result f64)
(drop (block f64
(drop (br_if 0 (f64.const 1) (f64.eq (f64.const 1) (f64.const 0))))
(drop (br 0 (f64.const 2))))))
(export "run" (func $run)))`);
(export "run" $run))`);

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

@ -1,12 +1,12 @@
// |jit-test| --arm-asm-nop-fill=1
var f = wasmEvalText(`(module (func (param i32) (result i32)
var f = wasmEvalText(`(module (func (result i32) (param i32)
(block $0
(block $1
(block $2
(block $default
(br_table $0 $1 $2 $default (local.get 0))))))
(return (i32.const 0)))
(export "" (func 0))
(export "" 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" (func 0)))`).exports;
(export "a" 0))`).exports;
assertEq(o["a"](), 0xEEFDEADB|0);

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

@ -7,6 +7,6 @@ var src =
i32.const 1
br_if 0
unreachable)
(export "run" (func 0)))`;
(export "run" 0))`;
wasmFullPass(src, 0);

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше