diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Date/prototype/setTime')
18 files changed, 471 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A1_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A1_T1.js new file mode 100644 index 0000000000..cdd891deac --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_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 "setTime" has { DontEnum } attributes +esid: sec-date.prototype.settime +description: Checking absence of ReadOnly attribute +---*/ + +var x = Date.prototype.setTime; +if (x === 1) { + Date.prototype.setTime = 2; +} else { + Date.prototype.setTime = 1; +} + +assert.notSameValue( + Date.prototype.setTime, + x, + 'The value of Date.prototype.setTime 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/setTime/S15.9.5.27_A1_T2.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A1_T2.js new file mode 100644 index 0000000000..3d425994ab --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A1_T2.js @@ -0,0 +1,18 @@ +// 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 "setTime" has { DontEnum } attributes +esid: sec-date.prototype.settime +description: Checking absence of DontDelete attribute +---*/ +assert.notSameValue(delete Date.prototype.setTime, false, 'The value of delete Date.prototype.setTime is not false'); + +assert( + !Date.prototype.hasOwnProperty('setTime'), + 'The value of !Date.prototype.hasOwnProperty(\'setTime\') is expected to be true' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A1_T3.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A1_T3.js new file mode 100644 index 0000000000..78164e813d --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_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 "setTime" has { DontEnum } attributes +esid: sec-date.prototype.settime +description: Checking DontEnum attribute +---*/ +assert( + !Date.prototype.propertyIsEnumerable('setTime'), + 'The value of !Date.prototype.propertyIsEnumerable(\'setTime\') is expected to be true' +); + +for (var x in Date.prototype) { + assert.notSameValue(x, "setTime", 'The value of x is not "setTime"'); +} + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A2_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A2_T1.js new file mode 100644 index 0000000000..a4fa4209a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A2_T1.js @@ -0,0 +1,17 @@ +// 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 "setTime" is 1 +esid: sec-date.prototype.settime +description: The "length" property of the "setTime" is 1 +---*/ +assert.sameValue( + Date.prototype.setTime.hasOwnProperty("length"), + true, + 'Date.prototype.setTime.hasOwnProperty("length") must return true' +); + +assert.sameValue(Date.prototype.setTime.length, 1, 'The value of Date.prototype.setTime.length is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A3_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A3_T1.js new file mode 100644 index 0000000000..4ef36f2f25 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_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.setTime property "length" has { ReadOnly, DontDelete, + DontEnum } attributes +esid: sec-date.prototype.settime +description: Checking ReadOnly attribute +includes: [propertyHelper.js] +---*/ + +var x = Date.prototype.setTime.length; +verifyNotWritable(Date.prototype.setTime, "length", null, 1); + +assert.sameValue( + Date.prototype.setTime.length, + x, + 'The value of Date.prototype.setTime.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/setTime/S15.9.5.27_A3_T2.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A3_T2.js new file mode 100644 index 0000000000..b66fe9c598 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_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.setTime property "length" has { ReadOnly, ! + DontDelete, DontEnum } attributes +esid: sec-date.prototype.settime +description: Checking DontDelete attribute +---*/ +assert.sameValue( + delete Date.prototype.setTime.length, + true, + 'The value of `delete Date.prototype.setTime.length` is expected to be true' +); + +assert( + !Date.prototype.setTime.hasOwnProperty('length'), + 'The value of !Date.prototype.setTime.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/setTime/S15.9.5.27_A3_T3.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_A3_T3.js new file mode 100644 index 0000000000..9a6bd16d4c --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/S15.9.5.27_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.setTime property "length" has { ReadOnly, DontDelete, + DontEnum } attributes +esid: sec-date.prototype.settime +description: Checking DontEnum attribute +---*/ +assert( + !Date.prototype.setTime.propertyIsEnumerable('length'), + 'The value of !Date.prototype.setTime.propertyIsEnumerable(\'length\') is expected to be true' +); + +for (var x in Date.prototype.setTime) { + 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/setTime/arg-to-number-err.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/arg-to-number-err.js new file mode 100644 index 0000000000..4ce961f808 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/arg-to-number-err.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.settime +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/arg-to-number.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/arg-to-number.js new file mode 100644 index 0000000000..daa2553131 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/arg-to-number.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.settime +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/browser.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/browser.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/name.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/name.js new file mode 100644 index 0000000000..b978b93ad5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/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.settime +description: > + Date.prototype.setTime.name is "setTime". +info: | + Date.prototype.setTime ( time ) + + 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.setTime.name, "setTime"); + +verifyNotEnumerable(Date.prototype.setTime, "name"); +verifyNotWritable(Date.prototype.setTime, "name"); +verifyConfigurable(Date.prototype.setTime, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/new-value-time-clip.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/new-value-time-clip.js new file mode 100644 index 0000000000..8912795503 --- /dev/null +++ b/js/src/tests/test262/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 +description: Behavior when new value exceeds [[DateValue]] limits +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/not-a-constructor.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/not-a-constructor.js new file mode 100644 index 0000000000..5bd2d83907 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/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.setTime 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.setTime), + false, + 'isConstructor(Date.prototype.setTime) must return false' +); + +assert.throws(TypeError, () => { + let date = new Date(Date.now()); new date.setTime(); +}, '`let date = new Date(Date.now()); new date.setTime()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/shell.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/shell.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-invalid-date.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-invalid-date.js new file mode 100644 index 0000000000..d575d58231 --- /dev/null +++ b/js/src/tests/test262/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 +description: > + Behavior when the "this" value is a Date object describing an invald date +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-non-date.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-non-date.js new file mode 100644 index 0000000000..6ecff8e82c --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/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.settime +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 precedes input coercion'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-non-object.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-non-object.js new file mode 100644 index 0000000000..c9eb97e3b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/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.settime +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 precedes input coercion'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-valid-date.js b/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-valid-date.js new file mode 100644 index 0000000000..e2cad61b51 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setTime/this-value-valid-date.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.settime +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)' +); + +reportCompare(0, 0); |