Chromium Code Reviews| 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({element: "anyfunc", initial: kTableSize, ma ximum: kTableSize}); |
|
rossberg
2017/01/17 14:22:06
Nit: line length
titzer
2017/01/17 16:47:18
Done.
| |
| 246 | 247 |
| 247 var builder = new WasmModuleBuilder(); | 248 var builder = new WasmModuleBuilder(); |
| 248 | 249 |
| 249 builder.addImportedTable("x", "table", kTableSize, kTableSize); | 250 builder.addImportedTable("x", "table", kTableSize, kTableSize); |
| 250 let g = builder.addImportedGlobal("x", "base", kWasmI32); | 251 let g = builder.addImportedGlobal("x", "base", kWasmI32); |
| 251 let sig_index = builder.addType(kSig_i_v); | 252 let sig_index = builder.addType(kSig_i_v); |
| 252 builder.addFunction("g", sig_index) | 253 builder.addFunction("g", sig_index) |
| 253 .addBody([ | 254 .addBody([ |
| 254 kExprGetGlobal, g | 255 kExprGetGlobal, g |
| 255 ]); | 256 ]); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 let new_func = instance.exports.wasm; | 451 let new_func = instance.exports.wasm; |
| 451 | 452 |
| 452 for (var j = 10; j < 20; j++) { | 453 for (var j = 10; j < 20; j++) { |
| 453 table.set(j, new_func); | 454 table.set(j, new_func); |
| 454 let func = table.get(j); | 455 let func = table.get(j); |
| 455 assertEquals("function", typeof func); | 456 assertEquals("function", typeof func); |
| 456 assertSame(new_func, table.get(j)); | 457 assertSame(new_func, table.get(j)); |
| 457 } | 458 } |
| 458 assertThrows(() => table.grow(11)); | 459 assertThrows(() => table.grow(11)); |
| 459 })(); | 460 })(); |
| 461 | |
| 462 | |
| 463 (function TestImportTooLarge() { | |
| 464 print("TestImportTooLarge..."); | |
| 465 let builder = new WasmModuleBuilder(); | |
| 466 builder.addImportedTable("t", "t", 1, 2); | |
| 467 | |
| 468 // initial size is too large | |
| 469 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table( | |
| 470 {element: "anyfunc", initial: 3, maximum: 3})}})); | |
| 471 | |
| 472 // maximum size is too large | |
| 473 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table( | |
| 474 {element: "anyfunc", initial: 1, maximum: 4})}})); | |
| 475 | |
| 476 // no maximum | |
| 477 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table( | |
| 478 {element: "anyfunc", initial: 1})}})); | |
| 479 })(); | |
| OLD | NEW |