Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | /* |
michael@0 | 9 | * SUMMARY: New properties fileName, lineNumber have been added to Error objects |
michael@0 | 10 | * in SpiderMonkey. These are non-ECMA extensions and do not exist in Rhino. |
michael@0 | 11 | * |
michael@0 | 12 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=50447 |
michael@0 | 13 | * |
michael@0 | 14 | * 2005-04-05 Modified by bclary to support changes to error reporting |
michael@0 | 15 | * which set default values for the error's fileName and |
michael@0 | 16 | * lineNumber properties. |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | //----------------------------------------------------------------------------- |
michael@0 | 20 | var BUGNUMBER = 50447; |
michael@0 | 21 | var summary = 'Test (non-ECMA) Error object properties fileName, lineNumber'; |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | //----------------------------------------------------------------------------- |
michael@0 | 25 | test(); |
michael@0 | 26 | //----------------------------------------------------------------------------- |
michael@0 | 27 | |
michael@0 | 28 | |
michael@0 | 29 | function test() |
michael@0 | 30 | { |
michael@0 | 31 | enterFunc ('test'); |
michael@0 | 32 | printBugNumber(BUGNUMBER); |
michael@0 | 33 | printStatus (summary); |
michael@0 | 34 | |
michael@0 | 35 | testRealError(); |
michael@0 | 36 | test1(); |
michael@0 | 37 | test2(); |
michael@0 | 38 | test3(); |
michael@0 | 39 | test4(); |
michael@0 | 40 | |
michael@0 | 41 | exitFunc('test'); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | // Normalize filenames so this test can work on Windows. This |
michael@0 | 45 | // function is also used on strings that contain filenames. |
michael@0 | 46 | function normalize(filename) |
michael@0 | 47 | { |
michael@0 | 48 | // Also convert double-backslash to single-slash to handle |
michael@0 | 49 | // escaped filenames in string literals. |
michael@0 | 50 | return filename.replace(/\\{1,2}/g, '/'); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function testRealError() |
michael@0 | 54 | { |
michael@0 | 55 | /* throw a real error, and see what it looks like */ |
michael@0 | 56 | enterFunc ("testRealError"); |
michael@0 | 57 | |
michael@0 | 58 | try |
michael@0 | 59 | { |
michael@0 | 60 | blabla; |
michael@0 | 61 | } |
michael@0 | 62 | catch (e) |
michael@0 | 63 | { |
michael@0 | 64 | if (e.fileName.search (/-50447-1\.js$/i) == -1) |
michael@0 | 65 | reportCompare('PASS', 'FAIL', "expected fileName to end with '-50447-1.js'"); |
michael@0 | 66 | |
michael@0 | 67 | reportCompare(60, e.lineNumber, |
michael@0 | 68 | "lineNumber property returned unexpected value."); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | exitFunc ("testRealError"); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | |
michael@0 | 75 | function test1() |
michael@0 | 76 | { |
michael@0 | 77 | /* generate an error with msg, file, and lineno properties */ |
michael@0 | 78 | enterFunc ("test1"); |
michael@0 | 79 | |
michael@0 | 80 | var e = new InternalError ("msg", "file", 2); |
michael@0 | 81 | reportCompare ("(new InternalError(\"msg\", \"file\", 2))", |
michael@0 | 82 | e.toSource(), |
michael@0 | 83 | "toSource() returned unexpected result."); |
michael@0 | 84 | reportCompare ("file", e.fileName, |
michael@0 | 85 | "fileName property returned unexpected value."); |
michael@0 | 86 | reportCompare (2, e.lineNumber, |
michael@0 | 87 | "lineNumber property returned unexpected value."); |
michael@0 | 88 | |
michael@0 | 89 | exitFunc ("test1"); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | |
michael@0 | 93 | function test2() |
michael@0 | 94 | { |
michael@0 | 95 | /* generate an error with only msg property */ |
michael@0 | 96 | enterFunc ("test2"); |
michael@0 | 97 | |
michael@0 | 98 | /* note this test incorporates the path to the |
michael@0 | 99 | test file and assumes the path to the test case |
michael@0 | 100 | is a subdirectory of the directory containing jsDriver.pl |
michael@0 | 101 | */ |
michael@0 | 102 | var expectedLine = 109; |
michael@0 | 103 | var expectedFileName = 'js1_5/extensions/regress-50447-1.js'; |
michael@0 | 104 | if (typeof document != "undefined") { |
michael@0 | 105 | expectedFileName = document.location.href. |
michael@0 | 106 | replace(/[^\/]*(\?.*)$/, '') + |
michael@0 | 107 | expectedFileName; |
michael@0 | 108 | } |
michael@0 | 109 | var e = new InternalError ("msg"); |
michael@0 | 110 | reportCompare ("(new InternalError(\"msg\", \"" + |
michael@0 | 111 | expectedFileName + "\", " + expectedLine + "))", |
michael@0 | 112 | normalize(e.toSource()), |
michael@0 | 113 | "toSource() returned unexpected result."); |
michael@0 | 114 | reportCompare (expectedFileName, normalize(e.fileName), |
michael@0 | 115 | "fileName property returned unexpected value."); |
michael@0 | 116 | reportCompare (expectedLine, e.lineNumber, |
michael@0 | 117 | "lineNumber property returned unexpected value."); |
michael@0 | 118 | |
michael@0 | 119 | exitFunc ("test2"); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | |
michael@0 | 123 | function test3() |
michael@0 | 124 | { |
michael@0 | 125 | /* generate an error with only msg and lineNo properties */ |
michael@0 | 126 | |
michael@0 | 127 | /* note this test incorporates the path to the |
michael@0 | 128 | test file and assumes the path to the test case |
michael@0 | 129 | is a subdirectory of the directory containing jsDriver.pl |
michael@0 | 130 | */ |
michael@0 | 131 | |
michael@0 | 132 | enterFunc ("test3"); |
michael@0 | 133 | |
michael@0 | 134 | var expectedFileName = 'js1_5/extensions/regress-50447-1.js'; |
michael@0 | 135 | if (typeof document != "undefined") { |
michael@0 | 136 | expectedFileName = document.location.href. |
michael@0 | 137 | replace(/[^\/]*(\?.*)$/, '') + |
michael@0 | 138 | expectedFileName; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | var e = new InternalError ("msg"); |
michael@0 | 142 | e.lineNumber = 10; |
michael@0 | 143 | reportCompare ("(new InternalError(\"msg\", \"" + |
michael@0 | 144 | expectedFileName + "\", 10))", |
michael@0 | 145 | normalize(e.toSource()), |
michael@0 | 146 | "toSource() returned unexpected result."); |
michael@0 | 147 | reportCompare (expectedFileName, normalize(e.fileName), |
michael@0 | 148 | "fileName property returned unexpected value."); |
michael@0 | 149 | reportCompare (10, e.lineNumber, |
michael@0 | 150 | "lineNumber property returned unexpected value."); |
michael@0 | 151 | |
michael@0 | 152 | exitFunc ("test3"); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | |
michael@0 | 156 | function test4() |
michael@0 | 157 | { |
michael@0 | 158 | /* generate an error with only msg and filename properties */ |
michael@0 | 159 | enterFunc ("test4"); |
michael@0 | 160 | |
michael@0 | 161 | var expectedLine = 163; |
michael@0 | 162 | |
michael@0 | 163 | var e = new InternalError ("msg", "file"); |
michael@0 | 164 | reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))", |
michael@0 | 165 | e.toSource(), |
michael@0 | 166 | "toSource() returned unexpected result."); |
michael@0 | 167 | reportCompare ("file", e.fileName, |
michael@0 | 168 | "fileName property returned unexpected value."); |
michael@0 | 169 | reportCompare (expectedLine, e.lineNumber, |
michael@0 | 170 | "lineNumber property returned unexpected value."); |
michael@0 | 171 | |
michael@0 | 172 | exitFunc ("test4"); |
michael@0 | 173 | } |