Bug 692300 - date_valueOf should claim to be date_valueOf to NonGenericMethodGuard (r=waldo)

--HG--
extra : rebase_source : dfbe787ad430c8f173f1f8a22ffe66e2cd5cf352
This commit is contained in:
Luke Wagner 2011-10-07 11:58:45 -07:00
parent 3d72635b02
commit b8fcb43b2b
2 changed files with 17 additions and 16 deletions

View File

@ -147,5 +147,6 @@ test("new Date()", function(d) justDontThrow(Date.prototype.toTimeString.call(d)
test("new Date()", function(d) justDontThrow(Date.prototype.toDateString.call(d)));
test("new Date()", function(d) justDontThrow(Date.prototype.toSource.call(d)));
test("new Date()", function(d) justDontThrow(Date.prototype.toString.call(d)));
test("new Date()", function(d) justDontThrow(Date.prototype.valueOf.call(d)));
throw "done";

View File

@ -2513,32 +2513,32 @@ date_toString(JSContext *cx, uintN argc, Value *vp)
static JSBool
date_valueOf(JSContext *cx, uintN argc, Value *vp)
{
/*
* It is an error to call date_valueOf on a non-date object, but we don't
* need to check for that explicitly here because every path calls
* GetUTCTime, which does the check.
*/
CallArgs args = CallArgsFromVp(argc, vp);
bool ok;
JSObject *obj = NonGenericMethodGuard(cx, args, date_valueOf, &DateClass, &ok);
if (!obj)
return ok;
/* If called directly with no arguments, convert to a time number. */
if (argc == 0)
return date_getTime(cx, argc, vp);
/* Verify this before extracting a string from the first argument. */
JSObject *obj = ToObject(cx, &vp[1]);
if (!obj)
return false;
if (argc == 0) {
args.rval() = obj->getDateUTCTime();
return true;
}
/* Convert to number only if the hint was given, otherwise favor string. */
JSString *str = js_ValueToString(cx, vp[2]);
JSString *str = js_ValueToString(cx, args[0]);
if (!str)
return false;
JSLinearString *linear_str = str->ensureLinear(cx);
if (!linear_str)
return false;
JSAtom *number_str = cx->runtime->atomState.typeAtoms[JSTYPE_NUMBER];
if (EqualStrings(linear_str, number_str))
return date_getTime(cx, argc, vp);
return date_toString(cx, argc, vp);
if (EqualStrings(linear_str, number_str)) {
args.rval() = obj->getDateUTCTime();
return true;
}
return date_format(cx, obj->getDateUTCTime().toNumber(), FORMATSPEC_FULL, args);
}
// Don't really need an argument here, but we don't support arg-less builtins