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,14 @@
// 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: --print-code
function module(global, imports) {
'use asm';
var x = imports.fn;
function f() {}
return f;
}
module(this, {fn: i => i});

View File

@ -0,0 +1,24 @@
// 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.
function setup_proxy() {
// Mess with the prototype to get funky conversion behavior.
Function.prototype.__proto__ = new Proxy(setup_proxy, {
get: async (target, key) => {
console.log(key);
}
});
}
setup_proxy();
function asm(global, imports) {
'use asm';
// Trigger proxy trap when looking up #toPrimitive:
var bar = +imports.bar;
function f() {}
return {f: f};
}
assertThrows(() => asm(undefined, {bar: setup_proxy}), TypeError);

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.
function print_stack(unsigned) {
print('stack:');
print((new Error()).stack);
}
function asm(global, env) {
'use asm';
var print_stack = env.print_stack;
function main() {
var count = 0;
while ((count | 0) < 10) {
print_stack(1);
count = count + 1 | 0;
}
}
return main;
}
asm({}, {'print_stack': print_stack})();

View File

@ -0,0 +1,45 @@
// 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
const initial = 2**16;
const max = 4 * initial;
const memory = new ArrayBuffer(initial, { maxByteLength: max } );
const heap = memory;
function builder(stdlib, foreign, heap) {
"use asm";
const mem = new stdlib.Float64Array(heap);
function add(x, y) {
x = +x;
y = +y;
mem[0] = +x;
mem[1] = +y;
return +mem[0] + +mem[1];
}
return {add: add};
}
// Check that the asm.js module can be instantiated in the asm.js pipeline.
builder(globalThis, undefined, new ArrayBuffer(initial));
assertTrue(%IsAsmWasmCode(builder));
const asm_js_module = builder(globalThis, undefined, heap);
memory.resize(8);
// Memory access out of bounds should return NaN.
assertEquals(NaN, asm_js_module.add(4, 56));
memory.resize(16);
const foo = new Float64Array(memory);
assertEquals(0, foo[1]);

View File

@ -0,0 +1,16 @@
// 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.
function print_stack(unused_arg) {
console.trace();
}
function asm(_, imports) {
'use asm';
var print_stack = imports.print_stack;
function f() {
print_stack(1);
}
return f;
}
asm({}, {'print_stack': print_stack})();

View File

@ -0,0 +1,33 @@
// 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
const memory = new WebAssembly.Memory({ initial: 1, maximum: 4 });
const heap = memory.buffer;
function builder(stdlib, foreign, heap) {
"use asm";
const mem = new stdlib.Float64Array(heap);
function add(x, y) {
x = +x;
y = +y;
return +mem[0] + +mem[1];
}
return {add: add};
}
// Check that the asm.js module can be instantiated in the asm.js pipeline.
builder(globalThis, undefined, new ArrayBuffer(2 ** 16));
assertTrue(%IsAsmWasmCode(builder));
const asm_js_module = builder(globalThis, undefined, heap);
// Should not throw.
memory.grow(0);

View File

@ -0,0 +1,11 @@
// Copyright 2015 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: --validate-asm --allow-natives-syntax
function f() {
"use asm";
}
assertFalse(%IsAsmWasmCode(f));

View File

@ -0,0 +1,20 @@
// 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: --allow-natives-syntax --validate-asm
function __f_76() {
"use asm";
function __f_72() {
%OptimizeFunctionOnNextCall();
}
return {__f_72:__f_72};
}
try {
assertTrue(%IsAsmWasmCode(__f_76));
assertTrue(false);
} catch (e) {
print("Caught: " + e);
}

View File

@ -0,0 +1,25 @@
// 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: --allow-natives-syntax --validate-asm
function __f_7() {
%DeoptimizeFunction(__f_5);
}
function __f_8(global, env) {
"use asm";
var __f_7 = env.__f_7;
function __f_9(i4, i5) {
i4 = i4 | 0;
i5 = i5 | 0;
__f_7();
}
return {__f_9: __f_9}
}
function __f_5() {
var __v_5 = __f_8({}, {'__f_7': __f_7});
assertTrue(%IsAsmWasmCode(__f_8));
__v_5.__f_9(0, 0, 0);
}
__f_5();

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.
// Flags: --validate-asm --allow-natives-syntax
function __f_97(stdlib, buffer) {
"use asm";
var __v_30 = new stdlib.Int32Array(buffer);
function __f_74() {
var __v_27 = 4;
__v_30[__v_27 >> __v_2] = ((__v_30[-1073741825]|-10) + 2) | 0;
}
}
var module = __f_97(this);
assertFalse(%IsAsmWasmCode(__f_97));

View File

@ -0,0 +1,71 @@
// 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: --validate-asm --allow-natives-syntax
var __v_5 = {};
var __v_35 = {};
var __v_44 = {};
var __v_43 = {};
try {
__v_1 = 1;
__v_2 = {
get: function() { return function() {} },
has() { return true },
getOwnPropertyDescriptor: function() {
if (__v_1-- == 0) throw "please die";
return {value: function() {}, configurable: true};
}
};
__v_3 = new Proxy({}, __v_2);
__v_30 = Object.create(__v_35);
with (__v_5) { f() }
} catch(e) { print("Caught: " + e); }
function __f_1(asmfunc, expect) {
var __v_1 = asmfunc.toString();
var __v_2 = __v_1.replace(new RegExp("use asm"), "");
var __v_39 = {Math: Math};
var __v_4 = eval("(" + __v_2 + ")")(__v_3);
print("Testing " + asmfunc.name + " (js)...");
__v_44.valueOf = __v_43;
expect(__v_4);
print("Testing " + asmfunc.name + " (asm.js)...");
var __v_5 = asmfunc(__v_3);
expect(__v_5);
print("Testing " + asmfunc.name + " (wasm)...");
var module_func = eval(__v_1);
var __v_6 = module_func({}, __v_3);
assertTrue(%IsAsmWasmCode(module_func));
expect(__v_6);
}
function __f_2() {
"use asm";
function __f_3() { return 0; }
function __f_4() { return 1; }
function __f_5() { return 4; }
function __f_6() { return 64; }
function __f_7() { return 137; }
function __f_8() { return 128; }
function __f_9() { return -1; }
function __f_10() { return 1000; }
function __f_11() { return 2000000; }
function __f_12() { return 2147483647; }
return {__f_3: __f_3, __f_4: __f_4, __f_5: __f_5, __f_6: __f_6, __f_7: __f_7, __f_8: __f_8,
__f_9: __f_9, __f_10: __f_10, __f_11, __f_12: __f_12};
}
try {
__f_1(__f_2, function(module) {
assertEquals(0, module.__f_3());
assertEquals(1, module.__f_4());
assertEquals(4, module.__f_5());
assertEquals(64, module.__f_6());
assertEquals(128, module.__f_8());
assertEquals(-1, module.__f_9());
assertEquals(1000, module.__f_10());
assertEquals(2000000, module.__f_11());
assertEquals(2147483647, module.__f_12());
});
} catch(e) { print("Caught: " + e); }

View File

@ -0,0 +1,19 @@
// 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: --validate-asm --allow-natives-syntax
(function __f_54() {
function __f_41(stdlib, __v_35) {
"use asm";
__v_35 = __v_35;
function __f_21(int_val, double_val) {
int_val = int_val|0;
double_val = +double_val;
}
return {__f_21:__f_21};
}
__f_41();
assertFalse(%IsAsmWasmCode(__f_41));
})();

View File

@ -0,0 +1,14 @@
// 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: --validate-asm --allow-natives-syntax
function __f_14() {
"use asm";
function __f_15() { return 0; }
function __f_15() { return 137; } // redeclared function
return {};
}
__f_14();
assertFalse(%IsAsmWasmCode(__f_14));

View File

@ -0,0 +1,24 @@
// 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: --validate-asm --allow-natives-syntax
// Changing the code a little to avoid infinite loop
function __f_109() {
"use asm";
function __f_18() {
var a = 0;
while(2147483648) {
a = 1;
break;
}
return a|0;
}
return {__f_18: __f_18};
}
var wasm = __f_109();
assertTrue(%IsAsmWasmCode(__f_109));
assertEquals(1, wasm.__f_18());

View File

@ -0,0 +1,17 @@
// 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: --validate-asm --allow-natives-syntax
function __f_71(stdlib, buffer) {
"use asm";
var __v_22 = new stdlib.Float64Array(buffer);
function __f_26() {
__v_22 = __v_22;
}
return {__f_26: __f_26};
}
__f_71(this);
assertFalse(%IsAsmWasmCode(__f_71));

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
// Copyright 2017 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: --validate-asm --allow-natives-syntax
function Module(stdlib, imports, buffer) {
"use asm";
function f(a,b,c) {
a = a | 0;
b = b | 0;
c = c | 0;
var x = 0;
x = funTable[a & 1](funTable[b & 1](c) | 0) | 0;
return x | 0;
}
function g(a) {
a = a | 0;
return (a + 23) | 0;
}
function h(a) {
a = a | 0;
return (a + 42) | 0;
}
var funTable = [ g, h ];
return f;
}
var f = Module(this);
assertTrue(%IsWasmCode(f));
assertTrue(%IsAsmWasmCode(Module));
assertEquals(165, f(0, 1, 100));

View File

@ -0,0 +1,16 @@
// Copyright 2017 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
function Module(stdlib, imports, buffer) {
"use asm";
function f() {
return (281474976710655 * 1048575) | 0;
}
return { f:f };
}
var m = Module(this);
assertEquals(-1048576, m.f());
assertFalse(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,32 @@
// Copyright 2017 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
(function TestImportSymbolValue() {
function Module(stdlib, foreign) {
"use asm";
var x = +foreign.x;
function f() {}
return { f:f };
}
var foreign = { x : Symbol("boom") };
assertThrows(() => Module(this, foreign));
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestImportMutatingObject() {
function Module(stdlib, foreign) {
"use asm";
var x = +foreign.x;
var PI = stdlib.Math.PI;
function f() { return +(PI + x) }
return { f:f };
}
var stdlib = { Math : { PI : Math.PI } };
var foreign = { x : { valueOf : () => (stdlib.Math.PI = 23, 42) } };
var m = Module(stdlib, foreign);
assertFalse(%IsAsmWasmCode(Module));
assertEquals(65, m.f());
})();

View File

@ -0,0 +1,92 @@
// Copyright 2017 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
let kMinHeapSize = 4096;
(function TestLeftRight() {
function Module(stdlib, foreign, heap) {
"use asm";
var HEAP32 = new stdlib.Int32Array(heap);
function f(i) {
i = i | 0;
return HEAP32[i << 2 >> 2] | 0;
}
return { f:f }
}
var buffer = new ArrayBuffer(kMinHeapSize);
var module = new Module(this, {}, buffer);
assertTrue(%IsAsmWasmCode(Module));
new Int32Array(buffer)[42] = 23;
assertEquals(23, module.f(42));
})();
(function TestRightRight() {
function Module(stdlib, foreign, heap) {
"use asm";
var HEAP32 = new stdlib.Int32Array(heap);
function f(i) {
i = i | 0;
return HEAP32[i >> 2 >> 2] | 0;
}
return { f:f }
}
var buffer = new ArrayBuffer(kMinHeapSize);
var module = new Module(this, {}, buffer)
assertTrue(%IsAsmWasmCode(Module));
new Int32Array(buffer)[42 >> 4] = 23;
assertEquals(23, module.f(42));
})();
(function TestRightLeft() {
function Module(stdlib, foreign, heap) {
"use asm";
var HEAP32 = new stdlib.Int32Array(heap);
function f(i) {
i = i | 0;
return HEAP32[i >> 2 << 2] | 0;
}
return { f:f }
}
var buffer = new ArrayBuffer(kMinHeapSize);
var module = new Module(this, {}, buffer)
assertFalse(%IsAsmWasmCode(Module));
new Int32Array(buffer)[42 & 0xfc] = 23;
assertEquals(23, module.f(42));
})();
(function TestRightButNotImmediate() {
function Module(stdlib, foreign, heap) {
"use asm";
var HEAP32 = new stdlib.Int32Array(heap);
function f(i) {
i = i | 0;
return HEAP32[i >> 2 + 1] | 0;
}
return { f:f }
}
var buffer = new ArrayBuffer(kMinHeapSize);
var module = new Module(this, {}, buffer)
assertFalse(%IsAsmWasmCode(Module));
new Int32Array(buffer)[42 >> 3] = 23;
assertEquals(23, module.f(42));
})();
(function TestLeftOnly() {
function Module(stdlib, foreign, heap) {
"use asm";
var HEAP32 = new stdlib.Int32Array(heap);
function f(i) {
i = i | 0;
return HEAP32[i << 2] | 0;
}
return { f:f }
}
var buffer = new ArrayBuffer(kMinHeapSize);
var module = new Module(this, {}, buffer)
assertFalse(%IsAsmWasmCode(Module));
new Int32Array(buffer)[42 << 2] = 23;
assertEquals(23, module.f(42));
})();

View File

@ -0,0 +1,13 @@
// 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: --validate-asm
function generateAsmJs() {
'use asm';
function fun() { fun(); }
return fun;
}
assertThrows(generateAsmJs(), RangeError);

View File

@ -0,0 +1,33 @@
// Copyright 2017 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
(function TestMathMaxOnLargeInt() {
function Module(stdlib) {
"use asm";
var max = stdlib.Math.max;
function f() {
return max(42,0xffffffff);
}
return f;
}
var f = Module(this);
assertEquals(0xffffffff, f());
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestMathMinOnLargeInt() {
function Module(stdlib) {
"use asm";
var min = stdlib.Math.min;
function f() {
return min(42,0xffffffff);
}
return f;
}
var f = Module(this);
assertEquals(42, f());
assertFalse(%IsAsmWasmCode(Module));
})();

View File

@ -0,0 +1,101 @@
// Copyright 2017 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
(function TestMathCeilReturningFloatish() {
function Module(stdlib) {
"use asm";
var ceil = stdlib.Math.ceil;
var fround = stdlib.Math.fround;
function f(a) {
a = fround(a);
return ceil(a);
}
return f;
}
var f = Module(this);
assertEquals(3, f(2.2));
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestMathFloorReturningFloatish() {
function Module(stdlib) {
"use asm";
var floor = stdlib.Math.floor;
var fround = stdlib.Math.fround;
function f(a) {
a = fround(a);
return floor(a);
}
return f;
}
var f = Module(this);
assertEquals(2, f(2.2));
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestMathSqrtReturningFloatish() {
function Module(stdlib) {
"use asm";
var sqrt = stdlib.Math.sqrt;
var fround = stdlib.Math.fround;
function f(a) {
a = fround(a);
return sqrt(a);
}
return f;
}
var f = Module(this);
assertEquals(Math.sqrt(Math.fround(2.2)), f(2.2));
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestMathAbsReturningFloatish() {
function Module(stdlib) {
"use asm";
var abs = stdlib.Math.abs;
var fround = stdlib.Math.fround;
function f(a) {
a = fround(a);
return abs(a);
}
return f;
}
var f = Module(this);
assertEquals(Math.fround(2.2), f(-2.2));
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestMathMinReturningFloat() {
function Module(stdlib) {
"use asm";
var min = stdlib.Math.min;
var fround = stdlib.Math.fround;
function f(a) {
a = fround(a);
return min(a, a);
}
return f;
}
var f = Module(this);
assertEquals(Math.fround(2.2), f(2.2));
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestMathMaxReturningFloat() {
function Module(stdlib) {
"use asm";
var max = stdlib.Math.max;
var fround = stdlib.Math.fround;
function f(a) {
a = fround(a);
return max(a, a);
}
return f;
}
var f = Module(this);
assertEquals(Math.fround(2.2), f(2.2));
assertTrue(%IsAsmWasmCode(Module));
})();

View File

@ -0,0 +1,39 @@
// Copyright 2017 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
(function TestMathAbsReturningUnsigned() {
function Module(stdlib) {
"use asm";
var abs=stdlib.Math.abs;
function f(a, b) {
a = a | 0;
b = b | 0;
return (abs(a >> 0) == (b >>> 0)) | 0;
}
return f;
}
var f = Module(this);
assertEquals(0, f(1, 2));
assertEquals(1, f(23, 23));
assertEquals(1, f(-42, 42));
assertEquals(1, f(-0x7fffffff, 0x7fffffff));
assertEquals(1, f(-0x80000000, 0x80000000));
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestMathAbsOverflowSignedValue() {
function Module(stdlib) {
"use asm";
var abs=stdlib.Math.abs;
function f() {
return (abs(-0x80000000) > 0) | 0;
}
return f;
}
var f = Module(this);
assertEquals(1, f());
assertTrue(%IsAsmWasmCode(Module));
})();

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: --allow-natives-syntax
(function TestMinusZeroIsDouble() {
function Module(stdlib) {
'use asm';
function f() {
var x = 0.;
x = 1. / +-0;
return +x;
}
return f;
}
var f = Module(this);
assertEquals(-Infinity, f());
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestMinusZeroIsDoubleBracketed() {
function Module(stdlib) {
'use asm';
function f() {
var x = 0.;
x = 1. / (-0);
return +x;
}
return f;
}
var f = Module(this);
assertEquals(-Infinity, f());
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestMinusZeroIsDoubleMultDouble1() {
function Module(stdlib) {
'use asm';
function f() {
var x = 0.;
x = 1. / (-0 * 1.0);
return +x;
}
return f;
}
var f = Module(this);
assertEquals(-Infinity, f());
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestMinusZeroIsDoubleMultDouble2() {
function Module(stdlib) {
'use asm';
function f() {
var x = 0.;
x = 1. / (1.0 * -0);
return +x;
}
return f;
}
var f = Module(this);
assertEquals(-Infinity, f());
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestMinusZeroIsDoubleMultInt() {
function Module(stdlib) {
'use asm';
function f() {
var x = 0.;
x = 1. / (-0 * 1);
return +x;
}
return f;
}
var f = Module(this);
assertFalse(%IsAsmWasmCode(Module));
})();

View File

@ -0,0 +1,13 @@
// Copyright 2017 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: --validate-asm
function Module(stdlib, foreign, heap) {
"use asm";
var a = stdlib.Math.PI;
function f() { return a }
return { f:f };
}
Module.length

View File

@ -0,0 +1,20 @@
// Copyright 2017 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: --validate-asm --allow-natives-syntax
const kMaxLocals = 50000;
const fn_template = '"use asm";\nfunction f() { LOCALS }\nreturn f;';
for (var num_locals = kMaxLocals; num_locals < kMaxLocals + 2; ++num_locals) {
const fn_code = fn_template.replace(
'LOCALS',
Array(num_locals)
.fill()
.map((_, idx) => 'var l' + idx + ' = 0;')
.join('\n'));
const asm_fn = new Function(fn_code);
const f = asm_fn();
f();
assertEquals(num_locals <= kMaxLocals, %IsAsmWasmCode(asm_fn));
}

View File

@ -0,0 +1,18 @@
// Copyright 2018 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: --validate-asm --allow-natives-syntax
function Module(stdlib, imports, buffer) {
"use asm";
function f() {
var bar = 0;
return 0x1e+bar|0;
}
return f;
}
var f = Module(this);
assertTrue(%IsWasmCode(f));
assertTrue(%IsAsmWasmCode(Module));
assertEquals(0x1e, f());

View File

@ -0,0 +1,24 @@
// Copyright 2018 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
function Module(global, env, buffer) {
"use asm";
function test1() {
var x = 0;
x = -1 / 1 | 0;
return x | 0;
}
function test2() {
var x = 0;
x = (-1 / 1) | 0;
return x | 0;
}
return { test1: test1, test2: test2 };
};
let module = Module(this);
assertEquals(-1, module.test1());
assertEquals(-1, module.test2());
assertTrue(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,203 @@
// Copyright 2018 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-math-intrinsics --validate-asm --allow-natives-syntax
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
function verbose(args) {
// print(...args);
}
//=============================================
// Global count of failures
//=============================================
let numFailures = 0;
function reportFailure(name, vals, m, w) {
print(" error: " + name + "(" + vals + ") == " + w + ", expected " + m);
numFailures++;
}
let global_imports = {Math: Math};
let inputs = [
1 / 0,
-1 / 0,
0 / 0,
-2.70497e+38,
-1.4698e+37,
-1.22813e+35,
-1.34584e+34,
-1.0079e+32,
-6.49364e+26,
-3.06077e+25,
-1.46821e+25,
-1.17658e+23,
-1.9617e+22,
-2.7357e+20,
-9223372036854775808.0, // INT64_MIN
-1.48708e+13,
-1.89633e+12,
-4.66622e+11,
-2.22581e+11,
-1.45381e+10,
-2147483904.0, // First float32 after INT32_MIN
-2147483648.0, // INT32_MIN
-2147483520.0, // Last float32 before INT32_MIN
-1.3956e+09,
-1.32951e+09,
-1.30721e+09,
-1.19756e+09,
-9.26822e+08,
-5.09256e+07,
-964300.0,
-192446.0,
-28455.0,
-27194.0,
-20575.0,
-17069.0,
-9167.0,
-960.178,
-113.0,
-62.0,
-15.0,
-7.0,
-1.0,
-0.0256635,
-4.60374e-07,
-3.63759e-10,
-4.30175e-14,
-5.27385e-15,
-1.5707963267948966,
-1.48084e-15,
-2.220446049250313e-16,
-1.05755e-19,
-3.2995e-21,
-1.67354e-23,
-1.11885e-23,
-1.78506e-30,
-1.43718e-34,
-1.27126e-38,
-0.0,
3e-88,
-2e66,
0.0,
2e66,
1.17549e-38,
1.56657e-37,
4.08512e-29,
6.25073e-22,
4.1723e-13,
1.44343e-09,
1.5707963267948966,
5.27004e-08,
9.48298e-08,
5.57888e-07,
4.89988e-05,
0.244326,
1.0,
12.4895,
19.0,
47.0,
106.0,
538.324,
564.536,
819.124,
7048.0,
12611.0,
19878.0,
20309.0,
797056.0,
1.77219e+09,
2147483648.0, // INT32_MAX + 1
4294967296.0, // UINT32_MAX + 1
1.51116e+11,
4.18193e+13,
3.59167e+16,
9223372036854775808.0, // INT64_MAX + 1
18446744073709551616.0, // UINT64_MAX + 1
3.38211e+19,
2.67488e+20,
1.78831e+21,
9.20914e+21,
8.35654e+23,
1.4495e+24,
5.94015e+25,
4.43608e+30,
2.44502e+33,
1.38178e+37,
1.71306e+37,
3.31899e+38,
3.40282e+38,
];
function assertBinop(name, math_func, wasm_func) {
let inputs2 = [ 1, 0.5, -1, -0.5, 0, -0, 1/0, -1/0, 0/0 ];
for (val of inputs) {
verbose(" ", val);
for (val2 of inputs2) {
verbose(" ", val2);
let m = math_func(val, val2);
let w = wasm_func(val, val2);
if (!deepEquals(m, w)) reportFailure(name, [val, val2], m, w);
m = math_func(val2, val);
w = wasm_func(val2, val);
if (!deepEquals(m, w)) reportFailure(name, [val2, val], m, w);
}
}
}
let stdlib = this;
function Module_pow(stdlib) {
"use asm";
var Stdlib = stdlib.Math.pow;
function pow(a, b) {
a = +a;
b = +b;
return +Stdlib(a, b);
}
return {pow: pow};
}
function wasmBinop(name, sig) {
var builder = new WasmModuleBuilder();
var sig_index = builder.addType(sig);
builder.addImport('Math', name, sig_index);
builder.addFunction('main', sig_index)
.addBody([
kExprLocalGet, 0, // --
kExprLocalGet, 1, // --
kExprCallFunction, 0
]) // --
.exportAs('main');
return builder.instantiate(global_imports).exports.main;
}
function asmBinop(name) {
let instance = Module_pow(stdlib);
assertTrue(%IsAsmWasmCode(Module_pow));
let asm_func = instance[name];
if (typeof asm_func != "function") throw "asm[" + full_name + "] not found";
return asm_func;
}
(function TestF64() {
let name = 'pow';
let math_func = Math[name];
let wasm_func = wasmBinop(name, kSig_d_dd);
assertBinop("(f64)" + name, math_func, wasm_func);
let asm_func = asmBinop(name);
assertBinop("(f64)" + name, math_func, asm_func);
})();
assertEquals(0, numFailures);

View File

@ -0,0 +1,30 @@
// 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: --validate-asm --allow-natives-syntax
function Module(stdlib, ffi) {
"use asm";
var log = ffi.log;
function boom() {
while (1) {
label: {
break;
}
log(1);
break;
}
log(2);
}
return { boom: boom }
}
var log_value = 0;
function log(i) {
log_value += i;
}
Module({}, { log: log }).boom();
assertTrue(%IsAsmWasmCode(Module));
assertEquals(2, log_value);

View File

@ -0,0 +1,21 @@
// 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: --allow-natives-syntax
function Module(stdlib) {
"use asm";
var fround = stdlib.Math.fround;
function f(a, b) {
a = +a;
b = +b;
return fround(a, b);
}
return { f: f };
}
var m = Module(this);
assertEquals(23, m.f(23));
assertEquals(42, m.f(42, 65));
assertFalse(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,19 @@
// Copyright 2017 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
function Module(stdlib, foreign, heap) {
"use asm";
var a = new stdlib.Int16Array(heap);
function f() {
return a[23 >> -1];
}
return { f:f };
}
var b = new ArrayBuffer(1024);
var m = Module(this, {}, b);
new Int16Array(b)[0] = 42;
assertEquals(42, m.f());
assertFalse(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,25 @@
// Copyright 2017 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
function MODULE() {
"use asm";
function f() {
bogus_function_table[0 & LIMIT]();
}
return { f:f };
}
var bogus_function_table = [ Object ];
var test_set = [ 0x3fffffff, 0x7fffffff, 0xffffffff ];
for (var i = 0; i < test_set.length; ++i) {
bogus_function_table[i] = Object;
var src = MODULE.toString();
src = src.replace(/MODULE/g, "Module" + i);
src = src.replace(/LIMIT/g, test_set[i]);
var module = eval("(" + src + ")");
module(this).f();
assertFalse(%IsAsmWasmCode(module));
}

View File

@ -0,0 +1,34 @@
// Copyright 2017 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
(function TestThrowingObserver() {
function Module(stdlib, foreign) {
"use asm";
var x = foreign.x | 0;
function f() {}
return { f:f };
}
var observer = { get x() { throw new Error() } };
assertThrows(() => Module(this, observer));
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestMutatingObserver() {
function Module(stdlib, foreign) {
"use asm";
var x = +foreign.x;
var PI = stdlib.Math.PI;
function f() {
return +(PI + x);
}
return { f:f };
}
var stdlib = { Math : { PI : Math.PI } };
var observer = { get x() { stdlib.Math.PI = 23; return 42; } };
var m = Module(stdlib, observer);
assertFalse(%IsAsmWasmCode(Module));
assertEquals(65, m.f());
})();

View File

@ -0,0 +1,31 @@
// Copyright 2017 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: --validate-asm --allow-natives-syntax
(function TestValidationFailureInForStatement() {
function Module() {
"use asm"
function f() {
var a = 0;
for (a = b; 0; 0) {};
return 0;
}
return { f:f };
}
assertThrows(() => Module().f(), ReferenceError);
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestForStatementInVoidFunction() {
function Module() {
"use asm"
function f() {
for (1; 0; 0) {};
}
return { f:f };
}
assertDoesNotThrow(() => Module().f());
assertTrue(%IsAsmWasmCode(Module));
})();

View File

@ -0,0 +1,14 @@
// Copyright 2017 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
function Module(global, env) {
"use asm";
var unused_fun = env.fun;
function f() {}
return { f:f }
}
assertThrows(() => Module(), TypeError);
assertFalse(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,23 @@
// Copyright 2017 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 --expose-gc
function Module(stdlib, env, heap) {
"use asm";
var MEM = new stdlib.Int32Array(heap);
function f() {
MEM[0] = 0;
}
return { f: f };
}
function instantiate() {
var buffer = new ArrayBuffer(4096);
Module(this, {}, buffer).f();
try {} finally {}
gc();
Module(this, {}, buffer).f();
}
instantiate();
assertTrue(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,24 @@
// Copyright 2017 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
function Module() {
"use asm";
function f(i) {
i = i | 0;
switch (i | 0) {
case 2:
// Exceeds value range.
i = 0x1ffffffff;
break;
}
return i | 0;
}
return f;
}
var f = Module();
assertEquals(0, f(0));
assertEquals(1, f(1));
assertEquals(-1, f(2));
assertFalse(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,34 @@
// Copyright 2018 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
function Module(global, env, buffer) {
"use asm";
var HEAPF64 = new global.Float64Array(buffer);
var HEAPF32 = new global.Float32Array(buffer);
var Math_fround = global.Math.fround;
function main_d_f() {
HEAPF64[0] = Math_fround(+HEAPF64[0]);
}
function main_d_fq() {
HEAPF64[1] = HEAPF32[4096];
}
function main_f_dq() {
HEAPF32[4] = HEAPF64[4096];
}
return {main_d_f: main_d_f, main_d_fq: main_d_fq, main_f_dq: main_f_dq};
};
let buffer = new ArrayBuffer(4096);
let module = Module(this, undefined, buffer);
let view64 = new Float64Array(buffer);
let view32 = new Float32Array(buffer);
assertEquals(view64[0] = 2.3, view64[0]);
module.main_d_f();
module.main_d_fq();
module.main_f_dq();
assertTrue(%IsAsmWasmCode(Module));
assertEquals(Math.fround(2.3), view64[0]);
assertTrue(isNaN(view64[1]));
assertTrue(isNaN(view32[4]));

View File

@ -0,0 +1,38 @@
// 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: --allow-natives-syntax
(function TestTrailingJunkAfterExport() {
function Module() {
"use asm";
function f() {}
return {f: f}
%kaboom;
}
assertThrows(() => Module(), ReferenceError);
assertFalse(%IsAsmWasmCode(Module));
})();
(function TestExportWithSemicolon() {
function Module() {
"use asm";
function f() {}
return {f: f};
// appreciate the semicolon
}
assertDoesNotThrow(() => Module());
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestExportWithoutSemicolon() {
function Module() {
"use asm";
function f() {}
return {f: f}
// appreciate the nothingness
}
assertDoesNotThrow(() => Module());
assertTrue(%IsAsmWasmCode(Module));
})();

View File

@ -0,0 +1,19 @@
// 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: --allow-natives-syntax
function Module() {
'use asm';
function f() {}
function g() {
var x = 0.0;
table[x & 3]();
}
var table = [f, f, f, f];
return { g: g };
}
var m = Module();
assertDoesNotThrow(m.g);
assertFalse(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,22 @@
// 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: --allow-natives-syntax
function Module(stdlib, imports, heap) {
"use asm";
var fround = stdlib.Math.fround;
function f() {
var x = fround(-1.7976931348623157e+308);
return fround(x);
}
return { f: f };
}
var m = Module(this);
assertEquals(-Infinity, m.f());
assertTrue(%IsAsmWasmCode(Module));

View File

@ -0,0 +1,18 @@
// 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: --validate-asm --allow-natives-syntax
function __f_100() {
"use asm";
function __f_76() {
var __v_39 = 0;
outer: while (1) {
while (__v_39 == 4294967295) {
}
}
}
return {__f_76: __f_76};
}
assertFalse(%IsAsmWasmCode(__f_100));

View File

@ -0,0 +1,15 @@
// 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: --validate-asm --allow-natives-syntax
function __f_1() {
'use asm';
function __f_3() {
var __v_11 = 1, __v_10 = 0, __v_12 = 0;
__v_12 = (__v_10 | 12) % 4294967295 | -1073741824;
}
return { __f_3: __f_3 };
}
assertFalse(%IsAsmWasmCode(__f_1));