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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 if (!IS_CALLABLE(result.resolve)) | 240 if (!IS_CALLABLE(result.resolve)) |
241 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Resolve]]"); | 241 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Resolve]]"); |
242 if (!IS_CALLABLE(result.reject)) | 242 if (!IS_CALLABLE(result.reject)) |
243 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Reject]]"); | 243 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Reject]]"); |
244 | 244 |
245 return result; | 245 return result; |
246 } | 246 } |
247 | 247 |
248 function PromiseDeferred() { | 248 function PromiseDeferred() { |
| 249 %IncrementUseCounter(kPromiseDefer); |
249 return NewPromiseCapability(this); | 250 return NewPromiseCapability(this); |
250 } | 251 } |
251 | 252 |
252 function PromiseResolved(x) { | 253 function PromiseResolved(x) { |
| 254 %IncrementUseCounter(kPromiseAccept); |
253 return %_Call(PromiseCast, this, x); | 255 return %_Call(PromiseCast, this, x); |
254 } | 256 } |
255 | 257 |
256 function PromiseRejected(r) { | 258 function PromiseRejected(r) { |
257 if (!IS_RECEIVER(this)) { | 259 if (!IS_RECEIVER(this)) { |
258 throw MakeTypeError(kCalledOnNonObject, PromiseRejected); | 260 throw MakeTypeError(kCalledOnNonObject, PromiseRejected); |
259 } | 261 } |
260 if (this === GlobalPromise) { | 262 if (this === GlobalPromise) { |
261 // Optimized case, avoid extra closure. | 263 // Optimized case, avoid extra closure. |
262 var promise = PromiseCreateAndSet(-1, r); | 264 var promise = PromiseCreateAndSet(-1, r); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // Mark this promise as having handler. | 309 // Mark this promise as having handler. |
308 SET_PRIVATE(this, promiseHasHandlerSymbol, true); | 310 SET_PRIVATE(this, promiseHasHandlerSymbol, true); |
309 if (DEBUG_IS_ACTIVE) { | 311 if (DEBUG_IS_ACTIVE) { |
310 %DebugPromiseEvent({ promise: deferred.promise, parentPromise: this }); | 312 %DebugPromiseEvent({ promise: deferred.promise, parentPromise: this }); |
311 } | 313 } |
312 return deferred.promise; | 314 return deferred.promise; |
313 } | 315 } |
314 | 316 |
315 // Chain is left around for now as an alias for then | 317 // Chain is left around for now as an alias for then |
316 function PromiseChain(onResolve, onReject) { | 318 function PromiseChain(onResolve, onReject) { |
| 319 %IncrementUseCounter(kPromiseChain); |
317 return %_Call(PromiseThen, this, onResolve, onReject); | 320 return %_Call(PromiseThen, this, onResolve, onReject); |
318 } | 321 } |
319 | 322 |
320 function PromiseCatch(onReject) { | 323 function PromiseCatch(onReject) { |
321 return this.then(UNDEFINED, onReject); | 324 return this.then(UNDEFINED, onReject); |
322 } | 325 } |
323 | 326 |
324 // Combinators. | 327 // Combinators. |
325 | 328 |
326 function PromiseCast(x) { | 329 function PromiseCast(x) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 458 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
456 fn => %FunctionRemovePrototype(fn)); | 459 fn => %FunctionRemovePrototype(fn)); |
457 | 460 |
458 utils.Export(function(to) { | 461 utils.Export(function(to) { |
459 to.PromiseChain = PromiseChain; | 462 to.PromiseChain = PromiseChain; |
460 to.PromiseDeferred = PromiseDeferred; | 463 to.PromiseDeferred = PromiseDeferred; |
461 to.PromiseResolved = PromiseResolved; | 464 to.PromiseResolved = PromiseResolved; |
462 }); | 465 }); |
463 | 466 |
464 }) | 467 }) |
OLD | NEW |