ref: c90c32326ed81e93bbb0474d947bd7f1880f50f9
parent: aba6644234865be0687c7df4888bcc8d4ae0b147
author: Tor Andersson <tor@ccxvii.net>
date: Fri Apr 15 08:18:34 EDT 2016
Fix bugs introduced when moving from argc to js_gettop. The 'length' field of a function is used to fill in missing arguments with undefined; this does not mesh well with functions that query for missing arguments using js_gettop. Set their lengths to 0 instead.
--- a/jsarray.c
+++ b/jsarray.c
@@ -687,16 +687,16 @@
js_pushobject(J, J->Array_prototype);
{
jsB_propf(J, "toString", Ap_toString, 0);
- jsB_propf(J, "concat", Ap_concat, 1);
+ jsB_propf(J, "concat", Ap_concat, 0); /* 1 */
jsB_propf(J, "join", Ap_join, 1);
jsB_propf(J, "pop", Ap_pop, 0);
- jsB_propf(J, "push", Ap_push, 1);
+ jsB_propf(J, "push", Ap_push, 0); /* 1 */
jsB_propf(J, "reverse", Ap_reverse, 0);
jsB_propf(J, "shift", Ap_shift, 0);
jsB_propf(J, "slice", Ap_slice, 2);
jsB_propf(J, "sort", Ap_sort, 1);
- jsB_propf(J, "splice", Ap_splice, 2);
- jsB_propf(J, "unshift", Ap_unshift, 1);
+ jsB_propf(J, "splice", Ap_splice, 0); /* 2 */
+ jsB_propf(J, "unshift", Ap_unshift, 0); /* 1 */
/* ES5 */
jsB_propf(J, "indexOf", Ap_indexOf, 1);
@@ -709,7 +709,7 @@
jsB_propf(J, "reduce", Ap_reduce, 1);
jsB_propf(J, "reduceRight", Ap_reduceRight, 1);
}
- js_newcconstructor(J, jsB_new_Array, jsB_new_Array, "Array", 1);
+ js_newcconstructor(J, jsB_new_Array, jsB_new_Array, "Array", 0); /* 1 */
{
/* ES5 */
jsB_propf(J, "isArray", A_isArray, 1);
--- a/jsdate.c
+++ b/jsdate.c
@@ -10,7 +10,7 @@
#include <sys/timeb.h>
#endif
-#define js_optnumber(J,I,V) (js_gettop(J) > I ? js_tonumber(J,I) : V)
+#define js_optnumber(J,I,V) (js_isdefined(J,I) ? js_tonumber(J,I) : V)
static double Now(void)
{
@@ -792,7 +792,7 @@
jsB_propf(J, "toISOString", Dp_toISOString, 0);
jsB_propf(J, "toJSON", Dp_toJSON, 1);
}
- js_newcconstructor(J, jsB_Date, jsB_new_Date, "Date", 1);
+ js_newcconstructor(J, jsB_Date, jsB_new_Date, "Date", 0); /* 1 */
{
jsB_propf(J, "parse", D_parse, 1);
jsB_propf(J, "UTC", D_UTC, 7);
--- a/jsmath.c
+++ b/jsmath.c
@@ -153,8 +153,8 @@
jsB_propf(J, "exp", Math_exp, 1);
jsB_propf(J, "floor", Math_floor, 1);
jsB_propf(J, "log", Math_log, 1);
- jsB_propf(J, "max", Math_max, 0);
- jsB_propf(J, "min", Math_min, 0);
+ jsB_propf(J, "max", Math_max, 0); /* 2 */
+ jsB_propf(J, "min", Math_min, 0); /* 2 */
jsB_propf(J, "pow", Math_pow, 2);
jsB_propf(J, "random", Math_random, 0);
jsB_propf(J, "round", Math_round, 1);
--- a/jsnumber.c
+++ b/jsnumber.c
@@ -89,7 +89,7 @@
jsB_propf(J, "toExponential", Np_toExponential, 1);
jsB_propf(J, "toPrecision", Np_toPrecision, 1);
}
- js_newcconstructor(J, jsB_Number, jsB_new_Number, "Number", 1);
+ js_newcconstructor(J, jsB_Number, jsB_new_Number, "Number", 0); /* 1 */
{
jsB_propn(J, "MAX_VALUE", 1.7976931348623157e+308);
jsB_propn(J, "MIN_VALUE", 5e-324);
--- a/jsobject.c
+++ b/jsobject.c
@@ -4,7 +4,7 @@
static void jsB_new_Object(js_State *J)
{
- if (js_gettop(J) == 1 || js_isundefined(J, 1) || js_isnull(J, 1))
+ if (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_gettop(J) == 1 || js_isundefined(J, 1) || js_isnull(J, 1))
+ if (js_isundefined(J, 1) || js_isnull(J, 1))
js_newobject(J);
else
js_pushobject(J, js_toobject(J, 1));
--- a/jsregexp.c
+++ b/jsregexp.c
@@ -146,7 +146,7 @@
static void jsB_RegExp(js_State *J)
{
- if (js_gettop(J) == 2 && js_isregexp(J, 1))
+ if (js_isregexp(J, 1))
return;
jsB_new_RegExp(J);
}
--- a/jsstring.c
+++ b/jsstring.c
@@ -661,7 +661,7 @@
jsB_propf(J, "valueOf", Sp_valueOf, 0);
jsB_propf(J, "charAt", Sp_charAt, 1);
jsB_propf(J, "charCodeAt", Sp_charCodeAt, 1);
- jsB_propf(J, "concat", Sp_concat, 1);
+ jsB_propf(J, "concat", Sp_concat, 0); /* 1 */
jsB_propf(J, "indexOf", Sp_indexOf, 1);
jsB_propf(J, "lastIndexOf", Sp_lastIndexOf, 1);
jsB_propf(J, "localeCompare", Sp_localeCompare, 1);
@@ -679,9 +679,9 @@
/* ES5 */
jsB_propf(J, "trim", Sp_trim, 0);
}
- js_newcconstructor(J, jsB_String, jsB_new_String, "String", 1);
+ js_newcconstructor(J, jsB_String, jsB_new_String, "String", 0); /* 1 */
{
- jsB_propf(J, "fromCharCode", S_fromCharCode, 1);
+ jsB_propf(J, "fromCharCode", S_fromCharCode, 0); /* 1 */
}
js_defglobal(J, "String", JS_DONTENUM);
}
--- a/main.c
+++ b/main.c
@@ -153,7 +153,7 @@
js_newcfunction(J, jsB_load, "load", 1);
js_setglobal(J, "load");
- js_newcfunction(J, jsB_print, "print", 1);
+ js_newcfunction(J, jsB_print, "print", 0);
js_setglobal(J, "print");
js_newcfunction(J, jsB_write, "write", 0);