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

Unified Diff: src/compiler/wasm-compiler.cc

Issue 2208703002: [wasm] Allow import function to be any kind of callables. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Create a native context at the beginning of all tests in test-run-wasm-js.cc Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
Index: src/compiler/wasm-compiler.cc
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
index 421066ee683682b17d5fee9a02ee7ef55441b951..d90367103b3a66faf72b71689adebe2689e4764b 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -2704,9 +2704,10 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
MergeControlToEnd(jsgraph(), ret);
}
-void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSFunction> function,
+void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
wasm::FunctionSig* sig) {
- int js_count = function->shared()->internal_formal_parameter_count();
+ DCHECK(target->IsCallable());
+
int wasm_count = static_cast<int>(sig->parameter_count());
int param_count;
if (jsgraph()->machine()->Is64()) {
@@ -2722,40 +2723,29 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSFunction> function,
*effect_ = start;
*control_ = start;
// JS context is the last parameter.
- Node* context = HeapConstant(Handle<Context>(function->context(), isolate));
+ Node* context = HeapConstant(isolate->native_context());
Benedikt Meurer 2016/08/03 17:14:43 Uhm, that looks weird. Are you really sure that th
ahaas 2016/08/09 14:34:54 Done.
Node** args = Buffer(wasm_count + 7);
bool arg_count_before_args = false;
bool add_new_target_undefined = false;
int pos = 0;
- if (js_count == wasm_count) {
- // exact arity match, just call the function directly.
- desc = Linkage::GetJSCallDescriptor(graph()->zone(), false, wasm_count + 1,
+
+ // Use the Call builtin.
titzer 2016/08/03 16:33:49 Always using the builtin does increase the overhea
ahaas 2016/08/09 14:34:54 I reintroduced this optimization now for the case
+ Callable callable = CodeFactory::Call(isolate);
+ args[pos++] = jsgraph()->HeapConstant(callable.code());
+ desc = Linkage::GetStubCallDescriptor(isolate, graph()->zone(),
+ callable.descriptor(), wasm_count + 1,
CallDescriptor::kNoFlags);
- arg_count_before_args = false;
- add_new_target_undefined = true;
- } else {
- // Use the Call builtin.
- Callable callable = CodeFactory::Call(isolate);
- args[pos++] = jsgraph()->HeapConstant(callable.code());
- desc = Linkage::GetStubCallDescriptor(isolate, graph()->zone(),
- callable.descriptor(), wasm_count + 1,
- CallDescriptor::kNoFlags);
- arg_count_before_args = true;
- }
+ arg_count_before_args = true;
- args[pos++] = jsgraph()->Constant(function); // JS function.
+ args[pos++] = jsgraph()->Constant(target); // JS function.
Benedikt Meurer 2016/08/03 17:14:43 Nit: Update comment.
ahaas 2016/08/09 14:34:54 Done.
if (arg_count_before_args) {
args[pos++] = jsgraph()->Int32Constant(wasm_count); // argument count
}
// Create the receiver constant (either undefined or the global proxy).
Handle<Object> receiver(isolate->heap()->undefined_value(), isolate);
- if (is_sloppy(function->shared()->language_mode())) {
- receiver = Handle<Object>(function->context()->global_proxy(), isolate);
- }
args[pos++] = jsgraph()->Constant(receiver);
-
// Convert WASM numbers to JS values.
int param_index = 0;
for (int i = 0; i < wasm_count; ++i) {
@@ -3224,8 +3214,7 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module,
return code;
}
-Handle<Code> CompileWasmToJSWrapper(Isolate* isolate,
- Handle<JSFunction> function,
+Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
wasm::FunctionSig* sig, uint32_t index,
Handle<String> import_module,
MaybeHandle<String> import_function) {
@@ -3244,7 +3233,7 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate,
WasmGraphBuilder builder(&zone, &jsgraph, sig);
builder.set_control_ptr(&control);
builder.set_effect_ptr(&effect);
- builder.BuildWasmToJSWrapper(function, sig);
+ builder.BuildWasmToJSWrapper(target, sig);
Handle<Code> code = Handle<Code>::null();
{
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/wasm/wasm-module.cc » ('j') | test/mjsunit/wasm/ffi.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698