Subj : JS_CallFunctionName doesn't work ... To : netscape.public.mozilla.jseng From : Gregory Sovaridis Date : Thu May 13 2004 05:52 pm Hi there, Quite new to js, I'm trying to execute a javascript function (from a file) from my C code. I'm using the JS_CallFunctionName which returns me always 0 (zero). I'm pretty confident it should do it but my boss doubt this library currently works! Any idea ? /*****************************************/ test.js file contains: function addValues(a,b) { result = a + b; return result; } /*****************************************/ I initialize the js API this way: JSClass global_class = { "global", 0, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; char szJSFile [_256B]; JSVersion version; JSRuntime *rt; JSContext *cx; JSObject *glob, *it; JSBool builtins; JSClass *clasp; JSScript *jsp; JSBool result; jsval jsargs[2]; jsval jretval; jsint number1 = 5; jsint number2 = 2; clasp = &global_class; strcpy(szJSFile, "test.js"); rt = JS_NewRuntime(8L * 1024L * 1024L); cx = JS_NewContext(rt, 8192); glob = JS_NewObject(cx, clasp, NULL, NULL); builtins = JS_InitStandardClasses(cx, glob); jsp = JS_CompileFile(cx, glob, szJSFile); jsargs[0] = INT_TO_JSVAL(number1); jsargs[1] = INT_TO_JSVAL(number2); result = JS_CallFunctionName(cx, glob, "addValues", 2, jsargs, &jretval); /*****************************************/ .