Closed Bug 123002 Opened 24 years ago Closed 24 years ago

Error.length should be 3 not 1

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: georg, Assigned: khanson)

References

Details

Attachments

(1 file)

a=new Error(1,2,3); alert(a.name); alert(a.message); alert(a.fileName); alert(a.lineNumber); alert(Error.length); The length property of function objects should reflect the typical number of arguments expected. In ECMA 262-3 only one argument is supported. In JavaScript 1.5 three arguments are expected. The length property of the Error function should be 3 in JavaScript 1.5 because three arguments are the typical usage in JavaScript 1.5.
Confirming for consideration. This seems reasonable to me, but I will attach the relevant sections from ECMA-262 Edition 3 Final and cc Waldemar to be sure this is correct. This all arises from bug 50447 filed against SpiderMonkey, "JS Exceptions should have filename/linenumber properties", As a result of that fix, the Error constructor in SpiderMonkey has a FormalParameterList is of length three now: USED TO BE ECMA-262 15.11.1.1 Error (message) AFTER BUG 50447 SpiderMonkey ECMA extension Error (message, fileName, lineNumber) Sample from current SpiderMonkey shell: js> var err = Error('aaa', 'bbb', 999); js> err.message; aaa js> err.fileName; bbb js> err.lineNumber; 999 The only thing that makes me hesitate is this language in ECMA-262: 15.11.3 Properties of the Error Constructor The value of the internal [[Prototype]] property of the Error constructor is the Function prototype object (15.3.4). Besides the internal properties and the length property (whose value is 1), the Error constructor has the following... etc. I ASSUME the parenthetical definition of Error.length = 1 here is due to ECMA assuming that the FormalParameterList of the Error constructor would have length 1. So if an implementation adds more elements to the FormalParameterList, Error.length should increase accordingly...
Assignee: rogerl → khanson
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Linux → All
Hardware: PC → All
Thanks for cc'ing me as well. Hm. The way I read it, the ECMA-262 specification has an error in stating explicitly the "(whose value is 1)" portion. Unless ECMAScript is deliberately restricting what JavaScript may be. As I understand ECMAScript, the intention is to set minimum requirements for the language, not to lock out extensions to the language. But I'll defer to waldemar for that clarification. :) I don't work on the standards.
It's a gray area -- the standard does not address every possible extension one could do. If we're doing this extension, I think that changing the length property to 3 would be in the spirit of the standard.
Testcase added to JS testsuite: mozilla/js/tests/js1_5/Exceptions/regress-123002.js
Easily done -- in fact I'm piggy-backing the one-line fix to jsexn.c in the next patch for bug 123177. /be
Depends on: 123177
Oh sorry -- I should have commented here about the testcase counting enumerable Error instance properties not being the right way to compute Error.length's best value, instead of at http://bugzilla.mozilla.org/show_bug.cgi?id=123177#c22. /be
The testcase has now been repaired: mozilla/js/tests/js1_5/Exceptions/regress-123002.js It is now passing on WinNT, Linux, and Mac9.1. I believe we can mark this bug FIXED now; the patch for bug 123177 has done the trick. I will let Brendan decide, in case there is anything else left to do on this -
Thanks for the reminder! /be
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Marking Verified FIXED; see Comment #8
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: