Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | * Contributor: |
michael@0 | 5 | * Jeff Walden <jwalden+code@mit.edu> |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | //----------------------------------------------------------------------------- |
michael@0 | 9 | print("ES5: Array.prototype.join"); |
michael@0 | 10 | |
michael@0 | 11 | /************** |
michael@0 | 12 | * BEGIN TEST * |
michael@0 | 13 | **************/ |
michael@0 | 14 | |
michael@0 | 15 | var count; |
michael@0 | 16 | var stringifyCounter = { toString: function() { count++; return "obj"; } }; |
michael@0 | 17 | |
michael@0 | 18 | var arr = [1, 2, 3, 4, 5]; |
michael@0 | 19 | assertEq(arr.join(), "1,2,3,4,5"); |
michael@0 | 20 | assertEq(arr.join(","), "1,2,3,4,5"); |
michael@0 | 21 | assertEq(arr.join(undefined), "1,2,3,4,5"); |
michael@0 | 22 | assertEq(arr.join(4), "142434445"); |
michael@0 | 23 | assertEq(arr.join(""), "12345"); |
michael@0 | 24 | |
michael@0 | 25 | count = 0; |
michael@0 | 26 | assertEq(arr.join(stringifyCounter), "1obj2obj3obj4obj5"); |
michael@0 | 27 | assertEq(count, 1); |
michael@0 | 28 | |
michael@0 | 29 | var holey = [1, 2, , 4, 5]; |
michael@0 | 30 | assertEq(holey.join(), "1,2,,4,5"); |
michael@0 | 31 | assertEq(holey.join(","), "1,2,,4,5"); |
michael@0 | 32 | assertEq(holey.join(undefined), "1,2,,4,5"); |
michael@0 | 33 | assertEq(holey.join(4), "14244445"); |
michael@0 | 34 | |
michael@0 | 35 | count = 0; |
michael@0 | 36 | assertEq(holey.join(stringifyCounter), "1obj2objobj4obj5"); |
michael@0 | 37 | assertEq(count, 1); |
michael@0 | 38 | |
michael@0 | 39 | var nully = [1, 2, 3, null, 5]; |
michael@0 | 40 | assertEq(nully.join(), "1,2,3,,5"); |
michael@0 | 41 | assertEq(nully.join(","), "1,2,3,,5"); |
michael@0 | 42 | assertEq(nully.join(undefined), "1,2,3,,5"); |
michael@0 | 43 | assertEq(nully.join(4), "14243445"); |
michael@0 | 44 | |
michael@0 | 45 | count = 0; |
michael@0 | 46 | assertEq(nully.join(stringifyCounter), "1obj2obj3objobj5"); |
michael@0 | 47 | assertEq(count, 1); |
michael@0 | 48 | |
michael@0 | 49 | var undefiney = [1, undefined, 3, 4, 5]; |
michael@0 | 50 | assertEq(undefiney.join(), "1,,3,4,5"); |
michael@0 | 51 | assertEq(undefiney.join(","), "1,,3,4,5"); |
michael@0 | 52 | assertEq(undefiney.join(undefined), "1,,3,4,5"); |
michael@0 | 53 | assertEq(undefiney.join(4), "14434445"); |
michael@0 | 54 | |
michael@0 | 55 | count = 0; |
michael@0 | 56 | assertEq(undefiney.join(stringifyCounter), "1objobj3obj4obj5"); |
michael@0 | 57 | assertEq(count, 1); |
michael@0 | 58 | |
michael@0 | 59 | var log = ''; |
michael@0 | 60 | arr = {length: {valueOf: function () { log += "L"; return 2; }}, |
michael@0 | 61 | 0: "x", 1: "z"}; |
michael@0 | 62 | var sep = {toString: function () { log += "S"; return "y"; }}; |
michael@0 | 63 | assertEq(Array.prototype.join.call(arr, sep), "xyz"); |
michael@0 | 64 | assertEq(log, "LS"); |
michael@0 | 65 | |
michael@0 | 66 | var funky = |
michael@0 | 67 | { |
michael@0 | 68 | toString: function() |
michael@0 | 69 | { |
michael@0 | 70 | Array.prototype[1] = "chorp"; |
michael@0 | 71 | Object.prototype[3] = "fnord"; |
michael@0 | 72 | return "funky"; |
michael@0 | 73 | } |
michael@0 | 74 | }; |
michael@0 | 75 | var trailingHoles = [0, funky, /* 2 */, /* 3 */,]; |
michael@0 | 76 | assertEq(trailingHoles.join(""), "0funkyfnord"); |
michael@0 | 77 | |
michael@0 | 78 | /******************************************************************************/ |
michael@0 | 79 | |
michael@0 | 80 | if (typeof reportCompare === "function") |
michael@0 | 81 | reportCompare(true, true); |
michael@0 | 82 | |
michael@0 | 83 | print("Tests complete"); |