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

Side by Side Diff: src/runtime/runtime-internal.cc

Issue 2451163003: [promises] Move PromiseReject to c++ (Closed)
Patch Set: make promise a jsobject Created 4 years, 1 month 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/runtime/runtime-debug.cc ('k') | no next file » | 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/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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(JSObject, 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
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
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698