Index: test/mjsunit/asm/asm-validation.js |
diff --git a/test/mjsunit/asm/asm-validation.js b/test/mjsunit/asm/asm-validation.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cac3843f56a5b24699ded3995ea3fba8105bf589 |
--- /dev/null |
+++ b/test/mjsunit/asm/asm-validation.js |
@@ -0,0 +1,94 @@ |
+// 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. |
Michael Starzinger
2016/08/11 11:44:10
Can we add tests for the following?
- Instantiati
bradn
2016/08/12 01:17:09
Done, but Questions:
* The new case seems to be a
Michael Starzinger
2016/08/12 09:21:55
Yes, that is what my intuition of the asm.js spec
|
+ |
+// Flags: --validate-asm --allow-natives-syntax |
+ |
+(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]; |
+ // TODO(bradnelson): Support modules without the stdlib. |
+ var m = module({}); |
+ assertTrue(%IsAsmWasmCode(module)); |
+ var m = module({}, {}); |
+ assertTrue(%IsAsmWasmCode(module)); |
+ var m = module({}, {}, heap); |
+ assertTrue(%IsAsmWasmCode(module)); |
+ var m = module({}, {}, heap, {}); |
+ assertTrue(%IsAsmWasmCode(module)); |
+ } |
+})(); |
+ |
+(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({}); |
+ assertFalse(%IsAsmWasmCode(Module)); |
+ assertEquals(123, m.foo()); |
+})(); |
+ |
+(function TestBadArgTypes() { |
+ function Module(a, b, c) { |
+ "use asm"; |
+ return {}; |
+ } |
+ var m = Module(1, 2, 3); |
+ assertFalse(%IsAsmWasmCode(Module)); |
+ assertEquals({}, m); |
+})(); |
+ |
+(function TestBadArgTypesMismatch() { |
+ function Module(a, b, c) { |
+ "use asm"; |
+ return {}; |
+ } |
+ var m = Module(1, 2); |
+ assertFalse(%IsAsmWasmCode(Module)); |
+ assertEquals({}, m); |
+})(); |
+ |
+(function TestModuleNoStdlib() { |
+ // TODO(bradnelson): |
+ // Support modules like this if they don't use the whole stdlib. |
+ function Module() { |
+ "use asm"; |
+ function foo() { return 123; } |
+ return { foo: foo }; |
+ } |
+ var m = Module({}); |
+ assertFalse(%IsAsmWasmCode(Module)); |
+ assertEquals(123, m.foo()); |
+})(); |
+ |
+(function TestModuleNoStdlibCall() { |
+ function Module(stdlib, ffi, heap) { |
+ "use asm"; |
+ function foo() { return 123; } |
+ return { foo: foo }; |
+ } |
+ // TODO(bradnelson): Support instantiation like this if stdlib is unused. |
+ var m = Module(); |
+ assertFalse(%IsAsmWasmCode(Module)); |
+ assertEquals(123, m.foo()); |
+})(); |