test_js_dev_error_interceptor.js (1546B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 "use strict"; 7 8 function errors() { 9 return [ 10 // The following two errors MUST NOT be captured. 11 new Error("This is an error: " + Math.random()), 12 new RangeError("This is a RangeError: " + Math.random()), 13 new TypeError("This is a TypeError: " + Math.random()), 14 "This is a string: " + Math.random(), 15 null, 16 undefined, 17 Math.random(), 18 {}, 19 20 // The following errors MUST be captured. 21 new SyntaxError("This is a SyntaxError: " + Math.random()), 22 new ReferenceError("This is a ReferenceError: " + Math.random()), 23 ]; 24 } 25 26 function isDeveloperError(e) { 27 if (e == null || typeof e != "object") { 28 return false; 29 } 30 31 return e.constructor == SyntaxError || e.constructor == ReferenceError; 32 } 33 34 function run_test() { 35 ChromeUtils.clearRecentJSDevError(); 36 Assert.equal(ChromeUtils.recentJSDevError, undefined); 37 38 for (let exn of errors()) { 39 ChromeUtils.clearRecentJSDevError(); 40 try { 41 throw exn; 42 } catch (e) { 43 // Discard error. 44 } 45 if (isDeveloperError(exn)) { 46 Assert.equal(ChromeUtils.recentJSDevError.message, "" + exn); 47 } else { 48 Assert.equal(ChromeUtils.recentJSDevError, undefined); 49 } 50 ChromeUtils.clearRecentJSDevError(); 51 Assert.equal(ChromeUtils.recentJSDevError, undefined); 52 } 53 }