| Index: test/mjsunit/wasm/wasm-module-builder.js
|
| diff --git a/test/mjsunit/wasm/wasm-module-builder.js b/test/mjsunit/wasm/wasm-module-builder.js
|
| index 5c5f6e205b7723a30549488a50d89a148f18d781..e3311c1cb620f8d798b9a6a8120e0c189c295768 100644
|
| --- a/test/mjsunit/wasm/wasm-module-builder.js
|
| +++ b/test/mjsunit/wasm/wasm-module-builder.js
|
| @@ -132,10 +132,11 @@ class WasmModuleBuilder {
|
| this.exports = [];
|
| this.globals = [];
|
| this.functions = [];
|
| - this.table = [];
|
| + this.function_table = [];
|
| + this.function_table_length = 0;
|
| + this.function_table_inits = [];
|
| this.segments = [];
|
| this.explicit = [];
|
| - this.pad = null;
|
| this.num_imported_funcs = 0;
|
| this.num_imported_globals = 0;
|
| return this;
|
| @@ -151,11 +152,6 @@ class WasmModuleBuilder {
|
| return this;
|
| }
|
|
|
| - addPadFunctionTable(size) {
|
| - this.pad = size;
|
| - return this;
|
| - }
|
| -
|
| addExplicitSection(bytes) {
|
| this.explicit.push(bytes);
|
| return this;
|
| @@ -220,8 +216,21 @@ class WasmModuleBuilder {
|
| this.exports.push({name: name, kind: kExternalMemory, index: 0});
|
| }
|
|
|
| + addFunctionTableInit(base, is_global, array) {
|
| + this.function_table_inits.push({base: base, is_global: is_global, array: array});
|
| + if (!is_global) {
|
| + var length = base + array.length;
|
| + if (length > this.function_table_length) this.function_table_length = length;
|
| + }
|
| + return this;
|
| + }
|
| +
|
| appendToTable(array) {
|
| - this.table.push(...array);
|
| + return this.addFunctionTableInit(this.function_table.length, false, array);
|
| + }
|
| +
|
| + setFunctionTableLength(length) {
|
| + this.function_table_length = length;
|
| return this;
|
| }
|
|
|
| @@ -292,15 +301,15 @@ class WasmModuleBuilder {
|
| });
|
| }
|
|
|
| - // Add table.
|
| - if (wasm.table.length > 0) {
|
| + // Add function_table.
|
| + if (wasm.function_table_length > 0) {
|
| if (debug) print("emitting table @ " + binary.length);
|
| binary.emit_section(kTableSectionCode, section => {
|
| section.emit_u8(1); // one table entry
|
| section.emit_u8(kWasmAnyFunctionTypeForm);
|
| section.emit_u8(1);
|
| - section.emit_u32v(wasm.table.length);
|
| - section.emit_u32v(wasm.table.length);
|
| + section.emit_u32v(wasm.function_table_length);
|
| + section.emit_u32v(wasm.function_table_length);
|
| });
|
| }
|
|
|
| @@ -394,17 +403,25 @@ class WasmModuleBuilder {
|
| }
|
|
|
| // Add table elements.
|
| - if (wasm.table.length > 0) {
|
| + if (wasm.function_table_inits.length > 0) {
|
| if (debug) print("emitting table @ " + binary.length);
|
| binary.emit_section(kElementSectionCode, section => {
|
| - section.emit_u8(1);
|
| + var inits = wasm.function_table_inits;
|
| + section.emit_u32v(inits.length);
|
| section.emit_u8(0); // table index
|
| - section.emit_u8(kExprI32Const);
|
| - section.emit_u8(0);
|
| - section.emit_u8(kExprEnd);
|
| - section.emit_u32v(wasm.table.length);
|
| - for (let index of wasm.table) {
|
| - section.emit_u32v(index);
|
| +
|
| + for (let init of inits) {
|
| + if (init.is_global) {
|
| + section.emit_u8(kExprGetGlobal);
|
| + } else {
|
| + section.emit_u8(kExprI32Const);
|
| + }
|
| + section.emit_u32v(init.base);
|
| + section.emit_u8(kExprEnd);
|
| + section.emit_u32v(init.array.length);
|
| + for (let index of init.array) {
|
| + section.emit_u32v(index);
|
| + }
|
| }
|
| });
|
| }
|
|
|