shithub: libmujs

Download patch

ref: 2296f47e4c749690bb9d0628064839ea29174d61
parent: c1bd06728a4d37eab587ab8e2d8516e4ae24ce5e
author: Tor Andersson <tor.andersson@gmail.com>
date: Thu Apr 20 10:54:49 EDT 2017

Make Error.prototype.toString conform to the spec.

Override the toString function in the default shell to provide a
stack trace instead.

--- a/jserror.c
+++ b/jserror.c
@@ -53,9 +53,6 @@
 		js_pushstring(J, message);
 		js_concat(J);
 	}
-
-	if (js_hasproperty(J, 0, "stackTrace"))
-		js_concat(J);
 }
 
 static int jsB_ErrorX(js_State *J, js_Object *prototype)
--- a/main.c
+++ b/main.c
@@ -120,6 +120,12 @@
 	"require.cache = Object.create(null);\n"
 ;
 
+static const char *stacktrace_js =
+	"Error.prototype.toString = function() {\n"
+	"return this.name + ': ' + this.message + this.stackTrace;\n"
+	"};\n"
+;
+
 static int eval_print(js_State *J, const char *source)
 {
 	if (js_ploadstring(J, "[string]", source)) {
@@ -200,6 +206,7 @@
 	js_setglobal(J, "quit");
 
 	js_dostring(J, require_js);
+	js_dostring(J, stacktrace_js);
 
 	if (argc > 1) {
 		for (i = 1; i < argc; ++i) {