diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Date/prototype/setMonth')
22 files changed, 761 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A1_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A1_T1.js new file mode 100644 index 0000000000..ac3d594ccb --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_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 "setMonth" has { DontEnum } attributes +esid: sec-date.prototype.setmonth +description: Checking absence of ReadOnly attribute +---*/ + +var x = Date.prototype.setMonth; +if (x === 1) { + Date.prototype.setMonth = 2; +} else { + Date.prototype.setMonth = 1; +} + +assert.notSameValue( + Date.prototype.setMonth, + x, + 'The value of Date.prototype.setMonth 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/setMonth/S15.9.5.38_A1_T2.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A1_T2.js new file mode 100644 index 0000000000..492b1be5cd --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_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 "setMonth" has { DontEnum } attributes +esid: sec-date.prototype.setmonth +description: Checking absence of DontDelete attribute +---*/ +assert.notSameValue(delete Date.prototype.setMonth, false, 'The value of delete Date.prototype.setMonth is not false'); + +assert( + !Date.prototype.hasOwnProperty('setMonth'), + 'The value of !Date.prototype.hasOwnProperty(\'setMonth\') is expected to be true' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A1_T3.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A1_T3.js new file mode 100644 index 0000000000..22d2585a7c --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_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 "setMonth" has { DontEnum } attributes +esid: sec-date.prototype.setmonth +description: Checking DontEnum attribute +---*/ +assert( + !Date.prototype.propertyIsEnumerable('setMonth'), + 'The value of !Date.prototype.propertyIsEnumerable(\'setMonth\') is expected to be true' +); + +for (var x in Date.prototype) { + assert.notSameValue(x, "setMonth", 'The value of x is not "setMonth"'); +} + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A2_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A2_T1.js new file mode 100644 index 0000000000..ed5846befa --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_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 "setMonth" is 2 +esid: sec-date.prototype.setmonth +description: The "length" property of the "setMonth" is 2 +---*/ +assert.sameValue( + Date.prototype.setMonth.hasOwnProperty("length"), + true, + 'Date.prototype.setMonth.hasOwnProperty("length") must return true' +); + +assert.sameValue(Date.prototype.setMonth.length, 2, 'The value of Date.prototype.setMonth.length is expected to be 2'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A3_T1.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A3_T1.js new file mode 100644 index 0000000000..f6c45f61ef --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_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.setMonth property "length" has { ReadOnly, DontDelete, + DontEnum } attributes +esid: sec-date.prototype.setmonth +description: Checking ReadOnly attribute +includes: [propertyHelper.js] +---*/ + +var x = Date.prototype.setMonth.length; +verifyNotWritable(Date.prototype.setMonth, "length", null, 1); + +assert.sameValue( + Date.prototype.setMonth.length, + x, + 'The value of Date.prototype.setMonth.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/setMonth/S15.9.5.38_A3_T2.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A3_T2.js new file mode 100644 index 0000000000..9238a8ed74 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_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.setMonth property "length" has { ReadOnly, ! + DontDelete, DontEnum } attributes +esid: sec-date.prototype.setmonth +description: Checking DontDelete attribute +---*/ +assert.sameValue( + delete Date.prototype.setMonth.length, + true, + 'The value of `delete Date.prototype.setMonth.length` is expected to be true' +); + +assert( + !Date.prototype.setMonth.hasOwnProperty('length'), + 'The value of !Date.prototype.setMonth.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/setMonth/S15.9.5.38_A3_T3.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_A3_T3.js new file mode 100644 index 0000000000..23f1888331 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/S15.9.5.38_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.setMonth property "length" has { ReadOnly, DontDelete, + DontEnum } attributes +esid: sec-date.prototype.setmonth +description: Checking DontEnum attribute +---*/ +assert( + !Date.prototype.setMonth.propertyIsEnumerable('length'), + 'The value of !Date.prototype.setMonth.propertyIsEnumerable(\'length\') is expected to be true' +); + +for (var x in Date.prototype.setMonth) { + 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/setMonth/arg-coercion-order.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-coercion-order.js new file mode 100644 index 0000000000..a1bc3862af --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/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.setmonth +description: Order of coercion of provided argument vs NaN check +info: | + 1. Let t be ? thisTimeValue(this value). + 2. Let m be ? ToNumber(month). + 3. If date is present, let dt be ? ToNumber(date). + 4. If t is NaN, return NaN. + 5. Set t to LocalTime(t). + 6. If date is not present, let dt be DateFromTime(t). + 7. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t)). + 8. Let u be TimeClip(UTC(newDate)). + 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 argMonth = { + valueOf: function() { + effects.push('valueOf month'); + return 0; + } +}; +var argDate = { + valueOf: function() { + effects.push('valueOf date'); + return 0; + } +}; + +var returnValue = date.setMonth(argMonth, argDate); + +var expectedEffects = ['valueOf month', 'valueOf date']; + +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/setMonth/arg-date-to-number-err.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-date-to-number-err.js new file mode 100644 index 0000000000..107b762d8e --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-date-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.setmonth +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-date-to-number.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-date-to-number.js new file mode 100644 index 0000000000..46db557fa8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-date-to-number.js @@ -0,0 +1,77 @@ +// 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 +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-month-to-number-err.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-month-to-number-err.js new file mode 100644 index 0000000000..e1ce3b4cc8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-month-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.setmonth +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-month-to-number.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-month-to-number.js new file mode 100644 index 0000000000..f1af4d13c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/arg-month-to-number.js @@ -0,0 +1,79 @@ +// 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 +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/browser.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/browser.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/name.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/name.js new file mode 100644 index 0000000000..9e28f33557 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/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.setmonth +description: > + Date.prototype.setMonth.name is "setMonth". +info: | + Date.prototype.setMonth ( month [ , date ] ) + + 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.setMonth.name, "setMonth"); + +verifyNotEnumerable(Date.prototype.setMonth, "name"); +verifyNotWritable(Date.prototype.setMonth, "name"); +verifyConfigurable(Date.prototype.setMonth, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/new-value-time-clip.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/new-value-time-clip.js new file mode 100644 index 0000000000..311f7e4ce6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/new-value-time-clip.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.setmonth +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 + 2); + +assert.sameValue(returnValue, NaN, 'overflow due to date'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/not-a-constructor.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/not-a-constructor.js new file mode 100644 index 0000000000..ce51b8a701 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/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.setMonth 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.setMonth), + false, + 'isConstructor(Date.prototype.setMonth) must return false' +); + +assert.throws(TypeError, () => { + let date = new Date(Date.now()); new date.setMonth(); +}, '`let date = new Date(Date.now()); new date.setMonth()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/shell.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/shell.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-invalid-date.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-invalid-date.js new file mode 100644 index 0000000000..d3e25b5e74 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-invalid-date.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 +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)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-non-date.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-non-date.js new file mode 100644 index 0000000000..4b57615917 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/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.setmonth +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 precedes input coercion'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-non-object.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-non-object.js new file mode 100644 index 0000000000..c43b784447 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/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.setmonth +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 precedes input coercion'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-valid-date-date.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-valid-date-date.js new file mode 100644 index 0000000000..ed06da40c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-valid-date-date.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.setmonth +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)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-valid-date-month.js b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-valid-date-month.js new file mode 100644 index 0000000000..f4ba0fc61d --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/setMonth/this-value-valid-date-month.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.setmonth +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)' +); + +reportCompare(0, 0); |