Closed Bug 190809 Opened 22 years ago Closed 13 years ago

in a toString() method, the error output is suppressed

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 645468

People

(Reporter: mschneider, Unassigned)

Details

User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Build Identifier: SpiderMonkey 1.5 RC 5

when i implement a toString() method for a javascript object, all error output 
is suppressed. this is because js_DefaultValue() calls js_TryMethod which sets 
the error reporter to NULL (jsobj.c:3380). this leads to the very uncool 
situation that if a toString() script contains an error, the execution of that 
script is terminated without any feedback..

Reproducible: Always

Steps to Reproduce:
function HierarchyElement(bla)
{
	this.bla=bla;
}

HierarchyElement.prototype.toString = function()
{
	this.bla += this.blubber() + " " + this.bla;
	return this.bla;
}

var xxx = new HierarchyElement("Hello, World!");

write(xxx);
Actual Results:  
the script terminates execution in the toString method.

Expected Results:  
call the errorhandler before, so that our implementation can give a feedback 
to the user
When I run your example in the JS shell, this is what I get:

[//d/JS_TRUNK/mozilla/js/src/WINNT4.0_DBG.OBJ]./js
js> load('test.js');
test.js:11: TypeError: this.blubber is not a function


As you say, the reported error is inside the user-defined toString() method:

    this.bla += this.blubber() + " " + this.bla;  <<<--------------- LINE 11


Isn't this informative enough? Just looking for extra clarification; thanks -
Assignee: rogerl → khanson
Status: UNCONFIRMED → NEW
Ever confirmed: true
I think the idea is that we should be calling the onerror handler...
okay, i've looked deeper in that problem and here's what i've found out:

because the error handler is not called directly but an exception is raised, 
it does not matter if the errorReporter is set to NULL in js_TryMethod() or 
not.. the problem is that our implementation has the following code in a 
wrapped jsvalue -> string conversion method:

	JSString* pjsString = JS_ValueToString(cx, val);
	char* cStr = NULL;
	if (pjsString) {
		cStr = JS_GetStringBytes(pjsString);
	} else {
		JS_ReportError(cx, "Conversion to String failed.");
	}
	return cStr;

JS_ReportError() reports the "Conversion to String failed" error, but the 
initial exception will be deleted :( 

okay, this is not a problem as we can just make the JS_IsExceptionPending() 
check before calling JS_ReportError()..

But what im still worring about is that this bug breaks my debugger 
implementation in a toString() method. this is because for the watches i 
evaluate the watch expression in the right stack frame.. for the time of the 
evaluation of the expression i redirect the error callbacks on rt-
>debugErrorHook so that im able to decide after the evaluation if the watch 
expression was successfully executed.. unfortunately, in jscntxt.c:327 the 
check

    } else if (cx->runtime->debugErrorHook && cx->errorReporter) {

makes that the debugger gets not error callback.. the same effect i have 
with "normal" script errors in a toString() method -> because the debug error 
callback is not called, i cannot display the error location

so the bug may be here in this check? why is the check to cx->errorReporter? 
must we care if only a debugger error callback is defined or could we still 
call it?

thanks!
cc'ing JS experts -
Assignee: khanson → general
QA Contact: pschwartau → general
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.