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 | 8 |
9 function instantiate(sig, body) { | 9 function instantiate(sig, body) { |
10 var module = new Array(); | 10 var module = new Array(); |
11 module = module.concat([ | 11 module = module.concat([ |
| 12 // -- header |
| 13 kWasmH0, kWasmH1, kWasmH2, kWasmH3, |
| 14 kWasmV0, kWasmV1, kWasmV2, kWasmV3 |
| 15 ]); |
| 16 module = module.concat([ |
12 // -- signatures | 17 // -- signatures |
13 kDeclSignatures, 1, | 18 kDeclSignatures, 1, |
14 ]); | 19 ]); |
15 module = module.concat(sig); | 20 module = module.concat(sig); |
16 module = module.concat([ | 21 module = module.concat([ |
17 // -- functions | 22 // -- functions |
18 kDeclFunctions, 1, | 23 kDeclFunctions, 1, |
19 0, // decl flags | 24 0, // decl flags |
20 0, 0, // signature | 25 0, 0, // signature |
21 body.length, 0, // body size | 26 body.length, 0, // body size |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 assertVerifies([0, kAstStmt], [kExprNop]); | 61 assertVerifies([0, kAstStmt], [kExprNop]); |
57 assertVerifies([0, kAstI32], [kExprI8Const, 0]); | 62 assertVerifies([0, kAstI32], [kExprI8Const, 0]); |
58 | 63 |
59 // Arguments aren't allow to start functions. | 64 // Arguments aren't allow to start functions. |
60 assertFails([1, kAstI32, kAstI32], [kExprGetLocal, 0]); | 65 assertFails([1, kAstI32, kAstI32], [kExprGetLocal, 0]); |
61 assertFails([2, kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]); | 66 assertFails([2, kAstI32, kAstI32, kAstF32], [kExprGetLocal, 0]); |
62 assertFails([3, kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); | 67 assertFails([3, kAstI32, kAstI32, kAstF32, kAstF64], [kExprGetLocal, 0]); |
63 | 68 |
64 (function testInvalidIndex() { | 69 (function testInvalidIndex() { |
65 var kBodySize = 1; | 70 var kBodySize = 1; |
66 var data = bytes( | 71 var data = bytesWithHeader( |
67 // -- signatures | 72 // -- signatures |
68 kDeclSignatures, 1, | 73 kDeclSignatures, 1, |
69 0, kAstStmt, | 74 0, kAstStmt, |
70 // -- functions | 75 // -- functions |
71 kDeclFunctions, 1, | 76 kDeclFunctions, 1, |
72 0, // decl flags | 77 0, // decl flags |
73 0, 0, // signature | 78 0, 0, // signature |
74 kBodySize, 0, // body size | 79 kBodySize, 0, // body size |
75 kExprNop, // body | 80 kExprNop, // body |
76 // -- declare start function | 81 // -- declare start function |
77 kDeclStartFunction, | 82 kDeclStartFunction, |
78 1 | 83 1 |
79 ); | 84 ); |
80 | 85 |
81 assertThrows(function() { _WASMEXP_.instantiateModule(data); }); | 86 assertThrows(function() { _WASMEXP_.instantiateModule(data); }); |
82 })(); | 87 })(); |
83 | 88 |
84 | 89 |
85 (function testTwoStartFuncs() { | 90 (function testTwoStartFuncs() { |
86 var kBodySize = 1; | 91 var kBodySize = 1; |
87 var data = bytes( | 92 var data = bytesWithHeader( |
88 // -- signatures | 93 // -- signatures |
89 kDeclSignatures, 1, | 94 kDeclSignatures, 1, |
90 0, kAstStmt, | 95 0, kAstStmt, |
91 // -- functions | 96 // -- functions |
92 kDeclFunctions, 1, | 97 kDeclFunctions, 1, |
93 0, // decl flags | 98 0, // decl flags |
94 0, 0, // signature | 99 0, 0, // signature |
95 kBodySize, 0, // body size | 100 kBodySize, 0, // body size |
96 kExprNop, // body | 101 kExprNop, // body |
97 // -- declare start function | 102 // -- declare start function |
98 kDeclStartFunction, | 103 kDeclStartFunction, |
99 0, | 104 0, |
100 // -- declare start function | 105 // -- declare start function |
101 kDeclStartFunction, | 106 kDeclStartFunction, |
102 0 | 107 0 |
103 ); | 108 ); |
104 | 109 |
105 assertThrows(function() { _WASMEXP_.instantiateModule(data); }); | 110 assertThrows(function() { _WASMEXP_.instantiateModule(data); }); |
106 })(); | 111 })(); |
107 | 112 |
108 | 113 |
109 (function testRun() { | 114 (function testRun() { |
110 var kBodySize = 6; | 115 var kBodySize = 6; |
111 | 116 |
112 var data = bytes( | 117 var data = bytesWithHeader( |
113 kDeclMemory, | 118 kDeclMemory, |
114 12, 12, 1, // memory | 119 12, 12, 1, // memory |
115 // -- signatures | 120 // -- signatures |
116 kDeclSignatures, 1, | 121 kDeclSignatures, 1, |
117 0, kAstStmt, | 122 0, kAstStmt, |
118 // -- start function | 123 // -- start function |
119 kDeclFunctions, 1, | 124 kDeclFunctions, 1, |
120 0, // decl flags | 125 0, // decl flags |
121 0, 0, // signature | 126 0, 0, // signature |
122 kBodySize, 0, // code size | 127 kBodySize, 0, // code size |
123 // -- start body | 128 // -- start body |
124 kExprI32StoreMem, 0, kExprI8Const, 0, kExprI8Const, 77, | 129 kExprI32StoreMem, 0, kExprI8Const, 0, kExprI8Const, 77, |
125 // -- declare start function | 130 // -- declare start function |
126 kDeclStartFunction, | 131 kDeclStartFunction, |
127 0 | 132 0 |
128 ); | 133 ); |
129 | 134 |
130 var module = _WASMEXP_.instantiateModule(data); | 135 var module = _WASMEXP_.instantiateModule(data); |
131 var memory = module.memory; | 136 var memory = module.memory; |
132 var view = new Int8Array(memory); | 137 var view = new Int8Array(memory); |
133 assertEquals(77, view[0]); | 138 assertEquals(77, view[0]); |
134 })(); | 139 })(); |
135 | 140 |
136 (function testStartFFI() { | 141 (function testStartFFI() { |
137 var kBodySize = 2; | 142 var kBodySize = 2; |
138 var kNameOffset = 4 + 9 + 7 + 3; | 143 var kNameOffset = kHeaderSize + 4 + 9 + 7 + 3; |
139 | 144 |
140 var data = bytes( | 145 var data = bytesWithHeader( |
141 // -- signatures | 146 // -- signatures |
142 kDeclSignatures, 1, | 147 kDeclSignatures, 1, |
143 0, kAstStmt, | 148 0, kAstStmt, |
144 // -- imported function | 149 // -- imported function |
145 kDeclFunctions, 2, | 150 kDeclFunctions, 2, |
146 kDeclFunctionImport | kDeclFunctionName, // decl flags | 151 kDeclFunctionImport | kDeclFunctionName, // decl flags |
147 0, 0, // signature | 152 0, 0, // signature |
148 kNameOffset, 0, 0, 0, | 153 kNameOffset, 0, 0, 0, |
149 // -- start function | 154 // -- start function |
150 0, // decl flags | 155 0, // decl flags |
(...skipping 12 matching lines...) Expand all Loading... |
163 var ffi = new Object(); | 168 var ffi = new Object(); |
164 ffi.foo = function() { | 169 ffi.foo = function() { |
165 print("we ranned at stert!"); | 170 print("we ranned at stert!"); |
166 ranned = true; | 171 ranned = true; |
167 } | 172 } |
168 var module = _WASMEXP_.instantiateModule(data, ffi); | 173 var module = _WASMEXP_.instantiateModule(data, ffi); |
169 var memory = module.memory; | 174 var memory = module.memory; |
170 var view = new Int8Array(memory); | 175 var view = new Int8Array(memory); |
171 assertTrue(ranned); | 176 assertTrue(ranned); |
172 })(); | 177 })(); |
OLD | NEW |