1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/strict/15.4.5.1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 + 1.6 +/* 1.7 + * Any copyright is dedicated to the Public Domain. 1.8 + * http://creativecommons.org/licenses/publicdomain/ 1.9 + */ 1.10 + 1.11 +var out = {}; 1.12 + 1.13 +function arr() { 1.14 + return Object.defineProperty([1, 2, 3, 4], 2, {configurable: false}); 1.15 +} 1.16 + 1.17 +function nonStrict1(out) 1.18 +{ 1.19 + var a = out.array = arr(); 1.20 + a.length = 2; 1.21 +} 1.22 + 1.23 +function strict1(out) 1.24 +{ 1.25 + "use strict"; 1.26 + var a = out.array = arr(); 1.27 + a.length = 2; 1.28 + return a; 1.29 +} 1.30 + 1.31 +out.array = null; 1.32 +nonStrict1(out); 1.33 +assertEq(deepEqual(out.array, [1, 2, 3]), true); 1.34 + 1.35 +out.array = null; 1.36 +try 1.37 +{ 1.38 + strict1(out); 1.39 + throw "no error"; 1.40 +} 1.41 +catch (e) 1.42 +{ 1.43 + assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); 1.44 +} 1.45 +assertEq(deepEqual(out.array, [1, 2, 3]), true); 1.46 + 1.47 +// Internally, SpiderMonkey has two representations for arrays: 1.48 +// fast-but-inflexible, and slow-but-flexible. Adding a non-index property 1.49 +// to an array turns it into the latter. We should test on both kinds. 1.50 +function addx(obj) { 1.51 + obj.x = 5; 1.52 + return obj; 1.53 +} 1.54 + 1.55 +function nonStrict2(out) 1.56 +{ 1.57 + var a = out.array = addx(arr()); 1.58 + a.length = 2; 1.59 +} 1.60 + 1.61 +function strict2(out) 1.62 +{ 1.63 + "use strict"; 1.64 + var a = out.array = addx(arr()); 1.65 + a.length = 2; 1.66 +} 1.67 + 1.68 +out.array = null; 1.69 +nonStrict2(out); 1.70 +assertEq(deepEqual(out.array, addx([1, 2, 3])), true); 1.71 + 1.72 +out.array = null; 1.73 +try 1.74 +{ 1.75 + strict2(out); 1.76 + throw "no error"; 1.77 +} 1.78 +catch (e) 1.79 +{ 1.80 + assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); 1.81 +} 1.82 +assertEq(deepEqual(out.array, addx([1, 2, 3])), true); 1.83 + 1.84 +if (typeof reportCompare === "function") 1.85 + reportCompare(true, true); 1.86 + 1.87 +print("Tests complete");