Commit f897e36c authored by titzer's avatar titzer Committed by Commit bot

[wasm] Names of exported functions should be the stringified function index.

R=bradnelson@chromium.org,rossberg@chromium.org
BUG=v8:5705

Review-Url: https://codereview.chromium.org/2551323003
Cr-Commit-Position: refs/heads/master@{#41530}
parent 051bc1ec
...@@ -1338,8 +1338,8 @@ class WasmInstanceBuilder { ...@@ -1338,8 +1338,8 @@ class WasmInstanceBuilder {
Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper( Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper(
isolate_, module_, startup_code, start_index); isolate_, module_, startup_code, start_index);
Handle<WasmExportedFunction> startup_fct = WasmExportedFunction::New( Handle<WasmExportedFunction> startup_fct = WasmExportedFunction::New(
isolate_, instance, factory->InternalizeUtf8String("start"), isolate_, instance, MaybeHandle<String>(), start_index,
wrapper_code, static_cast<int>(sig->parameter_count()), start_index); static_cast<int>(sig->parameter_count()), wrapper_code);
RecordStats(isolate_, *startup_code); RecordStats(isolate_, *startup_code);
// Call the JS function. // Call the JS function.
Handle<Object> undefined = factory->undefined_value(); Handle<Object> undefined = factory->undefined_value();
...@@ -1760,7 +1760,7 @@ class WasmInstanceBuilder { ...@@ -1760,7 +1760,7 @@ class WasmInstanceBuilder {
// Wrap the exported code as a JSFunction. // Wrap the exported code as a JSFunction.
Handle<Code> export_code = Handle<Code> export_code =
code_table->GetValueChecked<Code>(isolate_, func_index); code_table->GetValueChecked<Code>(isolate_, func_index);
Handle<String> func_name = name; MaybeHandle<String> func_name;
if (module_->origin == kAsmJsOrigin) { if (module_->origin == kAsmJsOrigin) {
// For modules arising from asm.js, honor the names section. // For modules arising from asm.js, honor the names section.
func_name = ExtractStringFromModuleBytes( func_name = ExtractStringFromModuleBytes(
...@@ -1769,9 +1769,8 @@ class WasmInstanceBuilder { ...@@ -1769,9 +1769,8 @@ class WasmInstanceBuilder {
.ToHandleChecked(); .ToHandleChecked();
} }
js_function = WasmExportedFunction::New( js_function = WasmExportedFunction::New(
isolate_, instance, func_name, export_code, isolate_, instance, func_name, function.func_index,
static_cast<int>(function.sig->parameter_count()), static_cast<int>(function.sig->parameter_count()), export_code);
function.func_index);
js_wrappers_[exp.index] = js_function; js_wrappers_[exp.index] = js_function;
} }
desc.set_value(js_function); desc.set_value(js_function);
...@@ -1921,7 +1920,7 @@ class WasmInstanceBuilder { ...@@ -1921,7 +1920,7 @@ class WasmInstanceBuilder {
Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper( Handle<Code> wrapper_code = compiler::CompileJSToWasmWrapper(
isolate_, module_, wasm_code, func_index); isolate_, module_, wasm_code, func_index);
Handle<String> func_name = isolate_->factory()->empty_string(); MaybeHandle<String> func_name;
if (module_->origin == kAsmJsOrigin) { if (module_->origin == kAsmJsOrigin) {
// For modules arising from asm.js, honor the names section. // For modules arising from asm.js, honor the names section.
func_name = ExtractStringFromModuleBytes( func_name = ExtractStringFromModuleBytes(
...@@ -1931,9 +1930,9 @@ class WasmInstanceBuilder { ...@@ -1931,9 +1930,9 @@ class WasmInstanceBuilder {
} }
Handle<WasmExportedFunction> js_function = Handle<WasmExportedFunction> js_function =
WasmExportedFunction::New( WasmExportedFunction::New(
isolate_, instance, func_name, wrapper_code, isolate_, instance, func_name, func_index,
static_cast<int>(function->sig->parameter_count()), static_cast<int>(function->sig->parameter_count()),
func_index); wrapper_code);
js_wrappers_[func_index] = js_function; js_wrappers_[func_index] = js_function;
} }
table_instance.js_wrappers->set(table_index, table_instance.js_wrappers->set(table_index,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-objects.h"
#include "src/utils.h"
#include "src/wasm/module-decoder.h" #include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
...@@ -307,8 +308,20 @@ WasmExportedFunction* WasmExportedFunction::cast(Object* object) { ...@@ -307,8 +308,20 @@ WasmExportedFunction* WasmExportedFunction::cast(Object* object) {
} }
Handle<WasmExportedFunction> WasmExportedFunction::New( Handle<WasmExportedFunction> WasmExportedFunction::New(
Isolate* isolate, Handle<WasmInstanceObject> instance, Handle<String> name, Isolate* isolate, Handle<WasmInstanceObject> instance,
Handle<Code> export_wrapper, int arity, int func_index) { MaybeHandle<String> maybe_name, int func_index, int arity,
Handle<Code> export_wrapper) {
ScopedVector<char> buffer(16);
int length = SNPrintF(buffer, "%d", func_index);
Handle<String> name;
if (maybe_name.is_null()) {
name = isolate->factory()
->NewStringFromAscii(
Vector<const char>::cast(buffer.SubVector(0, length)))
.ToHandleChecked();
} else {
name = maybe_name.ToHandleChecked();
}
DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind()); DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind());
Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo> shared =
isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false); isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false);
......
...@@ -142,9 +142,9 @@ class WasmExportedFunction : public JSFunction { ...@@ -142,9 +142,9 @@ class WasmExportedFunction : public JSFunction {
static Handle<WasmExportedFunction> New(Isolate* isolate, static Handle<WasmExportedFunction> New(Isolate* isolate,
Handle<WasmInstanceObject> instance, Handle<WasmInstanceObject> instance,
Handle<String> name, MaybeHandle<String> maybe_name,
Handle<Code> export_wrapper, int func_index, int arity,
int arity, int func_index); Handle<Code> export_wrapper);
}; };
class WasmCompiledModule : public FixedArray { class WasmCompiledModule : public FixedArray {
......
...@@ -208,16 +208,15 @@ class TestingModule : public ModuleEnv { ...@@ -208,16 +208,15 @@ class TestingModule : public ModuleEnv {
Handle<JSFunction> WrapCode(uint32_t index) { Handle<JSFunction> WrapCode(uint32_t index) {
// Wrap the code so it can be called as a JS function. // Wrap the code so it can be called as a JS function.
Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main");
Handle<WasmInstanceObject> instance_obj(0, isolate_); Handle<WasmInstanceObject> instance_obj(0, isolate_);
Handle<Code> code = instance->function_code[index]; Handle<Code> code = instance->function_code[index];
WasmJs::InstallWasmMapsIfNeeded(isolate_, isolate_->native_context()); WasmJs::InstallWasmMapsIfNeeded(isolate_, isolate_->native_context());
Handle<Code> ret_code = Handle<Code> ret_code =
compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index); compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index);
Handle<JSFunction> ret = WasmExportedFunction::New( Handle<JSFunction> ret = WasmExportedFunction::New(
isolate_, instance_obj, name, ret_code, isolate_, instance_obj, MaybeHandle<String>(), static_cast<int>(index),
static_cast<int>(this->module->functions[index].sig->parameter_count()), static_cast<int>(this->module->functions[index].sig->parameter_count()),
static_cast<int>(index)); ret_code);
return ret; return ret;
} }
......
...@@ -98,7 +98,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -98,7 +98,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
print("TestExportMultipleIdentity..."); print("TestExportMultipleIdentity...");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("one", kSig_v_v).addBody([kExprNop]) var f = builder.addFunction("one", kSig_v_v).addBody([kExprNop])
.exportAs("a") .exportAs("a")
.exportAs("b") .exportAs("b")
.exportAs("c"); .exportAs("c");
...@@ -110,5 +110,5 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -110,5 +110,5 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals("function", typeof e.c); assertEquals("function", typeof e.c);
assertSame(e.a, e.b); assertSame(e.a, e.b);
assertSame(e.a, e.c); assertSame(e.a, e.c);
assertEquals("a", e.a.name); assertEquals(String(f.index), e.a.name);
})(); })();
...@@ -10,7 +10,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -10,7 +10,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestFunctionPrototype() { (function TestFunctionPrototype() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("nine", kSig_i_v) var f = builder.addFunction("nine", kSig_i_v)
.addBody([kExprI8Const, 9]) .addBody([kExprI8Const, 9])
.exportFunc(); .exportFunc();
...@@ -19,7 +19,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -19,7 +19,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
// Check type and existence of prototype // Check type and existence of prototype
assertEquals("function", typeof func.apply); assertEquals("function", typeof func.apply);
assertTrue(func.prototype != undefined); assertTrue(func.prototype != undefined);
assertEquals("nine", func.name); assertEquals(String(f.index), func.name);
assertEquals(undefined, func.displayName); assertEquals(undefined, func.displayName);
// Check that .apply() works. // Check that .apply() works.
......
...@@ -81,7 +81,7 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -81,7 +81,7 @@ function js_div(a, b) { return (a / b) | 0; }
assertEquals(2, mul.length); assertEquals(2, mul.length);
assertEquals(2, add.length); assertEquals(2, add.length);
assertEquals(2, sub.length); assertEquals(2, sub.length);
assertEquals("blarg", add.name); assertEquals(String(f.add.index), add.name);
let exp_div = table.get(i+3); let exp_div = table.get(i+3);
assertEquals("function", typeof exp_div); assertEquals("function", typeof exp_div);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment