summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_5/Array/join-01.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_5/Array/join-01.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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/Array/join-01.js')
-rw-r--r--js/src/tests/ecma_5/Array/join-01.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/js/src/tests/ecma_5/Array/join-01.js b/js/src/tests/ecma_5/Array/join-01.js
new file mode 100644
index 000000000..3cc6cccd0
--- /dev/null
+++ b/js/src/tests/ecma_5/Array/join-01.js
@@ -0,0 +1,83 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ * Contributor:
+ * Jeff Walden <jwalden+code@mit.edu>
+ */
+
+//-----------------------------------------------------------------------------
+print("ES5: Array.prototype.join");
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+var count;
+var stringifyCounter = { toString: function() { count++; return "obj"; } };
+
+var arr = [1, 2, 3, 4, 5];
+assertEq(arr.join(), "1,2,3,4,5");
+assertEq(arr.join(","), "1,2,3,4,5");
+assertEq(arr.join(undefined), "1,2,3,4,5");
+assertEq(arr.join(4), "142434445");
+assertEq(arr.join(""), "12345");
+
+count = 0;
+assertEq(arr.join(stringifyCounter), "1obj2obj3obj4obj5");
+assertEq(count, 1);
+
+var holey = [1, 2, , 4, 5];
+assertEq(holey.join(), "1,2,,4,5");
+assertEq(holey.join(","), "1,2,,4,5");
+assertEq(holey.join(undefined), "1,2,,4,5");
+assertEq(holey.join(4), "14244445");
+
+count = 0;
+assertEq(holey.join(stringifyCounter), "1obj2objobj4obj5");
+assertEq(count, 1);
+
+var nully = [1, 2, 3, null, 5];
+assertEq(nully.join(), "1,2,3,,5");
+assertEq(nully.join(","), "1,2,3,,5");
+assertEq(nully.join(undefined), "1,2,3,,5");
+assertEq(nully.join(4), "14243445");
+
+count = 0;
+assertEq(nully.join(stringifyCounter), "1obj2obj3objobj5");
+assertEq(count, 1);
+
+var undefiney = [1, undefined, 3, 4, 5];
+assertEq(undefiney.join(), "1,,3,4,5");
+assertEq(undefiney.join(","), "1,,3,4,5");
+assertEq(undefiney.join(undefined), "1,,3,4,5");
+assertEq(undefiney.join(4), "14434445");
+
+count = 0;
+assertEq(undefiney.join(stringifyCounter), "1objobj3obj4obj5");
+assertEq(count, 1);
+
+var log = '';
+arr = {length: {valueOf: function () { log += "L"; return 2; }},
+ 0: "x", 1: "z"};
+var sep = {toString: function () { log += "S"; return "y"; }};
+assertEq(Array.prototype.join.call(arr, sep), "xyz");
+assertEq(log, "LS");
+
+var funky =
+ {
+ toString: function()
+ {
+ Array.prototype[1] = "chorp";
+ Object.prototype[3] = "fnord";
+ return "funky";
+ }
+ };
+var trailingHoles = [0, funky, /* 2 */, /* 3 */,];
+assertEq(trailingHoles.join(""), "0funkyfnord");
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");