diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_5/String/defaultvalue.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_5/String/defaultvalue.js')
-rw-r--r-- | js/src/tests/ecma_5/String/defaultvalue.js | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/js/src/tests/ecma_5/String/defaultvalue.js b/js/src/tests/ecma_5/String/defaultvalue.js new file mode 100644 index 000000000..50b4fe00d --- /dev/null +++ b/js/src/tests/ecma_5/String/defaultvalue.js @@ -0,0 +1,169 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +var BUGNUMBER = 645464; +var summary = + "[[DefaultValue]] behavior wrong for String with overridden valueOf/toString"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// equality + +var s = new String("c"); +assertEq(s == "c", true); + +var s2 = new String(); +s2.valueOf = function() { return "foo"; }; +assertEq(s2 == "foo", true); + +var s3 = new String(); +s3.toString = function() { return "bar"; }; +assertEq(s3 == "", true); + +function testEquality() +{ + var s = new String("c"); + assertEq(s == "c", true); + + var s2 = new String(); + s2.valueOf = function() { return "foo"; }; + assertEq(s2 == "foo", true); + + var s3 = new String(); + s3.toString = function() { return "bar"; }; + assertEq(s3 == "", true); +} +testEquality(); + + +// addition of String to string + +var s = new String(); +assertEq(s + "", ""); + +var s2 = new String(); +s2.toString = function() { return "bar"; }; +assertEq(s2 + "", ""); + +var s3 = new String(); +s3.valueOf = function() { return "baz"; }; +assertEq(s3 + "", "baz"); + +function testStringAddition() +{ + var s = new String(); + assertEq(s + "", ""); + + var s2 = new String(); + s2.toString = function() { return "bar"; }; + assertEq(s2 + "", ""); + + var s3 = new String(); + s3.valueOf = function() { return "baz"; }; + assertEq(s3 + "", "baz"); +} +testStringAddition(); + + +// addition of String to String + +var s = new String(); +assertEq(s + s, ""); + +var s2 = new String(); +s2.toString = function() { return "baz"; }; +assertEq(s2 + s2, ""); + +var s3 = new String(); +s3.valueOf = function() { return "quux"; }; +assertEq(s3 + s3, "quuxquux"); + +function testNonStringAddition() +{ + var s = new String(); + assertEq(s + s, ""); + + var s2 = new String(); + s2.toString = function() { return "baz"; }; + assertEq(s2 + s2, ""); + + var s3 = new String(); + s3.valueOf = function() { return "quux"; }; + assertEq(s3 + s3, "quuxquux"); +} +testNonStringAddition(); + + +// String as bracketed property name + +var obj = { primitive: 17, valueOf: 42, toString: 8675309 }; + +var s = new String("primitive"); +assertEq(obj[s], 17); + +var s2 = new String("primitive"); +s2.valueOf = function() { return "valueOf"; } +assertEq(obj[s2], 17); + +var s3 = new String("primitive"); +s3.toString = function() { return "toString"; }; +assertEq(obj[s3], 8675309); + +function testPropertyNameToString() +{ + var obj = { primitive: 17, valueOf: 42, toString: 8675309 }; + + var s = new String("primitive"); + assertEq(obj[s], 17); + + var s2 = new String("primitive"); + s2.valueOf = function() { return "valueOf"; } + assertEq(obj[s2], 17); + + var s3 = new String("primitive"); + s3.toString = function() { return "toString"; }; + assertEq(obj[s3], 8675309); +} +testPropertyNameToString(); + + +// String as property name with |in| operator + +var s = new String(); +assertEq(s in { "": 5 }, true); + +var s2 = new String(); +s.toString = function() { return "baz"; }; +assertEq(s in { baz: 42 }, true); + +var s3 = new String(); +s3.valueOf = function() { return "quux"; }; +assertEq(s3 in { "": 17 }, true); + +function testInOperatorName() +{ + var s = new String(); + assertEq(s in { "": 5 }, true); + + var s2 = new String(); + s.toString = function() { return "baz"; }; + assertEq(s in { baz: 42 }, true); + + var s3 = new String(); + s3.valueOf = function() { return "quux"; }; + assertEq(s3 in { "": 17 }, true); +} +testInOperatorName(); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); |