From bf55821f0bd19c4de33f8cd9ec6a53c93588d5fd Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sat, 6 Aug 2005 01:04:13 +0000
Subject: [PATCH] Created js.report_error() function for reporting errors
 (fatal or not) using the standard JS error reporting mechanism. Not
 recommended for most script-level error logging.

---
 src/sbbs3/js_internal.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/sbbs3/js_internal.c b/src/sbbs3/js_internal.c
index 9ef9b7c390..a70920e5ff 100644
--- a/src/sbbs3/js_internal.c
+++ b/src/sbbs3/js_internal.c
@@ -301,6 +301,16 @@ js_gc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 	return(JS_TRUE);
 }
 
+static JSBool
+js_report_error(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+	JS_ReportError(cx,"%s",JS_GetStringBytes(JS_ValueToString(cx, argv[0])));
+
+	if(argc>1 && argv[1]==JSVAL_TRUE)
+		return(JS_FALSE);	/* fatal */
+
+	return(JS_TRUE);
+}
 
 static JSClass js_internal_class = {
      "JsInternal"				/* name			*/
@@ -325,7 +335,13 @@ static jsSyncMethodSpec js_functions[] = {
 		"if <i>forced</i> is <i>true</i> (the default) a garbage collection is always performed, "
 		"otherwise it is only performed if deemed appropriate by the JavaScript engine")
 	,311
-	},		
+	},
+	{"report_error",	js_report_error,	1,	JSTYPE_VOID,	JSDOCSTR("error [, bool fatal]")
+	,JSDOCSTR("report an error using the standard JavaScript error reporting mechanism "
+	"(including script filename and line number), "
+	"if <i>fatal</i> is <i>true</i>, terminates script - (added in v3.12b)")
+	,312
+	},
 	{0}
 };
 
-- 
GitLab