History

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

Tor Andersson committed 7 years ago

Commit ffe0ca71 parent 5de1f973 files · +5 −4Browse files

Unified · Split

3 files
  1. jsdate.c +1 −1
  2. jsrun.c +3 −3
  3. mujs.h +1 −0
jsdate.c+1−1
@@ -741,7 +741,7 @@ static void Dp_toJSON(js_State *J) · 740 unmodified lines
741741
742742 js_getproperty(J, 0, "toISOString");
743743 if (!js_iscallable(J, -1))
744− js_typeerror(J, "Date.prototype.toJSON: this.toISOString not a function");
744+ js_typeerror(J, "this.toISOString is not a function");
745745 js_copy(J, 0);
746746 js_call(J, 0);
747747 }
jsrun.c+3−3
@@ -230,7 +230,7 @@ int js_iserror(js_State *J, int idx) · 229 unmodified lines
230230 return v->type == JS_TOBJECT && v->u.object->type == JS_CERROR;
231231 }
232232
233−static const char *js_typeof(js_State *J, int idx)
233+const char *js_typeof(js_State *J, int idx)
234234 {
235235 js_Value *v = stackidx(J, idx);
236236 switch (v->type) {
@@ -1056,7 +1056,7 @@ void js_call(js_State *J, int n) · 819 unmodified lines
10561056 int savebot;
10571057
10581058 if (!js_iscallable(J, -n-2))
1059− js_typeerror(J, "called object is not a function");
1059+ js_typeerror(J, "%s is not callable", js_typeof(J, -n-2));
10601060
10611061 obj = js_toobject(J, -n-2);
10621062
@@ -1090,7 +1090,7 @@ void js_construct(js_State *J, int n) · 27 unmodified lines
10901090 js_Object *newobj;
10911091
10921092 if (!js_iscallable(J, -n-1))
1093− js_typeerror(J, "called object is not a function");
1093+ js_typeerror(J, "%s is not callable", js_typeof(J, -n-1));
10941094
10951095 obj = js_toobject(J, -n-1);
10961096
mujs.h+1−0
@@ -213,6 +213,7 @@ int js_compare(js_State *J, int *okay); · 212 unmodified lines
213213 int js_equal(js_State *J);
214214 int js_strictequal(js_State *J);
215215 int js_instanceof(js_State *J);
216+const char *js_typeof(js_State *J, int idx);
216217
217218 #ifdef __cplusplus
218219 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t