| 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 | 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 function AddFunctions(builder) { | 10 function AddFunctions(builder) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 kExprGetLocal, 1, // -- | 192 kExprGetLocal, 1, // -- |
| 193 kExprCallIndirect, 0, kTableZero]) // -- | 193 kExprCallIndirect, 0, kTableZero]) // -- |
| 194 .exportAs("main"); | 194 .exportAs("main"); |
| 195 | 195 |
| 196 let m2 = new WebAssembly.Module(builder.toBuffer()); | 196 let m2 = new WebAssembly.Module(builder.toBuffer()); |
| 197 | 197 |
| 198 // Run 5 trials at different table bases. | 198 // Run 5 trials at different table bases. |
| 199 for (let i = 0; i < 5; i++) { | 199 for (let i = 0; i < 5; i++) { |
| 200 print(" base = " + i); | 200 print(" base = " + i); |
| 201 let table = new WebAssembly.Table({element: "anyfunc", | 201 let table = new WebAssembly.Table({element: "anyfunc", |
| 202 initial: kTableSize}); | 202 initial: kTableSize, |
| 203 maximum: kTableSize}); |
| 203 assertEquals(10, table.length); | 204 assertEquals(10, table.length); |
| 204 let i2 = new WebAssembly.Instance(m2, {q: {base: i, table: table, | 205 let i2 = new WebAssembly.Instance(m2, {q: {base: i, table: table, |
| 205 js_div: js_div}}); | 206 js_div: js_div}}); |
| 206 let main = i2.exports.main; | 207 let main = i2.exports.main; |
| 207 | 208 |
| 208 for (var j = 0; j < i; j++) { | 209 for (var j = 0; j < i; j++) { |
| 209 assertThrows(() => main(0, j)); | 210 assertThrows(() => main(0, j)); |
| 210 assertSame(null, table.get(j)); | 211 assertSame(null, table.get(j)); |
| 211 } | 212 } |
| 212 | 213 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 235 if (j < kTableSize) assertSame(null, table.get(j)); | 236 if (j < kTableSize) assertSame(null, table.get(j)); |
| 236 } | 237 } |
| 237 } | 238 } |
| 238 })(); | 239 })(); |
| 239 | 240 |
| 240 | 241 |
| 241 (function CumulativeTest() { | 242 (function CumulativeTest() { |
| 242 print("CumulativeTest..."); | 243 print("CumulativeTest..."); |
| 243 | 244 |
| 244 let kTableSize = 10; | 245 let kTableSize = 10; |
| 245 let table = new WebAssembly.Table({element: "anyfunc", initial: 10}); | 246 let table = new WebAssembly.Table( |
| 247 {element: "anyfunc", initial: kTableSize, maximum: kTableSize}); |
| 246 | 248 |
| 247 var builder = new WasmModuleBuilder(); | 249 var builder = new WasmModuleBuilder(); |
| 248 | 250 |
| 249 builder.addImportedTable("x", "table", kTableSize, kTableSize); | 251 builder.addImportedTable("x", "table", kTableSize, kTableSize); |
| 250 let g = builder.addImportedGlobal("x", "base", kWasmI32); | 252 let g = builder.addImportedGlobal("x", "base", kWasmI32); |
| 251 let sig_index = builder.addType(kSig_i_v); | 253 let sig_index = builder.addType(kSig_i_v); |
| 252 builder.addFunction("g", sig_index) | 254 builder.addFunction("g", sig_index) |
| 253 .addBody([ | 255 .addBody([ |
| 254 kExprGetGlobal, g | 256 kExprGetGlobal, g |
| 255 ]); | 257 ]); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 let new_func = instance.exports.wasm; | 452 let new_func = instance.exports.wasm; |
| 451 | 453 |
| 452 for (var j = 10; j < 20; j++) { | 454 for (var j = 10; j < 20; j++) { |
| 453 table.set(j, new_func); | 455 table.set(j, new_func); |
| 454 let func = table.get(j); | 456 let func = table.get(j); |
| 455 assertEquals("function", typeof func); | 457 assertEquals("function", typeof func); |
| 456 assertSame(new_func, table.get(j)); | 458 assertSame(new_func, table.get(j)); |
| 457 } | 459 } |
| 458 assertThrows(() => table.grow(11)); | 460 assertThrows(() => table.grow(11)); |
| 459 })(); | 461 })(); |
| 462 |
| 463 |
| 464 (function TestImportTooLarge() { |
| 465 print("TestImportTooLarge..."); |
| 466 let builder = new WasmModuleBuilder(); |
| 467 builder.addImportedTable("t", "t", 1, 2); |
| 468 |
| 469 // initial size is too large |
| 470 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table( |
| 471 {element: "anyfunc", initial: 3, maximum: 3})}})); |
| 472 |
| 473 // maximum size is too large |
| 474 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table( |
| 475 {element: "anyfunc", initial: 1, maximum: 4})}})); |
| 476 |
| 477 // no maximum |
| 478 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table( |
| 479 {element: "anyfunc", initial: 1})}})); |
| 480 })(); |
| OLD | NEW |