Ensure NaN time values are correctly handled in various Date setters

Related PR: https://github.com/tc39/ecma262/pull/2136
This commit is contained in:
André Bargull 2024-10-10 18:06:32 +02:00 committed by Philip Chimento
parent 5ae7de9942
commit 92b592547d
30 changed files with 1162 additions and 0 deletions

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setyear
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setYear ( year )
...
3. Let t be dateObject.[[DateValue]].
4. Let y be ? ToNumber(year).
5. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
6. Let yyyy be MakeFullYear(y).
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setYear(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getYear(), 1, "date value correctly updated");

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setyear
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setYear ( year )
...
3. Let t be dateObject.[[DateValue]].
4. Let y be ? ToNumber(year).
5. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
6. Let yyyy be MakeFullYear(y).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setYear(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getYear(), 1, "date value correctly updated");

View File

@ -0,0 +1,36 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setdate
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setDate ( date )
...
3. Let t be dateObject.[[DateValue]].
4. Let dt be ? ToNumber(date).
5. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setDate(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setdate
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setDate ( date )
...
3. Let t be dateObject.[[DateValue]].
4. Let dt be ? ToNumber(date).
5. If t is NaN, return NaN.
6. Set t to LocalTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setDate(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getDate(), 1, "date value correctly updated");

View File

@ -0,0 +1,38 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setfullyear
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setFullYear ( year [ , month [ , date ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let y be ? ToNumber(year).
5. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setFullYear(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getFullYear(), 1, "date value correctly updated");

View File

@ -0,0 +1,38 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setfullyear
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setFullYear ( year [ , month [ , date ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let y be ? ToNumber(year).
5. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setFullYear(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getFullYear(), 1, "date value correctly updated");

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.sethours
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let h be ? ToNumber(hour).
5. If min is present, let m be ? ToNumber(min).
6. If sec is present, let s be ? ToNumber(sec).
7. If ms is present, let milli be ? ToNumber(ms).
8. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setHours(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,42 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.sethours
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let h be ? ToNumber(hour).
5. If min is present, let m be ? ToNumber(min).
6. If sec is present, let s be ? ToNumber(sec).
7. If ms is present, let milli be ? ToNumber(ms).
8. If t is NaN, return NaN.
9. Set t to LocalTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setHours(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getHours(), 1, "date value correctly updated");

View File

@ -0,0 +1,36 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setmilliseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setMilliseconds ( ms )
...
3. Let t be dateObject.[[DateValue]].
4. Set ms to ? ToNumber(ms).
5. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setMilliseconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setmilliseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setMilliseconds ( ms )
...
3. Let t be dateObject.[[DateValue]].
4. Set ms to ? ToNumber(ms).
5. If t is NaN, return NaN.
6. Set t to LocalTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setMilliseconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getMilliseconds(), 1, "date value correctly updated");

View File

@ -0,0 +1,38 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setminutes
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(min).
5. If sec is present, let s be ? ToNumber(sec).
6. If ms is present, let milli be ? ToNumber(ms).
7. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setMinutes(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,41 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setminutes
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(min).
5. If sec is present, let s be ? ToNumber(sec).
6. If ms is present, let milli be ? ToNumber(ms).
7. If t is NaN, return NaN.
8. Set t to LocalTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setMinutes(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getMinutes(), 1, "date value correctly updated");

View File

@ -0,0 +1,37 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setmonth
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setMonth ( month [ , date ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(month).
5. If date is present, let dt be ? ToNumber(date).
6. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setMonth(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,44 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setmonth
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setMonth ( month [ , date ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(month).
5. If date is present, let dt be ? ToNumber(date).
6. If t is NaN, return NaN.
7. Set t to LocalTime(t).
...
---*/
var dt = new Date(0);
// Change date from "Jan 1 1970" to "Jan 2 1970" to ensure this test passes in
// all time zones.
dt.setDate(2);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setMonth(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getMonth(), 1, "date value correctly updated");

View File

@ -0,0 +1,37 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setSeconds ( sec [ , ms ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let s be ? ToNumber(sec).
5. If ms is present, let milli be ? ToNumber(ms).
6. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setSeconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setSeconds ( sec [ , ms ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let s be ? ToNumber(sec).
5. If ms is present, let milli be ? ToNumber(ms).
6. If t is NaN, return NaN.
7. Set t to LocalTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setSeconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getSeconds(), 1, "date value correctly updated");

View File

@ -0,0 +1,36 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcdate
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setUTCDate ( date )
...
3. Let t be dateObject.[[DateValue]].
4. Let dt be ? ToNumber(date).
5. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setUTCDate(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcdate
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setUTCDate ( date )
...
3. Let t be dateObject.[[DateValue]].
4. Let dt be ? ToNumber(date).
5. If t is NaN, return NaN.
6. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t)).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setUTCDate(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCDate(), 1, "date value correctly updated");

View File

@ -0,0 +1,38 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcfullyear
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. If t is NaN, set t to +0𝔽.
5. Let y be ? ToNumber(year).
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setUTCFullYear(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCFullYear(), 1, "date value correctly updated");

View File

@ -0,0 +1,38 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcfullyear
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. If t is NaN, set t to +0𝔽.
5. Let y be ? ToNumber(year).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setUTCFullYear(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCFullYear(), 1, "date value correctly updated");

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutchours
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let h be ? ToNumber(hour).
5. If min is present, let m be ? ToNumber(min).
6. If sec is present, let s be ? ToNumber(sec).
7. If ms is present, let milli be ? ToNumber(ms).
8. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setUTCHours(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,42 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutchours
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let h be ? ToNumber(hour).
5. If min is present, let m be ? ToNumber(min).
6. If sec is present, let s be ? ToNumber(sec).
7. If ms is present, let milli be ? ToNumber(ms).
8. If t is NaN, return NaN.
9. If min is not present, let m be MinFromTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setUTCHours(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCHours(), 1, "date value correctly updated");

View File

@ -0,0 +1,36 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcmilliseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setUTCMilliseconds ( ms )
...
3. Let t be dateObject.[[DateValue]].
4. Set ms to ? ToNumber(ms).
5. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setUTCMilliseconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,39 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcmilliseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setUTCMilliseconds ( ms )
...
3. Let t be dateObject.[[DateValue]].
4. Set ms to ? ToNumber(ms).
5. If t is NaN, return NaN.
6. Let time be MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setUTCMilliseconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCMilliseconds(), 1, "date value correctly updated");

View File

@ -0,0 +1,38 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcminutes
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setUTCMinutes ( min [ , sec [ , ms ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(min).
5. If sec is present, let s be ? ToNumber(sec).
6. If ms is present, let milli be ? ToNumber(ms).
7. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setUTCMinutes(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,41 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcminutes
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setUTCMinutes ( min [ , sec [ , ms ] ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(min).
5. If sec is present, let s be ? ToNumber(sec).
6. If ms is present, let milli be ? ToNumber(ms).
7. If t is NaN, return NaN.
8. If sec is not present, let s be SecFromTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setUTCMinutes(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCMinutes(), 1, "date value correctly updated");

View File

@ -0,0 +1,37 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcmonth
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setUTCMonth ( month [ , date ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(month).
5. If date is present, let dt be ? ToNumber(date).
6. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setUTCMonth(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcmonth
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setUTCMonth ( month [ , date ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let m be ? ToNumber(month).
5. If date is present, let dt be ? ToNumber(date).
6. If t is NaN, return NaN.
7. If date is not present, let dt be DateFromTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setUTCMonth(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCMonth(), 1, "date value correctly updated");

View File

@ -0,0 +1,37 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is invalid.
info: |
Date.prototype.setUTCSeconds ( sec [ , ms ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let s be ? ToNumber(sec).
5. If ms is present, let milli be ? ToNumber(ms).
6. If t is NaN, return NaN.
...
---*/
var dt = new Date(NaN);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(0);
return 1;
}
};
var result = dt.setUTCSeconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.sameValue(result, NaN, "result is NaN");
assert.sameValue(dt.getTime(), 0, "time updated in valueOf");

View File

@ -0,0 +1,40 @@
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-date.prototype.setutcseconds
description: >
Read [[DateValue]] and then call ToNumber when stored time-value is valid.
info: |
Date.prototype.setUTCSeconds ( sec [ , ms ] )
...
3. Let t be dateObject.[[DateValue]].
4. Let s be ? ToNumber(sec).
5. If ms is present, let milli be ? ToNumber(ms).
6. If t is NaN, return NaN.
7. If ms is not present, let milli be msFromTime(t).
...
---*/
var dt = new Date(0);
var valueOfCalled = 0;
var value = {
valueOf() {
valueOfCalled++;
dt.setTime(NaN);
return 1;
}
};
var result = dt.setUTCSeconds(value);
assert.sameValue(valueOfCalled, 1, "valueOf called exactly once");
assert.notSameValue(result, NaN, "result is not NaN");
assert.sameValue(result, dt.getTime(), "result is equal to getTime");
assert.sameValue(dt.getUTCSeconds(), 1, "date value correctly updated");