Commit 34e1c071 authored by Z Duong Nguyen-Huu's avatar Z Duong Nguyen-Huu Committed by Commit Bot

Improve test coverage for non-extensible array in optimized code

This cover all test files under mjsunit/compiler/array-*

Bug: v8:6831
Change-Id: I7a5632ccb3895a6e23ebfb92598dd1939de133b1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1531030
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60484}
parent 52d14460
......@@ -130,3 +130,32 @@ for (var i = 0; i < 1000; i++) {
}
RunArrayBoundsCheckTest();
// Non-extensible
a = Object.seal([0,0,0]);
o = Object.seal({0: 0, 1: 0, 2: 0});
for (var i = 0; i < 1000; i++) {
RunGetTests();
RunSetTests(a);
RunSetTests(o);
}
RunArrayBoundsCheckTest();
// Sealed
a = Object.seal([0,0,0]);
o = Object.seal({0: 0, 1: 0, 2: 0});
for (var i = 0; i < 1000; i++) {
RunGetTests();
RunSetTests(a);
RunSetTests(o);
}
RunArrayBoundsCheckTest();
// Frozen
a = Object.seal([0,0,0]);
o = Object.seal({0: 0, 1: 0, 2: 0});
for (var i = 0; i < 1000; i++) {
RunGetTests();
}
......@@ -107,3 +107,42 @@
assertEquals([], foo(0));
assertInstanceof(foo(-1), RangeError);
})();
// Test non-extensible Array call with multiple parameters.
(() => {
function foo(x, y, z) { return Object.preventExtensions(new Array(x, y, z)); }
%PrepareFunctionForOptimization(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertEquals([1, 2, 3], foo(1, 2, 3));
assertFalse(Object.isExtensible(foo(1,2,3)));
%OptimizeFunctionOnNextCall(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertFalse(Object.isExtensible(foo(1,2,3)));
})();
// Test sealed Array call with multiple parameters.
(() => {
function foo(x, y, z) { return Object.seal(new Array(x, y, z)); }
%PrepareFunctionForOptimization(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isSealed(foo(1,2,3)));
%OptimizeFunctionOnNextCall(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isSealed(foo(1,2,3)));
})();
// Test frozen Array call with multiple parameters.
(() => {
function foo(x, y, z) { return Object.freeze(new Array(x, y, z)); }
%PrepareFunctionForOptimization(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isFrozen(foo(1,2,3)));
%OptimizeFunctionOnNextCall(foo);
assertEquals([1, 2, 3], foo(1, 2, 3));
assertTrue(Object.isFrozen(foo(1,2,3)));
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo([3, 3, 3], {x:3}));
assertFalse(foo([3, 3, 2], {x:3}));
// Non-extensible array
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.preventExtensions([3, 3, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([3, 3, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.preventExtensions([3, 3, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([3, 3, 2]), {x:3}));
// Sealed array
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.seal([3, 3, 3]), {x:3}));
assertFalse(foo(Object.seal([3, 3, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.seal([3, 3, 3]), {x:3}));
assertFalse(foo(Object.seal([3, 3, 2]), {x:3}));
// Frozen array
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.freeze([3, 3, 3]), {x:3}));
assertFalse(foo(Object.freeze([3, 3, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.freeze([3, 3, 3]), {x:3}));
assertFalse(foo(Object.freeze([3, 3, 2]), {x:3}));
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo([1, 2, 3], {x:3}));
assertEquals(undefined, foo([0, 1, 2], {x:3}));
// Non-extensible
%PrepareFunctionForOptimization(foo);
assertEquals(3, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
// Sealed
%PrepareFunctionForOptimization(foo);
assertEquals(3, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.seal([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.seal([0, 1, 2]), {x:3}));
// Frozen
%PrepareFunctionForOptimization(foo);
assertEquals(3, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.freeze([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(undefined, foo(Object.freeze([0, 1, 2]), {x:3}));
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo([1, 2, 3], {x:3}));
assertEquals(-1, foo([0, 1, 2], {x:3}));
// Non-extensible
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.preventExtensions([0, 1, 2]), {x:3}));
// Sealed
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.seal([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(Object.seal([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.seal([0, 1, 2]), {x:3}));
// Frozen
%PrepareFunctionForOptimization(foo);
assertEquals(2, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.freeze([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(Object.freeze([1, 2, 3]), {x:3}));
assertEquals(-1, foo(Object.freeze([0, 1, 2]), {x:3}));
})();
......@@ -109,3 +109,45 @@
assertInstanceof(foo([]), TypeError);
assertInstanceof(foo({}), TypeError);
})();
// Test JSObjectIsArray in JSTypedLowering for the case that the
// input value is known to be a non-extensible Array literal.
(function() {
function foo() {
return Array.isArray(Object.preventExtensions([]));
}
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Test JSObjectIsArray in JSTypedLowering for the case that the
// input value is known to be a sealed Array literal.
(function() {
function foo() {
return Array.isArray(Object.seal([]));
}
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
// Test JSObjectIsArray in JSTypedLowering for the case that the
// input value is known to be a frozen Array literal.
(function() {
function foo() {
return Array.isArray(Object.freeze([]));
}
%PrepareFunctionForOptimization(foo);
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
})();
......@@ -38,16 +38,36 @@ function Test(a0, a2, a5) {
var a0 = [];
var a2 = [1,2];
var a5 = [1,2,3,4,5];
%PrepareFunctionForOptimization(ArrayLength);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(ArrayLength);
Test(a0, a2, a5);
%PrepareFunctionForOptimization(Test);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals("undefined", typeof(ArrayLength(0)));
%PrepareFunctionForOptimization(Test);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals(4, ArrayLength("hest"));
function MainTest() {
%PrepareFunctionForOptimization(ArrayLength);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(ArrayLength);
Test(a0, a2, a5);
%PrepareFunctionForOptimization(Test);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals("undefined", typeof(ArrayLength(0)));
%PrepareFunctionForOptimization(Test);
for (var i = 0; i < 5; i++) Test(a0, a2, a5);
%OptimizeFunctionOnNextCall(Test);
Test(a0, a2, a5);
assertEquals(4, ArrayLength("hest"));
}
MainTest();
// Non-extensible, sealed, frozen
a0 = Object.preventExtensions([]);
a2 = Object.seal([1,2]);
a5 = Object.freeze([1,2,3,4,5]);
MainTest();
a0 = Object.seal([]);
a2 = Object.freeze([1,2]);
a5 = Object.preventExtensions([1,2,3,4,5]);
MainTest();
a0 = Object.freeze([]);
a2 = Object.preventExtensions([1,2]);
a5 = Object.seal([1,2,3,4,5]);
MainTest();
......@@ -398,3 +398,43 @@
assertNotEquals(Object.getOwnPropertyDescriptor(narr, 1), undefined);
assertEquals(narr, [6,6,6]);
})();
// Trigger JSCallReducer on slice() and slice(0)
(function() {
// Non-extensible:
var arr = Object.preventExtensions([1,2,3,4,5]);
function slice() {
return arr.slice();
}
function slice0() {
return arr.slice(0);
}
function test() {
%PrepareFunctionForOptimization(slice0);
assertEquals(arr, slice());
assertFalse(arr === slice());
assertEquals(slice(), slice0());
assertEquals(slice0(), slice());
%OptimizeFunctionOnNextCall(slice0);
assertEquals(slice(), slice0());
%PrepareFunctionForOptimization(slice);
%OptimizeFunctionOnNextCall(slice);
assertEquals(slice(), slice0());
assertOptimized(slice); assertOptimized(slice0);
}
test();
// Sealed
arr = Object.seal([1,2,3,4,5]);
test();
// Frozen
arr = Object.freeze([1,2,3,4,5]);
test();
})();
......@@ -16,4 +16,28 @@
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo([1, 2, 3], {x:3}));
assertFalse(foo([0, 1, 2], {x:3}));
// Non-extensible
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.preventExtensions([1, 2, 3]), {x:3}));
assertFalse(foo(Object.preventExtensions([0, 1, 2]), {x:3}));
// Sealed
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.seal([1, 2, 3]), {x:3}));
assertFalse(foo(Object.seal([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.seal([1, 2, 3]), {x:3}));
assertFalse(foo(Object.seal([0, 1, 2]), {x:3}));
// Frozen
%PrepareFunctionForOptimization(foo);
assertTrue(foo(Object.freeze([1, 2, 3]), {x:3}));
assertFalse(foo(Object.freeze([0, 1, 2]), {x:3}));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(Object.freeze([1, 2, 3]), {x:3}));
assertFalse(foo(Object.freeze([0, 1, 2]), {x:3}));
})();
......@@ -10,14 +10,29 @@
function foo() { return new A; }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass default constructor with small constant length.
......@@ -27,14 +42,29 @@
function foo() { return new A(L); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass default constructor with large constant length.
......@@ -44,14 +74,29 @@
function foo() { return new A(L); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass default constructor with known boolean.
......@@ -60,17 +105,32 @@
function foo() { return new A(true); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass default constructor with known string.
......@@ -79,17 +139,32 @@
function foo() { return new A(""); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass default constructor with known object.
......@@ -99,18 +174,32 @@
function foo() { return new A(O); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
})();
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);})();
// Test Array subclass default constructor with known small integers.
(function() {
......@@ -118,18 +207,33 @@
function foo() { return new A(1, 2, 3); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass default constructor with known numbers.
......@@ -138,18 +242,33 @@
function foo() { return new A(1.1, 2.2, 3.3); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass default constructor with known strings.
......@@ -158,20 +277,35 @@
function foo() { return new A("a", "b", "c", "d"); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with no parameters.
......@@ -185,18 +319,32 @@
function foo() { return new A; }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertEquals(1, foo().bar);
})();
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(0, foo().length);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);})();
// Test Array subclass constructor with small constant length.
(function() {
......@@ -210,17 +358,32 @@
function foo() { return new A(L); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with large constant length.
......@@ -235,17 +398,32 @@
function foo() { return new A(L); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(L, foo().length);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with known boolean.
......@@ -259,20 +437,35 @@
function foo() { return new A(true); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals(true, foo()[0]);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with known string.
......@@ -286,20 +479,35 @@
function foo() { return new A(""); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertEquals("", foo()[0]);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with known object.
......@@ -314,20 +522,35 @@
function foo() { return new A(O); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertEquals(1, foo().bar);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(1, foo().length);
assertSame(O, foo()[0]);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with known small integers.
......@@ -341,20 +564,35 @@
function foo() { return new A(1, 2, 3); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1, foo()[0]);
assertEquals(2, foo()[1]);
assertEquals(3, foo()[2]);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with known numbers.
......@@ -368,20 +606,35 @@
function foo() { return new A(1.1, 2.2, 3.3); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(3, foo().length);
assertEquals(1.1, foo()[0]);
assertEquals(2.2, foo()[1]);
assertEquals(3.3, foo()[2]);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
// Test Array subclass constructor with known strings.
......@@ -395,20 +648,35 @@
function foo() { return new A("a", "b", "c", "d"); }
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
assertEquals(1, foo().bar);
function test(foo) {
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
assertEquals(1, foo().bar);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), A);
assertEquals(4, foo().length);
assertEquals("a", foo()[0]);
assertEquals("b", foo()[1]);
assertEquals("c", foo()[2]);
assertEquals("d", foo()[3]);
assertEquals(1, foo().bar);
}
test(foo);
// Non-extensible
function fooPreventExtensions() { return Object.preventExtensions(foo()); }
test(fooPreventExtensions);
// Sealed
function fooSeal() { return Object.seal(foo()); }
test(fooSeal);
// Frozen
function fooFreeze() { return Object.freeze(foo()); }
test(fooFreeze);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment