2016-08-17 17:22:09 +00:00
|
|
|
// 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
|
|
|
|
|
2016-08-23 04:06:52 +00:00
|
|
|
function assertValidAsm(func) {
|
|
|
|
assertTrue(%IsAsmWasmCode(func));
|
2016-08-17 17:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(function TestModuleArgs() {
|
|
|
|
function Module1(stdlib) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
function Module2(stdlib, ffi) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
function Module3(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var modules = [Module1, Module2, Module3];
|
|
|
|
var heap = new ArrayBuffer(1024 * 1024);
|
|
|
|
for (var i = 0; i < modules.length; ++i) {
|
|
|
|
print('Module' + (i + 1));
|
|
|
|
var module = modules[i];
|
2016-08-23 04:06:52 +00:00
|
|
|
var m = module();
|
|
|
|
assertValidAsm(module);
|
2016-08-17 17:22:09 +00:00
|
|
|
var m = module({});
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(module);
|
2016-08-17 17:22:09 +00:00
|
|
|
var m = module({}, {});
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(module);
|
2016-08-17 17:22:09 +00:00
|
|
|
var m = module({}, {}, heap);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(module);
|
2016-08-17 17:22:09 +00:00
|
|
|
var m = module({}, {}, heap, {});
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(module);
|
2016-08-17 17:22:09 +00:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestBadModule() {
|
|
|
|
function Module(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { var y = 3; var x = 1 + y; return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var m = Module({});
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module));
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m.foo());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestBadArgTypes() {
|
|
|
|
function Module(a, b, c) {
|
|
|
|
"use asm";
|
2016-08-23 04:06:52 +00:00
|
|
|
var NaN = a.NaN;
|
2016-08-17 17:22:09 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
var m = Module(1, 2, 3);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module));
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals({}, m);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestBadArgTypesMismatch() {
|
|
|
|
function Module(a, b, c) {
|
|
|
|
"use asm";
|
2016-08-23 04:06:52 +00:00
|
|
|
var NaN = a.NaN;
|
2016-08-17 17:22:09 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
var m = Module(1, 2);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module));
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals({}, m);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestModuleNoStdlib() {
|
|
|
|
function Module() {
|
|
|
|
"use asm";
|
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var m = Module({});
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(Module);
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m.foo());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestModuleWith5() {
|
|
|
|
function Module(a, b, c, d, e) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var heap = new ArrayBuffer(1024 * 1024);
|
|
|
|
var m = Module({}, {}, heap);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module));
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m.foo());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestModuleNoStdlibCall() {
|
|
|
|
function Module(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var m = Module();
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(Module);
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m.foo());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestModuleNew() {
|
|
|
|
function Module(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var m = new Module({}, {});
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(Module);
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m.foo());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestMultipleFailures() {
|
|
|
|
function Module(stdlib) {
|
|
|
|
"use asm";
|
2016-08-23 04:06:52 +00:00
|
|
|
var NaN = stdlib.NaN;
|
2016-08-17 17:22:09 +00:00
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var m1 = Module(1, 2, 3);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module));
|
2016-08-17 17:22:09 +00:00
|
|
|
var m2 = Module(1, 2, 3);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module));
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m1.foo());
|
|
|
|
assertEquals(123, m2.foo());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestFailureThenSuccess() {
|
|
|
|
function MkModule() {
|
|
|
|
function Module(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
2016-08-23 04:06:52 +00:00
|
|
|
var NaN = stdlib.NaN;
|
2016-08-17 17:22:09 +00:00
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
return Module;
|
|
|
|
}
|
|
|
|
var Module1 = MkModule();
|
|
|
|
var Module2 = MkModule();
|
|
|
|
var heap = new ArrayBuffer(1024 * 1024);
|
|
|
|
var m1 = Module1(1, 2, 3);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module1));
|
2016-08-17 17:22:09 +00:00
|
|
|
var m2 = Module2({}, {}, heap);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module2));
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m1.foo());
|
|
|
|
assertEquals(123, m2.foo());
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestSuccessThenFailure() {
|
|
|
|
function MkModule() {
|
|
|
|
function Module(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
2016-08-23 04:06:52 +00:00
|
|
|
var NaN = stdlib.NaN;
|
2016-08-17 17:22:09 +00:00
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
return Module;
|
|
|
|
}
|
|
|
|
var Module1 = MkModule();
|
|
|
|
var Module2 = MkModule();
|
|
|
|
var heap = new ArrayBuffer(1024 * 1024);
|
2016-08-23 04:06:52 +00:00
|
|
|
var m1 = Module1({NaN: NaN}, {}, heap);
|
|
|
|
assertValidAsm(Module1);
|
2016-08-17 17:22:09 +00:00
|
|
|
var m2 = Module2(1, 2, 3);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module2));
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m1.foo());
|
|
|
|
assertEquals(123, m2.foo());
|
|
|
|
})();
|
|
|
|
|
2016-08-18 07:44:15 +00:00
|
|
|
(function TestSuccessThenFailureThenRetry() {
|
|
|
|
function MkModule() {
|
|
|
|
function Module(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
2016-08-23 04:06:52 +00:00
|
|
|
var NaN = stdlib.NaN;
|
2016-08-18 07:44:15 +00:00
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
return Module;
|
|
|
|
}
|
|
|
|
var Module1 = MkModule();
|
|
|
|
var Module2 = MkModule();
|
|
|
|
var heap = new ArrayBuffer(1024 * 1024);
|
2016-08-23 04:06:52 +00:00
|
|
|
var m1a = Module1({NaN: NaN}, {}, heap);
|
|
|
|
assertValidAsm(Module1);
|
2016-08-18 07:44:15 +00:00
|
|
|
var m2 = Module2(1, 2, 3);
|
2016-08-23 04:06:52 +00:00
|
|
|
assertTrue(%IsNotAsmWasmCode(Module2));
|
|
|
|
var m1b = Module1({NaN: NaN}, {}, heap);
|
|
|
|
assertTrue(%IsNotAsmWasmCode(Module1));
|
2016-08-18 07:44:15 +00:00
|
|
|
assertEquals(123, m1a.foo());
|
|
|
|
assertEquals(123, m1b.foo());
|
|
|
|
assertEquals(123, m2.foo());
|
|
|
|
})();
|
|
|
|
|
2016-08-17 17:22:09 +00:00
|
|
|
(function TestBoundFunction() {
|
|
|
|
function Module(stdlib, ffi, heap) {
|
|
|
|
"use asm";
|
|
|
|
function foo() { return 123; }
|
|
|
|
return { foo: foo };
|
|
|
|
}
|
|
|
|
var heap = new ArrayBuffer(1024 * 1024);
|
|
|
|
var ModuleBound = Module.bind(this, {}, {}, heap);
|
|
|
|
var m = ModuleBound();
|
2016-08-23 04:06:52 +00:00
|
|
|
assertValidAsm(Module);
|
2016-08-17 17:22:09 +00:00
|
|
|
assertEquals(123, m.foo());
|
|
|
|
})();
|