michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: var out = {}; michael@0: michael@0: function arr() { michael@0: return Object.defineProperty([1, 2, 3, 4], 2, {configurable: false}); michael@0: } michael@0: michael@0: function nonStrict1(out) michael@0: { michael@0: var a = out.array = arr(); michael@0: a.length = 2; michael@0: } michael@0: michael@0: function strict1(out) michael@0: { michael@0: "use strict"; michael@0: var a = out.array = arr(); michael@0: a.length = 2; michael@0: return a; michael@0: } michael@0: michael@0: out.array = null; michael@0: nonStrict1(out); michael@0: assertEq(deepEqual(out.array, [1, 2, 3]), true); michael@0: michael@0: out.array = null; michael@0: try michael@0: { michael@0: strict1(out); michael@0: throw "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); michael@0: } michael@0: assertEq(deepEqual(out.array, [1, 2, 3]), true); michael@0: michael@0: // Internally, SpiderMonkey has two representations for arrays: michael@0: // fast-but-inflexible, and slow-but-flexible. Adding a non-index property michael@0: // to an array turns it into the latter. We should test on both kinds. michael@0: function addx(obj) { michael@0: obj.x = 5; michael@0: return obj; michael@0: } michael@0: michael@0: function nonStrict2(out) michael@0: { michael@0: var a = out.array = addx(arr()); michael@0: a.length = 2; michael@0: } michael@0: michael@0: function strict2(out) michael@0: { michael@0: "use strict"; michael@0: var a = out.array = addx(arr()); michael@0: a.length = 2; michael@0: } michael@0: michael@0: out.array = null; michael@0: nonStrict2(out); michael@0: assertEq(deepEqual(out.array, addx([1, 2, 3])), true); michael@0: michael@0: out.array = null; michael@0: try michael@0: { michael@0: strict2(out); michael@0: throw "no error"; michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); michael@0: } michael@0: assertEq(deepEqual(out.array, addx([1, 2, 3])), true); michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");