Subj : Re: Function name from JSObject To : JZ From : Brendan Eich Date : Fri Feb 07 2003 10:30 am JZ wrote: >I'm creating a bunch of JS functions using JS_DefineFunction, all mapped to >an internal C function, 'do_my_c_function'. > > do_my_c_function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, >jsval *rval) > >What I want to know from these args is what was the function name that the >user called in JS? Since I've mapped many JS functions to this one C >function, knowing the name of the function called allows me to take the >right action. > >Is that possible? Can I get the JS function name from the JSObject? How? > Use JS_GetFunctionId (new API; use JS_GetFunctionName only if you're stuck on an older version of the engine): JSObject *callee = JSVAL_TO_OBJECT(argv[-2]); JSFunction *fun = (JSFunction *) JS_GetPrivate(cx, callee); const JSString *funidstr = JS_GetFunctionId(fun); /* Now dispatch based on the characters in funidstr, using JS_GetStringChars */ . . . Or for faster dispatching, you might set a reserved slot in each function object to tell the underlying native function or code you want to execute. See JS_SetReservedSlot. >I'm hoping I don't have to map each function to a separate function. > Nope, no need for that. /be > >JZ > > > > .