From 57306b59e8f19eca89ef7d4773e132ac016651a0 Mon Sep 17 00:00:00 2001 From: mathias Date: Tue, 23 Jun 2015 11:42:52 -0700 Subject: [PATCH] Avoid built-ins in `Date.prototype.toISOString` TEST=mjsunit/date BUG=v8:4226 LOG=N Review URL: https://codereview.chromium.org/1203733002 Cr-Commit-Position: refs/heads/master@{#29240} --- src/date.js | 16 ++++++++-------- test/mjsunit/date.js | 9 +++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/date.js b/src/date.js index dbf4947..46fadec 100644 --- a/src/date.js +++ b/src/date.js @@ -747,12 +747,12 @@ function PadInt(n, digits) { } -// ECMA 262 - 15.9.5.43 +// ECMA 262 - 20.3.4.36 function DateToISOString() { CHECK_DATE(this); var t = UTC_DATE_VALUE(this); if (NUMBER_IS_NAN(t)) throw MakeRangeError(kInvalidTimeValue); - var year = this.getUTCFullYear(); + var year = UTC_YEAR(this); var year_string; if (year >= 0 && year <= 9999) { year_string = PadInt(year, 4); @@ -764,12 +764,12 @@ function DateToISOString() { } } return year_string + - '-' + PadInt(this.getUTCMonth() + 1, 2) + - '-' + PadInt(this.getUTCDate(), 2) + - 'T' + PadInt(this.getUTCHours(), 2) + - ':' + PadInt(this.getUTCMinutes(), 2) + - ':' + PadInt(this.getUTCSeconds(), 2) + - '.' + PadInt(this.getUTCMilliseconds(), 3) + + '-' + PadInt(UTC_MONTH(this) + 1, 2) + + '-' + PadInt(UTC_DAY(this), 2) + + 'T' + PadInt(UTC_HOUR(this), 2) + + ':' + PadInt(UTC_MIN(this), 2) + + ':' + PadInt(UTC_SEC(this), 2) + + '.' + PadInt(UTC_MS(this), 3) + 'Z'; } diff --git a/test/mjsunit/date.js b/test/mjsunit/date.js index 3d72032..0aadfde 100644 --- a/test/mjsunit/date.js +++ b/test/mjsunit/date.js @@ -340,3 +340,12 @@ date.getYear(); %OptimizeFunctionOnNextCall(Date.prototype.getYear); assertThrows(function() { Date.prototype.getYear.call(""); }, TypeError); assertUnoptimized(Date.prototype.getYear); + +delete Date.prototype.getUTCFullYear; +delete Date.prototype.getUTCMonth; +delete Date.prototype.getUTCDate; +delete Date.prototype.getUTCHours; +delete Date.prototype.getUTCMinutes; +delete Date.prototype.getUTCSeconds; +delete Date.prototype.getUTCMilliseconds; +date.toISOString(); -- 2.7.4