From 7151f3247e8614a952273347fc1d6fdcdf68a441 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 21 Mar 2017 10:44:32 +0100 Subject: [PATCH 1/3] Test that Date.prototype.toString throws for non-Date receiver Pending discussion of https://github.com/tc39/ecma262/issues/849 Test passes in V8. --- .../Date/prototype/toString/non-date-receiver.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/built-ins/Date/prototype/toString/non-date-receiver.js diff --git a/test/built-ins/Date/prototype/toString/non-date-receiver.js b/test/built-ins/Date/prototype/toString/non-date-receiver.js new file mode 100644 index 0000000000..2955654b51 --- /dev/null +++ b/test/built-ins/Date/prototype/toString/non-date-receiver.js @@ -0,0 +1,12 @@ +// Copyright (C) 2017 V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: #sec-date.prototype.tostring +description: Date.prototype.toString throws a TypeError on non-Date receivers +---*/ + +assert.throws(TypeError, () => Date.prototype.toString()); +assert.throws(TypeError, () => Date.prototype.toString.call(undefined)); +assert.throws(TypeError, () => Date.prototype.toString.call(0)); +assert.throws(TypeError, () => Date.prototype.toString.call({})); From 1f065b5b7140a8da9d458b1bb63af2edd25fadf1 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 21 Mar 2017 17:46:59 +0100 Subject: [PATCH 2/3] Changes to Date test from review --- .../Date/prototype/toString/non-date-receiver.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/built-ins/Date/prototype/toString/non-date-receiver.js b/test/built-ins/Date/prototype/toString/non-date-receiver.js index 2955654b51..4273975b1b 100644 --- a/test/built-ins/Date/prototype/toString/non-date-receiver.js +++ b/test/built-ins/Date/prototype/toString/non-date-receiver.js @@ -1,12 +1,20 @@ -// Copyright (C) 2017 V8 project authors. All rights reserved. +// Copyright (C) 2017 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: #sec-date.prototype.tostring +esid: sec-date.prototype.tostring description: Date.prototype.toString throws a TypeError on non-Date receivers +info: | + Date.prototype.toString ( ) + + 1. Let tv be ? thisTimeValue(this value). ---*/ assert.throws(TypeError, () => Date.prototype.toString()); assert.throws(TypeError, () => Date.prototype.toString.call(undefined)); assert.throws(TypeError, () => Date.prototype.toString.call(0)); assert.throws(TypeError, () => Date.prototype.toString.call({})); +assert.throws(TypeError, () => + Date.prototype.toString.call("Tue Mar 21 2017 12:16:43 GMT-0400 (EDT)")); +assert.throws(TypeError, () => + Date.prototype.toString.call(1490113011493)); From b3115654c16408b2156f50e2dce1d39c8d530af2 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 21 Mar 2017 12:00:13 +0100 Subject: [PATCH 3/3] Test toString() behavior of invalid Dates --- .../Date/prototype/toString/invalid-date.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/built-ins/Date/prototype/toString/invalid-date.js diff --git a/test/built-ins/Date/prototype/toString/invalid-date.js b/test/built-ins/Date/prototype/toString/invalid-date.js new file mode 100644 index 0000000000..dc85089966 --- /dev/null +++ b/test/built-ins/Date/prototype/toString/invalid-date.js @@ -0,0 +1,15 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-todatestring +description: Invalid Dates are rendered as "Invalid Date" +info: > + ToDateString ( tv ) + + ... + 2. If tv is NaN, return "Invalid Date". + ... +---*/ + +assert.sameValue(new Date(NaN).toString(), "Invalid Date");