Subj : Re: Querying the name of the function being called in the static callback To : netscape.public.mozilla.jseng From : "Stephen Jones" Date : Wed Mar 12 2003 11:43 am I would love to hear any suggestions for faster ways to dispatch the method. Using the string name of the method was the only way I could think of within SpiderMonkey. We have a "core" module that includes the scripting engine and this module can be hosted by many "containers". These "containers" need to be able to add unique root level objects to the scripting engine, but I don't want these containers to know anything about the implementation of the scripting engine. Previously, we did this using IDispatch and Microsoft's Active Scripting Engine, but we've ported everything to the Mac and can no longer use COM ;) Anyway, doing this is easy enough with properties, and it would be easy enough to have static methods in the container, but the problem comes from unpacking the parameters to the method. I would like to be able to abstract this so that the "core"can dynamcally dispatch method calls with varying arguements to the "containers", probably using some sort of Variant data type for the parameters. Any thoughts greatly appreciated, Thanks, - Stephen "Brendan Eich" wrote in message news:3E6F680E.1080901@meer.net... > Stephen Jones wrote: > > >Is it possible to point multiple methods/function to the same static > >callback and somehow determine which method is being called? Ideally, I > >would like to query the string name of the method. Something like this: > > > >static JSBool StaticMethod(JSContext *cx, JSObject *obj, uintN argc, jsval > >*argv, jsval *rval) > >{ > > string theName = GetMethodName( ); > > > > Use argv[-2] -- JS_GetFunctionId((JSFunction *)JS_GetPrivate(cx, > JSVAL_TO_OBJECT(argv[-2]))) if you must have the (JSString*) identifier, > but there's probably a faster way to dispatch. > > What kind of system are you building that shares a native function among > several JS functions, btw? > > /be > > > > > if ( theName == "foo" ) > > { > > // do foo > > } > > > > else if ( theName == "bar" ) > > { > > // do bar > > } > > > > return JS_TRUE; > >} > > > >Thanks, > >- Stephen Jones > > > > > > > > > .