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

Side by Side 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, 9 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 unified diff | Download patch
« no previous file with comments | « src/builtins.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "src/execution.h" 5 #include "src/execution.h"
6 6
7 #include "src/bootstrapper.h" 7 #include "src/bootstrapper.h"
8 #include "src/codegen.h" 8 #include "src/codegen.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 namespace { 53 namespace {
54 54
55 MUST_USE_RESULT MaybeHandle<Object> Invoke(Isolate* isolate, bool is_construct, 55 MUST_USE_RESULT MaybeHandle<Object> Invoke(Isolate* isolate, bool is_construct,
56 Handle<Object> target, 56 Handle<Object> target,
57 Handle<Object> receiver, int argc, 57 Handle<Object> receiver, int argc,
58 Handle<Object> args[], 58 Handle<Object> args[],
59 Handle<Object> new_target) { 59 Handle<Object> new_target) {
60 DCHECK(!receiver->IsJSGlobalObject()); 60 DCHECK(!receiver->IsJSGlobalObject());
61 61
62 // API callbacks can be called directly.
63 if (target->IsJSFunction() &&
64 Handle<JSFunction>::cast(target)->shared()->IsApiFunction()) {
65 Handle<JSFunction> function = Handle<JSFunction>::cast(target);
66 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
67 THROW_NEW_ERROR(isolate,
68 NewTypeError(MessageTemplate::kNotConstructor, function),
69 Object);
70 }
71 SaveContext save(isolate);
72 isolate->set_context(function->context());
73 // Do proper receiver conversion for non-strict mode api functions.
74 if (!receiver->IsJSReceiver() &&
75 is_sloppy(function->shared()->language_mode())) {
76 if (receiver->IsUndefined() || receiver->IsNull()) {
77 if (is_construct) {
78 receiver = isolate->factory()->the_hole_value();
79 } else {
80 receiver = handle(function->global_proxy(), isolate);
81 }
82 } else {
83 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
84 Object::ToObject(isolate, receiver), Object);
85 }
86 }
87 DCHECK(function->context()->global_object()->IsJSGlobalObject());
88 auto value = Builtins::InvokeApiFunction(is_construct, function, receiver,
89 argc, args);
90 bool has_exception = value.is_null();
91 DCHECK(has_exception == isolate->has_pending_exception());
92 if (has_exception) {
93 isolate->ReportPendingMessages();
94 return MaybeHandle<Object>();
95 } else {
96 isolate->clear_pending_message();
97 }
98 return value;
99 }
100
62 // Entering JavaScript. 101 // Entering JavaScript.
63 VMState<JS> state(isolate); 102 VMState<JS> state(isolate);
64 CHECK(AllowJavascriptExecution::IsAllowed(isolate)); 103 CHECK(AllowJavascriptExecution::IsAllowed(isolate));
65 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) { 104 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) {
66 isolate->ThrowIllegalOperation(); 105 isolate->ThrowIllegalOperation();
67 isolate->ReportPendingMessages(); 106 isolate->ReportPendingMessages();
68 return MaybeHandle<Object>(); 107 return MaybeHandle<Object>();
69 } 108 }
70 109
71 // Placeholder for return value. 110 // Placeholder for return value.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable, 163 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable,
125 Handle<Object> receiver, int argc, 164 Handle<Object> receiver, int argc,
126 Handle<Object> argv[]) { 165 Handle<Object> argv[]) {
127 // Convert calls on global objects to be calls on the global 166 // Convert calls on global objects to be calls on the global
128 // receiver instead to avoid having a 'this' pointer which refers 167 // receiver instead to avoid having a 'this' pointer which refers
129 // directly to a global object. 168 // directly to a global object.
130 if (receiver->IsJSGlobalObject()) { 169 if (receiver->IsJSGlobalObject()) {
131 receiver = 170 receiver =
132 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate); 171 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate);
133 } 172 }
134
135 // api callbacks can be called directly.
136 if (callable->IsJSFunction() &&
137 Handle<JSFunction>::cast(callable)->shared()->IsApiFunction()) {
138 Handle<JSFunction> function = Handle<JSFunction>::cast(callable);
139 SaveContext save(isolate);
140 isolate->set_context(function->context());
141 // Do proper receiver conversion for non-strict mode api functions.
142 if (!receiver->IsJSReceiver() &&
143 is_sloppy(function->shared()->language_mode())) {
144 if (receiver->IsUndefined() || receiver->IsNull()) {
145 receiver = handle(function->global_proxy(), isolate);
146 } else {
147 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
148 Object::ToObject(isolate, receiver), Object);
149 }
150 }
151 DCHECK(function->context()->global_object()->IsJSGlobalObject());
152 auto value = Builtins::InvokeApiFunction(function, receiver, argc, argv);
153 bool has_exception = value.is_null();
154 DCHECK(has_exception == isolate->has_pending_exception());
155 if (has_exception) {
156 isolate->ReportPendingMessages();
157 return MaybeHandle<Object>();
158 } else {
159 isolate->clear_pending_message();
160 }
161 return value;
162 }
163 return Invoke(isolate, false, callable, receiver, argc, argv, 173 return Invoke(isolate, false, callable, receiver, argc, argv,
164 isolate->factory()->undefined_value()); 174 isolate->factory()->undefined_value());
165 } 175 }
166 176
167 177
168 // static 178 // static
169 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc, 179 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc,
170 Handle<Object> argv[]) { 180 Handle<Object> argv[]) {
171 return New(constructor->GetIsolate(), constructor, constructor, argc, argv); 181 return New(constructor->GetIsolate(), constructor, constructor, argc, argv);
172 } 182 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 490
481 isolate_->counters()->stack_interrupts()->Increment(); 491 isolate_->counters()->stack_interrupts()->Increment();
482 isolate_->counters()->runtime_profiler_ticks()->Increment(); 492 isolate_->counters()->runtime_profiler_ticks()->Increment();
483 isolate_->runtime_profiler()->MarkCandidatesForOptimization(); 493 isolate_->runtime_profiler()->MarkCandidatesForOptimization();
484 494
485 return isolate_->heap()->undefined_value(); 495 return isolate_->heap()->undefined_value();
486 } 496 }
487 497
488 } // namespace internal 498 } // namespace internal
489 } // namespace v8 499 } // namespace v8
OLDNEW
« 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