Index: src/wasm/wasm-module.cc |
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
index 179af57ac6d626c06d0fc315d2aa38826b37892b..9e76c2005b750311dc23c933d0efc40fb78842fc 100644 |
--- a/src/wasm/wasm-module.cc |
+++ b/src/wasm/wasm-module.cc |
@@ -1149,6 +1149,8 @@ class WasmInstanceBuilder { |
RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start, |
old_mem_size, mem_size); |
compiled_module_->set_memory(memory_); |
+ } else if (!CheckDataSegmentsAreEmpty()) { |
titzer
2016/11/09 17:20:31
Why not just call LoadDataSegments(nullptr, 0)?
ahaas
2016/11/10 10:26:25
Done. I also fixed another issue with non-empty me
|
+ thrower_->TypeError("data segment does not fit"); |
} |
//-------------------------------------------------------------------------- |
@@ -1345,7 +1347,7 @@ class WasmInstanceBuilder { |
return result; |
} |
- uint32_t EvalUint32InitExpr(WasmInitExpr& expr) { |
+ uint32_t EvalUint32InitExpr(const WasmInitExpr& expr) { |
switch (expr.kind) { |
case WasmInitExpr::kI32Const: |
return expr.val.i32_const; |
@@ -1362,12 +1364,12 @@ class WasmInstanceBuilder { |
// Load data segments into the memory. |
void LoadDataSegments(Address mem_addr, size_t mem_size) { |
Handle<SeqOneByteString> module_bytes = compiled_module_->module_bytes(); |
- for (auto segment : module_->data_segments) { |
+ for (const WasmDataSegment& segment : module_->data_segments) { |
uint32_t dest_offset = EvalUint32InitExpr(segment.dest_addr); |
uint32_t source_size = segment.source_size; |
if (dest_offset >= mem_size || source_size >= mem_size || |
dest_offset > (mem_size - source_size)) { |
- thrower_->RangeError( |
+ thrower_->TypeError( |
"data segment (start = %u, size = %u) does not fit into memory " |
"(size = %zu)", |
dest_offset, source_size, mem_size); |
@@ -1380,6 +1382,16 @@ class WasmInstanceBuilder { |
} |
} |
+ // Returns true if all segments are empty and write to address 0. |
+ bool CheckDataSegmentsAreEmpty() { |
+ for (const WasmDataSegment& segment : module_->data_segments) { |
+ if (segment.source_size > 0) { |
+ return false; |
+ } |
+ } |
+ return true; |
+ } |
+ |
void WriteGlobalValue(WasmGlobal& global, Handle<Object> value) { |
double num = 0; |
if (value->IsSmi()) { |