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 "Change Array by Copy" tests (stage 3) #3464

Merged
merged 86 commits into from Oct 18, 2022

Conversation

nicolo-ribaudo
Copy link
Member

This PR adds tests for https://github.com/tc39/proposal-change-array-by-copy, which reached consensus for Stage 3 at the March 2022 meeting.

I'm marking it as draft because I wrote these tests a few months ago, so I need to check that they are up-to-date with the current specification.

cc @acutmore @catamorphism

ljharb added a commit to es-shims/Array.prototype.toReversed that referenced this pull request Apr 4, 2022
ljharb added a commit to es-shims/Array.prototype.toSorted that referenced this pull request Apr 4, 2022
@rwaldron rwaldron added the has consensus This has committee consensus label Apr 4, 2022
ljharb added a commit to es-shims/Array.prototype.toSorted that referenced this pull request Apr 4, 2022
ljharb added a commit to es-shims/Array.prototype.toSpliced that referenced this pull request Apr 5, 2022
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Is it intended that [].with always throws, no matter what arguments are passed?

@rwaldron
Copy link
Contributor

rwaldron commented Apr 5, 2022

@nicolo-ribaudo I'm not going to ask you to move the files out of the metadata/ dirs, but this is a heads up that I will move them later. 👍

@acutmore
Copy link
Contributor

acutmore commented Apr 5, 2022

Is it intended that [].with always throws, no matter what arguments are passed?

Yep that is intentional. There are no valid indexes to change for an empty array. And passing no arguments or undefined is interpreted as passing index 0 the same as Array.prototype.at.

@acutmore
Copy link
Contributor

acutmore commented Apr 5, 2022

Does it make sense to add tests to ensure that toSorted and toReversed are not susceptible to Array.prototype.{sort,reverse} being patched? (e.g. An implementation similar to: Array.prototype.toSorted = function(f) { return [...this].sort(f) }.

I don't know if this is the type of thing that test262 would test or not?

Thoughts @nicolo-ribaudo, @rwaldron, @ljharb ?

@ljharb
Copy link
Member

ljharb commented Apr 5, 2022

I think it falls into the kind of category where it's one of the infinite things the spec doesn't permit and thus implicitly forbids - but unless there's an implementation that has that bug, we wouldn't necessarily need a test for it.

@acutmore
Copy link
Contributor

acutmore commented Apr 5, 2022

thanks @ljharb! Makes sense 😀

@rwaldron
Copy link
Contributor

rwaldron commented Apr 5, 2022

@acutmore & @ljharb as long as every step in each method's algorithm has coverage, that will be assured 👍

@ljharb
Copy link
Member

ljharb commented Apr 5, 2022

@rwaldron i mean, not necessarily - an implementation could potentially replace some of the steps with an observable call to another builtin method. in this case, some of my polyfills did that, and i had to revert that optimization because it broke some tests, so we're probably fine :-)

@nicolo-ribaudo
Copy link
Member Author

Updated, I'm sorry that it took a while!

Fyi, we are running these tests at tc39/proposal-change-array-by-copy#83 to make sure that they respect the behavior of the "reference implementation" (which matches 1:1 the spec).

@rwaldron If you have any suggestion about how I should rename those files let me know (I think I copied the metadata/ folder from somewhere else?), but if it's faster to just do it by yourself please go ahead 🙂

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review April 24, 2022 18:28
@ljharb
Copy link
Member

ljharb commented May 19, 2022

@nicolo-ribaudo i think this needs to be updated and rebased

@nicolo-ribaudo

This comment was marked as outdated.

@catamorphism
Copy link
Contributor

@rwaldron Could you let me know if I've addressed your comments adequately? Thanks!

@acutmore
Copy link
Contributor

acutmore commented Jun 8, 2022

EDIT: DONE

TODO: we should add a new test to cover yesterdays spec change tc39/proposal-change-array-by-copy#85

maybe something like:

let userLandCodeCalled = false;
const arr = new Uint8Array(2);
const nonPureValue = {
  valueOf() {
    userLandCodeCalled = true;
    arr[0] = 1;
    return 2;
  }
};
const indexToChange = 1;
const changed = arr.with(indexToChange, nonPureValue);
assert(userLandCodeCalled);
assertEqual(changed[0], 1); // the copy should include the mutation (previously would have returned 0)
assertEqual(changed[1], 2);

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

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

Partial review.

@catamorphism catamorphism force-pushed the change-array-by-copy branch 2 times, most recently from da6ea35 to 2f9b3d9 Compare October 18, 2022 00:22
@catamorphism
Copy link
Contributor

@Ms2ger I think I've addressed all your comments. Github still says "1 change requested" by you, but I can't find it anywhere even after expanding all the resolved conversations :/

@Ms2ger
Copy link
Contributor

Ms2ger commented Oct 18, 2022

Let's move any further work to new PRs.

@Ms2ger Ms2ger merged commit 6f4601d into tc39:main Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting author has consensus This has committee consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants