Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,49 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
// This test creates the situation where BranchElimination's VisitIf sees a
// different condition than the preceding VisitBranch (because an interleaved
// CommonOperatorReducer replaced the condition).
(function foo() {
let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_v_l)
.addLocals(kWasmI32, 2)
.addBody([
kExprLoop, kWasmVoid,
kExprLocalGet, 0x02,
kExprLocalTee, 0x01,
kExprIf, kWasmVoid,
kExprElse,
kExprLoop, kWasmVoid,
kExprLoop, kWasmVoid,
kExprLocalGet, 0x01,
kExprIf, kWasmVoid,
kExprElse,
kExprLocalGet, 0x02,
kExprBrIf, 0x04,
kExprBr, 0x01,
kExprEnd,
kExprLocalGet, 0x00,
kExprCallFunction, 0x01,
kExprLocalTee, 0x02,
kExprBrIf, 0x00,
kExprEnd,
kExprLocalGet, 0x01,
kExprBrIf, 0x00,
kExprEnd,
kExprEnd,
kExprBr, 0x00,
kExprEnd])
.exportAs("main");
builder.addFunction("callee", kSig_i_l)
.addBody([kExprLocalGet, 0, kExprI32ConvertI64]);
let module = new WebAssembly.Module(builder.toBuffer());
let instance = new WebAssembly.Instance(module);
})();

View File

@ -0,0 +1,67 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
// Force different type indices in both modules.
let dummy = builder.addStruct([]);
let struct = builder.addStruct([makeField(kWasmI32, false)]);
let creatorAnySig = builder.addType(makeSig([], [kWasmAnyRef]));
let funcSig = builder.addType(makeSig([wasmRefType(creatorAnySig)],
[kWasmExternRef]));
let exportedAny = builder.addFunction("exportedAny", funcSig)
.addBody([
kExprLocalGet, 0,
kExprCallRef, creatorAnySig,
kGCPrefix, kExprExternConvertAny,
])
builder.addFunction("createStruct", creatorAnySig)
.addBody([kExprI32Const, 12, kGCPrefix, kExprStructNew, struct])
.exportFunc();
builder.addFunction("refFunc", makeSig([], [wasmRefType(funcSig)]))
.addBody([kExprRefFunc, exportedAny.index])
.exportFunc();
builder.addDeclarativeElementSegment([exportedAny.index]);
let instance = builder.instantiate();
let wasm = instance.exports;
let wasm2 = (function () {
let builder = new WasmModuleBuilder();
let struct = builder.addStruct([makeField(kWasmI32, false)]);
let creatorAnySig = builder.addType(makeSig([], [kWasmAnyRef]));
let funcSig = builder.addType(makeSig([wasmRefType(creatorAnySig)],
[kWasmExternRef]));
builder.addFunction("exportedAny", funcSig)
.addBody([
kExprLocalGet, 0,
kExprCallRef, creatorAnySig,
kGCPrefix, kExprExternConvertAny,
])
.exportFunc();
builder.addFunction("createStruct", creatorAnySig)
.addBody([kExprI32Const, 12, kGCPrefix, kExprStructNew, struct])
.exportFunc();
let instance = builder.instantiate();
let wasm = instance.exports;
// In case we have cached the wrapper when creating it for the previous
// module, it should still work here, despite the funcSig type being in a
// different index.
wasm.exportedAny(wasm.createStruct);
return wasm;
})();
// The intervening module compilation might overwrite export wrappers. This is
// fine as long as wrappers remain identical for canonically identical types.
wasm.refFunc()(wasm.createStruct);
// It should also work with the struct exported by the other module.
wasm.refFunc()(wasm2.createStruct);

View File

@ -0,0 +1,21 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
let builder = new WasmModuleBuilder();
// One global that's perfectly OK.
builder.addGlobal(kWasmI32, true, false, [kExprI32Const, 0]);
// One global that's invalid.
builder.addGlobal(kWasmI32, true, false, [kExprUnreachable]);
// The error is the second-to-last byte.
let module_bytes = builder.toBuffer();
assertEquals(kExprUnreachable, module_bytes[18]);
assertEquals(kExprEnd, module_bytes[19]);
assertEquals(20, module_bytes.byteLength);
assertThrows(() => builder.instantiate(), WebAssembly.CompileError,
"WebAssembly.Module(): opcode unreachable is not allowed in " +
"constant expressions @+18");

View File

@ -0,0 +1,33 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --no-liftoff --wasm-inlining
// This tests that inlining tolerates multi-return call uses that are not
// projections after Int64Lowering.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
let builder = new WasmModuleBuilder();
let callee1 = builder.addFunction("callee1", kSig_l_l)
.addBody([kExprLocalGet, 0, kExprI64Const, 1, kExprI64Add]);
let callee2 = builder.addFunction("callee2", kSig_l_l)
.addBody([kExprLocalGet, 0, kExprI64Const, 1, kExprI64Sub]);
builder.addFunction("caller", kSig_l_l)
.addBody([kExprLocalGet, 0,
kExprI64Const, 0,
kExprI64GtS,
kExprIf, kWasmI64,
kExprLocalGet, 0, kExprCallFunction, 0,
kExprElse,
kExprLocalGet, 0, kExprCallFunction, 1,
kExprEnd])
.exportFunc();
let instance = builder.instantiate();
assertEquals(5n, instance.exports.caller(4n));
assertEquals(-9n, instance.exports.caller(-8n));

View File

@ -0,0 +1,28 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --wasm-staging
// Flags: --wasm-wrapper-tiering-budget=1
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
const builder = new WasmModuleBuilder();
const impIndex = builder.addImport('m', 'foo', kSig_v_v);
const table = builder.addTable(kWasmAnyFunc, 10).exportAs('table').index;
builder.addActiveElementSegment(table, wasmI32Const(0), [impIndex]);
const reexport =
builder.instantiate({'m': {'foo': () => console.log('Hello World')}})
.exports.table.get(0);
function toBeOptimized() {
reexport();
}
%PrepareFunctionForOptimization(toBeOptimized);
toBeOptimized();
toBeOptimized();
toBeOptimized();
%OptimizeFunctionOnNextCall(toBeOptimized);
toBeOptimized();

View File

@ -0,0 +1,16 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function() {
var builder = new WasmModuleBuilder();
builder.addFunction("foo", kSig_i_ii)
.addBody([
kExprLoop, 00,
kExprBrTable, 0xfb, 0xff, 0xff, 0xff,
])
.exportFunc();
assertThrows(function() { builder.instantiate(); });
})();

View File

@ -0,0 +1,969 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --expose-gc --allow-natives-syntax
// Flags: --gc-interval=207 --stress-compaction --validate-asm
// Flags: --turbofan --no-always-turbofan
//
// /v8/test/mjsunit/wasm/grow-memory.js
// /v8/test/mjsunit/regress/regress-540.js
// /v8/test/mjsunit/regress/wasm/regression-02862.js
// /v8/test/mjsunit/regress/regress-2813.js
// /v8/test/mjsunit/regress/regress-323845.js
// Begin stripped down and modified version of mjsunit.js for easy minimization in CF.
function MjsUnitAssertionError(message) {}
MjsUnitAssertionError.prototype.toString = function() {
return this.message;
};
var assertSame;
var assertEquals;
var assertEqualsDelta;
var assertArrayEquals;
var assertPropertiesEqual;
var assertToStringEquals;
var assertTrue;
var assertFalse;
var triggerAssertFalse;
var assertNull;
var assertNotNull;
var assertThrows;
var assertDoesNotThrow;
var assertInstanceof;
var assertUnreachable;
var assertOptimized;
var assertUnoptimized;
function classOf(object) {
var string = Object.prototype.toString.call(object);
return string.substring(8, string.length - 1);
}
function PrettyPrint(value) {
return "";
}
function PrettyPrintArrayElement(value, index, array) {
return "";
}
function fail(expectedText, found, name_opt) {}
function deepObjectEquals(a, b) {
var aProps = Object.keys(a);
aProps.sort();
var bProps = Object.keys(b);
bProps.sort();
if (!deepEquals(aProps, bProps)) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
if (!deepEquals(a[aProps[i]], b[aProps[i]])) {
return false;
}
}
return true;
}
function deepEquals(a, b) {
if (a === b) {
if (a === 0) return (1 / a) === (1 / b);
return true;
}
if (typeof a != typeof b) return false;
if (typeof a == "number") return isNaN(a) && isNaN(b);
if (typeof a !== "object" && typeof a !== "function") return false;
var objectClass = classOf(a);
if (objectClass !== classOf(b)) return false;
if (objectClass === "RegExp") {
return (a.toString() === b.toString());
}
if (objectClass === "Function") return false;
if (objectClass === "Array") {
var elementCount = 0;
if (a.length != b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!deepEquals(a[i], b[i])) return false;
}
return true;
}
if (objectClass == "String" || objectClass == "Number" || objectClass == "Boolean" || objectClass == "Date") {
if (a.valueOf() !== b.valueOf()) return false;
}
return deepObjectEquals(a, b);
}
assertSame = function assertSame(expected, found, name_opt) {
if (found === expected) {
if (expected !== 0 || (1 / expected) == (1 / found)) return;
} else if ((expected !== expected) && (found !== found)) {
return;
}
fail(PrettyPrint(expected), found, name_opt);
};
assertEquals = function assertEquals(expected, found, name_opt) {
if (!deepEquals(found, expected)) {
fail(PrettyPrint(expected), found, name_opt);
}
};
assertEqualsDelta = function assertEqualsDelta(expected, found, delta, name_opt) {
assertTrue(Math.abs(expected - found) <= delta, name_opt);
};
assertArrayEquals = function assertArrayEquals(expected, found, name_opt) {
var start = "";
if (name_opt) {
start = name_opt + " - ";
}
assertEquals(expected.length, found.length, start + "array length");
if (expected.length == found.length) {
for (var i = 0; i < expected.length; ++i) {
assertEquals(expected[i], found[i], start + "array element at index " + i);
}
}
};
assertPropertiesEqual = function assertPropertiesEqual(expected, found, name_opt) {
if (!deepObjectEquals(expected, found)) {
fail(expected, found, name_opt);
}
};
assertToStringEquals = function assertToStringEquals(expected, found, name_opt) {
if (expected != String(found)) {
fail(expected, found, name_opt);
}
};
assertTrue = function assertTrue(value, name_opt) {
assertEquals(true, value, name_opt);
};
assertFalse = function assertFalse(value, name_opt) {
assertEquals(false, value, name_opt);
};
assertNull = function assertNull(value, name_opt) {
if (value !== null) {
fail("null", value, name_opt);
}
};
assertNotNull = function assertNotNull(value, name_opt) {
if (value === null) {
fail("not null", value, name_opt);
}
};
assertThrows = function assertThrows(code, type_opt, cause_opt) {
var threwException = true;
try {
if (typeof code == 'function') {
code();
} else {
eval(code);
}
threwException = false;
} catch (e) {
if (typeof type_opt == 'function') {
assertInstanceof(e, type_opt);
}
if (arguments.length >= 3) {
assertEquals(e.type, cause_opt);
}
return;
}
};
assertInstanceof = function assertInstanceof(obj, type) {
if (!(obj instanceof type)) {
var actualTypeName = null;
var actualConstructor = Object.getPrototypeOf(obj).constructor;
if (typeof actualConstructor == "function") {
actualTypeName = actualConstructor.name || String(actualConstructor);
}
fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" + (type.name || type) + ">" + (actualTypeName ? " but of < " + actualTypeName + ">" : ""));
}
};
assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) {
try {
if (typeof code == 'function') {
code();
} else {
eval(code);
}
} catch (e) {
fail("threw an exception: ", e.message || e, name_opt);
}
};
assertUnreachable = function assertUnreachable(name_opt) {
var message = "Fail" + "ure: unreachable";
if (name_opt) {
message += " - " + name_opt;
}
};
var OptimizationStatus = function() {}
assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) {
if (sync_opt === undefined) sync_opt = "";
assertTrue(OptimizationStatus(fun, sync_opt) != 1, name_opt);
}
assertOptimized = function assertOptimized(fun, sync_opt, name_opt) {
if (sync_opt === undefined) sync_opt = "";
assertTrue(OptimizationStatus(fun, sync_opt) != 2, name_opt);
}
triggerAssertFalse = function() {}
try {
console.log;
print = console.log;
alert = console.log;
} catch (e) {}
function runNearStackLimit(f) {
function t() {
try {
t();
} catch (e) {
f();
}
};
try {
t();
} catch (e) {}
}
function quit() {}
function nop() {}
try {
gc;
} catch (e) {
gc = nop;
}
function getRandomProperty(v, rand) {
var properties = Object.getOwnPropertyNames(v);
var proto = Object.getPrototypeOf(v);
if (proto) {
properties = properties.concat(Object.getOwnPropertyNames(proto));
}
if (properties.includes("constructor") && v.constructor.hasOwnProperty("__proto__")) {
properties = properties.concat(Object.getOwnPropertyNames(v.constructor.__proto__));
}
if (properties.length == 0) {
return "0";
}
return properties[rand % properties.length];
}
// End stripped down and modified version of mjsunit.js.
var __v_0 = {};
var __v_1 = {};
var __v_2 = {};
var __v_3 = {};
var __v_4 = -1073741824;
var __v_5 = {};
var __v_6 = 1;
var __v_7 = 1073741823;
var __v_8 = {};
var __v_9 = {};
var __v_10 = 4294967295;
var __v_11 = this;
var __v_12 = {};
var __v_13 = {};
try {
d8.file.execute("test/mjsunit/wasm/wasm-module-__v_1.js");
__v_2 = 0x10000;
} catch (e) {
print("Caught: " + e);
}
function __f_16() {
var __v_1 = new WasmModuleBuilder();
__v_1.addFunction("grow_memory", kSig_i_i)
.addBody([kExprLocalGet, 0, kExprMemoryGrow])
.exportFunc();
__v_1.addFunction("load", kSig_i_i)
.addBody([kExprLocalGet, 0, kExprI32LoadMem, 0, 0])
.exportFunc();
__v_1.addFunction("store", kSig_i_ii)
.addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprI32StoreMem, 0, 0, kExprLocalGet, 1])
.exportFunc();
__v_1.addFunction("load16", kSig_i_i)
.addBody([kExprLocalGet, 0, kExprI32LoadMem16U, 0, 0])
.exportFunc();
__v_1.addFunction("store16", kSig_i_ii)
.addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprI32StoreMem16, 0, 0, kExprLocalGet, 1])
.exportFunc();
__v_1.__p_1551105852 = __v_1[getRandomProperty(__v_1, 1551105852)];
__v_1.__defineGetter__(getRandomProperty(__v_1, 348910887), function() {
gc();
__v_9[getRandomProperty(__v_9, 1894652048)] = __v_13[getRandomProperty(__v_13, 1352929371)];
return __v_1.__p_1551105852;
});
__v_1.addFunction("load8", kSig_i_i)
.addBody([kExprLocalGet, 0, kExprI32LoadMem8U, 0, 0])
.exportFunc();
__v_1.addFunction("store8", kSig_i_ii)
.addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprI32StoreMem8, 0, 0, kExprLocalGet, 1])
.exportFunc();
return __v_1;
}
function __f_14() {
var __v_4 = __f_16();
__v_1.addMemory(1, 1);
var module = __v_1.instantiate();
var __v_3;
function __f_1() {
return module.exports.load(__v_3);
}
function __f_2(value) {
return module.exports.store(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
for (__v_3 = 0; __v_3 <= (__v_2 - 4); __v_3 += 4) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = __v_2 - 3; __v_3 < __v_2 + 4; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
assertEquals(1, __f_8(3));
for (__v_3 = __v_2; __v_3 <= 4 * __v_2 - 4; __v_3 += 4) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = 4 * __v_2 - 3; __v_3 < 4 * __v_2 + 4; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
assertEquals(4, __f_8(15));
for (__v_3 = 4 * __v_2 - 3; __v_3 <= 4 * __v_2 + 4; __v_3 += 4) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = 19 * __v_2 - 10; __v_3 <= 19 * __v_2 - 4; __v_3 += 4) {
__f_2(20);
gc();
assertEquals(12, __f_1());
}
for (__v_3 = 19 * __v_2 - 3; __v_3 < 19 * __v_2 + 5; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
}
try {
__f_14();
} catch (e) {
print("Caught: " + e);
}
function __f_13() {
var __v_1 = __f_16();
__v_1.__defineGetter__(getRandomProperty(__v_1, 1322348896), function() {
gc();
return __f_28(__v_1);
});
__v_1.addMemory(1, 1);
var module = __v_1.instantiate();
assertEquals(0, __f_30(0));
var __v_3;
function __f_1() {
return module.exports.load16(__v_3);
}
function __f_2(value) {
return module.exports.store16(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
for (__v_3 = 0; __v_3 <= (__v_2 - 2); __v_3 += 2) {
__f_2(20);
assertEquals(20, __f_1());
__f_19();
}
for (__v_3 = __v_2 - 1; __v_3 < __v_2 + 4; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
assertEquals(65535, __f_8(0));
for (__v_3 = __v_2; __v_3 <= 4 * __v_2 - 2; __v_3 += 2) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = 4 * __v_2 - 1; __v_3 < 4 * __v_2 + 4; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
assertEquals(4, __f_8(15));
for (__v_3 = 4 * __v_2 - 2; __v_3 <= 4 * __v_2 + 4; __v_3 += 2) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_1 = 19 * __v_11 - 10; __v_13 <= 19 * __v_2 - 2; __v_9 += 2) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = 19 * __v_2 - 1; __v_3 < 19 * __v_2 + 5; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
}
try {
__f_13();
} catch (e) {
print("Caught: " + e);
}
function __f_10() {
var __v_1 = __f_16();
__v_1.addMemory(1, 1);
var module = __v_1.instantiate();
var __v_3;
function __f_1() {
return module.exports.load8(__v_3);
}
function __f_2(value) {
return module.exports.store8(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
for (__v_3 = 0; __v_3 <= __v_2 - 1; __v_3++) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = __v_2; __v_3 < __v_2 + 4; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
assertEquals(1, __f_8(3));
for (__v_3 = __v_2; __v_3 <= 4 * __v_2 - 1; __v_3++) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = 4 * __v_2; __v_3 < 4 * __v_2 + 4; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
assertEquals(4, __f_8(15));
for (__v_3 = 4 * __v_2; __v_3 <= 4 * __v_2 + 4; __v_3++) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = 19 * __v_2 - 10; __v_3 <= 19 * __v_2 - 1; __v_3++) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = 19 * __v_2; __v_3 < 19 * __v_2 + 5; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
assertTraps(kTrapMemOutOfBounds, __f_1);
}
}
try {
__f_10();
} catch (e) {
print("Caught: " + e);
}
function __f_5() {
var __v_1 = __f_16();
var module = __v_1.instantiate();
var __v_3;
function __f_1() {
return module.exports.load(__v_3);
}
function __f_2(value) {
return module.exports.store(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
assertTraps(kTrapMemOutOfBounds, __f_1);
assertTraps(kTrapMemOutOfBounds, __f_2);
assertEquals(0, __f_8(1));
for (__v_3 = 0; __v_3 <= __v_2 - 4; __v_3++) {
__f_2(20);
assertEquals(20, __f_1());
}
for (__v_3 = __v_2; __v_3 <= __v_2 + 5; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_1);
}
}
try {
__f_5();
} catch (e) {
print("Caught: " + e);
}
function __f_9() {
var __v_1 = __f_16();
var module = __v_1.instantiate();
var __v_4 = 16385;
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
assertEquals(-1, __f_8(__v_13));
}
try {
__f_9();
} catch (e) {
print("Caught: " + e);
}
function __f_12() {
var __v_1 = __f_16();
__v_1.addMemory(1, 1);
var module = __v_9.instantiate();
__v_4.__p_1905062277 = __v_4[getRandomProperty(__v_4, 1905062277)];
__v_4.__defineGetter__(getRandomProperty(__v_4, 1764398743), function() {
gc();
__v_0[getRandomProperty(__v_0, 1011363961)] = __v_8[getRandomProperty(__v_8, 1946768258)];
return __v_4.__p_1905062277;
});
var __v_4 = 16384;
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
assertEquals(-1, __f_8(__v_4));
}
try {
__f_12();
} catch (e) {
print("Caught: " + e);
}
function __f_0() {
var __v_1 = __f_16();
var module = __v_1.instantiate();
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
assertEquals(-1, __f_8(-1));
};
try {
__f_0();
} catch (e) {
print("Caught: " + e);
}
function __f_4() {
var __v_1 = __f_16();
__v_1.addMemory(1, 1);
__v_1.addFunction("memory_size", kSig_i_v)
.addBody([kExprMemorySize])
.exportFunc();
var module = __v_1.instantiate();
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
function __f_7() {
return module.exports.memory_size();
}
assertEquals(1, __f_7());
assertEquals(1, __f_8(1));
assertEquals(2, __f_7());
}
try {
__f_4();
gc();
} catch (e) {
print("Caught: " + e);
}
function __f_6() {
var __v_1 = __f_16();
__v_1.addMemory(1, 1);
var module = __v_1.instantiate();
var __v_3, __v_0;
gc();
function __f_1() {
return module.exports.load(__v_3);
}
function __f_2(value) {
return module.exports.store(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
gc();
for (__v_3 = 0; __v_3 <= (__v_2 - 4); __v_3 += 4) {
__f_2(100000 - __v_3);
__v_3.__defineGetter__(getRandomProperty(__v_3, 764734523), function() {
gc();
return __f_16(__v_3);
});
assertEquals(100000 - __v_3, __f_1());
}
assertEquals(1, __f_8(3));
for (__v_3 = 0; __v_3 <= (__v_2 - 4); __v_3 += 4) {
assertEquals(100000 - __v_3, __f_1());
}
}
try {
__f_6();
gc();
} catch (e) {
print("Caught: " + e);
}
function __f_11() {
var __v_1 = __f_16();
__v_1.addMemory(1, 1);
var module = __v_2.instantiate();
var __v_3, __v_0;
function __f_1() {
return module.exports.load16(__v_3);
}
function __f_2(value) {
return module.exports.store16(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
for (__v_3 = 0; __v_3 <= (__v_2 - 2); __v_3 += 2) {
__f_2(65535 - __v_3);
assertEquals(65535 - __v_3, __f_1());
}
assertEquals(1, __f_8(3));
for (__v_3 = 0; __v_3 <= (__v_2 - 2); __v_3 += 2) {
assertEquals(65535 - __v_3, __f_1());
}
}
try {
__f_11();
} catch (e) {
print("Caught: " + e);
}
function __f_15() {
var __v_1 = __f_16();
__v_1.addMemory(1, 1);
var module = __v_1.instantiate();
var __v_3, __v_0 = 0;
function __f_1() {
return module.exports.load8(__v_10);
}
function __f_2(value) {
return module.exports.store8(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
for (__v_3 = 0; __v_3 <= (__v_2 - 1); __v_3++, __v_0++) {
__f_2(__v_0);
assertEquals(__v_0, __f_1());
if (__v_0 == 255) __v_0 = 0;
}
assertEquals(1, __f_8(3));
__v_0 = 0;
for (__v_10 = 0; __v_4 <= (__v_0 - 1); __v_11++, __v_5++) {
assertEquals(__v_0, __f_1());
if (__v_10 == 255) __v_5 = 0;
}
}
try {
__f_15();
} catch (e) {
print("Caught: " + e);
}
function __f_3() {
var __v_1 = __f_16();
__v_1.addMemory(1, 1);
var module = __v_1.instantiate();
var __v_3, __v_0;
function __f_1() {
return module.exports.load(__v_3);
}
function __f_2(value) {
return module.exports.store(__v_3, value);
}
function __f_8(pages) {
return module.exports.grow_memory(pages);
}
gc();
__v_3 = 3 * __v_2 + 4;
assertTraps(kTrapMemOutOfBounds, __f_2);
assertEquals(1, __f_8(1));
assertTraps(kTrapMemOutOfBounds, __f_2);
assertEquals(2, __f_8(1));
assertTraps(kTrapMemOutOfBounds, __f_2);
assertEquals(3, __f_8(1));
for (__v_3 = 3 * __v_2; __v_3 <= 4 * __v_2 - 4; __v_3++) {
__f_2(0xaced);
assertEquals(0xaced, __f_1());
}
for (__v_3 = 4 * __v_2 - 3; __v_3 <= 4 * __v_2 + 4; __v_3++) {
assertTraps(kTrapMemOutOfBounds, __f_2);
}
}
try {
__f_3();
} catch (e) {
print("Caught: " + e);
}
function __f_18(__f_17, y) {
eval(__f_17);
return y();
}
try {
var __v_17 = __f_18("function y() { return 1; }", function() {
return 0;
})
assertEquals(1, __v_17);
gc();
__v_17 =
(function(__f_17) {
function __f_17() {
return 3;
}
return __f_17();
})(function() {
return 2;
});
assertEquals(3, __v_17);
__v_17 =
(function(__f_17) {
function __f_17() {
return 5;
}
return arguments[0]();
})(function() {
return -1073741825;
});
assertEquals(5, __v_17);
} catch (e) {
print("Caught: " + e);
}
function __f_27() {}
try {
var __v_24 = {};
var __v_21 = {};
var __v_22 = {};
var __v_20 = {};
__v_58 = {
instantiateModuleFromAsm: function(text, ffi, heap) {
var __v_21 = eval('(' + text + ')');
if (__f_27()) {
throw "validate failure";
}
var __v_20 = __v_21();
if (__f_27()) {
throw "bad module args";
}
}
};
__f_21 = function __f_21() {
if (found === expected) {
if (1 / expected) return;
} else if ((expected !== expected) && (found !== found)) {
return;
};
};
__f_28 = function __f_28() {
if (!__f_23()) {
__f_125(__f_69(), found, name_opt);
}
};
__f_24 = function __f_24(code, type_opt, cause_opt) {
var __v_24 = true;
try {
if (typeof code == 'function') {
code();
} else {
eval();
}
__v_24 = false;
} catch (e) {
if (typeof type_opt == 'function') {
__f_22();
}
if (arguments.length >= 3) {
__f_28();
}
return;
}
};
__f_22 = function __f_22() {
if (obj instanceof type) {
obj.constructor;
if (typeof __v_57 == "function") {;
};
}
};
try {
__f_28();
__v_82.__p_750895751 = __v_82[getRandomProperty()];
} catch (e) {
"Caught: " + e;
}
__f_19();
gc();
__f_19(19, __f_24);
__f_19();
__f_19();
__f_24(function() {
__v_58.instantiateModuleFromAsm(__f_28.toString()).__f_20();
});
} catch (e) {
print("Caught: " + e);
}
function __f_19() {
"use asm";
function __f_20() {}
return {
__f_20: __f_20
};
}
try {
__f_19();
__f_19();
__f_19();
} catch (e) {
print("Caught: " + e);
}
function __f_29() {}
try {
__f_19();
try {
__f_19();
gc();
__f_25();
} catch (e) {
"Caught: " + e;
}
__f_19();
__f_19();
__f_19();
} catch (e) {
print("Caught: " + e);
}
function __f_23() {
"use asm";
function __f_20() {}
return {
__f_20: __f_20
};
}
try {
__f_19();
__f_19();
__f_19();
__f_19();
gc();
__f_19();
__f_19();
__f_19();
} catch (e) {
print("Caught: " + e);
}
function __f_26(stdlib) {
"use asm";
var __v_2 = new stdlib.Int32Array();
__v_22[4294967295] | 14 + 1 | 14;
return {
__f_20: __f_20
};
}
function __f_25() {
var __v_19 = new ArrayBuffer();
var __v_23 = new Int32Array(__v_19);
var module = __v_58.instantiateModuleFromAsm(__f_26.toString());
__f_28();
gc();
}
try {
(function() {})();
(function() {})();
try {
(function() {
__v_23.__defineGetter__(getRandomProperty(__v_23, 580179357), function() {
gc();
return __f_25(__v_23);
});
var __v_23 = 0x87654321;
__v_19.__f_89();
})();
} catch (e) {;
}
} catch (e) {
print("Caught: " + e);
}
function __f_30(x) {
var __v_30 = x + 1;
var __v_31 = x + 2;
if (x != 0) {
if (x > 0 & x < 100) {
return __v_30;
}
}
return 0;
}
try {
%PrepareFunctionForOptimization(__f_30);
assertEquals(0, __f_30(0));
assertEquals(0, __f_30(0));
%OptimizeFunctionOnNextCall(__f_30);
assertEquals(3, __f_30(2));
} catch (e) {
print("Caught: " + e);
}
function __f_31() {
__f_32.arguments;
}
function __f_32(x) {
__f_31();
}
function __f_33() {
__f_32({});
}
try {
%PrepareFunctionForOptimization(__f_33);
__f_33();
__f_33();
__f_33();
%OptimizeFunctionOnNextCall(__f_33);
__f_33();
gc();
} catch (e) {
print("Caught: " + e);
}

View File

@ -0,0 +1,504 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --expose-gc --allow-natives-syntax --gc-interval=207
// Flags: --stress-compaction --validate-asm --turbofan --no-always-turbofan
//
// /v8/test/mjsunit/wasm/grow-memory.js
// /v8/test/mjsunit/regress/regress-540.js
// /v8/test/mjsunit/regress/wasm/regression-02862.js
// /v8/test/mjsunit/regress/regress-2813.js
// /v8/test/mjsunit/regress/regress-323845.js
// Begin stripped down and modified version of mjsunit.js for easy minimization in CF.
function MjsUnitAssertionError(message) {}
MjsUnitAssertionError.prototype.toString = function() {
return this.message;
};
var assertSame;
var assertEquals;
var assertEqualsDelta;
var assertArrayEquals;
var assertPropertiesEqual;
var assertToStringEquals;
var assertTrue;
var assertFalse;
var triggerAssertFalse;
var assertNull;
var assertNotNull;
var assertThrows;
var assertDoesNotThrow;
var assertInstanceof;
var assertUnreachable;
var assertOptimized;
var assertUnoptimized;
function classOf(object) {
var string = Object.prototype.toString.call(object);
return string.substring(8, string.length - 1);
}
function PrettyPrint(value) {
return "";
}
function PrettyPrintArrayElement(value, index, array) {
return "";
}
function fail(expectedText, found, name_opt) {}
function deepObjectEquals(a, b) {
var aProps = Object.keys(a);
aProps.sort();
var bProps = Object.keys(b);
bProps.sort();
if (!deepEquals(aProps, bProps)) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
if (!deepEquals(a[aProps[i]], b[aProps[i]])) {
return false;
}
}
return true;
}
function deepEquals(a, b) {
if (a === b) {
if (a === 0) return (1 / a) === (1 / b);
return true;
}
if (typeof a != typeof b) return false;
if (typeof a == "number") return isNaN(a) && isNaN(b);
if (typeof a !== "object" && typeof a !== "function") return false;
var objectClass = classOf(a);
if (objectClass !== classOf(b)) return false;
if (objectClass === "RegExp") {
return (a.toString() === b.toString());
}
if (objectClass === "Function") return false;
if (objectClass === "Array") {
var elementCount = 0;
if (a.length != b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!deepEquals(a[i], b[i])) return false;
}
return true;
}
if (objectClass == "String" || objectClass == "Number" || objectClass == "Boolean" || objectClass == "Date") {
if (a.valueOf() !== b.valueOf()) return false;
}
return deepObjectEquals(a, b);
}
assertSame = function assertSame(expected, found, name_opt) {
if (found === expected) {
if (expected !== 0 || (1 / expected) == (1 / found)) return;
} else if ((expected !== expected) && (found !== found)) {
return;
}
fail(PrettyPrint(expected), found, name_opt);
};
assertEquals = function assertEquals(expected, found, name_opt) {
if (!deepEquals(found, expected)) {
fail(PrettyPrint(expected), found, name_opt);
}
};
assertEqualsDelta = function assertEqualsDelta(expected, found, delta, name_opt) {
assertTrue(Math.abs(expected - found) <= delta, name_opt);
};
assertArrayEquals = function assertArrayEquals(expected, found, name_opt) {
var start = "";
if (name_opt) {
start = name_opt + " - ";
}
assertEquals(expected.length, found.length, start + "array length");
if (expected.length == found.length) {
for (var i = 0; i < expected.length; ++i) {
assertEquals(expected[i], found[i], start + "array element at index " + i);
}
}
};
assertPropertiesEqual = function assertPropertiesEqual(expected, found, name_opt) {
if (!deepObjectEquals(expected, found)) {
fail(expected, found, name_opt);
}
};
assertToStringEquals = function assertToStringEquals(expected, found, name_opt) {
if (expected != String(found)) {
fail(expected, found, name_opt);
}
};
assertTrue = function assertTrue(value, name_opt) {
assertEquals(true, value, name_opt);
};
assertFalse = function assertFalse(value, name_opt) {
assertEquals(false, value, name_opt);
};
assertNull = function assertNull(value, name_opt) {
if (value !== null) {
fail("null", value, name_opt);
}
};
assertNotNull = function assertNotNull(value, name_opt) {
if (value === null) {
fail("not null", value, name_opt);
}
};
assertThrows = function assertThrows(code, type_opt, cause_opt) {
var threwException = true;
try {
if (typeof code == 'function') {
code();
} else {
eval(code);
}
threwException = false;
} catch (e) {
if (typeof type_opt == 'function') {
assertInstanceof(e, type_opt);
}
if (arguments.length >= 3) {
assertEquals(e.type, cause_opt);
}
return;
}
};
assertInstanceof = function assertInstanceof(obj, type) {
if (!(obj instanceof type)) {
var actualTypeName = null;
var actualConstructor = Object.getPrototypeOf(obj).constructor;
if (typeof actualConstructor == "function") {
actualTypeName = actualConstructor.name || String(actualConstructor);
}
fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" + (type.name || type) + ">" + (actualTypeName ? " but of < " + actualTypeName + ">" : ""));
}
};
assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) {
try {
if (typeof code == 'function') {
code();
} else {
eval(code);
}
} catch (e) {
fail("threw an exception: ", e.message || e, name_opt);
}
};
assertUnreachable = function assertUnreachable(name_opt) {
var message = "Fail" + "ure: unreachable";
if (name_opt) {
message += " - " + name_opt;
}
};
var OptimizationStatus = function() {}
assertUnoptimized = function assertUnoptimized(fun, sync_opt, name_opt) {
if (sync_opt === undefined) sync_opt = "";
assertTrue(OptimizationStatus(fun, sync_opt) != 1, name_opt);
}
assertOptimized = function assertOptimized(fun, sync_opt, name_opt) {
if (sync_opt === undefined) sync_opt = "";
assertTrue(OptimizationStatus(fun, sync_opt) != 2, name_opt);
}
triggerAssertFalse = function() {}
try {
console.log;
print = console.log;
alert = console.log;
} catch (e) {}
function runNearStackLimit(f) {
function t() {
try {
t();
} catch (e) {
f();
}
};
try {
t();
} catch (e) {}
}
function quit() {}
function nop() {}
try {
gc;
} catch (e) {
gc = nop;
}
function getRandomProperty(v, rand) {
var properties = Object.getOwnPropertyNames(v);
var proto = Object.getPrototypeOf(v);
if (proto) {
properties = properties.concat(Object.getOwnPropertyNames(proto));
}
if (properties.includes("constructor") && v.constructor.hasOwnProperty("__proto__")) {
properties = properties.concat(Object.getOwnPropertyNames(v.constructor.__proto__));
}
if (properties.length == 0) {
return "0";
}
return properties[rand % properties.length];
}
// End stripped down and modified version of mjsunit.js.
var __v_0 = {};
var __v_1 = {};
var __v_2 = {};
var __v_3 = {};
var __v_4 = -1073741824;
var __v_5 = {};
var __v_6 = 1;
var __v_7 = 1073741823;
var __v_8 = {};
var __v_9 = {};
var __v_10 = 4294967295;
var __v_11 = this;
var __v_12 = {};
var __v_13 = {};
function __f_18(__f_17, y) {
eval(__f_17);
return y();
}
try {
var __v_17 = __f_18("function y() { return 1; }", function() {
return 0;
})
assertEquals(1, __v_17);
gc();
__v_17 =
(function(__f_17) {
function __f_17() {
return 3;
}
return __f_17();
})(function() {
return 2;
});
assertEquals(3, __v_17);
__v_17 =
(function(__f_17) {
function __f_17() {
return 5;
}
return arguments[0]();
})(function() {
return -1073741825;
});
assertEquals(5, __v_17);
} catch (e) {
print("Caught: " + e);
}
function __f_27() {}
try {
var __v_24 = {};
var __v_21 = {};
var __v_22 = {};
var __v_20 = {};
__v_58 = {
instantiateModuleFromAsm: function(text, ffi, heap) {
var __v_21 = eval('(' + text + ')');
if (__f_27()) {
throw "validate failure";
}
var __v_20 = __v_21();
if (__f_27()) {
throw "bad module args";
}
}
};
__f_21 = function __f_21() {
if (found === expected) {
if (1 / expected) return;
} else if ((expected !== expected) && (found !== found)) {
return;
};
};
__f_28 = function __f_28() {
if (!__f_23()) {
__f_125(__f_69(), found, name_opt);
}
};
__f_24 = function __f_24(code, type_opt, cause_opt) {
var __v_24 = true;
try {
if (typeof code == 'function') {
code();
} else {
eval();
}
__v_24 = false;
} catch (e) {
if (typeof type_opt == 'function') {
__f_22();
}
if (arguments.length >= 3) {
__f_28();
}
return;
}
};
__f_22 = function __f_22() {
if (obj instanceof type) {
obj.constructor;
if (typeof __v_57 == "function") {;
};
}
};
try {
__f_28();
__v_82.__p_750895751 = __v_82[getRandomProperty()];
} catch (e) {
"Caught: " + e;
}
__f_19();
gc();
__f_19(19, __f_24);
__f_19();
__f_19();
__f_24(function() {
__v_58.instantiateModuleFromAsm(__f_28.toString()).__f_20();
});
} catch (e) {
print("Caught: " + e);
}
function __f_19() {
"use asm";
function __f_20() {}
return {
__f_20: __f_20
};
}
try {
__f_19();
__f_19();
__f_19();
} catch (e) {
print("Caught: " + e);
}
function __f_29() {}
try {
__f_19();
try {
__f_19();
gc();
__f_25();
} catch (e) {
"Caught: " + e;
}
__f_19();
__f_19();
__f_19();
} catch (e) {
print("Caught: " + e);
}
function __f_23() {
"use asm";
function __f_20() {}
return {
__f_20: __f_20
};
}
try {
__f_19();
__f_19();
__f_19();
__f_19();
gc();
__f_19();
__f_19();
__f_19();
} catch (e) {
print("Caught: " + e);
}
function __f_26(stdlib) {
"use asm";
var __v_2 = new stdlib.Int32Array();
__v_22[4294967295] | 14 + 1 | 14;
return {
__f_20: __f_20
};
}
function __f_25() {
var __v_19 = new ArrayBuffer();
var __v_23 = new Int32Array(__v_19);
var module = __v_58.instantiateModuleFromAsm(__f_26.toString());
__f_28();
gc();
}
try {
(function() {})();
(function() {})();
try {
(function() {
__v_23.__defineGetter__(getRandomProperty(__v_23, 580179357), function() {
gc();
return __f_25(__v_23);
});
var __v_23 = 0x87654321;
__v_19.__f_89();
})();
} catch (e) {;
}
} catch (e) {
print("Caught: " + e);
}
function __f_30(x) {
var __v_30 = x + 1;
var __v_31 = x + 2;
if (x != 0) {
if (x > 0 & x < 100) {
return __v_30;
}
}
return 0;
}
try {
%PrepareFunctionForOptimization(__f_30);
assertEquals(0, __f_30(0));
assertEquals(0, __f_30(0));
%OptimizeFunctionOnNextCall(__f_30);
assertEquals(3, __f_30(2));
} catch (e) {
print("Caught: " + e);
}
function __f_31() {
__f_32.arguments;
}
function __f_32(x) {
__f_31();
}
function __f_33() {
__f_32({});
}
try {
%PrepareFunctionForOptimization(__f_33);
__f_33();
__f_33();
__f_33();
%OptimizeFunctionOnNextCall(__f_33);
__f_33();
gc();
} catch (e) {
print("Caught: " + e);
}

View File

@ -0,0 +1,107 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-gc --invoke-weak-callbacks --omit-quit --gc-interval=469 --validate-asm
function nop() {}
var __v_42 = {};
var __v_49 = {};
var __v_70 = {};
var __v_79 = {};
__v_58 = {
instantiateModuleFromAsm: function(text, ffi, heap) {
var __v_49 = eval('(' + text + ')');
if (nop()) {
throw "validate failure";
}
var __v_79 = __v_49();
if (nop()) {
throw "bad module args";
}
}};
__f_140 = function __f_140() {
if (found === expected) {
if (1 / expected) return;
} else if ((expected !== expected) && (found !== found)) { return; };
};
__f_128 = function __f_128() { if (!__f_105()) { __f_125(__f_69(), found, name_opt); } };
__f_136 = function __f_136(code, type_opt, cause_opt) {
var __v_42 = true;
try {
if (typeof code == 'function') { code(); }
else { eval(); }
__v_42 = false;
} catch (e) {
if (typeof type_opt == 'function') { __f_101(); }
if (arguments.length >= 3) { __f_128(); }
return;
}
};
__f_101 = function __f_101() { if (obj instanceof type) {obj.constructor; if (typeof __v_57 == "function") {; }; } };
try {
__f_128();
__v_82.__p_750895751 = __v_82[getRandomProperty()];
} catch(e) {"Caught: " + e; }
__f_119();
gc();
__f_119(19, __f_136);
__f_119();
__f_119();
__f_136(function() {
__v_58.instantiateModuleFromAsm(__f_128.toString()).__f_108();
});
function __f_119() {
"use asm";
function __f_108() {
}
return {__f_108: __f_108};
}
__f_119();
__f_119();
__f_119();
function __f_95() {
}
__f_119();
try {
__f_119();
__f_135();
} catch(e) {"Caught: " + e; }
__f_119();
__f_119();
__f_119();
function __f_105() {
"use asm";
function __f_108() {
}
return {__f_108: __f_108};
}
__f_119();
__f_119();
__f_119();
__f_119();
__f_119();
__f_119();
__f_119();
function __f_93(stdlib) {
"use asm";
var __v_70 = new stdlib.Int32Array();
__v_70[4294967295]|14 + 1 | 14;
return {__f_108: __f_108};
}
function __f_135() {
var __v_66 = new ArrayBuffer();
var __v_54 = new Int32Array(__v_66);
var module = __v_58.instantiateModuleFromAsm( __f_93.toString());
__f_128();
}
(function () {
})();
(function () {
})();
try {
(function() {
var __v_54 = 0x87654321;
__v_66.__f_89();
})();
} catch(e) {; }

View File

@ -0,0 +1,29 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-grow-shared-memory
const kNumWorkers = 100;
const kNumMessages = 50;
function AllocMemory(initial, maximum = initial) {
return new WebAssembly.Memory({initial : initial, maximum : maximum, shared : true});
}
(function RunTest() {
let worker = [];
for (let w = 0; w < kNumWorkers; w++) {
worker[w] = new Worker(
`onmessage = function({data:msg}) {
msg.memory.grow(1);
}`, {type : 'string'});
}
for (let i = 0; i < kNumMessages; i++) {
let memory = AllocMemory(1, 128);
for (let w = 0; w < kNumWorkers; w++) {
worker[w].postMessage({memory : memory});
}
}
})();

View File

@ -0,0 +1,7 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-test-streaming
d8.file.execute('test/mjsunit/regress/wasm/regress-10126.js')

View File

@ -0,0 +1,32 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js')
let binary = new Binary;
binary.emit_bytes([
kWasmH0, // 0 header
kWasmH1, // 1 -
kWasmH2, // 2 -
kWasmH3, // 3 -
kWasmV0, // 4 version
kWasmV1, // 5 -
kWasmV2, // 6 -
kWasmV3, // 7 -
kUnknownSectionCode, // 8 custom section
0x5, // 9 length
0x6, // 10 invalid name length
'a', // 11 payload
'b', // 12 -
'c', // 13 -
'd', // 14 -
kCodeSectionCode, // 15 code section start
0x1, // 16 code section length
19, // 17 invalid number of functions
]);
const buffer = binary.trunc_buffer();
assertThrowsAsync(
WebAssembly.compile(buffer), WebAssembly.CompileError,
'WebAssembly.compile(): expected 6 bytes, fell off end @+11');

View File

@ -0,0 +1,20 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_iii)
.addLocals(kWasmF32, 4)
.addLocals(kWasmI64, 1)
.addLocals(kWasmF32, 2)
.addBodyWithEnd([
kExprI64Const, 0,
kExprLocalGet, 3,
kExprI64SConvertF32,
kExprI64Ne,
kExprEnd, // @17
]).exportFunc();
const instance = builder.instantiate();
assertEquals(0, instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,20 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-lazy-compilation
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var func = builder.addFunction('func', kSig_i_v).addBody([kExprI32Const, 1]);
var body = [];
for (let i = 0; i < 200; ++i) {
body.push(kExprCallFunction, func.index);
}
for (let i = 1; i < 200; ++i) {
body.push(kExprI32Add);
}
builder.addFunction('test', kSig_i_v).addBody(body).exportFunc();
var instance = builder.instantiate();
instance.exports.test();

View File

@ -0,0 +1,31 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function() {
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
builder.addType(makeSig([], []));
// Generate function 1 (out of 2).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_iii
// body:
kExprCallFunction, 0x01, // function #1: v_v
kExprI32Const, 0x00,
kExprEnd, // @5
]);
// Generate function 2 (out of 2).
builder.addFunction(undefined, 1 /* sig */)
.addLocals(kWasmF32, 1).addLocals(kWasmI32, 13)
.addBodyWithEnd([
// signature: v_v
// body:
kExprEnd, // @5
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
print(instance.exports.main(1, 2, 3));
})();

View File

@ -0,0 +1,56 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function() {
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmF64, kWasmF64, kWasmI32, kWasmI32], [kWasmI32]));
builder.addType(makeSig([], [kWasmF64]));
// Generate function 1 (out of 2).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_ddii
// body:
kExprI32Const, 0x01,
kExprEnd, // @3
]);
// Generate function 2 (out of 2).
builder.addFunction(undefined, 1 /* sig */)
.addLocals(kWasmF64, 8)
.addBodyWithEnd([
// signature: d_v
// body:
kExprBlock, kWasmF64, // @3 f64
kExprBlock, kWasmVoid, // @5
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
kExprLocalTee, 0x00,
kExprLocalTee, 0x01,
kExprLocalTee, 0x02,
kExprLocalTee, 0x03,
kExprLocalTee, 0x04,
kExprLocalTee, 0x05,
kExprLocalTee, 0x06,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f,
kExprLocalTee, 0x07,
kExprI32Const, 0x00,
kExprIf, kWasmI32, // @52 i32
kExprI32Const, 0x00,
kExprElse, // @56
kExprI32Const, 0x00,
kExprEnd, // @59
kExprBrIf, 0x01, // depth=1
kExprI32UConvertF64,
kExprI32Const, 0x00,
kExprCallFunction, 0x00, // function #0: i_ddii
kExprDrop,
kExprUnreachable,
kExprEnd, // @70
kExprUnreachable,
kExprEnd, // @72
kExprEnd, // @73
]);
assertDoesNotThrow(function() { builder.instantiate(); });
})();

View File

@ -0,0 +1,67 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js')
const builder = new WasmModuleBuilder();
builder.addMemory(0, 0);
builder.addType(makeSig([kWasmF32, kWasmF32, kWasmF64], [kWasmF64]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: d_ffdl
// body:
kExprLoop, kWasmF64, // @15 f64
kExprLoop, kWasmF64, // @17 f64
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprI32Const, 0,
kExprIf, kWasmF64, // @251 f64
kExprLoop, kWasmF64, // @253 f64
kExprI32Const, 0,
kExprIf, kWasmI32, // @267 i32
kExprMemorySize, 0x00,
kExprMemoryGrow, 0x00,
kExprElse, // @273
kExprF32Const, 0x00, 0x00, 0x00, 0x00,
kExprI32SConvertF32,
kExprEnd, // @282
kExprDrop,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprI32Const, 0x00,
kExprBrIf, 0x01, // depth=1
kExprI32SConvertF64,
kExprF64SConvertI32,
kExprEnd, // @311
kExprElse, // @312
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprEnd, // @322
kExprF64Max,
kExprF64Max,
kExprF32Const, 0x00, 0x00, 0x00, 0x00,
kExprF32Const, 0x00, 0x00, 0x00, 0x00,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprCallFunction, 0x00, // function #0: d_ffdl
kExprF64Max,
kExprF64Max,
kExprF64Max,
kExprI32Const, 0x00,
kExprF64SConvertI32,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprF64Max,
kExprF64Max,
kExprEnd, // @1374
kExprEnd, // @1375
kExprEnd, // @1376
]);
builder.addExport('main', 0);
builder.toModule();

View File

@ -0,0 +1,12 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --log-code
(function(foo, foreign) {
'use asm';
var fn = foreign.fn;
function f() { }
return f;
})(this, {fn: x => x});

View File

@ -0,0 +1,62 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let registry = {};
function module(bytes, valid = true) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);
for (let i = 0; i < bytes.length; ++i) {
view[i] = bytes.charCodeAt(i);
}
let validated;
try {
validated = WebAssembly.validate(buffer);
} catch (e) {
throw new Error("Wasm validate throws");
}
if (validated !== valid) {
throw new Error("Wasm validate failure" + (valid ? "" : " expected"));
}
return new WebAssembly.Module(buffer);
}
function instance(bytes, imports = registry) {
return new WebAssembly.Instance(module(bytes), imports);
}
function call(instance, name, args) {
return instance.exports[name](...args);
}
function exports(name, instance) {
return {[name]: instance.exports};
}
function assert_return(action, expected) {
let actual = action();
if (!Object.is(actual, expected)) {
throw new Error("Wasm return value " + expected + " expected, got " + actual);
};
}
let f32 = Math.fround;
// simple.wast:1
let $1 = instance("\x00\x61\x73\x6d\x01\x00\x00\x00\x01\x09\x02\x60\x00\x00\x60\x01\x7f\x01\x7d\x03\x04\x03\x00\x00\x01\x05\x03\x01\x00\x01\x07\x1c\x02\x11\x72\x65\x70\x6c\x61\x63\x65\x5f\x6c\x61\x6e\x65\x5f\x74\x65\x73\x74\x00\x01\x04\x72\x65\x61\x64\x00\x02\x08\x01\x00\x0a\x6e\x03\x2a\x00\x41\x10\x43\x00\x00\x80\x3f\x38\x02\x00\x41\x14\x43\x00\x00\x00\x40\x38\x02\x00\x41\x18\x43\x00\x00\x40\x40\x38\x02\x00\x41\x1c\x43\x00\x00\x80\x40\x38\x02\x00\x0b\x39\x01\x01\x7b\x41\x10\x2a\x02\x00\xfd\x13\x21\x00\x20\x00\x41\x10\x2a\x01\x04\xfd\x20\x01\x21\x00\x20\x00\x41\x10\x2a\x01\x08\xfd\x20\x02\x21\x00\x20\x00\x41\x10\x2a\x01\x0c\xfd\x20\x03\x21\x00\x41\x00\x20\x00\xfd\x0b\x02\x00\x0b\x07\x00\x20\x00\x2a\x02\x00\x0b");
// simple.wast:49
call($1, "replace_lane_test", []);
// simple.wast:50
assert_return(() => call($1, "read", [0]), f32(1.0));
// simple.wast:51
assert_return(() => call($1, "read", [4]), f32(2.0));
// simple.wast:52
assert_return(() => call($1, "read", [8]), f32(3.0));
// simple.wast:53
assert_return(() => call($1, "read", [12]), f32(4.0));

View File

@ -0,0 +1,9 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --perf-prof --perf-prof-delete-file
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
new WasmModuleBuilder().instantiate();

View File

@ -0,0 +1,13 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const desc = {
get mutable() {
throw "foo";
},
get value() {
console.trace();
}
};
assertThrowsEquals(() => new WebAssembly.Global(desc), "foo");

View File

@ -0,0 +1,29 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
// Construct a big table switch. The code size will overflow 4096 bytes.
const NUM_CASES = 3073;
let body = [];
// Add one block, so we can jump to this block or to the function end.
body.push(kExprBlock);
body.push(kWasmVoid);
// Add the big BrTable.
body.push(kExprLocalGet, 0);
body.push(kExprBrTable, ...wasmSignedLeb(NUM_CASES));
for (let i = 0; i < NUM_CASES + 1; i++) {
body.push(i % 2);
}
// End the block.
body.push(kExprEnd);
// Create a module for this.
let builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_v_i).addBody(body).exportFunc();
let instance = builder.instantiate();
instance.exports.main(0);

View File

@ -0,0 +1,28 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function() {
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0x80, 0x01,
kExprI32Clz,
kExprI32Const, 0x00,
kExprI64Const, 0x00,
kAtomicPrefix, kExprI64AtomicStore8U, 0x00, 0x00,
kExprEnd, // @13
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
print(instance.exports.main(1, 2, 3));
})();

