ref: f0c795771d30ad23c29bc499ae5ac2de63a1d2a7
parent: 6ecb4e7a4eda61860545ddff31fded249f536ebd
author: Tor Andersson <tor@ccxvii.net>
date: Wed Feb 5 00:46:23 EST 2014
The typeof operator should return 'function' for callable objects.
--- a/jsrun.c
+++ b/jsrun.c
@@ -147,13 +147,17 @@
static const char *js_typeof(js_State *J, int idx)
{
- switch (stackidx(J, idx)->type) {
+ const js_Value *v = stackidx(J, idx);
+ switch (v->type) {
case JS_TUNDEFINED: return "undefined";
case JS_TNULL: return "object";
case JS_TBOOLEAN: return "boolean";
case JS_TNUMBER: return "number";
case JS_TSTRING: return "string";
- case JS_TOBJECT: return "object";
+ case JS_TOBJECT:
+ if (v->u.object->type == JS_CFUNCTION || v->u.object->type == JS_CCFUNCTION)
+ return "function";
+ return "object";
}
return "object";
}