Subj : Re: Function name...? To : netscape.public.mozilla.jseng From : John Bandhauer Date : Tue Jul 08 2003 11:44 am Quick and dirty... The function object (as a jsval) is in argv[-2]. Use JS_ValueToFunction on it to get the JSFunction*. Then JS_GetFunctionName to get its name. If you don't want to work in terms of strings then you would tag the function object when you create it by setting a private property on the object using JS_SetReservedSlot (you can't mess with the 'main' private slot on a function object, but there are 2 available 'reserved' slots). See an example at: http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/src/xpcwrappednativeinfo.cpp#144 And then use JS_GetReservedSlot on the function object at call time: http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/src/xpcwrappednativeinfo.cpp#44 You can get the function object directly from argv[-2]... JSObject* funobj = JSVAL_TO_OBJECT(argv[-2]); http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/src/xpcwrappednativejsops.cpp#1257 John. Robert Bates wrote: > OK, in pursuit of my Quick-n-Dirty C++ wrapper for JSObject, I am trying to > figure out if there's a way (short of using the debug API) to get the actual > method name invoked from the JSNative function call. For example: > > JSBool c_method(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval > *rval) > { > JSString *jsMethod = ... > ... > } > > Is there a way, or am I trying to do something not intended...? > > Brendan's made me aware that there are lost cycles if I don't do the > straight-away mapping, but the objects I'm exposing will only have these > methods called a couple times at most, and not iteratively, so Quick-n-Dirty > is the name of the game right now... > > Thanks! > .