shithub: libmujs

Download patch

ref: a9d88e54afe2e6bfa1a284770604fdd6009f2fdd
parent: 2a1804ea263e5697c5ceeea21d45beea152d1299
author: Tor Andersson <tor.andersson@artifex.com>
date: Fri Jul 23 07:42:35 EDT 2021

Handle try stack errors like stack overflow errors.

Don't create a new object, because that may cause a cascade of
other errors since we're at the limit.

--- a/jsrun.c
+++ b/jsrun.c
@@ -13,6 +13,14 @@
 #define TOP (J->top)
 #define BOT (J->bot)
 
+static void js_trystackoverflow(js_State *J)
+{
+	STACK[TOP].type = JS_TLITSTR;
+	STACK[TOP].u.litstr = "try stack overflow";
+	++TOP;
+	js_throw(J);
+}
+
 static void js_stackoverflow(js_State *J)
 {
 	STACK[TOP].type = JS_TLITSTR;
@@ -1226,7 +1234,7 @@
 void *js_savetrypc(js_State *J, js_Instruction *pc)
 {
 	if (J->trytop == JS_TRYLIMIT)
-		js_error(J, "try: exception stack overflow");
+		js_trystackoverflow(J);
 	J->trybuf[J->trytop].E = J->E;
 	J->trybuf[J->trytop].envtop = J->envtop;
 	J->trybuf[J->trytop].tracetop = J->tracetop;
@@ -1240,7 +1248,7 @@
 void *js_savetry(js_State *J)
 {
 	if (J->trytop == JS_TRYLIMIT)
-		js_error(J, "try: exception stack overflow");
+		js_trystackoverflow(J);
 	J->trybuf[J->trytop].E = J->E;
 	J->trybuf[J->trytop].envtop = J->envtop;
 	J->trybuf[J->trytop].tracetop = J->tracetop;