| 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 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 return deferred.promise; | 97 return deferred.promise; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 return x; | 100 return x; |
| 101 } | 101 } |
| 102 | 102 |
| 103 function PromiseHandle(value, handler, deferred) { | 103 function PromiseHandle(value, handler, deferred) { |
| 104 try { | 104 try { |
| 105 %DebugPushPromise(deferred.promise); | 105 %DebugPushPromise(deferred.promise); |
| 106 DEBUG_PREPARE_STEP_IN_IF_STEPPING(handler); |
| 106 var result = handler(value); | 107 var result = handler(value); |
| 107 if (result === deferred.promise) | 108 if (result === deferred.promise) |
| 108 throw MakeTypeError('promise_cyclic', [result]); | 109 throw MakeTypeError('promise_cyclic', [result]); |
| 109 else if (IsPromise(result)) | 110 else if (IsPromise(result)) |
| 110 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); | 111 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); |
| 111 else | 112 else |
| 112 deferred.resolve(result); | 113 deferred.resolve(result); |
| 113 } catch (exception) { | 114 } catch (exception) { |
| 114 try { deferred.reject(exception); } catch (e) { } | 115 try { deferred.reject(exception); } catch (e) { } |
| 115 } finally { | 116 } finally { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 onResolve = IS_SPEC_FUNCTION(onResolve) ? onResolve | 264 onResolve = IS_SPEC_FUNCTION(onResolve) ? onResolve |
| 264 : PromiseIdResolveHandler; | 265 : PromiseIdResolveHandler; |
| 265 onReject = IS_SPEC_FUNCTION(onReject) ? onReject | 266 onReject = IS_SPEC_FUNCTION(onReject) ? onReject |
| 266 : PromiseIdRejectHandler; | 267 : PromiseIdRejectHandler; |
| 267 var that = this; | 268 var that = this; |
| 268 var constructor = this.constructor; | 269 var constructor = this.constructor; |
| 269 return %_CallFunction( | 270 return %_CallFunction( |
| 270 this, | 271 this, |
| 271 function(x) { | 272 function(x) { |
| 272 x = PromiseCoerce(constructor, x); | 273 x = PromiseCoerce(constructor, x); |
| 273 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : | 274 if (x === that) { |
| 274 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); | 275 DEBUG_PREPARE_STEP_IN_IF_STEPPING(onReject); |
| 276 return onReject(MakeTypeError('promise_cyclic', [x])); |
| 277 } else if (IsPromise(x)) { |
| 278 return x.then(onResolve, onReject); |
| 279 } else { |
| 280 DEBUG_PREPARE_STEP_IN_IF_STEPPING(onResolve); |
| 281 return onResolve(x); |
| 282 } |
| 275 }, | 283 }, |
| 276 onReject, | 284 onReject, |
| 277 PromiseChain | 285 PromiseChain |
| 278 ); | 286 ); |
| 279 } | 287 } |
| 280 | 288 |
| 281 // Combinators. | 289 // Combinators. |
| 282 | 290 |
| 283 function PromiseCast(x) { | 291 function PromiseCast(x) { |
| 284 // TODO(rossberg): cannot do better until we support @@create. | 292 // TODO(rossberg): cannot do better until we support @@create. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 "race", PromiseOne, | 383 "race", PromiseOne, |
| 376 "resolve", PromiseCast | 384 "resolve", PromiseCast |
| 377 ]); | 385 ]); |
| 378 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 386 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 379 "chain", PromiseChain, | 387 "chain", PromiseChain, |
| 380 "then", PromiseThen, | 388 "then", PromiseThen, |
| 381 "catch", PromiseCatch | 389 "catch", PromiseCatch |
| 382 ]); | 390 ]); |
| 383 | 391 |
| 384 })(); | 392 })(); |
| OLD | NEW |