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 assertArrayBuffer(val, expected) { | |
18 assertTrue(val instanceof ArrayBuffer); | |
19 assertEq(expected.length, val.byteLength); | |
20 var input = new Int8Array(val); | |
21 for (var i = 0; i < expected.length; i++) { | |
22 assertEq(expected[i], input[i]); | |
23 } | |
24 } | |
17 function wasmIsSupported() { | 25 function wasmIsSupported() { |
18 return (typeof WebAssembly.Module) == "function"; | 26 return (typeof WebAssembly.Module) == "function"; |
19 } | 27 } |
20 function assertErrorMessage(func, type, msg) { | 28 function assertErrorMessage(func, type, msg) { |
21 //TODO assertThrows(func, type, msg); | 29 //TODO assertThrows(func, type, msg); |
22 assertThrows(func, type); | 30 assertThrows(func, type); |
23 } | 31 } |
24 | 32 |
25 let emptyModuleBinary = (() => { | 33 let emptyModuleBinary = (() => { |
26 var builder = new WasmModuleBuilder(); | 34 var builder = new WasmModuleBuilder(); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 assertEq(arr.length, 4); | 251 assertEq(arr.length, 4); |
244 assertEq(arr[0].kind, "function"); | 252 assertEq(arr[0].kind, "function"); |
245 assertEq(arr[0].name, "a"); | 253 assertEq(arr[0].name, "a"); |
246 assertEq(arr[1].kind, "memory"); | 254 assertEq(arr[1].kind, "memory"); |
247 assertEq(arr[1].name, "b"); | 255 assertEq(arr[1].name, "b"); |
248 assertEq(arr[2].kind, "table"); | 256 assertEq(arr[2].kind, "table"); |
249 assertEq(arr[2].name, "c"); | 257 assertEq(arr[2].name, "c"); |
250 assertEq(arr[3].kind, "global"); | 258 assertEq(arr[3].kind, "global"); |
251 assertEq(arr[3].name, "x"); | 259 assertEq(arr[3].name, "x"); |
252 | 260 |
261 // 'WebAssembly.Module.customSections' data property | |
262 let moduleCustomSectionsDesc = | |
263 Object.getOwnPropertyDescriptor(Module, 'customSections'); | |
264 assertEq(typeof moduleCustomSectionsDesc.value, 'function'); | |
265 assertEq(moduleCustomSectionsDesc.writable, true); | |
266 assertEq(moduleCustomSectionsDesc.enumerable, false); | |
267 assertEq(moduleCustomSectionsDesc.configurable, true); | |
268 | |
269 let moduleCustomSections = moduleCustomSectionsDesc.value; | |
270 assertEq(moduleCustomSections.length, 2); | |
271 assertErrorMessage( | |
272 () => moduleCustomSections(), TypeError, /requires more than 0 arguments/); | |
273 assertErrorMessage( | |
274 () => moduleCustomSections(undefined), TypeError, | |
275 /first argument must be a WebAssembly.Module/); | |
276 assertErrorMessage( | |
277 () => moduleCustomSections({}), TypeError, | |
278 /first argument must be a WebAssembly.Module/); | |
279 var arr = moduleCustomSections(emptyModule, 'x'); | |
280 assertEq(arr instanceof Array, true); | |
281 assertEq(arr.length, 0); | |
282 | |
283 assertErrorMessage( | |
284 () => moduleCustomSections(1), TypeError, | |
285 'first argument must be a WebAssembly.Module'); | |
286 assertErrorMessage( | |
287 () => moduleCustomSections(emptyModule), TypeError, | |
288 'second argument must be a String'); | |
289 assertErrorMessage( | |
290 () => moduleCustomSections(emptyModule, 3), TypeError, | |
291 'second argument must be a String'); | |
292 | |
293 let customSectionModuleBinary2 = (() => { | |
294 let builder = new WasmModuleBuilder(); | |
295 builder.addExplicitSection([kUnknownSectionCode, 3, 1, 'x'.charCodeAt(0), 2]); | |
296 builder.addExplicitSection([ | |
297 kUnknownSectionCode, 6, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0), | |
298 'o'.charCodeAt(0), 66, 77 | |
299 ]); | |
300 builder.addExplicitSection([ | |
rossberg
2017/01/24 11:34:42
Can you add another section not named "foo", to te
titzer
2017/01/24 12:38:39
Well, the section above is called 'x', but I added
| |
301 kUnknownSectionCode, 7, 3, 'f'.charCodeAt(0), 'o'.charCodeAt(0), | |
302 'o'.charCodeAt(0), 91, 92, 93 | |
303 ]); | |
304 return new Int8Array(builder.toBuffer()); | |
305 })(); | |
306 var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'x'); | |
307 assertEq(arr instanceof Array, true); | |
308 assertEq(arr.length, 1); | |
309 assertArrayBuffer(arr[0], [2]); | |
310 var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'foo'); | |
311 assertEq(arr instanceof Array, true); | |
312 assertEq(arr.length, 2); | |
313 assertArrayBuffer(arr[0], [66, 77]); | |
314 assertArrayBuffer(arr[1], [91, 92, 93]); | |
315 var arr = moduleCustomSections(new Module(customSectionModuleBinary2), 'bar'); | |
316 assertEq(arr instanceof Array, true); | |
317 assertEq(arr.length, 0); | |
318 | |
253 // 'WebAssembly.Instance' data property | 319 // 'WebAssembly.Instance' data property |
254 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance'); | 320 let instanceDesc = Object.getOwnPropertyDescriptor(WebAssembly, 'Instance'); |
255 assertEq(typeof instanceDesc.value, "function"); | 321 assertEq(typeof instanceDesc.value, "function"); |
256 assertTrue(instanceDesc.writable); | 322 assertTrue(instanceDesc.writable); |
257 assertFalse(instanceDesc.enumerable); | 323 assertFalse(instanceDesc.enumerable); |
258 assertTrue(instanceDesc.configurable); | 324 assertTrue(instanceDesc.configurable); |
259 | 325 |
260 // 'WebAssembly.Instance' constructor function | 326 // 'WebAssembly.Instance' constructor function |
261 let Instance = WebAssembly.Instance; | 327 let Instance = WebAssembly.Instance; |
262 assertEq(Instance, instanceDesc.value); | 328 assertEq(Instance, instanceDesc.value); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 assertTrue(result.instance instanceof Instance); | 696 assertTrue(result.instance instanceof Instance); |
631 } | 697 } |
632 } | 698 } |
633 assertInstantiateSuccess(emptyModule); | 699 assertInstantiateSuccess(emptyModule); |
634 assertInstantiateSuccess(emptyModuleBinary); | 700 assertInstantiateSuccess(emptyModuleBinary); |
635 assertInstantiateSuccess(emptyModuleBinary.buffer); | 701 assertInstantiateSuccess(emptyModuleBinary.buffer); |
636 assertInstantiateSuccess(importingModule, {'': {f: () => {}}}); | 702 assertInstantiateSuccess(importingModule, {'': {f: () => {}}}); |
637 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); | 703 assertInstantiateSuccess(importingModuleBinary, {"":{f:()=>{}}}); |
638 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); | 704 assertInstantiateSuccess(importingModuleBinary.buffer, {"":{f:()=>{}}}); |
639 assertInstantiateSuccess(memoryImportingModuleBinary, {"": {"my_memory": scratch _memory}}); | 705 assertInstantiateSuccess(memoryImportingModuleBinary, {"": {"my_memory": scratch _memory}}); |
OLD | NEW |