Skip to content

Commit f0dd919

Browse files
Tom Jenkinsonljharb
Tom Jenkinson
authored andcommitted
[Fix] handle no deleteCount to splice() in Opera
In Opera 10.6 and 9.8, when the fix is applied and `deleteCount` is missing, no elements are deleted. This is incorrect - when `deleteCount` is missing the behavior should be to delete all elements from `start` onwards
1 parent 7c7a82b commit f0dd919

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

es5-shim.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,11 @@
821821
var len = ES.ToUint32(O.length);
822822
var relativeStart = ES.ToInteger(start);
823823
var actualStart = relativeStart < 0 ? max((len + relativeStart), 0) : min(relativeStart, len);
824-
var actualDeleteCount = min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
824+
var actualDeleteCount = arguments.length === 0
825+
? 0
826+
: arguments.length === 1
827+
? len - actualStart
828+
: min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
825829

826830
var k = 0;
827831
var from;

tests/spec/s-array.js

+6
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,12 @@ describe('Array', function () {
13681368
expect(test.splice(0)).toEqual(test.splice(0, 0));
13691369
});
13701370

1371+
// ES6 introduced a proper default value
1372+
it('defaults deleteCount to length - start if there is only 1 argument', function () {
1373+
expect([0, 1, 2].splice(0).length).toBe(3);
1374+
expect([0, 1, 2].splice(1).length).toBe(2);
1375+
});
1376+
13711377
it('basic implementation test 1', function () {
13721378
expect(test.splice(0, 0)).toEqual([]);
13731379
});

0 commit comments

Comments
 (0)