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

Side by Side Diff: src/execution.cc

Issue 1346763005: Revert of [runtime] Initial step towards switching Execution::Call to callable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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/execution.h ('k') | src/ia32/builtins-ia32.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/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 Object* name = Script::cast(script)->name(); 46 Object* name = Script::cast(script)->name();
47 if (name->IsString()) { 47 if (name->IsString()) {
48 PrintF(": %s", String::cast(name)->ToCString().get()); 48 PrintF(": %s", String::cast(name)->ToCString().get());
49 } 49 }
50 } 50 }
51 PrintF("]\n"); 51 PrintF("]\n");
52 } 52 }
53 } 53 }
54 54
55 55
56 namespace { 56 MUST_USE_RESULT static MaybeHandle<Object> Invoke(
57 57 bool is_construct,
58 MUST_USE_RESULT MaybeHandle<Object> Invoke(bool is_construct, 58 Handle<JSFunction> function,
59 Handle<JSFunction> function, 59 Handle<Object> receiver,
60 Handle<Object> receiver, int argc, 60 int argc,
61 Handle<Object> args[]) { 61 Handle<Object> args[]) {
62 Isolate* const isolate = function->GetIsolate(); 62 Isolate* isolate = function->GetIsolate();
63
64 // Convert calls on global objects to be calls on the global
65 // receiver instead to avoid having a 'this' pointer which refers
66 // directly to a global object.
67 if (receiver->IsGlobalObject()) {
68 receiver =
69 handle(Handle<GlobalObject>::cast(receiver)->global_proxy(), isolate);
70 }
71 63
72 // api callbacks can be called directly. 64 // api callbacks can be called directly.
73 if (!is_construct && function->shared()->IsApiFunction()) { 65 if (!is_construct && function->shared()->IsApiFunction()) {
74 SaveContext save(isolate); 66 SaveContext save(isolate);
75 isolate->set_context(function->context()); 67 isolate->set_context(function->context());
68 if (receiver->IsGlobalObject()) {
69 receiver = handle(Handle<GlobalObject>::cast(receiver)->global_proxy());
70 }
76 DCHECK(function->context()->global_object()->IsGlobalObject()); 71 DCHECK(function->context()->global_object()->IsGlobalObject());
77 auto value = Builtins::InvokeApiFunction(function, receiver, argc, args); 72 auto value = Builtins::InvokeApiFunction(function, receiver, argc, args);
78 bool has_exception = value.is_null(); 73 bool has_exception = value.is_null();
79 DCHECK(has_exception == isolate->has_pending_exception()); 74 DCHECK(has_exception == isolate->has_pending_exception());
80 if (has_exception) { 75 if (has_exception) {
81 isolate->ReportPendingMessages(); 76 isolate->ReportPendingMessages();
82 return MaybeHandle<Object>(); 77 return MaybeHandle<Object>();
83 } else { 78 } else {
84 isolate->clear_pending_message(); 79 isolate->clear_pending_message();
85 } 80 }
(...skipping 15 matching lines...) Expand all
101 typedef Object* (*JSEntryFunction)(byte* entry, 96 typedef Object* (*JSEntryFunction)(byte* entry,
102 Object* function, 97 Object* function,
103 Object* receiver, 98 Object* receiver,
104 int argc, 99 int argc,
105 Object*** args); 100 Object*** args);
106 101
107 Handle<Code> code = is_construct 102 Handle<Code> code = is_construct
108 ? isolate->factory()->js_construct_entry_code() 103 ? isolate->factory()->js_construct_entry_code()
109 : isolate->factory()->js_entry_code(); 104 : isolate->factory()->js_entry_code();
110 105
106 // Convert calls on global objects to be calls on the global
107 // receiver instead to avoid having a 'this' pointer which refers
108 // directly to a global object.
109 if (receiver->IsGlobalObject()) {
110 receiver = handle(Handle<GlobalObject>::cast(receiver)->global_proxy());
111 }
112
111 // Make sure that the global object of the context we're about to 113 // Make sure that the global object of the context we're about to
112 // make the current one is indeed a global object. 114 // make the current one is indeed a global object.
113 DCHECK(function->context()->global_object()->IsGlobalObject()); 115 DCHECK(function->context()->global_object()->IsGlobalObject());
114 116
115 { 117 {
116 // Save and restore context around invocation and block the 118 // Save and restore context around invocation and block the
117 // allocation of handles without explicit handle scopes. 119 // allocation of handles without explicit handle scopes.
118 SaveContext save(isolate); 120 SaveContext save(isolate);
119 SealHandleScope shs(isolate); 121 SealHandleScope shs(isolate);
120 JSEntryFunction stub_entry = FUNCTION_CAST<JSEntryFunction>(code->entry()); 122 JSEntryFunction stub_entry = FUNCTION_CAST<JSEntryFunction>(code->entry());
121 123
122 // Call the function through the right JS entry stub. 124 // Call the function through the right JS entry stub.
123 byte* ignored = nullptr; // TODO(bmeurer): Remove this altogether. 125 byte* function_entry = function->code()->entry();
124 JSFunction* func = *function; 126 JSFunction* func = *function;
125 Object* recv = *receiver; 127 Object* recv = *receiver;
126 Object*** argv = reinterpret_cast<Object***>(args); 128 Object*** argv = reinterpret_cast<Object***>(args);
127 if (FLAG_profile_deserialization) PrintDeserializedCodeInfo(function); 129 if (FLAG_profile_deserialization) PrintDeserializedCodeInfo(function);
128 value = CALL_GENERATED_CODE(stub_entry, ignored, func, recv, argc, argv); 130 value =
131 CALL_GENERATED_CODE(stub_entry, function_entry, func, recv, argc, argv);
129 } 132 }
130 133
131 #ifdef VERIFY_HEAP 134 #ifdef VERIFY_HEAP
132 if (FLAG_verify_heap) { 135 if (FLAG_verify_heap) {
133 value->ObjectVerify(); 136 value->ObjectVerify();
134 } 137 }
135 #endif 138 #endif
136 139
137 // Update the pending exception flag and return the value. 140 // Update the pending exception flag and return the value.
138 bool has_exception = value->IsException(); 141 bool has_exception = value->IsException();
139 DCHECK(has_exception == isolate->has_pending_exception()); 142 DCHECK(has_exception == isolate->has_pending_exception());
140 if (has_exception) { 143 if (has_exception) {
141 isolate->ReportPendingMessages(); 144 isolate->ReportPendingMessages();
142 // Reset stepping state when script exits with uncaught exception. 145 // Reset stepping state when script exits with uncaught exception.
143 if (isolate->debug()->is_active()) { 146 if (isolate->debug()->is_active()) {
144 isolate->debug()->ClearStepping(); 147 isolate->debug()->ClearStepping();
145 } 148 }
146 return MaybeHandle<Object>(); 149 return MaybeHandle<Object>();
147 } else { 150 } else {
148 isolate->clear_pending_message(); 151 isolate->clear_pending_message();
149 } 152 }
150 153
151 return Handle<Object>(value, isolate); 154 return Handle<Object>(value, isolate);
152 } 155 }
153 156
154 } // namespace
155 157
156 158 MaybeHandle<Object> Execution::Call(Isolate* isolate,
157 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable, 159 Handle<Object> callable,
158 Handle<Object> receiver, int argc, 160 Handle<Object> receiver,
159 Handle<Object> argv[]) { 161 int argc,
162 Handle<Object> argv[],
163 bool convert_receiver) {
160 if (!callable->IsJSFunction()) { 164 if (!callable->IsJSFunction()) {
161 ASSIGN_RETURN_ON_EXCEPTION(isolate, callable, 165 ASSIGN_RETURN_ON_EXCEPTION(isolate, callable,
162 GetFunctionDelegate(isolate, callable), Object); 166 GetFunctionDelegate(isolate, callable), Object);
163 } 167 }
164 Handle<JSFunction> func = Handle<JSFunction>::cast(callable); 168 Handle<JSFunction> func = Handle<JSFunction>::cast(callable);
165 169
170 // In sloppy mode, convert receiver.
171 if (convert_receiver && !receiver->IsJSReceiver() &&
172 !func->shared()->native() && is_sloppy(func->shared()->language_mode())) {
173 if (receiver->IsUndefined() || receiver->IsNull()) {
174 receiver = handle(func->global_proxy());
175 DCHECK(!receiver->IsJSBuiltinsObject());
176 } else {
177 ASSIGN_RETURN_ON_EXCEPTION(
178 isolate, receiver, ToObject(isolate, receiver), Object);
179 }
180 }
181
166 return Invoke(false, func, receiver, argc, argv); 182 return Invoke(false, func, receiver, argc, argv);
167 } 183 }
168 184
169 185
170 MaybeHandle<Object> Execution::New(Handle<JSFunction> func, 186 MaybeHandle<Object> Execution::New(Handle<JSFunction> func,
171 int argc, 187 int argc,
172 Handle<Object> argv[]) { 188 Handle<Object> argv[]) {
173 return Invoke(true, func, handle(func->global_proxy()), argc, argv); 189 return Invoke(true, func, handle(func->global_proxy()), argc, argv);
174 } 190 }
175 191
176 192
177 MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func, 193 MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func,
178 Handle<Object> receiver, int argc, 194 Handle<Object> receiver, int argc,
179 Handle<Object> args[], 195 Handle<Object> args[],
180 MaybeHandle<Object>* exception_out) { 196 MaybeHandle<Object>* exception_out) {
181 bool is_termination = false; 197 bool is_termination = false;
182 Isolate* isolate = func->GetIsolate(); 198 Isolate* isolate = func->GetIsolate();
183 MaybeHandle<Object> maybe_result; 199 MaybeHandle<Object> maybe_result;
184 if (exception_out != NULL) *exception_out = MaybeHandle<Object>(); 200 if (exception_out != NULL) *exception_out = MaybeHandle<Object>();
185 // Enter a try-block while executing the JavaScript code. To avoid 201 // Enter a try-block while executing the JavaScript code. To avoid
186 // duplicate error printing it must be non-verbose. Also, to avoid 202 // duplicate error printing it must be non-verbose. Also, to avoid
187 // creating message objects during stack overflow we shouldn't 203 // creating message objects during stack overflow we shouldn't
188 // capture messages. 204 // capture messages.
189 { 205 {
190 v8::TryCatch catcher(reinterpret_cast<v8::Isolate*>(isolate)); 206 v8::TryCatch catcher(reinterpret_cast<v8::Isolate*>(isolate));
191 catcher.SetVerbose(false); 207 catcher.SetVerbose(false);
192 catcher.SetCaptureMessage(false); 208 catcher.SetCaptureMessage(false);
193 209
194 maybe_result = Call(isolate, func, receiver, argc, args); 210 maybe_result = Invoke(false, func, receiver, argc, args);
195 211
196 if (maybe_result.is_null()) { 212 if (maybe_result.is_null()) {
197 DCHECK(catcher.HasCaught()); 213 DCHECK(catcher.HasCaught());
198 DCHECK(isolate->has_pending_exception()); 214 DCHECK(isolate->has_pending_exception());
199 DCHECK(isolate->external_caught_exception()); 215 DCHECK(isolate->external_caught_exception());
200 if (isolate->pending_exception() == 216 if (isolate->pending_exception() ==
201 isolate->heap()->termination_exception()) { 217 isolate->heap()->termination_exception()) {
202 is_termination = true; 218 is_termination = true;
203 } else { 219 } else {
204 if (exception_out != NULL) { 220 if (exception_out != NULL) {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 646
631 isolate_->counters()->stack_interrupts()->Increment(); 647 isolate_->counters()->stack_interrupts()->Increment();
632 isolate_->counters()->runtime_profiler_ticks()->Increment(); 648 isolate_->counters()->runtime_profiler_ticks()->Increment();
633 isolate_->runtime_profiler()->OptimizeNow(); 649 isolate_->runtime_profiler()->OptimizeNow();
634 650
635 return isolate_->heap()->undefined_value(); 651 return isolate_->heap()->undefined_value();
636 } 652 }
637 653
638 } // namespace internal 654 } // namespace internal
639 } // namespace v8 655 } // namespace v8
OLDNEW
« no previous file with comments | « src/execution.h ('k') | src/ia32/builtins-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698