Commit a6fd69ac authored by cbruni's avatar cbruni Committed by Commit bot

[elements] Add more tests to increase coverage

BUG=

Review URL: https://codereview.chromium.org/1873833002

Cr-Commit-Position: refs/heads/master@{#35371}
parent 2e329666
......@@ -146,3 +146,16 @@
f(a, {});
assertEquals(10, a.f());
})();
(function testDoubleArrayPush() {
var a = [];
var max = 1000;
for (var i = 0; i < max; i++) {
a.push(i + 0.1);
}
assertEquals(max, a.length);
for (var i = 0; i < max; i++) {
assertEquals(i+0.1, a[i]);
}
})();
......@@ -300,6 +300,55 @@
}
})();
// Check the behaviour when approaching maximal values for length.
(function() {
for (var i = 0; i < 7; i++) {
try {
new Array(Math.pow(2, 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5);
throw 'Should have thrown RangeError';
} catch (e) {
assertTrue(e instanceof RangeError);
}
// Check smi boundary
var bigNum = (1 << 30) - 3;
var array = new Array(bigNum);
array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7);
assertEquals(bigNum + 7, array.length);
}
})();
(function() {
for (var i = 0; i < 7; i++) {
var a = [7, 8, 9];
a.splice(0, 0, 1, 2, 3, 4, 5, 6);
assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a);
assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)");
assertEquals(undefined, a[10]);
}
})();
(function testSpliceDeleteDouble() {
var a = [1.1, 1.2, 1.3, 1.4];
a.splice(2, 1)
assertEquals([1.1, 1.2, 1.4], a);
})();
// Past this point the ArrayProtector is invalidated since we modify the
// Array.prototype.
// Check the case of JS builtin .splice()
(function() {
for (var i = 0; i < 7; i++) {
var array = [1, 2, 3, 4];
Array.prototype[3] = 'foo'; // To force JS builtin.
var spliced = array.splice();
assertEquals([], spliced);
assertEquals([1, 2, 3, 4], array);
}
})();
// Now check the case with array of holes and some elements on prototype.
(function() {
......@@ -350,7 +399,6 @@
}
})();
// Now check the case with array of holes and some elements on prototype.
(function() {
var len = 9;
......@@ -397,46 +445,3 @@
"array.hasOwnProperty(Math.pow(2, 32) - 2)");
}
})();
// Check the case of JS builtin .splice()
(function() {
for (var i = 0; i < 7; i++) {
var array = [1, 2, 3, 4];
Array.prototype[3] = 'foo'; // To force JS builtin.
var spliced = array.splice();
assertEquals([], spliced);
assertEquals([1, 2, 3, 4], array);
}
})();
// Check the behaviour when approaching maximal values for length.
(function() {
for (var i = 0; i < 7; i++) {
try {
new Array(Math.pow(2, 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5);
throw 'Should have thrown RangeError';
} catch (e) {
assertTrue(e instanceof RangeError);
}
// Check smi boundary
var bigNum = (1 << 30) - 3;
var array = new Array(bigNum);
array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7);
assertEquals(bigNum + 7, array.length);
}
})();
(function() {
for (var i = 0; i < 7; i++) {
var a = [7, 8, 9];
a.splice(0, 0, 1, 2, 3, 4, 5, 6);
assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a);
assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)");
assertEquals(undefined, a[10]);
}
})();
......@@ -178,3 +178,17 @@ function load_a(x) {
}
load_deleted_property_using_IC();
(function deleteLargeDoubleArrayAtEnd() {
var o = {};
var max = 100000;
for (var i = 0; i <= max; i++) {
o[i] = 1.1;
}
delete o[max];
for (var i = 0; i < max; i++) {
assertEquals(1.1, o[i]);
}
assertEquals(undefined, o[max]);
})();
......@@ -39,3 +39,24 @@ function testStringWrapper(string) {
testStringWrapper(string);
assertEquals(undefined, string[limit]);
})();
(function testReconfigureStringWrapperElements() {
var s = new String('abc');
// Can't reconfigure string contents.
assertThrows(() => Object.defineProperty(s, '1', {value: "value"}), TypeError);
// Configure a property outside the string range
var value = 'v1';
Object.defineProperty(s, '3', {
get: () => {return value},
configurable:true
});
assertEquals('v1', s[3]);
value = 'v2';
assertEquals('v2', s[3]);
Object.defineProperty(s, '3', {value: 'v3', configurable: false});
assertEquals('v3', s[3]);
assertThrows(() => Object.defineProperty(s, '3', {value:2}), TypeError);
})();
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