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

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

Issue 2581503003: [promisehook] Store promise in PromiseReactionJob (Closed)
Patch Set: rebase correctly Created 4 years 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 #include "src/runtime/runtime-utils.h" 4 #include "src/runtime/runtime-utils.h"
5 5
6 #include "src/debug/debug.h" 6 #include "src/debug/debug.h"
7 #include "src/elements.h" 7 #include "src/elements.h"
8 #include "src/promise-utils.h" 8 #include "src/promise-utils.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 HandleScope scope(isolate); 50 HandleScope scope(isolate);
51 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 51 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
52 // At this point, no revocation has been issued before 52 // At this point, no revocation has been issued before
53 CHECK(!promise->has_handler()); 53 CHECK(!promise->has_handler());
54 isolate->ReportPromiseReject(promise, Handle<Object>(), 54 isolate->ReportPromiseReject(promise, Handle<Object>(),
55 v8::kPromiseHandlerAddedAfterReject); 55 v8::kPromiseHandlerAddedAfterReject);
56 return isolate->heap()->undefined_value(); 56 return isolate->heap()->undefined_value();
57 } 57 }
58 58
59 namespace { 59 namespace {
60 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<Object> value, 60 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise,
61 Handle<Object> tasks, Handle<Object> deferred, 61 Handle<Object> value, Handle<Object> tasks,
62 Handle<Object> status) { 62 Handle<Object> deferred, Handle<Object> status) {
63 Handle<Object> debug_id = isolate->factory()->undefined_value(); 63 Handle<Object> debug_id = isolate->factory()->undefined_value();
64 Handle<Object> debug_name = isolate->factory()->undefined_value(); 64 Handle<Object> debug_name = isolate->factory()->undefined_value();
65 if (isolate->debug()->is_active()) { 65 if (isolate->debug()->is_active()) {
66 MaybeHandle<Object> maybe_result; 66 MaybeHandle<Object> maybe_result;
67 Handle<Object> deferred_obj(deferred); 67 Handle<Object> deferred_obj(deferred);
68 68
69 if (deferred->IsFixedArray()) { 69 if (deferred->IsFixedArray()) {
70 deferred_obj = isolate->factory()->undefined_value(); 70 deferred_obj = isolate->factory()->undefined_value();
71 } 71 }
72 72
73 Handle<Object> argv[] = {deferred_obj, status}; 73 Handle<Object> argv[] = {deferred_obj, status};
74 maybe_result = Execution::TryCall( 74 maybe_result = Execution::TryCall(
75 isolate, isolate->promise_debug_get_info(), 75 isolate, isolate->promise_debug_get_info(),
76 isolate->factory()->undefined_value(), arraysize(argv), argv); 76 isolate->factory()->undefined_value(), arraysize(argv), argv);
77 77
78 Handle<Object> result; 78 Handle<Object> result;
79 if ((maybe_result).ToHandle(&result)) { 79 if ((maybe_result).ToHandle(&result)) {
80 CHECK(result->IsJSArray()); 80 CHECK(result->IsJSArray());
81 Handle<JSArray> array = Handle<JSArray>::cast(result); 81 Handle<JSArray> array = Handle<JSArray>::cast(result);
82 ElementsAccessor* accessor = array->GetElementsAccessor(); 82 ElementsAccessor* accessor = array->GetElementsAccessor();
83 DCHECK(accessor->HasElement(array, 0)); 83 DCHECK(accessor->HasElement(array, 0));
84 DCHECK(accessor->HasElement(array, 1)); 84 DCHECK(accessor->HasElement(array, 1));
85 debug_id = accessor->Get(array, 0); 85 debug_id = accessor->Get(array, 0);
86 debug_name = accessor->Get(array, 1); 86 debug_name = accessor->Get(array, 1);
87 } 87 }
88 } 88 }
89 Handle<PromiseReactionJobInfo> info = 89 Handle<PromiseReactionJobInfo> info =
90 isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred, 90 isolate->factory()->NewPromiseReactionJobInfo(
91 debug_id, debug_name, 91 promise, value, tasks, deferred, debug_id, debug_name,
92 isolate->native_context()); 92 isolate->native_context());
93 isolate->EnqueueMicrotask(info); 93 isolate->EnqueueMicrotask(info);
94 } 94 }
95 95
96 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, 96 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status,
97 Handle<Object> result) { 97 Handle<Object> result) {
98 promise->set_status(status); 98 promise->set_status(status);
99 promise->set_result(*result); 99 promise->set_result(*result);
100 promise->set_deferred(isolate->heap()->undefined_value()); 100 promise->set_deferred(isolate->heap()->undefined_value());
101 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); 101 promise->set_fulfill_reactions(isolate->heap()->undefined_value());
102 promise->set_reject_reactions(isolate->heap()->undefined_value()); 102 promise->set_reject_reactions(isolate->heap()->undefined_value());
103 } 103 }
104 104
105 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, 105 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise,
106 Handle<Smi> status, Handle<Object> value) { 106 Handle<Smi> status, Handle<Object> value) {
107 // Check if there are any callbacks. 107 // Check if there are any callbacks.
108 if (!promise->deferred()->IsUndefined(isolate)) { 108 if (!promise->deferred()->IsUndefined(isolate)) {
109 Handle<Object> tasks((status->value() == kPromiseFulfilled) 109 Handle<Object> tasks((status->value() == kPromiseFulfilled)
110 ? promise->fulfill_reactions() 110 ? promise->fulfill_reactions()
111 : promise->reject_reactions(), 111 : promise->reject_reactions(),
112 isolate); 112 isolate);
113 Handle<Object> deferred(promise->deferred(), isolate); 113 Handle<Object> deferred(promise->deferred(), isolate);
114 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); 114 EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status);
115 } 115 }
116 116
117 PromiseSet(isolate, promise, status->value(), value); 117 PromiseSet(isolate, promise, status->value(), value);
118 } 118 }
119 119
120 } // namespace 120 } // namespace
121 121
122 RUNTIME_FUNCTION(Runtime_PromiseReject) { 122 RUNTIME_FUNCTION(Runtime_PromiseReject) {
123 DCHECK(args.length() == 3); 123 DCHECK(args.length() == 3);
124 HandleScope scope(isolate); 124 HandleScope scope(isolate);
(...skipping 13 matching lines...) Expand all
138 HandleScope scope(isolate); 138 HandleScope scope(isolate);
139 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 139 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
140 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1); 140 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1);
141 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 141 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
142 PromiseFulfill(isolate, promise, status, value); 142 PromiseFulfill(isolate, promise, status, value);
143 return isolate->heap()->undefined_value(); 143 return isolate->heap()->undefined_value();
144 } 144 }
145 145
146 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { 146 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) {
147 HandleScope scope(isolate); 147 HandleScope scope(isolate);
148 DCHECK(args.length() == 4); 148 DCHECK(args.length() == 5);
149 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); 149 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
150 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1); 150 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
151 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2); 151 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 2);
152 CONVERT_ARG_HANDLE_CHECKED(Object, status, 3); 152 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 3);
153 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); 153 CONVERT_ARG_HANDLE_CHECKED(Object, status, 4);
154 EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status);
154 return isolate->heap()->undefined_value(); 155 return isolate->heap()->undefined_value();
155 } 156 }
156 157
157 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { 158 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) {
158 HandleScope scope(isolate); 159 HandleScope scope(isolate);
159 DCHECK(args.length() == 3); 160 DCHECK(args.length() == 3);
160 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); 161 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
161 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1); 162 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1);
162 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2); 163 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2);
163 164
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 HandleScope scope(isolate); 279 HandleScope scope(isolate);
279 DCHECK(args.length() == 1); 280 DCHECK(args.length() == 1);
280 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 281 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
281 282
282 promise->set_has_handler(true); 283 promise->set_has_handler(true);
283 return isolate->heap()->undefined_value(); 284 return isolate->heap()->undefined_value();
284 } 285 }
285 286
286 } // namespace internal 287 } // namespace internal
287 } // namespace v8 288 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698