[mw-devel] [Git][arthur/mw][master] 2 commits: js-duk: Require stack space for js_handle_event()

Andrew Price welshbyte at sucs.org
Tue Oct 9 13:42:19 BST 2018


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
b13b7bd8 by Andrew Price at 2018-10-09T13:25:29+01:00
js-duk: Require stack space for js_handle_event()

- - - - -
bc7f079f by Andrew Price at 2018-10-09T13:38:00+01:00
js-duk: Install a fatal error handler

Gives more info than the unexplained aborts that duktape does by
default.

- - - - -


1 changed file:

- src/client/js-duk.c


Changes:

=====================================
src/client/js-duk.c
=====================================
--- a/src/client/js-duk.c
+++ b/src/client/js-duk.c
@@ -763,6 +763,7 @@ int js_handle_event(struct mwevent *ev)
 	unsigned len;
 	unsigned i;
 
+	duk_require_stack(ctx, 5);
 	if (!duk_get_global_string(ctx, "mw")) {
 		fprintf(stderr, "mwjs error: failed to lookup mw namespace\n");
 		return -1;
@@ -968,6 +969,15 @@ static void define_api(void)
 	duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE);
 }
 
+static void fatal_handler(void *unused, const char *msg) {
+	if (msg == NULL)
+		fprintf(stderr, "mwjs encountered a fatal error - aborting.\n");
+	else
+		fprintf(stderr, "mwjs error (fatal): %s\n", msg);
+	fflush(stderr);
+	abort();
+}
+
 int setup_js(void)
 {
 	int is_local = 1;
@@ -975,7 +985,7 @@ int setup_js(void)
 	if (getmylogin() == NULL)
 		is_local = 0;
 
-	ctx = duk_create_heap_default();
+	ctx = duk_create_heap(NULL, NULL, NULL, NULL, fatal_handler);
 	if (ctx == NULL)
 		return -1;
 



View it on GitLab: https://projects.sucs.org/arthur/mw/compare/622cbc53786286544b028f2778d2a6bbd4d2e8e6...bc7f079f87444197e89aeb73539bd241310e096c

-- 
View it on GitLab: https://projects.sucs.org/arthur/mw/compare/622cbc53786286544b028f2778d2a6bbd4d2e8e6...bc7f079f87444197e89aeb73539bd241310e096c
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20181009/ca08237d/attachment-0001.html>


More information about the mw-devel mailing list