ref: ffe0ca7d7f47dc11d8912b11daa388e66be358bb
parent: 5de1f97c520cbf9cb410853f473f8ba228874b20
author: Tor Andersson <tor.andersson@artifex.com>
date: Mon Mar 18 08:56:42 EDT 2019
Issue 95: Improve error message when trying to call a non-callable.
--- a/jsdate.c
+++ b/jsdate.c
@@ -741,7 +741,7 @@
js_getproperty(J, 0, "toISOString");
if (!js_iscallable(J, -1))
- js_typeerror(J, "Date.prototype.toJSON: this.toISOString not a function");
+ js_typeerror(J, "this.toISOString is not a function");
js_copy(J, 0);
js_call(J, 0);
}
--- a/jsrun.c
+++ b/jsrun.c
@@ -230,7 +230,7 @@
return v->type == JS_TOBJECT && v->u.object->type == JS_CERROR;
}
-static const char *js_typeof(js_State *J, int idx)
+const char *js_typeof(js_State *J, int idx)
{
js_Value *v = stackidx(J, idx);
switch (v->type) {
@@ -1056,7 +1056,7 @@
int savebot;
if (!js_iscallable(J, -n-2))
- js_typeerror(J, "called object is not a function");
+ js_typeerror(J, "%s is not callable", js_typeof(J, -n-2));
obj = js_toobject(J, -n-2);
@@ -1090,7 +1090,7 @@
js_Object *newobj;
if (!js_iscallable(J, -n-1))
- js_typeerror(J, "called object is not a function");
+ js_typeerror(J, "%s is not callable", js_typeof(J, -n-1));
obj = js_toobject(J, -n-1);
--- a/mujs.h
+++ b/mujs.h
@@ -213,6 +213,7 @@
int js_equal(js_State *J);
int js_strictequal(js_State *J);
int js_instanceof(js_State *J);
+const char *js_typeof(js_State *J, int idx);
#ifdef __cplusplus
}