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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 } | 162 } |
| 163 PromiseSet(promise, status, value); | 163 PromiseSet(promise, status, value); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 function PromiseHandle(value, handler, deferred) { | 167 function PromiseHandle(value, handler, deferred) { |
| 168 var debug_is_active = DEBUG_IS_ACTIVE; | 168 var debug_is_active = DEBUG_IS_ACTIVE; |
| 169 try { | 169 try { |
| 170 if (debug_is_active) %DebugPushPromise(deferred.promise); | 170 if (debug_is_active) %DebugPushPromise(deferred.promise); |
| 171 var result = handler(value); | 171 var result = handler(value); |
| 172 deferred.resolve(result); | 172 if (deferred.resolve) { deferred.resolve(result); } |
|
adamk
2016/10/05 22:12:00
And an explicit IS_UNDEFINED() check for these, ju
gsathya
2016/10/05 22:47:40
Done.
| |
| 173 else { ResolvePromise(deferred.promise, result); } | |
|
adamk
2016/10/05 22:12:00
Please reformat this and the below into the usual
gsathya
2016/10/05 22:47:40
Done.
| |
| 173 } %catch (exception) { // Natives syntax to mark this catch block. | 174 } %catch (exception) { // Natives syntax to mark this catch block. |
| 174 try { deferred.reject(exception); } catch (e) { } | 175 try { |
| 176 if (deferred.reject) { deferred.reject(exception); } | |
| 177 else { RejectPromise(deferred.promise, exception, false); } | |
|
adamk
2016/10/05 22:12:00
This needs a comment for why false is the third ar
gsathya
2016/10/05 22:47:40
Done.
| |
| 178 } catch (e) { } | |
| 175 } finally { | 179 } finally { |
| 176 if (debug_is_active) %DebugPopPromise(); | 180 if (debug_is_active) %DebugPopPromise(); |
| 177 } | 181 } |
| 178 } | 182 } |
| 179 | 183 |
| 180 function PromiseEnqueue(value, tasks, deferreds, status) { | 184 function PromiseEnqueue(value, tasks, deferreds, status) { |
| 181 var id, name, instrumenting = DEBUG_IS_ACTIVE; | 185 var id, name, instrumenting = DEBUG_IS_ACTIVE; |
| 182 %EnqueueMicrotask(function() { | 186 %EnqueueMicrotask(function() { |
| 183 if (instrumenting) { | 187 if (instrumenting) { |
| 184 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); | 188 %DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name }); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 // ES#sec-promise.prototype.then | 449 // ES#sec-promise.prototype.then |
| 446 // Promise.prototype.then ( onFulfilled, onRejected ) | 450 // Promise.prototype.then ( onFulfilled, onRejected ) |
| 447 // Multi-unwrapped chaining with thenable coercion. | 451 // Multi-unwrapped chaining with thenable coercion. |
| 448 function PromiseThen(onResolve, onReject) { | 452 function PromiseThen(onResolve, onReject) { |
| 449 var status = GET_PRIVATE(this, promiseStateSymbol); | 453 var status = GET_PRIVATE(this, promiseStateSymbol); |
| 450 if (IS_UNDEFINED(status)) { | 454 if (IS_UNDEFINED(status)) { |
| 451 throw %make_type_error(kNotAPromise, this); | 455 throw %make_type_error(kNotAPromise, this); |
| 452 } | 456 } |
| 453 | 457 |
| 454 var constructor = SpeciesConstructor(this, GlobalPromise); | 458 var constructor = SpeciesConstructor(this, GlobalPromise); |
| 455 // Pass false for debugEvent so .then chaining does not trigger | 459 var resultCapability; |
| 456 // redundant ExceptionEvents. | 460 if (constructor === GlobalPromise) { |
| 457 var resultCapability = NewPromiseCapability(constructor, false); | 461 resultCapability = { |
|
adamk
2016/10/05 22:12:00
Please add a comment here explaining this special
gsathya
2016/10/05 22:47:40
Done.
| |
| 462 promise: PromiseCreate(), | |
| 463 resolve: false, | |
| 464 reject: false | |
|
adamk
2016/10/05 22:12:00
How about UNDEFINED for these falses...
gsathya
2016/10/05 22:47:40
Done.
| |
| 465 }; | |
| 466 } else { | |
| 467 // Pass false for debugEvent so .then chaining does not trigger | |
| 468 // redundant ExceptionEvents. | |
| 469 resultCapability = NewPromiseCapability(constructor, false); | |
| 470 } | |
| 458 return PerformPromiseThen(this, onResolve, onReject, resultCapability); | 471 return PerformPromiseThen(this, onResolve, onReject, resultCapability); |
| 459 } | 472 } |
| 460 | 473 |
| 461 // ES#sec-promise.prototype.catch | 474 // ES#sec-promise.prototype.catch |
| 462 // Promise.prototype.catch ( onRejected ) | 475 // Promise.prototype.catch ( onRejected ) |
| 463 function PromiseCatch(onReject) { | 476 function PromiseCatch(onReject) { |
| 464 return this.then(UNDEFINED, onReject); | 477 return this.then(UNDEFINED, onReject); |
| 465 } | 478 } |
| 466 | 479 |
| 467 // Combinators. | 480 // Combinators. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 to.PromiseNextMicrotaskID = PromiseNextMicrotaskID; | 709 to.PromiseNextMicrotaskID = PromiseNextMicrotaskID; |
| 697 | 710 |
| 698 to.GlobalPromise = GlobalPromise; | 711 to.GlobalPromise = GlobalPromise; |
| 699 to.NewPromiseCapability = NewPromiseCapability; | 712 to.NewPromiseCapability = NewPromiseCapability; |
| 700 to.PerformPromiseThen = PerformPromiseThen; | 713 to.PerformPromiseThen = PerformPromiseThen; |
| 701 to.ResolvePromise = ResolvePromise; | 714 to.ResolvePromise = ResolvePromise; |
| 702 to.RejectPromise = RejectPromise; | 715 to.RejectPromise = RejectPromise; |
| 703 }); | 716 }); |
| 704 | 717 |
| 705 }) | 718 }) |
| OLD | NEW |