comparison context.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
1 #include "context.h" 1 #include "context.h"
2 #include "object.h" 2 #include "object.h"
3 #include "function.h" 3 #include "function.h"
4 #include "utils.h" 4 #include "utils.h"
5 5
6 // Default JSErrorReporter for pymonkey-owned JS contexts. We just throw an
7 // appropriate exception into Python-space.
8 static void 6 static void
9 PYM_reportError(JSContext *cx, const char *message, JSErrorReport *report) 7 PYM_reportError(JSContext *cx, const char *message, JSErrorReport *report)
10 { 8 {
11 if (report->filename) 9 // Convert JS warnings into Python warnings.
12 PyErr_Format(PYM_error, "File \"%s\", line %d: %s", 10 if (JSREPORT_IS_WARNING(report->flags)) {
13 report->filename, report->lineno, message); 11 if (report->filename)
14 else 12 PyErr_WarnExplicit(NULL, message, report->filename, report->lineno,
15 PyErr_SetString(PYM_error, message); 13 NULL, NULL);
14 else
15 PyErr_Warn(NULL, message);
16 } else
17 // TODO: Not sure if this will ever get called, but we should know
18 // if it is.
19 PyErr_Warn(NULL, "A JS error was reported.");
16 } 20 }
17 21
18 static void 22 static void
19 PYM_JSContextDealloc(PYM_JSContextObject *self) 23 PYM_JSContextDealloc(PYM_JSContextObject *self)
20 { 24 {