diff --git a/test/built-ins/Date/prototype/getDate/this-value-invalid-date.js b/test/built-ins/Date/prototype/getDate/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..801d6a5e81ccc9103ce16eeb2047697bc10e9eca --- /dev/null +++ b/test/built-ins/Date/prototype/getDate/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getdate +es6id: 20.3.4.2 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getDate(), NaN); diff --git a/test/built-ins/Date/prototype/getDate/this-value-non-date.js b/test/built-ins/Date/prototype/getDate/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..6734712ca1ff9cd1e6124081760f712077528732 --- /dev/null +++ b/test/built-ins/Date/prototype/getDate/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getdate +es6id: 20.3.4.2 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getDate = Date.prototype.getDate; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getDate, 'function'); + +assert.throws(TypeError, function() { + getDate.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getDate.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getDate.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getDate/this-value-non-object.js b/test/built-ins/Date/prototype/getDate/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..7764ab83ee6b8335f5f821a3e60faef3ffbee8b9 --- /dev/null +++ b/test/built-ins/Date/prototype/getDate/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getdate +es6id: 20.3.4.2 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getDate = Date.prototype.getDate; +var symbol = Symbol(); + +assert.sameValue(typeof getDate, 'function'); + +assert.throws(TypeError, function() { + getDate.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getDate.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getDate.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getDate.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getDate.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getDate.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getDate/this-value-valid-date.js b/test/built-ins/Date/prototype/getDate/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..ef065e18762d212e654185810aa7f5496bfba666 --- /dev/null +++ b/test/built-ins/Date/prototype/getDate/this-value-valid-date.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getdate +es6id: 20.3.4.2 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return DateFromTime(LocalTime(t)). +---*/ + +assert.sameValue(new Date(2016, 6, 6).getDate(), 6, 'first millisecond'); +assert.sameValue( + new Date(2016, 6, 6, 0, 0, 0, -1).getDate(), 5, 'previous millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 999).getDate(), 6, 'final millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 1000).getDate(), 7, 'subsequent millisecond' +); + +assert.sameValue( + new Date(2016, 1, 29).getDate(), 29, 'first millisecond (month boundary)' +); +assert.sameValue( + new Date(2016, 1, 29, 0, 0, 0, -1).getDate(), + 28, + 'previous millisecond (month boundary)' +); +assert.sameValue( + new Date(2016, 1, 29, 23, 59, 59, 999).getDate(), + 29, + 'final millisecond (month boundary)' +); +assert.sameValue( + new Date(2016, 1, 29, 23, 59, 59, 1000).getDate(), + 1, + 'subsequent millisecond (month boundary)' +); diff --git a/test/built-ins/Date/prototype/getDay/this-value-invalid-date.js b/test/built-ins/Date/prototype/getDay/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..cdcd54c0919a48d1914e87ac317caa9dfe391874 --- /dev/null +++ b/test/built-ins/Date/prototype/getDay/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getday +es6id: 20.3.4.3 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getDay(), NaN); diff --git a/test/built-ins/Date/prototype/getDay/this-value-non-date.js b/test/built-ins/Date/prototype/getDay/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..71adf2c09956835193a65058a0e1ccad5ad5d468 --- /dev/null +++ b/test/built-ins/Date/prototype/getDay/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getday +es6id: 20.3.4.3 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getDay = Date.prototype.getDay; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getDay, 'function'); + +assert.throws(TypeError, function() { + getDay.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getDay.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getDay.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getDay/this-value-non-object.js b/test/built-ins/Date/prototype/getDay/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..49bbab1d7872ad2f885ecaeddc93b7b1b98b39a5 --- /dev/null +++ b/test/built-ins/Date/prototype/getDay/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getday +es6id: 20.3.4.3 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getDay = Date.prototype.getDay; +var symbol = Symbol(); + +assert.sameValue(typeof getDay, 'function'); + +assert.throws(TypeError, function() { + getDay.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getDay.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getDay.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getDay.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getDay.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getDay.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getDay/this-value-valid-date.js b/test/built-ins/Date/prototype/getDay/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..a9f98f9d93a433e1837f2158b00c4cc322109604 --- /dev/null +++ b/test/built-ins/Date/prototype/getDay/this-value-valid-date.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getday +es6id: 20.3.4.3 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return WeekDay(LocalTime(t)). +---*/ + +assert.sameValue(new Date(2016, 6, 6).getDay(), 3, 'first millisecond'); +assert.sameValue( + new Date(2016, 6, 6, 0, 0, 0, -1).getDay(), 2, 'previous millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 999).getDay(), 3, 'final millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 1000).getDay(), 4, 'subsequent millisecond' +); + +assert.sameValue( + new Date(2016, 6, 9).getDay(), 6, 'first millisecond (week boundary)' +); +assert.sameValue( + new Date(2016, 6, 9, 0, 0, 0, -1).getDay(), + 5, + 'previous millisecond (week boundary)' +); +assert.sameValue( + new Date(2016, 6, 9, 23, 59, 59, 999).getDay(), + 6, + 'final millisecond (week boundary)' +); +assert.sameValue( + new Date(2016, 6, 9, 23, 59, 59, 1000).getDay(), + 0, + 'subsequent millisecond (week boundary)' +); diff --git a/test/built-ins/Date/prototype/getFullYear/this-value-invalid-date.js b/test/built-ins/Date/prototype/getFullYear/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..ed516b30bdf98b03bf8f6e7083cc686c99e5c54c --- /dev/null +++ b/test/built-ins/Date/prototype/getFullYear/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getfullyear +es6id: 20.3.4.4 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getFullYear(), NaN); diff --git a/test/built-ins/Date/prototype/getFullYear/this-value-non-date.js b/test/built-ins/Date/prototype/getFullYear/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..db86b65f9b67db1df4b7713800e7a5557bb21c94 --- /dev/null +++ b/test/built-ins/Date/prototype/getFullYear/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getfullyear +es6id: 20.3.4.4 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getFullYear = Date.prototype.getFullYear; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getFullYear, 'function'); + +assert.throws(TypeError, function() { + getFullYear.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getFullYear.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getFullYear.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getFullYear/this-value-non-object.js b/test/built-ins/Date/prototype/getFullYear/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..2db8d32958d4bda3954592ac6455547b77fc6ce0 --- /dev/null +++ b/test/built-ins/Date/prototype/getFullYear/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getfullyear +es6id: 20.3.4.4 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getFullYear = Date.prototype.getFullYear; +var symbol = Symbol(); + +assert.sameValue(typeof getFullYear, 'function'); + +assert.throws(TypeError, function() { + getFullYear.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getFullYear.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getFullYear.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getFullYear.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getFullYear.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getFullYear.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getFullYear/this-value-valid-date.js b/test/built-ins/Date/prototype/getFullYear/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..5020239ce563562aa43c82933bde8d066af60ad6 --- /dev/null +++ b/test/built-ins/Date/prototype/getFullYear/this-value-valid-date.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getfullyear +es6id: 20.3.4.4 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return YearFromTime(LocalTime(t)). +---*/ + +assert.sameValue(new Date(2016, 0).getFullYear(), 2016, 'first millisecond'); +assert.sameValue( + new Date(2016, 0, 1, 0, 0, 0, -1).getFullYear(), 2015, 'previous millisecond' +); +assert.sameValue( + new Date(2016, 11, 31, 23, 59, 59, 999).getFullYear(), + 2016, + 'final millisecond' +); +assert.sameValue( + new Date(2016, 11, 31, 23, 59, 59, 1000).getFullYear(), + 2017, + 'subsequent millisecond' +); diff --git a/test/built-ins/Date/prototype/getHours/this-value-invalid-date.js b/test/built-ins/Date/prototype/getHours/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..7d55381c44bbde5cb764860d020b94626559dcd9 --- /dev/null +++ b/test/built-ins/Date/prototype/getHours/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gethours +es6id: 20.3.4.5 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getHours(), NaN); diff --git a/test/built-ins/Date/prototype/getHours/this-value-non-date.js b/test/built-ins/Date/prototype/getHours/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..7c922a9b22afdb73f143659d9f7a4397c5b5ca40 --- /dev/null +++ b/test/built-ins/Date/prototype/getHours/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gethours +es6id: 20.3.4.5 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getHours = Date.prototype.getHours; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getHours, 'function'); + +assert.throws(TypeError, function() { + getHours.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getHours.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getHours.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getHours/this-value-non-object.js b/test/built-ins/Date/prototype/getHours/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..ad9536b85f2046e8fb61fc2c981add26e4879697 --- /dev/null +++ b/test/built-ins/Date/prototype/getHours/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gethours +es6id: 20.3.4.5 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getHours = Date.prototype.getHours; +var symbol = Symbol(); + +assert.sameValue(typeof getHours, 'function'); + +assert.throws(TypeError, function() { + getHours.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getHours.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getHours.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getHours.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getHours.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getHours.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getHours/this-value-valid-date.js b/test/built-ins/Date/prototype/getHours/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..7cc0e4a2bf547c231611c3bd259eddbf844ee819 --- /dev/null +++ b/test/built-ins/Date/prototype/getHours/this-value-valid-date.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gethours +es6id: 20.3.4.5 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return HourFromTime(LocalTime(t)). +---*/ + +assert.sameValue(new Date(2016, 6, 6, 13).getHours(), 13, 'first millisecond'); +assert.sameValue( + new Date(2016, 6, 6, 13, 0, 0, -1).getHours(), 12, 'previous millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 13, 59, 59, 999).getHours(), + 13, + 'final millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 13, 59, 59, 1000).getHours(), + 14, + 'subsequent millisecond' +); + +assert.sameValue( + new Date(2016, 6, 6, 23).getHours(), 23, 'first millisecond (hour boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 0, 0, -1).getHours(), + 22, + 'previous millisecond (hour boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 999).getHours(), + 23, + 'final millisecond (hour boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 1000).getHours(), + 0, + 'subsequent millisecond (hour boundary)' +); diff --git a/test/built-ins/Date/prototype/getMilliseconds/this-value-invalid-date.js b/test/built-ins/Date/prototype/getMilliseconds/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..50bbdb04529f1e0b9dfb9b5f866ebcca266fb5f3 --- /dev/null +++ b/test/built-ins/Date/prototype/getMilliseconds/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmilliseconds +es6id: 20.3.4.6 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getMilliseconds(), NaN); diff --git a/test/built-ins/Date/prototype/getMilliseconds/this-value-non-date.js b/test/built-ins/Date/prototype/getMilliseconds/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..1c71dc38399e5156b6341ad9c0ebdc6c93de44a1 --- /dev/null +++ b/test/built-ins/Date/prototype/getMilliseconds/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmilliseconds +es6id: 20.3.4.6 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getMilliseconds = Date.prototype.getMilliseconds; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getMilliseconds, 'function'); + +assert.throws(TypeError, function() { + getMilliseconds.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getMilliseconds.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getMilliseconds.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getMilliseconds/this-value-non-object.js b/test/built-ins/Date/prototype/getMilliseconds/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..b215b9c51b88df0da17bfcc01812c7d1805d4454 --- /dev/null +++ b/test/built-ins/Date/prototype/getMilliseconds/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmilliseconds +es6id: 20.3.4.6 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getMilliseconds = Date.prototype.getMilliseconds; +var symbol = Symbol(); + +assert.sameValue(typeof getMilliseconds, 'function'); + +assert.throws(TypeError, function() { + getMilliseconds.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getMilliseconds.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getMilliseconds.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getMilliseconds.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getMilliseconds.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getMilliseconds.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getMilliseconds/this-value-valid-date.js b/test/built-ins/Date/prototype/getMilliseconds/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..0cbcb5643e33e2756554f4261fe9adbd17eb498a --- /dev/null +++ b/test/built-ins/Date/prototype/getMilliseconds/this-value-valid-date.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmilliseconds +es6id: 20.3.4.6 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return msFromTime(LocalTime(t)). +---*/ + +assert.sameValue( + new Date(2016, 6, 6).getMilliseconds(), 0, 'first millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 0, 0, 0, -1).getMilliseconds(), + 999, + 'previous millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 999).getMilliseconds(), + 999, + 'final millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 23, 59, 59, 1000).getMilliseconds(), + 0, + 'subsequent millisecond' +); diff --git a/test/built-ins/Date/prototype/getMinutes/this-value-invalid-date.js b/test/built-ins/Date/prototype/getMinutes/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..6cf70768525237b2408d3897ccd9f4bd3e05b7bd --- /dev/null +++ b/test/built-ins/Date/prototype/getMinutes/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getminutes +es6id: 20.3.4.7 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getMinutes(), NaN); diff --git a/test/built-ins/Date/prototype/getMinutes/this-value-non-date.js b/test/built-ins/Date/prototype/getMinutes/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..b8e220a5aa3e89900c04d1f02f6e13c258abdbc8 --- /dev/null +++ b/test/built-ins/Date/prototype/getMinutes/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getminutes +es6id: 20.3.4.7 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getMinutes = Date.prototype.getMinutes; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getMinutes, 'function'); + +assert.throws(TypeError, function() { + getMinutes.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getMinutes.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getMinutes.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getMinutes/this-value-non-object.js b/test/built-ins/Date/prototype/getMinutes/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..00427806bba62e7062ea872609ef5e82526849e8 --- /dev/null +++ b/test/built-ins/Date/prototype/getMinutes/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getminutes +es6id: 20.3.4.7 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getMinutes = Date.prototype.getMinutes; +var symbol = Symbol(); + +assert.sameValue(typeof getMinutes, 'function'); + +assert.throws(TypeError, function() { + getMinutes.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getMinutes.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getMinutes.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getMinutes.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getMinutes.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getMinutes.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getMinutes/this-value-valid-date.js b/test/built-ins/Date/prototype/getMinutes/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..39c22add80d6985d2af0e6fe1b793839ac0dbdd4 --- /dev/null +++ b/test/built-ins/Date/prototype/getMinutes/this-value-valid-date.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getminutes +es6id: 20.3.4.7 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return MinFromTime(LocalTime(t)). +---*/ + +assert.sameValue(new Date(2016, 6, 6, 14, 6).getMinutes(), 6, 'first millisecond'); +assert.sameValue( + new Date(2016, 6, 6, 14, 6, 0, -1).getMinutes(), 5, 'previous millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 6, 59, 999).getMinutes(), 6, 'final millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 6, 59, 1000).getMinutes(), 7, 'subsequent millisecond' +); + +assert.sameValue( + new Date(2016, 6, 6, 14, 59).getMinutes(), 59, 'first millisecond (hour boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 59, 0, -1).getMinutes(), + 58, + 'previous millisecond (hour boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 59, 59, 999).getMinutes(), + 59, + 'final millisecond (hour boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 59, 59, 1000).getMinutes(), + 0, + 'subsequent millisecond (hour boundary)' +); diff --git a/test/built-ins/Date/prototype/getMonth/this-value-invalid-date.js b/test/built-ins/Date/prototype/getMonth/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..17200abbcfad6988dde116defd039215b3a105da --- /dev/null +++ b/test/built-ins/Date/prototype/getMonth/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmonth +es6id: 20.3.4.8 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getMonth(), NaN); diff --git a/test/built-ins/Date/prototype/getMonth/this-value-non-date.js b/test/built-ins/Date/prototype/getMonth/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..35e9a49c8caf4ee5a41ec8d7f54cf6785a39b57a --- /dev/null +++ b/test/built-ins/Date/prototype/getMonth/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmonth +es6id: 20.3.4.8 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getMonth = Date.prototype.getMonth; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getMonth, 'function'); + +assert.throws(TypeError, function() { + getMonth.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getMonth.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getMonth.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getMonth/this-value-non-object.js b/test/built-ins/Date/prototype/getMonth/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..742b5416b9cc107f398131e6f6d248a5593d92a5 --- /dev/null +++ b/test/built-ins/Date/prototype/getMonth/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmonth +es6id: 20.3.4.8 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getMonth = Date.prototype.getMonth; +var symbol = Symbol(); + +assert.sameValue(typeof getMonth, 'function'); + +assert.throws(TypeError, function() { + getMonth.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getMonth.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getMonth.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getMonth.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getMonth.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getMonth.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getMonth/this-value-valid-date.js b/test/built-ins/Date/prototype/getMonth/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..633a3d79cac7be20823c09302fcdccfc92c34866 --- /dev/null +++ b/test/built-ins/Date/prototype/getMonth/this-value-valid-date.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getmonth +es6id: 20.3.4.8 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return MonthFromTime(LocalTime(t)). +---*/ + +assert.sameValue(new Date(2016, 6).getMonth(), 6, 'first millisecond'); +assert.sameValue( + new Date(2016, 6, 0, 0, 0, 0, -1).getMonth(), 5, 'previous millisecond' +); +assert.sameValue( + new Date(2016, 6, 31, 23, 59, 59, 999).getMonth(), 6, 'final millisecond' +); +assert.sameValue( + new Date(2016, 6, 31, 23, 59, 59, 1000).getMonth(), 7, 'subsequent millisecond' +); + +assert.sameValue( + new Date(2016, 11, 31).getMonth(), 11, 'first millisecond (year boundary)' +); +assert.sameValue( + new Date(2016, 11, 0, 0, 0, 0, -1).getMonth(), + 10, + 'previous millisecond (year boundary)' +); +assert.sameValue( + new Date(2016, 11, 31, 23, 59, 59, 999).getMonth(), + 11, + 'final millisecond (year boundary)' +); +assert.sameValue( + new Date(2016, 11, 31, 23, 59, 59, 1000).getMonth(), + 0, + 'subsequent millisecond (year boundary)' +); diff --git a/test/built-ins/Date/prototype/getSeconds/this-value-invalid-date.js b/test/built-ins/Date/prototype/getSeconds/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..08dc11e732ab1083242c6484ddbb0df7c42dd9b7 --- /dev/null +++ b/test/built-ins/Date/prototype/getSeconds/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getseconds +es6id: 20.3.4.9 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getSeconds(), NaN); diff --git a/test/built-ins/Date/prototype/getSeconds/this-value-non-date.js b/test/built-ins/Date/prototype/getSeconds/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..e2068723eaa70e3abf8ccd519693f1d1fbc249b5 --- /dev/null +++ b/test/built-ins/Date/prototype/getSeconds/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getseconds +es6id: 20.3.4.9 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getSeconds = Date.prototype.getSeconds; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getSeconds, 'function'); + +assert.throws(TypeError, function() { + getSeconds.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getSeconds.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getSeconds.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getSeconds/this-value-non-object.js b/test/built-ins/Date/prototype/getSeconds/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..7470708bf9bfb894b777803904a110904672a81d --- /dev/null +++ b/test/built-ins/Date/prototype/getSeconds/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getseconds +es6id: 20.3.4.9 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getSeconds = Date.prototype.getSeconds; +var symbol = Symbol(); + +assert.sameValue(typeof getSeconds, 'function'); + +assert.throws(TypeError, function() { + getSeconds.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getSeconds.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getSeconds.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getSeconds.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getSeconds.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getSeconds.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getSeconds/this-value-valid-date.js b/test/built-ins/Date/prototype/getSeconds/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..d2abfc46548877a2007a7710c32febfef1f6ad9f --- /dev/null +++ b/test/built-ins/Date/prototype/getSeconds/this-value-valid-date.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getseconds +es6id: 20.3.4.9 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return SecFromTime(LocalTime(t)). +---*/ + +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 30).getSeconds(), + 30, + 'first millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 30, -1).getSeconds(), 29, 'previous millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 30, 999).getSeconds(), 30, 'final millisecond' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 30, 1000).getSeconds(), + 31, + 'subsequent millisecond' +); + +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 59).getSeconds(), + 59, + 'first millisecond (minute boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 59, -1).getSeconds(), + 58, + 'previous millisecond (minute boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 59, 999).getSeconds(), + 59, + 'final millisecond (minute boundary)' +); +assert.sameValue( + new Date(2016, 6, 6, 14, 16, 59, 1000).getSeconds(), + 0, + 'subsequent millisecond (minute boundary)' +); diff --git a/test/built-ins/Date/prototype/getTime/this-value-invalid-date.js b/test/built-ins/Date/prototype/getTime/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..d123be9b5e418d9536295b6e9c259c637943ab66 --- /dev/null +++ b/test/built-ins/Date/prototype/getTime/this-value-invalid-date.js @@ -0,0 +1,11 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettime +es6id: 20.3.4.10 +description: Return value for invalid date +info: | + 1. Return ? thisTimeValue(this value). +---*/ + +assert.sameValue(new Date(NaN).getTime(), NaN); diff --git a/test/built-ins/Date/prototype/getTime/this-value-non-date.js b/test/built-ins/Date/prototype/getTime/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..ee4bb53d55836c06aab5cdc7c4e3fe5a5348c938 --- /dev/null +++ b/test/built-ins/Date/prototype/getTime/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettime +es6id: 20.3.4.10 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Return ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getTime = Date.prototype.getTime; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getTime, 'function'); + +assert.throws(TypeError, function() { + getTime.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getTime.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getTime.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getTime/this-value-non-object.js b/test/built-ins/Date/prototype/getTime/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c2808853a3c054b602df8fa509d1360dc99845c2 --- /dev/null +++ b/test/built-ins/Date/prototype/getTime/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettime +es6id: 20.3.4.10 +description: Behavior when "this" value is not an Object +info: | + 1. Return ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getTime = Date.prototype.getTime; +var symbol = Symbol(); + +assert.sameValue(typeof getTime, 'function'); + +assert.throws(TypeError, function() { + getTime.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getTime.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getTime.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getTime.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getTime.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getTime.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getTime/this-value-valid-date.js b/test/built-ins/Date/prototype/getTime/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..0b3ebf336c9f03531304be63a8f805c0822402c5 --- /dev/null +++ b/test/built-ins/Date/prototype/getTime/this-value-valid-date.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettime +es6id: 20.3.4.10 +description: Return value for valid dates +info: | + 1. Return ? thisTimeValue(this value). +---*/ + +assert.sameValue(new Date(0).getTime(), 0, '+0'); +assert.sameValue(new Date(-0).getTime(), 0, '-0'); +assert.sameValue(new Date(-1).getTime(), -1); +assert.sameValue(new Date(1).getTime(), 1); +assert.sameValue(new Date(8640000000000000).getTime(), 8640000000000000); +assert.sameValue(new Date(-8640000000000000).getTime(), -8640000000000000); diff --git a/test/built-ins/Date/prototype/getTimezoneOffset/this-value-invalid-date.js b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..2e675061cdacbb27654421fe31486d460dde2430 --- /dev/null +++ b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettimezoneoffset +es6id: 20.3.4.11 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getTimezoneOffset(), NaN); diff --git a/test/built-ins/Date/prototype/getTimezoneOffset/this-value-non-date.js b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..5cda482118ba17e61d653f50968aaa41ea865fb2 --- /dev/null +++ b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettimezoneoffset +es6id: 20.3.4.11 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getTimezoneOffset = Date.prototype.getTimezoneOffset; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getTimezoneOffset, 'function'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getTimezoneOffset/this-value-non-object.js b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..add5279f656da8a719d9587c3c410a75b5cf3cf5 --- /dev/null +++ b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettimezoneoffset +es6id: 20.3.4.11 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getTimezoneOffset = Date.prototype.getTimezoneOffset; +var symbol = Symbol(); + +assert.sameValue(typeof getTimezoneOffset, 'function'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getTimezoneOffset.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getTimezoneOffset/this-value-valid-date.js b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..e99f3a2e7934d863b29bedb9fa6fb21db728bb9a --- /dev/null +++ b/test/built-ins/Date/prototype/getTimezoneOffset/this-value-valid-date.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.gettimezoneoffset +es6id: 20.3.4.11 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return (t - LocalTime(t)) / msPerMinute. +---*/ + +assert.sameValue( + typeof new Date(0).getTimezoneOffset(), 'number', 'Unix epoch' +); + +assert.sameValue( + typeof new Date(8640000000000000).getTimezoneOffset(), + 'number', + 'latest representable time' +); + +assert.sameValue( + typeof new Date(-8640000000000000).getTimezoneOffset(), + 'number', + 'earliest representable time' +); + +assert.sameValue( + typeof new Date().getTimezoneOffset(), 'number', 'current time' +); diff --git a/test/built-ins/Date/prototype/getUTCDate/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCDate/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..f6c960f56a0d4f44e68ac5e72c9ed562ecac01c8 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDate/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcdate +es6id: 20.3.4.12 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCDate(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCDate/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCDate/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..d2dae6634005fe5aff66e0210ba9c2a7256816ec --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDate/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcdate +es6id: 20.3.4.12 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCDate = Date.prototype.getUTCDate; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCDate, 'function'); + +assert.throws(TypeError, function() { + getUTCDate.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCDate.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCDate.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCDate/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCDate/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4065f37238de7a816d52559d35c46aa828601ae9 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDate/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcdate +es6id: 20.3.4.12 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCDate = Date.prototype.getUTCDate; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCDate, 'function'); + +assert.throws(TypeError, function() { + getUTCDate.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCDate.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCDate.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCDate.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCDate.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCDate.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCDate/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCDate/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..ad5e307c945f465f0742ff2edb543846ef0c8e7b --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDate/this-value-valid-date.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcdate +es6id: 20.3.4.12 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return DateFromTime(t). +---*/ + +var july6 = 1467763200000; +var feb29 = 1456704000000; +var dayMs = 24 * 60 * 60 * 1000; + +assert.sameValue(new Date(july6).getUTCDate(), 6, 'first millisecond'); +assert.sameValue( + new Date(july6 - 1).getUTCDate(), 5, 'previous millisecond' +); +assert.sameValue( + new Date(july6 + dayMs - 1).getUTCDate(), 6, 'final millisecond' +); +assert.sameValue( + new Date(july6 + dayMs).getUTCDate(), 7, 'subsequent millisecond' +); + +assert.sameValue( + new Date(feb29).getUTCDate(), 29, 'first millisecond (month boundary)' +); +assert.sameValue( + new Date(feb29 - 1).getUTCDate(), 28, 'previous millisecond (month boundary)' +); +assert.sameValue( + new Date(feb29 + dayMs - 1).getUTCDate(), + 29, + 'final millisecond (month boundary)' +); +assert.sameValue( + new Date(feb29 + dayMs).getUTCDate(), + 1, + 'subsequent millisecond (month boundary)' +); diff --git a/test/built-ins/Date/prototype/getUTCDay/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCDay/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..ff99a3e5fea37d428cf4e3165cdaa3ebdfc9ebcc --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDay/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcday +es6id: 20.3.4.13 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCDay(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCDay/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCDay/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..a7cbdb95317429dda23533a0515f9e6fe41872a9 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDay/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcday +es6id: 20.3.4.13 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCDay = Date.prototype.getUTCDay; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCDay, 'function'); + +assert.throws(TypeError, function() { + getUTCDay.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCDay.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCDay.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCDay/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCDay/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..a10626547bde7a43b5feba7df2763bba1b0559d2 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDay/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcdaty +es6id: 20.3.4.13 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCDay = Date.prototype.getUTCDay; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCDay, 'function'); + +assert.throws(TypeError, function() { + getUTCDay.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCDay.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCDay.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCDay.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCDay.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCDay.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCDay/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCDay/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..4bb42fa5fba0bb6179e28772f603b2688948b07a --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCDay/this-value-valid-date.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcday +es6id: 20.3.4.13 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return WeekDay(t). +---*/ + +var july6 = 1467763200000; +var july9 = 1468022400000; +var dayMs = 24 * 60 * 60 * 1000; + +assert.sameValue(new Date(july6).getUTCDay(), 3, 'first millisecond'); +assert.sameValue( + new Date(july6 - 1).getUTCDay(), 2, 'previous millisecond' +); +assert.sameValue( + new Date(july6 + dayMs - 1).getUTCDay(), 3, 'final millisecond' +); +assert.sameValue( + new Date(july6 + dayMs).getUTCDay(), 4, 'subsequent millisecond' +); + +assert.sameValue( + new Date(july9).getUTCDay(), 6, 'first millisecond (week boundary)' +); +assert.sameValue( + new Date(july9 - 1).getUTCDay(), 5, 'previous millisecond (week boundary)' +); +assert.sameValue( + new Date(july9 + dayMs - 1).getUTCDay(), + 6, + 'final millisecond (week boundary)' +); +assert.sameValue( + new Date(july9 + dayMs).getUTCDay(), + 0, + 'subsequent millisecond (week boundary)' +); diff --git a/test/built-ins/Date/prototype/getUTCFullYear/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCFullYear/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..dfb8121054467a4e85ff8cf480cf37574d91bf6e --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCFullYear/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcfullyear +es6id: 20.3.4.14 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCFullYear(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCFullYear/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCFullYear/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..deb4325ec2e7270adfe3af209a4f2a2a077d2e6c --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCFullYear/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcfullyear +es6id: 20.3.4.14 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCFullYear = Date.prototype.getUTCFullYear; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCFullYear, 'function'); + +assert.throws(TypeError, function() { + getUTCFullYear.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCFullYear.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCFullYear.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCFullYear/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCFullYear/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4938d9ec393380cdbae08300e7007fbb79fdd006 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCFullYear/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcfullyear +es6id: 20.3.4.14 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCFullYear = Date.prototype.getUTCFullYear; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCFullYear, 'function'); + +assert.throws(TypeError, function() { + getUTCFullYear.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCFullYear.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCFullYear.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCFullYear.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCFullYear.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCFullYear.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCFullYear/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCFullYear/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..18a4139976807b68a9a3adc11c6cd397d5b53159 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCFullYear/this-value-valid-date.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcfullyear +es6id: 20.3.4.14 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return YearFromTime(t). +---*/ + +var dec31 = 1483142400000; +var dayMs = 24 * 60 * 60 * 1000; + +assert.sameValue(new Date(dec31).getUTCFullYear(), 2016, 'first millisecond'); +assert.sameValue( + new Date(dec31 - 1).getUTCFullYear(), 2016, 'previous millisecond' +); +assert.sameValue( + new Date(dec31 + dayMs - 1).getUTCFullYear(), 2016, 'final millisecond' +); +assert.sameValue( + new Date(dec31 + dayMs).getUTCFullYear(), 2017, 'subsequent millisecond' +); diff --git a/test/built-ins/Date/prototype/getUTCHours/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCHours/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..e3dc1233bf6a484ef41065445544fd3a22d4e0c3 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCHours/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutchours +es6id: 20.3.4.15 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCHours(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCHours/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCHours/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..6eeee6196c0c5d89c1589a7d82c292a04f90c02c --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCHours/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutchours +es6id: 20.3.4.15 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCHours = Date.prototype.getUTCHours; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCHours, 'function'); + +assert.throws(TypeError, function() { + getUTCHours.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCHours.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCHours.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCHours/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCHours/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..f87e549b27457c93b2e9140555f1b4282ab5608b --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCHours/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutchours +es6id: 20.3.4.15 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCHours = Date.prototype.getUTCHours; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCHours, 'function'); + +assert.throws(TypeError, function() { + getUTCHours.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCHours.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCHours.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCHours.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCHours.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCHours.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCHours/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCHours/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..2db9f8ed477e96d38fc3f2ec30271f72e3a6f673 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCHours/this-value-valid-date.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutchours +es6id: 20.3.4.15 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return HourFromTime(t). +---*/ + +var hour15 = 1467817200000; +var hour23 = 1467846000000; +var hourMs = 60 * 60 * 1000; + +assert.sameValue(new Date(hour15).getUTCHours(), 15, 'first millisecond'); +assert.sameValue( + new Date(hour15 - 1).getUTCHours(), 14, 'previous millisecond' +); +assert.sameValue( + new Date(hour15 + hourMs - 1).getUTCHours(), 15, 'final millisecond' +); +assert.sameValue( + new Date(hour15 + hourMs).getUTCHours(), 16, 'subsequent millisecond' +); + +assert.sameValue( + new Date(hour23).getUTCHours(), 23, 'first millisecond (day boundary)' +); +assert.sameValue( + new Date(hour23 - 1).getUTCHours(), 22, 'previous millisecond (day boundary)' +); +assert.sameValue( + new Date(hour23 + hourMs - 1).getUTCHours(), + 23, + 'final millisecond (day boundary)' +); +assert.sameValue( + new Date(hour23 + hourMs).getUTCHours(), + 0, + 'subsequent millisecond (day boundary)' +); diff --git a/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..23f15f71c7bccfc946769a626bc269caac48dace --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmilliseconds +es6id: 20.3.4.16 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCMilliseconds(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..f819746d1699dcc87a3836444458acae254c74c5 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmilliseconds +es6id: 20.3.4.16 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCMilliseconds = Date.prototype.getUTCMilliseconds; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCMilliseconds, 'function'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..7cbcb0848cb979fd6e67c44e0e8df4cd0e3f9ea2 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmilliseconds +es6id: 20.3.4.16 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCMilliseconds = Date.prototype.getUTCMilliseconds; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCMilliseconds, 'function'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCMilliseconds.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..a0cfa89568871df07558531ce3d5e48a9e0104e3 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMilliseconds/this-value-valid-date.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmmilliseconds +es6id: 20.3.4.16 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return msFromTime(t). +---*/ + +var july6 = 1467763200000; + +assert.sameValue(new Date(july6).getUTCMilliseconds(), 0, 'first millisecond'); +assert.sameValue( + new Date(july6 - 1).getUTCMilliseconds(), 999, 'previous millisecond' +); +assert.sameValue( + new Date(july6 + 999).getUTCMilliseconds(), 999, 'final millisecond' +); +assert.sameValue( + new Date(july6 + 1000).getUTCMilliseconds(), 0, 'subsequent millisecond' +); diff --git a/test/built-ins/Date/prototype/getUTCMinutes/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCMinutes/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..73645b901c0350568cad163ae967df3fbd6495a9 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMinutes/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcminutes +es6id: 20.3.4.17 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCMinutes(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCMinutes/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCMinutes/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..d1ce694e4e76bde2df19661441a6a13c24851542 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMinutes/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcminutes +es6id: 20.3.4.17 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCMinutes = Date.prototype.getUTCMinutes; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCMinutes, 'function'); + +assert.throws(TypeError, function() { + getUTCMinutes.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCMinutes.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCMinutes.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCMinutes/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCMinutes/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8bd596246c8de075c632ad5361c956a38a80f2e5 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMinutes/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcminutes +es6id: 20.3.4.17 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCMinutes = Date.prototype.getUTCMinutes; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCMinutes, 'function'); + +assert.throws(TypeError, function() { + getUTCMinutes.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCMinutes.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCMinutes.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCMinutes.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCMinutes.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCMinutes.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCMinutes/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCMinutes/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..f1d37366dce87f8f2fa78c447459950489167b48 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMinutes/this-value-valid-date.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcminutes +es6id: 20.3.4.17 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return MinFromTime(t). +---*/ + +var threeTwentyTwo = 1467818520000; +var threeFiftyNine = 1467820740000; +var minMs = 60 * 1000; + +assert.sameValue( + new Date(threeTwentyTwo).getUTCMinutes(), 22, 'first millisecond' +); +assert.sameValue( + new Date(threeTwentyTwo - 1).getUTCMinutes(), 21, 'previous millisecond' +); +assert.sameValue( + new Date(threeTwentyTwo + minMs - 1).getUTCMinutes(), 22, 'final millisecond' +); +assert.sameValue( + new Date(threeTwentyTwo + minMs).getUTCMinutes(), + 23, + 'subsequent millisecond' +); + +assert.sameValue( + new Date(threeFiftyNine).getUTCMinutes(), + 59, + 'first millisecond (day boundary)' +); +assert.sameValue( + new Date(threeFiftyNine - 1).getUTCMinutes(), + 58, + 'previous millisecond (day boundary)' +); +assert.sameValue( + new Date(threeFiftyNine + minMs - 1).getUTCMinutes(), + 59, + 'final millisecond (day boundary)' +); +assert.sameValue( + new Date(threeFiftyNine + minMs).getUTCMinutes(), + 0, + 'subsequent millisecond (day boundary)' +); diff --git a/test/built-ins/Date/prototype/getUTCMonth/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCMonth/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..572c81f8a7bdde88ca9aff0a99d38de67320be49 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMonth/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmonth +es6id: 20.3.4.18 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCMonth(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCMonth/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCMonth/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..0dacaba82f5eabf0a729834887c0d0a2443436b7 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMonth/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmonth +es6id: 20.3.4.18 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCMonth = Date.prototype.getUTCMonth; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCMonth, 'function'); + +assert.throws(TypeError, function() { + getUTCMonth.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCMonth.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCMonth.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCMonth/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCMonth/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4c33ad2fb84e8d54f843cdfb0cc92149bcdfd8ab --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMonth/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmonth +es6id: 20.3.4.18 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCMonth = Date.prototype.getUTCMonth; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCMonth, 'function'); + +assert.throws(TypeError, function() { + getUTCMonth.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCMonth.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCMonth.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCMonth.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCMonth.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCMonth.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCMonth/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCMonth/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..20233307d4c7b2899aad59ac49594da6846ef550 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCMonth/this-value-valid-date.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcmonth +es6id: 20.3.4.18 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return MonthFromTime(t). +---*/ + +var july31 = 1469923200000; +var dec31 = 1483142400000; +var dayMs = 24 * 60 * 60 * 1000; + +assert.sameValue(new Date(july31).getUTCMonth(), 6, 'first millisecond'); +assert.sameValue( + new Date(july31 - 1).getUTCMonth(), 6, 'previous millisecond' +); +assert.sameValue( + new Date(july31 + dayMs - 1).getUTCMonth(), 6, 'final millisecond' +); +assert.sameValue( + new Date(july31 + dayMs).getUTCMonth(), 7, 'subsequent millisecond' +); + +assert.sameValue( + new Date(dec31).getUTCMonth(), 11, 'first millisecond (year boundary)' +); +assert.sameValue( + new Date(dec31 - 1).getUTCMonth(), 11, 'previous millisecond (year boundary)' +); +assert.sameValue( + new Date(dec31 + dayMs - 1).getUTCMonth(), + 11, + 'final millisecond (year boundary)' +); +assert.sameValue( + new Date(dec31 + dayMs).getUTCMonth(), + 0, + 'subsequent millisecond (year boundary)' +); diff --git a/test/built-ins/Date/prototype/getUTCSeconds/this-value-invalid-date.js b/test/built-ins/Date/prototype/getUTCSeconds/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..1dc7952165ad4d5c701f96977ae3c5ea755bcce3 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCSeconds/this-value-invalid-date.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcseconds +es6id: 20.3.4.19 +description: Return value for invalid date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. +---*/ + +assert.sameValue(new Date(NaN).getUTCSeconds(), NaN); diff --git a/test/built-ins/Date/prototype/getUTCSeconds/this-value-non-date.js b/test/built-ins/Date/prototype/getUTCSeconds/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..0b4fc5f08b86a5082b96b86593fda5f92dc97115 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCSeconds/this-value-non-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcseconds +es6id: 20.3.4.19 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var getUTCSeconds = Date.prototype.getUTCSeconds; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof getUTCSeconds, 'function'); + +assert.throws(TypeError, function() { + getUTCSeconds.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + getUTCSeconds.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + getUTCSeconds.call(args); +}, 'arguments exotic object'); diff --git a/test/built-ins/Date/prototype/getUTCSeconds/this-value-non-object.js b/test/built-ins/Date/prototype/getUTCSeconds/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..6f9e979f7cd1bfed11d7e7bccb260dece0bfdcd3 --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCSeconds/this-value-non-object.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcseconds +es6id: 20.3.4.19 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var getUTCSeconds = Date.prototype.getUTCSeconds; +var symbol = Symbol(); + +assert.sameValue(typeof getUTCSeconds, 'function'); + +assert.throws(TypeError, function() { + getUTCSeconds.call(0); +}, 'number'); + +assert.throws(TypeError, function() { + getUTCSeconds.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + getUTCSeconds.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + getUTCSeconds.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + getUTCSeconds.call(''); +}, 'string'); + +assert.throws(TypeError, function() { + getUTCSeconds.call(symbol); +}, 'symbol'); diff --git a/test/built-ins/Date/prototype/getUTCSeconds/this-value-valid-date.js b/test/built-ins/Date/prototype/getUTCSeconds/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..689d38cdba5772c4d8e8ae28335a8be6fb971afc --- /dev/null +++ b/test/built-ins/Date/prototype/getUTCSeconds/this-value-valid-date.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.getutcseconds +es6id: 20.3.4.19 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, return NaN. + 3. Return SecFromTime(t). +---*/ + +var sec34 = 1467819394000; +var sec59 = 1467819419000; + +assert.sameValue(new Date(sec34).getUTCSeconds(), 34, 'first millisecond'); +assert.sameValue( + new Date(sec34 - 1).getUTCSeconds(), 33, 'previous millisecond' +); +assert.sameValue( + new Date(sec34 + 999).getUTCSeconds(), 34, 'final millisecond' +); +assert.sameValue( + new Date(sec34 + 1000).getUTCSeconds(), 35, 'subsequent millisecond' +); + +assert.sameValue( + new Date(sec59).getUTCSeconds(), 59, 'first millisecond (minute boundary)' +); +assert.sameValue( + new Date(sec59 - 1).getUTCSeconds(), + 58, + 'previous millisecond (minute boundary)' +); +assert.sameValue( + new Date(sec59 + 99).getUTCSeconds(), + 59, + 'final millisecond (minute boundary)' +); +assert.sameValue( + new Date(sec59 + 1000).getUTCSeconds(), + 0, + 'subsequent millisecond (minute boundary)' +); diff --git a/test/built-ins/Date/prototype/setDate/arg-to-number-err.js b/test/built-ins/Date/prototype/setDate/arg-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..265610fdde0bce3b60578d4ce85cf681643dc2bc --- /dev/null +++ b/test/built-ins/Date/prototype/setDate/arg-to-number-err.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setdate +es6id: 20.3.4.20 +description: Abrupt completion during type coercion of provided argument +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setDate(obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setDate/arg-to-number.js b/test/built-ins/Date/prototype/setDate/arg-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..188da1d17d1bd5fcbe4ad941016dbcca2402c35c --- /dev/null +++ b/test/built-ins/Date/prototype/setDate/arg-to-number.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setdate +es6id: 20.3.4.20 +description: Type coercion of provided argument +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setDate(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, new Date(2016, 6, 2).getTime(), 'application of specified value' +); + +returnValue = date.setDate(null); + +assert.sameValue(returnValue, new Date(2016, 5, 30).getTime(), 'null'); + +returnValue = date.setDate(true); + +assert.sameValue(returnValue, new Date(2016, 5, 1).getTime(), 'true'); + +returnValue = date.setDate(false); + +assert.sameValue(returnValue, new Date(2016, 4, 31).getTime(), 'false'); + +returnValue = date.setDate(' +00200.000E-0002 '); + +assert.sameValue(returnValue, new Date(2016, 4, 2).getTime(), 'string'); + +returnValue = date.setDate(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setDate/new-value-time-clip.js b/test/built-ins/Date/prototype/setDate/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..ad9683617f7f1dc7c9fcffe0b2ad14af4be4346c --- /dev/null +++ b/test/built-ins/Date/prototype/setDate/new-value-time-clip.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setdate +es6id: 20.3.4.20 +description: Behavior when new value exceeds [[DateValue]] limits +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var date = new Date(8.64e15); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setDate(28); + +assert.sameValue(returnValue, NaN); diff --git a/test/built-ins/Date/prototype/setDate/this-value-invalid-date.js b/test/built-ins/Date/prototype/setDate/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..1537d97ccded4b5424bd41f777add312334776e9 --- /dev/null +++ b/test/built-ins/Date/prototype/setDate/this-value-invalid-date.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setdate +es6id: 20.3.4.20 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. +---*/ + +var date = new Date(NaN); +var result; + +result = date.setDate(0); + +assert.sameValue(result, NaN, 'return value'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot'); diff --git a/test/built-ins/Date/prototype/setDate/this-value-non-date.js b/test/built-ins/Date/prototype/setDate/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..8cfe106312b96a2b4a272f25f4bd2b3ba92e1a36 --- /dev/null +++ b/test/built-ins/Date/prototype/setDate/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setdate +es6id: 20.3.4.20 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setDate = Date.prototype.setDate; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setDate, 'function'); + +assert.throws(TypeError, function() { + setDate.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setDate.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setDate.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setDate/this-value-non-object.js b/test/built-ins/Date/prototype/setDate/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..3c0c823ddf164ca0e581cddadb2fb208a2216583 --- /dev/null +++ b/test/built-ins/Date/prototype/setDate/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setdate +es6id: 20.3.4.20 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setDate = Date.prototype.setDate; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setDate, 'function'); + +assert.throws(TypeError, function() { + setDate.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setDate.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setDate.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setDate.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setDate.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setDate.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setDate/this-value-valid-date.js b/test/built-ins/Date/prototype/setDate/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..8d368a2dfde62de1fd8aa164c83675884dcf4930 --- /dev/null +++ b/test/built-ins/Date/prototype/setDate/this-value-valid-date.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setdate +es6id: 20.3.4.20 +description: Return value for valid dates +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setDate(6); + +expected = new Date(2016, 6, 6).getTime(); +assert.sameValue( + returnValue, expected, 'within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setDate(0); + +expected = new Date(2016, 5, 30).getTime(); +assert.sameValue( + returnValue, expected, 'before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setDate(31); + +expected = new Date(2016, 6, 1).getTime(); +assert.sameValue( + returnValue, expected, 'after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setFullYear/arg-date-to-number-err.js b/test/built-ins/Date/prototype/setFullYear/arg-date-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..12a7953bc97d93293da476f10afeddea81b3347a --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/arg-date-to-number-err.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Abrupt completion during type coercion of provided "date" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setFullYear(0, 0, obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setFullYear/arg-date-to-number.js b/test/built-ins/Date/prototype/setFullYear/arg-date-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..40907bf5b9eda14dac3ad63473c8b0d3f7936d5b --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/arg-date-to-number.js @@ -0,0 +1,78 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Type coercion of provided "date" +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6, 7, 11, 36, 23, 2); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setFullYear(2016, 6, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 2, 11, 36, 23, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setFullYear(2016, 6, null); + +assert.sameValue( + returnValue, + new Date(2016, 6, 0, 11, 36, 23, 2).getTime(), + 'null' +); + +returnValue = date.setFullYear(2016, 6, true); + +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 11, 36, 23, 2).getTime(), + 'true' +); + +returnValue = date.setFullYear(2016, 6, false); + +assert.sameValue( + returnValue, + new Date(2016, 6, 0, 11, 36, 23, 2).getTime(), + 'false' +); + +returnValue = date.setFullYear(2016, 6, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, + new Date(2016, 6, 2, 11, 36, 23, 2).getTime(), + 'string' +); + +returnValue = date.setFullYear(2016, 6, undefined); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setFullYear/arg-month-to-number-err.js b/test/built-ins/Date/prototype/setFullYear/arg-month-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..e5fa11927828193a60a8fe8370b04adc8242605a --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/arg-month-to-number-err.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Abrupt completion during type coercion of provided "month" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setFullYear(0, obj, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setFullYear/arg-month-to-number.js b/test/built-ins/Date/prototype/setFullYear/arg-month-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..ff4cdc30778d8ea28a2ae8cafbdc02f8179012fa --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/arg-month-to-number.js @@ -0,0 +1,78 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Type coercion of provided "month" +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6, 7, 11, 36, 23, 2); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setFullYear(2016, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 2, 7, 11, 36, 23, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setFullYear(2016, null); + +assert.sameValue( + returnValue, + new Date(2016, 0, 7, 11, 36, 23, 2).getTime(), + 'null' +); + +returnValue = date.setFullYear(2016, true); + +assert.sameValue( + returnValue, + new Date(2016, 1, 7, 11, 36, 23, 2).getTime(), + 'true' +); + +returnValue = date.setFullYear(2016, false); + +assert.sameValue( + returnValue, + new Date(2016, 0, 7, 11, 36, 23, 2).getTime(), + 'false' +); + +returnValue = date.setFullYear(2016, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, + new Date(2016, 2, 7, 11, 36, 23, 2).getTime(), + 'string' +); + +returnValue = date.setFullYear(2016, undefined); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setFullYear/arg-year-to-number-err.js b/test/built-ins/Date/prototype/setFullYear/arg-year-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..a9369c3fa418cc89931e9ff5e45d4b646dff8115 --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/arg-year-to-number-err.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Abrupt completion during type coercion of provided "year" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setFullYear(obj, counter, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setFullYear/arg-year-to-number.js b/test/built-ins/Date/prototype/setFullYear/arg-year-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..3fbb4fde63b2273f3cb86040ec863e21a564008e --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/arg-year-to-number.js @@ -0,0 +1,78 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Type coercion of provided "year" +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6, 7, 11, 36, 23, 2); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setFullYear(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(-1, 42, 7, 11, 36, 23, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setFullYear(null); + +assert.sameValue( + returnValue, + new Date(-1, 18, 7, 11, 36, 23, 2).getTime(), + 'null' +); + +returnValue = date.setFullYear(true); + +assert.sameValue( + returnValue, + new Date(-1, 30, 7, 11, 36, 23, 2).getTime(), + 'true' +); + +returnValue = date.setFullYear(false); + +assert.sameValue( + returnValue, + new Date(-1, 18, 7, 11, 36, 23, 2).getTime(), + 'false' +); + +returnValue = date.setFullYear(' +00200.000E-0002 '); + +assert.sameValue( + returnValue, + new Date(-1, 42, 7, 11, 36, 23, 2).getTime(), + 'string' +); + +returnValue = date.setFullYear(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setFullYear/new-value-time-clip.js b/test/built-ins/Date/prototype/setFullYear/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..83aa448f97fa20adce96f6a9bd282db23b53b43a --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/new-value-time-clip.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Behavior when new value exceeds [[DateValue]] limits +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var maxMs = 8.64e15; +var maxYear = 275760; +var maxDate = 12; +var maxMonth = 8; +var date = new Date(maxMs); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setFullYear(maxYear + 1); + +assert.sameValue(returnValue, NaN, 'overflow due to year'); + +date = new Date(maxMs); + +returnValue = date.setFullYear(maxYear, maxMonth + 1); + +assert.sameValue(returnValue, NaN, 'overflow due to month'); + +date = new Date(maxMs); + +returnValue = date.setFullYear(maxYear, maxMonth, maxDate + 1); + +assert.sameValue(returnValue, NaN, 'overflow due to date'); diff --git a/test/built-ins/Date/prototype/setFullYear/this-value-invalid-date.js b/test/built-ins/Date/prototype/setFullYear/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..cfa2f055e8c67fb05c3b17b84e087275d225c30f --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/this-value-invalid-date.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(NaN); +var expected, result; + +result = date.setFullYear(2016); + +expected = new Date(2016, 0).getTime(); +assert.sameValue(result, expected, 'return value (year)'); +assert.sameValue( + date.getTime(), expected, '[[DateValue]] internal slot (year)' +); + +date = new Date(NaN); + +result = date.setFullYear(2016, 6); + +expected = new Date(2016, 6).getTime(); +assert.sameValue(result, expected, 'return value (month)'); +assert.sameValue( + date.getTime(), expected, '[[DateValue]] internal slot (month)' +); + +date = new Date(NaN); + +result = date.setFullYear(2016, 6, 7); + +expected = new Date(2016, 6, 7).getTime(); +assert.sameValue(result, expected, 'return value (date)'); +assert.sameValue( + date.getTime(), expected, '[[DateValue]] internal slot (month)' +); diff --git a/test/built-ins/Date/prototype/setFullYear/this-value-non-date.js b/test/built-ins/Date/prototype/setFullYear/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..ece79ddc411e0c1a1b0d56e5dc949421e8617ec6 --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setFullYear = Date.prototype.setFullYear; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setFullYear, 'function'); + +assert.throws(TypeError, function() { + setFullYear.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setFullYear.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setFullYear.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setFullYear/this-value-non-object.js b/test/built-ins/Date/prototype/setFullYear/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..ebaa6d5d481c3369099c0c65fb779c1865817961 --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setFullYear = Date.prototype.setFullYear; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setFullYear, 'function'); + +assert.throws(TypeError, function() { + setFullYear.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setFullYear.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setFullYear.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setFullYear.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setFullYear.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setFullYear.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-date.js b/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-date.js new file mode 100644 index 0000000000000000000000000000000000000000..0e6e247f551852d8c0268cf87a0daaafe77ce550 --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-date.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Return value for valid dates (setting date) +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setFullYear(2016, 6, 6); + +expected = new Date(2016, 6, 6).getTime(); +assert.sameValue( + returnValue, expected, 'date within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'date within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setFullYear(2016, 6, 0); + +expected = new Date(2016, 5, 30).getTime(); +assert.sameValue( + returnValue, expected, 'date before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'date before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setFullYear(2016, 5, 31); + +expected = new Date(2016, 6, 1).getTime(); +assert.sameValue( + returnValue, expected, 'date after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'date after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-month.js b/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-month.js new file mode 100644 index 0000000000000000000000000000000000000000..f522b1f96ebdff97160c820b9a75f1134612ce56 --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-month.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Return value for valid dates (setting month) +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setFullYear(2016, 3); + +expected = new Date(2016, 3).getTime(); +assert.sameValue( + returnValue, expected, 'month within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'month within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setFullYear(2016, -1); + +expected = new Date(2015, 11).getTime(); +assert.sameValue( + returnValue, expected, 'month before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'month before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setFullYear(2016, 12); + +expected = new Date(2017, 0).getTime(); +assert.sameValue( + returnValue, expected, 'month after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'month after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-year.js b/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-year.js new file mode 100644 index 0000000000000000000000000000000000000000..cbd2e977f6827c35f4112233af13fb19928b763b --- /dev/null +++ b/test/built-ins/Date/prototype/setFullYear/this-value-valid-date-year.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setfullyear +es6id: 20.3.4.21 +description: Return value for valid dates (setting year) +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setFullYear(2015); + +expected = new Date(2015, 6).getTime(); +assert.sameValue(returnValue, expected, 'year (return value)'); +assert.sameValue(date.getTime(), expected, 'year ([[DateValue]] slot)'); diff --git a/test/built-ins/Date/prototype/setHours/arg-hour-to-number-err.js b/test/built-ins/Date/prototype/setHours/arg-hour-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..0ee38e978aadda46113ba4542c3e101fe5db934e --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-hour-to-number-err.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Abrupt completion during type coercion of provided "hour" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(hour). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setHours(obj, counter, counter, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setHours/arg-hour-to-number.js b/test/built-ins/Date/prototype/setHours/arg-hour-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..39ca58709daedd9042fcaceb2a41f8912d83c540 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-hour-to-number.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Type coercion of provided "hour" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setHours(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setHours(null); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0).getTime(), 'null'); + +returnValue = date.setHours(true); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 1).getTime(), 'true'); + +returnValue = date.setHours(false); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0).getTime(), 'false'); + +returnValue = date.setHours(' +00200.000E-0002 '); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 2).getTime(), 'string'); + +returnValue = date.setHours(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setHours/arg-min-to-number-err.js b/test/built-ins/Date/prototype/setHours/arg-min-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..209eb0b64b1cfd02f401bce0112f24b81ee19737 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-min-to-number-err.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Abrupt completion during type coercion of provided "min" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setHours(0, obj, counter, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setHours/arg-min-to-number.js b/test/built-ins/Date/prototype/setHours/arg-min-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..20e8310d18e9e38c4f69856f9e7703c5920d7e4c --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-min-to-number.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Type coercion of provided "min" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setHours(0, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setHours(0, null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setHours(0, true); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0, 1).getTime(), 'true'); + +returnValue = date.setHours(0, false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setHours(0, ' +00200.000E-0002 '); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0, 2).getTime(), 'string'); + +returnValue = date.setHours(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setHours/arg-ms-to-number-err.js b/test/built-ins/Date/prototype/setHours/arg-ms-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..f3017a3a270a7dfb6aa3d62dcd3f81b08c8b79ab --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-ms-to-number-err.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Abrupt completion during type coercion of provided "ms" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setHours(0, 0, 0, obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setHours/arg-ms-to-number.js b/test/built-ins/Date/prototype/setHours/arg-ms-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..6d2e10092fa5d46543922f55909b9150a8e214cd --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-ms-to-number.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Type coercion of provided "ms" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setHours(0, 0, 0, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 0, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setHours(0, 0, 0, null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setHours(0, 0, 0, true); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0, 1).getTime(), 'true' +); + +returnValue = date.setHours(0, 0, 0, false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setHours(0, 0, 0, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0, 2).getTime(), 'string' +); + +returnValue = date.setHours(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setHours/arg-sec-to-number-err.js b/test/built-ins/Date/prototype/setHours/arg-sec-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..04bc8c62988f3472573bc6796a161d7ee35e0de9 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-sec-to-number-err.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Abrupt completion during type coercion of provided "sec" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setHours(0, 0, obj, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setHours/arg-sec-to-number.js b/test/built-ins/Date/prototype/setHours/arg-sec-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..b528318eb97a61ac9b8d45c6323a42129f655a90 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/arg-sec-to-number.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Type coercion of provided "sec" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setHours(0, 0, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setHours(0, 0, null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setHours(0, 0, true); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0, 0, 1).getTime(), 'true'); + +returnValue = date.setHours(0, 0, false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setHours(0, 0, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 2).getTime(), 'string' +); + +returnValue = date.setHours(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setHours/new-value-time-clip.js b/test/built-ins/Date/prototype/setHours/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..54d11b14ce37e1269c21bfd269a5a97eab393078 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/new-value-time-clip.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Behavior when new value exceeds [[DateValue]] limits +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var maxMs = 8.64e15; +var date = new Date(maxMs); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setHours(24); + +assert.sameValue(returnValue, NaN, 'overflow due to hours'); + +date = new Date(maxMs); + +returnValue = date.setHours(0, 24 * 60); + +assert.sameValue(returnValue, NaN, 'overflow due to minutes'); + +date = new Date(maxMs); + +returnValue = date.setHours(0, 0, 24 * 60 * 60); + +assert.sameValue(returnValue, NaN, 'overflow due to seconds'); + +date = new Date(maxMs); + +returnValue = date.setHours(0, 0, 0, 24 * 60 * 60 * 1000); + +assert.sameValue(returnValue, NaN, 'overflow due to milliseconds'); diff --git a/test/built-ins/Date/prototype/setHours/this-value-invalid-date.js b/test/built-ins/Date/prototype/setHours/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..80f2b84f17aaed1e176e6b7cf32c806e42ec1973 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/this-value-invalid-date.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(NaN); +var result; + +result = date.setHours(0); + +assert.sameValue(result, NaN, 'return value (hour)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (hour)'); + +result = date.setHours(0, 0); + +assert.sameValue(result, NaN, 'return value (minute)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (minute)'); + +result = date.setHours(0, 0, 0); + +assert.sameValue(result, NaN, 'return value (second)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (second)'); + +result = date.setHours(0, 0, 0, 0); + +assert.sameValue(result, NaN, 'return value (ms)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (ms)'); diff --git a/test/built-ins/Date/prototype/setHours/this-value-non-date.js b/test/built-ins/Date/prototype/setHours/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..1f0c79bffb71c40e3cfc4735e19b11e603afe5c4 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setHours = Date.prototype.setHours; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setHours, 'function'); + +assert.throws(TypeError, function() { + setHours.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setHours.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setHours.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setHours/this-value-non-object.js b/test/built-ins/Date/prototype/setHours/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8def5bbb4ed1d49665fdee19b8beb6d5a7e7366b --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setHours = Date.prototype.setHours; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setHours, 'function'); + +assert.throws(TypeError, function() { + setHours.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setHours.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setHours.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setHours.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setHours.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setHours.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setHours/this-value-valid-date-hour.js b/test/built-ins/Date/prototype/setHours/this-value-valid-date-hour.js new file mode 100644 index 0000000000000000000000000000000000000000..75dbd62a1adc090c89d84f159dc14e7cc2df400f --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/this-value-valid-date-hour.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Return value for valid dates (setting hour) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setHours(6); + +expected = new Date(2016, 6, 1, 6).getTime(); +assert.sameValue( + returnValue, expected, 'hour within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'hour within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(-1); + +expected = new Date(2016, 5, 30, 23).getTime(); +assert.sameValue( + returnValue, expected, 'hour before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'hour before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(24); + +expected = new Date(2016, 6, 1).getTime(); +assert.sameValue( + returnValue, expected, 'hour after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'hour after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setHours/this-value-valid-date-min.js b/test/built-ins/Date/prototype/setHours/this-value-valid-date-min.js new file mode 100644 index 0000000000000000000000000000000000000000..b021ee6313a2baf38f2a964c0964e850a35d3eb4 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/this-value-valid-date-min.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Return value for valid dates (setting min) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setHours(0, 23); + +expected = new Date(2016, 6, 1, 0, 23).getTime(); +assert.sameValue( + returnValue, expected, 'minute within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'minute within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(0, -1); + +expected = new Date(2016, 5, 30, 23, 59).getTime(); +assert.sameValue( + returnValue, expected, 'minute before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'minute before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(0, 60); + +expected = new Date(2016, 5, 30, 1).getTime(); +assert.sameValue( + returnValue, expected, 'minute after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'minute after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setHours/this-value-valid-date-ms.js b/test/built-ins/Date/prototype/setHours/this-value-valid-date-ms.js new file mode 100644 index 0000000000000000000000000000000000000000..6d48682fc3a31a114ae656f1d3a0cb06d5b5e69b --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/this-value-valid-date-ms.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Return value for valid dates (setting ms) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setHours(0, 0, 0, 543); + +expected = new Date(2016, 6, 1, 0, 0, 0, 543).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(0, 0, 0, -1); + +expected = new Date(2016, 5, 30, 23, 59, 59, 999).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(0, 0, 0, 1000); + +expected = new Date(2016, 5, 30, 0, 0, 1).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setHours/this-value-valid-date-sec.js b/test/built-ins/Date/prototype/setHours/this-value-valid-date-sec.js new file mode 100644 index 0000000000000000000000000000000000000000..63f80846d6cfcf804ab041049bf208ac692b9246 --- /dev/null +++ b/test/built-ins/Date/prototype/setHours/this-value-valid-date-sec.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.sethours +es6id: 20.3.4.22 +description: Return value for valid dates (setting sec) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setHours(0, 0, 45); + +expected = new Date(2016, 6, 1, 0, 0, 45).getTime(); +assert.sameValue( + returnValue, expected, 'second within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'second within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(0, 0, -1); + +expected = new Date(2016, 5, 30, 23, 59, 59).getTime(); +assert.sameValue( + returnValue, expected, 'second before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'second before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setHours(0, 0, 60); + +expected = new Date(2016, 5, 30, 0, 1).getTime(); +assert.sameValue( + returnValue, expected, 'second after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'second after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setMilliseconds/arg-to-number-err.js b/test/built-ins/Date/prototype/setMilliseconds/arg-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..e5ef61a411f69c6ea9738552a29083122bc26632 --- /dev/null +++ b/test/built-ins/Date/prototype/setMilliseconds/arg-to-number-err.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmilliseconds +es6id: 20.3.4.23 +description: Abrupt completion during type coercion of provided argument +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setMilliseconds(obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setMilliseconds/arg-to-number.js b/test/built-ins/Date/prototype/setMilliseconds/arg-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..4ec16e58973e86a64e61110d9435d0e0561f544c --- /dev/null +++ b/test/built-ins/Date/prototype/setMilliseconds/arg-to-number.js @@ -0,0 +1,62 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmilliseconds +es6id: 20.3.4.23 +description: Type coercion of provided argument +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setMilliseconds(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 0, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setMilliseconds(null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setMilliseconds(true); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0, 1).getTime(), 'true' +); + +returnValue = date.setMilliseconds(false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setMilliseconds(' +00200.000E-0002 '); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0 , 2).getTime(), 'string' +); + +returnValue = date.setMilliseconds(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setMilliseconds/new-value-time-clip.js b/test/built-ins/Date/prototype/setMilliseconds/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..5a0b9e0bb6c4aeaae0755964761a9d6c4f0d8f43 --- /dev/null +++ b/test/built-ins/Date/prototype/setMilliseconds/new-value-time-clip.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmilliseconds +es6id: 20.3.4.23 +description: Behavior when new value exceeds [[DateValue]] limits +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var date = new Date(8.64e15); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setMilliseconds(1); + +assert.sameValue(returnValue, NaN); diff --git a/test/built-ins/Date/prototype/setMilliseconds/this-value-invalid-date.js b/test/built-ins/Date/prototype/setMilliseconds/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..bd3245798e78434f02d418d391e98d9d44674c50 --- /dev/null +++ b/test/built-ins/Date/prototype/setMilliseconds/this-value-invalid-date.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmilliseconds +es6id: 20.3.4.23 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. +---*/ + +var date = new Date(NaN); +var result; + +result = date.setMilliseconds(0); + +assert.sameValue(result, NaN, 'return value'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot'); diff --git a/test/built-ins/Date/prototype/setMilliseconds/this-value-non-date.js b/test/built-ins/Date/prototype/setMilliseconds/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..df836da906e5dc45aaa9e7a3d945ab9f5a81e4b3 --- /dev/null +++ b/test/built-ins/Date/prototype/setMilliseconds/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmilliseconds +es6id: 20.3.4.23 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setMilliseconds = Date.prototype.setMilliseconds; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setMilliseconds, 'function'); + +assert.throws(TypeError, function() { + setMilliseconds.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setMilliseconds.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setMilliseconds.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setMilliseconds/this-value-non-object.js b/test/built-ins/Date/prototype/setMilliseconds/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c5045e22c1e4aa7a6332a3366bbd07761509ee90 --- /dev/null +++ b/test/built-ins/Date/prototype/setMilliseconds/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmilliseconds +es6id: 20.3.4.23 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setMilliseconds = Date.prototype.setMilliseconds; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setMilliseconds, 'function'); + +assert.throws(TypeError, function() { + setMilliseconds.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setMilliseconds.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setMilliseconds.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setMilliseconds.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setMilliseconds.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setMilliseconds.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setMilliseconds/this-value-valid-date.js b/test/built-ins/Date/prototype/setMilliseconds/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..95714f3afbff5cd5680ba23352c9ae553d89e8c8 --- /dev/null +++ b/test/built-ins/Date/prototype/setMilliseconds/this-value-valid-date.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmilliseconds +es6id: 20.3.4.23 +description: Return value for valid dates +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setMilliseconds(333); + +expected = new Date(2016, 6, 1, 0, 0, 0, 333).getTime(); +assert.sameValue( + returnValue, expected, 'within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMilliseconds(-1); + +expected = new Date(2016, 5, 30, 23, 59, 59, 999).getTime(); +assert.sameValue( + returnValue, expected, 'before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMilliseconds(1000); + +expected = new Date(2016, 6, 1).getTime(); +assert.sameValue( + returnValue, expected, 'after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setMinutes/arg-min-to-number-err.js b/test/built-ins/Date/prototype/setMinutes/arg-min-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..01adc5f6e48b9b04148bb2ef909a5e515ee5419c --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/arg-min-to-number-err.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Abrupt completion during type coercion of provided "min" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(min). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setMinutes(obj, counter, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setMinutes/arg-min-to-number.js b/test/built-ins/Date/prototype/setMinutes/arg-min-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..04c4e12b327908d811b686316eba00277c294db1 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/arg-min-to-number.js @@ -0,0 +1,61 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Type coercion of provided "min" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(min). + 3. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 4. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 5. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)). + 6. Let u be TimeClip(UTC(date)). + 7. Set the [[DateValue]] internal slot of this Date object to u. + 8. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setMinutes(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setMinutes(null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setMinutes(true); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0, 1).getTime(), 'true'); + +returnValue = date.setMinutes(false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setMinutes(' +00200.000E-0002 '); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0, 2).getTime(), 'string'); + +returnValue = date.setMinutes(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setMinutes/arg-ms-to-number-err.js b/test/built-ins/Date/prototype/setMinutes/arg-ms-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..d2eb4582b5aa85549240762de6b728d75b5c0183 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/arg-ms-to-number-err.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Abrupt completion during type coercion of provided "ms" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(min). + 3. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 4. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setMinutes(0, 0, obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setMinutes/arg-ms-to-number.js b/test/built-ins/Date/prototype/setMinutes/arg-ms-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..b3eefdd307b41e7e70a885916944eeef08a1dee6 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/arg-ms-to-number.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Type coercion of provided "ms" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(min). + 3. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 4. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 5. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)). + 6. Let u be TimeClip(UTC(date)). + 7. Set the [[DateValue]] internal slot of this Date object to u. + 8. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setMinutes(0, 0, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 0, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setMinutes(0, 0, null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setMinutes(0, 0, true); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0, 1).getTime(), 'true' +); + +returnValue = date.setMinutes(0, 0, false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setMinutes(0, 0, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0, 2).getTime(), 'string' +); + +returnValue = date.setMinutes(0, 0, undefined); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setMinutes/arg-sec-to-number-err.js b/test/built-ins/Date/prototype/setMinutes/arg-sec-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..a5d2d6ef6a42498af0f2cf7523d645dc696880bb --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/arg-sec-to-number-err.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Abrupt completion during type coercion of provided "sec" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(min). + 3. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setMinutes(0, 0, obj, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setMinutes/arg-sec-to-number.js b/test/built-ins/Date/prototype/setMinutes/arg-sec-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..755a787f17432dafae5a2fe0a8eed682af13db20 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/arg-sec-to-number.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Type coercion of provided "sec" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(min). + 3. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 4. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 5. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)). + 6. Let u be TimeClip(UTC(date)). + 7. Set the [[DateValue]] internal slot of this Date object to u. + 8. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setMinutes(0, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setMinutes(0, null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setMinutes(0, true); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0, 0, 1).getTime(), 'true'); + +returnValue = date.setMinutes(0, false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setMinutes(0, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 2).getTime(), 'string' +); + +returnValue = date.setMinutes(0, undefined); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setMinutes/new-value-time-clip.js b/test/built-ins/Date/prototype/setMinutes/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..9d9af7b9ad43027201fe966586440bcb69588712 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/new-value-time-clip.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Behavior when new value exceeds [[DateValue]] limits +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(min). + 3. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 4. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 5. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)). + 6. Let u be TimeClip(UTC(date)). + 7. Set the [[DateValue]] internal slot of this Date object to u. + 8. Return u. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var maxMs = 8.64e15; +var date = new Date(maxMs); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setMinutes(24 * 60); + +assert.sameValue(returnValue, NaN, 'overflow due to minutes'); + +date = new Date(maxMs); + +returnValue = date.setMinutes(0, 24 * 60 * 60); + +assert.sameValue(returnValue, NaN, 'overflow due to seconds'); + +date = new Date(maxMs); + +returnValue = date.setMinutes(0, 0, 24 * 60 * 60 * 1000); + +assert.sameValue(returnValue, NaN, 'overflow due to milliseconds'); diff --git a/test/built-ins/Date/prototype/setMinutes/this-value-invalid-date.js b/test/built-ins/Date/prototype/setMinutes/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..8ab883f701e7d09f1e2a74db74bfc1c9c42e6108 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/this-value-invalid-date.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let h be ? ToNumber(hour). + 3. If min is not specified, let m be MinFromTime(t); otherwise, let m be ? + ToNumber(min). + 4. If sec is not specified, let s be SecFromTime(t); otherwise, let s be ? + ToNumber(sec). + 5. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 6. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)). + 7. Let u be TimeClip(UTC(date)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(NaN); +var result; + +result = date.setMinutes(0); + +assert.sameValue(result, NaN, 'return value (hour)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (hour)'); + +result = date.setMinutes(0, 0); + +assert.sameValue(result, NaN, 'return value (minute)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (minute)'); + +result = date.setMinutes(0, 0, 0); + +assert.sameValue(result, NaN, 'return value (second)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (second)'); + +result = date.setMinutes(0, 0, 0, 0); + +assert.sameValue(result, NaN, 'return value (ms)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (ms)'); diff --git a/test/built-ins/Date/prototype/setMinutes/this-value-non-date.js b/test/built-ins/Date/prototype/setMinutes/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..dfb851f0938d3214b30ff33112f94d5e487a550b --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setMinutes = Date.prototype.setMinutes; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setMinutes, 'function'); + +assert.throws(TypeError, function() { + setMinutes.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setMinutes.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setMinutes.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setMinutes/this-value-non-object.js b/test/built-ins/Date/prototype/setMinutes/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..b4c66ced78b620ab8342f342fe94ffb803e7a894 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setMinutes = Date.prototype.setMinutes; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setMinutes, 'function'); + +assert.throws(TypeError, function() { + setMinutes.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setMinutes.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setMinutes.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setMinutes.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setMinutes.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setMinutes.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setMinutes/this-value-valid-date.js b/test/built-ins/Date/prototype/setMinutes/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..22f3c4a2773c6fb8574b682dfcf315a5236da289 --- /dev/null +++ b/test/built-ins/Date/prototype/setMinutes/this-value-valid-date.js @@ -0,0 +1,130 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setminutes +es6id: 20.3.4.24 +description: Return value for valid dates +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6, 1); +var returnValue, expected; + +returnValue = date.setMinutes(23); + +expected = new Date(2016, 6, 1, 0, 23).getTime(); +assert.sameValue( + returnValue, expected, 'minute within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'minute within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMinutes(-1); + +expected = new Date(2016, 5, 30, 23, 59).getTime(); +assert.sameValue( + returnValue, expected, 'minute before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'minute before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMinutes(60); + +expected = new Date(2016, 6, 1).getTime(); +assert.sameValue( + returnValue, expected, 'minute after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'minute after time unit boundary ([[DateValue]] slot)' +); + +date = new Date(2016, 6, 1); + +returnValue = date.setMinutes(0, 45); + +expected = new Date(2016, 6, 1, 0, 0, 45).getTime(); +assert.sameValue( + returnValue, expected, 'second within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'second within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMinutes(0, -1); + +expected = new Date(2016, 5, 30, 23, 59, 59).getTime(); +assert.sameValue( + returnValue, expected, 'second before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'second before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMinutes(0, 60); + +expected = new Date(2016, 5, 30, 23, 1).getTime(); +assert.sameValue( + returnValue, expected, 'second after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'second after time unit boundary ([[DateValue]] slot)' +); + +date = new Date(2016, 6, 1); + +returnValue = date.setMinutes(0, 0, 345); + +expected = new Date(2016, 6, 1, 0, 0, 0, 345).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMinutes(0, 0, -1); + +expected = new Date(2016, 5, 30, 23, 59, 59, 999).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMinutes(0, 0, 1000); + +expected = new Date(2016, 5, 30, 23, 0, 1).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setMonth/arg-date-to-number-err.js b/test/built-ins/Date/prototype/setMonth/arg-date-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..8b6d591d0b7a45243cfbed700e867c292002204e --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/arg-date-to-number-err.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Abrupt completion during type coercion of provided "date" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(month). + 3. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setMonth(0, obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setMonth/arg-date-to-number.js b/test/built-ins/Date/prototype/setMonth/arg-date-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..8f9477132a79767da8090a075d091eb42caa266c --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/arg-date-to-number.js @@ -0,0 +1,76 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Type coercion of provided "date" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(month). + 3. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 4. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), + TimeWithinDay(t)). + 5. Let u be TimeClip(UTC(newDate)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(2016, 6, 7, 11, 36, 23, 2); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setMonth(6, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 2, 11, 36, 23, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setMonth(6, null); + +assert.sameValue( + returnValue, + new Date(2016, 6, 0, 11, 36, 23, 2).getTime(), + 'null' +); + +returnValue = date.setMonth(6, true); + +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 11, 36, 23, 2).getTime(), + 'true' +); + +returnValue = date.setMonth(6, false); + +assert.sameValue( + returnValue, + new Date(2016, 6, 0, 11, 36, 23, 2).getTime(), + 'false' +); + +returnValue = date.setMonth(6, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, + new Date(2016, 6, 2, 11, 36, 23, 2).getTime(), + 'string' +); + +returnValue = date.setMonth(6, undefined); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setMonth/arg-month-to-number-err.js b/test/built-ins/Date/prototype/setMonth/arg-month-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..20762fe2f829278602755481afd71c90bb4626e0 --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/arg-month-to-number-err.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Abrupt completion during type coercion of provided "month" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setMonth(obj, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setMonth/arg-month-to-number.js b/test/built-ins/Date/prototype/setMonth/arg-month-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..971803ac198200379439a1102fd9d4ef4b471119 --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/arg-month-to-number.js @@ -0,0 +1,78 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Type coercion of provided "month" +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. +---*/ + +var date = new Date(2016, 6, 7, 11, 36, 23, 2); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setMonth(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 2, 7, 11, 36, 23, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setMonth(null); + +assert.sameValue( + returnValue, + new Date(2016, 0, 7, 11, 36, 23, 2).getTime(), + 'null' +); + +returnValue = date.setMonth(true); + +assert.sameValue( + returnValue, + new Date(2016, 1, 7, 11, 36, 23, 2).getTime(), + 'true' +); + +returnValue = date.setMonth(false); + +assert.sameValue( + returnValue, + new Date(2016, 0, 7, 11, 36, 23, 2).getTime(), + 'false' +); + +returnValue = date.setMonth(' +00200.000E-0002 '); + +assert.sameValue( + returnValue, + new Date(2016, 2, 7, 11, 36, 23, 2).getTime(), + 'string' +); + +returnValue = date.setMonth(undefined); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setMonth/new-value-time-clip.js b/test/built-ins/Date/prototype/setMonth/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..71e850544cf9bd8be11f9426b962cbd6256bdf15 --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/new-value-time-clip.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Behavior when new value exceeds [[DateValue]] limits +info: | + 1. Let t be ? thisTimeValue(this value). + 2. If t is NaN, let t be +0; otherwise, let t be LocalTime(t). + 3. Let y be ? ToNumber(year). + 4. If month is not specified, let m be MonthFromTime(t); otherwise, let m be + ? ToNumber(month). + 5. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 6. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)). + 7. Let u be TimeClip(UTC(newDate)). + 8. Set the [[DateValue]] internal slot of this Date object to u. + 9. Return u. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var maxMs = 8.64e15; +var maxDate = 12; +var maxMonth = 8; +var date = new Date(maxMs); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setMonth(maxMonth + 1); + +assert.sameValue(returnValue, NaN, 'overflow due to month'); + +date = new Date(maxMs); + +returnValue = date.setMonth(maxMonth, maxDate + 1); + +assert.sameValue(returnValue, NaN, 'overflow due to date'); diff --git a/test/built-ins/Date/prototype/setMonth/this-value-invalid-date.js b/test/built-ins/Date/prototype/setMonth/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..bb3783aab88ad60679eec7449a9b8a3ecf37c53d --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/this-value-invalid-date.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(month). + 3. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 4. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), + TimeWithinDay(t)). + 5. Let u be TimeClip(UTC(newDate)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(NaN); +var result; + +result = date.setMonth(6); + +assert.sameValue(result, NaN, 'return value (month)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (month)'); + +date = new Date(NaN); + +result = date.setMonth(6, 7); + +assert.sameValue(result, NaN, 'return value (date)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (month)'); diff --git a/test/built-ins/Date/prototype/setMonth/this-value-non-date.js b/test/built-ins/Date/prototype/setMonth/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..2828944675cfe9281a7690935aab82152776af04 --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setMonth = Date.prototype.setMonth; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setMonth, 'function'); + +assert.throws(TypeError, function() { + setMonth.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setMonth.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setMonth.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setMonth/this-value-non-object.js b/test/built-ins/Date/prototype/setMonth/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..cf2c20268a3398e66bedf9908797e1fe79a5c313 --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be ? thisTimeValue(this value). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setMonth = Date.prototype.setMonth; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setMonth, 'function'); + +assert.throws(TypeError, function() { + setMonth.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setMonth.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setMonth.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setMonth.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setMonth.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setMonth.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setMonth/this-value-valid-date-date.js b/test/built-ins/Date/prototype/setMonth/this-value-valid-date-date.js new file mode 100644 index 0000000000000000000000000000000000000000..2a6a1c5781c01a20f87ac650fb79dd1a6d3ea83a --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/this-value-valid-date-date.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Return value for valid dates (setting date) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(month). + 3. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 4. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), + TimeWithinDay(t)). + 5. Let u be TimeClip(UTC(newDate)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setMonth(6, 6); + +expected = new Date(2016, 6, 6).getTime(); +assert.sameValue( + returnValue, expected, 'date within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'date within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMonth(6, 0); + +expected = new Date(2016, 5, 30).getTime(); +assert.sameValue( + returnValue, expected, 'date before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'date before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMonth(5, 31); + +expected = new Date(2016, 6, 1).getTime(); +assert.sameValue( + returnValue, expected, 'date after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'date after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setMonth/this-value-valid-date-month.js b/test/built-ins/Date/prototype/setMonth/this-value-valid-date-month.js new file mode 100644 index 0000000000000000000000000000000000000000..b2084952ce985193b2eafdcaba4fa3adc266d077 --- /dev/null +++ b/test/built-ins/Date/prototype/setMonth/this-value-valid-date-month.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setmonth +es6id: 20.3.4.25 +description: Return value for valid dates (setting month) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let m be ? ToNumber(month). + 3. If date is not specified, let dt be DateFromTime(t); otherwise, let dt be + ? ToNumber(date). + 4. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), + TimeWithinDay(t)). + 5. Let u be TimeClip(UTC(newDate)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setMonth(3); + +expected = new Date(2016, 3).getTime(); +assert.sameValue( + returnValue, expected, 'month within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'month within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMonth(-1); + +expected = new Date(2015, 11).getTime(); +assert.sameValue( + returnValue, expected, 'month before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'month before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setMonth(12); + +expected = new Date(2016, 0).getTime(); +assert.sameValue( + returnValue, expected, 'month after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'month after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setSeconds/arg-ms-to-number-err.js b/test/built-ins/Date/prototype/setSeconds/arg-ms-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..ee86d2dd91614a66cf99e080260c6e0bfa85d679 --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/arg-ms-to-number-err.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Abrupt completion during type coercion of provided "ms" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). + 3. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setSeconds(0, obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setSeconds/arg-ms-to-number.js b/test/built-ins/Date/prototype/setSeconds/arg-ms-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..5b9afa06fd5895351d744182eaa34739e0b2b2dd --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/arg-ms-to-number.js @@ -0,0 +1,64 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Type coercion of provided "ms" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). + 3. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 4. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, + milli)). + 5. Let u be TimeClip(UTC(date)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setSeconds(0, arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 0, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setSeconds(0, null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setSeconds(0, true); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0, 1).getTime(), 'true' +); + +returnValue = date.setSeconds(0, false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setSeconds(0, ' +00200.000E-0002 '); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 0, 2).getTime(), 'string' +); + +returnValue = date.setSeconds(0, undefined); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setSeconds/arg-sec-to-number-err.js b/test/built-ins/Date/prototype/setSeconds/arg-sec-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..d3df83fea9b9235bab1981ea7992bf68449fcd6f --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/arg-sec-to-number-err.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Abrupt completion during type coercion of provided "sec" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). +---*/ + +var date = new Date(); +var callCount = 0; +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; +var counter = { + valueOf: function() { + callCount += 1; + } +}; + +assert.throws(Test262Error, function() { + date.setSeconds(obj, counter); +}); + +assert.sameValue(date.getTime(), originalValue); +assert.sameValue(callCount, 0); diff --git a/test/built-ins/Date/prototype/setSeconds/arg-sec-to-number.js b/test/built-ins/Date/prototype/setSeconds/arg-sec-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..37f86dc1264d7d740294e5850cedfe4ff553ce2e --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/arg-sec-to-number.js @@ -0,0 +1,62 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Type coercion of provided "sec" +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). + 3. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 4. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, + milli)). + 5. Let u be TimeClip(UTC(date)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setSeconds(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue( + returnValue, + new Date(2016, 6, 1, 0, 0, 2).getTime(), + 'application of specified value' +); + +returnValue = date.setSeconds(null); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'null'); + +returnValue = date.setSeconds(true); + +assert.sameValue(returnValue, new Date(2016, 6, 1, 0, 0, 1).getTime(), 'true'); + +returnValue = date.setSeconds(false); + +assert.sameValue(returnValue, new Date(2016, 6, 1).getTime(), 'false'); + +returnValue = date.setSeconds(' +00200.000E-0002 '); + +assert.sameValue( + returnValue, new Date(2016, 6, 1, 0, 0, 2).getTime(), 'string' +); + +returnValue = date.setSeconds(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setSeconds/new-value-time-clip.js b/test/built-ins/Date/prototype/setSeconds/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..737045bd76e502be7a7303a3fa687f81733c3290 --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/new-value-time-clip.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Behavior when new value exceeds [[DateValue]] limits +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). + 3. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 4. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, + milli)). + 5. Let u be TimeClip(UTC(date)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var maxMs = 8.64e15; +var date = new Date(maxMs); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setSeconds(24 * 60 * 60); + +assert.sameValue(returnValue, NaN, 'overflow due to seconds'); + +date = new Date(maxMs); + +returnValue = date.setSeconds(0, 24 * 60 * 60 * 1000); + +assert.sameValue(returnValue, NaN, 'overflow due to milliseconds'); diff --git a/test/built-ins/Date/prototype/setSeconds/this-value-invalid-date.js b/test/built-ins/Date/prototype/setSeconds/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..fe0061beddb8afead816685f4edf2484c2a7b33e --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/this-value-invalid-date.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). + 3. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 4. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, + milli)). + 5. Let u be TimeClip(UTC(date)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(NaN); +var result; + +result = date.setSeconds(0); + +assert.sameValue(result, NaN, 'return value (second)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (second)'); + +result = date.setSeconds(0, 0); + +assert.sameValue(result, NaN, 'return value (ms)'); +assert.sameValue(date.getTime(), NaN, '[[DateValue]] internal slot (ms)'); diff --git a/test/built-ins/Date/prototype/setSeconds/this-value-non-date.js b/test/built-ins/Date/prototype/setSeconds/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..23821c06a822aa9be4431d8300098906c1220495 --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setSeconds = Date.prototype.setSeconds; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setSeconds, 'function'); + +assert.throws(TypeError, function() { + setSeconds.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setSeconds.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setSeconds.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setSeconds/this-value-non-object.js b/test/built-ins/Date/prototype/setSeconds/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..44545126934463596d5b2acbc17f012af2a3a877 --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setSeconds = Date.prototype.setSeconds; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setSeconds, 'function'); + +assert.throws(TypeError, function() { + setSeconds.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setSeconds.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setSeconds.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setSeconds.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setSeconds.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setSeconds.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setSeconds/this-value-valid-date-ms.js b/test/built-ins/Date/prototype/setSeconds/this-value-valid-date-ms.js new file mode 100644 index 0000000000000000000000000000000000000000..364ce01c3de525f4b6481207844d5fdffc219a47 --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/this-value-valid-date-ms.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Return value for valid dates (setting ms) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). + 3. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 4. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, + milli)). + 5. Let u be TimeClip(UTC(date)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setSeconds(0, 543); + +expected = new Date(2016, 6, 1, 0, 0, 0, 543).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setSeconds(0, -1); + +expected = new Date(2016, 5, 30, 23, 59, 59, 999).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setSeconds(0, 1000); + +expected = new Date(2016, 5, 30, 23, 59, 1).getTime(); +assert.sameValue( + returnValue, expected, 'millisecond after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'millisecond after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setSeconds/this-value-valid-date-sec.js b/test/built-ins/Date/prototype/setSeconds/this-value-valid-date-sec.js new file mode 100644 index 0000000000000000000000000000000000000000..f90365f133b7c4e3a25d056debf5d64751c92c5d --- /dev/null +++ b/test/built-ins/Date/prototype/setSeconds/this-value-valid-date-sec.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +es6id: 20.3.4.26 +description: Return value for valid dates (setting sec) +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let s be ? ToNumber(sec). + 3. If ms is not specified, let milli be msFromTime(t); otherwise, let milli + be ? ToNumber(ms). + 4. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, + milli)). + 5. Let u be TimeClip(UTC(date)). + 6. Set the [[DateValue]] internal slot of this Date object to u. + 7. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue, expected; + +returnValue = date.setSeconds(45); + +expected = new Date(2016, 6, 1, 0, 0, 45).getTime(); +assert.sameValue( + returnValue, expected, 'second within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), expected, 'second within unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setSeconds(-1); + +expected = new Date(2016, 5, 30, 23, 59, 59).getTime(); +assert.sameValue( + returnValue, expected, 'second before time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'second before time unit boundary ([[DateValue]] slot)' +); + +returnValue = date.setSeconds(60); + +expected = new Date(2016, 6).getTime(); +assert.sameValue( + returnValue, expected, 'second after time unit boundary (return value)' +); +assert.sameValue( + date.getTime(), + expected, + 'second after time unit boundary ([[DateValue]] slot)' +); diff --git a/test/built-ins/Date/prototype/setTime/arg-to-number-err.js b/test/built-ins/Date/prototype/setTime/arg-to-number-err.js new file mode 100644 index 0000000000000000000000000000000000000000..dc2e542e8bedd60b5f62a6f7413abf9767eb4205 --- /dev/null +++ b/test/built-ins/Date/prototype/setTime/arg-to-number-err.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.settime +es6id: 20.3.4.27 +description: Abrupt completion during type coercion of provided argument +info: | + 1. Perform ? thisTimeValue(this value). + 2. Let t be ? ToNumber(time). +---*/ + +var date = new Date(); +var originalValue = date.getTime(); +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + date.setTime(obj); +}); + +assert.sameValue(date.getTime(), originalValue); diff --git a/test/built-ins/Date/prototype/setTime/arg-to-number.js b/test/built-ins/Date/prototype/setTime/arg-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..9b52b23f586f1b9ae8d78dc3a9a7873d4e44d5f3 --- /dev/null +++ b/test/built-ins/Date/prototype/setTime/arg-to-number.js @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.settime +es6id: 20.3.4.27 +description: Type coercion of provided argument +info: | + 1. Perform ? thisTimeValue(this value). + 2. Let t be ? ToNumber(time). + 3. Let v be TimeClip(t). + 4. Set the [[DateValue]] internal slot of this Date object to v. + 5. Return v. +---*/ + +var date = new Date(2016, 6); +var callCount = 0; +var arg = { + valueOf: function() { + args = arguments; + thisValue = this; + callCount += 1; + return 2; + } +}; +var args, thisValue, returnValue; + +returnValue = date.setTime(arg); + +assert.sameValue(callCount, 1, 'invoked exactly once'); +assert.sameValue(args.length, 0, 'invoked without arguments'); +assert.sameValue(thisValue, arg, '"this" value'); +assert.sameValue(returnValue, 2, 'application of specified value'); + +returnValue = date.setTime(null); + +assert.sameValue(returnValue, 0, 'null'); + +returnValue = date.setTime(true); + +assert.sameValue(returnValue, 1, 'true'); + +returnValue = date.setTime(false); + +assert.sameValue(returnValue, 0, 'false'); + +returnValue = date.setTime(' +00200.000E-0002 '); + +assert.sameValue(returnValue, 2, 'string'); + +returnValue = date.setTime(); + +assert.sameValue(returnValue, NaN, 'undefined'); diff --git a/test/built-ins/Date/prototype/setTime/new-value-time-clip.js b/test/built-ins/Date/prototype/setTime/new-value-time-clip.js new file mode 100644 index 0000000000000000000000000000000000000000..6740e0f0229d494c9940df9286c191266f0f448d --- /dev/null +++ b/test/built-ins/Date/prototype/setTime/new-value-time-clip.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.settime +es6id: 20.3.4.27 +description: Behavior when new value exceeds [[DateValue]] limits +info: | +info: | + 1. Perform ? thisTimeValue(this value). + 2. Let t be ? ToNumber(time). + 3. Let v be TimeClip(t). + 4. Set the [[DateValue]] internal slot of this Date object to v. + 5. Return v. + + TimeClip (time) + + 1. If time is not finite, return NaN. + 2. If abs(time) > 8.64 × 1015, return NaN. +---*/ + +var maxMs = 8.64e15; +var date = new Date(); +var returnValue; + +assert.notSameValue(date.getTime(), NaN); + +returnValue = date.setTime(maxMs + 1); + +assert.sameValue(returnValue, NaN); diff --git a/test/built-ins/Date/prototype/setTime/this-value-invalid-date.js b/test/built-ins/Date/prototype/setTime/this-value-invalid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..c3cb3db32d5e832b40898647769c22adfd933c1d --- /dev/null +++ b/test/built-ins/Date/prototype/setTime/this-value-invalid-date.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.settime +es6id: 20.3.4.27 +description: > + Behavior when the "this" value is a Date object describing an invald date +info: | +info: | + 1. Perform ? thisTimeValue(this value). + 2. Let t be ? ToNumber(time). + 3. Let v be TimeClip(t). + 4. Set the [[DateValue]] internal slot of this Date object to v. + 5. Return v. +---*/ + +var date = new Date(NaN); +var result; + +result = date.setTime(0); + +assert.sameValue(result, 0, 'return value'); +assert.sameValue(date.getTime(), 0, '[[DateValue]] internal slot'); diff --git a/test/built-ins/Date/prototype/setTime/this-value-non-date.js b/test/built-ins/Date/prototype/setTime/this-value-non-date.js new file mode 100644 index 0000000000000000000000000000000000000000..c2fb0f4b6510759f3f8451c025065471f21e3002 --- /dev/null +++ b/test/built-ins/Date/prototype/setTime/this-value-non-date.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.settime +es6id: 20.3.4.27 +description: > + Behavior when "this" value is an Object without a [[DateValue]] internal slot +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +---*/ + +var setTime = Date.prototype.setTime; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var args = (function() { return arguments; }()); + +assert.sameValue(typeof setTime, 'function'); + +assert.throws(TypeError, function() { + setTime.call({}, arg); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + setTime.call([], arg); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + setTime.call(args, arg); +}, 'arguments exotic object'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setTime/this-value-non-object.js b/test/built-ins/Date/prototype/setTime/this-value-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..87a4780d40084b84f8c55417f2920e6bf5dc7e1b --- /dev/null +++ b/test/built-ins/Date/prototype/setTime/this-value-non-object.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.settime +es6id: 20.3.4.27 +description: Behavior when "this" value is not an Object +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + + The abstract operation thisTimeValue(value) performs the following steps: + + 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then + a. Return value.[[DateValue]]. + 2. Throw a TypeError exception. +features: [Symbol] +---*/ + +var setTime = Date.prototype.setTime; +var callCount = 0; +var arg = { + valueOf: function() { + callCount += 1; + return 1; + } +}; +var symbol = Symbol(); + +assert.sameValue(typeof setTime, 'function'); + +assert.throws(TypeError, function() { + setTime.call(0, arg); +}, 'number'); + +assert.throws(TypeError, function() { + setTime.call(true, arg); +}, 'boolean'); + +assert.throws(TypeError, function() { + setTime.call(null, arg); +}, 'null'); + +assert.throws(TypeError, function() { + setTime.call(undefined, arg); +}, 'undefined'); + +assert.throws(TypeError, function() { + setTime.call('', arg); +}, 'string'); + +assert.throws(TypeError, function() { + setTime.call(symbol, arg); +}, 'symbol'); + +assert.sameValue(callCount, 0, 'validation preceeds input coercion'); diff --git a/test/built-ins/Date/prototype/setTime/this-value-valid-date.js b/test/built-ins/Date/prototype/setTime/this-value-valid-date.js new file mode 100644 index 0000000000000000000000000000000000000000..c044f909e4646eef3cd67714c33fa18c23e1b002 --- /dev/null +++ b/test/built-ins/Date/prototype/setTime/this-value-valid-date.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.settime +es6id: 20.3.4.27 +description: Return value for valid dates +info: | + 1. Let t be LocalTime(? thisTimeValue(this value)). + 2. Let dt be ? ToNumber(date). + 3. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), + TimeWithinDay(t)). + 4. Let u be TimeClip(UTC(newDate)). + 5. Set the [[DateValue]] internal slot of this Date object to u. + 6. Return u. +---*/ + +var date = new Date(2016, 6); +var returnValue; + +returnValue = date.setTime(6); + +assert.sameValue( + returnValue, 6, 'within unit boundary (return value)' +); +assert.sameValue( + date.getTime(), 6, 'within unit boundary ([[DateValue]] slot)' +);