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

Side by Side Diff: src/execution.cc

Issue 1756433002: [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 SaveContext save(isolate);
67 isolate->set_context(function->context());
68 // Do proper receiver conversion for non-strict mode api functions.
69 if (!receiver->IsJSReceiver() &&
70 is_sloppy(function->shared()->language_mode())) {
71 if (receiver->IsUndefined() || receiver->IsNull()) {
72 if (is_construct) {
73 receiver = isolate->factory()->the_hole_value();
74 } else {
75 receiver = handle(function->global_proxy(), isolate);
76 }
77 } else {
78 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
79 Object::ToObject(isolate, receiver), Object);
80 }
81 }
82 DCHECK(function->context()->global_object()->IsJSGlobalObject());
83 auto value = Builtins::InvokeApiFunction(is_construct, function, receiver,
84 argc, args);
85 bool has_exception = value.is_null();
86 DCHECK(has_exception == isolate->has_pending_exception());
87 if (has_exception) {
88 isolate->ReportPendingMessages();
89 return MaybeHandle<Object>();
90 } else {
91 isolate->clear_pending_message();
92 }
93 return value;
94 }
95
62 // Entering JavaScript. 96 // Entering JavaScript.
63 VMState<JS> state(isolate); 97 VMState<JS> state(isolate);
64 CHECK(AllowJavascriptExecution::IsAllowed(isolate)); 98 CHECK(AllowJavascriptExecution::IsAllowed(isolate));
65 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) { 99 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) {
66 isolate->ThrowIllegalOperation(); 100 isolate->ThrowIllegalOperation();
67 isolate->ReportPendingMessages(); 101 isolate->ReportPendingMessages();
68 return MaybeHandle<Object>(); 102 return MaybeHandle<Object>();
69 } 103 }
70 104
71 // Placeholder for return value. 105 // 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, 158 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable,
125 Handle<Object> receiver, int argc, 159 Handle<Object> receiver, int argc,
126 Handle<Object> argv[]) { 160 Handle<Object> argv[]) {
127 // Convert calls on global objects to be calls on the global 161 // Convert calls on global objects to be calls on the global
128 // receiver instead to avoid having a 'this' pointer which refers 162 // receiver instead to avoid having a 'this' pointer which refers
129 // directly to a global object. 163 // directly to a global object.
130 if (receiver->IsJSGlobalObject()) { 164 if (receiver->IsJSGlobalObject()) {
131 receiver = 165 receiver =
132 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate); 166 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate);
133 } 167 }
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, 168 return Invoke(isolate, false, callable, receiver, argc, argv,
164 isolate->factory()->undefined_value()); 169 isolate->factory()->undefined_value());
165 } 170 }
166 171
167 172
168 // static 173 // static
169 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc, 174 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc,
170 Handle<Object> argv[]) { 175 Handle<Object> argv[]) {
171 return New(constructor->GetIsolate(), constructor, constructor, argc, argv); 176 return New(constructor->GetIsolate(), constructor, constructor, argc, argv);
172 } 177 }
173 178
174 179
175 // static 180 // static
176 MaybeHandle<Object> Execution::New(Isolate* isolate, Handle<Object> constructor, 181 MaybeHandle<Object> Execution::New(Isolate* isolate, Handle<Object> constructor,
177 Handle<Object> new_target, int argc, 182 Handle<Object> new_target, int argc,
178 Handle<Object> argv[]) { 183 Handle<Object> argv[]) {
184 if (!constructor->IsConstructor() &&
Toon Verwaest 2016/03/01 17:30:35 Move up to the fast-path in the is_construct case.
185 (!constructor->IsJSFunction() ||
186 !Handle<JSFunction>::cast(constructor)->shared()->is_generator())) {
187 THROW_NEW_ERROR(isolate,
188 NewTypeError(MessageTemplate::kNotConstructor, constructor),
189 Object);
190 }
179 return Invoke(isolate, true, constructor, 191 return Invoke(isolate, true, constructor,
180 isolate->factory()->undefined_value(), argc, argv, new_target); 192 isolate->factory()->undefined_value(), argc, argv, new_target);
181 } 193 }
182 194
183 195
184 MaybeHandle<Object> Execution::TryCall(Isolate* isolate, 196 MaybeHandle<Object> Execution::TryCall(Isolate* isolate,
185 Handle<Object> callable, 197 Handle<Object> callable,
186 Handle<Object> receiver, int argc, 198 Handle<Object> receiver, int argc,
187 Handle<Object> args[], 199 Handle<Object> args[],
188 MaybeHandle<Object>* exception_out) { 200 MaybeHandle<Object>* exception_out) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 492
481 isolate_->counters()->stack_interrupts()->Increment(); 493 isolate_->counters()->stack_interrupts()->Increment();
482 isolate_->counters()->runtime_profiler_ticks()->Increment(); 494 isolate_->counters()->runtime_profiler_ticks()->Increment();
483 isolate_->runtime_profiler()->MarkCandidatesForOptimization(); 495 isolate_->runtime_profiler()->MarkCandidatesForOptimization();
484 496
485 return isolate_->heap()->undefined_value(); 497 return isolate_->heap()->undefined_value();
486 } 498 }
487 499
488 } // namespace internal 500 } // namespace internal
489 } // namespace v8 501 } // 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