1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/extensions/regress-50447-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,173 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +/* 1.12 + * SUMMARY: New properties fileName, lineNumber have been added to Error objects 1.13 + * in SpiderMonkey. These are non-ECMA extensions and do not exist in Rhino. 1.14 + * 1.15 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=50447 1.16 + * 1.17 + * 2005-04-05 Modified by bclary to support changes to error reporting 1.18 + * which set default values for the error's fileName and 1.19 + * lineNumber properties. 1.20 + */ 1.21 + 1.22 +//----------------------------------------------------------------------------- 1.23 +var BUGNUMBER = 50447; 1.24 +var summary = 'Test (non-ECMA) Error object properties fileName, lineNumber'; 1.25 + 1.26 + 1.27 +//----------------------------------------------------------------------------- 1.28 +test(); 1.29 +//----------------------------------------------------------------------------- 1.30 + 1.31 + 1.32 +function test() 1.33 +{ 1.34 + enterFunc ('test'); 1.35 + printBugNumber(BUGNUMBER); 1.36 + printStatus (summary); 1.37 + 1.38 + testRealError(); 1.39 + test1(); 1.40 + test2(); 1.41 + test3(); 1.42 + test4(); 1.43 + 1.44 + exitFunc('test'); 1.45 +} 1.46 + 1.47 +// Normalize filenames so this test can work on Windows. This 1.48 +// function is also used on strings that contain filenames. 1.49 +function normalize(filename) 1.50 +{ 1.51 + // Also convert double-backslash to single-slash to handle 1.52 + // escaped filenames in string literals. 1.53 + return filename.replace(/\\{1,2}/g, '/'); 1.54 +} 1.55 + 1.56 +function testRealError() 1.57 +{ 1.58 + /* throw a real error, and see what it looks like */ 1.59 + enterFunc ("testRealError"); 1.60 + 1.61 + try 1.62 + { 1.63 + blabla; 1.64 + } 1.65 + catch (e) 1.66 + { 1.67 + if (e.fileName.search (/-50447-1\.js$/i) == -1) 1.68 + reportCompare('PASS', 'FAIL', "expected fileName to end with '-50447-1.js'"); 1.69 + 1.70 + reportCompare(60, e.lineNumber, 1.71 + "lineNumber property returned unexpected value."); 1.72 + } 1.73 + 1.74 + exitFunc ("testRealError"); 1.75 +} 1.76 + 1.77 + 1.78 +function test1() 1.79 +{ 1.80 + /* generate an error with msg, file, and lineno properties */ 1.81 + enterFunc ("test1"); 1.82 + 1.83 + var e = new InternalError ("msg", "file", 2); 1.84 + reportCompare ("(new InternalError(\"msg\", \"file\", 2))", 1.85 + e.toSource(), 1.86 + "toSource() returned unexpected result."); 1.87 + reportCompare ("file", e.fileName, 1.88 + "fileName property returned unexpected value."); 1.89 + reportCompare (2, e.lineNumber, 1.90 + "lineNumber property returned unexpected value."); 1.91 + 1.92 + exitFunc ("test1"); 1.93 +} 1.94 + 1.95 + 1.96 +function test2() 1.97 +{ 1.98 + /* generate an error with only msg property */ 1.99 + enterFunc ("test2"); 1.100 + 1.101 + /* note this test incorporates the path to the 1.102 + test file and assumes the path to the test case 1.103 + is a subdirectory of the directory containing jsDriver.pl 1.104 + */ 1.105 + var expectedLine = 109; 1.106 + var expectedFileName = 'js1_5/extensions/regress-50447-1.js'; 1.107 + if (typeof document != "undefined") { 1.108 + expectedFileName = document.location.href. 1.109 + replace(/[^\/]*(\?.*)$/, '') + 1.110 + expectedFileName; 1.111 + } 1.112 + var e = new InternalError ("msg"); 1.113 + reportCompare ("(new InternalError(\"msg\", \"" + 1.114 + expectedFileName + "\", " + expectedLine + "))", 1.115 + normalize(e.toSource()), 1.116 + "toSource() returned unexpected result."); 1.117 + reportCompare (expectedFileName, normalize(e.fileName), 1.118 + "fileName property returned unexpected value."); 1.119 + reportCompare (expectedLine, e.lineNumber, 1.120 + "lineNumber property returned unexpected value."); 1.121 + 1.122 + exitFunc ("test2"); 1.123 +} 1.124 + 1.125 + 1.126 +function test3() 1.127 +{ 1.128 + /* generate an error with only msg and lineNo properties */ 1.129 + 1.130 + /* note this test incorporates the path to the 1.131 + test file and assumes the path to the test case 1.132 + is a subdirectory of the directory containing jsDriver.pl 1.133 + */ 1.134 + 1.135 + enterFunc ("test3"); 1.136 + 1.137 + var expectedFileName = 'js1_5/extensions/regress-50447-1.js'; 1.138 + if (typeof document != "undefined") { 1.139 + expectedFileName = document.location.href. 1.140 + replace(/[^\/]*(\?.*)$/, '') + 1.141 + expectedFileName; 1.142 + } 1.143 + 1.144 + var e = new InternalError ("msg"); 1.145 + e.lineNumber = 10; 1.146 + reportCompare ("(new InternalError(\"msg\", \"" + 1.147 + expectedFileName + "\", 10))", 1.148 + normalize(e.toSource()), 1.149 + "toSource() returned unexpected result."); 1.150 + reportCompare (expectedFileName, normalize(e.fileName), 1.151 + "fileName property returned unexpected value."); 1.152 + reportCompare (10, e.lineNumber, 1.153 + "lineNumber property returned unexpected value."); 1.154 + 1.155 + exitFunc ("test3"); 1.156 +} 1.157 + 1.158 + 1.159 +function test4() 1.160 +{ 1.161 + /* generate an error with only msg and filename properties */ 1.162 + enterFunc ("test4"); 1.163 + 1.164 + var expectedLine = 163; 1.165 + 1.166 + var e = new InternalError ("msg", "file"); 1.167 + reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))", 1.168 + e.toSource(), 1.169 + "toSource() returned unexpected result."); 1.170 + reportCompare ("file", e.fileName, 1.171 + "fileName property returned unexpected value."); 1.172 + reportCompare (expectedLine, e.lineNumber, 1.173 + "lineNumber property returned unexpected value."); 1.174 + 1.175 + exitFunc ("test4"); 1.176 +}