Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: test/mjsunit/wasm/indirect-tables.js

Issue 2637643002: [wasm] Table.Grow should grow dispatch tables (Closed)
Patch Set: Rebase + review Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-objects.cc ('k') | test/mjsunit/wasm/js-api.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // TODO(titzer): v8 currently requires import table size to match 364 // TODO(titzer): v8 currently requires import table size to match
365 // export table size. 365 // export table size.
366 var ffi = {y: {impfoo: i1.exports.expfoo}}; 366 var ffi = {y: {impfoo: i1.exports.expfoo}};
367 if (expsize == impsize) { 367 if (expsize == impsize) {
368 var i2 = new WebAssembly.Instance(m2, ffi); 368 var i2 = new WebAssembly.Instance(m2, ffi);
369 } else { 369 } else {
370 assertThrows(() => new WebAssembly.Instance(m2, ffi)); 370 assertThrows(() => new WebAssembly.Instance(m2, ffi));
371 } 371 }
372 } 372 }
373 } 373 }
374 })();
374 375
376 (function TableGrowBoundsCheck() {
377 print("TableGrowBoundsCheck");
378 var kMaxSize = 30, kInitSize = 5;
379 let table = new WebAssembly.Table({element: "anyfunc",
380 initial: kInitSize, maximum: kMaxSize});
381 var builder = new WasmModuleBuilder();
382 builder.addImportedTable("x", "table", kInitSize, kMaxSize);
383 let module = new WebAssembly.Module(builder.toBuffer());
384 let instance = new WebAssembly.Instance(module, {x: {base: 1, table: table}});
375 385
386 for(var i = kInitSize; i < kMaxSize; i+=5) {
387 assertEquals(i, table.length);
388 for (var j = 0; j < i; j++) table.set(j, null);
389 for (var j = 0; j < i; j++) assertEquals(null, table.get(j));
390 assertThrows(() => table.set(i, null));
391 assertThrows(() => table.get(i));
392 assertEquals(i, table.grow(5));
393 }
394 assertEquals(30, table.length);
395 assertThrows(() => table.grow(1));
396 assertThrows(() => table.set(kMaxSize, null));
397 assertThrows(() => table.get(kMaxSize));
398 })();
376 399
400 (function CumulativeGrowTest() {
401 print("CumulativeGrowTest...");
402 let table = new WebAssembly.Table({
403 element: "anyfunc", initial: 10, maximum: 30});
404 var builder = new WasmModuleBuilder();
405 builder.addImportedTable("x", "table", 10, 30);
406
407 let g = builder.addImportedGlobal("x", "base", kWasmI32);
408 let sig_index = builder.addType(kSig_i_v);
409 builder.addFunction("g", sig_index)
410 .addBody([
411 kExprGetGlobal, g
412 ]);
413 builder.addFunction("main", kSig_i_ii)
414 .addBody([
415 kExprGetLocal, 0,
416 kExprCallIndirect, sig_index, kTableZero]) // --
417 .exportAs("main");
418 builder.addFunctionTableInit(g, true, [g]);
419 let module = new WebAssembly.Module(builder.toBuffer());
420
421 var instances = [];
422 for (var i = 0; i < 10; i++) {
423 print(" base = " + i);
424 instances.push(new WebAssembly.Instance(
425 module, {x: {base: i, table: table}}));
426 }
427
428 for (var j = 0; j < 10; j++) {
429 let func = table.get(j);
430 assertEquals("function", typeof func);
431 assertEquals(j, func());
432 assertEquals(j, instances[j].exports.main(j));
433 }
434
435 assertEquals(10, table.grow(10));
436
437 // Verify that grow does not alter function behaviors
438 for (var j = 0; j < 10; j++) {
439 let func = table.get(j);
440 assertEquals("function", typeof func);
441 assertEquals(j, func());
442 assertEquals(j, instances[j].exports.main(j));
443 }
444
445 let new_builder = new WasmModuleBuilder();
446 new_builder.addExport("wasm", new_builder.addFunction("", kSig_v_v));
447 new_builder.addImportedTable("x", "table", 20, 30);
448 let new_module = new WebAssembly.Module(new_builder.toBuffer());
449 let instance = new WebAssembly.Instance(new_module, {x: {table: table}});
450 let new_func = instance.exports.wasm;
451
452 for (var j = 10; j < 20; j++) {
453 table.set(j, new_func);
454 let func = table.get(j);
455 assertEquals("function", typeof func);
456 assertSame(new_func, table.get(j));
457 }
458 assertThrows(() => table.grow(11));
377 })(); 459 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-objects.cc ('k') | test/mjsunit/wasm/js-api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698