Commit 16073072 authored by alph@chromium.org's avatar alph@chromium.org

DevTools: Fix a bug in Array.remove

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

git-svn-id: svn://svn.chromium.org/blink/trunk@169940 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1d84b119
This test checks Web Inspector utilities. This test checks Web Inspector utilities.
Running: remove
Running: orderedMergeIntersect Running: orderedMergeIntersect
Running: binaryIndexOfTest Running: binaryIndexOfTest
......
...@@ -6,6 +6,28 @@ ...@@ -6,6 +6,28 @@
function test() function test()
{ {
InspectorTest.runTestSuite([ InspectorTest.runTestSuite([
function remove(next)
{
var testArrays = [
[], [], [],
[1], [1], [1],
[1, 2, 3, 4, 5, 4, 3, 2, 1], [1, 3, 4, 5, 4, 3, 2, 1], [1, 3, 4, 5, 4, 3, 1],
[2, 2, 2, 2, 2], [2, 2, 2, 2], [],
[2, 2, 2, 1, 2, 2, 3, 2], [2, 2, 1, 2, 2, 3, 2], [1, 3]
];
for (var i = 0; i < testArrays.length; i += 3) {
var actual = testArrays[i].slice(0);
var expected = testArrays[i + 1];
actual.remove(2, true);
InspectorTest.assertEquals(JSON.stringify(expected), JSON.stringify(actual), "remove(2, true) passed");
actual = testArrays[i].slice(0);
expected = testArrays[i + 2];
actual.remove(2, false);
InspectorTest.assertEquals(JSON.stringify(expected), JSON.stringify(actual), "remove(2, false) passed");
}
next();
},
function orderedMergeIntersect(next) function orderedMergeIntersect(next)
{ {
function comparator(a, b) function comparator(a, b)
......
...@@ -374,23 +374,22 @@ Object.defineProperty(Array.prototype, "remove", ...@@ -374,23 +374,22 @@ Object.defineProperty(Array.prototype, "remove",
{ {
/** /**
* @param {!T} value * @param {!T} value
* @param {boolean=} onlyFirst * @param {boolean=} firstOnly
* @this {Array.<!T>} * @this {Array.<!T>}
* @template T * @template T
*/ */
value: function(value, onlyFirst) value: function(value, firstOnly)
{ {
if (onlyFirst) { if (firstOnly) {
var index = this.indexOf(value); var index = this.indexOf(value);
if (index !== -1) if (index !== -1)
this.splice(index, 1); this.splice(index, 1);
return; return;
} }
var length = this.length; for (var i = 0; i < this.length; ++i) {
for (var i = 0; i < length; ++i) {
if (this[i] === value) if (this[i] === value)
this.splice(i, 1); this.splice(i--, 1);
} }
} }
}); });
......
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