Created attachment 6
patch for 15.11.4.4-8-2
in chapter15/15.11/15.11.4/15.11.4.4/15.11.4.4^8-2.js, errObj.toString() should return "Error".
First, errObj.name is ""
Quoted from section 15.11.2.1
If the argument message is not undefined, the message own property of the newly constructed object is set to ToString(message).
And errObj instance is created by Error constructor with argument is undefined, so errObj.message is not own property and if [[Get]] is called, returns "" because Error.prototype.message is "".
So in section 15.11.4.4, step 7
http://es5.github.com/#x15.11.4.4
7. If name and msg are both the empty String, return "Error".
Because errObj.name is "" and errObj.message is "", errObj.toString() returns "Error".
I believe the test case is actually correct here according to my version of the spec. After the line:
var errObj = new Error();
errObj.name==="Error" (15.11.4.2) and errObj.message==="" (15.11.4.3).
The next line causes us to use "" for the value of the 'name' property rather than Error.prototype.name's value:
errObj.name = "";
The next part might be contentious. My version of ES5.1 - Rev. 5 – 10 January 2011 (15.11.4.4 Step 7) reads:
"If msg is undefined, then let msg be the empty String; else let msg be ToString(msg)."
and Annex F (corrections between ES5 and ES5.1) states:
15.11.4.4: Steps 6-10 modified/added to correctly deal with missing or empty message property value.
To complicate things a bit more, steps 6 and 7 in 15.11.4.4 (of ES5.1) are identical which is an issue in and of itself.
I'll do a bit of digging and see if this is a known spec issue or if there's a newer revision available yet.
There is indeed a newer version of ES5.1 (June 2011 edition) found at http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf. Unfortunately, it has the same issue I mentioned before and the full 15.11.4.4 algorithm given is:
15.11.4.4 Error.prototype.toString ( )
The following steps are taken:
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
3. Let name be the result of calling the [[Get]] internal method of O with argument "name".
4. If name is undefined, then let name be "Error"; else let name be ToString(name).
5. Let msg be the result of calling the [[Get]] internal method of O with argument "message".
6. If msg is undefined, then let msg be the empty String; else let msg be ToString(msg).
7. If msg is undefined, then let msg be the empty String; else let msg be ToString(msg).
8. If name is the empty String, return msg.
9. If msg is the empty String, return name.
10. Return the result of concatenating name, ":", a single space character, and msg.
This issue has been filed as https://bugs.ecmascript.org/show_bug.cgi?id=239, and we can modify the tests as needed once we get clarification on the expected behavior.
Thanks!
I saw ES5 Errata (Updated July 31, 2010) http://wiki.ecmascript.org/doku.php?id=
http://wiki.ecmascript.org/lib/exe/fetch.php?id=start&cache=cache&media=resources:es5_errata_7-31-10.pdf
in Errata P.5 and P.6
statement of 15.11.1.1 and 15.11.2.1, "Otherwise, the message own property is set to the empty String." is removed.
And 15.11.4.4 is modified to
15.11.4.4 Error.prototype.toString ( )
(Algorithm incorrect when message is the empty string or undefined)
6. If msg is undefined, then let msg be the empty String; else let msg be ToString(msg).
7. If name and msg are both the empty String, return "Error".
8. If name is the empty String, return msg.
9. If msg is the empty String, return name.
10. Return the result of concatenating name, ":", a single space character, and msg.
So I thought when errObj.name==="" and errObj.message==="", toString result is "Error".
If I overlooked something, please point out.
(In reply to comment #3)
> Thanks!
>
> I saw ES5 Errata (Updated July 31, 2010)
> http://wiki.ecmascript.org/doku.php?id=
> http://wiki.ecmascript.org/lib/exe/fetch.php?id=start&cache=cache&media=resources:es5_errata_7-31-10.pdf
The only normative source is the http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf please use source except where it is clearly by a confirmed ES5.1 at bugs.ecmascript.org
The ES5 errata are obsolete and do not apply to the ES5.1 spec.
>
> in Errata P.5 and P.6
>
> statement of 15.11.1.1 and 15.11.2.1, "Otherwise, the message own property is
> set to the empty String." is removed.
Yes, this correction was made in ES5.1. new Error objects that do not explicitly provide a (non-undefined) name or message value do not have corresponding own properties created for them. They inherit those properties from Error.prototype where their default values are "Error" and "".
>
> And 15.11.4.4 is modified to
The actual algorithm used in the ES5.1 spec is different from the algorithm given in the Errata but the results should be the same.
(new Error(undefined)).toString()
should produce "Error" because that is normally the value of the name property that is inherited from Error.prototype.
However, this logic is only correct if the values of the name and message properties of have Error.prototype have not been modified (or deleted). That probably need to be a precondition of this test. If such tests don't already exist, there should also be tests that ensure that such modification actually produce correct output according to 15.11.4.4.
>> The ES5 errata are obsolete and do not apply to the ES5.1 spec.
Oh, I didn't know this.
Now I see. I understood that this test case is actually correct.
Thank you for your clarification.