js/src/jit-test/tests/ion/array-splice.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 function test1() {
michael@0 2 // splice GetElement calls are observable and should be executed even if
michael@0 3 // the return value of splice is unused.
michael@0 4 Object.defineProperty(Object.prototype, "0", {get: function() {
michael@0 5 c++;
michael@0 6 }, set: function() {}});
michael@0 7 var arr = [,,,];
michael@0 8 var c = 0;
michael@0 9 for (var i=0; i<100; i++) {
michael@0 10 arr.splice(0, 1);
michael@0 11 arr.length = 1;
michael@0 12 }
michael@0 13
michael@0 14 assertEq(c, 100);
michael@0 15 }
michael@0 16 test1();
michael@0 17
michael@0 18 function test2() {
michael@0 19 var arr = [];
michael@0 20 for (var i=0; i<100; i++)
michael@0 21 arr.push(i);
michael@0 22 for (var i=0; i<40; i++)
michael@0 23 arr.splice(0, 2);
michael@0 24 assertEq(arr.length, 20);
michael@0 25 assertEq(arr[0], 80);
michael@0 26 }
michael@0 27 test2();
michael@0 28
michael@0 29 function testNonArray() {
michael@0 30 for (var i=0; i<10; i++) {
michael@0 31 var o = {splice:[].splice, 0:"a", 1:"b", 2:"c", length:3};
michael@0 32 o.splice(0, 2);
michael@0 33 assertEq(o.length, 1);
michael@0 34 assertEq(o[0], "c");
michael@0 35 }
michael@0 36 }
michael@0 37 testNonArray();

mercurial