Skip to content

Commit dbb86fc

Browse files
committed
Call "join" property instead of hardcoding Ap_join in Ap_toString.
1 parent e38bff1 commit dbb86fc

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

jsarray.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,18 @@ static void Ap_unshift(js_State *J)
423423

424424
static void Ap_toString(js_State *J)
425425
{
426-
int top = js_gettop(J);
427-
js_pop(J, top - 1);
428-
Ap_join(J);
426+
if (!js_iscoercible(J, 0))
427+
js_typeerror(J, "'this' is not an object");
428+
js_getproperty(J, 0, "join");
429+
if (!js_iscallable(J, -1)) {
430+
// TODO: call Object.prototype.toString implementation; not via Object.toString JS objects
431+
js_getglobal(J, "Object");
432+
js_getproperty(J, -1, "toString");
433+
js_rot2pop1(J);
434+
}
435+
js_copy(J, 0);
436+
js_call(J, 0);
437+
js_pop(J, 1);
429438
}
430439

431440
static void Ap_indexOf(js_State *J)

0 commit comments

Comments
 (0)