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 --allow-natives-syntax --expose-gc | 5 // Flags: --expose-wasm --allow-natives-syntax --expose-gc |
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 (function SerializeAndDeserializeModule() { | 10 (function SerializeAndDeserializeModule() { |
(...skipping 17 matching lines...) Expand all Loading... |
28 ]).exportFunc(); | 28 ]).exportFunc(); |
29 | 29 |
30 // writer(mem[i]); | 30 // writer(mem[i]); |
31 // return mem[i] + some_value(); | 31 // return mem[i] + some_value(); |
32 builder.addFunction("_wrap_writer", signature) | 32 builder.addFunction("_wrap_writer", signature) |
33 .addBody([ | 33 .addBody([ |
34 kExprGetLocal, 0, | 34 kExprGetLocal, 0, |
35 kExprCallFunction, 1]); | 35 kExprCallFunction, 1]); |
36 builder.appendToTable([2, 3]); | 36 builder.appendToTable([2, 3]); |
37 | 37 |
38 | 38 var wire_bytes = builder.toBuffer(); |
39 var module = new WebAssembly.Module(builder.toBuffer()); | 39 var module = new WebAssembly.Module(wire_bytes); |
40 var buff = %SerializeWasmModule(module); | 40 var buff = %SerializeWasmModule(module); |
41 module = null; | 41 module = null; |
42 gc(); | 42 gc(); |
43 module = %DeserializeWasmModule(buff); | 43 module = %DeserializeWasmModule(buff, wire_bytes); |
44 | 44 |
45 var mem_1 = new ArrayBuffer(4); | 45 var mem_1 = new ArrayBuffer(4); |
46 var view_1 = new Int32Array(mem_1); | 46 var view_1 = new Int32Array(mem_1); |
47 | 47 |
48 view_1[0] = 42; | 48 view_1[0] = 42; |
49 | 49 |
50 var outval_1; | 50 var outval_1; |
51 var i1 = new WebAssembly.Instance(module, {some_value: () => 1, | 51 var i1 = new WebAssembly.Instance(module, {some_value: () => 1, |
52 writer: (x)=>outval_1 = x }, mem_1); | 52 writer: (x)=>outval_1 = x }, mem_1); |
53 | 53 |
54 assertEquals(43, i1.exports.main(0)); | 54 assertEquals(43, i1.exports.main(0)); |
55 | 55 |
56 assertEquals(42, outval_1); | 56 assertEquals(42, outval_1); |
57 })(); | 57 })(); |
58 | 58 |
59 (function DeserializeInvalidObject() { | 59 (function DeserializeInvalidObject() { |
60 var invalid_buffer = new ArrayBuffer(10); | 60 var invalid_buffer = new ArrayBuffer(10); |
61 | 61 |
62 module = %DeserializeWasmModule(invalid_buffer); | 62 module = %DeserializeWasmModule(invalid_buffer, invalid_buffer); |
63 assertEquals(module, undefined); | 63 assertEquals(module, undefined); |
64 })(); | 64 })(); |
65 | 65 |
66 (function RelationBetweenModuleAndClone() { | 66 (function RelationBetweenModuleAndClone() { |
67 let builder = new WasmModuleBuilder(); | 67 let builder = new WasmModuleBuilder(); |
68 builder.addFunction("main", kSig_i_v) | 68 builder.addFunction("main", kSig_i_v) |
69 .addBody([kExprI8Const, 42]) | 69 .addBody([kExprI8Const, 42]) |
70 .exportFunc(); | 70 .exportFunc(); |
71 | 71 |
72 var compiled_module = new WebAssembly.Module(builder.toBuffer()); | 72 var wire_bytes = builder.toBuffer(); |
| 73 var compiled_module = new WebAssembly.Module(wire_bytes); |
73 var serialized = %SerializeWasmModule(compiled_module); | 74 var serialized = %SerializeWasmModule(compiled_module); |
74 var clone = %DeserializeWasmModule(serialized); | 75 var clone = %DeserializeWasmModule(serialized, wire_bytes); |
75 | 76 |
76 assertNotNull(clone); | 77 assertNotNull(clone); |
77 assertFalse(clone == undefined); | 78 assertFalse(clone == undefined); |
78 assertFalse(clone == compiled_module); | 79 assertFalse(clone == compiled_module); |
79 assertEquals(clone.constructor, compiled_module.constructor); | 80 assertEquals(clone.constructor, compiled_module.constructor); |
80 })(); | 81 })(); |
81 | 82 |
82 (function SerializeAfterInstantiation() { | 83 (function SerializeAfterInstantiation() { |
83 let builder = new WasmModuleBuilder(); | 84 let builder = new WasmModuleBuilder(); |
84 builder.addFunction("main", kSig_i_v) | 85 builder.addFunction("main", kSig_i_v) |
85 .addBody([kExprI8Const, 42]) | 86 .addBody([kExprI8Const, 42]) |
86 .exportFunc(); | 87 .exportFunc(); |
87 | 88 |
88 var compiled_module = new WebAssembly.Module(builder.toBuffer()); | 89 var wire_bytes = builder.toBuffer() |
| 90 var compiled_module = new WebAssembly.Module(wire_bytes); |
89 var instance1 = new WebAssembly.Instance(compiled_module); | 91 var instance1 = new WebAssembly.Instance(compiled_module); |
90 var instance2 = new WebAssembly.Instance(compiled_module); | 92 var instance2 = new WebAssembly.Instance(compiled_module); |
91 var serialized = %SerializeWasmModule(compiled_module); | 93 var serialized = %SerializeWasmModule(compiled_module); |
92 var clone = %DeserializeWasmModule(serialized); | 94 var clone = %DeserializeWasmModule(serialized, wire_bytes); |
93 | 95 |
94 assertNotNull(clone); | 96 assertNotNull(clone); |
95 assertFalse(clone == undefined); | 97 assertFalse(clone == undefined); |
96 assertFalse(clone == compiled_module); | 98 assertFalse(clone == compiled_module); |
97 assertEquals(clone.constructor, compiled_module.constructor); | 99 assertEquals(clone.constructor, compiled_module.constructor); |
98 var instance3 = new WebAssembly.Instance(clone); | 100 var instance3 = new WebAssembly.Instance(clone); |
99 assertFalse(instance3 == undefined); | 101 assertFalse(instance3 == undefined); |
100 })(); | 102 })(); |
OLD | NEW |