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) { |
(...skipping 15 matching lines...) Expand all Loading... |
26 assertEquals("object", typeof module); | 26 assertEquals("object", typeof module); |
27 return module; | 27 return module; |
28 } | 28 } |
29 | 29 |
30 assertVerifies(kSig_v_v, [kExprNop]); | 30 assertVerifies(kSig_v_v, [kExprNop]); |
31 | 31 |
32 // Arguments aren't allow to start functions. | 32 // Arguments aren't allow to start functions. |
33 assertThrows(() => {instantiate(kSig_i_i, [kExprGetLocal, 0]);}); | 33 assertThrows(() => {instantiate(kSig_i_i, [kExprGetLocal, 0]);}); |
34 assertThrows(() => {instantiate(kSig_i_ii, [kExprGetLocal, 0]);}); | 34 assertThrows(() => {instantiate(kSig_i_ii, [kExprGetLocal, 0]);}); |
35 assertThrows(() => {instantiate(kSig_i_dd, [kExprGetLocal, 0]);}); | 35 assertThrows(() => {instantiate(kSig_i_dd, [kExprGetLocal, 0]);}); |
36 assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);}); | 36 assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);}); |
37 | 37 |
38 (function testInvalidIndex() { | 38 (function testInvalidIndex() { |
39 print("testInvalidIndex"); | 39 print("testInvalidIndex"); |
40 var builder = new WasmModuleBuilder(); | 40 var builder = new WasmModuleBuilder(); |
41 | 41 |
42 var func = builder.addFunction("", kSig_v_v) | 42 var func = builder.addFunction("", kSig_v_v) |
43 .addBody([kExprNop]); | 43 .addBody([kExprNop]); |
44 | 44 |
45 builder.addStart(func.index + 1); | 45 builder.addStart(func.index + 1); |
46 | 46 |
(...skipping 15 matching lines...) Expand all Loading... |
62 })(); | 62 })(); |
63 | 63 |
64 | 64 |
65 (function testRun1() { | 65 (function testRun1() { |
66 print("testRun1"); | 66 print("testRun1"); |
67 var builder = new WasmModuleBuilder(); | 67 var builder = new WasmModuleBuilder(); |
68 | 68 |
69 builder.addMemory(12, 12, true); | 69 builder.addMemory(12, 12, true); |
70 | 70 |
71 var func = builder.addFunction("", kSig_v_v) | 71 var func = builder.addFunction("", kSig_v_v) |
72 .addBody([kExprI8Const, 0, kExprI8Const, 66, kExprI32StoreMem, 0, 0]); | 72 .addBody([kExprI32Const, 0, kExprI32Const, 55, kExprI32StoreMem, 0, 0]); |
73 | 73 |
74 builder.addStart(func.index); | 74 builder.addStart(func.index); |
75 | 75 |
76 var module = builder.instantiate(); | 76 var module = builder.instantiate(); |
77 var memory = module.exports.memory.buffer; | 77 var memory = module.exports.memory.buffer; |
78 var view = new Int8Array(memory); | 78 var view = new Int8Array(memory); |
79 assertEquals(66, view[0]); | 79 assertEquals(55, view[0]); |
80 })(); | 80 })(); |
81 | 81 |
82 (function testRun2() { | 82 (function testRun2() { |
83 print("testRun2"); | 83 print("testRun2"); |
84 var builder = new WasmModuleBuilder(); | 84 var builder = new WasmModuleBuilder(); |
85 | 85 |
86 builder.addMemory(12, 12, true); | 86 builder.addMemory(12, 12, true); |
87 | 87 |
88 var func = builder.addFunction("", kSig_v_v) | 88 var func = builder.addFunction("", kSig_v_v) |
89 .addBody([kExprI8Const, 0, kExprI8Const, 22, kExprI8Const, 55, kExprI32Add,
kExprI32StoreMem, 0, 0]); | 89 .addBody([kExprI32Const, 0, kExprI32Const, 22, kExprI32Const, 55, kExprI32Ad
d, kExprI32StoreMem, 0, 0]); |
90 | 90 |
91 builder.addStart(func.index); | 91 builder.addStart(func.index); |
92 | 92 |
93 var module = builder.instantiate(); | 93 var module = builder.instantiate(); |
94 var memory = module.exports.memory.buffer; | 94 var memory = module.exports.memory.buffer; |
95 var view = new Int8Array(memory); | 95 var view = new Int8Array(memory); |
96 assertEquals(77, view[0]); | 96 assertEquals(77, view[0]); |
97 })(); | 97 })(); |
98 | 98 |
99 (function testStartFFI() { | 99 (function testStartFFI() { |
100 print("testStartFFI"); | 100 print("testStartFFI"); |
101 var ranned = false; | 101 var ranned = false; |
102 var ffi = {gak: {foo : function() { | 102 var ffi = {gak: {foo : function() { |
103 print("we ranned at stert!"); | 103 print("we ranned at stert!"); |
104 ranned = true; | 104 ranned = true; |
105 }}}; | 105 }}}; |
106 | 106 |
107 var builder = new WasmModuleBuilder(); | 107 var builder = new WasmModuleBuilder(); |
108 var sig_index = builder.addType(kSig_v_v); | 108 var sig_index = builder.addType(kSig_v_v); |
109 | 109 |
110 builder.addImport("gak", "foo", sig_index); | 110 builder.addImport("gak", "foo", sig_index); |
111 var func = builder.addFunction("", sig_index) | 111 var func = builder.addFunction("", sig_index) |
112 .addBody([kExprCallFunction, 0]); | 112 .addBody([kExprCallFunction, 0]); |
113 | 113 |
114 builder.addStart(func.index); | 114 builder.addStart(func.index); |
115 | 115 |
116 var module = builder.instantiate(ffi); | 116 var module = builder.instantiate(ffi); |
117 assertTrue(ranned); | 117 assertTrue(ranned); |
118 })(); | 118 })(); |
OLD | NEW |