| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
| 6 | 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 | 9 |
| 10 function instantiate(sig, body) { | 10 function instantiate(sig, body) { |
| 11 var builder = new WasmModuleBuilder(); | 11 var builder = new WasmModuleBuilder(); |
| 12 | 12 |
| 13 var func = builder.addFunction("", sig) | 13 var func = builder.addFunction("", sig) |
| 14 .addBody(body); | 14 .addBody(body); |
| 15 | 15 |
| 16 builder.addStart(func.index); | 16 builder.addStart(func.index); |
| 17 | 17 |
| 18 return builder.instantiate(); | 18 return builder.instantiate(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 function assertFails(sig, body) { | |
| 22 try { | |
| 23 var module = instantiate(sig, body); | |
| 24 print("expected failure, but passes"); | |
| 25 assertFalse(true); | |
| 26 } catch (expected) { | |
| 27 print("ok: " + expected); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 function assertVerifies(sig, body) { | 21 function assertVerifies(sig, body) { |
| 32 var module = instantiate(sig, body); | 22 var module = instantiate(sig, body); |
| 33 assertFalse(module === undefined); | 23 assertFalse(module === undefined); |
| 34 assertFalse(module === null); | 24 assertFalse(module === null); |
| 35 assertFalse(module === 0); | 25 assertFalse(module === 0); |
| 36 assertEquals("object", typeof module); | 26 assertEquals("object", typeof module); |
| 37 return module; | 27 return module; |
| 38 } | 28 } |
| 39 | 29 |
| 40 assertVerifies(kSig_v_v, [kExprNop]); | 30 assertVerifies(kSig_v_v, [kExprNop]); |
| 41 assertVerifies(kSig_i_v, [kExprI8Const, 0]); | |
| 42 | 31 |
| 43 // Arguments aren't allow to start functions. | 32 // Arguments aren't allow to start functions. |
| 44 assertFails(kSig_i_i, [kExprGetLocal, 0]); | 33 assertThrows(() => {instantiate(kSig_i_i, [kExprGetLocal, 0]);}); |
| 45 assertFails(kSig_i_ii, [kExprGetLocal, 0]); | 34 assertThrows(() => {instantiate(kSig_i_ii, [kExprGetLocal, 0]);}); |
| 46 assertFails(kSig_i_dd, [kExprGetLocal, 0]); | 35 assertThrows(() => {instantiate(kSig_i_dd, [kExprGetLocal, 0]);}); |
| 36 assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);}); |
| 47 | 37 |
| 48 (function testInvalidIndex() { | 38 (function testInvalidIndex() { |
| 49 print("testInvalidIndex"); | 39 print("testInvalidIndex"); |
| 50 var builder = new WasmModuleBuilder(); | 40 var builder = new WasmModuleBuilder(); |
| 51 | 41 |
| 52 var func = builder.addFunction("", kSig_v_v) | 42 var func = builder.addFunction("", kSig_v_v) |
| 53 .addBody([kExprNop]); | 43 .addBody([kExprNop]); |
| 54 | 44 |
| 55 builder.addStart(func.index + 1); | 45 builder.addStart(func.index + 1); |
| 56 | 46 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 92 |
| 103 builder.addImport("foo", sig_index); | 93 builder.addImport("foo", sig_index); |
| 104 var func = builder.addFunction("", sig_index) | 94 var func = builder.addFunction("", sig_index) |
| 105 .addBody([kExprCallFunction, 0]); | 95 .addBody([kExprCallFunction, 0]); |
| 106 | 96 |
| 107 builder.addStart(func.index); | 97 builder.addStart(func.index); |
| 108 | 98 |
| 109 var module = builder.instantiate(ffi); | 99 var module = builder.instantiate(ffi); |
| 110 assertTrue(ranned); | 100 assertTrue(ranned); |
| 111 })(); | 101 })(); |
| OLD | NEW |