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

Side by Side Diff: src/execution.cc

Issue 1767663002: Revert of 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()) {
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
101 // Entering JavaScript. 62 // Entering JavaScript.
102 VMState<JS> state(isolate); 63 VMState<JS> state(isolate);
103 CHECK(AllowJavascriptExecution::IsAllowed(isolate)); 64 CHECK(AllowJavascriptExecution::IsAllowed(isolate));
104 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) { 65 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) {
105 isolate->ThrowIllegalOperation(); 66 isolate->ThrowIllegalOperation();
106 isolate->ReportPendingMessages(); 67 isolate->ReportPendingMessages();
107 return MaybeHandle<Object>(); 68 return MaybeHandle<Object>();
108 } 69 }
109 70
110 // Placeholder for return value. 71 // Placeholder for return value.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable, 124 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable,
164 Handle<Object> receiver, int argc, 125 Handle<Object> receiver, int argc,
165 Handle<Object> argv[]) { 126 Handle<Object> argv[]) {
166 // Convert calls on global objects to be calls on the global 127 // Convert calls on global objects to be calls on the global
167 // receiver instead to avoid having a 'this' pointer which refers 128 // receiver instead to avoid having a 'this' pointer which refers
168 // directly to a global object. 129 // directly to a global object.
169 if (receiver->IsJSGlobalObject()) { 130 if (receiver->IsJSGlobalObject()) {
170 receiver = 131 receiver =
171 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate); 132 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate);
172 } 133 }
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 }
173 return Invoke(isolate, false, callable, receiver, argc, argv, 163 return Invoke(isolate, false, callable, receiver, argc, argv,
174 isolate->factory()->undefined_value()); 164 isolate->factory()->undefined_value());
175 } 165 }
176 166
177 167
178 // static 168 // static
179 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc, 169 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc,
180 Handle<Object> argv[]) { 170 Handle<Object> argv[]) {
181 return New(constructor->GetIsolate(), constructor, constructor, argc, argv); 171 return New(constructor->GetIsolate(), constructor, constructor, argc, argv);
182 } 172 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 480
491 isolate_->counters()->stack_interrupts()->Increment(); 481 isolate_->counters()->stack_interrupts()->Increment();
492 isolate_->counters()->runtime_profiler_ticks()->Increment(); 482 isolate_->counters()->runtime_profiler_ticks()->Increment();
493 isolate_->runtime_profiler()->MarkCandidatesForOptimization(); 483 isolate_->runtime_profiler()->MarkCandidatesForOptimization();
494 484
495 return isolate_->heap()->undefined_value(); 485 return isolate_->heap()->undefined_value();
496 } 486 }
497 487
498 } // namespace internal 488 } // namespace internal
499 } // namespace v8 489 } // 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