View File

@ -0,0 +1,25 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging --liftoff --no-wasm-tier-up
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function() {
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */).addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0x00, kExprI64Const, 0xc2, 0xe6, 0x00, kAtomicPrefix,
kExprI64AtomicAdd8U, 0x00, 0xb6, 0x0e, kExprF32SConvertI64,
kExprI32SConvertF32,
kExprEnd, // @14
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(instance.exports.main(1, 2, 3), 0);
})();

View File

@ -0,0 +1,33 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --liftoff --no-wasm-tier-up --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function() {
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction('main', 0 /* sig */)
.addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0x20,
kExprI64LoadMem, 0x00, 0xce, 0xf2, 0xff, 0x01,
kExprBlock, kWasmF32, // @9 f32
kExprI32Const, 0x04,
kExprI32Const, 0x01,
kExprBrTable, 0x01, 0x01, 0x00, // entries=1
kExprEnd, // @19
kExprUnreachable,
kExprEnd, // @21
]);
builder.addExport('main', 0);
assertThrows(
() => {builder.toModule()}, WebAssembly.CompileError,
'WebAssembly.Module(): Compiling function #0:\"main\" failed: ' +
'type error in branch[0] (expected f32, got i32) @+57');
})();

View File

@ -0,0 +1,19 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
const sig = makeSig([kWasmF64, kWasmI64, kWasmI32, kWasmF64], []);
builder.addFunction(undefined, sig).addBody([
kExprI32Const, 0x00, // -
kExprI32Const, 0x00, // -
kExprI32Const, 0x00, // -
kAtomicPrefix, kExprI32AtomicXor16U, 0x01, 0x00, // -
kAtomicPrefix, kExprI32AtomicStore8U, 0x00, 0x00, // -
]);
builder.instantiate();

View File

@ -0,0 +1,18 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js')
let binary = new Binary();
binary.emit_header();
binary.emit_bytes([kTypeSectionCode, 4, 1, kWasmFunctionTypeForm, 0, 0]);
binary.emit_bytes([kFunctionSectionCode, 2, 1, 0]);
binary.emit_bytes([kCodeSectionCode, 6, 1, 4]);
binary.emit_bytes([kUnknownSectionCode, 2, 1, 0]);
binary.emit_bytes([kUnknownSectionCode, 2, 1, 0]);
binary.emit_bytes([kUnknownSectionCode, 2, 1, 0]);
binary.emit_bytes([ kExprEnd]);
let buffer = binary.trunc_buffer();
WebAssembly.compile(buffer).then(
() => assertUnreachable(), () => {/* ignore */});

View File

@ -0,0 +1,50 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addLocals(kWasmI32, 2).addLocals(kWasmF32, 2)
.addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0xf9, 0x00, // i32.const
kExprI32Ior, // i32.or
kExprI32Eqz, // i32.eqz
kExprI32Add, // i32.Add
kSimdPrefix, kExprI32x4Splat, // i32x4.splat
kExprF32Const, 0x46, 0x5d, 0x00, 0x00, // f32.const
kExprI32Const, 0x83, 0x01, // i32.const
kExprI32Const, 0x83, 0x01, // i32.const
kExprI32Const, 0x83, 0x01, // i32.const
kExprI32Add, // i32.Add
kExprI32Add, // i32.Add
kExprIf, kWasmI32, // if @33 i32
kExprI32Const, 0x00, // i32.const
kExprElse, // else @37
kExprI32Const, 0x00, // i32.const
kExprEnd, // end @40
kExprIf, kWasmI32, // if @41 i32
kExprI32Const, 0x00, // i32.const
kExprElse, // else @45
kExprI32Const, 0x00, // i32.const
kExprEnd, // end @48
kExprF32ReinterpretI32, // f32.reinterpret_i32
kExprF32Max, // f32.max
kSimdPrefix, kExprF32x4Splat, // f32x4.splat
kExprI32Const, 0x83, 0x01, // i32.const
kSimdPrefix, kExprI32x4Splat, // i32x4.splat
kSimdPrefix, kExprI32x4Eq, // i32x4.eq
kSimdPrefix, kExprI32x4Eq, // i32x4.eq
kSimdPrefix, kExprV128AnyTrue, // v128.any_true
kExprEnd, // end @64
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
print(instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,25 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */).addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0xba, 0x01, // i32.const
kSimdPrefix, kExprI16x8Splat, // i16x8.splat
kExprMemorySize, 0x00, // memory.size
kSimdPrefix, kExprI16x8ShrS, 0x01, // i16x8.shr_s
kSimdPrefix, kExprV128AnyTrue, // v128.any_true
kExprMemorySize, 0x00, // memory.size
kExprI32RemS, // i32.rem_s
kExprEnd, // end @15
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
instance.exports.main(1, 2, 3);

View File

@ -0,0 +1,13 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function foo() {
'use asm';
function bar() {
return -1e-15;
}
return {bar: bar};
}
assertEquals(-1e-15, foo().bar());

View File

@ -0,0 +1,14 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function* asm() {
"use asm";
function x(v) {
v = v | 0;
}
return x;
}
// 'function*' creates a generator with an implicit 'next' method.
asm().next();

View File

@ -0,0 +1,80 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const kNumberOfWorker = 4;
const workerOnMessage = function({data:msg}) {
if (msg.module) {
let module = msg.module;
let mem = msg.mem;
this.instance = new WebAssembly.Instance(module, {m: {memory: mem}});
postMessage({instantiated: true});
} else {
const kNumberOfRuns = 20;
let result = new Array(kNumberOfRuns);
for (let i = 0; i < kNumberOfRuns; ++i) {
result[i] = instance.exports.grow();
}
postMessage({result: result});
}
};
function spawnWorkers() {
let workers = [];
for (let i = 0; i < kNumberOfWorker; i++) {
let worker = new Worker(
'onmessage = ' + workerOnMessage.toString(), {type: 'string'});
workers.push(worker);
}
return workers;
}
function instantiateModuleInWorkers(workers, module, shared_memory) {
for (let worker of workers) {
worker.postMessage({module: module, mem: shared_memory});
let msg = worker.getMessage();
if (!msg.instantiated) throw 'Worker failed to instantiate';
}
}
function triggerWorkers(workers) {
for (i = 0; i < workers.length; i++) {
let worker = workers[i];
worker.postMessage({});
}
}
(function TestConcurrentGrowMemoryResult() {
let builder = new WasmModuleBuilder();
builder.addImportedMemory('m', 'memory', 1, 500, 'shared');
builder.addFunction('grow', kSig_i_v)
.addBody([kExprI32Const, 1, kExprMemoryGrow, kMemoryZero])
.exportFunc();
const module = builder.toModule();
const shared_memory =
new WebAssembly.Memory({initial: 1, maximum: 500, shared: true});
// Spawn off the workers and run the sequences.
let workers = spawnWorkers();
instantiateModuleInWorkers(workers, module, shared_memory);
triggerWorkers(workers);
let all_results = [];
for (let worker of workers) {
let msg = worker.getMessage();
all_results = all_results.concat(msg.result);
}
all_results.sort((a, b) => a - b);
for (let i = 1; i < all_results.length; ++i) {
assertEquals(all_results[i - 1] + 1, all_results[i]);
}
// Terminate all workers.
for (let worker of workers) {
worker.terminate();
}
})();

View File

@ -0,0 +1,37 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 4).
builder.addFunction(undefined, 0 /* sig */).addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0x00, // i32.const
kExprMemoryGrow, 0x00, // memory.grow
kExprI32Const, 0xd3, 0xe7, 0x03, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x84, 0x80, 0xc0, 0x05, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x84, 0x81, 0x80, 0xc8, 0x01, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x19, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI8x16Shuffle,
0x00, 0x00, 0x17, 0x00, 0x04, 0x04, 0x04, 0x04,
0x04, 0x10, 0x01, 0x00, 0x04, 0x04, 0x04, 0x04, // i8x16.shuffle
kSimdPrefix, kExprI8x16Shuffle,
0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // i8x16.shuffle
kSimdPrefix, kExprI8x16LeU, // i8x16.le_u
kSimdPrefix, kExprV128AnyTrue, // v128.any_true
kExprMemoryGrow, 0x00, // memory.grow
kExprDrop,
kExprEnd, // end @233
]);
builder.addExport('main', 0);
builder.instantiate();

View File

@ -0,0 +1,40 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addGlobal(kWasmI32, true, false, wasmI32Const(35));
builder.addType(makeSig([], [kWasmI32]));
builder.addType(makeSig([kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 3).
builder.addFunction(undefined, 0 /* sig */).addBody([
// signature: i_v
// body:
kExprI32Const, 1, // i32.const
]);
// Generate function 2 (out of 3).
builder.addFunction(undefined, 0 /* sig */).addBody([
// signature: i_v
// body:
kExprI32Const, 0, // i32.const
]);
// Generate function 3 (out of 3).
builder.addFunction(undefined, 1 /* sig */).addBody([
// signature: i_ii
// body:
kExprBlock, kWasmI32, // block @1 i32
kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0, // f64.const
kExprI32SConvertF64, // i32.trunc_f64_s
kExprCallFunction, 1, // call function #1: i_v
kExprBrIf, 0, // br_if depth=0
kExprGlobalGet, 0, // global.get
kExprCallFunction, 0, // call function #0: i_v
kExprBrIf, 0, // br_if depth=0
kExprI32ShrS, // i32.shr_s
kExprEnd, // end @24
]);
builder.addExport('f', 2);
const instance = builder.instantiate();
assertEquals(35, instance.exports.f(0, 0));

View File

@ -0,0 +1,14 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1);
builder.addFunction(undefined, kSig_v_i) .addBodyWithEnd([
kExprI32Const, 1, kExprMemoryGrow, kMemoryZero, kNumericPrefix]);
// Intentionally add just a numeric opcode prefix without the index byte.
const b = builder.toBuffer();
WebAssembly.compile(b).then(() => assertUnreachable(), () => { /* ignore */ })

View File

@ -0,0 +1,23 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
const sig = builder.addType(makeSig(
[kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32],
[]));
builder.addFunction(undefined, sig).addBodyWithEnd([
// signature: v_iiiiifidi
// body:
kExprI32Const, 0x00, // i32.const
kExprI64Const, 0x00, // i64.const
kAtomicPrefix, kExprI64AtomicStore, 0x03, 0x00, // i64.atomic.store64
kExprEnd, // end @9
]);
builder.addExport('main', 0);
assertDoesNotThrow(() => builder.instantiate());

View File

@ -0,0 +1,94 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addGlobal(kWasmI32, true, false);
const sig = builder.addType(makeSig([kWasmI32, kWasmI64, kWasmI64, kWasmI64], [kWasmF32]));
// Generate function 1 (out of 3).
builder.addFunction(undefined, sig)
.addLocals(kWasmI32, 57).addLocals(kWasmI64, 11)
.addBodyWithEnd([
// signature: f_illl
// body:
kExprLocalGet, 0x1b, // local.get
kExprLocalSet, 0x1c, // local.set
kExprI32Const, 0x00, // i32.const
kExprIf, kWasmVoid, // if @11
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x1e, // local.set
kExprBlock, kWasmVoid, // block @19
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x21, // local.set
kExprBlock, kWasmVoid, // block @25
kExprBlock, kWasmVoid, // block @27
kExprBlock, kWasmVoid, // block @29
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x0a, // local.set
kExprI32Const, 0x00, // i32.const
kExprLocalSet, 0x28, // local.set
kExprLocalGet, 0x00, // local.get
kExprLocalSet, 0x0b, // local.set
kExprI32Const, 0x00, // i32.const
kExprBrIf, 0x01, // br_if depth=1
kExprEnd, // end @47
kExprUnreachable, // unreachable
kExprEnd, // end @49
kExprI32Const, 0x01, // i32.const
kExprLocalSet, 0x36, // local.set
kExprI32Const, 0x00, // i32.const
kExprIf, kWasmVoid, // if @56
kExprEnd, // end @59
kExprLocalGet, 0x00, // local.get
kExprLocalSet, 0x10, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Eqz, // i32.eqz
kExprLocalSet, 0x38, // local.set
kExprBlock, kWasmVoid, // block @69
kExprI32Const, 0x7f, // i32.const
kExprI32Eqz, // i32.eqz
kExprLocalSet, 0x39, // local.set
kExprI32Const, 0x01, // i32.const
kExprIf, kWasmVoid, // if @78
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x11, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Eqz, // i32.eqz
kExprLocalSet, 0x12, // local.set
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x13, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x01, // i32.const
kExprI32Sub, // i32.sub
kExprLocalSet, 0x3a, // local.set
kExprI32Const, 0x00, // i32.const
kAtomicPrefix, kExprI64AtomicLoad16U, 0x01, 0x04, // i64.atomic.load16_u
kExprDrop, // drop
kExprI64Const, 0x01, // i64.const
kExprLocalSet, 0x44, // local.set
kExprI64Const, 0x01, // i64.const
kExprLocalSet, 0x3e, // local.set
kExprElse, // else @115
kExprNop, // nop
kExprEnd, // end @117
kExprLocalGet, 0x40, // local.get
kExprLocalSet, 0x41, // local.set
kExprLocalGet, 0x41, // local.get
kExprI64Const, 0x4b, // i64.const
kExprI64Add, // i64.add
kExprDrop, // drop
kExprEnd, // end @128
kExprEnd, // end @129
kExprUnreachable, // unreachable
kExprEnd, // end @132
kExprUnreachable, // unreachable
kExprEnd, // end @134
kExprF32Const, 0x00, 0x00, 0x84, 0x42, // f32.const
kExprEnd, // end @140
]);
const instance = builder.instantiate();

View File

@ -0,0 +1,38 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
const sig = builder.addType(makeSig([], [kWasmI32]));
builder.addFunction(undefined, sig)
.addLocals(kWasmI32, 1002).addLocals(kWasmI64, 3)
.addBodyWithEnd([
// signature: i_v
// body:
kExprLocalGet, 0xec, 0x07, // local.get
kExprLocalGet, 0xea, 0x07, // local.set
kExprLocalGet, 0x17, // local.set
kExprLocalGet, 0xb5, 0x01, // local.set
kExprI32Const, 0x00, // i32.const
kExprIf, kWasmI32, // if @39 i32
kExprI32Const, 0x91, 0xe8, 0x7e, // i32.const
kExprElse, // else @45
kExprI32Const, 0x00, // i32.const
kExprEnd, // end @48
kExprIf, kWasmVoid, // if @49
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x00, // i32.const
kAtomicPrefix, kExprI32AtomicSub, 0x02, 0x04, // i32.atomic.sub
kExprDrop,
kExprEnd,
kExprUnreachable,
kExprEnd
]);
const instance = builder.instantiate();

View File

@ -0,0 +1,37 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
const sig = builder.addType(makeSig(
[
kWasmI64, kWasmI32, kWasmI64, kWasmI32, kWasmI32, kWasmI32, kWasmI32,
kWasmI32, kWasmI32, kWasmI64, kWasmI64, kWasmI64
],
[kWasmI64]));
// Generate function 2 (out of 3).
builder.addFunction(undefined, sig)
.addLocals(kWasmF32, 10)
.addLocals(kWasmI32, 4)
.addLocals(kWasmF64, 1)
.addLocals(kWasmI32, 15)
.addBodyWithEnd([
// signature: v_liliiiiiilll
// body:
kExprI32Const, 0x00, // i32.const
kExprI64Const, 0x00, // i64.const
kExprI64Const, 0x00, // i64.const
kAtomicPrefix, kExprI64AtomicCompareExchange, 0x03,
0x8, // i64.atomic.cmpxchng64
kExprEnd, // end @124
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(
0n, instance.exports.main(1n, 2, 3n, 4, 5, 6, 7, 8, 9, 10n, 11n, 12n, 13n));

View File

@ -0,0 +1,25 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
let memory = new WebAssembly.Memory({
initial: 1,
maximum: 10,
shared: true
});
let builder = new WasmModuleBuilder();
builder.addImportedMemory("m", "imported_mem", 0, 1 << 16, "shared");
builder.addFunction("main", kSig_i_v).addBody([
kExprI32Const, 0,
kAtomicPrefix,
kExprI32AtomicLoad16U, 1, 0]).exportAs("main");
let module = new WebAssembly.Module(builder.toBuffer());
let instance = new WebAssembly.Instance(module, {
m: {
imported_mem: memory
}
});
instance.exports.main();

View File

@ -0,0 +1,23 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */).addBodyWithEnd([
// signature: i_iii
// body:
kExprF32Const, 0xf8, 0xf8, 0xf8, 0xf8,
kSimdPrefix, kExprF32x4Splat, // f32x4.splat
kExprF32Const, 0xf8, 0xf8, 0xf8, 0xf8,
kSimdPrefix, kExprF32x4Splat, // f32x4.splat
kSimdPrefix, kExprF32x4Min, 0x01, // f32x4.min
kSimdPrefix, kExprV128AnyTrue, 0x01, // v128.any_true
kExprEnd, // end @16
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(1, instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,45 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
// This test is shrunk from a test case provided at https://crbug.com/v8/10831.
// This exercises an aligned-load bug in ia32. Some SIMD operations were using
// instructions that required aligned operands (like movaps and movapd), but we
// don't have the right memory alignment yet, see https://crbug.com/v8/9198,
// resulting in a SIGSEGV when running the generated code.
const builder = new WasmModuleBuilder();
builder.addType(makeSig([], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_v
// body:
kExprI32Const, 0xfc, 0xb6, 0xed, 0x02, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0xfc, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI64x2Sub, 0x01, // i64x2.sub
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x81, 0x96, 0xf0, 0xe3, 0x07, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprF64x2Max, 0x01, // f64x2.max
kSimdPrefix, kExprI64x2Sub, 0x01, // i64x2.sub
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x0b, // i32.const
kExprI32LtU, // i32.lt_u
kSimdPrefix, kExprI8x16ReplaceLane, 0x00, // i8x16.replace_lane
kExprI32Const, 0xfc, 0xf8, 0x01, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprF64x2Max, 0x01, // f64x2.max
kSimdPrefix, kExprI16x8MaxS, 0x01, // i16x8.max_s
kSimdPrefix, kExprI8x16AllTrue, // i8x16.all_true
kExprEnd, // end @70
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
print(instance.exports.main());

View File

@ -0,0 +1,29 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
let builder = new WasmModuleBuilder();
let sig_i_iii = builder.addType(kSig_i_iii);
builder.addFunction("main", sig_i_iii)
.addBody([
kExprLocalGet, 1,
kExprLocalGet, 1,
kExprI32Const, 5,
kExprLoop, sig_i_iii,
kExprLocalGet, 1,
kExprBlock, sig_i_iii,
kExprLocalGet, 1,
kExprLocalGet, 2,
kExprBrIf, 1,
kExprDrop,
kExprDrop,
kExprDrop,
kExprEnd,
kExprDrop,
kExprEnd])
.exportAs("main");
let module = new WebAssembly.Module(builder.toBuffer());

View File

@ -0,0 +1,45 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addActiveDataSegment(0, [kExprI32Const, 2], [0x12, 0x00, 0x1c]);
builder.addActiveDataSegment(0, [kExprI32Const, 17],
[0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0xc2, 0x00, 0xb33, 0x03, 0xf6, 0x0e]);
builder.addActiveDataSegment(0, [kExprI32Const, 41],
[0x00, 0xdb, 0xa6, 0xa6, 0x00, 0xe9, 0x1c, 0x06, 0xac]);
builder.addActiveDataSegment(0, [kExprI32Const, 57],
[0x00, 0x00, 0x00, 0x00, 0xda, 0xc0, 0xbe]);
builder.addType(makeSig([kWasmI32], [kWasmI32]));
builder.addType(makeSig([kWasmF32], [kWasmF32]));
builder.addType(makeSig([kWasmF64], [kWasmF64]));
// Generate function 1 (out of 3).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_i
// body:
kExprF32Const, 0x00, 0x00, 0x00, 0x00, // f32.const
kExprF32Const, 0x00, 0x00, 0x00, 0x00, // f32.const
kExprF32Le, // f32.le
kExprLocalTee, 0x00, // local.tee
kExprI32Const, 0xff, 0x00, // i32.const
kAtomicPrefix, kExprAtomicNotify, 0x02, 0x03, // atomic.notify
kExprI32LoadMem16S, 0x00, 0x02, // i32.load16_s
kExprIf, kWasmVoid, // if @28
kExprLocalGet, 0x00, // local.get
kExprReturn, // return
kExprElse, // else @33
kExprUnreachable, // unreachable
kExprEnd, // end @35
kExprUnreachable, // unreachable
kExprEnd, // end @37
]);
builder.addExport('func_194', 0);
let instance = builder.instantiate();
assertEquals(1, instance.exports.func_194(0));

View File

@ -0,0 +1,29 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addType(makeSig(
[kWasmI64, kWasmI32, kWasmF64, kWasmI64, kWasmI64, kWasmI32, kWasmI64],
[]));
builder.addFunction(undefined, 0 /* sig */).addBody([
kExprI32Const, 0, // i32.const
kExprIf, kWasmVoid, // if @3
kExprI32Const, 1, // i32.const
kExprIf, kWasmVoid, // if @7
kExprNop, // nop
kExprElse, // else @10
kExprUnreachable, // unreachable
kExprEnd, // end @12
kExprLocalGet, 0x06, // local.get
kExprLocalSet, 0x00, // local.set
kExprLocalGet, 0x03, // local.get
kExprLocalGet, 0x00, // local.get
kExprI64Sub, // i64.sub
kExprDrop, // drop
kExprUnreachable, // unreachable
kExprEnd // end @24
]);
builder.toModule();

View File

@ -0,0 +1,37 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The test needs --no-liftoff because we can't serialize and deserialize
// Liftoff code.
// Flags: --allow-natives-syntax --expose-gc --no-liftoff
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
const num_functions = 3;
function create_builder() {
const builder = new WasmModuleBuilder();
for (let i = 0; i < num_functions; ++i) {
builder.addFunction('f' + i, kSig_i_v)
.addBody(wasmI32Const(i))
.exportFunc();
}
return builder;
}
const wire_bytes = create_builder().toBuffer();
const serialized = (() => {
const module = new WebAssembly.Module(wire_bytes);
const instance = new WebAssembly.Instance(module);
// Run one function so that serialization happens.
instance.exports.f2();
return %SerializeWasmModule(module);
})();
// Collect the compiled module, to avoid sharing of the NativeModule.
gc();
const module = %DeserializeWasmModule(serialized, wire_bytes);
%SerializeWasmModule(module);

View File

@ -0,0 +1,24 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
// Regression test to exercise Liftoff's i64x2.shr_s codegen, which back up rcx
// to a scratch register, and immediately overwrote the backup, then later
// restoring the incorrect value. See https://crbug.com/v8/10752 and
// https://crbug.com/1111522 for more.
const builder = new WasmModuleBuilder();
// i64x2.shr_s shifts a v128 (with all bits set), by 1, then drops the result.
// The function returns param 2, which should be unmodified.
builder.addFunction(undefined, kSig_i_iii).addBodyWithEnd([
kSimdPrefix, kExprS128Const, ...new Array(16).fill(0xff),
kExprI32Const, 0x01,
kSimdPrefix, kExprI64x2ShrS, 0x01,
kExprDrop,
kExprLocalGet, 0x02,
kExprEnd,
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(3, instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,22 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_iii
// body:
kSimdPrefix, kExprS128Const, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // s128.const
kSimdPrefix, kExprI32x4ExtractLane, 0x00, // i32x4.extract_lane
kExprEnd, // end @22
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(-1, instance.exports.main(1, 2, 3));
// The bug happens on the second call to the same exported function, it returns 0.
assertEquals(-1, instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,12 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
const builder = new WasmModuleBuilder();
let table = new WebAssembly.Table({element: 'anyfunc', initial: 2});
// Big size that causes an int32 overflow.
builder.addImportedTable('m', 'table', 4000000000);
assertThrows(
() => builder.instantiate({m: {table: table}}), WebAssembly.CompileError);

View File

@ -0,0 +1,21 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32);
builder.addType(makeSig([], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_v
// body:
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprS128Load8x8U, 0x03, 0xff, 0xff, 0x3f, // i16x8.load8x8_u
kSimdPrefix, kExprI16x8ExtractLaneS, 0,
kExprEnd, // end @371
]).exportAs('main');
const instance = builder.instantiate();
assertTraps(kTrapMemOutOfBounds, () => instance.exports.main());

View File

@ -0,0 +1,54 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-gc --stress-compaction --stress-scavenge=16
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function TestReturnOddNumberOfReturns() {
let builder = new WasmModuleBuilder();
let void_sig = builder.addType(kSig_v_v);
let mv_sig = builder.addType(
makeSig([], [kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32]));
let gc_index = builder.addImport('q', 'gc', void_sig);
builder.addFunction('main', mv_sig)
.addBodyWithEnd([
kExprCallFunction, gc_index,
kExprI32Const, 1,
kExprI32Const, 2,
kExprI32Const, 3,
kExprI32Const, 4,
kExprI32Const, 5,
kExprEnd
])
.exportFunc();
let instance = builder.instantiate({q: {gc: gc}});
instance.exports.main();
})();
(function TestReturnEvenNumberOfReturns() {
let builder = new WasmModuleBuilder();
let void_sig = builder.addType(kSig_v_v);
let mv_sig =
builder.addType(makeSig([], [kWasmI32, kWasmI32, kWasmI32, kWasmI32]));
let gc_index = builder.addImport('q', 'gc', void_sig);
builder.addFunction('main', mv_sig)
.addBodyWithEnd([
kExprCallFunction, gc_index,
kExprI32Const, 1,
kExprI32Const, 2,
kExprI32Const, 3,
kExprI32Const, 4,
kExprEnd
])
.exportFunc();
let instance = builder.instantiate({q: {gc: gc}});
instance.exports.main();
})();

View File

@ -0,0 +1,45 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This exercises an bug in scalar-lowering for load transforms. In
// particular, if the index input to v128.load32_splat was a extract_lane, the
// input wasn't correctly lowered. This caused the extract_lane node to stick
// around until code-generator, where we hit a mismatch in the register types.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function() {
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
builder.addFunction(undefined, kSig_i_ii)
.addBodyWithEnd([
kExprI32Const, 0,
kExprLocalGet, 0,
kExprI32StoreMem, 0, 0,
kExprI32Const, 4,
kExprLocalGet, 0,
kExprI32StoreMem, 0, 0,
kExprI32Const, 8,
kExprLocalGet, 0,
kExprI32StoreMem, 0, 0,
kExprI32Const, 12,
kExprLocalGet, 0,
kExprI32StoreMem, 0, 0,
// Memory now looks like (in bytes):
// [4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0]
kExprI32Const, 0,
kSimdPrefix, kExprS128LoadMem, 0, 0,
kSimdPrefix, kExprI32x4ExtractLane, 0,
// load 32-bit from byte 4, then splat to all lanes.
kSimdPrefix, kExprS128Load32Splat, 0, 0,
kSimdPrefix, kExprI32x4ExtractLane, 3,
kExprEnd,
])
.exportAs('main');
const instance = builder.instantiate();
assertEquals(4, instance.exports.main(4));
})();

View File

@ -0,0 +1,19 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --liftoff --no-wasm-tier-up --print-code --wasm-staging
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function testPrintCode() {
let builder = new WasmModuleBuilder();
builder.addMemory(1, undefined);
builder
.addFunction('main', makeSig([kWasmI32, kWasmI32, kWasmF64], [kWasmI32]))
.addBody([
kExprLocalGet, 0, kExprLocalGet, 1, kExprI64UConvertI32, kExprLocalGet,
2, kExprI64SConvertF64, kAtomicPrefix, kExprI64AtomicWait, 3, 0
]);
builder.instantiate();
})();

View File

@ -0,0 +1,27 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
// We load-splat a value, then drop it. Verify that the OOB load is not
// eliminated, it should trap. This test case is simplified from the fuzzer
// provided test case in https://crbug.com/1132461.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
builder.addFunction(undefined, makeSig([], [kWasmI32]))
.addBodyWithEnd([
kExprI32Const, 0x00,
kExprI32Const, 0x00,
kSimdPrefix, kExprS128Load32Splat, 0x00, 0xb6, 0xec, 0xd8, 0xb1, 0x03,
kSimdPrefix, kExprI32x4ExtractLane, 0x00,
kExprDrop,
kExprEnd,
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertThrows(() => instance.exports.main());

View File

@ -0,0 +1,56 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-gc --interrupt-budget=100
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
function makeFFI(func, t) {
var builder = new WasmModuleBuilder();
var sig_index = builder.addType(makeSig([t,t,t,t,t,t,t,t,t,t], [t]));
builder.addImport("m", "func", sig_index);
// Try to create a frame with lots of spilled values and parameters
// on the stack to try to catch GC bugs in the reference maps for
// the different parts of the stack.
builder.addFunction("main", sig_index)
.addBody([
kExprLocalGet, 0, // --
kExprLocalGet, 1, // --
kExprLocalGet, 2, // --
kExprLocalGet, 3, // --
kExprLocalGet, 4, // --
kExprLocalGet, 5, // --
kExprLocalGet, 6, // --
kExprLocalGet, 7, // --
kExprLocalGet, 8, // --
kExprLocalGet, 9, // --
kExprCallFunction, 0, // --
kExprDrop, // --
kExprLocalGet, 0, // --
kExprLocalGet, 1, // --
kExprLocalGet, 2, // --
kExprLocalGet, 3, // --
kExprLocalGet, 4, // --
kExprLocalGet, 5, // --
kExprLocalGet, 6, // --
kExprLocalGet, 7, // --
kExprLocalGet, 8, // --
kExprLocalGet, 9, // --
kExprCallFunction, 0, // --
]) // --
.exportFunc();
return builder.instantiate({m: {func: func}}).exports.main;
}
function print10(a, b, c, d, e, f, g, h, i) {
gc();
}
(function F64Test() {
var main = makeFFI(print10, kWasmF64);
for (var i = 1; i < 2e+80; i *= -1137) {
main(i - 1, i, i + 2, i + 3, i + 4, i + 5, i + 6, i + 7, i + 8);
}
})();

View File

@ -0,0 +1,10 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const results = new Array(9).fill(kWasmI32);
builder.addFunction('foo', makeSig([], results)).addBody([kExprUnreachable]);
builder.instantiate();

View File

@ -0,0 +1,44 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function Regress1137608() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig0 = builder.addType(kSig_i_iii);
let sig1 = builder.addType(makeSig([kWasmF64, kWasmF64, kWasmI32,
kWasmI32, kWasmI32, kWasmF32, kWasmI32, kWasmF64, kWasmI32, kWasmF32,
kWasmI32, kWasmF32, kWasmI32, kWasmF64, kWasmI32], [kWasmI32]));
let main = builder.addFunction("main", sig0)
.addBody([
kExprI64Const, 0,
kExprF64UConvertI64,
kExprF64Const, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00,
kExprF64Const, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprF64Mul,
kExprI32Const, 0,
kExprF64Const, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprF64StoreMem, 0x00, 0xb0, 0xe0, 0xc0, 0x81, 0x03,
kExprI32Const, 0,
kExprI32Const, 0,
kExprI32Const, 0,
kExprF32Const, 0x00, 0x00, 0x00, 0x00,
kExprI32Const, 0,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprI32Const, 0,
kExprF32Const, 0x00, 0x00, 0x00, 0x00,
kExprI32Const, 0,
kExprF32Const, 0x00, 0x00, 0x00, 0x00,
kExprI32Const, 0,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
kExprI32Const, 0,
kExprI32Const, 2,
kExprReturnCallIndirect, sig1, kTableZero]).exportFunc();
builder.addFunction("f", sig1).addBody([kExprI32Const, 0]);
builder.addTable(kWasmAnyFunc, 4, 4);
builder.addMemory(16, 32, true);
let module = new WebAssembly.Module(builder.toBuffer());
let instance = new WebAssembly.Instance(module);
})();

View File

@ -0,0 +1,25 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
builder.addType(makeSig([], []));
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: v_v
// body:
kExprI32Const, 0x00,
kExprI32Const, 0x00,
kExprI32Const, 0x00,
kAtomicPrefix, kExprI32AtomicCompareExchange8U, 0x00, 0xc3, 0x01,
kExprDrop,
kExprEnd, // end @193
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
print(instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,39 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addGlobal(kWasmI32, true, false);
builder.addFunction(undefined, kSig_v_i)
.addLocals(kWasmI32, 5)
.addBody([
// signature: v_i
// body:
kExprGlobalGet, 0x00, // global.get
kExprI32Const, 0x10, // i32.const
kExprI32Sub, // i32.sub
kExprLocalTee, 0x02, // local.tee
kExprGlobalSet, 0x00, // global.set
kExprBlock, kWasmVoid, // block @12
kExprLocalGet, 0x00, // local.get
kExprI32LoadMem, 0x02, 0x00, // i32.load
kExprI32Eqz, // i32.eqz
kExprIf, kWasmVoid, // if @20
kExprLocalGet, 0x02, // local.get
kExprI32Const, 0x00, // i32.const
kExprI32StoreMem, 0x02, 0x0c, // i32.store
kExprLocalGet, 0x00, // local.get
kExprI32Const, 0x20, // i32.const
kExprI32Add, // i32.add
kExprLocalSet, 0x05, // local.set
kExprLocalGet, 0x00, // local.get
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x01, // i32.const
kAtomicPrefix, kExprI32AtomicCompareExchange, 0x02, 0x20, // i32.atomic.cmpxchng32
]);
assertThrows(() => builder.toModule(), WebAssembly.CompileError);

View File

@ -0,0 +1,56 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addGlobal(kWasmI32, true, false);
builder.addType(makeSig([], [kWasmF64]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addLocals(kWasmI32, 8).addLocals(kWasmI64, 3)
.addBodyWithEnd([
// signature: d_v
// body:
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x00, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Eqz, // i32.eqz
kExprLocalSet, 0x01, // local.set
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x02, // local.set
kExprI32Const, 0x01, // i32.const
kExprI32Const, 0x01, // i32.const
kExprI32Sub, // i32.sub
kExprLocalSet, 0x03, // local.set
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x04, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Eqz, // i32.eqz
kExprLocalSet, 0x05, // local.set
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x06, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x01, // i32.const
kExprI32Sub, // i32.sub
kExprLocalSet, 0x07, // local.set
kExprBlock, kWasmVoid, // block @45
kExprI32Const, 0x00, // i32.const
kExprIf, kWasmVoid, // if @49
kExprLocalGet, 0x0a, // local.get
kExprLocalSet, 0x08, // local.set
kExprElse, // else @55
kExprNop, // nop
kExprEnd, // end @57
kExprLocalGet, 0x08, // local.get
kExprLocalSet, 0x09, // local.set
kExprLocalGet, 0x09, // local.get
kExprI64Const, 0xff, 0x01, // i64.const
kExprI64Add, // i64.add
kExprDrop, // drop
kExprEnd, // end @69
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // f64.const
kExprEnd, // end @79
]);
builder.instantiate();

View File

@ -0,0 +1,27 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function Regress11472() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let throw_fn = builder.addFunction('throw', kSig_v_v)
.addBody([kExprNop])
.exportFunc();
builder.addFunction('test', kSig_i_ii)
.addBody([
kExprTry, kWasmI32,
kExprCallFunction, throw_fn.index,
kExprCallFunction, throw_fn.index,
kExprTry, kWasmI32,
kExprCallFunction, throw_fn.index,
kExprI32Const, 1,
kExprDelegate, 0,
kExprCatchAll,
kExprI32Const, 2,
kExprEnd,
]).exportFunc();
instance = builder.instantiate();
})();

View File

@ -0,0 +1,14 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test that decoding of 'br' exits early and does not invoke the codegen
// interface when reading the LEB128 branch target fails.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_v_v)
.addBodyWithEnd([kExprBr, 0xFF]);
assertThrows(() => builder.instantiate(), WebAssembly.CompileError);

View File

@ -0,0 +1,59 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addGlobal(kWasmI32, true, false);
builder.addGlobal(kWasmI32, true, false);
builder.addType(makeSig([kWasmI32, kWasmI64, kWasmI32], []));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addLocals(kWasmI32, 10)
.addBodyWithEnd([
// signature: v_ili
// body:
kExprI32Const, 0x00, // i32.const
kExprLocalSet, 0x04, // local.set
kExprI32Const, 0x01, // i32.const
kExprLocalSet, 0x05, // local.set
kExprBlock, kWasmVoid, // block @11
kExprBr, 0x00, // br depth=0
kExprEnd, // end @15
kExprGlobalGet, 0x01, // global.get
kExprLocalSet, 0x03, // local.set
kExprLocalGet, 0x03, // local.get
kExprI32Const, 0x01, // i32.const
kExprI32Sub, // i32.sub
kExprLocalSet, 0x06, // local.set
kExprI64Const, 0x01, // i64.const
kExprLocalSet, 0x01, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Eqz, // i32.eqz
kExprLocalSet, 0x07, // local.set
kExprBlock, kWasmVoid, // block @36
kExprBr, 0x00, // br depth=0
kExprEnd, // end @40
kExprGlobalGet, 0x01, // global.get
kExprLocalSet, 0x08, // local.set
kExprI32Const, 0x01, // i32.const
kExprI32Const, 0x01, // i32.const
kExprI32Sub, // i32.sub
kExprLocalSet, 0x09, // local.set
kExprLocalGet, 0x00, // local.get
kExprLocalSet, 0x0a, // local.set
kExprGlobalGet, 0x00, // global.get
kExprLocalSet, 0x0b, // local.set
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x0f, // i32.const
kExprI32And, // i32.and
kExprLocalSet, 0x0c, // local.set
kExprI32Const, 0x00, // i32.const
kAtomicPrefix, kExprI64AtomicLoad, 0x03, 0x04, // i64.atomic.load64
kExprDrop, // drop
kExprUnreachable, // unreachable
kExprEnd, // end @75
]);
builder.toModule();

View File

@ -0,0 +1,38 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-lazy-compilation
// Test case copied from clusterfuzz, this exercises a bug in WasmCompileLazy
// where we are not correctly pushing the full 128-bits of a SIMD register.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const __v_0 = new WasmModuleBuilder();
__v_0.addImportedMemory('m', 'imported_mem');
__v_0.addFunction('main', makeSig([], [])).addBodyWithEnd([
kExprI32Const, 0, kSimdPrefix, kExprS128LoadMem, 0, 0, kExprCallFunction,
0x01, kExprEnd
]);
__v_0.addFunction('function2', makeSig([kWasmS128], [])).addBodyWithEnd([
kExprI32Const, 17, kExprLocalGet, 0, kSimdPrefix, kExprS128StoreMem, 0, 0,
kExprI32Const, 9, kExprLocalGet, 0, kExprCallFunction, 0x02, kExprEnd
]);
__v_0.addFunction('function3', makeSig([kWasmI32, kWasmS128], []))
.addBodyWithEnd([
kExprI32Const, 32, kExprLocalGet, 1, kSimdPrefix, kExprS128StoreMem, 0, 0,
kExprEnd
]);
__v_0.addExport('main');
var __v_1 = new WebAssembly.Memory({
initial: 1,
});
const __v_2 = __v_0.instantiate({m: {imported_mem: __v_1}});
const __v_3 = new Uint8Array(__v_1.buffer);
for (let __v_4 = 0; __v_4 < 16; __v_4++) {
__v_3[__v_4] = __v_4 * 2;
}
__v_2.exports.main();
for (let __v_5 = 0; __v_5 < 16; __v_5++) {
assertEquals(__v_3[__v_5], __v_3[__v_5 + 32]);
}

View File

@ -0,0 +1,56 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
// This is a fuzzer-generated test case that exposed a bug in Liftoff that only
// affects ARM, where the fp register aliasing is different from other archs.
// We were inncorrectly clearing the the high fp register in a LiftoffRegList
// indicating registers to load, hitting a DCHECK.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(19, 32);
builder.addGlobal(kWasmI32, false, false);
builder.addType(makeSig([], []));
builder.addType(makeSig([kWasmI64, kWasmS128, kWasmF32], [kWasmI32]));
// Generate function 1 (out of 5).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: v_v
// body:
kExprI32Const, 0x05, // i32.const
kExprReturn, // return
kExprUnreachable, // unreachable
kExprEnd, // end @5
]);
// Generate function 4 (out of 5).
builder.addFunction(undefined, 1 /* sig */)
.addBodyWithEnd([
// signature: i_lsf
// body:
kExprLocalGet, 0x01, // local.get
kExprLocalGet, 0x01, // local.get
kExprGlobalGet, 0x00, // global.get
kExprDrop, // drop
kExprLoop, kWasmVoid, // loop @8
kExprLoop, 0x00, // loop @10
kExprI32Const, 0x01, // i32.const
kExprMemoryGrow, 0x00, // memory.grow
kExprI64LoadMem8U, 0x00, 0x70, // i64.load8_u
kExprLoop, 0x00, // loop @19
kExprCallFunction, 0x00, // call function #0: v_v
kExprEnd, // end @23
kExprI64Const, 0xf1, 0x24, // i64.const
kExprGlobalGet, 0x00, // global.get
kExprDrop, // drop
kExprBr, 0x00, // br depth=0
kExprEnd, // end @32
kExprEnd, // end @33
kExprI32Const, 0x5b, // i32.const
kExprReturn, // return
kExprEnd, // end @37
]);
// Instantiation is enough to cause a crash.
const instance = builder.instantiate();

View File

@ -0,0 +1,79 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
// This test is manually reduced from a fuzzer test case at
// https://crbug.com/1161954. This exercises a bug in IA32 instruction
// selection for v128.select, in the AVX case it was too flexible and allowed
// the input operands to be slots, but the code-gen required them to be
// registers.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
// Generate function 1 (out of 1).
builder.addFunction(undefined, kSig_i_v)
.addBodyWithEnd([
// signature: i_v
// body:
kExprI32Const, 0x37, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0xb9, 0xf2, 0xd8, 0x01, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprS128AndNot, // s128.andnot
kExprI32Const, 0xb2, 0xf2, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0xf2, 0x82, 0x02, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprF64x2Max, 0x01, // f64x2.max
kSimdPrefix, kExprI16x8Add, 0x01, // i16x8.add
kSimdPrefix, kExprS128Or, // s128.or
kSimdPrefix, kExprI8x16Neg, // i8x16.neg
kExprI32Const, 0x8e, 0x1c, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x9d, 0x26, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0xf0, 0xe0, 0x01, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI8x16LeS, // i8x16.le_s
kSimdPrefix, kExprI8x16LeS, // i8x16.le_s
kExprI32Const, 0xff, 0xfb, 0x03, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x93, 0x26, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x9d, 0x26, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI8x16GtU, // i8x16.gt_u
kExprI32Const, 0xf0, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI16x8Mul, 0x01, // i16x8.mul
kSimdPrefix, kExprF32x4Ge, // f32x4.ge
kSimdPrefix, kExprI8x16LeS, // i8x16.le_s
kSimdPrefix, kExprI8x16LeS, // i8x16.le_s
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0xc1, 0x8e, 0x35, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x0d, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI32x4Ne, // i32x4.ne
kSimdPrefix, kExprF32x4Ge, // f32x4.ge
kSimdPrefix, kExprI8x16LeS, // i8x16.le_s
kExprI32Const, 0xc1, 0x8e, 0x35, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x0d, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprS128Select, // s128.select
kSimdPrefix, kExprF64x2Div, 0x01, // f64x2.div
kSimdPrefix, kExprF64x2ExtractLane, 0x00, // f64x2.extract_lane
kNumericPrefix, kExprI32SConvertSatF64, // i32.trunc_sat_f64_s
kExprEnd, // end @142
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
print(instance.exports.main());

View File

@ -0,0 +1,42 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
// This test case is simplified slightly from a fuzzer-generated test case. It
// causes spills for one of the inputs to kExprI64x2ExtMulHighI32x4U, which the
// codegen incorrectly assumes will always be a register.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
// Generate function 1 (out of 1).
builder.addFunction(undefined, kSig_i_v)
.addLocals(kWasmI64, 1)
.addBodyWithEnd([
// signature: i_v
// body:
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x00, // i32.const
kExprSelectWithType, 0x01, 0x7f, // select
kExprMemoryGrow, 0x00, // memory.grow
kExprI32Const, 0xb0, 0xde, 0xc9, 0x03, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0xb0, 0xe0, 0xc0, 0x01, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI64x2ExtMulHighI32x4U, 0x01, // i64x2.extmul_high_i32x4_u
kSimdPrefix, kExprF32x4Le, // f32x4.le
kSimdPrefix, kExprI32x4ExtractLane, 0x00, // i32x4.extract_lane
kExprI32DivS, // i32.div_s
kExprEnd, // end @41
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertThrows(
() => instance.exports.main(),
WebAssembly.RuntimeError,
"divide by zero");

View File

@ -0,0 +1,48 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmF32, kWasmF32, kWasmI32, kWasmI32, kWasmI32, kWasmExternRef, kWasmI32, kWasmI32, kWasmI32, kWasmI32], [kWasmI64]));
// Generate function 1 (out of 2).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: l_ffiiiniiii
// body:
]);
// Generate function 2 (out of 2).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: l_ffiiiniiii
// body:
kExprLocalGet, 0x00, // local.get
kExprLocalGet, 0x01, // local.get
kExprLocalGet, 0x02, // local.get
kExprLocalGet, 0x03, // local.get
kExprI32Const, 0x05, // i32.const
kExprLocalGet, 0x05, // local.get
kExprLocalGet, 0x06, // local.get
kExprLocalGet, 0x07, // local.get
kExprI32Const, 0x5b, // i32.const
kExprI32Const, 0x30, // i32.const
kExprCallFunction, 0x01, // call function #1: l_ffiiiniiii
kExprLocalGet, 0x00, // local.get
kExprLocalGet, 0x01, // local.get
kExprLocalGet, 0x02, // local.get
kExprLocalGet, 0x03, // local.get
kExprLocalGet, 0x07, // local.get
kExprLocalGet, 0x05, // local.get
kExprLocalGet, 0x06, // local.get
kExprLocalGet, 0x07, // local.get
kExprI32Const, 0x7f, // i32.const
kExprI64DivS, // i64.div_s
kExprF64Eq, // f64.eq
kExprI32DivU, // i32.div_u
kExprTableGet, 0x7f, // table.get
kExprI64ShrS, // i64.shr_s
]);
assertThrows(function() { builder.instantiate(); }, WebAssembly.CompileError);

View File

@ -0,0 +1,46 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addType(makeSig(
[
kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmFuncRef, kWasmI32, kWasmI32,
kWasmI32, kWasmI32, kWasmI32
],
[kWasmF64]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: d_iiiiniiiii
// body:
kExprLocalGet, 0x03, // local.get
kExprLocalGet, 0x08, // local.get
kExprLocalGet, 0x00, // local.get
kExprI32Const, 0x01, // i32.const
kExprLocalGet, 0x04, // local.get
kExprLocalGet, 0x05, // local.get
kExprLocalGet, 0x06, // local.get
kExprLocalGet, 0x00, // local.get
kExprLocalGet, 0x07, // local.get
kExprLocalGet, 0x06, // local.get
kExprCallFunction, 0x00, // call function #0: d_iiiiniiiii
kExprLocalGet, 0x00, // local.get
kExprLocalGet, 0x01, // local.get
kExprLocalGet, 0x00, // local.get
kExprLocalGet, 0x08, // local.get
kExprLocalGet, 0x01, // local.get
kExprLocalGet, 0x00, // local.get
kExprLocalGet, 0x01, // local.get
kExprLocalGet, 0x07, // local.get
kExprLocalGet, 0x08, // local.get
kExprLocalGet, 0x09, // local.get
kExprCallFunction, 0x00, // call function #0: d_iiiiniiiii
kExprUnreachable, // unreachable
kExprEnd, // end @46
]);
assertThrows(function() { builder.instantiate(); }, WebAssembly.CompileError);

View File

@ -0,0 +1,42 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addType(makeSig([], []));
builder.addType(makeSig([kWasmI64], [kWasmF32]));
// Generate function 1 (out of 2).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: v_v
// body:
kExprNop, // nop
kExprEnd, // end @2
]);
// Generate function 2 (out of 2).
builder.addFunction(undefined, 1 /* sig */)
.addLocals(kWasmI64, 1)
.addBodyWithEnd([
// signature: f_l
// body:
kExprBlock, kWasmF32, // block @3 f32
kExprI32Const, 0x00, // i32.const
kExprI32Const, 0x01, // i32.const
kExprIf, kWasmI64, // if @9 i64
kExprI64Const, 0x00, // i64.const
kExprElse, // else @13
kExprUnreachable, // unreachable
kExprEnd, // end @15
kAtomicPrefix, kExprI64AtomicStore, 0x03, 0x04, // i64.atomic.store64
kExprF32Const, 0x00, 0x00, 0x00, 0x00, // f32.const
kExprEnd, // end @25
kExprDrop, // drop
kExprF32Const, 0x00, 0x00, 0x80, 0x51, // f32.const
kExprEnd, // end @32
]);
builder.instantiate();

View File

@ -0,0 +1,22 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging --wasm-dynamic-tiering --allow-natives-syntax
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 10);
let loadFct = builder.addFunction('load', kSig_i_i).addBody([
// signature: i_i
// body:
kExprLocalGet, 0, // local.get
kExprI32LoadMem, 0, 0, // i32.load_mem
]).exportFunc();
const instance = builder.instantiate();
const load = instance.exports.load;
for (let i = 0; i < 20; i++) load(1);
%WasmTierUpFunction(load);
assertFalse(%IsLiftoffFunction(load));
load(1);

View File

@ -0,0 +1,28 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(28, 32);
builder.addFunction(undefined, kSig_i_v)
.addLocals(kWasmI32, 61)
.addBody([
kExprI64Const, 0x0, // i64.const
kExprI32Const, 0x0, // i32.const
kExprIf, kWasmVoid, // if
kExprI32Const, 0x0, // i32.const
kExprI32LoadMem, 0x01, 0x23, // i32.load
kExprBrTable, 0x01, 0x00, 0x00, // br_table
kExprEnd, // end
kExprI64SExtendI16, // i64.extend16_s
kExprI32Const, 0x00, // i32.const
kExprLocalGet, 0x00, // local.get
kExprI32StoreMem16, 0x00, 0x10, // i32.store16
kExprUnreachable, // unreachable
]).exportAs('main');
const instance = builder.instantiate();
assertThrows(instance.exports.main, WebAssembly.RuntimeError, 'unreachable');

View File

@ -0,0 +1,29 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --wasm-test-streaming --wasm-lazy-compilation --wasm-lazy-validation
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
(function f1() {
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
builder.addFunction('main', kSig_i_i).addBody([
kExprLocalGet, 0,
kExprI32LoadMem, 0, 0
]).exportFunc();
const instance = builder.instantiate();
instance.exports.main();
})();
(function f2() {
const builder = new WasmModuleBuilder();
builder.addFunction('id', kSig_i_i).addBody([]).exportFunc();
const buffer = builder.toBuffer();
const instance = builder.instantiate();
try {
instance.exports.id();
} catch {}
})();

View File

@ -0,0 +1,64 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --enable-testing-opcode-in-wasm --nowasm-tier-up
// Flags: --wasm-tier-mask-for-testing=2
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
function InstanceMaker(offset) {
var builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
var sig_index = builder.addType(makeSig(
[kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32,
kWasmI32],
[kWasmI32]));
var sig_three = builder.addType(makeSig(
[kWasmI64, kWasmI64, kWasmI64, kWasmI64, kWasmI64, kWasmI64, kWasmI64,
kWasmI64],
[]));
var zero = builder.addFunction("zero", kSig_i_i);
var one = builder.addFunction("one", sig_index);
var two = builder.addFunction("two", kSig_v_i);
var three = builder.addFunction("three", sig_three).addBody([]);
zero.addBody([kExprLocalGet, 0, kExprI32LoadMem, 0, offset]);
one.addBody([
kExprLocalGet, 7,
kExprCallFunction, zero.index]);
two.addBody([
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprI64Const, 0x81, 0x80, 0x80, 0x80, 0x10,
kExprCallFunction, three.index,
kExprI32Const, 0,
kExprI32Const, 0,
kExprI32Const, 0,
kExprI32Const, 0,
kExprI32Const, 0,
kExprI32Const, 0,
kExprI32Const, 0,
kExprI32Const, 0,
kExprCallFunction, one.index,
kExprDrop,
]).exportFunc();
return builder.instantiate({});
}
var instance = InstanceMaker(0);
instance.exports.two();
// Regression test for crbug.com/1224882.
var instance_with_offset = InstanceMaker(4);
instance_with_offset.exports.two();

