Mercurial > pymonkey
comparison src/context.cpp @ 146:b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 29 Aug 2009 13:16:43 -0700 |
parents | 5d53f6293a81 |
children | ebc0ff767290 |
comparison
equal
deleted
inserted
replaced
145:5d53f6293a81 | 146:b1cf9decc36f |
---|---|
39 #include "function.h" | 39 #include "function.h" |
40 #include "script.h" | 40 #include "script.h" |
41 #include "utils.h" | 41 #include "utils.h" |
42 | 42 |
43 #include "jsdbgapi.h" | 43 #include "jsdbgapi.h" |
44 #include "jsscript.h" | |
44 | 45 |
45 // This is the default JSOperationCallback for pymonkey-owned JS contexts, | 46 // This is the default JSOperationCallback for pymonkey-owned JS contexts, |
46 // when they've defined one in Python. | 47 // when they've defined one in Python. |
47 static JSBool | 48 static JSBool |
48 PYM_operationCallback(JSContext *cx) | 49 PYM_operationCallback(JSContext *cx) |
138 PyObject *last = NULL; | 139 PyObject *last = NULL; |
139 | 140 |
140 while ((frame = JS_FrameIterator(self->cx, &iteratorp)) != NULL) { | 141 while ((frame = JS_FrameIterator(self->cx, &iteratorp)) != NULL) { |
141 bool success = true; | 142 bool success = true; |
142 JSScript *script = JS_GetFrameScript(self->cx, frame); | 143 JSScript *script = JS_GetFrameScript(self->cx, frame); |
144 unsigned int pc = 0; | |
145 unsigned int lineno = 0; | |
143 PyObject *pyScript; | 146 PyObject *pyScript; |
144 if (script) | 147 if (script) { |
145 pyScript = (PyObject *) PYM_newJSScript(self, script); | 148 pyScript = (PyObject *) PYM_newJSScript(self, script); |
146 else { | 149 if (pyScript == NULL) |
150 return NULL; | |
151 jsbytecode *pcByte = JS_GetFramePC(self->cx, frame); | |
152 pc = pcByte - script->code; | |
153 lineno = JS_PCToLineNumber(self->cx, script, pcByte); | |
154 } else { | |
147 pyScript = Py_None; | 155 pyScript = Py_None; |
148 Py_INCREF(pyScript); | 156 Py_INCREF(pyScript); |
149 } | 157 } |
150 | 158 |
151 PyObject *frameDict = Py_BuildValue( | 159 PyObject *frameDict = Py_BuildValue( |
152 "{sO}", | 160 "{sOsIsI}", |
153 "script", pyScript | 161 "script", pyScript, |
162 "pc", pc, | |
163 "lineno", lineno | |
154 ); | 164 ); |
155 | 165 |
156 Py_XDECREF(pyScript); | 166 Py_DECREF(pyScript); |
157 | 167 |
158 if (frameDict) { | 168 if (frameDict) { |
159 if (last) { | 169 if (last) { |
160 if (PyDict_SetItemString(last, "caller", frameDict) == 0) { | 170 if (PyDict_SetItemString(last, "caller", frameDict) == 0) { |
161 last = frameDict; | 171 last = frameDict; |