Subj : Re: Can't get JS_CallFunction to work - OK. Works now :) To : netscape.public.mozilla.jseng From : c_ibrahim Date : Mon Oct 25 2004 08:30 am Hi, Pls ignore the previous mail. Managed to get it work :) cath c_ibrahim@yahoo.com (c.ibrahim) wrote in message news:... > Hi, > > I saw a similar question posted like 3-4 months ago, but I cannot get > much from the answer so I post this question again. > > I need to use a function many a times so I decide to use > JS_CompileFunction once and call the function many times using > JS_CallFunction. I wanna make sure the idea works so I implement a > simple test code, which to my dismay, does not work.. > > > the code snippet: > > //somewhere in class constructor > ... > JSContext* m_context = JSNewContext( > JSObject* m_global = JS_NewObject( > > > //in class function that contains the simple test code > ... > long grade = -1; > > //compile function > const char* Grade = "function grade() { return 10 }"; > const char* filename = 0; > uintN lineno = 0; > JSFunction* func = JS_CompileFunction(m_context, m_global, "grade", 0, > 0, Grade, strlen(Grade), filename, lineno); > > //call function > if (0!=func) > { > jsval rval; > if (JS_TRUE == JS_CallFunction(m_context, m_global, func, 0, 0, > &rval)) > { > if (JS_FALSE == JS_ValueToInt32(m_context, rval, &grade)) > { > cout << "FAILS! AARCK!!"; > } > } > } > ... > > func != 0, so I assume JS_CompileFunction works fine. > JSCallFunction returns JS_TRUE, so I assume it works fine there as > well. > BUT, rval returns -2147483647 (undefined, I suppose?) > JS_ValueToInt32 then returns JS_FALSE > > I completely have no clue what goes wrong here. Plz help.. > > thanks in advance, > cath .