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}
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(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)
V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun)
var MathAbs;
var MathFloor;
var ToNumber;
var MathAbs;
var MathFloor;
var ToNumber;
-var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol");
var ToString;
utils.Import(function(from) {
var ToString;
utils.Import(function(from) {
} else if (argc == 1) {
if (IS_NUMBER(year)) {
value = year;
} 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.
} 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.
+ } else if (IS_DATE(year)) {
+ value = UTC_DATE_VALUE(year);
+
- // 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);
value = IS_STRING(time) ? DateParse(time) : ToNumber(time);
}
SET_UTC_DATE_VALUE(this, value);
define GETTER = 0;
define SETTER = 1;
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;
# For date.js.
define HoursPerDay = 24;
define MinutesPerHour = 60;
var $toLength;
var $toNumber;
var $toPositiveInteger;
var $toLength;
var $toNumber;
var $toPositiveInteger;
var $toString;
var harmony_tolength = false;
var $toString;
var harmony_tolength = false;
-------------------------------------
*/
-------------------------------------
*/
-// 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;
// ECMA-262, section 9.2, page 30
function ToBoolean(x) {
if (IS_BOOLEAN(x)) return x;
$toLength = ToLength;
$toNumber = ToNumber;
$toPositiveInteger = ToPositiveInteger;
$toLength = ToLength;
$toNumber = ToNumber;
$toPositiveInteger = ToPositiveInteger;
-$toPrimitive = ToPrimitive;
$toString = ToString;
%InstallToContext([
$toString = ToString;
%InstallToContext([
"to_integer_fun", ToInteger,
"to_length_fun", ToLength,
"to_number_fun", ToNumber,
"to_integer_fun", ToInteger,
"to_length_fun", ToLength,
"to_number_fun", ToNumber,
- "to_primitive", ToPrimitive,
"to_string_fun", ToString,
]);
"to_string_fun", ToString,
]);
to.ToBoolean = ToBoolean;
to.ToLength = ToLength;
to.ToNumber = ToNumber;
to.ToBoolean = ToBoolean;
to.ToLength = ToLength;
to.ToNumber = ToNumber;
- to.ToPrimitive = ToPrimitive;
to.ToString = ToString;
});
to.ToString = ToString;
});