Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --expose-wasm --expose-gc --verify-heap | |
| 6 | |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | |
| 9 | |
| 10 const verifyHeap = gc; | |
| 11 let globalCounter = 10000000; | |
| 12 | |
| 13 function testProperties(obj) { | |
| 14 for (let i = 0; i < 3; i++) { | |
| 15 obj.x = 1001; | |
| 16 assertEquals(1001, obj.x); | |
| 17 | |
| 18 obj.y = "old"; | |
| 19 assertEquals("old", obj.y); | |
| 20 | |
| 21 delete obj.y; | |
| 22 assertEquals("undefined", typeof obj.y); | |
| 23 | |
| 24 let uid = globalCounter++; | |
| 25 let fresh = "f_" + uid; | |
| 26 | |
| 27 obj.z = fresh; | |
| 28 assertEquals(fresh, obj.z); | |
| 29 | |
| 30 obj[fresh] = uid; | |
| 31 assertEquals(uid, obj[fresh]); | |
| 32 | |
| 33 verifyHeap(); | |
| 34 | |
| 35 assertEquals(1001, obj.x); | |
| 36 assertEquals(fresh, obj.z); | |
| 37 assertEquals(uid, obj[fresh]); | |
| 38 } | |
| 39 | |
| 40 obj.tested = "yep"; | |
| 41 } | |
| 42 | |
| 43 function minus18(x) { return x - 18; } | |
| 44 function id(x) { return x; } | |
| 45 | |
| 46 (function ExportedFunctionTest() { | |
| 47 print("ExportedFunctionTest"); | |
| 48 | |
| 49 print(" instance 1, exporting"); | |
| 50 var builder = new WasmModuleBuilder(); | |
| 51 builder.addFunction("exp", kSig_i_i) | |
| 52 .addBody([ | |
| 53 kExprGetLocal, 0, | |
| 54 kExprCallFunction, 0]) | |
| 55 .exportAs("exp"); | |
| 56 let module1 = builder.toModule(); | |
| 57 let instance1 = new WebAssembly.Instance(module1); | |
| 58 let g = instance1.exports.exp; | |
| 59 | |
| 60 testProperties(g); | |
| 61 | |
| 62 // The WASM-internal fields of {g} are only inspected when {g} is | |
| 63 // used as an import into another instance. | |
| 64 print(" instance 2, importing"); | |
| 65 var builder = new WasmModuleBuilder(); | |
| 66 builder.addImport("imp", "func", kSig_i_i); | |
| 67 let module2 = builder.toModule(); | |
| 68 let instance2 = new WebAssembly.Instance(module2, {imp: {func: g}}); | |
| 69 | |
| 70 testProperties(g); | |
| 71 })(); | |
| 72 | |
| 73 (function ImportReexportChain() { | |
| 74 print("ImportReexportChain"); | |
| 75 | |
| 76 var f = id; | |
|
Clemens Hammacher
2017/07/14 13:04:35
wouldn't it be easier to just write "var f = x =>
| |
| 77 | |
| 78 for (let i = 0; i < 5; i++) { | |
| 79 let builder = new WasmModuleBuilder(); | |
| 80 builder.addImport("imp", "func", kSig_i_i); | |
| 81 builder.addExport("exp", 0); | |
| 82 let module = builder.toModule(); | |
| 83 let instance = new WebAssembly.Instance(module, {imp: {func: f}}); | |
| 84 let g = instance.exports.exp; | |
| 85 assertInstanceof(g, Function); | |
| 86 testProperties(g); | |
| 87 | |
| 88 // The WASM-internal fields of {g} are only inspected when {g} is | |
| 89 // used as an import into another instance. Use {g} as the import | |
| 90 // the next time through the loop. | |
| 91 f = g; | |
| 92 } | |
| 93 })(); | |
| 94 | |
| 95 | |
| 96 (function ModuleTest() { | |
| 97 for (f of [x => (x + 19 + globalCounter), minus18]) { | |
|
Clemens Hammacher
2017/07/14 13:04:35
This is the only use of minus18, so you should jus
titzer
2017/07/14 13:12:40
This was intentional to have a JSFunction instance
| |
| 98 print("ModuleTest"); | |
| 99 | |
| 100 let builder = new WasmModuleBuilder(); | |
| 101 builder.addImport("m", "f", kSig_i_i); | |
| 102 builder.addFunction("main", kSig_i_i) | |
| 103 .addBody([ | |
| 104 kExprGetLocal, 0, | |
| 105 kExprCallFunction, 0]) | |
| 106 .exportAs("main"); | |
| 107 builder.addMemory(1, 1, false) | |
| 108 .exportMemoryAs("memory") | |
| 109 | |
| 110 let module = builder.toModule(); | |
| 111 testProperties(module); | |
| 112 | |
| 113 for (let i = 0; i < 3; i++) { | |
| 114 print(" instance " + i); | |
| 115 let instance = new WebAssembly.Instance(module, {m: {f: f}}); | |
| 116 testProperties(instance); | |
| 117 | |
| 118 print(" memory " + i); | |
| 119 let m = instance.exports.memory; | |
| 120 assertInstanceof(m, WebAssembly.Memory); | |
| 121 testProperties(m); | |
| 122 | |
| 123 print(" function " + i); | |
| 124 let g = instance.exports.main; | |
| 125 assertInstanceof(g, Function); | |
| 126 testProperties(g); | |
| 127 assertInstanceof(g, Function); | |
| 128 testProperties(g); | |
| 129 for (let j = 10; j < 15; j++) { | |
| 130 assertEquals(f(j), g(j)); | |
| 131 } | |
| 132 verifyHeap(); | |
| 133 // The WASM-internal fields of {g} are only inspected when {g} is | |
| 134 // used as an import into another instance. Use {g} as the import | |
| 135 // the next time through the loop. | |
| 136 f = g; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 })(); | |
| 141 | |
| 142 (function ConstructedTest() { | |
| 143 print("ConstructedTest"); | |
| 144 | |
| 145 var memory = undefined, table = undefined; | |
| 146 for (let i = 0; i < 4; i++) { | |
| 147 print(" iteration " + i); | |
| 148 | |
| 149 let m = new WebAssembly.Memory({initial: 1}); | |
| 150 let t = new WebAssembly.Table({element: "anyfunc", initial: 1}); | |
| 151 m.old = memory; | |
| 152 t.old = table; | |
| 153 | |
| 154 memory = m; | |
| 155 table = t; | |
| 156 testProperties(memory); | |
| 157 testProperties(table); | |
| 158 } | |
| 159 })(); | |
| OLD | NEW |