Subj : Re: SM: run a script from a native function To : netscape.public.mozilla.jseng From : Shanti Rao Date : Wed Jan 07 2004 11:14 pm Brendan Eich wrote: > Shanti Rao wrote: > >> Hi folks, >> >> In SpiderMonkey, what's the proper way to call JS_EvaluateScript from >> within a native function (itself invoked by a script)? Do you have to >> do anything to reset the stack frame or context state? > > > Do you want to make something like eval? If not, just use > JS_EvaluateScript or one of its {UC, ForPrincipals} variants. > > If you want to make something like eval, you'll have to use private or > debugger APIs. > > /be > JS_EvaluateScriptXX works, but if the invoked script has an error, my error reporter never gets called. eval() has the handy feature of properly reporting syntax errors to me. This JS code calls my error reporter: new Script("print('hello')\nasdf;").exec() 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? Shanti PS. jsobj.c#2336 needs to read if (lastobj = obj) do { .