diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Date/prototype/setSeconds | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Date/prototype/setSeconds')
22 files changed, 734 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T1.js new file mode 100644 index 0000000000..80cacf2f6a --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T1.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The Date.prototype property "setSeconds" has { DontEnum } attributes +esid: sec-date.prototype.setseconds +description: Checking absence of ReadOnly attribute +---*/ + +var x = Date.prototype.setSeconds; +if (x === 1) { + Date.prototype.setSeconds = 2; +} else { + Date.prototype.setSeconds = 1; +} + +assert.notSameValue( + Date.prototype.setSeconds, + x, + 'The value of Date.prototype.setSeconds is expected to not equal the value of `x`' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T2.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T2.js new file mode 100644 index 0000000000..8d6c81ce9a --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T2.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The Date.prototype property "setSeconds" has { DontEnum } attributes +esid: sec-date.prototype.setseconds +description: Checking absence of DontDelete attribute +---*/ +assert.notSameValue( + delete Date.prototype.setSeconds, + false, + 'The value of delete Date.prototype.setSeconds is not false' +); + +assert( + !Date.prototype.hasOwnProperty('setSeconds'), + 'The value of !Date.prototype.hasOwnProperty(\'setSeconds\') is expected to be true' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T3.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T3.js new file mode 100644 index 0000000000..0692617eb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A1_T3.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The Date.prototype property "setSeconds" has { DontEnum } attributes +esid: sec-date.prototype.setseconds +description: Checking DontEnum attribute +---*/ +assert( + !Date.prototype.propertyIsEnumerable('setSeconds'), + 'The value of !Date.prototype.propertyIsEnumerable(\'setSeconds\') is expected to be true' +); + +for (var x in Date.prototype) { + assert.notSameValue(x, "setSeconds", 'The value of x is not "setSeconds"'); +} + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A2_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A2_T1.js new file mode 100644 index 0000000000..dcac968a56 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A2_T1.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The "length" property of the "setSeconds" is 2 +esid: sec-date.prototype.setseconds +description: The "length" property of the "setSeconds" is 2 +---*/ +assert.sameValue( + Date.prototype.setSeconds.hasOwnProperty("length"), + true, + 'Date.prototype.setSeconds.hasOwnProperty("length") must return true' +); + +assert.sameValue( + Date.prototype.setSeconds.length, + 2, + 'The value of Date.prototype.setSeconds.length is expected to be 2' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T1.js new file mode 100644 index 0000000000..5a240eca98 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T1.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The Date.prototype.setSeconds property "length" has { ReadOnly, + DontDelete, DontEnum } attributes +esid: sec-date.prototype.setseconds +description: Checking ReadOnly attribute +includes: [propertyHelper.js] +---*/ + +var x = Date.prototype.setSeconds.length; +verifyNotWritable(Date.prototype.setSeconds, "length", null, 1); + +assert.sameValue( + Date.prototype.setSeconds.length, + x, + 'The value of Date.prototype.setSeconds.length is expected to equal the value of x' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T2.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T2.js new file mode 100644 index 0000000000..789bca4e48 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T2.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The Date.prototype.setSeconds property "length" has { ReadOnly, ! + DontDelete, DontEnum } attributes +esid: sec-date.prototype.setseconds +description: Checking DontDelete attribute +---*/ +assert.sameValue( + delete Date.prototype.setSeconds.length, + true, + 'The value of `delete Date.prototype.setSeconds.length` is expected to be true' +); + +assert( + !Date.prototype.setSeconds.hasOwnProperty('length'), + 'The value of !Date.prototype.setSeconds.hasOwnProperty(\'length\') is expected to be true' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T3.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T3.js new file mode 100644 index 0000000000..80e814d9dd --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/S15.9.5.30_A3_T3.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The Date.prototype.setSeconds property "length" has { ReadOnly, + DontDelete, DontEnum } attributes +esid: sec-date.prototype.setseconds +description: Checking DontEnum attribute +---*/ +assert( + !Date.prototype.setSeconds.propertyIsEnumerable('length'), + 'The value of !Date.prototype.setSeconds.propertyIsEnumerable(\'length\') is expected to be true' +); + +for (var x in Date.prototype.setSeconds) { + assert.notSameValue(x, "length", 'The value of x is not "length"'); +} + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-coercion-order.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-coercion-order.js new file mode 100644 index 0000000000..1cbc4420c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-coercion-order.js @@ -0,0 +1,43 @@ +// Copyright (C) 2021 Kevin Gibbons. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.setseconds +description: Order of coercion of provided arguments vs NaN check +info: | + 1. Let t be ? thisTimeValue(this value). + 2. Let s be ? ToNumber(sec). + 3. If ms is present, let milli be ? ToNumber(ms). + 4. If t is NaN, return NaN. + 5. Set t to LocalTime(t). + 6. If ms is not present, let milli be msFromTime(t). + 7. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli)). + 8. Let u be TimeClip(UTC(date)). + 9. Set the [[DateValue]] internal slot of this Date object to u. + 10. Return u. +includes: [compareArray.js] +---*/ + +var date = new Date(NaN); +var effects = []; +var argSec = { + valueOf: function() { + effects.push('valueOf sec'); + return 0; + } +}; +var argMs = { + valueOf: function() { + effects.push('valueOf ms'); + return 0; + } +}; + +var returnValue = date.setSeconds(argSec, argMs); + +var expectedEffects = ['valueOf sec', 'valueOf ms']; + +assert.compareArray(effects, expectedEffects); +assert.sameValue(returnValue, NaN, 'argument is ignored when `this` is an invalid date'); +assert.sameValue(date.getTime(), NaN, 'argument is ignored when `this` is an invalid date'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-ms-to-number-err.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-ms-to-number-err.js new file mode 100644 index 0000000000..abde04c4d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-ms-to-number-err.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.setseconds +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-ms-to-number.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-ms-to-number.js new file mode 100644 index 0000000000..daff2f09ed --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/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.setseconds +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-sec-to-number-err.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-sec-to-number-err.js new file mode 100644 index 0000000000..c9dd0a499b --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-sec-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.setseconds +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-sec-to-number.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/arg-sec-to-number.js new file mode 100644 index 0000000000..c75b2ba52a --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/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.setseconds +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/browser.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/browser.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/name.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/name.js new file mode 100644 index 0000000000..1850428386 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.setseconds +description: > + Date.prototype.setSeconds.name is "setSeconds". +info: | + Date.prototype.setSeconds ( sec [ , ms ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Date.prototype.setSeconds.name, "setSeconds"); + +verifyNotEnumerable(Date.prototype.setSeconds, "name"); +verifyNotWritable(Date.prototype.setSeconds, "name"); +verifyConfigurable(Date.prototype.setSeconds, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/new-value-time-clip.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/new-value-time-clip.js new file mode 100644 index 0000000000..533ee21aa4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/new-value-time-clip.js @@ -0,0 +1,39 @@ +// 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 +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/not-a-constructor.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/not-a-constructor.js new file mode 100644 index 0000000000..47cfa721dd --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Date.prototype.setSeconds does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Date.prototype.setSeconds), + false, + 'isConstructor(Date.prototype.setSeconds) must return false' +); + +assert.throws(TypeError, () => { + let date = new Date(Date.now()); new date.setSeconds(); +}, '`let date = new Date(Date.now()); new date.setSeconds()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/shell.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/shell.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-invalid-date.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-invalid-date.js new file mode 100644 index 0000000000..5c587952f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-invalid-date.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.setseconds +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)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-non-date.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-non-date.js new file mode 100644 index 0000000000..4905c669bd --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-non-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.setseconds +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 precedes input coercion'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-non-object.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-non-object.js new file mode 100644 index 0000000000..f977f32a26 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-non-object.js @@ -0,0 +1,55 @@ +// 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 +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 precedes input coercion'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-valid-date-ms.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-valid-date-ms.js new file mode 100644 index 0000000000..9b1d89ff07 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-valid-date-ms.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.setseconds +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)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-valid-date-sec.js b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-valid-date-sec.js new file mode 100644 index 0000000000..27075d0610 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setSeconds/this-value-valid-date-sec.js @@ -0,0 +1,55 @@ +// 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 +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)' +); + +reportCompare(0, 0); |