int main(int argc, char **argv) { // expecting a filename if (argc < 2) { fprintf(stderr, "You have to specify at least one filename\n"); return -1; } bool ret = true; { JSLock lock; // create interpreter w/ global object Object global(new GlobalImp()); Interpreter interp; interp.setGlobalObject(global); ExecState *exec = interp.globalExec(); MyObject *myObject = (MyObject *)NPN_CreateObject (myFunctionPtrs); global.put(exec, Identifier("myInterface"), Instance::createRuntimeObject(Instance::CLanguage, (void *)myObject)); for (int i = 1; i < argc; i++) { const char *code = readJavaScriptFromFile(argv[i]); if (code) { // run Completion comp(interp.evaluate(code)); if (comp.complType() == Throw) { Value exVal = comp.value(); char *msg = exVal.toString(exec).ascii(); int lineno = -1; if (exVal.type() == ObjectType) { Value lineVal = Object::dynamicCast(exVal).get(exec,Identifier("line")); if (lineVal.type() == NumberType) lineno = int(lineVal.toNumber(exec)); } if (lineno != -1) fprintf(stderr,"Exception, line %d: %s\n",lineno,msg); else fprintf(stderr,"Exception: %s\n",msg); ret = false; } else if (comp.complType() == ReturnValue) { char *msg = comp.value().toString(interp.globalExec()).ascii(); fprintf(stderr,"Return value: %s\n",msg); } } } NPN_ReleaseObject ((NPObject *)myObject); } // end block, so that Interpreter and global get deleted return ret ? 0 : 3; }