Subj : Re: SM: run a script from a native function To : Marcello Bastea-Forte From : Brendan Eich Date : Thu Jan 08 2004 11:03 am Marcello Bastea-Forte wrote: >>> 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. > > > Does that mean I shouldn't be doing the following: Certainly not. I was answering a question about JS_EvaluateScript. My answer did not exclude other API entry points from being used together to compile and execute (in a word, evaluate). /be > ------------------------------------------------------------------------ > JSBool JavaScript::JS_include(JSContext *cx, JSObject *obj, uintN argc, > jsval *argv, jsval *rval) { > > JSString *str = JS_ValueToString(cx, argv[0]); > if (!str) return JS_FALSE; > > JSScript *s = JS_CompileFile(cx, obj, JS_GetStringBytes(str)); > jsval ret; > bool b = JS_ExecuteScript(cx, obj, s, &ret); > JS_DestroyScript(cx, s); > > return b; > } > ------------------------------------------------------------------------ > To make an include() function? (Need to improve it to handle relative > directories.) > > Marcello .