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/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 isolate_->factory()->NewJSObject(object_function, TENURED); | 1620 isolate_->factory()->NewJSObject(object_function, TENURED); |
1621 Handle<String> exports_name = | 1621 Handle<String> exports_name = |
1622 isolate_->factory()->InternalizeUtf8String("exports"); | 1622 isolate_->factory()->InternalizeUtf8String("exports"); |
1623 JSObject::AddProperty(instance, exports_name, exports_object, READ_ONLY); | 1623 JSObject::AddProperty(instance, exports_name, exports_object, READ_ONLY); |
1624 } | 1624 } |
1625 | 1625 |
1626 PropertyDescriptor desc; | 1626 PropertyDescriptor desc; |
1627 desc.set_writable(false); | 1627 desc.set_writable(false); |
1628 | 1628 |
1629 // Process each export in the export table. | 1629 // Process each export in the export table. |
1630 int func_index = 0; | 1630 int export_index = 0; |
1631 for (auto exp : module_->export_table) { | 1631 for (auto exp : module_->export_table) { |
1632 Handle<String> name = | 1632 Handle<String> name = |
1633 ExtractStringFromModuleBytes(isolate_, compiled_module_, | 1633 ExtractStringFromModuleBytes(isolate_, compiled_module_, |
1634 exp.name_offset, exp.name_length) | 1634 exp.name_offset, exp.name_length) |
1635 .ToHandleChecked(); | 1635 .ToHandleChecked(); |
1636 switch (exp.kind) { | 1636 switch (exp.kind) { |
1637 case kExternalFunction: { | 1637 case kExternalFunction: { |
1638 // Wrap and export the code as a JSFunction. | 1638 // Wrap and export the code as a JSFunction. |
1639 WasmFunction& function = module_->functions[exp.index]; | 1639 WasmFunction& function = module_->functions[exp.index]; |
1640 int export_index = | 1640 int func_index = |
1641 static_cast<int>(module_->functions.size() + func_index); | 1641 static_cast<int>(module_->functions.size() + export_index); |
1642 Handle<JSFunction> js_function = js_wrappers_[exp.index]; | 1642 Handle<JSFunction> js_function = js_wrappers_[exp.index]; |
1643 if (js_function.is_null()) { | 1643 if (js_function.is_null()) { |
1644 // Wrap the exported code as a JSFunction. | 1644 // Wrap the exported code as a JSFunction. |
1645 Handle<Code> export_code = | 1645 Handle<Code> export_code = |
1646 code_table->GetValueChecked<Code>(isolate_, export_index); | 1646 code_table->GetValueChecked<Code>(isolate_, func_index); |
1647 js_function = | 1647 js_function = WrapExportCodeAsJSFunction( |
1648 WrapExportCodeAsJSFunction(isolate_, export_code, name, | 1648 isolate_, export_code, name, function.sig, function.func_index, |
1649 function.sig, func_index, instance); | 1649 instance); |
1650 js_wrappers_[exp.index] = js_function; | 1650 js_wrappers_[exp.index] = js_function; |
1651 } | 1651 } |
1652 desc.set_value(js_function); | 1652 desc.set_value(js_function); |
1653 func_index++; | 1653 export_index++; |
1654 break; | 1654 break; |
1655 } | 1655 } |
1656 case kExternalTable: { | 1656 case kExternalTable: { |
1657 // Export a table as a WebAssembly.Table object. | 1657 // Export a table as a WebAssembly.Table object. |
1658 TableInstance& table_instance = table_instances_[exp.index]; | 1658 TableInstance& table_instance = table_instances_[exp.index]; |
1659 WasmIndirectFunctionTable& table = | 1659 WasmIndirectFunctionTable& table = |
1660 module_->function_tables[exp.index]; | 1660 module_->function_tables[exp.index]; |
1661 if (table_instance.table_object.is_null()) { | 1661 if (table_instance.table_object.is_null()) { |
1662 table_instance.table_object = WasmJs::CreateWasmTableObject( | 1662 table_instance.table_object = WasmJs::CreateWasmTableObject( |
1663 isolate_, table.min_size, table.has_max, table.max_size, | 1663 isolate_, table.min_size, table.has_max, table.max_size, |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2232 CHECK_NOT_NULL(result.val); | 2232 CHECK_NOT_NULL(result.val); |
2233 module = const_cast<WasmModule*>(result.val); | 2233 module = const_cast<WasmModule*>(result.val); |
2234 } | 2234 } |
2235 | 2235 |
2236 Handle<WasmModuleWrapper> module_wrapper = | 2236 Handle<WasmModuleWrapper> module_wrapper = |
2237 WasmModuleWrapper::New(isolate, module); | 2237 WasmModuleWrapper::New(isolate, module); |
2238 | 2238 |
2239 compiled_module->set_module_wrapper(module_wrapper); | 2239 compiled_module->set_module_wrapper(module_wrapper); |
2240 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); | 2240 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); |
2241 } | 2241 } |
OLD | NEW |