From f0c795771d30ad23c29bc499ae5ac2de63a1d2a7 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 5 Feb 2014 05:46:23 +0100 Subject: [PATCH] The typeof operator should return 'function' for callable objects. --- jsrun.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jsrun.c b/jsrun.c index 69ee5a2..057decc 100644 --- a/jsrun.c +++ b/jsrun.c @@ -147,13 +147,17 @@ int js_isuserdata(js_State *J, const char *tag, int idx) 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"; }