From f65e61ef447d7e273e9af5c10f3e5e2e3089ea66 Mon Sep 17 00:00:00 2001 From: littledan Date: Mon, 31 Aug 2015 13:45:35 -0700 Subject: [PATCH] Make Date.prototype an ordinary object This is a change for ES2015. Date objects have mutable state, so having a mutable prototype is bad for SES requirements, and it is an inconsistency from the typical ES2015 class style of objects BUG=v8:4004 LOG=Y R=adamk Review URL: https://codereview.chromium.org/1317403002 Cr-Commit-Position: refs/heads/master@{#30486} --- src/date.js | 3 ++- test/mjsunit/date.js | 5 +++++ test/mozilla/mozilla.status | 2 ++ test/test262-es6/test262-es6.status | 3 --- test/test262/test262.status | 3 +++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/date.js b/src/date.js index 4f49565e603..dd535b6e629 100644 --- a/src/date.js +++ b/src/date.js @@ -16,6 +16,7 @@ var $createDate; // Imports var GlobalDate = global.Date; +var GlobalObject = global.Object; var InternalArray = utils.InternalArray; var IsFinite; var MathAbs; @@ -822,7 +823,7 @@ function CreateDate(time) { // ------------------------------------------------------------------- %SetCode(GlobalDate, DateConstructor); -%FunctionSetPrototype(GlobalDate, new GlobalDate(NAN)); +%FunctionSetPrototype(GlobalDate, new GlobalObject()); // Set up non-enumerable properties of the Date object itself. utils.InstallFunctions(GlobalDate, DONT_ENUM, [ diff --git a/test/mjsunit/date.js b/test/mjsunit/date.js index adebbd141f7..33b5af4f00d 100644 --- a/test/mjsunit/date.js +++ b/test/mjsunit/date.js @@ -341,6 +341,11 @@ date.getYear(); assertThrows(function() { Date.prototype.getYear.call(""); }, TypeError); assertUnoptimized(Date.prototype.getYear); +(function TestDatePrototypeOrdinaryObject() { + assertEquals(Object.prototype, Date.prototype.__proto__); + assertThrows(function () { Date.prototype.toString() }, TypeError); +})(); + delete Date.prototype.getUTCFullYear; delete Date.prototype.getUTCMonth; delete Date.prototype.getUTCDate; diff --git a/test/mozilla/mozilla.status b/test/mozilla/mozilla.status index 94278e39b30..27827159ce9 100644 --- a/test/mozilla/mozilla.status +++ b/test/mozilla/mozilla.status @@ -85,6 +85,8 @@ 'ecma/String/15.5.4.8-1': [FAIL], 'ecma/String/15.5.4.9-1': [FAIL], + # Date.prototype is an Object, not a Date + 'ecma/Date/15.9.5': [FAIL], ##################### SKIPPED TESTS ##################### diff --git a/test/test262-es6/test262-es6.status b/test/test262-es6/test262-es6.status index 16068bf0cac..c3496a3a56b 100644 --- a/test/test262-es6/test262-es6.status +++ b/test/test262-es6/test262-es6.status @@ -295,9 +295,6 @@ 'built-ins/Symbol/species/builtin-getter-name': [FAIL], 'built-ins/Symbol/species/subclassing': [FAIL], - # https://code.google.com/p/v8/issues/detail?id=4004 - 'built-ins/Date/prototype/setFullYear/15.9.5.40_1': [FAIL], - # https://code.google.com/p/v8/issues/detail?id=4002 'built-ins/Error/prototype/S15.11.4_A2': [FAIL], diff --git a/test/test262/test262.status b/test/test262/test262.status index b9ef3c68f4f..dd854d00621 100644 --- a/test/test262/test262.status +++ b/test/test262/test262.status @@ -284,6 +284,9 @@ # ES6 says for dates to default to the local timezone if none is specified '15.9.1.15-1': [FAIL], + # ES6 makes Date.prototype an Object, not a Date + '15.9.5.40_1': [FAIL], + ######################## NEEDS INVESTIGATION ########################### # These test failures are specific to the intl402 suite and need investigation