Index: src/wasm/wasm-interpreter.cc |
diff --git a/src/wasm/wasm-interpreter.cc b/src/wasm/wasm-interpreter.cc |
index 4d2d994e459db356d3572400f6636f42d4bf4e5d..77099cb51ef0f0d193e97c7cff5200f1561213e9 100644 |
--- a/src/wasm/wasm-interpreter.cc |
+++ b/src/wasm/wasm-interpreter.cc |
@@ -915,9 +915,11 @@ class CodeMap { |
return Preprocess(&interpreter_code_[function_index]); |
} |
- InterpreterCode* GetIndirectCode(uint32_t indirect_index) { |
- if (indirect_index >= module_->function_table.size()) return nullptr; |
- uint32_t index = module_->function_table[indirect_index]; |
+ InterpreterCode* GetIndirectCode(uint32_t table_index, uint32_t entry_index) { |
+ if (table_index >= module_->function_table.size()) return nullptr; |
+ const WasmTable* table = &module_->function_table[table_index]; |
+ if (entry_index >= table->values.size()) return nullptr; |
+ uint32_t index = table->values[entry_index]; |
if (index >= interpreter_code_.size()) return nullptr; |
return GetCode(index); |
} |
@@ -1383,14 +1385,12 @@ class ThreadImpl : public WasmInterpreter::Thread { |
CallIndirectOperand operand(&decoder, code->at(pc)); |
size_t index = stack_.size() - operand.arity - 1; |
DCHECK_LT(index, stack_.size()); |
- uint32_t table_index = stack_[index].to<uint32_t>(); |
- if (table_index >= module()->function_table.size()) { |
+ uint32_t entry_index = stack_[index].to<uint32_t>(); |
+ // Assume only one table for now. |
ahaas
2016/07/25 19:23:44
I think we should have a DCHECK for this assumptio
ddchen
2016/07/25 22:17:36
Done.
|
+ InterpreterCode* target = codemap()->GetIndirectCode(0, entry_index); |
+ if (!target) { |
return DoTrap(kTrapFuncInvalid, pc); |
- } |
- uint16_t function_index = module()->function_table[table_index]; |
- InterpreterCode* target = codemap()->GetCode(function_index); |
- DCHECK(target); |
- if (target->function->sig_index != operand.index) { |
+ } else if (target->function->sig_index != operand.index) { |
return DoTrap(kTrapFuncSigMismatch, pc); |
} |