Chromium Code Reviews| 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/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 | 351 |
| 352 module->export_table.push_back({0, // func_index | 352 module->export_table.push_back({0, // func_index |
| 353 0, // name_offset | 353 0, // name_offset |
| 354 0}); // name_length | 354 0}); // name_length |
| 355 WasmExport* exp = &module->export_table.back(); | 355 WasmExport* exp = &module->export_table.back(); |
| 356 | 356 |
| 357 WasmFunction* func; | 357 WasmFunction* func; |
| 358 exp->func_index = consume_func_index(module, &func); | 358 exp->func_index = consume_func_index(module, &func); |
| 359 exp->name_offset = consume_string(&exp->name_length, true); | 359 exp->name_offset = consume_string(&exp->name_length, true); |
| 360 } | 360 } |
| 361 // Check for duplicate exports. | |
| 362 if (ok() && module->export_table.size() > 1) { | |
| 363 std::vector<WasmExport> sorted_exports(module->export_table); | |
| 364 const byte* base = start_; | |
| 365 auto cmp = [base](const WasmExport& a, const WasmExport& b) { | |
|
ahaas
2016/06/16 09:16:13
I was confused by the name "cmp" because I expecte
Clemens Hammacher
2016/06/16 12:16:10
I renamed it to cmp_less.
| |
| 366 // Return true if a < b. | |
| 367 uint32_t len = a.name_length; | |
| 368 if (len != b.name_length) return len < b.name_length; | |
| 369 return memcmp(base + a.name_offset, base + b.name_offset, len) < | |
| 370 0; | |
| 371 }; | |
| 372 std::stable_sort(sorted_exports.begin(), sorted_exports.end(), cmp); | |
| 373 auto it = sorted_exports.begin(); | |
| 374 WasmExport* last = &*it++; | |
| 375 for (auto end = sorted_exports.end(); it != end; last = &*it++) { | |
| 376 DCHECK(!cmp(*it, *last)); | |
| 377 if (!cmp(*last, *it)) { | |
| 378 const byte* pc = start_ + it->name_offset; | |
| 379 error(pc, pc, | |
| 380 "Duplicate export name '%.*s' for functions %d and %d", | |
| 381 it->name_length, pc, last->func_index, it->func_index); | |
| 382 break; | |
| 383 } | |
| 384 } | |
| 385 } | |
| 361 break; | 386 break; |
| 362 } | 387 } |
| 363 case WasmSection::Code::Max: | 388 case WasmSection::Code::Max: |
| 364 // Skip unknown sections. | 389 // Skip unknown sections. |
| 365 TRACE("Unknown section: '"); | 390 TRACE("Unknown section: '"); |
| 366 for (uint32_t i = 0; i != string_length; ++i) { | 391 for (uint32_t i = 0; i != string_length; ++i) { |
| 367 TRACE("%c", *(section_name_start + i)); | 392 TRACE("%c", *(section_name_start + i)); |
| 368 } | 393 } |
| 369 TRACE("'\n"); | 394 TRACE("'\n"); |
| 370 consume_bytes(section_length); | 395 consume_bytes(section_length); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 return FunctionError("size > maximum function size"); | 783 return FunctionError("size > maximum function size"); |
| 759 isolate->counters()->wasm_function_size_bytes()->AddSample( | 784 isolate->counters()->wasm_function_size_bytes()->AddSample( |
| 760 static_cast<int>(size)); | 785 static_cast<int>(size)); |
| 761 WasmFunction* function = new WasmFunction(); | 786 WasmFunction* function = new WasmFunction(); |
| 762 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 787 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
| 763 return decoder.DecodeSingleFunction(module_env, function); | 788 return decoder.DecodeSingleFunction(module_env, function); |
| 764 } | 789 } |
| 765 } // namespace wasm | 790 } // namespace wasm |
| 766 } // namespace internal | 791 } // namespace internal |
| 767 } // namespace v8 | 792 } // namespace v8 |
| OLD | NEW |