Issue 95: Improve error message when trying to call a non-callable.

This commit is contained in:
Tor Andersson
2019-03-18 12:56:42 +01:00
parent 5de1f97c52
commit ffe0ca7d7f
3 changed files with 5 additions and 4 deletions

View File

@@ -741,7 +741,7 @@ static void Dp_toJSON(js_State *J)
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);
}

View File

@@ -230,7 +230,7 @@ int js_iserror(js_State *J, int idx)
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 @@ void js_call(js_State *J, int n)
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 @@ void js_construct(js_State *J, int n)
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);

1
mujs.h
View File

@@ -213,6 +213,7 @@ int js_compare(js_State *J, int *okay);
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
}