Subj : Re: SM: run a script from a native function To : netscape.public.mozilla.jseng From : Shanti Rao Date : Fri Jan 09 2004 10:47 am Thanks, Brendan. Your message was very helpful. Let me provide some more information about what I want: Brendan Eich wrote: > Shanti Rao wrote: > >> This JS code calls my error reporter: >> With this code, >> new Script("print('hello')\nasdf;").exec() js_ReportIsNotDefined() gets called from jsscript#script_exec(). This creates an exception object containing the text (ReferenceError) and the line number (2) on which the error occurred. The pending exception then has the messgae "asdf is not defined". After script_exec() finishes, control returns to the first JS_EvaluateUCScriptFP(), which notices the pending exception, calls js_ReportUncaughtException(), which eventually calls my error handler, which writes "ReferenceError: asdf is not defined on error.js line 2". Line 2 refers to the "\n" in my script string. Another way to do it is to pass "run()" to the JS interpreter, where run() is a native function that looks like JS_EvaluateScript(cx,global,"print('hello')\nasdf;",14,'error.js',1,&rval); js_ReportIsNotDefined() gets called back from js_Interpret. InitExecptionObject() gets called as before, and makes a ReferenceError exception with the right file name and line number. The pending exception then has the messgae "asdf is not defined", just as before. This time, however, when control returns to EvaluateUCScriptFP(), cx->fp is null, and it doesn't call js_ReportUncaughtException(). EvaluateUCScriptFP() returns false, so I know an error occurred, but the exception got deleted before I got a chance to see what it was. For anyone else who's interested, the workaround is to wrap your scripts in try { my script text blah blah blah } catch(err) {print(err,' '); for (var m in err) print(m,'=',err[m],' ');} This will print enough information to debug the program. Shanti .