123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <!DOCTYPE html>
- <html>
- <!--
- Copyright 2013 The Closure Library Authors. All Rights Reserved.
- -->
- <head>
- <title>Closure Unit Tests - goog.async.Deferred</title>
- <script src="../../../../../closure/goog/base.js"></script>
- <script>
- goog.require('goog.async.Deferred');
- goog.require('goog.testing.jsunit');
- </script>
- </head>
- <body>
- <script>
- function shouldRunTests() {
- return !!Error.captureStackTrace;
- }
- function setUpPage() {
- goog.async.Deferred.LONG_STACK_TRACES = true;
- }
- function testErrorStack() {
- var d;
- // Get the deferred from somewhere deep in the callstack.
- (function immediate() {
- (function immediate2() {
- d = new goog.async.Deferred();
- d.addCallback(function actuallyThrows() { throw new Error('Foo'); });
- })();
- })();
- window.setTimeout(function willThrow() {
- (function callbackCaller() { d.callback(); })();
- }, 0);
- return d.then(fail, function(error) {
- assertContains('Foo', error.stack);
- assertContains('testErrorStack', error.stack);
- assertContains('callbackCaller', error.stack);
- assertContains('willThrow', error.stack);
- assertContains('actuallyThrows', error.stack);
- assertContains('DEFERRED OPERATION', error.stack);
- assertContains('immediate', error.stack);
- assertContains('immediate2', error.stack);
- });
- }
- function testErrorStack_forErrback() {
- var d = new goog.async.Deferred();
- window.setTimeout(function willThrow() { d.errback(new Error('Foo')); }, 0);
- return d.then(fail, function(error) {
- assertContains('Foo', error.stack);
- assertContains('testErrorStack_forErrback', error.stack);
- assertContains('willThrow', error.stack);
- assertContains('DEFERRED OPERATION', error.stack);
- });
- }
- function testErrorStack_nested() {
- var d = new goog.async.Deferred();
- window.setTimeout(function async1() {
- var nested = new goog.async.Deferred();
- nested.addErrback(function nestedErrback(error) { d.errback(error); });
- window.setTimeout(function async2() {
- (function immediate() { nested.errback(new Error('Foo')); })();
- });
- }, 0);
- return d.then(fail, function(error) {
- assertContains('Foo', error.stack);
- assertContains('testErrorStack_nested', error.stack);
- assertContains('async1', error.stack);
- assertContains('async2', error.stack);
- assertContains('immediate', error.stack);
- assertContains('DEFERRED OPERATION', error.stack);
- });
- }
- function testErrorStack_doesNotTouchCustomStack() {
- var d = new goog.async.Deferred();
- d.addCallback(function actuallyThrows() {
- var e = new Error('Foo');
- e.stack = 'STACK';
- throw e;
- });
- window.setTimeout(function willThrow() {
- (function callbackCaller() { d.callback(); })();
- }, 0);
- return d.then(fail, function(error) { assertEquals('STACK', error.stack); });
- }
- </script>
- </body>
- </html>
|