OLD | NEW |
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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 265 |
266 RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) { | 266 RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) { |
267 HandleScope scope(isolate); | 267 HandleScope scope(isolate); |
268 DCHECK_EQ(1, args.length()); | 268 DCHECK_EQ(1, args.length()); |
269 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 269 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
270 Handle<String> type = Object::TypeOf(isolate, object); | 270 Handle<String> type = Object::TypeOf(isolate, object); |
271 THROW_NEW_ERROR_RETURN_FAILURE( | 271 THROW_NEW_ERROR_RETURN_FAILURE( |
272 isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type)); | 272 isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type)); |
273 } | 273 } |
274 | 274 |
| 275 namespace { |
| 276 |
| 277 void PromiseRejectEvent(Isolate* isolate, Handle<JSObject> promise, |
| 278 Handle<JSObject> rejected_promise, Handle<Object> value, |
| 279 bool debug_event) { |
| 280 if (isolate->debug()->is_active() && debug_event) { |
| 281 isolate->debug()->OnPromiseReject(rejected_promise, value); |
| 282 } |
| 283 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); |
| 284 // Do not report if we actually have a handler. |
| 285 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)) { |
| 286 isolate->ReportPromiseReject(promise, value, |
| 287 v8::kPromiseRejectWithNoHandler); |
| 288 } |
| 289 } |
| 290 |
| 291 } // namespace |
275 | 292 |
276 RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) { | 293 RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) { |
277 DCHECK(args.length() == 3); | 294 DCHECK(args.length() == 3); |
278 HandleScope scope(isolate); | 295 HandleScope scope(isolate); |
279 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); | 296 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); |
280 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 297 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
281 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); | 298 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); |
282 if (debug_event) isolate->debug()->OnPromiseReject(promise, value); | 299 |
283 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); | 300 PromiseRejectEvent(isolate, promise, promise, value, debug_event); |
284 // Do not report if we actually have a handler. | |
285 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)) { | |
286 isolate->ReportPromiseReject(promise, value, | |
287 v8::kPromiseRejectWithNoHandler); | |
288 } | |
289 return isolate->heap()->undefined_value(); | 301 return isolate->heap()->undefined_value(); |
290 } | 302 } |
291 | 303 |
| 304 RUNTIME_FUNCTION(Runtime_PromiseRejectEventFromStack) { |
| 305 DCHECK(args.length() == 2); |
| 306 HandleScope scope(isolate); |
| 307 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); |
| 308 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 309 |
| 310 Handle<JSObject> rejected_promise = promise; |
| 311 if (isolate->debug()->is_active()) { |
| 312 Handle<Object> promise_on_stack = isolate->GetPromiseOnStackOnThrow(); |
| 313 if (promise_on_stack->IsJSObject()) { |
| 314 rejected_promise = Handle<JSObject>::cast(promise_on_stack); |
| 315 } |
| 316 } |
| 317 PromiseRejectEvent(isolate, promise, rejected_promise, value, true); |
| 318 return isolate->heap()->undefined_value(); |
| 319 } |
292 | 320 |
293 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { | 321 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { |
294 DCHECK(args.length() == 1); | 322 DCHECK(args.length() == 1); |
295 HandleScope scope(isolate); | 323 HandleScope scope(isolate); |
296 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); | 324 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); |
297 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); | 325 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); |
298 // At this point, no revocation has been issued before | 326 // At this point, no revocation has been issued before |
299 CHECK(JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)); | 327 CHECK(JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)); |
300 isolate->ReportPromiseReject(promise, Handle<Object>(), | 328 isolate->ReportPromiseReject(promise, Handle<Object>(), |
301 v8::kPromiseHandlerAddedAfterReject); | 329 v8::kPromiseHandlerAddedAfterReject); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 591 |
564 RUNTIME_FUNCTION(Runtime_Typeof) { | 592 RUNTIME_FUNCTION(Runtime_Typeof) { |
565 HandleScope scope(isolate); | 593 HandleScope scope(isolate); |
566 DCHECK_EQ(1, args.length()); | 594 DCHECK_EQ(1, args.length()); |
567 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 595 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
568 return *Object::TypeOf(isolate, object); | 596 return *Object::TypeOf(isolate, object); |
569 } | 597 } |
570 | 598 |
571 } // namespace internal | 599 } // namespace internal |
572 } // namespace v8 | 600 } // namespace v8 |
OLD | NEW |