diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/Date/defaultvalue.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Date/defaultvalue.js')
-rw-r--r-- | js/src/tests/non262/Date/defaultvalue.js | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/js/src/tests/non262/Date/defaultvalue.js b/js/src/tests/non262/Date/defaultvalue.js new file mode 100644 index 0000000000..2fc5887d18 --- /dev/null +++ b/js/src/tests/non262/Date/defaultvalue.js @@ -0,0 +1,190 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommonn.org/licenses/publicdomain/ + */ + +var BUGNUMBER = 645464; +var summary = + "[[DefaultValue]] behavior wrong for Date with overridden valueOf/toString"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +function allTests() +{ + var DS = new Date(2010, 1, 1).toString(); + + // equality + + var d = new Date(2010, 1, 1); + assertEq(d == DS, true); + + var d2 = new Date(2010, 1, 1); + d2.valueOf = function() { assertEq(arguments.length, 0); return 17; }; + assertEq(d2 == DS, true); + + var d3 = new Date(2010, 1, 1); + d3.toString = function() { return 42; }; + assertEq(d3 == 42, true); + + function testEquality() + { + var d = new Date(2010, 1, 1); + assertEq(d == DS, true); + + var d2 = new Date(2010, 1, 1); + d2.valueOf = function() { assertEq(arguments.length, 0); return 17; }; + assertEq(d2 == DS, true); + + var d3 = new Date(2010, 1, 1); + d3.toString = function() { return 42; }; + assertEq(d3 == 42, true); + } + testEquality(); + + + // addition of Date to number + + var d = new Date(2010, 1, 1); + assertEq(d + 5, DS + "5"); + + var d2 = new Date(2010, 1, 1); + d2.toString = function() { return 9; }; + assertEq(d2 + 3, 9 + 3); + + var d3 = new Date(2010, 1, 1); + d3.valueOf = function() { assertEq(arguments.length, 0); return 17; }; + assertEq(d3 + 5, DS + "5"); + + function testDateNumberAddition() + { + var d = new Date(2010, 1, 1); + assertEq(d + 5, DS + "5"); + + var d2 = new Date(2010, 1, 1); + d2.toString = function() { return 9; }; + assertEq(d2 + 3, 9 + 3); + + var d3 = new Date(2010, 1, 1); + d3.valueOf = function() { assertEq(arguments.length, 0); return 17; }; + assertEq(d3 + 5, DS + "5"); + } + testDateNumberAddition(); + + + // addition of Date to Date + + var d = new Date(2010, 1, 1); + assertEq(d + d, DS + DS); + + var d2 = new Date(2010, 1, 1); + d2.toString = function() { return 5; }; + assertEq(d2 + d2, 10); + + var d3 = new Date(2010, 1, 1); + d3.valueOf = function() { assertEq(arguments.length, 0); return 8.5; }; + assertEq(d3 + d3, DS + DS); + + function testDateDateAddition() + { + var d = new Date(2010, 1, 1); + assertEq(d + d, DS + DS); + + var d2 = new Date(2010, 1, 1); + d2.toString = function() { return 5; }; + assertEq(d2 + d2, 10); + + var d3 = new Date(2010, 1, 1); + d3.valueOf = function() { assertEq(arguments.length, 0); return 8.5; }; + assertEq(d3 + d3, DS + DS); + } + testDateDateAddition(); + + + // Date as bracketed property name + + var obj = { 8: 42, 9: 73 }; + obj[DS] = 17; + + var d = new Date(2010, 1, 1); + assertEq(obj[d], 17); + + var d2 = new Date(2010, 1, 1); + d2.valueOf = function() { assertEq(arguments.length, 0); return 8; } + assertEq(obj[d2], 17); + + var d3 = new Date(2010, 1, 1); + d3.toString = function() { return 9; }; + assertEq(obj[d3], 73); + + function testPropertyName() + { + var obj = { 8: 42, 9: 73 }; + obj[DS] = 17; + + var d = new Date(2010, 1, 1); + assertEq(obj[d], 17); + + var d2 = new Date(2010, 1, 1); + d2.valueOf = function() { assertEq(arguments.length, 0); return 8; } + assertEq(obj[d2], 17); + + var d3 = new Date(2010, 1, 1); + d3.toString = function() { return 9; }; + assertEq(obj[d3], 73); + } + testPropertyName(); + + + // Date as property name with |in| operator + + var obj = {}; + obj[DS] = 5; + + var d = new Date(2010, 1, 1); + assertEq(d in obj, true); + + var d2 = new Date(2010, 1, 1); + d2.toString = function() { return "baz"; }; + assertEq(d2 in { baz: 42 }, true); + + var d3 = new Date(2010, 1, 1); + d3.valueOf = function() { assertEq(arguments.length, 0); return "quux"; }; + assertEq(d3 in obj, true); + + function testInOperatorName() + { + var obj = {}; + obj[DS] = 5; + + var d = new Date(2010, 1, 1); + assertEq(d in obj, true); + + var d2 = new Date(2010, 1, 1); + d2.toString = function() { return "baz"; }; + assertEq(d2 in { baz: 42 }, true); + + var d3 = new Date(2010, 1, 1); + d3.valueOf = function() { assertEq(arguments.length, 0); return "quux"; }; + assertEq(d3 in obj, true); + } + testInOperatorName(); +} + +allTests(); + +if (typeof newGlobal === "function") +{ + Date = newGlobal().Date; + allTests(); +} + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); |