Closed
Bug 181654
Opened 22 years ago
Closed 22 years ago
Calling toString for an object derived from the Error class throws TypeError
Categories
(Rhino Graveyard :: Core, defect)
Rhino Graveyard
Core
Tracking
(Not tracked)
VERIFIED
FIXED
1.5R4
People
(Reporter: joerg.schaible, Assigned: norrisboyd)
Details
Attachments
(2 files)
|
4.29 KB,
text/plain
|
Details | |
|
2.32 KB,
patch
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461)
Build Identifier: Rhino 1.5 release 4 0000 00 00 (in progress)
Calling the toString method for an object that is derived from the Error class
results in a thrown TypeError (Rhino only, works perfectly in SpiderMonkey).
Reproducible: Always
Steps to Reproduce:
regression test case attached
Actual Results:
TypeError raised
Expected Results:
same behaviour as with SpiderMonkey: method returns String with class name and
error message.
Environment is reproducable with Rhino 1.5 RC4pre from current CVS
| Reporter | ||
Comment 1•22 years ago
|
||
Regression test for this bug.
Comment 2•22 years ago
|
||
Jörg's testcase added to JS testsuite:
mozilla/js/tests/ecma_3/Exceptions/regress-181654.js
Comment 3•22 years ago
|
||
Confirming what Jörg has reported. SpiderMonkey passes the above test,
whereas Rhino generates a TypeError. Here is an example:
--------------------------- IN SPIDERMONKEY ---------------------------
js> function f() {}
js> f.prototype = new Error();
Error
js> obj = new f();
Error
js> obj.toString();
Error
--------------------------- IN RHINO ---------------------------
js> function f() {}
js> f.prototype = new Error();
Error: undefined
js> obj = new f();
js: "<stdin>", line 25: uncaught JavaScript exception: TypeError:
Method "toString" called on incompatible object. (<stdin>; line 25)
js> obj.toString();
js: "<stdin>", line 26: uncaught JavaScript exception: TypeError:
Method "toString" called on incompatible object. (<stdin>; line 26)
Note, no trouble in Rhino for a primary Error object:
js> obj = new Error();
Error: undefined
js> obj.toString();
Error: undefined
Comment 4•22 years ago
|
||
I guess it is possible to argue that current Rhino behavior confirms Ecma 262,
v3 as according to 15.11.4.4 Error.prototype.toString() returns an
implementation defined string, and throwing an exception can be very well
defined result ;).
But as not throwing exceptions fulfills 15.11.4.4 without guesses, here is a
patch that effectively makes Error.prototype.toString a generic function
printing this.name + ": " + this.message for any this.
Comment 5•22 years ago
|
||
Can be marked as fixed as I commited the attachment
Comment 6•22 years ago
|
||
Marking FIXED -
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Comment 7•22 years ago
|
||
Marking Verified FIXED.
The above testcase now passes in the Rhino shell, in both compiled
and interpreted modes. Here is an interactive session:
[ ] java org.mozilla.javascript.tools.shell.Main
Rhino 1.5 release 4 0000 00 00 (in progress)
js> function f() {}
js> f.prototype = new Error();
Error:
js> obj = new f();
Error:
js> obj.toString()
Error:
js> f.prototype = new SyntaxError();
SyntaxError:
js> obj = new f();
SyntaxError:
js> obj.toString()
SyntaxError:
js> f.prototype = new TypeError();
TypeError:
js> obj = new f();
TypeError:
js> obj.toString()
TypeError:
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•