Closed Bug 225817 Opened 21 years ago Closed 21 years ago

Support for fileName/lineNumber properties in Error objects

Categories

(Rhino Graveyard :: Core, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: igor, Assigned: igor)

Details

Attachments

(3 files, 1 obsolete file)

It would be nice if Rhino would define fileName and lineNumber in error objects
as SpiderMonkey does.
Rhino CVS tip already contains code to put fileName and lineNumber properties.
I added that code to ScriptRuntime.getCatchObject together with code to create
JS Error objects from Java exceptions only when scripts catches exceptions. But
it did not help to pass js1_5/Exceptions/regress-50447.js and the patch fixes
that so hopefully the patch makes Rhino matching SpiderMonkey behavior.
The SpiderMonkey test suite is awesome!
Attachment #135575 - Attachment is obsolete: true
I committed the fix, but I keep the bug open since I think it would be resonable
to add fileName and lineNumber properties to JS objects representing caught Java
execptions.
Status: NEW → ASSIGNED
With the patch when I run:

try {
	null.value;
} catch (e) {
	print(format_ex(e));
}

try {
	new java.util.Vector(-1);
} catch (e) {
	print(format_ex(e));
}

function format_ex(e)
{
	return e.fileName+":"+e.lineNumber+": "+e.name+": "+e.message;
}

I get:

/tmp/x.js:2: TypeError: Cannot read property "value" from null
/tmp/x.js:8: JavaException: java.lang.IllegalArgumentException: Illegal
Capacity: -1

The patch adds new exception constructor, JavaException and puts the original
java exception as javaException property of the catch object so the following
would also works:

try {
	new java.util.Vector(-1);
} catch (e if JavaException) {
	e.javaException.printStackTrace();
}
I commiteed the last patch.
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
With the patches committed the test cases passes fully OK.
Thanks, Igor. Patch checked in for rhino-n.tests:

[//d/JS_TRUNK/mozilla/js/tests] cvs ci rhino-n.tests
Checking in rhino-n.tests;
/cvsroot/mozilla/js/tests/rhino-n.tests,v  <--  rhino-n.tests
new revision: 1.57; previous revision: 1.56
done


Marking Verified FIXED. Testcase js1_5/Exceptions/regress-50447.js
above now passes in the Rhino shell, in compiled/interpreted modes.
Status: RESOLVED → VERIFIED
Trageting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: