Commit 47cdcc4a authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Passive data segments don't need a memory

This CL fixes a spec violation that new spec tests uncovered.

R=thibaudm@chromium.org
CC=ecmziegler@chromium.org

Change-Id: I1004eca9e4f98a0960795907fea0ab263c907938
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2122022Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66874}
parent dbb9f510
......@@ -958,10 +958,6 @@ class ModuleDecoderImpl : public Decoder {
module_->data_segments.reserve(data_segments_count);
for (uint32_t i = 0; ok() && i < data_segments_count; ++i) {
const byte* pos = pc();
if (!module_->has_memory) {
error("cannot load data without memory");
break;
}
TRACE("DecodeDataSegment[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
......@@ -971,10 +967,16 @@ class ModuleDecoderImpl : public Decoder {
consume_data_segment_header(&is_active, &memory_index, &dest_addr);
if (failed()) break;
if (is_active && memory_index != 0) {
if (is_active) {
if (!module_->has_memory) {
error("cannot load data without memory");
break;
}
if (memory_index != 0) {
errorf(pos, "illegal memory index %u != 0", memory_index);
break;
}
}
uint32_t source_length = consume_u32v("source size");
uint32_t source_offset = pc_offset();
......
......@@ -214,3 +214,11 @@ function getMemoryFill(mem) {
assertEquals(0, view[0]);
})();
(function TestPassiveDataSegmentNoMemory() {
const builder = new WasmModuleBuilder();
builder.addPassiveDataSegment([0, 1, 2]);
// Should not throw.
builder.instantiate();
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment