| 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 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Object = global.Object | 9 // var $Object = global.Object |
| 10 // var $WeakMap = global.WeakMap | 10 // var $WeakMap = global.WeakMap |
| 11 | 11 |
| 12 // For bootstrapper. | 12 // For bootstrapper. |
| 13 | 13 |
| 14 var IsPromise; | 14 var IsPromise; |
| 15 var PromiseCreate; | 15 var PromiseCreate; |
| 16 var PromiseResolve; | 16 var PromiseResolve; |
| 17 var PromiseReject; | 17 var PromiseReject; |
| 18 var PromiseChain; | 18 var PromiseChain; |
| 19 var PromiseCatch; | 19 var PromiseCatch; |
| 20 var PromiseThen; |
| 20 | 21 |
| 21 // mirror-debugger.js currently uses builtins.promiseStatus. It would be nice | 22 // mirror-debugger.js currently uses builtins.promiseStatus. It would be nice |
| 22 // if we could move these property names into the closure below. | 23 // if we could move these property names into the closure below. |
| 23 // TODO(jkummerow/rossberg/yangguo): Find a better solution. | 24 // TODO(jkummerow/rossberg/yangguo): Find a better solution. |
| 24 | 25 |
| 25 // Status values: 0 = pending, +1 = resolved, -1 = rejected | 26 // Status values: 0 = pending, +1 = resolved, -1 = rejected |
| 26 var promiseStatus = GLOBAL_PRIVATE("Promise#status"); | 27 var promiseStatus = GLOBAL_PRIVATE("Promise#status"); |
| 27 var promiseValue = GLOBAL_PRIVATE("Promise#value"); | 28 var promiseValue = GLOBAL_PRIVATE("Promise#value"); |
| 28 var promiseOnResolve = GLOBAL_PRIVATE("Promise#onResolve"); | 29 var promiseOnResolve = GLOBAL_PRIVATE("Promise#onResolve"); |
| 29 var promiseOnReject = GLOBAL_PRIVATE("Promise#onReject"); | 30 var promiseOnReject = GLOBAL_PRIVATE("Promise#onReject"); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 214 } |
| 214 return deferred.promise; | 215 return deferred.promise; |
| 215 } | 216 } |
| 216 | 217 |
| 217 PromiseCatch = function PromiseCatch(onReject) { | 218 PromiseCatch = function PromiseCatch(onReject) { |
| 218 return this.then(UNDEFINED, onReject); | 219 return this.then(UNDEFINED, onReject); |
| 219 } | 220 } |
| 220 | 221 |
| 221 // Multi-unwrapped chaining with thenable coercion. | 222 // Multi-unwrapped chaining with thenable coercion. |
| 222 | 223 |
| 223 function PromiseThen(onResolve, onReject) { | 224 PromiseThen = function PromiseThen(onResolve, onReject) { |
| 224 onResolve = IS_SPEC_FUNCTION(onResolve) ? onResolve | 225 onResolve = IS_SPEC_FUNCTION(onResolve) ? onResolve |
| 225 : PromiseIdResolveHandler; | 226 : PromiseIdResolveHandler; |
| 226 onReject = IS_SPEC_FUNCTION(onReject) ? onReject | 227 onReject = IS_SPEC_FUNCTION(onReject) ? onReject |
| 227 : PromiseIdRejectHandler; | 228 : PromiseIdRejectHandler; |
| 228 var that = this; | 229 var that = this; |
| 229 var constructor = this.constructor; | 230 var constructor = this.constructor; |
| 230 return %_CallFunction( | 231 return %_CallFunction( |
| 231 this, | 232 this, |
| 232 function(x) { | 233 function(x) { |
| 233 x = PromiseCoerce(constructor, x); | 234 x = PromiseCoerce(constructor, x); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 "race", PromiseOne, | 308 "race", PromiseOne, |
| 308 "resolve", PromiseCast | 309 "resolve", PromiseCast |
| 309 ]); | 310 ]); |
| 310 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 311 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 311 "chain", PromiseChain, | 312 "chain", PromiseChain, |
| 312 "then", PromiseThen, | 313 "then", PromiseThen, |
| 313 "catch", PromiseCatch | 314 "catch", PromiseCatch |
| 314 ]); | 315 ]); |
| 315 | 316 |
| 316 })(); | 317 })(); |
| OLD | NEW |