Bug 562446 - ES5: Array.prototype.toString and Array.prototype.toLocaleString should be generic. r=igor

This commit is contained in:
Jeff Walden
2010-07-15 12:33:33 -05:00
parent 6bd406943e
commit 6de1a8bb2b
10 changed files with 136 additions and 32 deletions

View File

@@ -1334,28 +1334,48 @@ array_toString_sub(JSContext *cx, JSObject *obj, JSBool locale,
return ok;
}
/* ES5 15.4.4.2. NB: The algorithm here differs from the one in ES3. */
static JSBool
array_toString(JSContext *cx, uintN argc, Value *vp)
{
JSObject *obj = ComputeThisFromVp(cx, vp);
if (!obj ||
(obj->getClass() != &js_SlowArrayClass &&
!InstanceOf(cx, obj, &js_ArrayClass, vp + 2))) {
return JS_FALSE;
if (!obj)
return false;
Value &join = vp[0];
if (!obj->getProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.joinAtom), &join))
return false;
if (!js_IsCallable(join)) {
JSString *str = obj_toStringHelper(cx, obj);
if (!str)
return false;
vp->setString(str);
return true;
}
return array_toString_sub(cx, obj, JS_FALSE, NULL, vp);
LeaveTrace(cx);
InvokeArgsGuard args;
if (!cx->stack().pushInvokeArgs(cx, 0, args))
return false;
Value *sp = args.getvp();
sp[0] = join;
sp[1].setObject(*obj);
/* Do the call. */
if (!Invoke(cx, args, 0))
return false;
*vp = *args.getvp();
return true;
}
static JSBool
array_toLocaleString(JSContext *cx, uintN argc, Value *vp)
{
JSObject *obj = ComputeThisFromVp(cx, vp);
if (!obj ||
(obj->getClass() != &js_SlowArrayClass &&
!InstanceOf(cx, obj, &js_ArrayClass, vp + 2))) {
return JS_FALSE;
}
if (!obj)
return false;
/*
* Passing comma here as the separator. Need a way to get a