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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 function PromiseHandle(value, handler, deferred) { | 185 function PromiseHandle(value, handler, deferred) { |
186 try { | 186 try { |
187 var result = handler(value); | 187 var result = handler(value); |
188 if (result === deferred.promise) | 188 if (result === deferred.promise) |
189 throw MakeTypeError('promise_cyclic', [result]); | 189 throw MakeTypeError('promise_cyclic', [result]); |
190 else if (IsPromise(result)) | 190 else if (IsPromise(result)) |
191 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); | 191 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); |
192 else | 192 else |
193 deferred.resolve(result); | 193 deferred.resolve(result); |
194 } catch(e) { | 194 } catch(e) { |
195 // TODO(rossberg): perhaps log uncaught exceptions below. | 195 if (GET_PRIVATE(deferred.promise, promiseOnReject).length == 0) { |
196 try { deferred.reject(e) } catch(e) {} | 196 // There is no reject handler defined (yet). The debugger should know. |
| 197 %DebugPendingExceptionInPromise(e, deferred.promise); |
| 198 } |
| 199 try { deferred.reject(e) } catch(e) { |
| 200 // Reject handler threw (must have been a custom one). |
| 201 %DebugPendingExceptionInPromise(e, deferred.promise); |
| 202 } |
197 } | 203 } |
198 } | 204 } |
199 | 205 |
200 | 206 |
201 // Multi-unwrapped chaining with thenable coercion. | 207 // Multi-unwrapped chaining with thenable coercion. |
202 | 208 |
203 function PromiseThen(onResolve, onReject) { | 209 function PromiseThen(onResolve, onReject) { |
204 onResolve = | 210 onResolve = |
205 IS_NULL_OR_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve; | 211 IS_NULL_OR_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve; |
206 onReject = | 212 onReject = |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 "resolve", PromiseCast | 324 "resolve", PromiseCast |
319 ]); | 325 ]); |
320 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 326 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
321 "chain", PromiseChain, | 327 "chain", PromiseChain, |
322 "then", PromiseThen, | 328 "then", PromiseThen, |
323 "catch", PromiseCatch | 329 "catch", PromiseCatch |
324 ]); | 330 ]); |
325 } | 331 } |
326 | 332 |
327 SetUpPromise(); | 333 SetUpPromise(); |
OLD | NEW |