michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: * Contributor: michael@0: * Jeff Walden michael@0: */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 858381; michael@0: var summary = michael@0: "Array length redefinition behavior with non-configurable elements"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: function addDataProperty(obj, prop, value, enumerable, configurable, writable) michael@0: { michael@0: var desc = michael@0: { enumerable: enumerable, michael@0: configurable: configurable, michael@0: writable: writable, michael@0: value: value }; michael@0: Object.defineProperty(obj, prop, desc); michael@0: } michael@0: michael@0: function nonstrict() michael@0: { michael@0: var arr = [0, , 2, , , 5]; michael@0: michael@0: addDataProperty(arr, 31415926, "foo", true, true, true); michael@0: addDataProperty(arr, 123456789, "bar", true, true, false); michael@0: addDataProperty(arr, 8675309, "qux", false, true, true); michael@0: addDataProperty(arr, 1735039, "eit", false, true, false); michael@0: addDataProperty(arr, 987654321, "fun", false, true, false); michael@0: michael@0: // non-array indexes to spice things up michael@0: addDataProperty(arr, "foopy", "sdfsd", false, false, false); michael@0: addDataProperty(arr, 4294967296, "psych", true, false, false); michael@0: addDataProperty(arr, 4294967295, "psych", true, false, false); michael@0: michael@0: addDataProperty(arr, 27182818, "eep", false, false, false); michael@0: michael@0: // Truncate...but only as far as possible. michael@0: arr.length = 1; michael@0: michael@0: assertEq(arr.length, 27182819); michael@0: michael@0: var props = Object.getOwnPropertyNames(arr).sort(); michael@0: var expected = michael@0: ["0", "2", "5", "1735039", "8675309", "27182818", michael@0: "foopy", "4294967296", "4294967295", "length"].sort(); michael@0: michael@0: assertEq(props.length, expected.length); michael@0: for (var i = 0; i < props.length; i++) michael@0: assertEq(props[i], expected[i], "unexpected property: " + props[i]); michael@0: } michael@0: nonstrict(); michael@0: michael@0: function strict() michael@0: { michael@0: "use strict"; michael@0: michael@0: var arr = [0, , 2, , , 5]; michael@0: michael@0: addDataProperty(arr, 31415926, "foo", true, true, true); michael@0: addDataProperty(arr, 123456789, "bar", true, true, false); michael@0: addDataProperty(arr, 8675309, "qux", false, true, true); michael@0: addDataProperty(arr, 1735039, "eit", false, true, false); michael@0: addDataProperty(arr, 987654321, "fun", false, true, false); michael@0: michael@0: // non-array indexes to spice things up michael@0: addDataProperty(arr, "foopy", "sdfsd", false, false, false); michael@0: addDataProperty(arr, 4294967296, "psych", true, false, false); michael@0: addDataProperty(arr, 4294967295, "psych", true, false, false); michael@0: michael@0: addDataProperty(arr, 27182818, "eep", false, false, false); michael@0: michael@0: try michael@0: { michael@0: arr.length = 1; michael@0: throw new Error("didn't throw?!"); michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, michael@0: "non-configurable property should trigger TypeError, got " + e); michael@0: } michael@0: michael@0: assertEq(arr.length, 27182819); michael@0: michael@0: var props = Object.getOwnPropertyNames(arr).sort(); michael@0: var expected = michael@0: ["0", "2", "5", "1735039", "8675309", "27182818", michael@0: "foopy", "4294967296", "4294967295", "length"].sort(); michael@0: michael@0: assertEq(props.length, expected.length); michael@0: for (var i = 0; i < props.length; i++) michael@0: assertEq(props[i], expected[i], "unexpected property: " + props[i]); michael@0: } michael@0: strict(); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");