Subj : Re: SM: run a script from a native function To : Shanti Rao From : Brendan Eich Date : Fri Jan 09 2004 05:54 pm Shanti Rao wrote: > Sorry, you're right. My problem is that, although there's a pending > exception, the interpreter never acts on it. Here's what one needs to do > to make a proper run() native function: > > JSBool RunScript(JSContext*cx, JSObject*obj, uintN argc, jsval *argv, > jsval *rval) > { > *rval = OBJECT_TO_JSVAL(0); > > if (argc < 1) return JS_TRUE; > > //open the script > > if (JS_BufferIsCompilableUnit(cx,global,text,text.size()) > { > if (!JS_EvaluateScript(cx,global,text,text.size(),filename,line,&rval)) > return JS_FALSE; > } > return JS_TRUE; > } > > My mistake was in not returning JS_FALSE if JS_EvaluateScript didn't > return false. Thanks for your help! > Why not just pass whatever's passed in to JS_EvaluateScript? JS_BufferIsCompilableUnit is really only for assembling lines from the JS shell into source programs. Your use of it here silently ignores any syntax errors in text. /be .