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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ); | 317 ); |
318 } | 318 } |
319 } catch (e) { | 319 } catch (e) { |
320 deferred.reject(e) | 320 deferred.reject(e) |
321 } | 321 } |
322 return deferred.promise; | 322 return deferred.promise; |
323 } | 323 } |
324 | 324 |
325 | 325 |
326 // Utility for debugger | 326 // Utility for debugger |
| 327 |
| 328 function PromiseHasRejectHandlerRecursive(promise) { |
| 329 var queue = GET_PRIVATE(promise, promiseOnReject); |
| 330 if (IS_UNDEFINED(queue)) return false; |
| 331 // Do a depth first search for a reject handler that's not |
| 332 // the default PromiseIdRejectHandler. |
| 333 for (var i = 0; i < queue.length; i += 2) { |
| 334 if (queue[i] != PromiseIdRejectHandler) return true; |
| 335 if (PromiseHasRejectHandlerRecursive(queue[i + 1])) return true; |
| 336 } |
| 337 return false; |
| 338 } |
327 | 339 |
328 PromiseHasRejectHandler = function PromiseHasRejectHandler() { | 340 PromiseHasRejectHandler = function PromiseHasRejectHandler() { |
329 // Mark promise as already having triggered a reject event. | 341 // Mark promise as already having triggered a reject event. |
330 SET_PRIVATE(this, promiseDebug, true); | 342 SET_PRIVATE(this, promiseDebug, true); |
331 var queue = GET_PRIVATE(this, promiseOnReject); | 343 return PromiseHasRejectHandlerRecursive(this); |
332 return !IS_UNDEFINED(queue) && queue.length > 0; | |
333 }; | 344 }; |
334 | 345 |
335 // ------------------------------------------------------------------- | 346 // ------------------------------------------------------------------- |
336 // Install exported functions. | 347 // Install exported functions. |
337 | 348 |
338 %CheckIsBootstrapping(); | 349 %CheckIsBootstrapping(); |
339 %AddNamedProperty(global, 'Promise', $Promise, DONT_ENUM); | 350 %AddNamedProperty(global, 'Promise', $Promise, DONT_ENUM); |
340 InstallFunctions($Promise, DONT_ENUM, [ | 351 InstallFunctions($Promise, DONT_ENUM, [ |
341 "defer", PromiseDeferred, | 352 "defer", PromiseDeferred, |
342 "accept", PromiseResolved, | 353 "accept", PromiseResolved, |
343 "reject", PromiseRejected, | 354 "reject", PromiseRejected, |
344 "all", PromiseAll, | 355 "all", PromiseAll, |
345 "race", PromiseOne, | 356 "race", PromiseOne, |
346 "resolve", PromiseCast | 357 "resolve", PromiseCast |
347 ]); | 358 ]); |
348 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 359 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
349 "chain", PromiseChain, | 360 "chain", PromiseChain, |
350 "then", PromiseThen, | 361 "then", PromiseThen, |
351 "catch", PromiseCatch | 362 "catch", PromiseCatch |
352 ]); | 363 ]); |
353 | 364 |
354 })(); | 365 })(); |
OLD | NEW |