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

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

Issue 2637643002: [wasm] Table.Grow should grow dispatch tables (Closed)
Patch Set: 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
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({element: "anyfunc", initial: 10, maximum: 3 0});
bradnelson 2017/01/15 03:00:14 >80
gdeepti 2017/01/15 05:57:54 Done.
403 var builder = new WasmModuleBuilder();
404 builder.addImportedTable("x", "table", 10, 30);
405
406 let g = builder.addImportedGlobal("x", "base", kWasmI32);
407 let sig_index = builder.addType(kSig_i_v);
408 builder.addFunction("g", sig_index)
409 .addBody([
410 kExprGetGlobal, g
411 ]);
412 builder.addFunction("main", kSig_i_ii)
413 .addBody([
414 kExprGetLocal, 0,
415 kExprCallIndirect, sig_index, kTableZero]) // --
416 .exportAs("main");
417 builder.addFunctionTableInit(g, true, [g]);
418 let module = new WebAssembly.Module(builder.toBuffer());
419
420 var instances = [];
421 for (var i = 0; i < 10; i++) {
422 print(" base = " + i);
423 instances.push(new WebAssembly.Instance(
424 module, {x: {base: i, table: table}}));
425 }
426
427 for (var j = 0; j < 10; j++) {
428 let func = table.get(j);
429 assertEquals("function", typeof func);
430 assertEquals(j, func());
431 assertEquals(j, instances[j].exports.main(j));
432 }
433
434 assertEquals(10, table.grow(10));
435
436 // Verify that grow does not alter function behaviors
437 for (var j = 0; j < 10; j++) {
438 let func = table.get(j);
439 assertEquals("function", typeof func);
440 assertEquals(j, func());
441 assertEquals(j, instances[j].exports.main(j));
442 }
443
444 let new_builder = new WasmModuleBuilder();
445 new_builder.addExport("wasm", new_builder.addFunction("", kSig_v_v));
446 new_builder.addImportedTable("x", "table", 20, 30);
447 let new_module = new WebAssembly.Module(new_builder.toBuffer());
448 let instance = new WebAssembly.Instance(new_module, {x: {table: table}});
449 let new_func = instance.exports.wasm;
450
451 for (var j = 10; j < 20; j++) {
452 table.set(j, new_func);
453 let func = table.get(j);
454 assertEquals("function", typeof func);
455 assertSame(new_func, table.get(j));
456 }
457 assertThrows(() => table.grow(11));
377 })(); 458 })();
OLDNEW
« src/wasm/wasm-js.cc ('K') | « 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