OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/wasm/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
6 #include "src/wasm/function-body-decoder-impl.h" | 6 #include "src/wasm/function-body-decoder-impl.h" |
7 | 7 |
8 #include "src/base/functional.h" | 8 #include "src/base/functional.h" |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/counters.h" | 10 #include "src/counters.h" |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 consume_count("element count", FLAG_wasm_max_table_size); | 568 consume_count("element count", FLAG_wasm_max_table_size); |
569 for (uint32_t i = 0; ok() && i < element_count; ++i) { | 569 for (uint32_t i = 0; ok() && i < element_count; ++i) { |
570 const byte* pos = pc(); | 570 const byte* pos = pc(); |
571 uint32_t table_index = consume_u32v("table index"); | 571 uint32_t table_index = consume_u32v("table index"); |
572 if (table_index != 0) { | 572 if (table_index != 0) { |
573 error(pos, pos, "illegal table index %u != 0", table_index); | 573 error(pos, pos, "illegal table index %u != 0", table_index); |
574 } | 574 } |
575 WasmIndirectFunctionTable* table = nullptr; | 575 WasmIndirectFunctionTable* table = nullptr; |
576 if (table_index >= module->function_tables.size()) { | 576 if (table_index >= module->function_tables.size()) { |
577 error(pos, pos, "out of bounds table index %u", table_index); | 577 error(pos, pos, "out of bounds table index %u", table_index); |
578 } else { | 578 break; |
579 table = &module->function_tables[table_index]; | |
580 } | 579 } |
| 580 table = &module->function_tables[table_index]; |
581 WasmInitExpr offset = consume_init_expr(module, kWasmI32); | 581 WasmInitExpr offset = consume_init_expr(module, kWasmI32); |
582 uint32_t num_elem = | 582 uint32_t num_elem = |
583 consume_count("number of elements", kV8MaxWasmTableEntries); | 583 consume_count("number of elements", kV8MaxWasmTableEntries); |
584 std::vector<uint32_t> vector; | 584 std::vector<uint32_t> vector; |
585 module->table_inits.push_back({table_index, offset, vector}); | 585 module->table_inits.push_back({table_index, offset, vector}); |
586 WasmTableInit* init = &module->table_inits.back(); | 586 WasmTableInit* init = &module->table_inits.back(); |
587 for (uint32_t j = 0; ok() && j < num_elem; j++) { | 587 for (uint32_t j = 0; ok() && j < num_elem; j++) { |
588 WasmFunction* func = nullptr; | 588 WasmFunction* func = nullptr; |
589 uint32_t index = consume_func_index(module, &func); | 589 uint32_t index = consume_func_index(module, &func); |
| 590 DCHECK_EQ(func != nullptr, ok()); |
| 591 if (!func) break; |
| 592 DCHECK_EQ(index, func->func_index); |
590 init->entries.push_back(index); | 593 init->entries.push_back(index); |
591 if (table && index < module->functions.size()) { | 594 // Canonicalize signature indices during decoding. |
592 // Canonicalize signature indices during decoding. | 595 table->map.FindOrInsert(func->sig); |
593 table->map.FindOrInsert(module->functions[index].sig); | |
594 } | |
595 } | 596 } |
596 } | 597 } |
597 | 598 |
598 section_iter.advance(); | 599 section_iter.advance(); |
599 } | 600 } |
600 | 601 |
601 // ===== Code section ==================================================== | 602 // ===== Code section ==================================================== |
602 if (section_iter.section_code() == kCodeSectionCode) { | 603 if (section_iter.section_code() == kCodeSectionCode) { |
603 const byte* pos = pc_; | 604 const byte* pos = pc_; |
604 uint32_t functions_count = consume_u32v("functions count"); | 605 uint32_t functions_count = consume_u32v("functions count"); |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 result.push_back({section_start, name_offset, name_length, payload_offset, | 1340 result.push_back({section_start, name_offset, name_length, payload_offset, |
1340 payload_length, section_length}); | 1341 payload_length, section_length}); |
1341 } | 1342 } |
1342 | 1343 |
1343 return result; | 1344 return result; |
1344 } | 1345 } |
1345 | 1346 |
1346 } // namespace wasm | 1347 } // namespace wasm |
1347 } // namespace internal | 1348 } // namespace internal |
1348 } // namespace v8 | 1349 } // namespace v8 |
OLD | NEW |