Subj : Re: question about javascript functions To : netscape.public.mozilla.jseng From : Béatrice Philippe Date : Mon Feb 21 2005 10:27 am Well, if i try to change a user javascript function, then i can't use js_evaluate() anymore (i can use js_evaluate only if nothing is changed by my C++ application). so what i have to do is calling the modified function with js_callFunctionValue() and to perform this, i must know wich arguments i have to give to the function (my c++ app scans all javascript functions in the web page, so it doesn't know what kind of function it's scanning). I had a look in js_convert...() : i think it's not the right way to give arguments to js_callFunctionValue(). I'll try js_valueto...() function .... Thanks. Béatrice. "Matthew Mondor" a écrit dans le message de news: mailman.1108764480.605.mozilla-jseng@mozilla.org... > On Wed, 16 Feb 2005 15:43:19 +0100 > "Béatrice Philippe" wrote: > >> Thank you Matt, you are right !! >> with js_enumerate in c++, we can retrieve all parameter names of the >> function (parameters appear at the top of the enumeration). >> Now, i just need to give parameter values to my >> js_callFunctionValue(). I think js_convert() should be >> the right solution ?! > > Hmm I'm not sure I understand... So you obtain the arguments and their > types of a user created function, using JS_Evaluate(), so that you can > then call that user/script function with the proper arguments from C? > > I guess that JS_ConvertArguments() could serve perhaps, if it's what you > meant, but the arguments are simply passed as an array of jsval, of > course (argv) with the number of elements of the array in argc. It > appears that in javascript the value types can easily be converted as > well automatically in many cases... This is also true with SpiderMonkey > when using JS_ValueTo*() functions rather than strict JSVAL_IS_*() > followed by conditional JSVAL_TO_*() macros (which are probably good for > performance and to ensure proper types though). > > Also, you can attempt to call a JS function from C which is assumed to > have been defined with the expected arguments. Very possibly there is a > simple way to then detect if the function wasn't declared as it had to > be when doing so (I would have to write a little test and see to confirm > this though). > > Sorry if I'm way off, I couldn't clearly understand the question > > Matt .