| Index: src/wasm/module-decoder.cc
|
| diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
|
| index ffa24a41b826872a6630708ad945dfd787c53a9f..ad2124ed98a776beb53395ca8c71601c1e57bb10 100644
|
| --- a/src/wasm/module-decoder.cc
|
| +++ b/src/wasm/module-decoder.cc
|
| @@ -257,38 +257,19 @@ class ModuleDecoder : public Decoder {
|
| }
|
| break;
|
| }
|
| - case WasmSection::Code::FunctionTablePad: {
|
| - if (!FLAG_wasm_jit_prototype) {
|
| - error("FunctionTablePad section without jiting enabled");
|
| - }
|
| - // An indirect function table requires functions first.
|
| - module->indirect_table_size = consume_u32v("indirect entry count");
|
| - if (module->indirect_table_size > 0 &&
|
| - module->indirect_table_size < module->function_table.size()) {
|
| - error("more predefined indirect entries than table can hold");
|
| - }
|
| - break;
|
| - }
|
| case WasmSection::Code::FunctionTable: {
|
| // An indirect function table requires functions first.
|
| CheckForFunctions(module, section);
|
| - uint32_t function_table_count = consume_u32v("function table count");
|
| - module->function_table.reserve(SafeReserve(function_table_count));
|
| + // Assume only one table for now.
|
| + static const uint32_t kSupportedTableCount = 1;
|
| + module->function_tables.reserve(SafeReserve(kSupportedTableCount));
|
| // Decode function table.
|
| - for (uint32_t i = 0; i < function_table_count; ++i) {
|
| + for (uint32_t i = 0; i < kSupportedTableCount; ++i) {
|
| if (failed()) break;
|
| TRACE("DecodeFunctionTable[%d] module+%d\n", i,
|
| static_cast<int>(pc_ - start_));
|
| - uint16_t index = consume_u32v();
|
| - if (index >= module->functions.size()) {
|
| - error(pc_ - 2, "invalid function index");
|
| - break;
|
| - }
|
| - module->function_table.push_back(index);
|
| - }
|
| - if (module->indirect_table_size > 0 &&
|
| - module->indirect_table_size < module->function_table.size()) {
|
| - error("more predefined indirect entries than table can hold");
|
| + module->function_tables.push_back({0, 0, std::vector<uint16_t>()});
|
| + DecodeFunctionTableInModule(module, &module->function_tables[i]);
|
| }
|
| break;
|
| }
|
| @@ -520,6 +501,27 @@ class ModuleDecoder : public Decoder {
|
| consume_bytes(segment->source_size);
|
| }
|
|
|
| + // Decodes a single function table inside a module starting at {pc_}.
|
| + void DecodeFunctionTableInModule(WasmModule* module,
|
| + WasmIndirectFunctionTable* table) {
|
| + table->size = consume_u32v("function table entry count");
|
| + table->max_size = FLAG_wasm_jit_prototype ? consume_u32v() : table->size;
|
| +
|
| + if ((!FLAG_wasm_jit_prototype && table->max_size != table->size) ||
|
| + (FLAG_wasm_jit_prototype && table->max_size < table->size)) {
|
| + error("invalid table maximum size");
|
| + }
|
| +
|
| + for (uint32_t i = 0; i < table->size; ++i) {
|
| + uint16_t index = consume_u32v();
|
| + if (index >= module->functions.size()) {
|
| + error(pc_ - sizeof(index), "invalid function index");
|
| + break;
|
| + }
|
| + table->values.push_back(index);
|
| + }
|
| + }
|
| +
|
| // Calculate individual global offsets and total size of globals table.
|
| void CalculateGlobalsOffsets(WasmModule* module) {
|
| uint32_t offset = 0;
|
|
|