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 // 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 } catch(e) { | 193 } catch(e) { |
| 194 // TODO(rossberg): perhaps log uncaught exceptions below. | 194 // TODO(rossberg): perhaps log uncaught exceptions below. |
| 195 try { deferred.reject(e) } catch(e) {} | 195 try { deferred.reject(e) } catch(e) {} |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 | 199 |
| 200 // Multi-unwrapped chaining with thenable coercion. | 200 // Multi-unwrapped chaining with thenable coercion. |
| 201 | 201 |
| 202 function PromiseThen(onResolve, onReject) { | 202 function PromiseThen(onResolve, onReject) { |
| 203 onResolve = | 203 if (typeof onResolve !== 'function') onResolve = PromiseIdResolveHandler; |
|
arv (Not doing code reviews)
2014/03/27 21:10:46
Maybe we should add an IsCallable macro?
| |
| 204 IS_NULL_OR_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve; | 204 if (typeof onReject !== 'function') onReject = PromiseIdRejectHandler; |
| 205 onReject = | |
| 206 IS_NULL_OR_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject; | |
| 207 var that = this; | 205 var that = this; |
| 208 var constructor = this.constructor; | 206 var constructor = this.constructor; |
| 209 return %_CallFunction( | 207 return %_CallFunction( |
| 210 this, | 208 this, |
| 211 function(x) { | 209 function(x) { |
| 212 x = PromiseCoerce(constructor, x); | 210 x = PromiseCoerce(constructor, x); |
| 213 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : | 211 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : |
| 214 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); | 212 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); |
| 215 }, | 213 }, |
| 216 onReject, | 214 onReject, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 "resolve", PromiseCast | 315 "resolve", PromiseCast |
| 318 ]); | 316 ]); |
| 319 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 317 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 320 "chain", PromiseChain, | 318 "chain", PromiseChain, |
| 321 "then", PromiseThen, | 319 "then", PromiseThen, |
| 322 "catch", PromiseCatch | 320 "catch", PromiseCatch |
| 323 ]); | 321 ]); |
| 324 } | 322 } |
| 325 | 323 |
| 326 SetUpPromise(); | 324 SetUpPromise(); |
| OLD | NEW |