Chromium Code Reviews| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 HandleScope scope(isolate); | 283 HandleScope scope(isolate); |
| 284 DCHECK_EQ(1, args.length()); | 284 DCHECK_EQ(1, args.length()); |
| 285 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 285 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 286 Handle<String> type = Object::TypeOf(isolate, object); | 286 Handle<String> type = Object::TypeOf(isolate, object); |
| 287 THROW_NEW_ERROR_RETURN_FAILURE( | 287 THROW_NEW_ERROR_RETURN_FAILURE( |
| 288 isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type)); | 288 isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 namespace { | 291 namespace { |
| 292 | 292 |
| 293 void PromiseRejectEvent(Isolate* isolate, Handle<JSObject> promise, | 293 void PromiseRejectEvent(Isolate* isolate, Handle<JSReceiver> promise, |
| 294 Handle<Object> rejected_promise, Handle<Object> value, | 294 Handle<Object> rejected_promise, Handle<Object> value, |
| 295 bool debug_event) { | 295 bool debug_event) { |
| 296 if (isolate->debug()->is_active() && debug_event) { | 296 if (isolate->debug()->is_active() && debug_event) { |
| 297 isolate->debug()->OnPromiseReject(rejected_promise, value); | 297 isolate->debug()->OnPromiseReject(rejected_promise, value); |
| 298 } | 298 } |
| 299 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); | 299 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); |
| 300 // Do not report if we actually have a handler. | 300 // Do not report if we actually have a handler. |
| 301 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)) { | 301 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)) { |
| 302 isolate->ReportPromiseReject(promise, value, | 302 isolate->ReportPromiseReject(Handle<JSObject>::cast(promise), value, |
|
adamk
2016/10/27 08:02:34
Why is this safe? Or rather, why did the promise a
gsathya
2016/10/27 11:27:48
Changed back to JSObject
| |
| 303 v8::kPromiseRejectWithNoHandler); | 303 v8::kPromiseRejectWithNoHandler); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace | 307 } // namespace |
| 308 | 308 |
| 309 RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) { | 309 RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) { |
| 310 DCHECK(args.length() == 3); | 310 DCHECK(args.length() == 3); |
| 311 HandleScope scope(isolate); | 311 HandleScope scope(isolate); |
| 312 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); | 312 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 debug_id = accessor->Get(array, 0); | 594 debug_id = accessor->Get(array, 0); |
| 595 debug_name = accessor->Get(array, 1); | 595 debug_name = accessor->Get(array, 1); |
| 596 } | 596 } |
| 597 } | 597 } |
| 598 Handle<PromiseReactionJobInfo> info = | 598 Handle<PromiseReactionJobInfo> info = |
| 599 isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred, | 599 isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred, |
| 600 debug_id, debug_name, | 600 debug_id, debug_name, |
| 601 isolate->native_context()); | 601 isolate->native_context()); |
| 602 isolate->EnqueueMicrotask(info); | 602 isolate->EnqueueMicrotask(info); |
| 603 } | 603 } |
| 604 | |
| 605 void PromiseFulfill(Isolate* isolate, Handle<JSReceiver> promise, | |
| 606 Handle<Smi> status, Handle<Object> value, | |
| 607 Handle<Symbol> reaction) { | |
| 608 Handle<Object> tasks = JSReceiver::GetDataProperty(promise, reaction); | |
| 609 if (!tasks->IsUndefined(isolate)) { | |
| 610 Handle<Object> deferred = JSReceiver::GetDataProperty( | |
| 611 promise, isolate->factory()->promise_deferred_reaction_symbol()); | |
| 612 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); | |
| 613 } | |
| 614 } | |
| 604 } // namespace | 615 } // namespace |
| 605 | 616 |
| 617 RUNTIME_FUNCTION(Runtime_PromiseReject) { | |
| 618 DCHECK(args.length() == 3); | |
| 619 HandleScope scope(isolate); | |
| 620 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, promise, 0); | |
| 621 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1); | |
| 622 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); | |
| 623 | |
| 624 PromiseRejectEvent(isolate, promise, promise, reason, debug_event); | |
| 625 | |
| 626 Handle<Smi> status = handle(Smi::FromInt(kPromiseRejected), isolate); | |
| 627 Handle<Symbol> reaction = | |
| 628 isolate->factory()->promise_reject_reactions_symbol(); | |
| 629 PromiseFulfill(isolate, promise, status, reason, reaction); | |
| 630 return isolate->heap()->undefined_value(); | |
| 631 } | |
| 632 | |
| 606 RUNTIME_FUNCTION(Runtime_PromiseFulfill) { | 633 RUNTIME_FUNCTION(Runtime_PromiseFulfill) { |
| 607 DCHECK(args.length() == 4); | 634 DCHECK(args.length() == 4); |
| 608 HandleScope scope(isolate); | 635 HandleScope scope(isolate); |
| 609 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, promise, 0); | 636 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, promise, 0); |
| 610 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1); | 637 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1); |
| 611 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 638 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 612 CONVERT_ARG_HANDLE_CHECKED(Symbol, reaction, 3); | 639 CONVERT_ARG_HANDLE_CHECKED(Symbol, reaction, 3); |
| 613 Handle<Object> tasks = JSReceiver::GetDataProperty(promise, reaction); | 640 PromiseFulfill(isolate, promise, status, value, reaction); |
| 614 if (!tasks->IsUndefined(isolate)) { | |
| 615 Handle<Object> deferred = JSReceiver::GetDataProperty( | |
| 616 promise, isolate->factory()->promise_deferred_reaction_symbol()); | |
| 617 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); | |
| 618 } | |
| 619 return isolate->heap()->undefined_value(); | 641 return isolate->heap()->undefined_value(); |
| 620 } | 642 } |
| 621 | 643 |
| 622 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { | 644 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { |
| 623 HandleScope scope(isolate); | 645 HandleScope scope(isolate); |
| 624 DCHECK(args.length() == 4); | 646 DCHECK(args.length() == 4); |
| 625 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); | 647 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); |
| 626 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1); | 648 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1); |
| 627 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2); | 649 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2); |
| 628 CONVERT_ARG_HANDLE_CHECKED(Object, status, 3); | 650 CONVERT_ARG_HANDLE_CHECKED(Object, status, 3); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 | 714 |
| 693 RUNTIME_FUNCTION(Runtime_Typeof) { | 715 RUNTIME_FUNCTION(Runtime_Typeof) { |
| 694 HandleScope scope(isolate); | 716 HandleScope scope(isolate); |
| 695 DCHECK_EQ(1, args.length()); | 717 DCHECK_EQ(1, args.length()); |
| 696 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 718 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 697 return *Object::TypeOf(isolate, object); | 719 return *Object::TypeOf(isolate, object); |
| 698 } | 720 } |
| 699 | 721 |
| 700 } // namespace internal | 722 } // namespace internal |
| 701 } // namespace v8 | 723 } // namespace v8 |
| OLD | NEW |