| 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 | 6 |
| 7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
| 8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 9 #include "src/flags.h" | 9 #include "src/flags.h" |
| 10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 0 // source_size | 616 0 // source_size |
| 617 }); | 617 }); |
| 618 WasmDataSegment* segment = &module->data_segments.back(); | 618 WasmDataSegment* segment = &module->data_segments.back(); |
| 619 DecodeDataSegmentInModule(module, segment); | 619 DecodeDataSegmentInModule(module, segment); |
| 620 } | 620 } |
| 621 section_iter.advance(); | 621 section_iter.advance(); |
| 622 } | 622 } |
| 623 | 623 |
| 624 // ===== Name section ==================================================== | 624 // ===== Name section ==================================================== |
| 625 if (section_iter.section_code() == kNameSectionCode) { | 625 if (section_iter.section_code() == kNameSectionCode) { |
| 626 const byte* pos = pc_; | |
| 627 uint32_t functions_count = consume_u32v("functions count"); | 626 uint32_t functions_count = consume_u32v("functions count"); |
| 628 if (functions_count != module->num_declared_functions) { | |
| 629 error(pos, pos, "function name count %u mismatch (%u expected)", | |
| 630 functions_count, module->num_declared_functions); | |
| 631 } | |
| 632 | 627 |
| 633 for (uint32_t i = 0; ok() && i < functions_count; ++i) { | 628 for (uint32_t i = 0; ok() && i < functions_count; ++i) { |
| 634 WasmFunction* function = | 629 uint32_t function_name_length = 0; |
| 635 &module->functions[i + module->num_imported_functions]; | 630 uint32_t name_offset = consume_string(&function_name_length, false); |
| 636 function->name_offset = consume_string(&function->name_length, false); | 631 uint32_t func_index = i; |
| 632 if (func_index < module->functions.size()) { |
| 633 module->functions[func_index].name_offset = name_offset; |
| 634 module->functions[func_index].name_length = function_name_length; |
| 635 } |
| 637 | 636 |
| 638 uint32_t local_names_count = consume_u32v("local names count"); | 637 uint32_t local_names_count = consume_u32v("local names count"); |
| 639 for (uint32_t j = 0; ok() && j < local_names_count; j++) { | 638 for (uint32_t j = 0; ok() && j < local_names_count; j++) { |
| 640 skip_string(); | 639 skip_string(); |
| 641 } | 640 } |
| 642 } | 641 } |
| 643 section_iter.advance(); | 642 section_iter.advance(); |
| 644 } | 643 } |
| 645 | 644 |
| 646 // ===== Remaining sections ============================================== | 645 // ===== Remaining sections ============================================== |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 table.push_back(std::move(func_asm_offsets)); | 1231 table.push_back(std::move(func_asm_offsets)); |
| 1233 } | 1232 } |
| 1234 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1233 if (decoder.more()) decoder.error("unexpected additional bytes"); |
| 1235 | 1234 |
| 1236 return decoder.toResult(std::move(table)); | 1235 return decoder.toResult(std::move(table)); |
| 1237 } | 1236 } |
| 1238 | 1237 |
| 1239 } // namespace wasm | 1238 } // namespace wasm |
| 1240 } // namespace internal | 1239 } // namespace internal |
| 1241 } // namespace v8 | 1240 } // namespace v8 |
| OLD | NEW |