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

Fix Array.prototype.copyWithin polyfill #2902

Closed
wants to merge 3 commits into from

Conversation

teppeis
Copy link
Contributor

@teppeis teppeis commented Apr 22, 2018

Improvement:

  • should handle negative params
  • should coerce params to integer
  • fix bug in deleting props of ArrayLike
  • should throw if this is null or undefined
  • should throw if impossible to delete props

Also this fixes .name and .length with defineProperty.
But if the policy of Closure Compiler for them is "won't fix", I will revert them.

I don't know how to run polyfill tests (#1504), but I confirmed this passed all Test262 tests for copyWithin. (https://gist.github.com/teppeis/c8a88f653cdd70ed3e3d6597ec1ee30c)

Ref:

@brad4d
Copy link
Contributor

brad4d commented Apr 25, 2018

@shicks could you review this one, since polyfills are really your thing?

@brad4d
Copy link
Contributor

brad4d commented Dec 27, 2018

Created internal issue b/122075328

@brad4d brad4d added the internal-issue-created An internal Google issue has been created to track this GitHub issue label Dec 27, 2018
Copy link
Member

@shicks shicks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay - I didn't see this until Bradford pinged me on the internal bug.

@teppeis
Copy link
Contributor Author

teppeis commented Dec 28, 2018

@shicks Thanks! I've fixed and commented, please review them.
I'll rebase on latest master if you want.

@shicks
Copy link
Member

shicks commented Jan 4, 2019

I'm not super familiar with the github code review tools - I marked two conversations as unresolved, so hopefully you'll see my responses now.

@brad4d brad4d assigned tjgq and unassigned shicks Jan 15, 2019
assertObjectEquals([1, 3, 4, 4, 5], [1, 2, 3, 4, 5].copyWithin(1, 2, -1));
},

testCopyWithin_throwsIfNullish() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test no longer passes. Please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? It should be pass and I believe it passes.

this is null and this.length is referred on the top of the polyfill function, so it should throw an error.
https://github.com/google/closure-compiler/pull/2902/files#diff-a5e0f0788d56ad46f3db1223fd3c8b5cR36

Copy link
Contributor

@tjgq tjgq Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look close enough: it fails because the start and target arguments are not optional (unfortunately, I don't think there's a way to run the polyfill tests externally, so there's no way for you to reproduce it). The best you can do is something like this:

Array.prototype.copyWithin.call(null, some_other_array, 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjgq understood. It is not a runtime test, but a type check failed. I added the second and the third argument.

});
},

testCopyWithin_throwIfFailToDeleteProperty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjgq Probably type check in 2nd arg of Object.defineProperty() failed, so I fixed it.

@tjgq tjgq closed this in 6dbfbbd Jan 23, 2019
@teppeis teppeis deleted the fix-array-copywithin branch January 23, 2019 23:48
@teppeis
Copy link
Contributor Author

teppeis commented Jan 24, 2019

@tjgq Thanks! 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes internal-issue-created An internal Google issue has been created to track this GitHub issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants