shithub: libmujs

Download patch

ref: 5dbd120154152ae674e01697e6a20ec7f52ba6a4
parent: 858d5890b344f4a5f6025c94b62a64d29673913e
author: Tor Andersson <tor@ccxvii.net>
date: Thu Mar 13 09:36:29 EDT 2014

Fix several constructors.

"is/was supplied/specified" is different from "is not undefined" which
is used in most of the spec.

--- a/jsdate.c
+++ b/jsdate.c
@@ -11,7 +11,7 @@
 #include <sys/time.h>
 #endif
 
-#define js_optnumber(J,I,V) (js_isdefined(J,I) ? js_tonumber(J,I) : V)
+#define js_optnumber(J,I,V) (js_gettop(J) > I ? js_tonumber(J,I) : V)
 
 static double Now(void)
 {
--- a/jsnumber.c
+++ b/jsnumber.c
@@ -4,12 +4,12 @@
 
 static void jsB_new_Number(js_State *J)
 {
-	js_newnumber(J, js_isdefined(J, 1) ? js_tonumber(J, 1) : 0);
+	js_newnumber(J, js_gettop(J) > 1 ? js_tonumber(J, 1) : 0);
 }
 
 static void jsB_Number(js_State *J)
 {
-	js_pushnumber(J, js_isdefined(J, 1) ? js_tonumber(J, 1) : 0);
+	js_pushnumber(J, js_gettop(J) > 1 ? js_tonumber(J, 1) : 0);
 }
 
 static void Np_valueOf(js_State *J)
--- a/jsobject.c
+++ b/jsobject.c
@@ -4,7 +4,7 @@
 
 static void jsB_new_Object(js_State *J)
 {
-	if (js_isundefined(J, 1) || js_isnull(J, 1))
+	if (js_gettop(J) == 1 || js_isundefined(J, 1) || js_isnull(J, 1))
 		js_newobject(J);
 	else
 		js_pushobject(J, js_toobject(J, 1));
@@ -12,7 +12,7 @@
 
 static void jsB_Object(js_State *J)
 {
-	if (js_isundefined(J, 1) || js_isnull(J, 1))
+	if (js_gettop(J) == 1 || js_isundefined(J, 1) || js_isnull(J, 1))
 		js_newobject(J);
 	else
 		js_pushobject(J, js_toobject(J, 1));
--- a/jsstring.c
+++ b/jsstring.c
@@ -50,12 +50,12 @@
 
 static void jsB_new_String(js_State *J)
 {
-	js_newstring(J, js_isdefined(J, 1) ? js_tostring(J, 1) : "");
+	js_newstring(J, js_gettop(J) > 1 ? js_tostring(J, 1) : "");
 }
 
 static void jsB_String(js_State *J)
 {
-	js_pushliteral(J, js_isdefined(J, 1) ? js_tostring(J, 1) : "");
+	js_pushliteral(J, js_gettop(J) > 1 ? js_tostring(J, 1) : "");
 }
 
 static void Sp_toString(js_State *J)