View File

@ -0,0 +1,11 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-lazy-compilation
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction('foo', kSig_v_v).addBody([kExprDrop]);
assertThrows(() => builder.instantiate(), WebAssembly.CompileError);

View File

@ -0,0 +1,37 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --liftoff --no-wasm-tier-up --wasm-tier-mask-for-testing=2
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
// Generate a Liftoff call with too many reference parameters to fit in
// parameter registers, to force stack parameter slots.
const kManyParams = 32;
const kSigWithManyRefParams = makeSig(
new Array(kManyParams).fill(kWasmExternRef), []);
const kPrepareManyParamsCallBody = Array.from(
{length: kManyParams * 2},
(item, index) => index % 2 == 0 ? kExprLocalGet : 0);
builder.addFunction(undefined, kSigWithManyRefParams).addBody([
]);
builder.addFunction(undefined, kSigWithManyRefParams)
.addBody([
...kPrepareManyParamsCallBody,
kExprCallFunction, 0, // call 0
]);
builder.addFunction(undefined, kSigWithManyRefParams).addBody([
...kPrepareManyParamsCallBody,
kExprCallFunction, 1, // call 1
]).exportAs('manyRefs');
const instance = builder.instantiate();
instance.exports.manyRefs();

View File

@ -0,0 +1,30 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32, true);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
builder.addType(makeSig([], []));
builder.setTableBounds(1, 1);
builder.addActiveElementSegment(0, wasmI32Const(0), [0]);
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0x03, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16ReplaceLane, 0x00, // i8x16.replace_lane
kSimdPrefix, kExprI32x4ExtAddPairwiseI16x8U, // i32x4.extadd_pairwise_i16x8_u
kSimdPrefix, kExprI8x16ExtractLaneU, 0x00, // i8x16.extract_lane_u
kExprEnd, // end @15
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(3, instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,27 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js')
let obj = {};
let proxy = new Proxy(obj, {});
let builder = new WasmModuleBuilder();
builder.addType(kSig_v_v);
let imports = builder.addImport("m","f", kSig_v_v);
let exception = builder.addTag(kSig_v_v);
builder.addFunction("foo", kSig_v_v)
.addBody([
kExprTry,
kWasmVoid,
kExprCallFunction, imports,
kExprCatch, exception,
kExprEnd]
).exportFunc();
let inst = builder.instantiate({
m: {
f: function () {
throw proxy;
}
}
});
assertThrows(inst.exports.foo);

View File

@ -0,0 +1,19 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function Regress1188975() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
builder.addFunction("f", kSig_v_v)
.addBody([
kExprUnreachable,
kExprTry, kWasmVoid,
kExprElse,
kExprCatchAll,
kExprEnd,
]);
assertThrows(() => builder.instantiate(), WebAssembly.CompileError);
})();

View File

@ -0,0 +1,216 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// During Turbofan optimizations, when a TrapIf/Unless node is found to always
// trap, its uses need to be marked as dead. However, in the case that one of
// these uses is a Merge or Loop node, only the input of the Merge/Loop that
// corresponds to the trap should be marked as dead.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
builder.addStruct([makeField(kWasmI32, true)]);
builder.addFunction('test', makeSig([wasmRefNullType(0)], [kWasmI32]))
.addBody([
kExprLocalGet, 0,
kExprRefIsNull,
kExprIf, kWasmI32,
kExprLocalGet, 0,
kGCPrefix, kExprStructGet, 0, 0,
kExprElse,
kExprI32Const, 42,
kExprEnd
])
.exportFunc();
builder.instantiate();
// We include a clusterfuzz-generated testcase for this error verbatim.
const module = new WebAssembly.Module(new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 51, 9, 96, 0, 0, 96,
0, 1, 125, 96, 0, 1, 124, 96, 2, 124, 127, 1, 125, 96, 4,
126, 126, 125, 127, 1, 127, 96, 1, 126, 1, 127, 96, 7, 127, 126,
126, 125, 124, 127, 125, 1, 124, 96, 0, 1, 127, 96, 1, 124, 1,
125, 3, 23, 22, 0, 4, 0, 5, 6, 0, 7, 0, 2, 0, 3,
1, 0, 8, 0, 0, 0, 0, 0, 2, 2, 0, 4, 5, 1, 112,
1, 9, 9, 5, 4, 1, 3, 1, 1, 6, 6, 1, 127, 1, 65,
10, 11, 7, 213, 1, 14, 6, 102, 117, 110, 99, 95, 48, 0, 0,
14, 102, 117, 110, 99, 95, 49, 95, 105, 110, 118, 111, 107, 101, 114,
0, 2, 14, 102, 117, 110, 99, 95, 52, 95, 105, 110, 118, 111, 107,
101, 114, 0, 5, 14, 102, 117, 110, 99, 95, 54, 95, 105, 110, 118,
111, 107, 101, 114, 0, 7, 14, 102, 117, 110, 99, 95, 56, 95, 105,
110, 118, 11, 107, 101, 114, 0, 9, 7, 102, 117, 110, 99, 95, 49,
49, 0, 11, 15, 102, 117, 110, 99, 95, 49, 49, 95, 105, 110, 118,
111, 107, 101, 114, 0, 12, 15, 102, 117, 110, 99, 95, 49, 51, 95,
105, 110, 118, 111, 107, 101, 114, 0, 14, 7, 102, 117, 110, 99, 95,
49, 53, 0, 15, 15, 102, 117, 110, 99, 95, 49, 53, 95, 105, 110,
118, 111, 107, 101, 114, 0, 16, 15, 102, 117, 110, 99, 95, 49, 55,
95, 105, 110, 118, 111, 107, 101, 114, 0, 18, 7, 102, 117, 110, 99,
95, 49, 57, 0, 19, 7, 102, 117, 110, 99, 95, 50, 48, 0, 20,
20, 104, 97, 110, 103, 76, 105, 109, 105, 116, 73, 110, 105, 116, 105,
97, 108, 105, 122, 101, 114, 0, 21, 9, 15, 1, 0, 65, 0, 11,
9, 4, 6, 6, 8, 10, 11, 11, 15, 15, 10, 220, 18, 22, 113,
0, 35, 0, 69, 4, 64, 15, 11, 35, 0, 65, 1, 107, 36, 0,
3, 64, 35, 0, 69, 4, 64, 15, 11, 35, 0, 65, 1, 107, 36,
0, 2, 127, 35, 0, 69, 4, 64, 15, 11, 35, 0, 65, 1, 107,
36, 0, 65, 128, 128, 128, 4, 11, 4, 127, 65, 193, 255, 3, 5,
2, 127, 3, 64, 35, 0, 69, 4, 64, 15, 11, 35, 0, 65, 1,
107, 36, 0, 3, 64, 35, 0, 69, 4, 64, 15, 11, 35, 0, 65,
1, 107, 36, 0, 12, 1, 11, 0, 65, 0, 13, 1, 0, 11, 0,
11, 11, 26, 12, 0, 11, 0, 11, 131, 3, 1, 1, 125, 35, 0,
69, 4, 64, 65, 128, 128, 128, 2, 15, 11, 35, 0, 65, 1, 107,
36, 0, 2, 127, 2, 64, 66, 157, 228, 193, 147, 127, 3, 126, 35,
0, 69, 4, 64, 65, 224, 196, 126, 15, 11, 35, 0, 65, 1, 107,
36, 0, 35, 0, 69, 4, 64, 65, 129, 128, 124, 15, 11, 35, 0,
65, 1, 107, 36, 0, 32, 3, 65, 105, 13, 2, 13, 0, 66, 128,
128, 128, 128, 192, 0, 11, 2, 125, 35, 0, 69, 4, 64, 32, 3,
15, 11, 35, 0, 65, 1, 107, 36, 0, 67, 0, 0, 80, 193, 32,
2, 2, 127, 35, 0, 69, 4, 64, 65, 117, 15, 11, 35, 0, 65,
1, 107, 36, 0, 32, 3, 11, 27, 34, 4, 67, 0, 0, 0, 0,
32, 4, 32, 4, 91, 27, 11, 32, 3, 16, 1, 3, 127, 35, 0,
69, 4, 64, 65, 168, 186, 126, 15, 11, 35, 0, 65, 1, 107, 36,
0, 35, 0, 69, 4, 64, 65, 128, 1, 15, 11, 35, 0, 65, 1,
107, 36, 0, 65, 255, 0, 32, 3, 69, 13, 2, 34, 3, 13, 0,
32, 3, 11, 69, 13, 1, 32, 3, 69, 13, 1, 65, 220, 188, 126,
13, 1, 34, 3, 4, 64, 2, 64, 2, 127, 35, 0, 69, 4, 64,
65, 128, 128, 128, 128, 120, 15, 11, 35, 0, 65, 1, 107, 36, 0,
32, 3, 32, 3, 13, 0, 13, 3, 35, 0, 69, 4, 64, 32, 3,
15, 11, 35, 0, 65, 1, 107, 36, 0, 12, 1, 11, 26, 3, 127,
35, 0, 69, 4, 64, 32, 3, 15, 11, 35, 0, 65, 1, 107, 36,
0, 32, 3, 13, 0, 65, 1, 11, 26, 12, 2, 11, 35, 0, 69,
4, 64, 65, 167, 127, 15, 11, 35, 0, 65, 1, 107, 36, 0, 35,
0, 69, 4, 64, 65, 128, 192, 0, 15, 11, 35, 0, 65, 1, 107,
36, 0, 35, 0, 69, 4, 64, 32, 3, 15, 11, 35, 0, 65, 1,
107, 36, 0, 65, 147, 127, 12, 2, 5, 35, 0, 69, 4, 64, 65,
129, 128, 128, 128, 120, 15, 11, 35, 0, 65, 1, 107, 36, 0, 11,
11, 65, 255, 255, 125, 11, 11, 33, 0, 66, 252, 130, 221, 255, 15,
66, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 67, 0, 0, 234,
66, 65, 252, 224, 168, 179, 122, 16, 1, 26, 11, 178, 2, 1, 2,
127, 35, 0, 69, 4, 64, 65, 120, 15, 11, 35, 0, 65, 1, 107,
36, 0, 2, 127, 35, 0, 69, 4, 64, 65, 0, 15, 11, 35, 0,
65, 1, 107, 36, 0, 2, 127, 35, 0, 69, 4, 64, 65, 0, 15,
11, 35, 0, 65, 1, 107, 36, 0, 65, 128, 8, 11, 4, 127, 65,
0, 5, 2, 127, 65, 0, 65, 129, 126, 69, 13, 2, 4, 64, 3,
64, 35, 0, 69, 4, 64, 65, 159, 216, 137, 124, 15, 11, 35, 0,
65, 1, 107, 36, 0, 65, 0, 40, 2, 3, 26, 35, 0, 69, 4,
64, 65, 222, 136, 126, 15, 11, 35, 0, 65, 1, 107, 36, 0, 3,
64, 35, 0, 4, 64, 35, 0, 65, 1, 107, 36, 0, 12, 1, 5,
65, 128, 8, 15, 11, 0, 11, 0, 11, 0, 5, 3, 64, 35, 0,
69, 4, 64, 65, 0, 15, 11, 35, 0, 65, 1, 107, 36, 0, 2,
127, 35, 0, 69, 4, 64, 65, 0, 15, 11, 35, 0, 65, 1, 107,
36, 0, 65, 0, 2, 127, 35, 0, 69, 4, 64, 65, 0, 15, 11,
35, 0, 65, 1, 107, 36, 0, 3, 64, 35, 0, 69, 4, 64, 65,
0, 15, 11, 35, 0, 65, 1, 107, 36, 0, 11, 65, 1, 254, 18,
0, 22, 11, 69, 13, 0, 11, 13, 0, 35, 0, 69, 4, 64, 65,
128, 124, 15, 11, 35, 0, 65, 1, 107, 36, 0, 3, 64, 35, 0,
69, 4, 64, 65, 224, 216, 2, 15, 11, 35, 0, 65, 1, 107, 36,
0, 35, 0, 69, 4, 64, 65, 128, 128, 2, 15, 11, 35, 0, 65,
1, 107, 36, 0, 65, 190, 127, 12, 3, 11, 0, 11, 0, 11, 0,
11, 11, 11, 11, 23, 0, 35, 0, 69, 4, 64, 32, 4, 15, 11,
35, 0, 65, 1, 107, 36, 0, 65, 0, 43, 3, 2, 11, 116, 0,
65, 141, 176, 126, 66, 217, 236, 126, 66, 128, 1, 67, 0, 0, 0,
79, 68, 0, 0, 0, 0, 0, 0, 80, 64, 65, 76, 67, 0, 0,
128, 95, 16, 4, 26, 65, 32, 66, 129, 128, 128, 128, 120, 66, 230,
212, 156, 252, 15, 67, 0, 0, 160, 64, 68, 0, 0, 0, 0, 0,
0, 224, 67, 65, 127, 67, 0, 0, 128, 128, 16, 4, 26, 65, 255,
166, 200, 177, 123, 66, 185, 127, 66, 128, 128, 128, 128, 8, 67, 0,
0, 0, 93, 68, 0, 0, 0, 0, 0, 0, 96, 67, 65, 150, 224,
126, 67, 0, 0, 0, 88, 16, 4, 26, 11, 111, 0, 35, 0, 69,
4, 64, 65, 144, 194, 0, 15, 11, 35, 0, 65, 1, 107, 36, 0,
3, 64, 35, 0, 69, 4, 64, 65, 0, 15, 11, 35, 0, 65, 1,
107, 36, 0, 3, 64, 35, 0, 69, 4, 64, 65, 124, 15, 11, 35,
0, 65, 1, 107, 36, 0, 35, 0, 69, 4, 64, 65, 111, 15, 11,
35, 0, 65, 1, 107, 36, 0, 3, 127, 35, 0, 69, 4, 64, 65,
128, 128, 2, 15, 11, 35, 0, 65, 1, 107, 36, 0, 65, 128, 128,
126, 11, 69, 13, 0, 12, 1, 11, 0, 69, 0, 13, 0, 0, 11,
0, 11, 14, 0, 16, 6, 26, 16, 6, 26, 16, 6, 26, 16, 6,
26, 11, 34, 0, 35, 0, 69, 4, 64, 68, 0, 0, 0, 0, 0,
0, 224, 67, 15, 11, 35, 0, 65, 1, 107, 36, 0, 68, 26, 192,
255, 255, 255, 255, 255, 255, 11, 5, 0, 16, 8, 26, 11, 26, 0,
35, 0, 69, 4, 64, 67, 0, 0, 0, 0, 15, 11, 35, 0, 65,
1, 107, 36, 0, 67, 0, 0, 128, 214, 11, 26, 0, 35, 0, 69,
4, 64, 67, 0, 0, 0, 90, 15, 11, 35, 0, 65, 1, 107, 36,
0, 67, 0, 0, 44, 194, 11, 8, 0, 16, 11, 26, 16, 11, 26,
11, 26, 0, 35, 0, 69, 4, 64, 67, 0, 0, 0, 197, 15, 11,
35, 0, 65, 1, 107, 36, 0, 67, 117, 227, 255, 255, 11, 38, 0,
68, 129, 255, 255, 255, 255, 255, 255, 255, 16, 13, 26, 68, 0, 0,
0, 0, 0, 0, 16, 65, 16, 13, 26, 68, 193, 255, 255, 255, 255,
255, 255, 255, 16, 13, 26, 11, 30, 0, 35, 0, 69, 4, 64, 15,
11, 35, 0, 65, 1, 107, 36, 0, 35, 0, 69, 4, 64, 15, 11,
35, 0, 65, 1, 107, 36, 0, 11, 6, 0, 16, 15, 16, 15, 11,
16, 0, 35, 0, 69, 4, 64, 15, 11, 35, 0, 65, 1, 107, 36,
0, 11, 8, 0, 16, 17, 16, 17, 16, 17, 11, 52, 0, 35, 0,
69, 4, 64, 68, 0, 0, 0, 0, 0, 0, 0, 0, 15, 11, 35,
0, 65, 1, 107, 36, 0, 3, 124, 35, 0, 4, 124, 35, 0, 65,
1, 107, 36, 0, 12, 1, 5, 68, 0, 0, 0, 0, 0, 128, 109,
64, 11, 11, 11, 218, 7, 3, 4, 127, 1, 126, 2, 125, 35, 0,
69, 4, 64, 68, 255, 255, 255, 255, 255, 255, 239, 255, 15, 11, 35,
0, 65, 1, 107, 36, 0, 2, 124, 3, 64, 35, 0, 69, 4, 64,
68, 0, 0, 0, 0, 0, 0, 42, 192, 15, 11, 35, 0, 65, 1,
107, 36, 0, 2, 64, 3, 64, 35, 0, 69, 4, 64, 68, 0, 0,
0, 0, 0, 0, 176, 64, 15, 11, 35, 0, 65, 1, 107, 36, 0,
65, 128, 127, 34, 2, 4, 127, 32, 0, 5, 35, 0, 69, 4, 64,
68, 0, 0, 192, 137, 207, 250, 239, 65, 15, 11, 35, 0, 65, 1,
107, 36, 0, 3, 64, 35, 0, 69, 4, 64, 68, 0, 0, 0, 245,
255, 255, 239, 65, 15, 11, 35, 0, 65, 1, 107, 36, 0, 65, 134,
82, 34, 0, 33, 3, 32, 1, 69, 13, 0, 11, 35, 0, 69, 4,
64, 68, 0, 0, 0, 0, 0, 0, 144, 192, 15, 11, 35, 0, 65,
1, 107, 36, 0, 32, 1, 69, 13, 2, 32, 4, 16, 3, 13, 1,
65, 116, 33, 0, 12, 3, 11, 33, 2, 3, 127, 35, 0, 69, 4,
64, 68, 77, 69, 29, 145, 255, 255, 255, 255, 15, 11, 35, 0, 65,
1, 107, 36, 0, 32, 1, 13, 0, 32, 2, 34, 0, 34, 1, 11,
13, 0, 11, 3, 64, 35, 0, 69, 4, 64, 68, 0, 0, 0, 0,
0, 0, 48, 64, 15, 11, 35, 0, 65, 1, 107, 36, 0, 35, 0,
69, 4, 64, 68, 0, 0, 0, 0, 0, 160, 102, 64, 15, 11, 35,
0, 65, 1, 107, 36, 0, 32, 1, 33, 2, 65, 7, 17, 0, 0,
3, 127, 35, 0, 69, 4, 64, 68, 0, 0, 0, 0, 0, 0, 240,
63, 15, 11, 35, 0, 65, 1, 107, 36, 0, 2, 127, 35, 0, 69,
4, 64, 68, 0, 0, 0, 0, 0, 128, 78, 192, 15, 11, 35, 0,
65, 1, 107, 36, 0, 66, 129, 128, 128, 128, 120, 66, 128, 128, 2,
32, 0, 27, 33, 4, 65, 177, 152, 126, 11, 4, 64, 3, 64, 35,
0, 69, 4, 64, 68, 0, 0, 0, 0, 0, 0, 16, 195, 15, 11,
35, 0, 65, 1, 107, 36, 0, 16, 6, 65, 15, 113, 65, 130, 128,
126, 254, 0, 2, 0, 4, 64, 32, 0, 32, 1, 32, 2, 27, 4,
127, 65, 207, 230, 157, 153, 4, 34, 0, 5, 65, 140, 226, 132, 187,
6, 11, 26, 5, 67, 151, 255, 255, 255, 33, 6, 11, 32, 2, 13,
0, 66, 128, 128, 128, 128, 128, 1, 33, 4, 11, 11, 3, 64, 35,
0, 69, 4, 64, 68, 0, 0, 0, 0, 32, 250, 239, 64, 15, 11,
35, 0, 65, 1, 107, 36, 0, 32, 6, 26, 3, 127, 35, 0, 69,
4, 64, 68, 0, 0, 0, 0, 0, 0, 128, 67, 15, 11, 35, 0,
65, 1, 107, 36, 0, 3, 127, 35, 0, 69, 4, 64, 68, 0, 0,
0, 0, 0, 0, 77, 64, 15, 11, 35, 0, 65, 1, 107, 36, 0,
67, 80, 255, 55, 202, 33, 6, 32, 2, 69, 13, 0, 65, 110, 11,
34, 3, 13, 4, 32, 2, 33, 0, 32, 3, 69, 13, 0, 65, 128,
96, 11, 69, 13, 0, 32, 1, 4, 127, 2, 127, 35, 0, 69, 4,
64, 68, 138, 255, 255, 255, 255, 255, 255, 255, 15, 11, 35, 0, 65,
1, 107, 36, 0, 35, 0, 69, 4, 64, 68, 215, 255, 255, 255, 255,
255, 255, 255, 15, 11, 35, 0, 65, 1, 107, 36, 0, 65, 185, 127,
2, 127, 35, 0, 69, 4, 64, 68, 0, 0, 0, 0, 0, 0, 224,
195, 15, 11, 35, 0, 65, 1, 107, 36, 0, 65, 0, 11, 13, 0,
4, 64, 68, 0, 0, 0, 0, 0, 0, 240, 66, 32, 3, 65, 4,
17, 3, 0, 26, 5, 32, 1, 69, 13, 3, 11, 32, 2, 34, 1,
11, 5, 65, 129, 1, 34, 1, 34, 0, 11, 69, 13, 2, 11, 32,
1, 65, 15, 113, 65, 128, 128, 32, 34, 1, 254, 0, 2, 0, 69,
13, 0, 65, 128, 128, 32, 65, 129, 128, 124, 32, 0, 27, 11, 34,
0, 13, 0, 65, 4, 66, 217, 208, 176, 127, 254, 24, 3, 0, 12,
0, 11, 0, 11, 3, 127, 35, 0, 69, 4, 64, 68, 0, 0, 0,
0, 0, 128, 84, 64, 15, 11, 35, 0, 65, 1, 107, 36, 0, 35,
0, 69, 4, 64, 68, 177, 255, 255, 255, 255, 255, 255, 255, 15, 11,
35, 0, 65, 1, 107, 36, 0, 32, 2, 13, 0, 35, 0, 69, 4,
64, 68, 0, 0, 0, 0, 0, 0, 64, 195, 15, 11, 35, 0, 65,
1, 107, 36, 0, 32, 0, 69, 13, 0, 35, 0, 69, 4, 64, 68,
0, 0, 0, 0, 0, 0, 96, 64, 15, 11, 35, 0, 65, 1, 107,
36, 0, 3, 124, 35, 0, 69, 4, 64, 68, 0, 0, 0, 0, 0,
0, 16, 184, 15, 11, 35, 0, 65, 1, 107, 36, 0, 32, 3, 13,
0, 68, 0, 0, 0, 0, 0, 0, 224, 195, 11, 32, 0, 13, 2,
26, 35, 0, 69, 4, 64, 68, 0, 0, 0, 0, 0, 0, 192, 66,
15, 11, 35, 0, 65, 1, 107, 36, 0, 32, 1, 13, 0, 35, 0,
69, 4, 64, 68, 0, 0, 0, 0, 0, 0, 240, 191, 15, 11, 35,
0, 65, 1, 107, 36, 0, 65, 128, 126, 11, 13, 0, 11, 35, 0,
69, 4, 64, 68, 136, 255, 255, 255, 255, 255, 255, 255, 15, 11, 35,
0, 65, 1, 107, 36, 0, 68, 0, 0, 0, 0, 0, 0, 0, 192,
11, 11, 6, 0, 65, 10, 36, 0, 11, 11, 15, 1, 0, 65, 0,
11, 9, 109, 0, 0, 0, 0, 0, 0, 0, 38
]));

