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) { |
| 1757 if (exp.kind == kExternalFunction) { |
| 1758 ++export_index; |
| 1759 } |
| 1760 } |
| 1761 // Process each export in the export table (go in reverse so asm.js |
| 1762 // can skip duplicates). |
| 1763 for (auto exp : base::Reversed(module_->export_table)) { |
1756 Handle<String> name = | 1764 Handle<String> name = |
1757 ExtractStringFromModuleBytes(isolate_, compiled_module_, | 1765 ExtractStringFromModuleBytes(isolate_, compiled_module_, |
1758 exp.name_offset, exp.name_length) | 1766 exp.name_offset, exp.name_length) |
1759 .ToHandleChecked(); | 1767 .ToHandleChecked(); |
1760 switch (exp.kind) { | 1768 switch (exp.kind) { |
1761 case kExternalFunction: { | 1769 case kExternalFunction: { |
1762 // Wrap and export the code as a JSFunction. | 1770 // Wrap and export the code as a JSFunction. |
1763 WasmFunction& function = module_->functions[exp.index]; | 1771 WasmFunction& function = module_->functions[exp.index]; |
1764 int func_index = | 1772 int func_index = |
1765 static_cast<int>(module_->functions.size() + export_index); | 1773 static_cast<int>(module_->functions.size() + --export_index); |
1766 Handle<JSFunction> js_function = js_wrappers_[exp.index]; | 1774 Handle<JSFunction> js_function = js_wrappers_[exp.index]; |
1767 if (js_function.is_null()) { | 1775 if (js_function.is_null()) { |
1768 // Wrap the exported code as a JSFunction. | 1776 // Wrap the exported code as a JSFunction. |
1769 Handle<Code> export_code = | 1777 Handle<Code> export_code = |
1770 code_table->GetValueChecked<Code>(isolate_, func_index); | 1778 code_table->GetValueChecked<Code>(isolate_, func_index); |
1771 MaybeHandle<String> func_name; | 1779 MaybeHandle<String> func_name; |
1772 if (module_->origin == kAsmJsOrigin) { | 1780 if (module_->origin == kAsmJsOrigin) { |
1773 // For modules arising from asm.js, honor the names section. | 1781 // For modules arising from asm.js, honor the names section. |
1774 func_name = ExtractStringFromModuleBytes( | 1782 func_name = ExtractStringFromModuleBytes( |
1775 isolate_, compiled_module_, function.name_offset, | 1783 isolate_, compiled_module_, function.name_offset, |
1776 function.name_length) | 1784 function.name_length) |
1777 .ToHandleChecked(); | 1785 .ToHandleChecked(); |
1778 } | 1786 } |
1779 js_function = WasmExportedFunction::New( | 1787 js_function = WasmExportedFunction::New( |
1780 isolate_, instance, func_name, function.func_index, | 1788 isolate_, instance, func_name, function.func_index, |
1781 static_cast<int>(function.sig->parameter_count()), export_code); | 1789 static_cast<int>(function.sig->parameter_count()), export_code); |
1782 js_wrappers_[exp.index] = js_function; | 1790 js_wrappers_[exp.index] = js_function; |
1783 } | 1791 } |
1784 desc.set_value(js_function); | 1792 desc.set_value(js_function); |
1785 export_index++; | |
1786 break; | 1793 break; |
1787 } | 1794 } |
1788 case kExternalTable: { | 1795 case kExternalTable: { |
1789 // Export a table as a WebAssembly.Table object. | 1796 // Export a table as a WebAssembly.Table object. |
1790 TableInstance& table_instance = table_instances_[exp.index]; | 1797 TableInstance& table_instance = table_instances_[exp.index]; |
1791 WasmIndirectFunctionTable& table = | 1798 WasmIndirectFunctionTable& table = |
1792 module_->function_tables[exp.index]; | 1799 module_->function_tables[exp.index]; |
1793 if (table_instance.table_object.is_null()) { | 1800 if (table_instance.table_object.is_null()) { |
1794 uint32_t maximum = | 1801 uint32_t maximum = |
1795 table.has_max ? table.max_size : kV8MaxWasmTableSize; | 1802 table.has_max ? table.max_size : kV8MaxWasmTableSize; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 UNREACHABLE(); | 1845 UNREACHABLE(); |
1839 } | 1846 } |
1840 desc.set_value(isolate_->factory()->NewNumber(num)); | 1847 desc.set_value(isolate_->factory()->NewNumber(num)); |
1841 break; | 1848 break; |
1842 } | 1849 } |
1843 default: | 1850 default: |
1844 UNREACHABLE(); | 1851 UNREACHABLE(); |
1845 break; | 1852 break; |
1846 } | 1853 } |
1847 | 1854 |
| 1855 // Skip duplicates for asm.js. |
| 1856 if (module_->origin == kAsmJsOrigin) { |
| 1857 v8::Maybe<bool> status = |
| 1858 JSReceiver::HasOwnProperty(exports_object, name); |
| 1859 if (status.FromMaybe(false)) { |
| 1860 continue; |
| 1861 } |
| 1862 } |
1848 v8::Maybe<bool> status = JSReceiver::DefineOwnProperty( | 1863 v8::Maybe<bool> status = JSReceiver::DefineOwnProperty( |
1849 isolate_, exports_object, name, &desc, Object::THROW_ON_ERROR); | 1864 isolate_, exports_object, name, &desc, Object::THROW_ON_ERROR); |
1850 if (!status.IsJust()) { | 1865 if (!status.IsJust()) { |
1851 thrower_->TypeError("export of %.*s failed.", name->length(), | 1866 thrower_->TypeError("export of %.*s failed.", name->length(), |
1852 name->ToCString().get()); | 1867 name->ToCString().get()); |
1853 return; | 1868 return; |
1854 } | 1869 } |
1855 } | 1870 } |
1856 } | 1871 } |
1857 | 1872 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2394 MaybeHandle<String> WasmCompiledModule::GetFunctionName( |
2380 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2395 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { |
2381 DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2396 DCHECK_LT(func_index, compiled_module->module()->functions.size()); |
2382 WasmFunction& function = compiled_module->module()->functions[func_index]; | 2397 WasmFunction& function = compiled_module->module()->functions[func_index]; |
2383 Isolate* isolate = compiled_module->GetIsolate(); | 2398 Isolate* isolate = compiled_module->GetIsolate(); |
2384 MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2399 MaybeHandle<String> string = ExtractStringFromModuleBytes( |
2385 isolate, compiled_module, function.name_offset, function.name_length); | 2400 isolate, compiled_module, function.name_offset, function.name_length); |
2386 if (!string.is_null()) return string.ToHandleChecked(); | 2401 if (!string.is_null()) return string.ToHandleChecked(); |
2387 return {}; | 2402 return {}; |
2388 } | 2403 } |
OLD | NEW |