| 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 | /* |
| 7 | * |
| 8 | * Date: 01 Feb 2002 |
| 9 | * SUMMARY: Testing Error.length |
| 10 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=123002 |
| 11 | * |
| 12 | * NOTE: Error.length should equal the length of FormalParameterList of the |
| 13 | * Error constructor. This is currently 1 in Rhino, 3 in SpiderMonkey. |
| 14 | * |
| 15 | * The difference is due to http://bugzilla.mozilla.org/show_bug.cgi?id=50447. |
| 16 | * As a result of that bug, SpiderMonkey has extended ECMA to allow two new |
| 17 | * parameters to Error constructors: |
| 18 | * |
| 19 | * Rhino: new Error (message) |
| 20 | * SpiderMonkey: new Error (message, fileName, lineNumber) |
| 21 | * |
| 22 | * NOTE: since we have hard-coded the length expectations, this testcase will |
| 23 | * have to be changed if the Error FormalParameterList is ever changed again. |
| 24 | * |
| 25 | * To do this, just change the two LENGTH constants below - |
| 26 | */ |
| 27 | //----------------------------------------------------------------------------- |
| 28 | var gTestfile = 'regress-123002.js'; |
| 29 | var LENGTH_RHINO = 1; |
| 30 | var LENGTH_SPIDERMONKEY = 3; |
| 31 | var UBound = 0; |
| 32 | var BUGNUMBER = 123002; |
| 33 | var summary = 'Testing Error.length'; |
| 34 | var QUOTE = '"'; |
| 35 | var status = ''; |
| 36 | var statusitems = []; |
| 37 | var actual = ''; |
| 38 | var actualvalues = []; |
| 39 | var expect= ''; |
| 40 | var expectedvalues = []; |
| 41 | |
| 42 | |
| 43 | /* |
| 44 | * Are we in Rhino or SpiderMonkey? |
| 45 | */ |
| 46 | var LENGTH_EXPECTED = inRhino()? LENGTH_RHINO : LENGTH_SPIDERMONKEY; |
| 47 | |
| 48 | /* |
| 49 | * The various NativeError objects; see ECMA-262 Edition 3, Section 15.11.6 |
| 50 | */ |
| 51 | var errObjects = [new Error(), new EvalError(), new RangeError(), |
| 52 | new ReferenceError(), new SyntaxError(), new TypeError(), new URIError()]; |
| 53 | |
| 54 | |
| 55 | for (var i in errObjects) |
| 56 | { |
| 57 | var err = errObjects[i]; |
| 58 | status = inSection(quoteThis(err.name)); |
| 59 | actual = Error.length; |
| 60 | expect = LENGTH_EXPECTED; |
| 61 | addThis(); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | //----------------------------------------------------------------------------- |
| 67 | test(); |
| 68 | //----------------------------------------------------------------------------- |
| 69 | |
| 70 | |
| 71 | |
| 72 | function addThis() |
| 73 | { |
| 74 | statusitems[UBound] = status; |
| 75 | actualvalues[UBound] = actual; |
| 76 | expectedvalues[UBound] = expect; |
| 77 | UBound++; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | function test() |
| 82 | { |
| 83 | enterFunc('test'); |
| 84 | printBugNumber(BUGNUMBER); |
| 85 | printStatus(summary); |
| 86 | |
| 87 | for (var i=0; i<UBound; i++) |
| 88 | { |
| 89 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
| 90 | } |
| 91 | |
| 92 | exitFunc ('test'); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | function quoteThis(text) |
| 97 | { |
| 98 | return QUOTE + text + QUOTE; |
| 99 | } |