Subj : Suggestion on JSErrorReporter. To : netscape.public.mozilla.jseng From : J.P. Date : Thu Sep 09 2004 12:26 pm In SM, the current JSErrorReporter signature is defined as: typedef void (* JS_DLL_CALLBACK JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report); Often the time, the callback funtion is a static member function of a class. Sometimes, it is desirable to be able to know from which instance of that class the callback is getting called. For example, in order to do this, I hacked the JSContext and added one more member variable "void* ErrorCallbackUserData". I also changed the JS_SetErrorReporter(JSContext* cx, JSErrorReporter er) to JS_SetErrorReporter(JSContext* cx, JSErrorReporter er, void* userdata). Now given a class: class Foo { public: JS_Context ctx; const char* InstanceId; static void SM_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); bool RunScript(); } In Foo::RunScript(), I set error reporter like: bool Foo::RunScript() { /* * I pass the pointer to this object. And I hacked the SM, so that * the value of this pointer will be assigned to * ctx->ErrorCallbackUserData. */ JS_SetErrorReporter(ctx, SM_ErrorReporter, (void*)this); } When the error callback gets called, I will know which instance of class Foo is giving me trouble, like: void Foo::SM_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) { Foo* self = (Foo*)(cx->ErrorCallbackUserData); printf("Instance Id: %s\n", self->InstanceId); } So I am suggesting to provide a mechanism to allow programmer associated some kind of user data with the error reporter. Just my 2 cents. .