OLD | NEW |
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 promise->set_result(*result); | 102 promise->set_result(*result); |
103 promise->set_deferred(isolate->heap()->undefined_value()); | 103 promise->set_deferred(isolate->heap()->undefined_value()); |
104 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); | 104 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); |
105 promise->set_reject_reactions(isolate->heap()->undefined_value()); | 105 promise->set_reject_reactions(isolate->heap()->undefined_value()); |
106 } | 106 } |
107 | 107 |
108 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, | 108 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, |
109 Handle<Smi> status, Handle<Object> value) { | 109 Handle<Smi> status, Handle<Object> value) { |
110 // Check if there are any callbacks. | 110 // Check if there are any callbacks. |
111 if (!promise->deferred()->IsUndefined(isolate)) { | 111 if (!promise->deferred()->IsUndefined(isolate)) { |
112 Handle<Object> tasks((status->value() == kPromiseFulfilled) | 112 Handle<Object> tasks((status->value() == v8::Promise::kFulfilled) |
113 ? promise->fulfill_reactions() | 113 ? promise->fulfill_reactions() |
114 : promise->reject_reactions(), | 114 : promise->reject_reactions(), |
115 isolate); | 115 isolate); |
116 Handle<Object> deferred(promise->deferred(), isolate); | 116 Handle<Object> deferred(promise->deferred(), isolate); |
117 EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status); | 117 EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status); |
118 } | 118 } |
119 | 119 |
120 PromiseSet(isolate, promise, status->value(), value); | 120 PromiseSet(isolate, promise, status->value(), value); |
121 } | 121 } |
122 | 122 |
123 } // namespace | 123 } // namespace |
124 | 124 |
125 RUNTIME_FUNCTION(Runtime_PromiseReject) { | 125 RUNTIME_FUNCTION(Runtime_PromiseReject) { |
126 DCHECK(args.length() == 3); | 126 DCHECK(args.length() == 3); |
127 HandleScope scope(isolate); | 127 HandleScope scope(isolate); |
128 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 128 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
129 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1); | 129 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1); |
130 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); | 130 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); |
131 | 131 |
132 PromiseRejectEvent(isolate, promise, promise, reason, debug_event); | 132 PromiseRejectEvent(isolate, promise, promise, reason, debug_event); |
133 | 133 |
134 Handle<Smi> status(Smi::FromInt(kPromiseRejected), isolate); | 134 Handle<Smi> status(Smi::FromInt(v8::Promise::kRejected), isolate); |
135 PromiseFulfill(isolate, promise, status, reason); | 135 PromiseFulfill(isolate, promise, status, reason); |
136 return isolate->heap()->undefined_value(); | 136 return isolate->heap()->undefined_value(); |
137 } | 137 } |
138 | 138 |
139 RUNTIME_FUNCTION(Runtime_PromiseFulfill) { | 139 RUNTIME_FUNCTION(Runtime_PromiseFulfill) { |
140 DCHECK(args.length() == 3); | 140 DCHECK(args.length() == 3); |
141 HandleScope scope(isolate); | 141 HandleScope scope(isolate); |
142 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 142 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
143 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1); | 143 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1); |
144 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 144 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 HandleScope scope(isolate); | 318 HandleScope scope(isolate); |
319 DCHECK_EQ(1, args.length()); | 319 DCHECK_EQ(1, args.length()); |
320 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); | 320 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); |
321 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, | 321 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, |
322 isolate->factory()->undefined_value()); | 322 isolate->factory()->undefined_value()); |
323 return isolate->heap()->undefined_value(); | 323 return isolate->heap()->undefined_value(); |
324 } | 324 } |
325 | 325 |
326 } // namespace internal | 326 } // namespace internal |
327 } // namespace v8 | 327 } // namespace v8 |
OLD | NEW |