mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 738511 - new Date(value) should call ToPrimitive on value before testing for string-ness. r=jwalden
--HG-- extra : rebase_source : 45ac679985c3834d90b2da9c76c753dd3e167059
This commit is contained in:
parent
a44baa565a
commit
97c0ab79ca
@ -2613,15 +2613,17 @@ js_Date(JSContext *cx, unsigned argc, Value *vp)
|
||||
/* Date called as constructor. */
|
||||
double d;
|
||||
if (args.length() == 0) {
|
||||
/* ES5 15.9.3.3. */
|
||||
d = NowAsMillis();
|
||||
} else if (args.length() == 1) {
|
||||
if (!args[0].isString()) {
|
||||
/* the argument is a millisecond number */
|
||||
if (!ToNumber(cx, args[0], &d))
|
||||
return false;
|
||||
d = TimeClip(d);
|
||||
} else {
|
||||
/* the argument is a string; parse it. */
|
||||
/* ES5 15.9.3.2. */
|
||||
|
||||
/* Step 1. */
|
||||
if (!ToPrimitive(cx, &args[0]))
|
||||
return false;
|
||||
|
||||
if (args[0].isString()) {
|
||||
/* Step 2. */
|
||||
JSString *str = ToString(cx, args[0]);
|
||||
if (!str)
|
||||
return false;
|
||||
@ -2634,6 +2636,11 @@ js_Date(JSContext *cx, unsigned argc, Value *vp)
|
||||
d = js_NaN;
|
||||
else
|
||||
d = TimeClip(d);
|
||||
} else {
|
||||
/* Step 3. */
|
||||
if (!ToNumber(cx, args[0], &d))
|
||||
return false;
|
||||
d = TimeClip(d);
|
||||
}
|
||||
} else {
|
||||
double msec_time;
|
||||
|
26
js/src/tests/ecma_5/Date/constructor-one-argument.js
Normal file
26
js/src/tests/ecma_5/Date/constructor-one-argument.js
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommonn.org/licenses/publicdomain/
|
||||
*/
|
||||
|
||||
var BUGNUMBER = 738511;
|
||||
var summary =
|
||||
"new Date(value) should call ToPrimitive on value before testing for " +
|
||||
"string-ness";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
**************/
|
||||
|
||||
assertEq(new Date(new String("2012-01-31T00:00:00.000Z")).valueOf(),
|
||||
1327968000000,
|
||||
"Date constructor passed a String object should parse it");
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
||||
print("Tests complete");
|
Loading…
Reference in New Issue
Block a user