Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2551323003: [wasm] Names of exported functions should be the stringified function index. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-objects.h » ('j') | src/wasm/wasm-objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/compiler/wasm-compiler.h" 9 #include "src/compiler/wasm-compiler.h"
10 #include "src/debug/interface-types.h" 10 #include "src/debug/interface-types.h"
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 //-------------------------------------------------------------------------- 1331 //--------------------------------------------------------------------------
1332 if (module_->start_function_index >= 0) { 1332 if (module_->start_function_index >= 0) {
1333 HandleScope scope(isolate_); 1333 HandleScope scope(isolate_);
1334 int start_index = module_->start_function_index; 1334 int start_index = module_->start_function_index;
1335 Handle<Code> startup_code = 1335 Handle<Code> startup_code =
1336 code_table->GetValueChecked<Code>(isolate_, start_index); 1336 code_table->GetValueChecked<Code>(isolate_, start_index);
1337 FunctionSig* sig = module_->functions[start_index].sig; 1337 FunctionSig* sig = module_->functions[start_index].sig;
1338 Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper( 1338 Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper(
1339 isolate_, module_, startup_code, start_index); 1339 isolate_, module_, startup_code, start_index);
1340 Handle<WasmExportedFunction> startup_fct = WasmExportedFunction::New( 1340 Handle<WasmExportedFunction> startup_fct = WasmExportedFunction::New(
1341 isolate_, instance, factory->InternalizeUtf8String("start"), 1341 isolate_, instance, MaybeHandle<String>(), start_index,
1342 wrapper_code, static_cast<int>(sig->parameter_count()), start_index); 1342 static_cast<int>(sig->parameter_count()), wrapper_code);
1343 RecordStats(isolate_, *startup_code); 1343 RecordStats(isolate_, *startup_code);
1344 // Call the JS function. 1344 // Call the JS function.
1345 Handle<Object> undefined = factory->undefined_value(); 1345 Handle<Object> undefined = factory->undefined_value();
1346 MaybeHandle<Object> retval = 1346 MaybeHandle<Object> retval =
1347 Execution::Call(isolate_, startup_fct, undefined, 0, nullptr); 1347 Execution::Call(isolate_, startup_fct, undefined, 0, nullptr);
1348 1348
1349 if (retval.is_null()) { 1349 if (retval.is_null()) {
1350 DCHECK(isolate_->has_pending_exception()); 1350 DCHECK(isolate_->has_pending_exception());
1351 isolate_->OptionalRescheduleException(false); 1351 isolate_->OptionalRescheduleException(false);
1352 // It's unfortunate that the new instance is already linked in the 1352 // It's unfortunate that the new instance is already linked in the
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 case kExternalFunction: { 1753 case kExternalFunction: {
1754 // Wrap and export the code as a JSFunction. 1754 // Wrap and export the code as a JSFunction.
1755 WasmFunction& function = module_->functions[exp.index]; 1755 WasmFunction& function = module_->functions[exp.index];
1756 int func_index = 1756 int func_index =
1757 static_cast<int>(module_->functions.size() + export_index); 1757 static_cast<int>(module_->functions.size() + export_index);
1758 Handle<JSFunction> js_function = js_wrappers_[exp.index]; 1758 Handle<JSFunction> js_function = js_wrappers_[exp.index];
1759 if (js_function.is_null()) { 1759 if (js_function.is_null()) {
1760 // Wrap the exported code as a JSFunction. 1760 // Wrap the exported code as a JSFunction.
1761 Handle<Code> export_code = 1761 Handle<Code> export_code =
1762 code_table->GetValueChecked<Code>(isolate_, func_index); 1762 code_table->GetValueChecked<Code>(isolate_, func_index);
1763 Handle<String> func_name = name; 1763 MaybeHandle<String> func_name;
1764 if (module_->origin == kAsmJsOrigin) { 1764 if (module_->origin == kAsmJsOrigin) {
1765 // For modules arising from asm.js, honor the names section. 1765 // For modules arising from asm.js, honor the names section.
1766 func_name = ExtractStringFromModuleBytes( 1766 func_name = ExtractStringFromModuleBytes(
1767 isolate_, compiled_module_, function.name_offset, 1767 isolate_, compiled_module_, function.name_offset,
1768 function.name_length) 1768 function.name_length)
1769 .ToHandleChecked(); 1769 .ToHandleChecked();
1770 } 1770 }
1771 js_function = WasmExportedFunction::New( 1771 js_function = WasmExportedFunction::New(
1772 isolate_, instance, func_name, export_code, 1772 isolate_, instance, func_name, function.func_index,
1773 static_cast<int>(function.sig->parameter_count()), 1773 static_cast<int>(function.sig->parameter_count()), export_code);
1774 function.func_index);
1775 js_wrappers_[exp.index] = js_function; 1774 js_wrappers_[exp.index] = js_function;
1776 } 1775 }
1777 desc.set_value(js_function); 1776 desc.set_value(js_function);
1778 export_index++; 1777 export_index++;
1779 break; 1778 break;
1780 } 1779 }
1781 case kExternalTable: { 1780 case kExternalTable: {
1782 // Export a table as a WebAssembly.Table object. 1781 // Export a table as a WebAssembly.Table object.
1783 TableInstance& table_instance = table_instances_[exp.index]; 1782 TableInstance& table_instance = table_instances_[exp.index];
1784 WasmIndirectFunctionTable& table = 1783 WasmIndirectFunctionTable& table =
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 // not exported but are in an exported table. This should be done 1913 // not exported but are in an exported table. This should be done
1915 // at module compile time and cached instead. 1914 // at module compile time and cached instead.
1916 WasmInstance temp_instance(module_); 1915 WasmInstance temp_instance(module_);
1917 temp_instance.context = isolate_->native_context(); 1916 temp_instance.context = isolate_->native_context();
1918 temp_instance.mem_size = 0; 1917 temp_instance.mem_size = 0;
1919 temp_instance.mem_start = nullptr; 1918 temp_instance.mem_start = nullptr;
1920 temp_instance.globals_start = nullptr; 1919 temp_instance.globals_start = nullptr;
1921 1920
1922 Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper( 1921 Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper(
1923 isolate_, module_, wasm_code, func_index); 1922 isolate_, module_, wasm_code, func_index);
1924 Handle<String> func_name = isolate_->factory()->empty_string(); 1923 MaybeHandle<String> func_name;
1925 if (module_->origin == kAsmJsOrigin) { 1924 if (module_->origin == kAsmJsOrigin) {
1926 // For modules arising from asm.js, honor the names section. 1925 // For modules arising from asm.js, honor the names section.
1927 func_name = ExtractStringFromModuleBytes( 1926 func_name = ExtractStringFromModuleBytes(
1928 isolate_, compiled_module_, 1927 isolate_, compiled_module_,
1929 function->name_offset, function->name_length) 1928 function->name_offset, function->name_length)
1930 .ToHandleChecked(); 1929 .ToHandleChecked();
1931 } 1930 }
1932 Handle<WasmExportedFunction> js_function = 1931 Handle<WasmExportedFunction> js_function =
1933 WasmExportedFunction::New( 1932 WasmExportedFunction::New(
1934 isolate_, instance, func_name, wrapper_code, 1933 isolate_, instance, func_name, func_index,
1935 static_cast<int>(function->sig->parameter_count()), 1934 static_cast<int>(function->sig->parameter_count()),
1936 func_index); 1935 wrapper_code);
1937 js_wrappers_[func_index] = js_function; 1936 js_wrappers_[func_index] = js_function;
1938 } 1937 }
1939 table_instance.js_wrappers->set(table_index, 1938 table_instance.js_wrappers->set(table_index,
1940 *js_wrappers_[func_index]); 1939 *js_wrappers_[func_index]);
1941 1940
1942 UpdateDispatchTablesInternal(isolate_, all_dispatch_tables, 1941 UpdateDispatchTablesInternal(isolate_, all_dispatch_tables,
1943 table_index, function, wasm_code); 1942 table_index, function, wasm_code);
1944 } 1943 }
1945 } 1944 }
1946 } 1945 }
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 MaybeHandle<String> WasmCompiledModule::GetFunctionName( 2371 MaybeHandle<String> WasmCompiledModule::GetFunctionName(
2373 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { 2372 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) {
2374 DCHECK_LT(func_index, compiled_module->module()->functions.size()); 2373 DCHECK_LT(func_index, compiled_module->module()->functions.size());
2375 WasmFunction& function = compiled_module->module()->functions[func_index]; 2374 WasmFunction& function = compiled_module->module()->functions[func_index];
2376 Isolate* isolate = compiled_module->GetIsolate(); 2375 Isolate* isolate = compiled_module->GetIsolate();
2377 MaybeHandle<String> string = ExtractStringFromModuleBytes( 2376 MaybeHandle<String> string = ExtractStringFromModuleBytes(
2378 isolate, compiled_module, function.name_offset, function.name_length); 2377 isolate, compiled_module, function.name_offset, function.name_length);
2379 if (!string.is_null()) return string.ToHandleChecked(); 2378 if (!string.is_null()) return string.ToHandleChecked();
2380 return {}; 2379 return {};
2381 } 2380 }
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-objects.h » ('j') | src/wasm/wasm-objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698