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

Unified Diff: src/execution.cc

Issue 2203353002: [api] Stay in C++ when constructing an API-function (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: set the receiver to the_hole for construct calls 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
« no previous file with comments | « src/builtins/builtins-api.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/execution.cc
diff --git a/src/execution.cc b/src/execution.cc
index 4ec18f87353255809d8545ec8ecee22e7e60dc2a..f4c48740db764fc70878df43437a15bdfce4bd83 100644
--- a/src/execution.cc
+++ b/src/execution.cc
@@ -72,6 +72,30 @@ MUST_USE_RESULT MaybeHandle<Object> Invoke(Isolate* isolate, bool is_construct,
}
#endif
+ // api callbacks can be called directly.
+ if (target->IsJSFunction()) {
+ Handle<JSFunction> function = Handle<JSFunction>::cast(target);
+ if ((!is_construct || function->IsConstructor()) &&
+ function->shared()->IsApiFunction()) {
+ SaveContext save(isolate);
+ isolate->set_context(function->context());
+ DCHECK(function->context()->global_object()->IsJSGlobalObject());
+ if (is_construct) receiver = isolate->factory()->the_hole_value();
+ auto value = Builtins::InvokeApiFunction(
+ isolate, is_construct, function, receiver, argc, args,
+ Handle<HeapObject>::cast(new_target));
+ bool has_exception = value.is_null();
+ DCHECK(has_exception == isolate->has_pending_exception());
+ if (has_exception) {
+ isolate->ReportPendingMessages();
+ return MaybeHandle<Object>();
+ } else {
+ isolate->clear_pending_message();
+ }
+ return value;
+ }
+ }
+
// Entering JavaScript.
VMState<JS> state(isolate);
CHECK(AllowJavascriptExecution::IsAllowed(isolate));
@@ -145,26 +169,6 @@ MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable,
receiver =
handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate);
}
-
- // api callbacks can be called directly.
- if (callable->IsJSFunction() &&
- Handle<JSFunction>::cast(callable)->shared()->IsApiFunction()) {
- Handle<JSFunction> function = Handle<JSFunction>::cast(callable);
- SaveContext save(isolate);
- isolate->set_context(function->context());
- DCHECK(function->context()->global_object()->IsJSGlobalObject());
- auto value =
- Builtins::InvokeApiFunction(isolate, function, receiver, argc, argv);
- bool has_exception = value.is_null();
- DCHECK(has_exception == isolate->has_pending_exception());
- if (has_exception) {
- isolate->ReportPendingMessages();
- return MaybeHandle<Object>();
- } else {
- isolate->clear_pending_message();
- }
- return value;
- }
return Invoke(isolate, false, callable, receiver, argc, argv,
isolate->factory()->undefined_value());
}
« no previous file with comments | « src/builtins/builtins-api.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698