ref: 7d9888b739040b9d58f1d6d0e42df98975b86d92
parent: bd037ab7aaf4cc516062dd1727218ac480666d45
author: Tor Andersson <[email protected]>
date: Wed Jan 4 12:25:44 EST 2023
Return "undefined" from C functions if no return value is pushed. Don't return the last input argument in this case.
--- a/jsrun.c
+++ b/jsrun.c
@@ -1224,6 +1224,7 @@
static void jsR_callcfunction(js_State *J, int n, int min, js_CFunction F)
{
+ int save_top;
int i;
js_Value v;
@@ -1230,10 +1231,16 @@
for (i = n; i < min; ++i)
js_pushundefined(J);
+ save_top = TOP;
F(J);
- v = *stackidx(J, -1);
- TOP = --BOT; /* clear stack */
- js_pushvalue(J, v);
+ if (TOP > save_top) {
+ v = *stackidx(J, -1);
+ TOP = --BOT; /* clear stack */
+ js_pushvalue(J, v);
+ } else {
+ TOP = --BOT; /* clear stack */
+ js_pushundefined(J);
+ }
}
static void jsR_pushtrace(js_State *J, const char *name, const char *file, int line)