1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_8_5/extensions/array-length-protochange.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,35 @@ 1.4 +// Any copyright is dedicated to the Public Domain. 1.5 +// http://creativecommons.org/licenses/publicdomain/ 1.6 + 1.7 +//----------------------------------------------------------------------------- 1.8 +var BUGNUMBER = 548671; 1.9 +var summary = 1.10 + "Don't use a shared-permanent inherited property to implement " + 1.11 + "[].length or (function(){}).length"; 1.12 + 1.13 +print(BUGNUMBER + ": " + summary); 1.14 + 1.15 +/************** 1.16 + * BEGIN TEST * 1.17 + **************/ 1.18 + 1.19 +var a = [1, 2, 3]; 1.20 +a.__proto__ = null; 1.21 +reportCompare("length" in a, true, "length should be own property of array"); 1.22 +reportCompare(Object.hasOwnProperty.call(a, "length"), true, 1.23 + "length should be own property of array"); 1.24 +reportCompare(a.length, 3, "array length should be 3"); 1.25 + 1.26 +var a = [], b = []; 1.27 +b.__proto__ = a; 1.28 +reportCompare(b.hasOwnProperty("length"), true, 1.29 + "length should be own property of array"); 1.30 +b.length = 42; 1.31 +reportCompare(b.length, 42, "should have mutated b's (own) length"); 1.32 +reportCompare(a.length, 0, "should not have mutated a's (own) length"); 1.33 + 1.34 + 1.35 +if (typeof reportCompare === "function") 1.36 + reportCompare(true, true); 1.37 + 1.38 +print("All tests passed!");