Skip to content

Commit

Permalink
[Fix] handle no deleteCount to splice() in Opera
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tom Jenkinson authored and ljharb committed Jul 30, 2019
1 parent 7c7a82b commit f0dd919
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion es5-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,11 @@
var len = ES.ToUint32(O.length);
var relativeStart = ES.ToInteger(start);
var actualStart = relativeStart < 0 ? max((len + relativeStart), 0) : min(relativeStart, len);
var actualDeleteCount = min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
var actualDeleteCount = arguments.length === 0
? 0
: arguments.length === 1
? len - actualStart
: min(max(ES.ToInteger(deleteCount), 0), len - actualStart);

var k = 0;
var from;
Expand Down
6 changes: 6 additions & 0 deletions tests/spec/s-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,12 @@ describe('Array', function () {
expect(test.splice(0)).toEqual(test.splice(0, 0));
});

// ES6 introduced a proper default value
it('defaults deleteCount to length - start if there is only 1 argument', function () {
expect([0, 1, 2].splice(0).length).toBe(3);
expect([0, 1, 2].splice(1).length).toBe(2);
});

it('basic implementation test 1', function () {
expect(test.splice(0, 0)).toEqual([]);
});
Expand Down

0 comments on commit f0dd919

Please sign in to comment.