| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 if (GET_PRIVATE(promise, promiseStatusSymbol) == 0) { | 210 if (GET_PRIVATE(promise, promiseStatusSymbol) == 0) { |
| 211 var debug_is_active = DEBUG_IS_ACTIVE; | 211 var debug_is_active = DEBUG_IS_ACTIVE; |
| 212 if (debug_is_active || | 212 if (debug_is_active || |
| 213 !HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) { | 213 !HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) { |
| 214 %PromiseRejectEvent(promise, r, debug_is_active); | 214 %PromiseRejectEvent(promise, r, debug_is_active); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 PromiseDone(promise, -1, r, promiseOnRejectSymbol) | 217 PromiseDone(promise, -1, r, promiseOnRejectSymbol) |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Convenience. | |
| 221 | |
| 222 function NewPromiseCapability(C) { | 220 function NewPromiseCapability(C) { |
| 223 if (C === GlobalPromise) { | 221 if (C === GlobalPromise) { |
| 224 // Optimized case, avoid extra closure. | 222 // Optimized case, avoid extra closure. |
| 225 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); | 223 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); |
| 226 var callbacks = CreateResolvingFunctions(promise); | 224 var callbacks = CreateResolvingFunctions(promise); |
| 227 return { | 225 return { |
| 228 promise: promise, | 226 promise: promise, |
| 229 resolve: callbacks.resolve, | 227 resolve: callbacks.resolve, |
| 230 reject: callbacks.reject | 228 reject: callbacks.reject |
| 231 }; | 229 }; |
| 232 } | 230 } |
| 233 | 231 |
| 234 var result = {promise: UNDEFINED, resolve: UNDEFINED, reject: UNDEFINED }; | 232 var result = {promise: UNDEFINED, resolve: UNDEFINED, reject: UNDEFINED }; |
| 235 result.promise = new C((resolve, reject) => { | 233 result.promise = new C((resolve, reject) => { |
| 236 if (!IS_UNDEFINED(result.resolve) || !IS_UNDEFINED(result.reject)) | 234 if (!IS_UNDEFINED(result.resolve) || !IS_UNDEFINED(result.reject)) |
| 237 throw MakeTypeError(kPromiseExecutorAlreadyInvoked); | 235 throw MakeTypeError(kPromiseExecutorAlreadyInvoked); |
| 238 result.resolve = resolve; | 236 result.resolve = resolve; |
| 239 result.reject = reject; | 237 result.reject = reject; |
| 240 }); | 238 }); |
| 241 | 239 |
| 240 if (!IS_CALLABLE(result.resolve) || !IS_CALLABLE(result.reject)) |
| 241 throw MakeTypeError(kPromiseNonCallable); |
| 242 |
| 242 return result; | 243 return result; |
| 243 } | 244 } |
| 244 | 245 |
| 245 function PromiseDeferred() { | 246 function PromiseDeferred() { |
| 246 %IncrementUseCounter(kPromiseDefer); | 247 %IncrementUseCounter(kPromiseDefer); |
| 247 return NewPromiseCapability(this); | 248 return NewPromiseCapability(this); |
| 248 } | 249 } |
| 249 | 250 |
| 250 function PromiseResolved(x) { | 251 function PromiseResolved(x) { |
| 251 %IncrementUseCounter(kPromiseAccept); | 252 %IncrementUseCounter(kPromiseAccept); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 472 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
| 472 fn => %FunctionRemovePrototype(fn)); | 473 fn => %FunctionRemovePrototype(fn)); |
| 473 | 474 |
| 474 utils.Export(function(to) { | 475 utils.Export(function(to) { |
| 475 to.PromiseChain = PromiseChain; | 476 to.PromiseChain = PromiseChain; |
| 476 to.PromiseDeferred = PromiseDeferred; | 477 to.PromiseDeferred = PromiseDeferred; |
| 477 to.PromiseResolved = PromiseResolved; | 478 to.PromiseResolved = PromiseResolved; |
| 478 }); | 479 }); |
| 479 | 480 |
| 480 }) | 481 }) |
| OLD | NEW |