Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Unified Diff: src/date.js

Issue 1346893003: [es6] Use the correct ToPrimitive in the Date Constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/contexts.h ('k') | src/macros.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/date.js
diff --git a/src/date.js b/src/date.js
index dd535b6e629322cdca08be4f4bdbc08160ef8799..f7a6a0825b409c320f43f0ffe6cc478b8fb9544e 100644
--- a/src/date.js
+++ b/src/date.js
@@ -22,7 +22,6 @@ var IsFinite;
var MathAbs;
var MathFloor;
var ToNumber;
-var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol");
var ToString;
utils.Import(function(from) {
@@ -150,6 +149,7 @@ function DateConstructor(year, month, date, hours, minutes, seconds, ms) {
} else if (argc == 1) {
if (IS_NUMBER(year)) {
value = year;
+
} else if (IS_STRING(year)) {
// Probe the Date cache. If we already have a time value for the
// given time, we re-use that instead of parsing the string again.
@@ -165,15 +165,11 @@ function DateConstructor(year, month, date, hours, minutes, seconds, ms) {
}
}
+ } else if (IS_DATE(year)) {
+ value = UTC_DATE_VALUE(year);
+
} else {
- // According to ECMA 262, no hint should be given for this
- // conversion. However, ToPrimitive defaults to STRING_HINT for
- // Date objects which will lose precision when the Date
- // constructor is called with another Date object as its
- // argument. We therefore use NUMBER_HINT for the conversion,
- // which is the default for everything else than Date objects.
- // This makes us behave like KJS and SpiderMonkey.
- var time = $toPrimitive(year, NUMBER_HINT);
+ var time = TO_PRIMITIVE(year);
value = IS_STRING(time) ? DateParse(time) : ToNumber(time);
}
SET_UTC_DATE_VALUE(this, value);
« no previous file with comments | « src/contexts.h ('k') | src/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698