OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 let kReturnValue = 17; | 10 let kReturnValue = 17; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 let main = instance.exports.main; | 50 let main = instance.exports.main; |
51 assertFalse(main === undefined); | 51 assertFalse(main === undefined); |
52 assertFalse(main === null); | 52 assertFalse(main === null); |
53 assertFalse(main === 0); | 53 assertFalse(main === 0); |
54 assertEquals("function", typeof main); | 54 assertEquals("function", typeof main); |
55 | 55 |
56 assertEquals(kReturnValue, main()); | 56 assertEquals(kReturnValue, main()); |
57 } | 57 } |
58 | 58 |
59 // Official API | 59 // Official API |
60 let module = new WebAssembly.Module(buffer); | 60 (function BasicJSAPITest() { |
61 CheckInstance(new WebAssembly.Instance(module)); | 61 print("sync module compile..."); |
| 62 let module = new WebAssembly.Module(buffer); |
| 63 print("sync module instantiate..."); |
| 64 CheckInstance(new WebAssembly.Instance(module)); |
62 | 65 |
63 let promise = WebAssembly.compile(buffer); | 66 print("async module compile..."); |
64 promise.then(module => CheckInstance(new WebAssembly.Instance(module))); | 67 let promise = WebAssembly.compile(buffer); |
| 68 promise.then(module => CheckInstance(new WebAssembly.Instance(module))); |
| 69 |
| 70 print("async instantiate..."); |
| 71 let instance_promise = WebAssembly.instantiate(buffer); |
| 72 instance_promise.then(CheckInstance); |
| 73 })(); |
65 | 74 |
66 // Check that validate works correctly for a module. | 75 // Check that validate works correctly for a module. |
67 assertTrue(WebAssembly.validate(buffer)); | 76 assertTrue(WebAssembly.validate(buffer)); |
68 assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); | 77 assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); |
69 | 78 |
70 // Negative tests. | 79 // Negative tests. |
71 (function InvalidModules() { | 80 (function InvalidModules() { |
72 print("InvalidModules..."); | 81 print("InvalidModules..."); |
73 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}]; | 82 let invalid_cases = [undefined, 1, "", "a", {some:1, obj: "b"}]; |
74 let len = invalid_cases.length; | 83 let len = invalid_cases.length; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 assertEquals(1, i1.exports.f()); | 228 assertEquals(1, i1.exports.f()); |
220 assertEquals(1000, i2.exports.f()); | 229 assertEquals(1000, i2.exports.f()); |
221 })(); | 230 })(); |
222 | 231 |
223 (function MustBeMemory() { | 232 (function MustBeMemory() { |
224 print("MustBeMemory..."); | 233 print("MustBeMemory..."); |
225 var memory = new ArrayBuffer(65536); | 234 var memory = new ArrayBuffer(65536); |
226 var module = new WebAssembly.Module(buffer); | 235 var module = new WebAssembly.Module(buffer); |
227 assertThrows(() => new WebAssembly.Instance(module, null, memory), TypeError); | 236 assertThrows(() => new WebAssembly.Instance(module, null, memory), TypeError); |
228 })(); | 237 })(); |
OLD | NEW |