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 = 117; | 10 let kReturnValue = 117; |
11 | 11 |
12 let buffer = (() => { | 12 let buffer = (() => { |
13 let builder = new WasmModuleBuilder(); | 13 let builder = new WasmModuleBuilder(); |
14 builder.addMemory(1, 1, true); | 14 builder.addMemory(1, 1, true); |
15 builder.addFunction("main", kSig_i_v) | 15 builder.addFunction("main", kSig_i_v) |
16 .addBody([kExprI8Const, kReturnValue]) | 16 .addBody([kExprI8Const, kReturnValue]) |
17 .exportFunc(); | 17 .exportFunc(); |
18 | 18 |
19 return builder.toBuffer(); | 19 return builder.toBuffer(); |
20 })() | 20 })() |
21 | 21 |
22 function CheckInstance(instance) { | 22 function CheckInstance(instance) { |
23 assertFalse(instance === undefined); | 23 assertFalse(instance === undefined); |
24 assertFalse(instance === null); | 24 assertFalse(instance === null); |
25 assertFalse(instance === 0); | 25 assertFalse(instance === 0); |
26 assertEquals("object", typeof instance); | 26 assertEquals("object", typeof instance); |
27 | 27 |
| 28 // Check the exports object is frozen. |
| 29 assertFalse(Object.isExtensible(instance.exports)); |
| 30 assertTrue(Object.isFrozen(instance.exports)); |
| 31 |
28 // Check the memory is an ArrayBuffer. | 32 // Check the memory is an ArrayBuffer. |
29 var mem = instance.exports.memory; | 33 var mem = instance.exports.memory; |
30 assertFalse(mem === undefined); | 34 assertFalse(mem === undefined); |
31 assertFalse(mem === null); | 35 assertFalse(mem === null); |
32 assertFalse(mem === 0); | 36 assertFalse(mem === 0); |
33 assertEquals("object", typeof mem); | 37 assertEquals("object", typeof mem); |
34 assertTrue(mem instanceof WebAssembly.Memory); | 38 assertTrue(mem instanceof WebAssembly.Memory); |
35 var buf = mem.buffer; | 39 var buf = mem.buffer; |
36 assertTrue(buf instanceof ArrayBuffer); | 40 assertTrue(buf instanceof ArrayBuffer); |
37 assertEquals(65536, buf.byteLength); | 41 assertEquals(65536, buf.byteLength); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 assertEquals(1, i1.exports.f()); | 217 assertEquals(1, i1.exports.f()); |
214 assertEquals(1000, i2.exports.f()); | 218 assertEquals(1000, i2.exports.f()); |
215 })(); | 219 })(); |
216 | 220 |
217 (function MustBeMemory() { | 221 (function MustBeMemory() { |
218 print("MustBeMemory..."); | 222 print("MustBeMemory..."); |
219 var memory = new ArrayBuffer(65536); | 223 var memory = new ArrayBuffer(65536); |
220 var module = new WebAssembly.Module(buffer); | 224 var module = new WebAssembly.Module(buffer); |
221 assertThrows(() => new WebAssembly.Instance(module, null, memory), TypeError); | 225 assertThrows(() => new WebAssembly.Instance(module, null, memory), TypeError); |
222 })(); | 226 })(); |
OLD | NEW |