shithub: libmujs

Download patch

ref: 70bd7ea61c1b5486e8cb3f4a3b07896a4ef95215
parent: 78e56b78544106b4639189b4e967d77305ebc183
author: Tor Andersson <tor.andersson@artifex.com>
date: Mon Dec 6 11:23:31 EST 2021

Minor cleanups.

--- a/jsnumber.c
+++ b/jsnumber.c
@@ -30,10 +30,12 @@
 	char buf[100];
 	js_Object *self = js_toobject(J, 0);
 	int radix = js_isundefined(J, 1) ? 10 : js_tointeger(J, 1);
+	double x = 0;
 	if (self->type != JS_CNUMBER)
 		js_typeerror(J, "not a number");
+	x = self->u.number;
 	if (radix == 10) {
-		js_pushstring(J, jsV_numbertostring(J, buf, self->u.number));
+		js_pushstring(J, jsV_numbertostring(J, buf, x));
 		return;
 	}
 	if (radix < 2 || radix > 36)
@@ -42,8 +44,8 @@
 	/* lame number to string conversion for any radix from 2 to 36 */
 	{
 		static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
-		double number = self->u.number;
-		int sign = self->u.number < 0;
+		double number = x;
+		int sign = x < 0;
 		js_Buffer *sb = NULL;
 		uint64_t u, limit = ((uint64_t)1<<52);
 
@@ -154,7 +156,7 @@
 	if (isnan(x) || isinf(x))
 		js_pushstring(J, jsV_numbertostring(J, buf, x));
 	else
-		numtostr(J, "%.*e", width, self->u.number);
+		numtostr(J, "%.*e", width, x);
 }
 
 static void Np_toPrecision(js_State *J)
@@ -170,7 +172,7 @@
 	if (isnan(x) || isinf(x))
 		js_pushstring(J, jsV_numbertostring(J, buf, x));
 	else
-		numtostr(J, "%.*g", width, self->u.number);
+		numtostr(J, "%.*g", width, x);
 }
 
 void jsB_initnumber(js_State *J)