shithub: libmujs

Download patch

ref: dc386479da124f5c3dd021c530aadf8ec22eee78
parent: 44ddedea93a3150b7b6dc9aedd625c058a01d697
author: Tor Andersson <tor@ccxvii.net>
date: Thu Mar 6 17:33:37 EST 2014

Add and use js_touint16.

--- a/jsrun.c
+++ b/jsrun.c
@@ -248,6 +248,16 @@
 	return jsV_numbertouint32(jsV_tonumber(J, stackidx(J, idx)));
 }
 
+short js_toint16(js_State *J, int idx)
+{
+	return jsV_numbertoint16(jsV_tonumber(J, stackidx(J, idx)));
+}
+
+unsigned short js_touint16(js_State *J, int idx)
+{
+	return jsV_numbertouint16(jsV_tonumber(J, stackidx(J, idx)));
+}
+
 const char *js_tostring(js_State *J, int idx)
 {
 	return jsV_tostring(J, stackidx(J, idx));
--- a/jsstring.c
+++ b/jsstring.c
@@ -294,7 +294,7 @@
 	}
 
 	for (i = 1; i <= argc; ++i) {
-		c = js_tointeger(J, i); // TODO: ToUInt16()
+		c = js_touint16(J, i);
 		p += runetochar(p, &c);
 	}
 	*p = 0;
@@ -424,7 +424,6 @@
 					x = *r - '0';
 					if (r[1] >= '0' && r[1] <= '9')
 						x = x * 10 + *(++r) - '0';
-					// TODO: use prog->nsub somehow
 					if (x > 0 && x < m.nsub) {
 						js_putm(J, &sb, m.sub[x].sp, m.sub[x].ep);
 					} else {
--- a/jsvalue.c
+++ b/jsvalue.c
@@ -33,6 +33,16 @@
 	return jsV_numbertoint32(n);
 }
 
+short jsV_numbertoint16(double n)
+{
+	return jsV_numbertoint32(n);
+}
+
+unsigned short jsV_numbertouint16(double n)
+{
+	return jsV_numbertoint32(n);
+}
+
 /* obj.toString() */
 static int jsV_toString(js_State *J, js_Object *obj)
 {
--- a/jsvalue.h
+++ b/jsvalue.h
@@ -127,6 +127,8 @@
 double jsV_numbertointeger(double n);
 int jsV_numbertoint32(double n);
 unsigned int jsV_numbertouint32(double n);
+short jsV_numbertoint16(double n);
+unsigned short jsV_numbertouint16(double n);
 const char *jsV_numbertostring(js_State *J, double number);
 double jsV_stringtonumber(js_State *J, const char *string);