[wasm] check that there is at most 1 table

R=titzer@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2643783002
Cr-Commit-Position: refs/heads/master@{#42465}
This commit is contained in:
rossberg 2017-01-18 07:36:22 -08:00 committed by Commit bot
parent c69a40fc57
commit d62914f6e9
3 changed files with 22 additions and 12 deletions

View File

@ -304,6 +304,7 @@ class ModuleDecoder : public Decoder {
}
case kExternalTable: {
// ===== Imported table ==========================================
if (!AddTable(module)) break;
import->index =
static_cast<uint32_t>(module->function_tables.size());
module->function_tables.push_back({0, 0, false,
@ -319,11 +320,11 @@ class ModuleDecoder : public Decoder {
}
case kExternalMemory: {
// ===== Imported memory =========================================
if (!AddMemory(module)) break;
consume_resizable_limits(
"memory", "pages", kV8MaxWasmMemoryPages,
&module->min_mem_pages, &module->has_max_mem,
kSpecMaxWasmMemoryPages, &module->max_mem_pages);
SetHasMemory(module);
break;
}
case kExternalGlobal: {
@ -373,12 +374,11 @@ class ModuleDecoder : public Decoder {
// ===== Table section ===================================================
if (section_iter.section_code() == kTableSectionCode) {
uint32_t table_count = consume_count("table count", kV8MaxWasmTables);
if (module->function_tables.size() < 1) {
module->function_tables.push_back({0, 0, false, std::vector<int32_t>(),
false, false, SignatureMap()});
}
for (uint32_t i = 0; ok() && i < table_count; i++) {
if (!AddTable(module)) break;
module->function_tables.push_back({0, 0, false, std::vector<int32_t>(),
false, false, SignatureMap()});
WasmIndirectFunctionTable* table = &module->function_tables.back();
expect_u8("table type", kWasmAnyFunctionTypeForm);
consume_resizable_limits(
@ -393,12 +393,12 @@ class ModuleDecoder : public Decoder {
uint32_t memory_count = consume_count("memory count", kV8MaxWasmMemories);
for (uint32_t i = 0; ok() && i < memory_count; i++) {
if (!AddMemory(module)) break;
consume_resizable_limits("memory", "pages", kV8MaxWasmMemoryPages,
&module->min_mem_pages, &module->has_max_mem,
kSpecMaxWasmMemoryPages,
&module->max_mem_pages);
}
SetHasMemory(module);
section_iter.advance();
}
@ -683,11 +683,22 @@ class ModuleDecoder : public Decoder {
uint32_t off(const byte* ptr) { return static_cast<uint32_t>(ptr - start_); }
void SetHasMemory(WasmModule* module) {
bool AddTable(WasmModule* module) {
if (module->function_tables.size() > 0) {
error("At most one table is supported");
return false;
} else {
return true;
}
}
bool AddMemory(WasmModule* module) {
if (module->has_memory) {
error("At most one memory object is supported");
error("At most one memory is supported");
return false;
} else {
module->has_memory = true;
return true;
}
}

View File

@ -319,9 +319,8 @@ function js_div(a, b) { return (a / b) | 0; }
kExprCallIndirect, sig_index2, kTableZero]) // --
.exportAs("main");
builder.setFunctionTableLength(kTableSize);
builder.addFunctionTableInit(1, false, [f2.index]);
builder.addImportedTable("z", "table", kTableSize, kTableSize);
builder.addFunctionTableInit(1, false, [f2.index], true);
var m2 = new WebAssembly.Module(builder.toBuffer());

View File

@ -227,12 +227,12 @@ class WasmModuleBuilder {
this.exports.push({name: name, kind: kExternalMemory, index: 0});
}
addFunctionTableInit(base, is_global, array) {
addFunctionTableInit(base, is_global, array, is_import = false) {
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) {
if (length > this.function_table_length && !is_import) {
this.function_table_length = length;
}
}