bool Module::instantiateTable(JSContext* cx, HandleWasmTableObject tableImport, SharedTableVector* tables) const { for (const TableDesc& tableDesc : metadata_->tables) { SharedTable table; if (tableImport) { table = &tableImport->table(); if (table->length() < tableDesc.initial || table->length() > tableDesc.maximum) { JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_IMP_SIZE, "Table"); return false; } } else { table = Table::create(cx, tableDesc.kind, tableDesc.initial); if (!table) return false; } if (!tables->emplaceBack(table)) { ReportOutOfMemory(cx); return false; } } return true; }
bool Module::instantiateTable(JSContext* cx, const CodeSegment& cs, SharedTableVector* tables) const { for (const TableDesc& tableDesc : metadata_->tables) { SharedTable table = Table::create(cx, tableDesc.kind, tableDesc.length); if (!table || !tables->emplaceBack(table)) return false; for (size_t i = 0; i < table->length(); i++) table->array()[i] = cs.badIndirectCallCode(); } for (const ElemSegment& seg : elemSegments_) { SharedTable& table = (*tables)[seg.tableIndex]; MOZ_ASSERT(seg.offset + seg.elems.length() <= table->length()); for (size_t i = 0; i < seg.elems.length(); i++) table->array()[seg.offset + i] = cs.code() + seg.elems[i]; } return true; }