diff 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
line wrap: on
line diff
--- a/context.c	Mon Jul 06 01:37:16 2009 -0700
+++ b/context.c	Mon Jul 06 08:13:45 2009 -0700
@@ -3,16 +3,20 @@
 #include "function.h"
 #include "utils.h"
 
-// Default JSErrorReporter for pymonkey-owned JS contexts. We just throw an
-// appropriate exception into Python-space.
 static void
 PYM_reportError(JSContext *cx, const char *message, JSErrorReport *report)
 {
-  if (report->filename)
-    PyErr_Format(PYM_error, "File \"%s\", line %d: %s",
-                 report->filename, report->lineno, message);
-  else
-    PyErr_SetString(PYM_error, message);
+  // Convert JS warnings into Python warnings.
+  if (JSREPORT_IS_WARNING(report->flags)) {
+    if (report->filename)
+      PyErr_WarnExplicit(NULL, message, report->filename, report->lineno,
+                         NULL, NULL);
+    else
+      PyErr_Warn(NULL, message);
+  } else
+    // TODO: Not sure if this will ever get called, but we should know
+    // if it is.
+    PyErr_Warn(NULL, "A JS error was reported.");
 }
 
 static void