Skip to content

Add tests for Array#splice when only the first argument is provided. - #385

Open
Xotic750 wants to merge 1 commit into
es-shims:masterfrom
Xotic750:spliceargs
Open

Xotic750 wants to merge 1 commit into
es-shims:masterfrom
Xotic750:spliceargs

Conversation

@Xotic750

Copy link
Copy Markdown
Contributor

@Xotic750

Copy link
Copy Markdown
Contributor Author

I am actually wondering what the correct results should be as I get different answers from multiple environments.

My initial expectation was what I got from Google Chrome 48.0.2564.97 and from FireFox v43.0.3
IE9 & IE10 also give

[]
[0]
[0, 1]

But all node versions in the travis tests seem to give

[0, 1, 2]
[1, 2]
[2]

IE 11 gives me

undefined
[0]
[0,1]

IE8 gives

[0, 1, 2]
[0, 1, 2]
[0, 1, 2]

ES5.1 spec http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.12

Array.prototype.splice (start, deleteCount [ , item1 [ , item2 [ , … ] ] ] )

9 Else if the number of actual arguments is 1, then

a Let insertCount be 0.

b Let actualDeleteCount be len – actualStart.

ES6 spec http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.splice

Array.prototype.splice (start, deleteCount , ...items )

9 Else if the number of actual arguments is 1, then

a Let insertCount be 0.

b Let actualDeleteCount be len – actualStart.

I'm going to have to run it through the polyfil and check the result.

This gives

[]
[]
[]

@ljharb

ljharb commented Jan 28, 2016

Copy link
Copy Markdown
Member

I believe this is actually a change from ES5 to ES6, which would mean that es5-shim would not check or test for deviations from ES6 semantics. I'll leave this open to verify later.

@Xotic750

Copy link
Copy Markdown
Contributor Author

Ie11 is clearly in the wrong whichever :P
But an interesting mix of results.

@ljharb

ljharb commented Apr 22, 2022

Copy link
Copy Markdown
Member

In latest Safari and Chrome and Firefox, these tests fail natively, so I think these are invalid tests.

However, when I update your tests so they're not assuming that splice returns the receiver - since it in fact returns the removed elements - they all pass, including in IE 8. I'll update this and land.

@ljharb

ljharb commented Apr 22, 2022

Copy link
Copy Markdown
Member

@Xotic750 oops, i can't; can you please check the "allow edits" box on the RHS of the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants