| 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/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
| 8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
| 9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 283 } |
| 284 DCHECK_LE(this_idx + 2, deopt_data->length()); | 284 DCHECK_LE(this_idx + 2, deopt_data->length()); |
| 285 DCHECK(deopt_data->get(this_idx)->IsUndefined(isolate)); | 285 DCHECK(deopt_data->get(this_idx)->IsUndefined(isolate)); |
| 286 DCHECK(deopt_data->get(this_idx + 1)->IsUndefined(isolate)); | 286 DCHECK(deopt_data->get(this_idx + 1)->IsUndefined(isolate)); |
| 287 deopt_data->set(this_idx, *export_table); | 287 deopt_data->set(this_idx, *export_table); |
| 288 deopt_data->set(this_idx + 1, Smi::FromInt(export_index)); | 288 deopt_data->set(this_idx + 1, Smi::FromInt(export_index)); |
| 289 return code; | 289 return code; |
| 290 } | 290 } |
| 291 | 291 |
| 292 bool compile_lazy(const WasmModule* module) { | 292 bool compile_lazy(const WasmModule* module) { |
| 293 return FLAG_wasm_lazy_compilation || (FLAG_asm_wasm_lazy_compilation && | 293 return FLAG_wasm_lazy_compilation || |
| 294 module->origin == wasm::kAsmJsOrigin); | 294 (FLAG_asm_wasm_lazy_compilation && module->is_asm_js()); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // A helper for compiling an entire module. | 297 // A helper for compiling an entire module. |
| 298 class CompilationHelper { | 298 class CompilationHelper { |
| 299 public: | 299 public: |
| 300 CompilationHelper(Isolate* isolate, WasmModule* module) | 300 CompilationHelper(Isolate* isolate, WasmModule* module) |
| 301 : isolate_(isolate), module_(module) {} | 301 : isolate_(isolate), module_(module) {} |
| 302 | 302 |
| 303 // The actual runnable task that performs compilations in the background. | 303 // The actual runnable task that performs compilations in the background. |
| 304 class CompilationTask : public CancelableTask { | 304 class CompilationTask : public CancelableTask { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 Handle<FixedArray> signature_tables = | 507 Handle<FixedArray> signature_tables = |
| 508 factory->NewFixedArray(function_table_count, TENURED); | 508 factory->NewFixedArray(function_table_count, TENURED); |
| 509 for (int i = 0; i < function_table_count; ++i) { | 509 for (int i = 0; i < function_table_count; ++i) { |
| 510 temp_instance.function_tables[i] = factory->NewFixedArray(1, TENURED); | 510 temp_instance.function_tables[i] = factory->NewFixedArray(1, TENURED); |
| 511 temp_instance.signature_tables[i] = factory->NewFixedArray(1, TENURED); | 511 temp_instance.signature_tables[i] = factory->NewFixedArray(1, TENURED); |
| 512 function_tables->set(i, *temp_instance.function_tables[i]); | 512 function_tables->set(i, *temp_instance.function_tables[i]); |
| 513 signature_tables->set(i, *temp_instance.signature_tables[i]); | 513 signature_tables->set(i, *temp_instance.signature_tables[i]); |
| 514 } | 514 } |
| 515 | 515 |
| 516 HistogramTimerScope wasm_compile_module_time_scope( | 516 HistogramTimerScope wasm_compile_module_time_scope( |
| 517 module_->origin == ModuleOrigin::kWasmOrigin | 517 module_->is_wasm() |
| 518 ? isolate_->counters()->wasm_compile_wasm_module_time() | 518 ? isolate_->counters()->wasm_compile_wasm_module_time() |
| 519 : isolate_->counters()->wasm_compile_asm_module_time()); | 519 : isolate_->counters()->wasm_compile_asm_module_time()); |
| 520 | 520 |
| 521 ModuleBytesEnv module_env(module_, &temp_instance, wire_bytes); | 521 ModuleBytesEnv module_env(module_, &temp_instance, wire_bytes); |
| 522 | 522 |
| 523 // The {code_table} array contains import wrappers and functions (which | 523 // The {code_table} array contains import wrappers and functions (which |
| 524 // are both included in {functions.size()}, and export wrappers. | 524 // are both included in {functions.size()}, and export wrappers. |
| 525 int code_table_size = static_cast<int>(module_->functions.size() + | 525 int code_table_size = static_cast<int>(module_->functions.size() + |
| 526 module_->num_exported_functions); | 526 module_->num_exported_functions); |
| 527 Handle<FixedArray> code_table = | 527 Handle<FixedArray> code_table = |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 // Check that an imports argument was provided, if the module requires it. | 1150 // Check that an imports argument was provided, if the module requires it. |
| 1151 // No point in continuing otherwise. | 1151 // No point in continuing otherwise. |
| 1152 if (!module_->import_table.empty() && ffi_.is_null()) { | 1152 if (!module_->import_table.empty() && ffi_.is_null()) { |
| 1153 thrower_->TypeError( | 1153 thrower_->TypeError( |
| 1154 "Imports argument must be present and must be an object"); | 1154 "Imports argument must be present and must be an object"); |
| 1155 return {}; | 1155 return {}; |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 // Record build time into correct bucket, then build instance. | 1158 // Record build time into correct bucket, then build instance. |
| 1159 HistogramTimerScope wasm_instantiate_module_time_scope( | 1159 HistogramTimerScope wasm_instantiate_module_time_scope( |
| 1160 module_->origin == ModuleOrigin::kWasmOrigin | 1160 module_->is_wasm() |
| 1161 ? isolate_->counters()->wasm_instantiate_wasm_module_time() | 1161 ? isolate_->counters()->wasm_instantiate_wasm_module_time() |
| 1162 : isolate_->counters()->wasm_instantiate_asm_module_time()); | 1162 : isolate_->counters()->wasm_instantiate_asm_module_time()); |
| 1163 Factory* factory = isolate_->factory(); | 1163 Factory* factory = isolate_->factory(); |
| 1164 | 1164 |
| 1165 //-------------------------------------------------------------------------- | 1165 //-------------------------------------------------------------------------- |
| 1166 // Reuse the compiled module (if no owner), otherwise clone. | 1166 // Reuse the compiled module (if no owner), otherwise clone. |
| 1167 //-------------------------------------------------------------------------- | 1167 //-------------------------------------------------------------------------- |
| 1168 Handle<FixedArray> code_table; | 1168 Handle<FixedArray> code_table; |
| 1169 Handle<FixedArray> old_code_table; | 1169 Handle<FixedArray> old_code_table; |
| 1170 MaybeHandle<WasmInstanceObject> owner; | 1170 MaybeHandle<WasmInstanceObject> owner; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 //-------------------------------------------------------------------------- | 1312 //-------------------------------------------------------------------------- |
| 1313 MaybeHandle<JSArrayBuffer> old_memory; | 1313 MaybeHandle<JSArrayBuffer> old_memory; |
| 1314 | 1314 |
| 1315 uint32_t min_mem_pages = module_->min_mem_pages; | 1315 uint32_t min_mem_pages = module_->min_mem_pages; |
| 1316 isolate_->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages); | 1316 isolate_->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages); |
| 1317 | 1317 |
| 1318 if (!memory_.is_null()) { | 1318 if (!memory_.is_null()) { |
| 1319 // Set externally passed ArrayBuffer non neuterable. | 1319 // Set externally passed ArrayBuffer non neuterable. |
| 1320 memory_->set_is_neuterable(false); | 1320 memory_->set_is_neuterable(false); |
| 1321 | 1321 |
| 1322 DCHECK_IMPLIES(EnableGuardRegions(), module_->origin == kAsmJsOrigin || | 1322 DCHECK_IMPLIES(EnableGuardRegions(), |
| 1323 memory_->has_guard_region()); | 1323 module_->is_asm_js() || memory_->has_guard_region()); |
| 1324 } else if (min_mem_pages > 0) { | 1324 } else if (min_mem_pages > 0) { |
| 1325 memory_ = AllocateMemory(min_mem_pages); | 1325 memory_ = AllocateMemory(min_mem_pages); |
| 1326 if (memory_.is_null()) return {}; // failed to allocate memory | 1326 if (memory_.is_null()) return {}; // failed to allocate memory |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 //-------------------------------------------------------------------------- | 1329 //-------------------------------------------------------------------------- |
| 1330 // Check that indirect function table segments are within bounds. | 1330 // Check that indirect function table segments are within bounds. |
| 1331 //-------------------------------------------------------------------------- | 1331 //-------------------------------------------------------------------------- |
| 1332 for (WasmTableInit& table_init : module_->table_inits) { | 1332 for (WasmTableInit& table_init : module_->table_inits) { |
| 1333 DCHECK(table_init.table_index < table_instances_.size()); | 1333 DCHECK(table_init.table_index < table_instances_.size()); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 // Function imports must be callable. | 1699 // Function imports must be callable. |
| 1700 if (!value->IsCallable()) { | 1700 if (!value->IsCallable()) { |
| 1701 ReportLinkError("function import requires a callable", index, | 1701 ReportLinkError("function import requires a callable", index, |
| 1702 module_name, import_name); | 1702 module_name, import_name); |
| 1703 return -1; | 1703 return -1; |
| 1704 } | 1704 } |
| 1705 | 1705 |
| 1706 Handle<Code> import_wrapper = CompileImportWrapper( | 1706 Handle<Code> import_wrapper = CompileImportWrapper( |
| 1707 isolate_, index, module_->functions[import.index].sig, | 1707 isolate_, index, module_->functions[import.index].sig, |
| 1708 Handle<JSReceiver>::cast(value), module_name, import_name, | 1708 Handle<JSReceiver>::cast(value), module_name, import_name, |
| 1709 module_->origin); | 1709 module_->get_origin()); |
| 1710 if (import_wrapper.is_null()) { | 1710 if (import_wrapper.is_null()) { |
| 1711 ReportLinkError( | 1711 ReportLinkError( |
| 1712 "imported function does not match the expected type", index, | 1712 "imported function does not match the expected type", index, |
| 1713 module_name, import_name); | 1713 module_name, import_name); |
| 1714 return -1; | 1714 return -1; |
| 1715 } | 1715 } |
| 1716 code_table->set(num_imported_functions, *import_wrapper); | 1716 code_table->set(num_imported_functions, *import_wrapper); |
| 1717 RecordStats(isolate_, *import_wrapper); | 1717 RecordStats(isolate_, *import_wrapper); |
| 1718 num_imported_functions++; | 1718 num_imported_functions++; |
| 1719 break; | 1719 break; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1933 void ProcessExports(Handle<FixedArray> code_table, | 1933 void ProcessExports(Handle<FixedArray> code_table, |
| 1934 Handle<WasmInstanceObject> instance, | 1934 Handle<WasmInstanceObject> instance, |
| 1935 Handle<WasmCompiledModule> compiled_module) { | 1935 Handle<WasmCompiledModule> compiled_module) { |
| 1936 if (NeedsWrappers()) { | 1936 if (NeedsWrappers()) { |
| 1937 // Fill the table to cache the exported JSFunction wrappers. | 1937 // Fill the table to cache the exported JSFunction wrappers. |
| 1938 js_wrappers_.insert(js_wrappers_.begin(), module_->functions.size(), | 1938 js_wrappers_.insert(js_wrappers_.begin(), module_->functions.size(), |
| 1939 Handle<JSFunction>::null()); | 1939 Handle<JSFunction>::null()); |
| 1940 } | 1940 } |
| 1941 | 1941 |
| 1942 Handle<JSObject> exports_object; | 1942 Handle<JSObject> exports_object; |
| 1943 if (module_->origin == kWasmOrigin) { | 1943 if (module_->is_wasm()) { |
| 1944 // Create the "exports" object. | 1944 // Create the "exports" object. |
| 1945 exports_object = isolate_->factory()->NewJSObjectWithNullProto(); | 1945 exports_object = isolate_->factory()->NewJSObjectWithNullProto(); |
| 1946 } else if (module_->origin == kAsmJsOrigin) { | 1946 } else if (module_->is_asm_js()) { |
| 1947 Handle<JSFunction> object_function = Handle<JSFunction>( | 1947 Handle<JSFunction> object_function = Handle<JSFunction>( |
| 1948 isolate_->native_context()->object_function(), isolate_); | 1948 isolate_->native_context()->object_function(), isolate_); |
| 1949 exports_object = isolate_->factory()->NewJSObject(object_function); | 1949 exports_object = isolate_->factory()->NewJSObject(object_function); |
| 1950 } else { | 1950 } else { |
| 1951 UNREACHABLE(); | 1951 UNREACHABLE(); |
| 1952 } | 1952 } |
| 1953 Handle<String> exports_name = | 1953 Handle<String> exports_name = |
| 1954 isolate_->factory()->InternalizeUtf8String("exports"); | 1954 isolate_->factory()->InternalizeUtf8String("exports"); |
| 1955 JSObject::AddProperty(instance, exports_name, exports_object, NONE); | 1955 JSObject::AddProperty(instance, exports_name, exports_object, NONE); |
| 1956 | 1956 |
| 1957 Handle<String> foreign_init_name = | 1957 Handle<String> foreign_init_name = |
| 1958 isolate_->factory()->InternalizeUtf8String( | 1958 isolate_->factory()->InternalizeUtf8String( |
| 1959 wasm::AsmWasmBuilder::foreign_init_name); | 1959 wasm::AsmWasmBuilder::foreign_init_name); |
| 1960 Handle<String> single_function_name = | 1960 Handle<String> single_function_name = |
| 1961 isolate_->factory()->InternalizeUtf8String( | 1961 isolate_->factory()->InternalizeUtf8String( |
| 1962 wasm::AsmWasmBuilder::single_function_name); | 1962 wasm::AsmWasmBuilder::single_function_name); |
| 1963 | 1963 |
| 1964 PropertyDescriptor desc; | 1964 PropertyDescriptor desc; |
| 1965 desc.set_writable(module_->origin == kAsmJsOrigin); | 1965 desc.set_writable(module_->is_asm_js()); |
| 1966 desc.set_enumerable(true); | 1966 desc.set_enumerable(true); |
| 1967 | 1967 |
| 1968 // Count up export indexes. | 1968 // Count up export indexes. |
| 1969 int export_index = 0; | 1969 int export_index = 0; |
| 1970 for (auto exp : module_->export_table) { | 1970 for (auto exp : module_->export_table) { |
| 1971 if (exp.kind == kExternalFunction) { | 1971 if (exp.kind == kExternalFunction) { |
| 1972 ++export_index; | 1972 ++export_index; |
| 1973 } | 1973 } |
| 1974 } | 1974 } |
| 1975 | 1975 |
| 1976 // Store weak references to all exported functions. | 1976 // Store weak references to all exported functions. |
| 1977 Handle<FixedArray> weak_exported_functions; | 1977 Handle<FixedArray> weak_exported_functions; |
| 1978 if (compiled_module->has_weak_exported_functions()) { | 1978 if (compiled_module->has_weak_exported_functions()) { |
| 1979 weak_exported_functions = compiled_module->weak_exported_functions(); | 1979 weak_exported_functions = compiled_module->weak_exported_functions(); |
| 1980 } else { | 1980 } else { |
| 1981 weak_exported_functions = | 1981 weak_exported_functions = |
| 1982 isolate_->factory()->NewFixedArray(export_index); | 1982 isolate_->factory()->NewFixedArray(export_index); |
| 1983 compiled_module->set_weak_exported_functions(weak_exported_functions); | 1983 compiled_module->set_weak_exported_functions(weak_exported_functions); |
| 1984 } | 1984 } |
| 1985 DCHECK_EQ(export_index, weak_exported_functions->length()); | 1985 DCHECK_EQ(export_index, weak_exported_functions->length()); |
| 1986 | 1986 |
| 1987 // Process each export in the export table (go in reverse so asm.js | 1987 // Process each export in the export table (go in reverse so asm.js |
| 1988 // can skip duplicates). | 1988 // can skip duplicates). |
| 1989 for (auto exp : base::Reversed(module_->export_table)) { | 1989 for (auto exp : base::Reversed(module_->export_table)) { |
| 1990 Handle<String> name = | 1990 Handle<String> name = |
| 1991 WasmCompiledModule::ExtractUtf8StringFromModuleBytes( | 1991 WasmCompiledModule::ExtractUtf8StringFromModuleBytes( |
| 1992 isolate_, compiled_module_, exp.name_offset, exp.name_length) | 1992 isolate_, compiled_module_, exp.name_offset, exp.name_length) |
| 1993 .ToHandleChecked(); | 1993 .ToHandleChecked(); |
| 1994 Handle<JSObject> export_to; | 1994 Handle<JSObject> export_to; |
| 1995 if (module_->origin == kAsmJsOrigin && exp.kind == kExternalFunction && | 1995 if (module_->is_asm_js() && exp.kind == kExternalFunction && |
| 1996 (String::Equals(name, foreign_init_name) || | 1996 (String::Equals(name, foreign_init_name) || |
| 1997 String::Equals(name, single_function_name))) { | 1997 String::Equals(name, single_function_name))) { |
| 1998 export_to = instance; | 1998 export_to = instance; |
| 1999 } else { | 1999 } else { |
| 2000 export_to = exports_object; | 2000 export_to = exports_object; |
| 2001 } | 2001 } |
| 2002 | 2002 |
| 2003 switch (exp.kind) { | 2003 switch (exp.kind) { |
| 2004 case kExternalFunction: { | 2004 case kExternalFunction: { |
| 2005 // Wrap and export the code as a JSFunction. | 2005 // Wrap and export the code as a JSFunction. |
| 2006 WasmFunction& function = module_->functions[exp.index]; | 2006 WasmFunction& function = module_->functions[exp.index]; |
| 2007 int func_index = | 2007 int func_index = |
| 2008 static_cast<int>(module_->functions.size() + --export_index); | 2008 static_cast<int>(module_->functions.size() + --export_index); |
| 2009 Handle<JSFunction> js_function = js_wrappers_[exp.index]; | 2009 Handle<JSFunction> js_function = js_wrappers_[exp.index]; |
| 2010 if (js_function.is_null()) { | 2010 if (js_function.is_null()) { |
| 2011 // Wrap the exported code as a JSFunction. | 2011 // Wrap the exported code as a JSFunction. |
| 2012 Handle<Code> export_code = | 2012 Handle<Code> export_code = |
| 2013 code_table->GetValueChecked<Code>(isolate_, func_index); | 2013 code_table->GetValueChecked<Code>(isolate_, func_index); |
| 2014 MaybeHandle<String> func_name; | 2014 MaybeHandle<String> func_name; |
| 2015 if (module_->origin == kAsmJsOrigin) { | 2015 if (module_->is_asm_js()) { |
| 2016 // For modules arising from asm.js, honor the names section. | 2016 // For modules arising from asm.js, honor the names section. |
| 2017 func_name = WasmCompiledModule::ExtractUtf8StringFromModuleBytes( | 2017 func_name = WasmCompiledModule::ExtractUtf8StringFromModuleBytes( |
| 2018 isolate_, compiled_module_, function.name_offset, | 2018 isolate_, compiled_module_, function.name_offset, |
| 2019 function.name_length) | 2019 function.name_length) |
| 2020 .ToHandleChecked(); | 2020 .ToHandleChecked(); |
| 2021 } | 2021 } |
| 2022 js_function = WasmExportedFunction::New( | 2022 js_function = WasmExportedFunction::New( |
| 2023 isolate_, instance, func_name, function.func_index, | 2023 isolate_, instance, func_name, function.func_index, |
| 2024 static_cast<int>(function.sig->parameter_count()), export_code); | 2024 static_cast<int>(function.sig->parameter_count()), export_code); |
| 2025 js_wrappers_[exp.index] = js_function; | 2025 js_wrappers_[exp.index] = js_function; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2088 } | 2088 } |
| 2089 desc.set_value(isolate_->factory()->NewNumber(num)); | 2089 desc.set_value(isolate_->factory()->NewNumber(num)); |
| 2090 break; | 2090 break; |
| 2091 } | 2091 } |
| 2092 default: | 2092 default: |
| 2093 UNREACHABLE(); | 2093 UNREACHABLE(); |
| 2094 break; | 2094 break; |
| 2095 } | 2095 } |
| 2096 | 2096 |
| 2097 // Skip duplicates for asm.js. | 2097 // Skip duplicates for asm.js. |
| 2098 if (module_->origin == kAsmJsOrigin) { | 2098 if (module_->is_asm_js()) { |
| 2099 v8::Maybe<bool> status = JSReceiver::HasOwnProperty(export_to, name); | 2099 v8::Maybe<bool> status = JSReceiver::HasOwnProperty(export_to, name); |
| 2100 if (status.FromMaybe(false)) { | 2100 if (status.FromMaybe(false)) { |
| 2101 continue; | 2101 continue; |
| 2102 } | 2102 } |
| 2103 } | 2103 } |
| 2104 v8::Maybe<bool> status = JSReceiver::DefineOwnProperty( | 2104 v8::Maybe<bool> status = JSReceiver::DefineOwnProperty( |
| 2105 isolate_, export_to, name, &desc, Object::THROW_ON_ERROR); | 2105 isolate_, export_to, name, &desc, Object::THROW_ON_ERROR); |
| 2106 if (!status.IsJust()) { | 2106 if (!status.IsJust()) { |
| 2107 thrower_->LinkError("export of %.*s failed.", name->length(), | 2107 thrower_->LinkError("export of %.*s failed.", name->length(), |
| 2108 name->ToCString().get()); | 2108 name->ToCString().get()); |
| 2109 return; | 2109 return; |
| 2110 } | 2110 } |
| 2111 } | 2111 } |
| 2112 | 2112 |
| 2113 if (module_->origin == kWasmOrigin) { | 2113 if (module_->is_wasm()) { |
| 2114 v8::Maybe<bool> success = JSReceiver::SetIntegrityLevel( | 2114 v8::Maybe<bool> success = JSReceiver::SetIntegrityLevel( |
| 2115 exports_object, FROZEN, Object::DONT_THROW); | 2115 exports_object, FROZEN, Object::DONT_THROW); |
| 2116 DCHECK(success.FromMaybe(false)); | 2116 DCHECK(success.FromMaybe(false)); |
| 2117 USE(success); | 2117 USE(success); |
| 2118 } | 2118 } |
| 2119 } | 2119 } |
| 2120 | 2120 |
| 2121 void InitializeTables(Handle<FixedArray> code_table, | 2121 void InitializeTables(Handle<FixedArray> code_table, |
| 2122 Handle<WasmInstanceObject> instance, | 2122 Handle<WasmInstanceObject> instance, |
| 2123 CodeSpecialization* code_specialization) { | 2123 CodeSpecialization* code_specialization) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2238 if (js_wrappers_[func_index].is_null()) { | 2238 if (js_wrappers_[func_index].is_null()) { |
| 2239 // No JSFunction entry yet exists for this function. Create one. | 2239 // No JSFunction entry yet exists for this function. Create one. |
| 2240 // TODO(titzer): We compile JS->WASM wrappers for functions are | 2240 // TODO(titzer): We compile JS->WASM wrappers for functions are |
| 2241 // not exported but are in an exported table. This should be done | 2241 // not exported but are in an exported table. This should be done |
| 2242 // at module compile time and cached instead. | 2242 // at module compile time and cached instead. |
| 2243 | 2243 |
| 2244 Handle<Code> wrapper_code = | 2244 Handle<Code> wrapper_code = |
| 2245 js_to_wasm_cache_.CloneOrCompileJSToWasmWrapper( | 2245 js_to_wasm_cache_.CloneOrCompileJSToWasmWrapper( |
| 2246 isolate_, module_, wasm_code, func_index); | 2246 isolate_, module_, wasm_code, func_index); |
| 2247 MaybeHandle<String> func_name; | 2247 MaybeHandle<String> func_name; |
| 2248 if (module_->origin == kAsmJsOrigin) { | 2248 if (module_->is_asm_js()) { |
| 2249 // For modules arising from asm.js, honor the names section. | 2249 // For modules arising from asm.js, honor the names section. |
| 2250 func_name = | 2250 func_name = |
| 2251 WasmCompiledModule::ExtractUtf8StringFromModuleBytes( | 2251 WasmCompiledModule::ExtractUtf8StringFromModuleBytes( |
| 2252 isolate_, compiled_module_, function->name_offset, | 2252 isolate_, compiled_module_, function->name_offset, |
| 2253 function->name_length) | 2253 function->name_length) |
| 2254 .ToHandleChecked(); | 2254 .ToHandleChecked(); |
| 2255 } | 2255 } |
| 2256 Handle<WasmExportedFunction> js_function = | 2256 Handle<WasmExportedFunction> js_function = |
| 2257 WasmExportedFunction::New( | 2257 WasmExportedFunction::New( |
| 2258 isolate_, instance, func_name, func_index, | 2258 isolate_, instance, func_name, func_index, |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3209 callee_compiled->instruction_start()); | 3209 callee_compiled->instruction_start()); |
| 3210 } | 3210 } |
| 3211 DCHECK_EQ(non_compiled_functions.size(), idx); | 3211 DCHECK_EQ(non_compiled_functions.size(), idx); |
| 3212 } | 3212 } |
| 3213 | 3213 |
| 3214 Code* ret = | 3214 Code* ret = |
| 3215 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 3215 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
| 3216 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 3216 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
| 3217 return handle(ret, isolate); | 3217 return handle(ret, isolate); |
| 3218 } | 3218 } |
| OLD | NEW |