Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Xotic750
Copy link
Contributor

@Xotic750
Copy link
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
Copy link
Member

ljharb commented Jan 28, 2016

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
Contributor Author

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

@ljharb
Copy link
Member

ljharb commented Apr 22, 2022

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
Copy link
Member

ljharb commented Apr 22, 2022

@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.

None yet

2 participants