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

Improve tests for CreateByteDataBlock #3826

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

Conversation

dewren99
Copy link

Please see the discussion on tc39/ecma262#3052

@dewren99 dewren99 requested a review from a team as a code owner May 11, 2023 17:28
Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! This looks correct to me.

Personally I didn't mind having the 2⁵³-1 case in the test corpus as a test of "If it is impossible to create such a Data Block, throw a RangeError exception", but I can also see the point of view that it is not a 100% reliable test.

@ptomato
Copy link
Contributor

ptomato commented May 18, 2023

I'm not sure what the [NotSupported] ArrayBuffer output means in esmeta. @jhnaldo is this an expected failure?

Copy link
Contributor

@anba anba left a comment

Choose a reason for hiding this comment

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

Please revert the changes to this file, because tc39/ecma262#3052 can't be tested using the ArrayBuffer constructor:

The ArrayBuffer constructor applies ToIndex on its input parameter. ToIndex throws a RangeError when the input number is >253-1. So the observed RangeError after modifying the file isn't thrown from CreateByteDataBlock, but instead it's thrown from ToIndex.

@michaelficarra
Copy link
Member

because tc39/ecma262#3052 can't be tested using the ArrayBuffer constructor:

@anba That's true, but we're also not going to advance an iterator 253 times to hit that guard. These tests are still valid, though, and an improvement. How do you suggest we test tc39/ecma262#3052?

@anba
Copy link
Contributor

anba commented Jun 6, 2023

Yes, they're valid, but they test a different code path. If we want to keep them, they should be placed into a new file.

How do you suggest we test tc39/ecma262#3052?

TypedArray constructors should hit the new range check in CreateByteDataBlock:
TypedArray
AllocateTypedArray
AllocateTypedArrayBuffer
AllocateArrayBuffer
CreateByteDataBlock

AllocateTypedArrayBuffer performs elementSize × length, where length is a user-input coerced through ToIndex and elementSize is an integer in [1, 2, 4, 8]. So new Int16Array(2 ** 52) should hit the new range check, right?

@dewren99
Copy link
Author

dewren99 commented Jun 8, 2023

Hey @michaelficarra @ptomato, just letting you know since I had your approval for the PR, if @anba's suggestion sounds good I will start working on creating the tests under TypedArray constructor(s).

Do you still want to merge these improvements to CreateByteDataBlock tests under a different PR or should I keep this PR open?

@michaelficarra
Copy link
Member

@anba You're right, I wasn't aware of the multiplication in AllocateTypedArrayBuffer step 3. So there's a way to trigger it other than iterating. Thanks.

@dewren99 I still like these changes as-is, but they don't exercise tc39/ecma262#3052. It's up to @ptomato and @tc39/test262-maintainers whether we should include those tests in this PR or make a separate one. If you want to get started right away, it'd probably be safest to just open a separate PR with those tests.

@ptomato
Copy link
Contributor

ptomato commented Jun 12, 2023

It's fine to include them in this PR as far as I'm concerned. Are you planning to adopt @anba's suggestion of placing these tests in a different file, as well?

@dewren99
Copy link
Author

dewren99 commented Jun 12, 2023

@ptomato I haven't had the chance to look if there are already tests for TypedArray constructor(s), but if there are, I was thinking about adding the new tests there. Otherwise I was going to create a new file for the tests.

Or do you have recommendation on where I should add them? If it fine I can just update this PR to include new tests too.

@ptomato
Copy link
Contributor

ptomato commented Jun 13, 2023

I'm not too familiar with the TypedArray constructors tests, but @jugglinmike might be able to answer that question.

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

Successfully merging this pull request may close these issues.

4 participants