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: --validate-asm --allow-natives-syntax | 5 // Flags: --validate-asm --allow-natives-syntax |
6 | 6 |
7 // Note that this test file contains tests that explicitly check modules are | 7 // Note that this test file contains tests that explicitly check modules are |
8 // valid asm.js and then break them with invalid instantiation arguments. If | 8 // valid asm.js and then break them with invalid instantiation arguments. If |
9 // this script is run more than once (e.g. --stress-opt) then modules remain | 9 // this script is run more than once (e.g. --stress-opt) then modules remain |
10 // broken in the second run and assertions would fail. We prevent re-runs. | 10 // broken in the second run and assertions would fail. We prevent re-runs. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 assertEquals(-3, m.i()); | 75 assertEquals(-3, m.i()); |
76 assertEquals(-3.0, m.d()); | 76 assertEquals(-3.0, m.d()); |
77 assertEquals(Math.fround(-3.0), m.f()); | 77 assertEquals(Math.fround(-3.0), m.f()); |
78 | 78 |
79 assertEquals(-3, m.iVar()); | 79 assertEquals(-3, m.iVar()); |
80 assertEquals(-3.0, m.dVar()); | 80 assertEquals(-3.0, m.dVar()); |
81 assertEquals(Math.fround(-3.0), m.fVar()); | 81 assertEquals(Math.fround(-3.0), m.fVar()); |
82 | 82 |
83 var m = DisallowAssignToConstGlobal(); | 83 var m = DisallowAssignToConstGlobal(); |
84 assertTrue(%IsNotAsmWasmCode(DisallowAssignToConstGlobal)); | 84 assertFalse(%IsAsmWasmCode(DisallowAssignToConstGlobal)); |
85 })(); | 85 })(); |
86 | 86 |
87 (function TestModuleArgs() { | 87 (function TestModuleArgs() { |
88 function Module1(stdlib) { | 88 function Module1(stdlib) { |
89 "use asm"; | 89 "use asm"; |
90 function foo() { } | 90 function foo() { } |
91 return { foo: foo }; | 91 return { foo: foo }; |
92 } | 92 } |
93 function Module2(stdlib, ffi) { | 93 function Module2(stdlib, ffi) { |
94 "use asm"; | 94 "use asm"; |
(...skipping 23 matching lines...) Expand all Loading... |
118 } | 118 } |
119 })(); | 119 })(); |
120 | 120 |
121 (function TestBadModule() { | 121 (function TestBadModule() { |
122 function Module(stdlib, ffi, heap) { | 122 function Module(stdlib, ffi, heap) { |
123 "use asm"; | 123 "use asm"; |
124 function foo() { var y = 3; var x = 1 + y; return 123; } | 124 function foo() { var y = 3; var x = 1 + y; return 123; } |
125 return { foo: foo }; | 125 return { foo: foo }; |
126 } | 126 } |
127 var m = Module({}); | 127 var m = Module({}); |
128 assertTrue(%IsNotAsmWasmCode(Module)); | 128 assertFalse(%IsAsmWasmCode(Module)); |
129 assertEquals(123, m.foo()); | 129 assertEquals(123, m.foo()); |
130 })(); | 130 })(); |
131 | 131 |
132 (function TestBadArgTypes() { | 132 (function TestBadArgTypes() { |
133 function Module(a, b, c) { | 133 function Module(a, b, c) { |
134 "use asm"; | 134 "use asm"; |
135 var NaN = a.NaN; | 135 var NaN = a.NaN; |
136 return {}; | 136 return {}; |
137 } | 137 } |
138 var m = Module(1, 2, 3); | 138 var m = Module(1, 2, 3); |
139 assertTrue(%IsNotAsmWasmCode(Module)); | 139 assertFalse(%IsAsmWasmCode(Module)); |
140 assertEquals({}, m); | 140 assertEquals({}, m); |
141 })(); | 141 })(); |
142 | 142 |
143 (function TestBadArgTypesMismatch() { | 143 (function TestBadArgTypesMismatch() { |
144 function Module(a, b, c) { | 144 function Module(a, b, c) { |
145 "use asm"; | 145 "use asm"; |
146 var NaN = a.NaN; | 146 var NaN = a.NaN; |
147 return {}; | 147 return {}; |
148 } | 148 } |
149 var m = Module(1, 2); | 149 var m = Module(1, 2); |
150 assertTrue(%IsNotAsmWasmCode(Module)); | 150 assertFalse(%IsAsmWasmCode(Module)); |
151 assertEquals({}, m); | 151 assertEquals({}, m); |
152 })(); | 152 })(); |
153 | 153 |
154 (function TestModuleNoStdlib() { | 154 (function TestModuleNoStdlib() { |
155 function Module() { | 155 function Module() { |
156 "use asm"; | 156 "use asm"; |
157 function foo() { return 123; } | 157 function foo() { return 123; } |
158 return { foo: foo }; | 158 return { foo: foo }; |
159 } | 159 } |
160 var m = Module({}); | 160 var m = Module({}); |
161 assertValidAsm(Module); | 161 assertValidAsm(Module); |
162 assertEquals(123, m.foo()); | 162 assertEquals(123, m.foo()); |
163 })(); | 163 })(); |
164 | 164 |
165 (function TestModuleWith5() { | 165 (function TestModuleWith5() { |
166 function Module(a, b, c, d, e) { | 166 function Module(a, b, c, d, e) { |
167 "use asm"; | 167 "use asm"; |
168 function foo() { return 123; } | 168 function foo() { return 123; } |
169 return { foo: foo }; | 169 return { foo: foo }; |
170 } | 170 } |
171 var heap = new ArrayBuffer(1024 * 1024); | 171 var heap = new ArrayBuffer(1024 * 1024); |
172 var m = Module({}, {}, heap); | 172 var m = Module({}, {}, heap); |
173 assertTrue(%IsNotAsmWasmCode(Module)); | 173 assertFalse(%IsAsmWasmCode(Module)); |
174 assertEquals(123, m.foo()); | 174 assertEquals(123, m.foo()); |
175 })(); | 175 })(); |
176 | 176 |
177 (function TestModuleNoStdlibCall() { | 177 (function TestModuleNoStdlibCall() { |
178 function Module(stdlib, ffi, heap) { | 178 function Module(stdlib, ffi, heap) { |
179 "use asm"; | 179 "use asm"; |
180 function foo() { return 123; } | 180 function foo() { return 123; } |
181 return { foo: foo }; | 181 return { foo: foo }; |
182 } | 182 } |
183 var m = Module(); | 183 var m = Module(); |
(...skipping 13 matching lines...) Expand all Loading... |
197 })(); | 197 })(); |
198 | 198 |
199 (function TestMultipleFailures() { | 199 (function TestMultipleFailures() { |
200 function Module(stdlib) { | 200 function Module(stdlib) { |
201 "use asm"; | 201 "use asm"; |
202 var NaN = stdlib.NaN; | 202 var NaN = stdlib.NaN; |
203 function foo() { return 123; } | 203 function foo() { return 123; } |
204 return { foo: foo }; | 204 return { foo: foo }; |
205 } | 205 } |
206 var m1 = Module(1, 2, 3); | 206 var m1 = Module(1, 2, 3); |
207 assertTrue(%IsNotAsmWasmCode(Module)); | 207 assertFalse(%IsAsmWasmCode(Module)); |
208 var m2 = Module(1, 2, 3); | 208 var m2 = Module(1, 2, 3); |
209 assertTrue(%IsNotAsmWasmCode(Module)); | 209 assertFalse(%IsAsmWasmCode(Module)); |
210 assertEquals(123, m1.foo()); | 210 assertEquals(123, m1.foo()); |
211 assertEquals(123, m2.foo()); | 211 assertEquals(123, m2.foo()); |
212 })(); | 212 })(); |
213 | 213 |
214 (function TestFailureThenSuccess() { | 214 (function TestFailureThenSuccess() { |
215 function MkModule() { | 215 function MkModule() { |
216 function Module(stdlib, ffi, heap) { | 216 function Module(stdlib, ffi, heap) { |
217 "use asm"; | 217 "use asm"; |
218 var NaN = stdlib.NaN; | 218 var NaN = stdlib.NaN; |
219 function foo() { return 123; } | 219 function foo() { return 123; } |
220 return { foo: foo }; | 220 return { foo: foo }; |
221 } | 221 } |
222 return Module; | 222 return Module; |
223 } | 223 } |
224 var Module1 = MkModule(); | 224 var Module1 = MkModule(); |
225 var Module2 = MkModule(); | 225 var Module2 = MkModule(); |
226 var heap = new ArrayBuffer(1024 * 1024); | 226 var heap = new ArrayBuffer(1024 * 1024); |
227 var m1 = Module1(1, 2, 3); | 227 var m1 = Module1(1, 2, 3); |
228 assertTrue(%IsNotAsmWasmCode(Module1)); | 228 assertFalse(%IsAsmWasmCode(Module1)); |
229 var m2 = Module2({}, {}, heap); | 229 var m2 = Module2({}, {}, heap); |
230 assertTrue(%IsNotAsmWasmCode(Module2)); | 230 assertFalse(%IsAsmWasmCode(Module2)); |
231 assertEquals(123, m1.foo()); | 231 assertEquals(123, m1.foo()); |
232 assertEquals(123, m2.foo()); | 232 assertEquals(123, m2.foo()); |
233 })(); | 233 })(); |
234 | 234 |
235 (function TestSuccessThenFailure() { | 235 (function TestSuccessThenFailure() { |
236 function MkModule() { | 236 function MkModule() { |
237 function Module(stdlib, ffi, heap) { | 237 function Module(stdlib, ffi, heap) { |
238 "use asm"; | 238 "use asm"; |
239 var NaN = stdlib.NaN; | 239 var NaN = stdlib.NaN; |
240 function foo() { return 123; } | 240 function foo() { return 123; } |
241 return { foo: foo }; | 241 return { foo: foo }; |
242 } | 242 } |
243 return Module; | 243 return Module; |
244 } | 244 } |
245 var Module1 = MkModule(); | 245 var Module1 = MkModule(); |
246 var Module2 = MkModule(); | 246 var Module2 = MkModule(); |
247 var heap = new ArrayBuffer(1024 * 1024); | 247 var heap = new ArrayBuffer(1024 * 1024); |
248 var m1 = Module1({NaN: NaN}, {}, heap); | 248 var m1 = Module1({NaN: NaN}, {}, heap); |
249 assertValidAsm(Module1); | 249 assertValidAsm(Module1); |
250 var m2 = Module2(1, 2, 3); | 250 var m2 = Module2(1, 2, 3); |
251 assertTrue(%IsNotAsmWasmCode(Module2)); | 251 assertFalse(%IsAsmWasmCode(Module2)); |
252 assertEquals(123, m1.foo()); | 252 assertEquals(123, m1.foo()); |
253 assertEquals(123, m2.foo()); | 253 assertEquals(123, m2.foo()); |
254 })(); | 254 })(); |
255 | 255 |
256 (function TestSuccessThenFailureThenRetry() { | 256 (function TestSuccessThenFailureThenRetry() { |
257 function MkModule() { | 257 function MkModule() { |
258 function Module(stdlib, ffi, heap) { | 258 function Module(stdlib, ffi, heap) { |
259 "use asm"; | 259 "use asm"; |
260 var NaN = stdlib.NaN; | 260 var NaN = stdlib.NaN; |
261 function foo() { return 123; } | 261 function foo() { return 123; } |
262 return { foo: foo }; | 262 return { foo: foo }; |
263 } | 263 } |
264 return Module; | 264 return Module; |
265 } | 265 } |
266 var Module1 = MkModule(); | 266 var Module1 = MkModule(); |
267 var Module2 = MkModule(); | 267 var Module2 = MkModule(); |
268 var heap = new ArrayBuffer(1024 * 1024); | 268 var heap = new ArrayBuffer(1024 * 1024); |
269 var m1a = Module1({NaN: NaN}, {}, heap); | 269 var m1a = Module1({NaN: NaN}, {}, heap); |
270 assertValidAsm(Module1); | 270 assertValidAsm(Module1); |
271 var m2 = Module2(1, 2, 3); | 271 var m2 = Module2(1, 2, 3); |
272 assertTrue(%IsNotAsmWasmCode(Module2)); | 272 assertFalse(%IsAsmWasmCode(Module2)); |
273 var m1b = Module1({NaN: NaN}, {}, heap); | 273 var m1b = Module1({NaN: NaN}, {}, heap); |
274 assertTrue(%IsNotAsmWasmCode(Module1)); | 274 assertFalse(%IsAsmWasmCode(Module1)); |
275 assertEquals(123, m1a.foo()); | 275 assertEquals(123, m1a.foo()); |
276 assertEquals(123, m1b.foo()); | 276 assertEquals(123, m1b.foo()); |
277 assertEquals(123, m2.foo()); | 277 assertEquals(123, m2.foo()); |
278 })(); | 278 })(); |
279 | 279 |
280 (function TestBoundFunction() { | 280 (function TestBoundFunction() { |
281 function Module(stdlib, ffi, heap) { | 281 function Module(stdlib, ffi, heap) { |
282 "use asm"; | 282 "use asm"; |
283 function foo() { return 123; } | 283 function foo() { return 123; } |
284 return { foo: foo }; | 284 return { foo: foo }; |
285 } | 285 } |
286 var heap = new ArrayBuffer(1024 * 1024); | 286 var heap = new ArrayBuffer(1024 * 1024); |
287 var ModuleBound = Module.bind(this, {}, {}, heap); | 287 var ModuleBound = Module.bind(this, {}, {}, heap); |
288 var m = ModuleBound(); | 288 var m = ModuleBound(); |
289 assertValidAsm(Module); | 289 assertValidAsm(Module); |
290 assertEquals(123, m.foo()); | 290 assertEquals(123, m.foo()); |
291 })(); | 291 })(); |
292 | 292 |
293 (function TestBadConstUnsignedReturn() { | 293 (function TestBadConstUnsignedReturn() { |
294 function Module() { | 294 function Module() { |
295 "use asm"; | 295 "use asm"; |
296 const i = 0xffffffff; | 296 const i = 0xffffffff; |
297 function foo() { return i; } | 297 function foo() { return i; } |
298 return { foo: foo }; | 298 return { foo: foo }; |
299 } | 299 } |
300 var m = Module(); | 300 var m = Module(); |
301 assertTrue(%IsNotAsmWasmCode(Module)); | 301 assertFalse(%IsAsmWasmCode(Module)); |
302 assertEquals(0xffffffff, m.foo()); | 302 assertEquals(0xffffffff, m.foo()); |
303 })(); | 303 })(); |
304 | 304 |
305 (function TestBadBooleanAnnotation() { | 305 (function TestBadBooleanAnnotation() { |
306 function Module() { | 306 function Module() { |
307 "use asm"; | 307 "use asm"; |
308 function foo(x) { | 308 function foo(x) { |
309 x = x | true; | 309 x = x | true; |
310 return x; | 310 return x; |
311 } | 311 } |
312 return { foo: foo }; | 312 return { foo: foo }; |
313 } | 313 } |
314 var m = Module(); | 314 var m = Module(); |
315 assertTrue(%IsNotAsmWasmCode(Module)); | 315 assertFalse(%IsAsmWasmCode(Module)); |
316 assertEquals(3, m.foo(3)); | 316 assertEquals(3, m.foo(3)); |
317 })(); | 317 })(); |
318 | 318 |
319 (function TestBadCase() { | 319 (function TestBadCase() { |
320 function Module() { | 320 function Module() { |
321 "use asm"; | 321 "use asm"; |
322 function foo(x) { | 322 function foo(x) { |
323 x = x | 0; | 323 x = x | 0; |
324 switch (x|0) { | 324 switch (x|0) { |
325 case true: | 325 case true: |
326 return 42; | 326 return 42; |
327 default: | 327 default: |
328 return 43; | 328 return 43; |
329 } | 329 } |
330 return 0; | 330 return 0; |
331 } | 331 } |
332 return { foo: foo }; | 332 return { foo: foo }; |
333 } | 333 } |
334 var m = Module(); | 334 var m = Module(); |
335 assertTrue(%IsNotAsmWasmCode(Module)); | 335 assertFalse(%IsAsmWasmCode(Module)); |
336 assertEquals(43, m.foo(3)); | 336 assertEquals(43, m.foo(3)); |
337 })(); | 337 })(); |
OLD | NEW |