Commit 90e1a0dd authored by bmeurer's avatar bmeurer Committed by Commit bot

[es6] Use the correct ToPrimitive in the Date Constructor.

This way we can finally remove the ES5 ToPrimitive builtin from
runtime.js, and the Date Constructor now properly supports
@@toPrimitive for the single argument case as well.

CQ_INCLUDE_TRYBOTS=tryserver.v8:v8_linux_layout_dbg,v8_linux_nosnap_dbg
R=rossberg@chromium.org
BUG=v8:4307
LOG=n

Review URL: https://codereview.chromium.org/1346893003

Cr-Commit-Position: refs/heads/master@{#30832}
parent 4efa41f3
......@@ -86,7 +86,6 @@ enum BindingFlags {
V(SPREAD_ITERABLE_INDEX, JSFunction, spread_iterable) \
V(TO_LENGTH_FUN_INDEX, JSFunction, to_length_fun) \
V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun) \
V(TO_PRIMITIVE_INDEX, JSFunction, to_primitive) \
V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun)
......
......@@ -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);
......
......@@ -39,10 +39,6 @@ define NEW_TWO_BYTE_STRING = false;
define GETTER = 0;
define SETTER = 1;
define NO_HINT = 0;
define NUMBER_HINT = 1;
define STRING_HINT = 2;
# For date.js.
define HoursPerDay = 24;
define MinutesPerHour = 60;
......
......@@ -21,7 +21,6 @@ var $toInteger;
var $toLength;
var $toNumber;
var $toPositiveInteger;
var $toPrimitive;
var $toString;
var harmony_tolength = false;
......@@ -176,15 +175,6 @@ function CONCAT_ITERABLE_TO_ARRAY(iterable) {
-------------------------------------
*/
// ECMA-262, section 9.1, page 30. Use null/undefined for no hint,
// (1) for number hint, and (2) for string hint.
function ToPrimitive(x, hint) {
if (!IS_SPEC_OBJECT(x)) return x;
if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x);
}
// ECMA-262, section 9.2, page 30
function ToBoolean(x) {
if (IS_BOOLEAN(x)) return x;
......@@ -377,7 +367,6 @@ $toInteger = ToInteger;
$toLength = ToLength;
$toNumber = ToNumber;
$toPositiveInteger = ToPositiveInteger;
$toPrimitive = ToPrimitive;
$toString = ToString;
%InstallToContext([
......@@ -394,7 +383,6 @@ $toString = ToString;
"to_integer_fun", ToInteger,
"to_length_fun", ToLength,
"to_number_fun", ToNumber,
"to_primitive", ToPrimitive,
"to_string_fun", ToString,
]);
......@@ -402,7 +390,6 @@ utils.Export(function(to) {
to.ToBoolean = ToBoolean;
to.ToLength = ToLength;
to.ToNumber = ToNumber;
to.ToPrimitive = ToPrimitive;
to.ToString = ToString;
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment