Mercurial > pymonkey
comparison utils.c @ 47:3f4982759e55
Converting JS exceptions into Python exceptions is now doable, albeit not yet implemented, thanks to the discovery of JSOPTION_DONT_REPORT_UNCAUGHT. Also, JS warnings are now converted into Python warnings.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 06 Jul 2009 08:13:45 -0700 |
parents | a0f677cfc679 |
children | bc4263c6ae82 |
comparison
equal
deleted
inserted
replaced
46:a0f677cfc679 | 47:3f4982759e55 |
---|---|
144 PyObject *str = PyObject_Unicode(value); | 144 PyObject *str = PyObject_Unicode(value); |
145 if (str == NULL) | 145 if (str == NULL) |
146 JS_ReportError(context->cx, "Python exception occurred"); | 146 JS_ReportError(context->cx, "Python exception occurred"); |
147 else { | 147 else { |
148 jsval val; | 148 jsval val; |
149 if (PYM_pyObjectToJsval(context, str, &val) == 0) | 149 if (PYM_pyObjectToJsval(context, str, &val) == 0) { |
150 // TODO: Include filename/line information. | 150 // TODO: Wrap Python traceback info in JS exception so the client |
151 // can examine it. | |
151 JS_SetPendingException(context->cx, val); | 152 JS_SetPendingException(context->cx, val); |
152 else | 153 } else |
153 JS_ReportError(context->cx, "Python exception occurred"); | 154 JS_ReportError(context->cx, "Python exception occurred"); |
154 } | 155 } |
155 | 156 |
156 Py_DECREF(type); | 157 Py_DECREF(type); |
157 Py_DECREF(value); | 158 Py_DECREF(value); |
167 | 168 |
168 jsval val; | 169 jsval val; |
169 if (JS_GetPendingException(context->cx, &val)) { | 170 if (JS_GetPendingException(context->cx, &val)) { |
170 JSString *str = JS_ValueToString(context->cx, val); | 171 JSString *str = JS_ValueToString(context->cx, val); |
171 if (str != NULL) { | 172 if (str != NULL) { |
173 // TODO: Wrap the original JS exception so that the client can | |
174 // examine it. | |
172 const char *chars = JS_GetStringBytes(str); | 175 const char *chars = JS_GetStringBytes(str); |
173 PyErr_SetString(PYM_error, chars); | 176 PyErr_SetString(PYM_error, chars); |
174 } else | 177 } else |
175 PyErr_SetString(PYM_error, "JS exception occurred"); | 178 PyErr_SetString(PYM_error, "JS exception occurred"); |
176 } else | 179 } else |