| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // TODO(rossberg): perhaps log uncaught exceptions below. | 195 // TODO(rossberg): perhaps log uncaught exceptions below. |
| 196 try { deferred.reject(e) } catch(e) {} | 196 try { deferred.reject(e) } catch(e) {} |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 // Multi-unwrapped chaining with thenable coercion. | 201 // Multi-unwrapped chaining with thenable coercion. |
| 202 | 202 |
| 203 function PromiseThen(onResolve, onReject) { | 203 function PromiseThen(onResolve, onReject) { |
| 204 onResolve = | 204 onResolve = |
| 205 IS_NULL_OR_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve; | 205 IS_SPEC_FUNCTION(onResolve) ? onResolve : PromiseIdResolveHandler; |
| 206 onReject = | 206 onReject = |
| 207 IS_NULL_OR_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject; | 207 IS_SPEC_FUNCTION(onReject) ? onReject : PromiseIdRejectHandler; |
| 208 var that = this; | 208 var that = this; |
| 209 var constructor = this.constructor; | 209 var constructor = this.constructor; |
| 210 return %_CallFunction( | 210 return %_CallFunction( |
| 211 this, | 211 this, |
| 212 function(x) { | 212 function(x) { |
| 213 x = PromiseCoerce(constructor, x); | 213 x = PromiseCoerce(constructor, x); |
| 214 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : | 214 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : |
| 215 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); | 215 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); |
| 216 }, | 216 }, |
| 217 onReject, | 217 onReject, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 "resolve", PromiseCast | 318 "resolve", PromiseCast |
| 319 ]); | 319 ]); |
| 320 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 320 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 321 "chain", PromiseChain, | 321 "chain", PromiseChain, |
| 322 "then", PromiseThen, | 322 "then", PromiseThen, |
| 323 "catch", PromiseCatch | 323 "catch", PromiseCatch |
| 324 ]); | 324 ]); |
| 325 } | 325 } |
| 326 | 326 |
| 327 SetUpPromise(); | 327 SetUpPromise(); |
| OLD | NEW |