View File

@ -0,0 +1,39 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: i_iii
// body:
kExprLocalGet, 0x01,
kExprLocalGet, 0x01,
kExprLocalGet, 0x01,
kExprLocalGet, 0x01,
kAtomicPrefix, kExprI32AtomicCompareExchange16U, 0x01, 0x7a,
kExprLocalGet, 0x01,
kExprLocalGet, 0x01,
kExprLocalGet, 0x01,
kExprLocalGet, 0x00,
kExprMemoryGrow, 0x00,
kAtomicPrefix, kExprI32AtomicCompareExchange16U, 0x01, 0x7a,
kExprLocalGet, 0x01,
kExprLocalGet, 0x00,
kAtomicPrefix, kExprI32AtomicCompareExchange16U, 0x01, 0x7a,
kExprLocalGet, 0x01,
kExprLocalGet, 0x00,
kAtomicPrefix, kExprI32AtomicCompareExchange16U, 0x01, 0x7a,
kExprLocalGet, 0x01,
kExprReturnCall, 0x00,
kExprEnd,
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertTraps(kTrapUnalignedAccess, () => instance.exports.main(0, 0, 0));

View File

@ -0,0 +1,35 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmI32, kWasmI64, kWasmF64, kWasmI64], []));
builder.addType(makeSig([kWasmF64], [kWasmF64]));
// Generate function 1 (out of 2).
builder.addFunction(undefined, 0 /* sig */)
.addBodyWithEnd([
// signature: v_ildl
// body:
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // f64.const
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // f64.const
kExprLocalGet, 0x00, // local.get
kExprI32Const, 0x82, 0x7f, // i32.const
kExprI32DivS, // i32.div_s
kExprSelect, // select
kExprCallFunction, 0x01, // call function #1: d_d
kExprDrop, // drop
kExprEnd, // end @29
]);
// Generate function 2 (out of 2).
builder.addFunction(undefined, 1 /* sig */)
.addBodyWithEnd([
// signature: d_d
// body:
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // f64.const
kExprEnd, // end @10
]);
const instance = builder.instantiate();

View File

@ -0,0 +1,38 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
// This is a regression test that is minimized and manually trimmed down. It
// exercises a bug in our attempt to canonicalize shuffle in platform
// independent code, see
// https://bugs.chromium.org/p/v8/issues/detail?id=11542#c6.
const builder = new WasmModuleBuilder();
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
// Generate function 1 (out of 1).
builder.addFunction(undefined, 0 /* sig */).addBodyWithEnd([
// signature: i_iii
// body:
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kExprI32Const, 0x00, // i32.const
kSimdPrefix, kExprI8x16Splat, // i8x16.splat
kSimdPrefix, kExprI8x16Shuffle,
0x00, 0x15,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00, // i8x16.shuffle
kSimdPrefix, kExprI64x2BitMask,
0x01, // i64x2.bitmask
kExprEnd, // end @30
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(0, instance.exports.main(1, 2, 3));

View File

@ -0,0 +1,19 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --trace-turbo-graph
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(`get`, makeSig([], [kWasmExternRef]))
.addBody([kExprTableGet])
.exportFunc();
builder.addFunction(`fill`, makeSig([kWasmI32, kWasmAnyFunc, kWasmI32], []))
.addBody([])
.exportFunc();
try {
builder.toModule();
} catch {}

View File

@ -0,0 +1,13 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
builder = new WasmModuleBuilder();
builder.addImportedMemory();
let leb = [0x80, 0x80, 0x80, 0x80, 0x0c];
builder.addFunction('store', makeSig([kWasmI32, kWasmI32], []))
.addBody([kExprLocalGet, 0, kExprLocalGet, 1, kExprI32StoreMem, 0, ...leb])
.exportFunc();
builder.toModule();

View File

@ -0,0 +1,34 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addType(
makeSig([kWasmF64, kWasmI32, kWasmI32, kWasmF64, kWasmF32], [kWasmI64]));
builder.addFunction(undefined, 0 /* sig */)
.addLocals(kWasmI64, 1)
.addBodyWithEnd([
// signature: l_diidf
// body:
kExprLoop, 0x7e, // loop @3 i64
kExprI64Const, 0x01, // i64.const
kExprEnd, // end @7
kExprBlock, 0x7f, // block @8 i32
kExprLocalGet, 0x05, // local.get
kExprLocalSet, 0x05, // local.set
kExprI32Const, 0x00, // i32.const
kExprEnd, // end @16
kExprLocalGet, 0x05, // local.get
kExprLocalGet, 0x05, // local.get
kAtomicPrefix, kExprI64AtomicCompareExchange, 0x03, 0x04,
kExprI64GtS, // i64.gt_s
kExprDrop, // drop
kExprI64Const, 0x01, // i64.const
kExprEnd, // end @29
]);
const instance = builder.instantiate();

View File

@ -0,0 +1,22 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const two_gb = 2 * 1024 * 1024 * 1024;
builder.addMemory(two_gb / kPageSize + 1);
builder.addFunction('load', kSig_v_v)
.addBody([
kExprI32Const, 0, kExprI32LoadMem, 0, ...wasmUnsignedLeb(two_gb),
kExprDrop
])
.exportFunc();
let instance;
try {
instance = builder.instantiate();
} catch (RangeError) { }
if (instance) {
instance.exports.load();
}

View File

@ -0,0 +1,10 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const k4GB = 4 * 1024 * 1024 * 1024;
let memory = new WebAssembly.Memory({initial: 1});
try {
memory.grow(k4GB - 1);
} catch {}

View File

@ -0,0 +1,32 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(16, 32);
builder.addType(makeSig([kWasmI32, kWasmI32, kWasmI32], [kWasmI32]));
builder.addFunction(undefined, 0 /* sig */).addBody([
kExprI64Const, 0x7a, // i64.const
kExprI64Const, 0x42, // i64.const
kExprI64Const, 0xb4, 0xbd, 0xeb, 0xb5, 0x72, // i64.const
kExprI32Const, 0x37, // i32.const
kExprI32Const, 0x67, // i32.const
kExprI32Const, 0x45, // i32.const
kExprLoop, 0, // loop
kExprLocalGet, 0, // local.get
kExprBrIf, 1, // br_if depth=1
kExprLocalGet, 1, // local.get
kExprLocalGet, 0, // local.get
kExprMemorySize, 0, // memory.size
kExprLocalTee, 0, // local.tee
kExprLocalGet, 0, // local.get
kExprBrIf, 0, // br_if depth=0
kExprUnreachable, // unreachable
kExprEnd, // end
kExprUnreachable, // unreachable
]);
builder.addExport('main', 0);
const instance = builder.instantiate();
assertEquals(16, instance.exports.main(0, 0, 0));

View File

@ -0,0 +1,19 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging --liftoff --no-wasm-tier-up
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
builder.addFunction('test', makeSig([kWasmI32], [kWasmI64]))
.addBody([
...wasmI32Const(1 << 30), // pages to grow
kExprMemoryGrow, 0, // returns -1
kExprI64UConvertI32 // asserts that the i32 is zero extended
])
.exportFunc();
const instance = builder.instantiate();
instance.exports.test();

View File

@ -0,0 +1,39 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --liftoff-only
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function Regress12270() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig = makeSig([], [kWasmF32, kWasmF64, kWasmF64, kWasmF64, kWasmF64, kWasmF64, kWasmF64, kWasmF64, kWasmF64, kWasmF64, kWasmF64]);
let sig_index = builder.addType(sig);
builder.addFunction("main", sig).addBody([
kExprI32Const, 0,
kExprIf, sig_index,
kExprF32Const, 0x0, 0x0, 0x0, 0x0,
kExprBlock, kWasmVoid,
kExprCallFunction, 0,
kExprBr, 1,
kExprEnd,
kExprUnreachable,
kExprElse,
kExprF32Const, 0x00, 0x00, 0x80, 0x3f, // 1.0
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, // 1.0
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, // 2.0
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprF64Const, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
kExprEnd
]).exportFunc();
let instance = builder.instantiate();
assertEquals(1.0, instance.exports.main()[1]);
})();

View File

@ -0,0 +1,13 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_d_v)
.addLocals(kWasmExternRef, 16000)
.addBody([kExprCallFunction, 0]);
builder.toModule();

View File

@ -0,0 +1,13 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-staging
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction(undefined, kSig_v_v)
.addLocals(kWasmExternRef, 16268)
.addBody([kExprLoop, kWasmVoid, kExprEnd]);
builder.toModule();

View File

@ -0,0 +1,18 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
builder.addFunction('main', kSig_d_v)
.addBody([
...wasmI32Const(-3), // i32.const
kExprI32SExtendI8, // i32.extend8_s
kSimdPrefix, kExprS128Load32Splat, 0x01, 0x02, // s128.load32_splat
kExprUnreachable, // unreachable
])
.exportFunc();
const instance = builder.instantiate();
assertTraps(kTrapMemOutOfBounds, instance.exports.main);

View File

@ -0,0 +1,20 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
let array = builder.addArray(kWasmI64, true);
builder.addFunction('test', kSig_v_v)
.addBody([kExprLoop, kWasmVoid,
kExprI64Const, 15,
kExprI32Const, 12,
kGCPrefix, kExprArrayNew, array,
kExprDrop,
kExprEnd])
.exportFunc();
builder.instantiate();

View File

@ -0,0 +1,23 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
let array_index = builder.addArray(kWasmS128, true);
builder.addFunction("main", kSig_i_i)
.addBody([
kExprLocalGet, 0,
kGCPrefix, kExprArrayNewDefault, array_index,
kGCPrefix, kExprArrayLen,
])
.exportFunc();
var instance = builder.instantiate();
assertThrows(
() => instance.exports.main(1 << 26), WebAssembly.RuntimeError,
'requested new array is too large');

View File

@ -0,0 +1,20 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
builder.exportMemoryAs('memory');
builder.addFunction('main', kSig_i_v)
.addBody([
kExprI32Const, 0, // i32.const
kExprI32LoadMem8S, 0, 0, // i32.load8_s
kExprI32LoadMem, 0, 0, // i32.load
])
.exportFunc();
const instance = builder.instantiate();
let mem = new Uint8Array(instance.exports.memory.buffer);
mem[0] = -1;
assertTraps(kTrapMemOutOfBounds, instance.exports.main);

View File

@ -0,0 +1,20 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addMemory(1, 1);
builder.exportMemoryAs('memory');
builder.addFunction('main', kSig_i_v)
.addBody([
kExprI32Const, 0, // i32.const
kExprI32LoadMem16S, 0, 0, // i32.load16_s
kExprI32LoadMem, 0, 0, // i32.load
])
.exportFunc();
const instance = builder.instantiate();
let mem = new Uint16Array(instance.exports.memory.buffer);
mem[0] = -1;
assertTraps(kTrapMemOutOfBounds, instance.exports.main);

View File

@ -0,0 +1,16 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var asm = function(global) {
'use asm';
function f() {}
return f;
};
function asm2(global, imports) {
'use asm';
var asm = imports.asm;
function f() {}
return {f: f};
}
asm2(this, {asm: asm});

View File

@ -0,0 +1,34 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
let array_index = builder.addArray(kWasmI64, true);
let sig_index = builder.addType(kSig_v_v);
let main = builder.addFunction("main", kSig_v_i);
let other = builder.addFunction("other", sig_index).addBody([]);
let table = builder.addTable(kWasmAnyFunc, 1, 1);
builder.addActiveElementSegment(
0, // table
wasmI32Const(0), // offset
[1]); // values
main.addBody([
kExprI64Const, 0x33,
kExprLocalGet, 0,
kGCPrefix, kExprArrayNew, array_index,
kExprDrop,
kExprI32Const, 0,
kExprCallIndirect, sig_index, table.index,
]).exportFunc();
var instance = builder.instantiate();
assertThrows(
() => instance.exports.main(1<<29), WebAssembly.RuntimeError,
'requested new array is too large');

Some files were not shown because too many files have changed in this diff Show More