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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "src/base/adapters.h" | |
| 7 #include "src/base/atomic-utils.h" | 8 #include "src/base/atomic-utils.h" |
| 8 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 9 #include "src/compiler/wasm-compiler.h" | 10 #include "src/compiler/wasm-compiler.h" |
| 10 #include "src/debug/interface-types.h" | 11 #include "src/debug/interface-types.h" |
| 11 #include "src/macro-assembler.h" | 12 #include "src/macro-assembler.h" |
| 12 #include "src/objects.h" | 13 #include "src/objects.h" |
| 13 #include "src/property-descriptor.h" | 14 #include "src/property-descriptor.h" |
| 14 #include "src/simulator.h" | 15 #include "src/simulator.h" |
| 15 #include "src/snapshot/snapshot.h" | 16 #include "src/snapshot/snapshot.h" |
| 16 #include "src/v8.h" | 17 #include "src/v8.h" |
| (...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1743 exports_object = | 1744 exports_object = |
| 1744 isolate_->factory()->NewJSObject(object_function, TENURED); | 1745 isolate_->factory()->NewJSObject(object_function, TENURED); |
| 1745 Handle<String> exports_name = | 1746 Handle<String> exports_name = |
| 1746 isolate_->factory()->InternalizeUtf8String("exports"); | 1747 isolate_->factory()->InternalizeUtf8String("exports"); |
| 1747 JSObject::AddProperty(instance, exports_name, exports_object, READ_ONLY); | 1748 JSObject::AddProperty(instance, exports_name, exports_object, READ_ONLY); |
| 1748 } | 1749 } |
| 1749 | 1750 |
| 1750 PropertyDescriptor desc; | 1751 PropertyDescriptor desc; |
| 1751 desc.set_writable(false); | 1752 desc.set_writable(false); |
| 1752 | 1753 |
| 1753 // Process each export in the export table. | 1754 // Count up export indexes. |
| 1754 int export_index = 0; | 1755 int export_index = 0; |
| 1755 for (auto exp : module_->export_table) { | 1756 for (auto exp : module_->export_table) { |
|
titzer
2016/12/12 12:59:10
Couldn't you just set it to module_->export_table.
bradn
2016/12/12 13:53:21
Ah, wasn't gating on the condition, that's why it
| |
| 1757 ++export_index; | |
| 1758 } | |
| 1759 // Process each export in the export table (go in reverse so asm.js | |
| 1760 // can skip duplicates). | |
| 1761 for (auto exp : base::Reversed(module_->export_table)) { | |
| 1756 Handle<String> name = | 1762 Handle<String> name = |
| 1757 ExtractStringFromModuleBytes(isolate_, compiled_module_, | 1763 ExtractStringFromModuleBytes(isolate_, compiled_module_, |
| 1758 exp.name_offset, exp.name_length) | 1764 exp.name_offset, exp.name_length) |
| 1759 .ToHandleChecked(); | 1765 .ToHandleChecked(); |
| 1760 switch (exp.kind) { | 1766 switch (exp.kind) { |
| 1761 case kExternalFunction: { | 1767 case kExternalFunction: { |
| 1762 // Wrap and export the code as a JSFunction. | 1768 // Wrap and export the code as a JSFunction. |
| 1763 WasmFunction& function = module_->functions[exp.index]; | 1769 WasmFunction& function = module_->functions[exp.index]; |
| 1764 int func_index = | 1770 int func_index = |
| 1765 static_cast<int>(module_->functions.size() + export_index); | 1771 static_cast<int>(module_->functions.size() + --export_index); |
| 1766 Handle<JSFunction> js_function = js_wrappers_[exp.index]; | 1772 Handle<JSFunction> js_function = js_wrappers_[exp.index]; |
| 1767 if (js_function.is_null()) { | 1773 if (js_function.is_null()) { |
| 1768 // Wrap the exported code as a JSFunction. | 1774 // Wrap the exported code as a JSFunction. |
| 1769 Handle<Code> export_code = | 1775 Handle<Code> export_code = |
| 1770 code_table->GetValueChecked<Code>(isolate_, func_index); | 1776 code_table->GetValueChecked<Code>(isolate_, func_index); |
| 1771 MaybeHandle<String> func_name; | 1777 MaybeHandle<String> func_name; |
| 1772 if (module_->origin == kAsmJsOrigin) { | 1778 if (module_->origin == kAsmJsOrigin) { |
| 1773 // For modules arising from asm.js, honor the names section. | 1779 // For modules arising from asm.js, honor the names section. |
| 1774 func_name = ExtractStringFromModuleBytes( | 1780 func_name = ExtractStringFromModuleBytes( |
| 1775 isolate_, compiled_module_, function.name_offset, | 1781 isolate_, compiled_module_, function.name_offset, |
| 1776 function.name_length) | 1782 function.name_length) |
| 1777 .ToHandleChecked(); | 1783 .ToHandleChecked(); |
| 1778 } | 1784 } |
| 1779 js_function = WasmExportedFunction::New( | 1785 js_function = WasmExportedFunction::New( |
| 1780 isolate_, instance, func_name, function.func_index, | 1786 isolate_, instance, func_name, function.func_index, |
| 1781 static_cast<int>(function.sig->parameter_count()), export_code); | 1787 static_cast<int>(function.sig->parameter_count()), export_code); |
| 1782 js_wrappers_[exp.index] = js_function; | 1788 js_wrappers_[exp.index] = js_function; |
| 1783 } | 1789 } |
| 1784 desc.set_value(js_function); | 1790 desc.set_value(js_function); |
| 1785 export_index++; | |
| 1786 break; | 1791 break; |
| 1787 } | 1792 } |
| 1788 case kExternalTable: { | 1793 case kExternalTable: { |
| 1789 // Export a table as a WebAssembly.Table object. | 1794 // Export a table as a WebAssembly.Table object. |
| 1790 TableInstance& table_instance = table_instances_[exp.index]; | 1795 TableInstance& table_instance = table_instances_[exp.index]; |
| 1791 WasmIndirectFunctionTable& table = | 1796 WasmIndirectFunctionTable& table = |
| 1792 module_->function_tables[exp.index]; | 1797 module_->function_tables[exp.index]; |
| 1793 if (table_instance.table_object.is_null()) { | 1798 if (table_instance.table_object.is_null()) { |
| 1794 uint32_t maximum = | 1799 uint32_t maximum = |
| 1795 table.has_max ? table.max_size : kV8MaxWasmTableSize; | 1800 table.has_max ? table.max_size : kV8MaxWasmTableSize; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1838 UNREACHABLE(); | 1843 UNREACHABLE(); |
| 1839 } | 1844 } |
| 1840 desc.set_value(isolate_->factory()->NewNumber(num)); | 1845 desc.set_value(isolate_->factory()->NewNumber(num)); |
| 1841 break; | 1846 break; |
| 1842 } | 1847 } |
| 1843 default: | 1848 default: |
| 1844 UNREACHABLE(); | 1849 UNREACHABLE(); |
| 1845 break; | 1850 break; |
| 1846 } | 1851 } |
| 1847 | 1852 |
| 1853 // Skip duplicates for asm.js. | |
| 1854 if (module_->origin == kAsmJsOrigin) { | |
| 1855 v8::Maybe<bool> status = | |
| 1856 JSReceiver::HasOwnProperty(exports_object, name); | |
| 1857 if (status.FromMaybe(false)) { | |
| 1858 continue; | |
| 1859 } | |
| 1860 } | |
| 1848 v8::Maybe<bool> status = JSReceiver::DefineOwnProperty( | 1861 v8::Maybe<bool> status = JSReceiver::DefineOwnProperty( |
| 1849 isolate_, exports_object, name, &desc, Object::THROW_ON_ERROR); | 1862 isolate_, exports_object, name, &desc, Object::THROW_ON_ERROR); |
| 1850 if (!status.IsJust()) { | 1863 if (!status.IsJust()) { |
| 1851 thrower_->TypeError("export of %.*s failed.", name->length(), | 1864 thrower_->TypeError("export of %.*s failed.", name->length(), |
| 1852 name->ToCString().get()); | 1865 name->ToCString().get()); |
| 1853 return; | 1866 return; |
| 1854 } | 1867 } |
| 1855 } | 1868 } |
| 1856 } | 1869 } |
| 1857 | 1870 |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2379 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2392 MaybeHandle<String> WasmCompiledModule::GetFunctionName( |
| 2380 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2393 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { |
| 2381 DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2394 DCHECK_LT(func_index, compiled_module->module()->functions.size()); |
| 2382 WasmFunction& function = compiled_module->module()->functions[func_index]; | 2395 WasmFunction& function = compiled_module->module()->functions[func_index]; |
| 2383 Isolate* isolate = compiled_module->GetIsolate(); | 2396 Isolate* isolate = compiled_module->GetIsolate(); |
| 2384 MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2397 MaybeHandle<String> string = ExtractStringFromModuleBytes( |
| 2385 isolate, compiled_module, function.name_offset, function.name_length); | 2398 isolate, compiled_module, function.name_offset, function.name_length); |
| 2386 if (!string.is_null()) return string.ToHandleChecked(); | 2399 if (!string.is_null()) return string.ToHandleChecked(); |
| 2387 return {}; | 2400 return {}; |
| 2388 } | 2401 } |
| OLD | NEW |