Mercurial > pymonkey
diff src/context.cpp @ 157:a31ff2de6017
Added 'function' key to stack frame dicts; lineno and pc information is now provided even if script is not.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 30 Aug 2009 15:06:10 -0700 |
parents | 7daa74f861c4 |
children | 22d46b688ace |
line wrap: on
line diff
--- a/src/context.cpp Sun Aug 30 11:53:56 2009 -0700 +++ b/src/context.cpp Sun Aug 30 15:06:10 2009 -0700 @@ -144,6 +144,7 @@ unsigned int pc = 0; unsigned int lineno = 0; PyObject *pyScript = NULL; + PyObject *pyFunc = NULL; // TODO: Ideally, we'd always convert the script to an object and // set it as an attribute of the function, but this can result in @@ -151,15 +152,18 @@ // scripts on finalization while creating an object from a script // makes it subject to GC. So to be safe, we'll only provide the // script object if one already exists. - if (script && JS_GetScriptObject(script)) { - pyScript = (PyObject *) PYM_newJSScript(self, script); - if (pyScript == NULL) { - // TODO: We should clean up here. - return NULL; - } + if (script) { jsbytecode *pcByte = JS_GetFramePC(self->cx, frame); pc = pcByte - script->code; lineno = JS_PCToLineNumber(self->cx, script, pcByte); + + if (JS_GetScriptObject(script)) { + pyScript = (PyObject *) PYM_newJSScript(self, script); + if (pyScript == NULL) { + // TODO: We should clean up here. + return NULL; + } + } } if (pyScript == NULL) { @@ -167,15 +171,29 @@ Py_INCREF(pyScript); } + JSObject *funObj = JS_GetFrameFunctionObject(self->cx, frame); + if (funObj) { + pyFunc = (PyObject *) PYM_newJSObject(self, funObj, NULL); + if (pyFunc == NULL) { + // TODO: We should clean up here. + return NULL; + } + } else { + pyFunc = Py_None; + Py_INCREF(pyFunc); + } + PyObject *frameDict = Py_BuildValue( - "{sOsIsIsO}", + "{sOsIsIsOsO}", "script", pyScript, "pc", pc, "lineno", lineno, - "caller", Py_None + "caller", Py_None, + "function", pyFunc ); Py_DECREF(pyScript); + Py_DECREF(pyFunc); if (frameDict) { if (last) {