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 --allow-natives-syntax | 5 // Flags: --expose-wasm --allow-natives-syntax |
6 | 6 |
7 if ((typeof drainJobQueue) != "function") { | 7 if ((typeof drainJobQueue) != "function") { |
8 drainJobQueue = () => { %RunMicrotasks() }; | 8 drainJobQueue = () => { %RunMicrotasks() }; |
9 } | 9 } |
10 | 10 |
11 load("test/mjsunit/wasm/wasm-constants.js"); | 11 load("test/mjsunit/wasm/wasm-constants.js"); |
12 load("test/mjsunit/wasm/wasm-module-builder.js"); | 12 load("test/mjsunit/wasm/wasm-module-builder.js"); |
13 | 13 |
14 function assertEq(val, expected) { | 14 function assertEq(val, expected) { |
15 assertEquals(expected, val); | 15 assertEquals(expected, val); |
16 } | 16 } |
17 function wasmIsSupported() { | 17 function wasmIsSupported() { |
18 return (typeof WebAssembly.Module) == "function"; | 18 return (typeof WebAssembly.Module) == "function"; |
19 } | 19 } |
20 function assertErrorMessage(func, type, msg) { | 20 function assertErrorMessage(func, type, msg) { |
21 //TODO assertThrows(func, type, msg); | 21 //TODO assertThrows(func, type, msg); |
22 assertThrows(func, type); | 22 assertThrows(func, type); |
23 } | 23 } |
24 | 24 |
25 let PROP_FLAGS = false; // property flags are implemented correctly | |
26 | |
27 let emptyModuleBinary = (() => { | 25 let emptyModuleBinary = (() => { |
28 var builder = new WasmModuleBuilder(); | 26 var builder = new WasmModuleBuilder(); |
29 return new Int8Array(builder.toBuffer()); | 27 return new Int8Array(builder.toBuffer()); |
30 })(); | 28 })(); |
31 | 29 |
32 let exportingModuleBinary = (() => { | 30 let exportingModuleBinary = (() => { |
33 var builder = new WasmModuleBuilder(); | 31 var builder = new WasmModuleBuilder(); |
34 builder.addFunction("f", kSig_i_v) | 32 builder.addFunction("f", kSig_i_v) |
35 .addBody([kExprI32Const, 42]) | 33 .addBody([kExprI32Const, 42]) |
36 .exportAs("f"); | 34 .exportAs("f"); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 assertErrorMessage(() => new Module(1), TypeError, "first argument must be an Ar
rayBuffer or typed array object"); | 121 assertErrorMessage(() => new Module(1), TypeError, "first argument must be an Ar
rayBuffer or typed array object"); |
124 assertErrorMessage(() => new Module({}), TypeError, "first argument must be an A
rrayBuffer or typed array object"); | 122 assertErrorMessage(() => new Module({}), TypeError, "first argument must be an A
rrayBuffer or typed array object"); |
125 //TODO assertErrorMessage(() => new Module(new Uint8Array()), CompileError, /fai
led to match magic number/); | 123 //TODO assertErrorMessage(() => new Module(new Uint8Array()), CompileError, /fai
led to match magic number/); |
126 //TODO assertErrorMessage(() => new Module(new ArrayBuffer()), CompileError, /fa
iled to match magic number/); | 124 //TODO assertErrorMessage(() => new Module(new ArrayBuffer()), CompileError, /fa
iled to match magic number/); |
127 assertEq(new Module(emptyModuleBinary) instanceof Module, true); | 125 assertEq(new Module(emptyModuleBinary) instanceof Module, true); |
128 assertEq(new Module(emptyModuleBinary.buffer) instanceof Module, true); | 126 assertEq(new Module(emptyModuleBinary.buffer) instanceof Module, true); |
129 | 127 |
130 // 'WebAssembly.Module.prototype' data property | 128 // 'WebAssembly.Module.prototype' data property |
131 let moduleProtoDesc = Object.getOwnPropertyDescriptor(Module, 'prototype'); | 129 let moduleProtoDesc = Object.getOwnPropertyDescriptor(Module, 'prototype'); |
132 assertEq(typeof moduleProtoDesc.value, "object"); | 130 assertEq(typeof moduleProtoDesc.value, "object"); |
133 if (PROP_FLAGS) assertEq(moduleProtoDesc.writable, false); | 131 assertEq(moduleProtoDesc.writable, false); |
134 if (PROP_FLAGS) assertEq(moduleProtoDesc.enumerable, false); | 132 assertEq(moduleProtoDesc.enumerable, false); |
135 if (PROP_FLAGS) assertEq(moduleProtoDesc.configurable, false); | 133 assertEq(moduleProtoDesc.configurable, false); |
136 | 134 |
137 // 'WebAssembly.Module.prototype' object | 135 // 'WebAssembly.Module.prototype' object |
138 let moduleProto = Module.prototype; | 136 let moduleProto = Module.prototype; |
139 assertEq(moduleProto, moduleProtoDesc.value); | 137 assertEq(moduleProto, moduleProtoDesc.value); |
140 assertEq(String(moduleProto), "[object Object]"); | 138 assertEq(String(moduleProto), "[object Object]"); |
141 assertEq(Object.getPrototypeOf(moduleProto), Object.prototype); | 139 assertEq(Object.getPrototypeOf(moduleProto), Object.prototype); |
142 | 140 |
143 // 'WebAssembly.Module' instance objects | 141 // 'WebAssembly.Module' instance objects |
144 let emptyModule = new Module(emptyModuleBinary); | 142 let emptyModule = new Module(emptyModuleBinary); |
145 let importingModule = new Module(importingModuleBinary); | 143 let importingModule = new Module(importingModuleBinary); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb
idden/); | 225 assertErrorMessage(() => Instance(), TypeError, /constructor without new is forb
idden/); |
228 assertErrorMessage(() => new Instance(1), TypeError, "first argument must be a W
ebAssembly.Module"); | 226 assertErrorMessage(() => new Instance(1), TypeError, "first argument must be a W
ebAssembly.Module"); |
229 assertErrorMessage(() => new Instance({}), TypeError, "first argument must be a
WebAssembly.Module"); | 227 assertErrorMessage(() => new Instance({}), TypeError, "first argument must be a
WebAssembly.Module"); |
230 //TODO assertErrorMessage(() => new Instance(emptyModule, null), TypeError, "sec
ond argument must be an object"); | 228 //TODO assertErrorMessage(() => new Instance(emptyModule, null), TypeError, "sec
ond argument must be an object"); |
231 //TODO assertEq(new Instance(emptyModule) instanceof Instance, true); | 229 //TODO assertEq(new Instance(emptyModule) instanceof Instance, true); |
232 //TODO assertEq(new Instance(emptyModule, {}) instanceof Instance, true); | 230 //TODO assertEq(new Instance(emptyModule, {}) instanceof Instance, true); |
233 | 231 |
234 // 'WebAssembly.Instance.prototype' data property | 232 // 'WebAssembly.Instance.prototype' data property |
235 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype'); | 233 let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype'); |
236 assertEq(typeof instanceProtoDesc.value, "object"); | 234 assertEq(typeof instanceProtoDesc.value, "object"); |
237 if (PROP_FLAGS) assertEq(instanceProtoDesc.writable, false); | 235 assertEq(instanceProtoDesc.writable, false); |
238 if (PROP_FLAGS) assertEq(instanceProtoDesc.enumerable, false); | 236 assertEq(instanceProtoDesc.enumerable, false); |
239 if (PROP_FLAGS) assertEq(instanceProtoDesc.configurable, false); | 237 assertEq(instanceProtoDesc.configurable, false); |
240 | 238 |
241 // 'WebAssembly.Instance.prototype' object | 239 // 'WebAssembly.Instance.prototype' object |
242 let instanceProto = Instance.prototype; | 240 let instanceProto = Instance.prototype; |
243 assertEq(instanceProto, instanceProtoDesc.value); | 241 assertEq(instanceProto, instanceProtoDesc.value); |
244 assertEq(String(instanceProto), "[object Object]"); | 242 assertEq(String(instanceProto), "[object Object]"); |
245 assertEq(Object.getPrototypeOf(instanceProto), Object.prototype); | 243 assertEq(Object.getPrototypeOf(instanceProto), Object.prototype); |
246 | 244 |
247 // 'WebAssembly.Instance' instance objects | 245 // 'WebAssembly.Instance' instance objects |
248 let exportingInstance = new Instance(exportingModule); | 246 let exportingInstance = new Instance(exportingModule); |
249 assertEq(typeof exportingInstance, "object"); | 247 assertEq(typeof exportingInstance, "object"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 assertErrorMessage(() => new Memory({initial:Math.pow(2,32)}), RangeError, /bad
Memory initial size/); | 282 assertErrorMessage(() => new Memory({initial:Math.pow(2,32)}), RangeError, /bad
Memory initial size/); |
285 assertErrorMessage(() => new Memory({initial:1, maximum: Math.pow(2,32)/Math.pow
(2,14) }), RangeError, /bad Memory maximum size/); | 283 assertErrorMessage(() => new Memory({initial:1, maximum: Math.pow(2,32)/Math.pow
(2,14) }), RangeError, /bad Memory maximum size/); |
286 assertErrorMessage(() => new Memory({initial:2, maximum:1 }), RangeError, /bad M
emory maximum size/); | 284 assertErrorMessage(() => new Memory({initial:2, maximum:1 }), RangeError, /bad M
emory maximum size/); |
287 assertErrorMessage(() => new Memory({maximum: -1 }), RangeError, /bad Memory max
imum size/); | 285 assertErrorMessage(() => new Memory({maximum: -1 }), RangeError, /bad Memory max
imum size/); |
288 assertEq(new Memory({initial:1}) instanceof Memory, true); | 286 assertEq(new Memory({initial:1}) instanceof Memory, true); |
289 assertEq(new Memory({initial:1.5}).buffer.byteLength, kPageSize); | 287 assertEq(new Memory({initial:1.5}).buffer.byteLength, kPageSize); |
290 | 288 |
291 // 'WebAssembly.Memory.prototype' data property | 289 // 'WebAssembly.Memory.prototype' data property |
292 let memoryProtoDesc = Object.getOwnPropertyDescriptor(Memory, 'prototype'); | 290 let memoryProtoDesc = Object.getOwnPropertyDescriptor(Memory, 'prototype'); |
293 assertEq(typeof memoryProtoDesc.value, "object"); | 291 assertEq(typeof memoryProtoDesc.value, "object"); |
294 if (PROP_FLAGS) assertEq(memoryProtoDesc.writable, false); | 292 assertEq(memoryProtoDesc.writable, false); |
295 if (PROP_FLAGS) assertEq(memoryProtoDesc.enumerable, false); | 293 assertEq(memoryProtoDesc.enumerable, false); |
296 if (PROP_FLAGS) assertEq(memoryProtoDesc.configurable, false); | 294 assertEq(memoryProtoDesc.configurable, false); |
297 | 295 |
298 // 'WebAssembly.Memory.prototype' object | 296 // 'WebAssembly.Memory.prototype' object |
299 let memoryProto = Memory.prototype; | 297 let memoryProto = Memory.prototype; |
300 assertEq(memoryProto, memoryProtoDesc.value); | 298 assertEq(memoryProto, memoryProtoDesc.value); |
301 assertEq(String(memoryProto), "[object Object]"); | 299 assertEq(String(memoryProto), "[object Object]"); |
302 assertEq(Object.getPrototypeOf(memoryProto), Object.prototype); | 300 assertEq(Object.getPrototypeOf(memoryProto), Object.prototype); |
303 | 301 |
304 // 'WebAssembly.Memory' instance objects | 302 // 'WebAssembly.Memory' instance objects |
305 let mem1 = new Memory({initial:1}); | 303 let mem1 = new Memory({initial:1}); |
306 assertEq(typeof mem1, "object"); | 304 assertEq(typeof mem1, "object"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 assertErrorMessage(() => new Table({initial:2, maximum:1, element:"anyfunc"}), R
angeError, /bad Table maximum size/); | 374 assertErrorMessage(() => new Table({initial:2, maximum:1, element:"anyfunc"}), R
angeError, /bad Table maximum size/); |
377 assertErrorMessage(() => new Table({initial:2, maximum:Math.pow(2,32), element:"
anyfunc"}), RangeError, /bad Table maximum size/); | 375 assertErrorMessage(() => new Table({initial:2, maximum:Math.pow(2,32), element:"
anyfunc"}), RangeError, /bad Table maximum size/); |
378 assertEq(new Table({initial:1, element:"anyfunc"}) instanceof Table, true); | 376 assertEq(new Table({initial:1, element:"anyfunc"}) instanceof Table, true); |
379 assertEq(new Table({initial:1.5, element:"anyfunc"}) instanceof Table, true); | 377 assertEq(new Table({initial:1.5, element:"anyfunc"}) instanceof Table, true); |
380 assertEq(new Table({initial:1, maximum:1.5, element:"anyfunc"}) instanceof Table
, true); | 378 assertEq(new Table({initial:1, maximum:1.5, element:"anyfunc"}) instanceof Table
, true); |
381 //TODO:maximum assertEq(new Table({initial:1, maximum:Math.pow(2,32)-1, element:
"anyfunc"}) instanceof Table, true); | 379 //TODO:maximum assertEq(new Table({initial:1, maximum:Math.pow(2,32)-1, element:
"anyfunc"}) instanceof Table, true); |
382 | 380 |
383 // 'WebAssembly.Table.prototype' data property | 381 // 'WebAssembly.Table.prototype' data property |
384 let tableProtoDesc = Object.getOwnPropertyDescriptor(Table, 'prototype'); | 382 let tableProtoDesc = Object.getOwnPropertyDescriptor(Table, 'prototype'); |
385 assertEq(typeof tableProtoDesc.value, "object"); | 383 assertEq(typeof tableProtoDesc.value, "object"); |
386 if (PROP_FLAGS) assertEq(tableProtoDesc.writable, false); | 384 assertEq(tableProtoDesc.writable, false); |
387 if (PROP_FLAGS) assertEq(tableProtoDesc.enumerable, false); | 385 assertEq(tableProtoDesc.enumerable, false); |
388 if (PROP_FLAGS) assertEq(tableProtoDesc.configurable, false); | 386 assertEq(tableProtoDesc.configurable, false); |
389 | 387 |
390 // 'WebAssembly.Table.prototype' object | 388 // 'WebAssembly.Table.prototype' object |
391 let tableProto = Table.prototype; | 389 let tableProto = Table.prototype; |
392 assertEq(tableProto, tableProtoDesc.value); | 390 assertEq(tableProto, tableProtoDesc.value); |
393 assertEq(String(tableProto), "[object Object]"); | 391 assertEq(String(tableProto), "[object Object]"); |
394 assertEq(Object.getPrototypeOf(tableProto), Object.prototype); | 392 assertEq(Object.getPrototypeOf(tableProto), Object.prototype); |
395 | 393 |
396 // 'WebAssembly.Table' instance objects | 394 // 'WebAssembly.Table' instance objects |
397 let tbl1 = new Table({initial:2, element:"anyfunc"}); | 395 let tbl1 = new Table({initial:2, element:"anyfunc"}); |
398 assertEq(typeof tbl1, "object"); | 396 assertEq(typeof tbl1, "object"); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 assertEq(result.instance instanceof Instance, true); | 563 assertEq(result.instance instanceof Instance, true); |
566 } | 564 } |
567 } | 565 } |
568 assertInstantiateSuccess(emptyModule); | 566 assertInstantiateSuccess(emptyModule); |
569 assertInstantiateSuccess(emptyModuleBinary); | 567 assertInstantiateSuccess(emptyModuleBinary); |
570 assertInstantiateSuccess(emptyModuleBinary.buffer); | 568 assertInstantiateSuccess(emptyModuleBinary.buffer); |
571 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}}); | 569 assertInstantiateSuccess(importingModule, {"":{f:()=>{}}}); |
572 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); | 570 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); |
573 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); | 571 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); |
574 } | 572 } |
OLD | NEW |