shithub: libmujs

Download patch

ref: 32c0c6c4103e8753ac8ad8ca581bec9c87362ca0
parent: ce0a690a04a172b183020b650ac5e6742885a095
author: Tor Andersson <[email protected]>
date: Sun Jan 19 09:55:19 EST 2014

Rename jsR_numbertostring to jsR_stringfromnumber.

Add js_tointeger, js_toint32, js_touint32.

--- a/jsbnumber.c
+++ b/jsbnumber.c
@@ -27,7 +27,7 @@
 {
 	js_Object *self = js_toobject(J, 0);
 	if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
-	js_pushliteral(J, jsR_numbertostring(J, self->u.number));
+	js_pushliteral(J, jsR_stringfromnumber(J, self->u.number));
 	return 1;
 }
 
--- a/jsbuiltin.c
+++ b/jsbuiltin.c
@@ -49,7 +49,7 @@
 static int jsB_parseFloat(js_State *J, int argc)
 {
 	const char *s = js_tostring(J, 1);
-	js_pushnumber(J, jsR_stringtonumber(J, s));
+	js_pushnumber(J, jsR_numberfromstring(J, s));
 	return 1;
 }
 
--- a/jsrun.c
+++ b/jsrun.c
@@ -155,6 +155,21 @@
 	return jsR_tonumber(J, stackidx(J, idx));
 }
 
+double js_tointeger(js_State *J, int idx)
+{
+	return tointeger(jsR_tonumber(J, stackidx(J, idx)));
+}
+
+int js_toint32(js_State *J, int idx)
+{
+	return toint32(jsR_tonumber(J, stackidx(J, idx)));
+}
+
+unsigned int js_touint32(js_State *J, int idx)
+{
+	return touint32(jsR_tonumber(J, stackidx(J, idx)));
+}
+
 const char *js_tostring(js_State *J, int idx)
 {
 	return jsR_tostring(J, stackidx(J, idx));
--- a/jsrun.h
+++ b/jsrun.h
@@ -28,8 +28,8 @@
 int jsR_equal(js_State *J);
 int jsR_strictequal(js_State *J);
 
-const char *jsR_numbertostring(js_State *J, double number);
-double jsR_stringtonumber(js_State *J, const char *string);
+const char *jsR_stringfromnumber(js_State *J, double number);
+double jsR_numberfromstring(js_State *J, const char *string);
 
 /* public */
 
@@ -69,8 +69,11 @@
 
 int js_toboolean(js_State *J, int idx);
 double js_tonumber(js_State *J, int idx);
-double js_tointeger(js_State *J, int idx);
 const char *js_tostring(js_State *J, int idx);
+
+double js_tointeger(js_State *J, int idx);
+int js_toint32(js_State *J, int idx);
+unsigned int js_touint32(js_State *J, int idx);
 
 void js_pop(js_State *J, int n);
 void js_dup(js_State *J);
--- a/jsvalue.c
+++ b/jsvalue.c
@@ -2,7 +2,7 @@
 #include "jsobject.h"
 #include "jsrun.h"
 
-const char *jsR_numbertostring(js_State *J, double n)
+const char *jsR_stringfromnumber(js_State *J, double n)
 {
 	char buf[32];
 	if (isnan(n)) return "NaN";
@@ -12,7 +12,7 @@
 	return js_intern(J, buf);
 }
 
-double jsR_stringtonumber(js_State *J, const char *s)
+double jsR_numberfromstring(js_State *J, const char *s)
 {
 	/* TODO: use lexer to parse string grammar */
 	return strtod(s, NULL);
@@ -99,7 +99,7 @@
 	case JS_TNULL: return 0;
 	case JS_TBOOLEAN: return v->u.boolean;
 	case JS_TNUMBER: return v->u.number;
-	case JS_TSTRING: return jsR_stringtonumber(J, v->u.string);
+	case JS_TSTRING: return jsR_numberfromstring(J, v->u.string);
 	case JS_TOBJECT:
 		{
 			js_Value vv = jsR_toprimitive(J, v, JS_HNUMBER);
@@ -115,7 +115,7 @@
 	case JS_TUNDEFINED: return "undefined";
 	case JS_TNULL: return "null";
 	case JS_TBOOLEAN: return v->u.boolean ? "true" : "false";
-	case JS_TNUMBER: return jsR_numbertostring(J, v->u.number);
+	case JS_TNUMBER: return jsR_stringfromnumber(J, v->u.number);
 	case JS_TSTRING: return v->u.string;
 	case JS_TOBJECT:
 		{