OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 function PromiseDone(promise, status, value, promiseQueue) { | 111 function PromiseDone(promise, status, value, promiseQueue) { |
112 if (GET_PRIVATE(promise, promiseStatusSymbol) === 0) { | 112 if (GET_PRIVATE(promise, promiseStatusSymbol) === 0) { |
113 var tasks = GET_PRIVATE(promise, promiseQueue); | 113 var tasks = GET_PRIVATE(promise, promiseQueue); |
114 if (tasks.length) PromiseEnqueue(value, tasks, status); | 114 if (tasks.length) PromiseEnqueue(value, tasks, status); |
115 PromiseSet(promise, status, value); | 115 PromiseSet(promise, status, value); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 function PromiseCoerce(constructor, x) { | 119 function PromiseCoerce(constructor, x) { |
120 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) { | 120 if (!IsPromise(x) && IS_RECEIVER(x)) { |
121 var then; | 121 var then; |
122 try { | 122 try { |
123 then = x.then; | 123 then = x.then; |
124 } catch(r) { | 124 } catch(r) { |
125 return %_Call(PromiseRejected, constructor, r); | 125 return %_Call(PromiseRejected, constructor, r); |
126 } | 126 } |
127 if (IS_CALLABLE(then)) { | 127 if (IS_CALLABLE(then)) { |
128 var deferred = NewPromiseCapability(constructor); | 128 var deferred = NewPromiseCapability(constructor); |
129 try { | 129 try { |
130 %_Call(then, x, deferred.resolve, deferred.reject); | 130 %_Call(then, x, deferred.resolve, deferred.reject); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 function PromiseIdRejectHandler(r) { throw r } | 178 function PromiseIdRejectHandler(r) { throw r } |
179 | 179 |
180 function PromiseNopResolver() {} | 180 function PromiseNopResolver() {} |
181 | 181 |
182 // ------------------------------------------------------------------- | 182 // ------------------------------------------------------------------- |
183 // Define exported functions. | 183 // Define exported functions. |
184 | 184 |
185 // For bootstrapper. | 185 // For bootstrapper. |
186 | 186 |
187 function IsPromise(x) { | 187 function IsPromise(x) { |
188 return IS_SPEC_OBJECT(x) && HAS_DEFINED_PRIVATE(x, promiseStatusSymbol); | 188 return IS_RECEIVER(x) && HAS_DEFINED_PRIVATE(x, promiseStatusSymbol); |
189 } | 189 } |
190 | 190 |
191 function PromiseCreate() { | 191 function PromiseCreate() { |
192 return new GlobalPromise(PromiseNopResolver) | 192 return new GlobalPromise(PromiseNopResolver) |
193 } | 193 } |
194 | 194 |
195 function PromiseResolve(promise, x) { | 195 function PromiseResolve(promise, x) { |
196 if (GET_PRIVATE(promise, promiseStatusSymbol) === 0) { | 196 if (GET_PRIVATE(promise, promiseStatusSymbol) === 0) { |
197 if (IS_SPEC_OBJECT(x)) { | 197 if (IS_RECEIVER(x)) { |
198 // 25.4.1.3.2 steps 8-12 | 198 // 25.4.1.3.2 steps 8-12 |
199 try { | 199 try { |
200 var then = x.then; | 200 var then = x.then; |
201 } catch (e) { | 201 } catch (e) { |
202 return PromiseReject(promise, e); | 202 return PromiseReject(promise, e); |
203 } | 203 } |
204 if (IS_CALLABLE(then)) { | 204 if (IS_CALLABLE(then)) { |
205 // PromiseResolveThenableJob | 205 // PromiseResolveThenableJob |
206 return %EnqueueMicrotask(function() { | 206 return %EnqueueMicrotask(function() { |
207 try { | 207 try { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 478 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
479 fn => %FunctionRemovePrototype(fn)); | 479 fn => %FunctionRemovePrototype(fn)); |
480 | 480 |
481 utils.Export(function(to) { | 481 utils.Export(function(to) { |
482 to.PromiseChain = PromiseChain; | 482 to.PromiseChain = PromiseChain; |
483 to.PromiseDeferred = PromiseDeferred; | 483 to.PromiseDeferred = PromiseDeferred; |
484 to.PromiseResolved = PromiseResolved; | 484 to.PromiseResolved = PromiseResolved; |
485 }); | 485 }); |
486 | 486 |
487 }) | 487 }) |
OLD | NEW |