Chromium Code Reviews| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 // Define exported functions. | 229 // Define exported functions. |
| 230 | 230 |
| 231 // For bootstrapper. | 231 // For bootstrapper. |
| 232 | 232 |
| 233 // ES#sec-ispromise IsPromise ( x ) | 233 // ES#sec-ispromise IsPromise ( x ) |
| 234 function IsPromise(x) { | 234 function IsPromise(x) { |
| 235 return IS_RECEIVER(x) && HAS_DEFINED_PRIVATE(x, promiseStateSymbol); | 235 return IS_RECEIVER(x) && HAS_DEFINED_PRIVATE(x, promiseStateSymbol); |
| 236 } | 236 } |
| 237 | 237 |
| 238 function PromiseCreate() { | 238 function PromiseCreate() { |
| 239 return new GlobalPromise(PromiseNopResolver) | 239 return new GlobalPromise(PromiseNopResolver); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // ES#sec-promise-resolve-functions | 242 // ES#sec-promise-resolve-functions |
| 243 // Promise Resolve Functions, steps 6-13 | 243 // Promise Resolve Functions, steps 6-13 |
| 244 function ResolvePromise(promise, resolution) { | 244 function ResolvePromise(promise, resolution) { |
| 245 if (resolution === promise) { | 245 if (resolution === promise) { |
| 246 return RejectPromise(promise, | 246 return RejectPromise(promise, |
| 247 %make_type_error(kPromiseCyclic, resolution), | 247 %make_type_error(kPromiseCyclic, resolution), |
| 248 true); | 248 true); |
| 249 } | 249 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 280 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); | 280 SET_PRIVATE(resolution, promiseHasHandlerSymbol, true); |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 if (IS_CALLABLE(then)) { | 285 if (IS_CALLABLE(then)) { |
| 286 // PromiseResolveThenableJob | 286 // PromiseResolveThenableJob |
| 287 var id; | 287 var id; |
| 288 var name = "PromiseResolveThenableJob"; | 288 var name = "PromiseResolveThenableJob"; |
| 289 var instrumenting = DEBUG_IS_ACTIVE; | 289 var instrumenting = DEBUG_IS_ACTIVE; |
| 290 if (!IS_UNDEFINED(resolution) && DEBUG_IS_ACTIVE && IsPromise(resolution)) { | |
|
gsathya
2016/09/08 21:38:58
nit: format, s/DEBUG_IS_ACTIVE/instrumenting, and
Dan Ehrenberg
2016/09/12 22:49:25
Done
| |
| 291 // Mark the dependency of the new promise on the resolution | |
| 292 SET_PRIVATE(resolution, promiseAwaitHandlerSymbol, promise); | |
| 293 } | |
| 290 %EnqueueMicrotask(function() { | 294 %EnqueueMicrotask(function() { |
| 291 if (instrumenting) { | 295 if (instrumenting) { |
| 292 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); | 296 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); |
| 293 } | 297 } |
| 294 // These resolving functions simply forward the exception, so | 298 // These resolving functions simply forward the exception, so |
| 295 // don't create a new debugEvent. | 299 // don't create a new debugEvent. |
| 296 var callbacks = CreateResolvingFunctions(promise, false); | 300 var callbacks = CreateResolvingFunctions(promise, false); |
| 297 try { | 301 try { |
| 298 %_Call(then, resolution, callbacks.resolve, callbacks.reject); | 302 %_Call(then, resolution, callbacks.resolve, callbacks.reject); |
| 299 } catch (e) { | 303 } catch (e) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 } catch (e) { | 534 } catch (e) { |
| 531 deferred.reject(e) | 535 deferred.reject(e) |
| 532 } | 536 } |
| 533 return deferred.promise; | 537 return deferred.promise; |
| 534 } | 538 } |
| 535 | 539 |
| 536 | 540 |
| 537 // Utility for debugger | 541 // Utility for debugger |
| 538 | 542 |
| 539 function PromiseHasUserDefinedRejectHandlerCheck(handler, deferred) { | 543 function PromiseHasUserDefinedRejectHandlerCheck(handler, deferred) { |
| 540 if (GET_PRIVATE(handler, promiseAwaitHandlerSymbol)) return false; | 544 var outerPromise = GET_PRIVATE(handler, promiseAwaitHandlerSymbol); |
| 545 if (outerPromise) { | |
| 546 return PromiseHasUserDefinedRejectHandlerRecursive(outerPromise); | |
| 547 } | |
| 541 if (handler !== PromiseIdRejectHandler) { | 548 if (handler !== PromiseIdRejectHandler) { |
| 542 var combinedDeferred = GET_PRIVATE(handler, promiseCombinedDeferredSymbol); | 549 var combinedDeferred = GET_PRIVATE(handler, promiseCombinedDeferredSymbol); |
| 543 if (IS_UNDEFINED(combinedDeferred)) return true; | 550 if (IS_UNDEFINED(combinedDeferred)) return true; |
| 544 if (PromiseHasUserDefinedRejectHandlerRecursive(combinedDeferred.promise)) { | 551 if (PromiseHasUserDefinedRejectHandlerRecursive(combinedDeferred.promise)) { |
| 545 return true; | 552 return true; |
| 546 } | 553 } |
| 547 } else if (PromiseHasUserDefinedRejectHandlerRecursive(deferred.promise)) { | 554 } else if (PromiseHasUserDefinedRejectHandlerRecursive(deferred.promise)) { |
| 548 return true; | 555 return true; |
| 549 } | 556 } |
| 550 return false; | 557 return false; |
| 551 } | 558 } |
| 552 | 559 |
| 553 function PromiseHasUserDefinedRejectHandlerRecursive(promise) { | 560 function PromiseHasUserDefinedRejectHandlerRecursive(promise) { |
| 554 var handledHintSymbol = GET_PRIVATE(promise, promiseHandledHintSymbol); | 561 var handledHintSymbol = GET_PRIVATE(promise, promiseHandledHintSymbol); |
| 555 if (handledHintSymbol) return true; | 562 if (handledHintSymbol) return true; |
| 563 var outerPromise = GET_PRIVATE(promise, promiseAwaitHandlerSymbol); | |
| 564 if (outerPromise) { | |
| 565 return PromiseHasUserDefinedRejectHandlerRecursive(outerPromise); | |
| 566 } | |
| 556 var queue = GET_PRIVATE(promise, promiseRejectReactionsSymbol); | 567 var queue = GET_PRIVATE(promise, promiseRejectReactionsSymbol); |
| 557 var deferreds = GET_PRIVATE(promise, promiseDeferredReactionsSymbol); | 568 var deferreds = GET_PRIVATE(promise, promiseDeferredReactionsSymbol); |
| 558 if (IS_UNDEFINED(queue)) return false; | 569 if (IS_UNDEFINED(queue)) return false; |
| 559 if (!IS_ARRAY(queue)) { | 570 if (!IS_ARRAY(queue)) { |
| 560 return PromiseHasUserDefinedRejectHandlerCheck(queue, deferreds); | 571 return PromiseHasUserDefinedRejectHandlerCheck(queue, deferreds); |
| 561 } else { | 572 } else { |
| 562 for (var i = 0; i < queue.length; i += 2) { | 573 for (var i = 0; i < queue.length; i += 2) { |
| 563 if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], queue[i + 1])) { | 574 if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], queue[i + 1])) { |
| 564 return true; | 575 return true; |
| 565 } | 576 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 to.PromiseThen = PromiseThen; | 638 to.PromiseThen = PromiseThen; |
| 628 | 639 |
| 629 to.GlobalPromise = GlobalPromise; | 640 to.GlobalPromise = GlobalPromise; |
| 630 to.NewPromiseCapability = NewPromiseCapability; | 641 to.NewPromiseCapability = NewPromiseCapability; |
| 631 to.PerformPromiseThen = PerformPromiseThen; | 642 to.PerformPromiseThen = PerformPromiseThen; |
| 632 to.ResolvePromise = ResolvePromise; | 643 to.ResolvePromise = ResolvePromise; |
| 633 to.RejectPromise = RejectPromise; | 644 to.RejectPromise = RejectPromise; |
| 634 }); | 645 }); |
| 635 | 646 |
| 636 }) | 647 }) |
| OLD | NEW |