js/src/jit-test/tests/arrays/ion-push-nonwritable-length.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 function f(arr)
michael@0 2 {
michael@0 3 assertEq(arr.push(4), 5); // if it doesn't throw :-)
michael@0 4 }
michael@0 5
michael@0 6 function test(out)
michael@0 7 {
michael@0 8 // Create an array of arrays, to be iterated over for [].push-calling. We
michael@0 9 // can't just loop on push on a single array with non-writable length because
michael@0 10 // push throws when called on an array with non-writable length.
michael@0 11 var arrs = out.arrs = [];
michael@0 12 for (var i = 0; i < 100; i++)
michael@0 13 arrs.push([0, 1, 2, 3]);
michael@0 14
michael@0 15 // Use a much-greater capacity than the eventual non-writable length, so that
michael@0 16 // the inline-push will work.
michael@0 17 var a = [0, 1, 2, 3, 4, 5, 6, 7];
michael@0 18 Object.defineProperty(a, "length", { writable: false, value: 4 });
michael@0 19
michael@0 20 arrs.push(a);
michael@0 21
michael@0 22 for (var i = 0, sz = arrs.length; i < sz; i++)
michael@0 23 {
michael@0 24 var arr = arrs[i];
michael@0 25 f(arr);
michael@0 26 }
michael@0 27 }
michael@0 28
michael@0 29 var obj = {};
michael@0 30 var a, arrs;
michael@0 31
michael@0 32 try
michael@0 33 {
michael@0 34 test(obj);
michael@0 35 throw new Error("didn't throw!");
michael@0 36 }
michael@0 37 catch (e)
michael@0 38 {
michael@0 39 assertEq(e instanceof TypeError, true, "expected TypeError, got " + e);
michael@0 40
michael@0 41 arrs = obj.arrs;
michael@0 42 assertEq(arrs.length, 101);
michael@0 43 for (var i = 0; i < 100; i++)
michael@0 44 {
michael@0 45 assertEq(arrs[i].length, 5, "unexpected length for arrs[" + i + "]");
michael@0 46 assertEq(arrs[i][0], 0, "bad element for arrs[" + i + "][0]");
michael@0 47 assertEq(arrs[i][1], 1, "bad element for arrs[" + i + "][1]");
michael@0 48 assertEq(arrs[i][2], 2, "bad element for arrs[" + i + "][2]");
michael@0 49 assertEq(arrs[i][3], 3, "bad element for arrs[" + i + "][3]");
michael@0 50 assertEq(arrs[i][4], 4, "bad element for arrs[" + i + "][4]");
michael@0 51 }
michael@0 52
michael@0 53 a = arrs[100];
michael@0 54 assertEq(a[0], 0, "bad element for a[" + i + "]");
michael@0 55 assertEq(a[1], 1, "bad element for a[" + i + "]");
michael@0 56 assertEq(a[2], 2, "bad element for a[" + i + "]");
michael@0 57 assertEq(a[3], 3, "bad element for a[" + i + "]");
michael@0 58 assertEq(a.hasOwnProperty(4), false, "element addition should have thrown");
michael@0 59 assertEq(a[4], undefined);
michael@0 60 assertEq(a.length, 4, "length shouldn't have been changed");
michael@0 61 }

mercurial