michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // This test is designed to fail. michael@0: // It ensures that throwing an asynchronous error from add_task will michael@0: // fail the test. michael@0: michael@0: let passedTests = 0; michael@0: michael@0: function rejectWithTimeout(error = undefined) { michael@0: let deferred = Promise.defer(); michael@0: executeSoon(function() { michael@0: ok(true, "we get here after a timeout"); michael@0: deferred.reject(error); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: add_task(function failWithoutError() { michael@0: try { michael@0: yield rejectWithTimeout(); michael@0: } finally { michael@0: ++passedTests; michael@0: } michael@0: }); michael@0: michael@0: add_task(function failWithString() { michael@0: try { michael@0: yield rejectWithTimeout("Meaningless error"); michael@0: } finally { michael@0: ++passedTests; michael@0: } michael@0: }); michael@0: michael@0: add_task(function failWithoutInt() { michael@0: try { michael@0: yield rejectWithTimeout(42); michael@0: } finally { michael@0: ++passedTests; michael@0: } michael@0: }); michael@0: michael@0: michael@0: // This one should display a stack trace michael@0: add_task(function failWithError() { michael@0: try { michael@0: yield rejectWithTimeout(new Error("This is an error")); michael@0: } finally { michael@0: ++passedTests; michael@0: } michael@0: }); michael@0: michael@0: add_task(function done() { michael@0: is(passedTests, 4, "Passed all tests"); michael@0: });