Subj : Re: obtaining script line number when invoking C function To : netscape.public.mozilla.jseng From : John Bandhauer Date : Mon Jul 07 2003 11:37 am Damian Slee wrote: > Hi, > is there any way to obtain the script line number when invoking a 'C' function, using the JSContext *variable? > > > JSBool CScriptPort::log(JSContext *Context, JSObject *Object, uintN argc, jsval *argv, jsval *rval) > { > int lineno = ... > > > I can obtain the lineno with the error reporter, but thats only when an error occurs. > Yes, there are functions in jsdbgapi.h that you can use to do this. Basically, you use JS_FrameIterator to get the JS stack frame in question for the given JSContext, JS_GetFramePC to get the opcode location in the executing frame, and JS_PCToLineNumber to convert this to a line number. There are additional functions that can get you the filename (or URL) etc. There is an example of this sort of thing at: http://lxr.mozilla.org/seamonkey/source/js/src/xpconnect/src/xpcdebug.cpp#262 John. .