Subj : Re: SM: run a script from a native function To : Shanti Rao From : Brendan Eich Date : Thu Jan 08 2004 11:06 am Shanti Rao wrote: > This JS code calls my error reporter: > > new Script("print('hello')\nasdf;").exec() Are you sure the call to your error reporter happens within the call to new Script here? It should be coming from the JS shell (or whatever you are running this in), when control unwinds from the outermost JS API entry point. > > Oddly, though, this code doesn't. It just writes 'false' and stops. > > JSScript* script = > JS_CompileScript(cx,obj,"print('hello')\nasdf;",20,'filename',1); > JSObject* o2 = JS_NewScriptObject(cx,script); > JS_CallFunctionName(cx,o2,"exec",0,0,&rval); > > Of course, that's the same as calling JS_EvaluateScript, but what > happens to the error reporter? The error is a pending exception in cx, until control unwinds from the outermost JS API entry point (JS_Evaluate*, JS_Execute*, JS_Call*), which will report uncaught exceptions. Errors as exceptions allow the script that's calling your native function to catch errors with a try statement. /be .