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

Unified Diff: src/execution.cc

Issue 1756973002: Reland "[api] Don't go to javascript to construct API functions" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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.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 e6a569f33d967d66bdfc0065ef10c7117a3a091a..5f24e5e336b373d91d3294d4d9e37e14b367162a 100644
--- a/src/execution.cc
+++ b/src/execution.cc
@@ -59,6 +59,45 @@ MUST_USE_RESULT MaybeHandle<Object> Invoke(Isolate* isolate, bool is_construct,
Handle<Object> new_target) {
DCHECK(!receiver->IsJSGlobalObject());
+ // API callbacks can be called directly.
+ if (target->IsJSFunction() &&
+ Handle<JSFunction>::cast(target)->shared()->IsApiFunction()) {
+ Handle<JSFunction> function = Handle<JSFunction>::cast(target);
+ if (is_construct && !function->IsConstructor()) {
jochen (gone - plz use gerrit) 2016/03/02 18:15:54 in the original CL, the is_construct && was missin
+ THROW_NEW_ERROR(isolate,
+ NewTypeError(MessageTemplate::kNotConstructor, function),
+ Object);
+ }
+ SaveContext save(isolate);
+ isolate->set_context(function->context());
+ // Do proper receiver conversion for non-strict mode api functions.
+ if (!receiver->IsJSReceiver() &&
+ is_sloppy(function->shared()->language_mode())) {
+ if (receiver->IsUndefined() || receiver->IsNull()) {
+ if (is_construct) {
+ receiver = isolate->factory()->the_hole_value();
+ } else {
+ receiver = handle(function->global_proxy(), isolate);
+ }
+ } else {
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
+ Object::ToObject(isolate, receiver), Object);
+ }
+ }
+ DCHECK(function->context()->global_object()->IsJSGlobalObject());
+ auto value = Builtins::InvokeApiFunction(is_construct, function, receiver,
+ argc, args);
+ 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));
@@ -131,35 +170,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());
- // Do proper receiver conversion for non-strict mode api functions.
- if (!receiver->IsJSReceiver() &&
- is_sloppy(function->shared()->language_mode())) {
- if (receiver->IsUndefined() || receiver->IsNull()) {
- receiver = handle(function->global_proxy(), isolate);
- } else {
- ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
- Object::ToObject(isolate, receiver), Object);
- }
- }
- DCHECK(function->context()->global_object()->IsJSGlobalObject());
- auto value = Builtins::InvokeApiFunction(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.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698