How to use addImportedTable method in wpt

Best JavaScript code snippet using wpt

615cae19c8452d37e64011977b7167d1.js

Source:615cae19c8452d37e64011977b7167d1.js Github

copy

Full Screen

...98 d]);99 builder.addExportOfKind("table", kExternalTable, 0);100 let m1 = new WebAssembly.Module(builder.toBuffer());101 var builder = new WasmModuleBuilder();102 builder.addImportedTable("r", "table", kTableSize, kTableSize);103 builder.addFunction("main", kSig_i_ii)104 .addBody([105 kExprI32Const, 33, // --106 kExprGetLocal, 0, // --107 kExprGetLocal, 1, // --108 kExprCallIndirect, 0, kTableZero]) // --109 .exportAs("main");110 let m2 = new WebAssembly.Module(builder.toBuffer());111 // Run 5 trials at different table bases.112 for (let i = 0; i < 5; i++) {113 print(" base = " + i);114 let i1 = new WebAssembly.Instance(m1, {q: {base: i, js_div: js_div}});115 let table = i1.exports.table;116 assertEquals(10, table.length);117 let i2 = new WebAssembly.Instance(m2, {r: {table: table}});118 let main = i2.exports.main;119 for (var j = 0; j < i; j++) {120 assertThrows(() => main(0, j));121 assertSame(null, table.get(j));122 }123 // mul124 assertEquals("function", typeof table.get(i+0));125 assertEquals(0, main(0, i+0));126 assertEquals(66, main(2, i+0));127 // add128 assertEquals("function", typeof table.get(i+1));129 assertEquals(33, main(0, i+1));130 assertEquals(38, main(5, i+1));131 // sub132 assertEquals("function", typeof table.get(i+2));133 assertEquals(32, main(1, i+2));134 assertEquals(28, main(5, i+2));135 // div136 assertEquals("function", typeof table.get(i+3));137 assertEquals(8, main(4, i+3));138 assertEquals(3, main(11, i+3));139 for (var j = i + 4; j < (kTableSize + 5); j++) {140 assertThrows(x => main(0, j));141 if (j < kTableSize) assertSame(null, table.get(j));142 }143 }144})();145(function ImportedTableTest() {146 let kTableSize = 10;147 print("ManualTableTest...");148 var builder = new WasmModuleBuilder();149 let d = builder.addImport("q", "js_div", kSig_i_ii);150 builder.addImportedTable("q", "table", kTableSize, kTableSize);151 let g = builder.addImportedGlobal("q", "base", kWasmI32);152 let f = AddFunctions(builder);153 builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index,154 f.sub.index,155 d]);156 builder.addFunction("main", kSig_i_ii)157 .addBody([158 kExprI32Const, 55, // --159 kExprGetLocal, 0, // --160 kExprGetLocal, 1, // --161 kExprCallIndirect, 0, kTableZero]) // --162 .exportAs("main");163 let m2 = new WebAssembly.Module(builder.toBuffer());164 // Run 5 trials at different table bases.165 for (let i = 0; i < 5; i++) {166 print(" base = " + i);167 let table = new WebAssembly.Table({element: "anyfunc",168 initial: kTableSize,169 maximum: kTableSize});170 assertEquals(10, table.length);171 let i2 = new WebAssembly.Instance(m2, {q: {base: i, table: table,172 js_div: js_div}});173 let main = i2.exports.main;174 for (var j = 0; j < i; j++) {175 assertThrows(() => main(0, j));176 assertSame(null, table.get(j));177 }178 // mul179 assertEquals("function", typeof table.get(i+0));180 assertEquals(0, main(0, i+0));181 assertEquals(110, main(2, i+0));182 // add183 assertEquals("function", typeof table.get(i+1));184 assertEquals(55, main(0, i+1));185 assertEquals(60, main(5, i+1));186 // sub187 assertEquals("function", typeof table.get(i+2));188 assertEquals(54, main(1, i+2));189 assertEquals(50, main(5, i+2));190 // div191 assertEquals("function", typeof table.get(i+3));192 assertEquals(13, main(4, i+3));193 assertEquals(5, main(11, i+3));194 for (var j = i + 4; j < (kTableSize + 5); j++) {195 assertThrows(x => main(0, j));196 if (j < kTableSize) assertSame(null, table.get(j));197 }198 }199})();200(function CumulativeTest() {201 print("CumulativeTest...");202 let kTableSize = 10;203 let table = new WebAssembly.Table(204 {element: "anyfunc", initial: kTableSize, maximum: kTableSize});205 var builder = new WasmModuleBuilder();206 builder.addImportedTable("x", "table", kTableSize, kTableSize);207 let g = builder.addImportedGlobal("x", "base", kWasmI32);208 let sig_index = builder.addType(kSig_i_v);209 builder.addFunction("g", sig_index)210 .addBody([211 kExprGetGlobal, g212 ]);213 builder.addFunction("main", kSig_i_ii)214 .addBody([215 kExprGetLocal, 0,216 kExprCallIndirect, sig_index, kTableZero]) // --217 .exportAs("main");218 builder.addFunctionTableInit(g, true, [g]);219 let module = new WebAssembly.Module(builder.toBuffer());220 for (var i = 0; i < kTableSize; i++) {221 print(" base = " + i);222 let instance = new WebAssembly.Instance(module, {x: {base: i, table: table}});223 for (var j = 0; j < kTableSize; j++) {224 let func = table.get(j);225 if (j > i) {226 assertSame(null, func);227 assertTraps(kTrapFuncSigMismatch, () => instance.exports.main(j));228 } else {229 assertEquals("function", typeof func);230 assertEquals(j, func());231 assertEquals(j, instance.exports.main(j));232 }233 }234 }235})();236(function TwoWayTest() {237 print("TwoWayTest...");238 let kTableSize = 3;239 // Module {m1} defines the table and exports it.240 var builder = new WasmModuleBuilder();241 builder.addType(kSig_i_i);242 builder.addType(kSig_i_ii);243 var sig_index1 = builder.addType(kSig_i_v);244 var f1 = builder.addFunction("f1", sig_index1)245 .addBody([kExprI32Const, 11]);246 builder.addFunction("main", kSig_i_ii)247 .addBody([248 kExprGetLocal, 0, // --249 kExprCallIndirect, sig_index1, kTableZero]) // --250 .exportAs("main");251 builder.setFunctionTableLength(kTableSize);252 builder.addFunctionTableInit(0, false, [f1.index]);253 builder.addExportOfKind("table", kExternalTable, 0);254 var m1 = new WebAssembly.Module(builder.toBuffer());255 // Module {m2} imports the table and adds {f2}.256 var builder = new WasmModuleBuilder();257 builder.addType(kSig_i_ii);258 var sig_index2 = builder.addType(kSig_i_v);259 var f2 = builder.addFunction("f2", sig_index2)260 .addBody([kExprI32Const, 22]);261 builder.addFunction("main", kSig_i_ii)262 .addBody([263 kExprGetLocal, 0, // --264 kExprCallIndirect, sig_index2, kTableZero]) // --265 .exportAs("main");266 builder.addImportedTable("z", "table", kTableSize, kTableSize);267 builder.addFunctionTableInit(1, false, [f2.index], true);268 var m2 = new WebAssembly.Module(builder.toBuffer());269 assertFalse(sig_index1 == sig_index2);270 var i1 = new WebAssembly.Instance(m1);271 var i2 = new WebAssembly.Instance(m2, {z: {table: i1.exports.table}});272 assertEquals(11, i1.exports.main(0));273 assertEquals(11, i2.exports.main(0));274 assertEquals(22, i1.exports.main(1));275 assertEquals(22, i2.exports.main(1));276 assertThrows(() => i1.exports.main(2));277 assertThrows(() => i2.exports.main(2));278 assertThrows(() => i1.exports.main(3));279 assertThrows(() => i2.exports.main(3));280})();281(function MismatchedTableSize() {282 print("MismatchedTableSize...");283 let kTableSize = 5;284 for (var expsize = 1; expsize < 4; expsize++) {285 for (var impsize = 1; impsize < 4; impsize++) {286 print(" expsize = " + expsize + ", impsize = " + impsize);287 var builder = new WasmModuleBuilder();288 builder.setFunctionTableLength(expsize);289 builder.addExportOfKind("expfoo", kExternalTable, 0);290 let m1 = new WebAssembly.Module(builder.toBuffer());291 var builder = new WasmModuleBuilder();292 builder.addImportedTable("y", "impfoo", impsize, impsize);293 let m2 = new WebAssembly.Module(builder.toBuffer());294 var i1 = new WebAssembly.Instance(m1);295 // TODO(titzer): v8 currently requires import table size to match296 // export table size.297 var ffi = {y: {impfoo: i1.exports.expfoo}};298 if (expsize == impsize) {299 var i2 = new WebAssembly.Instance(m2, ffi);300 } else {301 assertThrows(() => new WebAssembly.Instance(m2, ffi));302 }303 }304 }305})();306(function TableGrowBoundsCheck() {307 print("TableGrowBoundsCheck");308 var kMaxSize = 30, kInitSize = 5;309 let table = new WebAssembly.Table({element: "anyfunc",310 initial: kInitSize, maximum: kMaxSize});311 var builder = new WasmModuleBuilder();312 builder.addImportedTable("x", "table", kInitSize, kMaxSize);313 let module = new WebAssembly.Module(builder.toBuffer());314 let instance = new WebAssembly.Instance(module, {x: {base: 1, table: table}});315 for(var i = kInitSize; i < kMaxSize; i+=5) {316 assertEquals(i, table.length);317 for (var j = 0; j < i; j++) table.set(j, null);318 for (var j = 0; j < i; j++) assertEquals(null, table.get(j));319 assertThrows(() => table.set(i, null));320 assertThrows(() => table.get(i));321 assertEquals(i, table.grow(5));322 }323 assertEquals(30, table.length);324 assertThrows(() => table.grow(1));325 assertThrows(() => table.set(kMaxSize, null));326 assertThrows(() => table.get(kMaxSize));327})();328(function CumulativeGrowTest() {329 print("CumulativeGrowTest...");330 let table = new WebAssembly.Table({331 element: "anyfunc", initial: 10, maximum: 30});332 var builder = new WasmModuleBuilder();333 builder.addImportedTable("x", "table", 10, 30);334 let g = builder.addImportedGlobal("x", "base", kWasmI32);335 let sig_index = builder.addType(kSig_i_v);336 builder.addFunction("g", sig_index)337 .addBody([338 kExprGetGlobal, g339 ]);340 builder.addFunction("main", kSig_i_ii)341 .addBody([342 kExprGetLocal, 0,343 kExprCallIndirect, sig_index, kTableZero]) // --344 .exportAs("main");345 builder.addFunctionTableInit(g, true, [g]);346 let module = new WebAssembly.Module(builder.toBuffer());347 var instances = [];348 for (var i = 0; i < 10; i++) {349 print(" base = " + i);350 instances.push(new WebAssembly.Instance(351 module, {x: {base: i, table: table}}));352 }353 for (var j = 0; j < 10; j++) {354 let func = table.get(j);355 assertEquals("function", typeof func);356 assertEquals(j, func());357 assertEquals(j, instances[j].exports.main(j));358 }359 assertEquals(10, table.grow(10));360 // Verify that grow does not alter function behaviors361 for (var j = 0; j < 10; j++) {362 let func = table.get(j);363 assertEquals("function", typeof func);364 assertEquals(j, func());365 assertEquals(j, instances[j].exports.main(j));366 }367 let new_builder = new WasmModuleBuilder();368 new_builder.addExport("wasm", new_builder.addFunction("", kSig_v_v).addBody([]));369 new_builder.addImportedTable("x", "table", 20, 30);370 let new_module = new WebAssembly.Module(new_builder.toBuffer());371 let instance = new WebAssembly.Instance(new_module, {x: {table: table}});372 let new_func = instance.exports.wasm;373 for (var j = 10; j < 20; j++) {374 table.set(j, new_func);375 let func = table.get(j);376 assertEquals("function", typeof func);377 assertSame(new_func, table.get(j));378 }379 assertThrows(() => table.grow(11));380})();381(function TestImportTooLarge() {382 print("TestImportTooLarge...");383 let builder = new WasmModuleBuilder();384 builder.addImportedTable("t", "t", 1, 2);385 // initial size is too large386 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(387 {element: "anyfunc", initial: 3, maximum: 3})}}));388 // maximum size is too large389 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(390 {element: "anyfunc", initial: 1, maximum: 4})}}));391 // no maximum392 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(393 {element: "anyfunc", initial: 1})}}));394})();395(function TableImportLargerThanCompiled() {396 print("TableImportLargerThanCompiled...");397 var kMaxSize = 30, kInitSize = 5;398 var builder = new WasmModuleBuilder();399 builder.addImportedTable("x", "table", 1, 35);400 let table = new WebAssembly.Table({element: "anyfunc",401 initial: kInitSize, maximum: kMaxSize});402 let module = new WebAssembly.Module(builder.toBuffer());403 let instance = new WebAssembly.Instance(module, {x: {base: 1, table: table}});404 for (var i = 0; i < kInitSize; ++i) table.set(i, null);405 for (var i = 0; i < kInitSize; ++i) assertEquals(null, table.get(i));406 assertThrows(() => table.set(kInitSize, null));407})();408(function ModulesShareTableAndGrow() {409 print("ModulesShareTableAndGrow...");410 let module1 = (() => {411 let builder = new WasmModuleBuilder();412 builder.addImportedTable("x", "table", 1, 35);413 return new WebAssembly.Module(builder.toBuffer());414 })();415 let module2 = (() => {416 let builder = new WasmModuleBuilder();417 builder.addImportedTable("x", "table", 2, 40);418 return new WebAssembly.Module(builder.toBuffer());419 })();420 var kMaxSize = 30, kInitSize = 5;421 let table = new WebAssembly.Table({element: "anyfunc",422 initial: kInitSize, maximum: kMaxSize});423 let instance1 = new WebAssembly.Instance(424 module1, {x: {base: 1, table: table}});425 let instance2 = new WebAssembly.Instance(426 module2, {x: {base: 1, table: table}});427 for (var i = 0; i < kInitSize; ++i) table.set(i, null);428 for (var i = 0; i < kInitSize; ++i) assertEquals(null, table.get(i));429 assertThrows(() => table.set(kInitSize, null));430 assertEquals(kInitSize, table.grow(5));431 for (var i = 0; i < 2*kInitSize; ++i) table.set(i, null);...

Full Screen

Full Screen

indirect-tables.js

Source:indirect-tables.js Github

copy

Full Screen

...97 d]);98 builder.addExportOfKind("table", kExternalTable, 0);99 let m1 = new WebAssembly.Module(builder.toBuffer());100 var builder = new WasmModuleBuilder();101 builder.addImportedTable("r", "table", kTableSize, kTableSize);102 builder.addFunction("main", kSig_i_ii)103 .addBody([104 kExprI32Const, 33, // --105 kExprGetLocal, 0, // --106 kExprGetLocal, 1, // --107 kExprCallIndirect, 0, kTableZero]) // --108 .exportAs("main");109 let m2 = new WebAssembly.Module(builder.toBuffer());110 // Run 5 trials at different table bases.111 for (let i = 0; i < 5; i++) {112 print(" base = " + i);113 let i1 = new WebAssembly.Instance(m1, {q: {base: i, js_div: js_div}});114 let table = i1.exports.table;115 assertEquals(10, table.length);116 let i2 = new WebAssembly.Instance(m2, {r: {table: table}});117 let main = i2.exports.main;118 for (var j = 0; j < i; j++) {119 assertThrows(() => main(0, j));120 assertSame(null, table.get(j));121 }122 // mul123 assertEquals("function", typeof table.get(i+0));124 assertEquals(0, main(0, i+0));125 assertEquals(66, main(2, i+0));126 // add127 assertEquals("function", typeof table.get(i+1));128 assertEquals(33, main(0, i+1));129 assertEquals(38, main(5, i+1));130 // sub131 assertEquals("function", typeof table.get(i+2));132 assertEquals(32, main(1, i+2));133 assertEquals(28, main(5, i+2));134 // div135 assertEquals("function", typeof table.get(i+3));136 assertEquals(8, main(4, i+3));137 assertEquals(3, main(11, i+3));138 for (var j = i + 4; j < (kTableSize + 5); j++) {139 assertThrows(x => main(0, j));140 if (j < kTableSize) assertSame(null, table.get(j));141 }142 }143})();144(function ImportedTableTest() {145 let kTableSize = 10;146 print("ManualTableTest...");147 var builder = new WasmModuleBuilder();148 let d = builder.addImport("q", "js_div", kSig_i_ii);149 builder.addImportedTable("q", "table", kTableSize, kTableSize);150 let g = builder.addImportedGlobal("q", "base", kWasmI32);151 let f = AddFunctions(builder);152 builder.addFunctionTableInit(g, true, [f.mul.index, f.add.index,153 f.sub.index,154 d]);155 builder.addFunction("main", kSig_i_ii)156 .addBody([157 kExprI32Const, 55, // --158 kExprGetLocal, 0, // --159 kExprGetLocal, 1, // --160 kExprCallIndirect, 0, kTableZero]) // --161 .exportAs("main");162 let m2 = new WebAssembly.Module(builder.toBuffer());163 // Run 5 trials at different table bases.164 for (let i = 0; i < 5; i++) {165 print(" base = " + i);166 let table = new WebAssembly.Table({element: "anyfunc",167 initial: kTableSize,168 maximum: kTableSize});169 assertEquals(10, table.length);170 let i2 = new WebAssembly.Instance(m2, {q: {base: i, table: table,171 js_div: js_div}});172 let main = i2.exports.main;173 for (var j = 0; j < i; j++) {174 assertThrows(() => main(0, j));175 assertSame(null, table.get(j));176 }177 // mul178 assertEquals("function", typeof table.get(i+0));179 assertEquals(0, main(0, i+0));180 assertEquals(110, main(2, i+0));181 // add182 assertEquals("function", typeof table.get(i+1));183 assertEquals(55, main(0, i+1));184 assertEquals(60, main(5, i+1));185 // sub186 assertEquals("function", typeof table.get(i+2));187 assertEquals(54, main(1, i+2));188 assertEquals(50, main(5, i+2));189 // div190 assertEquals("function", typeof table.get(i+3));191 assertEquals(13, main(4, i+3));192 assertEquals(5, main(11, i+3));193 for (var j = i + 4; j < (kTableSize + 5); j++) {194 assertThrows(x => main(0, j));195 if (j < kTableSize) assertSame(null, table.get(j));196 }197 }198})();199(function CumulativeTest() {200 print("CumulativeTest...");201 let kTableSize = 10;202 let table = new WebAssembly.Table(203 {element: "anyfunc", initial: kTableSize, maximum: kTableSize});204 var builder = new WasmModuleBuilder();205 builder.addImportedTable("x", "table", kTableSize, kTableSize);206 let g = builder.addImportedGlobal("x", "base", kWasmI32);207 let sig_index = builder.addType(kSig_i_v);208 builder.addFunction("g", sig_index)209 .addBody([210 kExprGetGlobal, g211 ]);212 builder.addFunction("main", kSig_i_ii)213 .addBody([214 kExprGetLocal, 0,215 kExprCallIndirect, sig_index, kTableZero]) // --216 .exportAs("main");217 builder.addFunctionTableInit(g, true, [g]);218 let module = new WebAssembly.Module(builder.toBuffer());219 for (var i = 0; i < kTableSize; i++) {220 print(" base = " + i);221 let instance = new WebAssembly.Instance(module, {x: {base: i, table: table}});222 for (var j = 0; j < kTableSize; j++) {223 let func = table.get(j);224 if (j > i) {225 assertSame(null, func);226 assertTraps(kTrapFuncSigMismatch, () => instance.exports.main(j));227 } else {228 assertEquals("function", typeof func);229 assertEquals(j, func());230 assertEquals(j, instance.exports.main(j));231 }232 }233 }234})();235(function TwoWayTest() {236 print("TwoWayTest...");237 let kTableSize = 3;238 // Module {m1} defines the table and exports it.239 var builder = new WasmModuleBuilder();240 builder.addType(kSig_i_i);241 builder.addType(kSig_i_ii);242 var sig_index1 = builder.addType(kSig_i_v);243 var f1 = builder.addFunction("f1", sig_index1)244 .addBody([kExprI32Const, 11]);245 builder.addFunction("main", kSig_i_ii)246 .addBody([247 kExprGetLocal, 0, // --248 kExprCallIndirect, sig_index1, kTableZero]) // --249 .exportAs("main");250 builder.setFunctionTableLength(kTableSize);251 builder.addFunctionTableInit(0, false, [f1.index]);252 builder.addExportOfKind("table", kExternalTable, 0);253 var m1 = new WebAssembly.Module(builder.toBuffer());254 // Module {m2} imports the table and adds {f2}.255 var builder = new WasmModuleBuilder();256 builder.addType(kSig_i_ii);257 var sig_index2 = builder.addType(kSig_i_v);258 var f2 = builder.addFunction("f2", sig_index2)259 .addBody([kExprI32Const, 22]);260 builder.addFunction("main", kSig_i_ii)261 .addBody([262 kExprGetLocal, 0, // --263 kExprCallIndirect, sig_index2, kTableZero]) // --264 .exportAs("main");265 builder.addImportedTable("z", "table", kTableSize, kTableSize);266 builder.addFunctionTableInit(1, false, [f2.index], true);267 var m2 = new WebAssembly.Module(builder.toBuffer());268 assertFalse(sig_index1 == sig_index2);269 var i1 = new WebAssembly.Instance(m1);270 var i2 = new WebAssembly.Instance(m2, {z: {table: i1.exports.table}});271 assertEquals(11, i1.exports.main(0));272 assertEquals(11, i2.exports.main(0));273 assertEquals(22, i1.exports.main(1));274 assertEquals(22, i2.exports.main(1));275 assertThrows(() => i1.exports.main(2));276 assertThrows(() => i2.exports.main(2));277 assertThrows(() => i1.exports.main(3));278 assertThrows(() => i2.exports.main(3));279})();280(function MismatchedTableSize() {281 print("MismatchedTableSize...");282 let kTableSize = 5;283 for (var expsize = 1; expsize < 4; expsize++) {284 for (var impsize = 1; impsize < 4; impsize++) {285 print(" expsize = " + expsize + ", impsize = " + impsize);286 var builder = new WasmModuleBuilder();287 builder.setFunctionTableLength(expsize);288 builder.addExportOfKind("expfoo", kExternalTable, 0);289 let m1 = new WebAssembly.Module(builder.toBuffer());290 var builder = new WasmModuleBuilder();291 builder.addImportedTable("y", "impfoo", impsize, impsize);292 let m2 = new WebAssembly.Module(builder.toBuffer());293 var i1 = new WebAssembly.Instance(m1);294 // TODO(titzer): v8 currently requires import table size to match295 // export table size.296 var ffi = {y: {impfoo: i1.exports.expfoo}};297 if (expsize == impsize) {298 var i2 = new WebAssembly.Instance(m2, ffi);299 } else {300 assertThrows(() => new WebAssembly.Instance(m2, ffi));301 }302 }303 }304})();305(function TableGrowBoundsCheck() {306 print("TableGrowBoundsCheck");307 var kMaxSize = 30, kInitSize = 5;308 let table = new WebAssembly.Table({element: "anyfunc",309 initial: kInitSize, maximum: kMaxSize});310 var builder = new WasmModuleBuilder();311 builder.addImportedTable("x", "table", kInitSize, kMaxSize);312 let module = new WebAssembly.Module(builder.toBuffer());313 let instance = new WebAssembly.Instance(module, {x: {base: 1, table: table}});314 for(var i = kInitSize; i < kMaxSize; i+=5) {315 assertEquals(i, table.length);316 for (var j = 0; j < i; j++) table.set(j, null);317 for (var j = 0; j < i; j++) assertEquals(null, table.get(j));318 assertThrows(() => table.set(i, null));319 assertThrows(() => table.get(i));320 assertEquals(i, table.grow(5));321 }322 assertEquals(30, table.length);323 assertThrows(() => table.grow(1));324 assertThrows(() => table.set(kMaxSize, null));325 assertThrows(() => table.get(kMaxSize));326})();327(function CumulativeGrowTest() {328 print("CumulativeGrowTest...");329 let table = new WebAssembly.Table({330 element: "anyfunc", initial: 10, maximum: 30});331 var builder = new WasmModuleBuilder();332 builder.addImportedTable("x", "table", 10, 30);333 let g = builder.addImportedGlobal("x", "base", kWasmI32);334 let sig_index = builder.addType(kSig_i_v);335 builder.addFunction("g", sig_index)336 .addBody([337 kExprGetGlobal, g338 ]);339 builder.addFunction("main", kSig_i_ii)340 .addBody([341 kExprGetLocal, 0,342 kExprCallIndirect, sig_index, kTableZero]) // --343 .exportAs("main");344 builder.addFunctionTableInit(g, true, [g]);345 let module = new WebAssembly.Module(builder.toBuffer());346 var instances = [];347 for (var i = 0; i < 10; i++) {348 print(" base = " + i);349 instances.push(new WebAssembly.Instance(350 module, {x: {base: i, table: table}}));351 }352 for (var j = 0; j < 10; j++) {353 let func = table.get(j);354 assertEquals("function", typeof func);355 assertEquals(j, func());356 assertEquals(j, instances[j].exports.main(j));357 }358 assertEquals(10, table.grow(10));359 // Verify that grow does not alter function behaviors360 for (var j = 0; j < 10; j++) {361 let func = table.get(j);362 assertEquals("function", typeof func);363 assertEquals(j, func());364 assertEquals(j, instances[j].exports.main(j));365 }366 let new_builder = new WasmModuleBuilder();367 new_builder.addExport("wasm", new_builder.addFunction("", kSig_v_v).addBody([]));368 new_builder.addImportedTable("x", "table", 20, 30);369 let new_module = new WebAssembly.Module(new_builder.toBuffer());370 let instance = new WebAssembly.Instance(new_module, {x: {table: table}});371 let new_func = instance.exports.wasm;372 for (var j = 10; j < 20; j++) {373 table.set(j, new_func);374 let func = table.get(j);375 assertEquals("function", typeof func);376 assertSame(new_func, table.get(j));377 }378 assertThrows(() => table.grow(11));379})();380(function TestImportTooLarge() {381 print("TestImportTooLarge...");382 let builder = new WasmModuleBuilder();383 builder.addImportedTable("t", "t", 1, 2);384 // initial size is too large385 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(386 {element: "anyfunc", initial: 3, maximum: 3})}}));387 // maximum size is too large388 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(389 {element: "anyfunc", initial: 1, maximum: 4})}}));390 // no maximum391 assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(392 {element: "anyfunc", initial: 1})}}));393})();394(function TableImportLargerThanCompiled() {395 print("TableImportLargerThanCompiled...");396 var kMaxSize = 30, kInitSize = 5;397 var builder = new WasmModuleBuilder();398 builder.addImportedTable("x", "table", 1, 35);399 let table = new WebAssembly.Table({element: "anyfunc",400 initial: kInitSize, maximum: kMaxSize});401 let module = new WebAssembly.Module(builder.toBuffer());402 let instance = new WebAssembly.Instance(module, {x: {base: 1, table: table}});403 for (var i = 0; i < kInitSize; ++i) table.set(i, null);404 for (var i = 0; i < kInitSize; ++i) assertEquals(null, table.get(i));405 assertThrows(() => table.set(kInitSize, null));406})();407(function ModulesShareTableAndGrow() {408 print("ModulesShareTableAndGrow...");409 let module1 = (() => {410 let builder = new WasmModuleBuilder();411 builder.addImportedTable("x", "table", 1, 35);412 return new WebAssembly.Module(builder.toBuffer());413 })();414 let module2 = (() => {415 let builder = new WasmModuleBuilder();416 builder.addImportedTable("x", "table", 2, 40);417 return new WebAssembly.Module(builder.toBuffer());418 })();419 var kMaxSize = 30, kInitSize = 5;420 let table = new WebAssembly.Table({element: "anyfunc",421 initial: kInitSize, maximum: kMaxSize});422 let instance1 = new WebAssembly.Instance(423 module1, {x: {base: 1, table: table}});424 let instance2 = new WebAssembly.Instance(425 module2, {x: {base: 1, table: table}});426 for (var i = 0; i < kInitSize; ++i) table.set(i, null);427 for (var i = 0; i < kInitSize; ++i) assertEquals(null, table.get(i));428 assertThrows(() => table.set(kInitSize, null));429 assertEquals(kInitSize, table.grow(5));430 for (var i = 0; i < 2*kInitSize; ++i) table.set(i, null);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptable = require('wptable');2var table = new wptable();3var table2 = new wptable();4var table3 = new wptable();5var table4 = new wptable();6var table5 = new wptable();7var table6 = new wptable();8var table7 = new wptable();9var table8 = new wptable();10var table9 = new wptable();11var table10 = new wptable();12var table11 = new wptable();13var table12 = new wptable();14var table13 = new wptable();15var table14 = new wptable();16var table15 = new wptable();17var table16 = new wptable();18var table17 = new wptable();19var table18 = new wptable();20var table19 = new wptable();21var table20 = new wptable();22var table21 = new wptable();23var table22 = new wptable();24var table23 = new wptable();25var table24 = new wptable();26var table25 = new wptable();27var table26 = new wptable();28var table27 = new wptable();29var table28 = new wptable();30var table29 = new wptable();31var table30 = new wptable();32var table31 = new wptable();33var table32 = new wptable();34var table33 = new wptable();35var table34 = new wptable();36var table35 = new wptable();37var table36 = new wptable();38var table37 = new wptable();39var table38 = new wptable();40var table39 = new wptable();41var table40 = new wptable();42var table41 = new wptable();43var table42 = new wptable();44var table43 = new wptable();45var table44 = new wptable();46var table45 = new wptable();47var table46 = new wptable();48var table47 = new wptable();49var table48 = new wptable();50var table49 = new wptable();51var table50 = new wptable();52var table51 = new wptable();53var table52 = new wptable();54var table53 = new wptable();55var table54 = new wptable();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.addImportedTable(url, options, function(err, data) {6 if (err) {7 console.log(err);8 }9 else {10 console.log(data);11 }12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15var options = {16};17wpt.addScript(url, options, function(err, data) {18 if (err) {19 console.log(err);20 }21 else {22 console.log(data);23 }24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getLocations(function(err, data) {28 if (err) {29 console.log(err);30 }31 else {32 console.log(data);33 }34});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var fs = require('fs');3var csv = require('csv');4var data = fs.readFileSync('test.csv', 'utf8');5csv().from.string(data, {columns: true}).to.array(function(data){6 wpt.addImportedTable(data);7});8var wpt = require('wpt');9var fs = require('fs');10var csv = require('csv');11var data = fs.readFileSync('test.csv', 'utf8');12csv().from.string(data, {columns: true}).to.array(function(data){13 wpt.addImportedTable(data);14});15var wpt = require('wpt');16var fs = require('fs');17var csv = require('csv');18var data = fs.readFileSync('test.csv', 'utf8');19csv().from.string(data, {columns: true}).to.array(function(data){20 wpt.addImportedTable(data);21});22var wpt = require('wpt');23var fs = require('fs');24var csv = require('csv');25var data = fs.readFileSync('test.csv', 'utf8');26csv().from.string(data, {columns: true}).to.array(function(data){27 wpt.addImportedTable(data);28});29var wpt = require('wpt');30var fs = require('fs');31var csv = require('csv');32var data = fs.readFileSync('test.csv', 'utf8');33csv().from.string(data, {columns: true}).to.array(function(data){34 wpt.addImportedTable(data);35});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var table = require('wpt').table;3var importedTable = wpt.addImportedTable(table);4var importedTable = table.addImportedTable(table);5var wpt = require('wpt');6var importedTable = wpt.addImportedTable(wpt.table);7var importedTable = wpt.table.addImportedTable(wpt.table);8Which of the following are valid ways to import the wpt module?

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools.page('India');3wp.addImportedTable('India', 'India', 'India');4wp.get(function(err, resp) {5 if (err) {6 console.log(err);7 }8 else {9 console.log(resp);10 }11});12{ pageid: 1269750,13 [ { contentformat: 'text/x-wiki',14 '*': 'India' } ],15 imported_tables: 16 [ { title: 'India',17 content: 'India' } ] }

Full Screen

Using AI Code Generation

copy

Full Screen

1var WPTable = require('wptable');2var wptable = new WPTable();3wptable.addImportedTable('path/to/file.csv');4console.log(wptable.toString());5wptable.saveToFile('path/to/file.txt');6wptable.saveToFile('path/to/file.html');7wptable.saveToFile('path/to/file.json');8wptable.saveToFile('path/to/file.xml');9wptable.saveToFile('path/to/file.csv');10wptable.saveToFile('path/to/file.tsv');11wptable.saveToFile('path/to/file.xlsx');12wptable.saveToFile('path/to/file.ods');13wptable.saveToFile('path/to/file.dbf');14wptable.saveToFile('path/to/file.xls');15wptable.saveToFile('path/to/file.sxc');16wptable.saveToFile('path/to/file.dif');17wptable.saveToFile('path/to/file.sql');18wptable.saveToFile('path/to/file.php');19wptable.saveToFile('path/to/file.yaml');20wptable.saveToFile('path/to/file.yml');21wptable.saveToFile('path/to/file.psv');22wptable.saveToFile('path/to/file.ini');23wptable.saveToFile('path/to/file.properties');24wptable.saveToFile('path/to/file.toml');25wptable.saveToFile('path/to/file.rss');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptable = require('wptable');2var wp = new wptable();3wp.addImportedTable('test', 'test.js', 'test');4wp.test('test', 'test.js', 'test');5var wptable = require('wptable');6var wp = new wptable();7wp.addImportedTable('test', 'test.js', 'test');8wp.test('test', 'test.js', 'test');9var wptable = require('wptable');10var wp = new wptable();11wp.addImportedTable('test', 'test.js', 'test');12wp.test('test', 'test.js', 'test');13var wptable = require('wptable');14var wp = new wptable();15wp.addImportedTable('test', 'test.js', 'test');16wp.test('test', 'test.js', 'test');17var wptable = require('wptable');18var wp = new wptable();19wp.addImportedTable('test', 'test.js', 'test');20wp.test('test', 'test.js', 'test');21var wptable = require('wptable');22var wp = new wptable();23wp.addImportedTable('test', 'test.js', 'test');24wp.test('test', 'test.js', 'test');25var wptable = require('wptable');26var wp = new wptable();27wp.addImportedTable('test', 'test.js', 'test');28wp.test('test', 'test.js', 'test');29var wptable = require('wptable');30var wp = new wptable();31wp.addImportedTable('test', 'test.js', 'test');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful