| 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 --expose-gc --allow-natives-syntax | 5 // Flags: --expose-wasm --expose-gc --allow-natives-syntax |
| 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 // Use global variables for all values where the test wants to maintain strict | 10 // Use global variables for all values where the test wants to maintain strict |
| 11 // control over value lifetime. Using local variables would not give sufficient | 11 // control over value lifetime. Using local variables would not give sufficient |
| 12 // guarantees of the value lifetime. | 12 // guarantees of the value lifetime. |
| 13 var module; | 13 var module; |
| 14 var instance1; | 14 var instance1; |
| 15 var instance2; | 15 var instance2; |
| 16 var instance3; | 16 var instance3; |
| 17 var instance4; | 17 var instance4; |
| 18 | 18 |
| 19 (function CompiledModuleInstancesInitialize1to3() { | 19 (function CompiledModuleInstancesInitialize1to3() { |
| 20 var builder = new WasmModuleBuilder(); | 20 var builder = new WasmModuleBuilder(); |
| 21 | 21 |
| 22 builder.addMemory(1,1, true); | 22 builder.addMemory(1,1, true); |
| 23 builder.addImport("getValue", kSig_i_v); | 23 builder.addImport("", "getValue", kSig_i_v); |
| 24 builder.addFunction("f", kSig_i_v) | 24 builder.addFunction("f", kSig_i_v) |
| 25 .addBody([ | 25 .addBody([ |
| 26 kExprCallFunction, 0 | 26 kExprCallFunction, 0 |
| 27 ]).exportFunc(); | 27 ]).exportFunc(); |
| 28 | 28 |
| 29 module = new WebAssembly.Module(builder.toBuffer()); | 29 module = new WebAssembly.Module(builder.toBuffer()); |
| 30 %ValidateWasmModuleState(module); | 30 %ValidateWasmModuleState(module); |
| 31 %ValidateWasmInstancesChain(module, 0); | 31 %ValidateWasmInstancesChain(module, 0); |
| 32 instance1 = new WebAssembly.Instance(module, {getValue: () => 1}); | 32 instance1 = new WebAssembly.Instance(module, {"": {getValue: () => 1}}); |
| 33 %ValidateWasmInstancesChain(module, 1); | 33 %ValidateWasmInstancesChain(module, 1); |
| 34 instance2 = new WebAssembly.Instance(module, {getValue: () => 2}); | 34 instance2 = new WebAssembly.Instance(module, {"": {getValue: () => 2}}); |
| 35 %ValidateWasmInstancesChain(module, 2); | 35 %ValidateWasmInstancesChain(module, 2); |
| 36 instance3 = new WebAssembly.Instance(module, {getValue: () => 3}); | 36 instance3 = new WebAssembly.Instance(module, {"": {getValue: () => 3}}); |
| 37 %ValidateWasmInstancesChain(module, 3); | 37 %ValidateWasmInstancesChain(module, 3); |
| 38 })(); | 38 })(); |
| 39 | 39 |
| 40 (function CompiledModuleInstancesClear1() { | 40 (function CompiledModuleInstancesClear1() { |
| 41 assertEquals(1, instance1.exports.f()); | 41 assertEquals(1, instance1.exports.f()); |
| 42 instance1 = null; | 42 instance1 = null; |
| 43 })(); | 43 })(); |
| 44 | 44 |
| 45 gc(); | 45 gc(); |
| 46 %ValidateWasmInstancesChain(module, 2); | 46 %ValidateWasmInstancesChain(module, 2); |
| 47 | 47 |
| 48 (function CompiledModuleInstancesClear3() { | 48 (function CompiledModuleInstancesClear3() { |
| 49 assertEquals(3, instance3.exports.f()); | 49 assertEquals(3, instance3.exports.f()); |
| 50 instance3 = null; | 50 instance3 = null; |
| 51 })(); | 51 })(); |
| 52 | 52 |
| 53 gc(); | 53 gc(); |
| 54 %ValidateWasmInstancesChain(module, 1); | 54 %ValidateWasmInstancesChain(module, 1); |
| 55 | 55 |
| 56 (function CompiledModuleInstancesClear2() { | 56 (function CompiledModuleInstancesClear2() { |
| 57 assertEquals(2, instance2.exports.f()); | 57 assertEquals(2, instance2.exports.f()); |
| 58 instance2 = null; | 58 instance2 = null; |
| 59 })(); | 59 })(); |
| 60 | 60 |
| 61 gc(); | 61 gc(); |
| 62 %ValidateWasmModuleState(module); | 62 %ValidateWasmModuleState(module); |
| 63 | 63 |
| 64 (function CompiledModuleInstancesInitialize4AndClearModule() { | 64 (function CompiledModuleInstancesInitialize4AndClearModule() { |
| 65 instance4 = new WebAssembly.Instance(module, {getValue: () => 4}); | 65 instance4 = new WebAssembly.Instance(module, {"": {getValue: () => 4}}); |
| 66 assertEquals(4, instance4.exports.f()); | 66 assertEquals(4, instance4.exports.f()); |
| 67 module = null; | 67 module = null; |
| 68 })(); | 68 })(); |
| 69 | 69 |
| 70 gc(); | 70 gc(); |
| 71 %ValidateWasmOrphanedInstance(instance4); | 71 %ValidateWasmOrphanedInstance(instance4); |
| OLD | NEW |