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..6846fb2a67eff7a9debe79fa7fcec2edd5c21de9 |
--- /dev/null |
+++ b/test/mjsunit/asm/asm-validation.js |
@@ -0,0 +1,73 @@ |
+// 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 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 TestModuleNoStdlib() { |
+ // TODO(bradnelson): Support modules like 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()); |
+})(); |