Skip to content

Add test case when countBytes in TA.p.slice is set to zero #4537

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

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

Conversation

anba
Copy link
Contributor

@anba anba commented Jul 16, 2025

countBytes can be set to zero in step 14.d when resizable array buffers are used.

`countBytes` can be set to zero in step 14.d when resizable array
buffers are used.
@anba anba requested a review from a team as a code owner July 16, 2025 12:50
@anba
Copy link
Contributor Author

anba commented Jul 16, 2025

This case isn't covered by existing tests.

Copy link
Contributor

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

Thanks; just a few suggestions.

var sliced = ta.slice(start);

// Result typed array has the correct length with all elements set to zero.
assert.compareArray(sliced, new TA(N - startIndex));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.compareArray(sliced, new TA(N - startIndex));
assert.compareArray(sliced, new TA(N - startIndex), TA.name + ", start index " + startIndex);

var ta = new SourceTA(buffer);

// Create own "constructor" property to create a different result typed array.
ta.constructor = TargetTA;
Copy link
Contributor

Choose a reason for hiding this comment

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

For not breaking in a hardened environment:

Suggested change
ta.constructor = TargetTA;
Object.defineProperty(ta, "constructor", { value: TargetTA });

Comment on lines +77 to +78
// Result typed array has the correct length with all elements set to zero.
assert.compareArray(sliced, new TargetTA(N - startIndex));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Result typed array has the correct length with all elements set to zero.
assert.compareArray(sliced, new TargetTA(N - startIndex));
// Result typed array has the correct type and length with all elements set to zero.
var label = SourceTA.name + " to " + TargetTA.name;
assert.sameValue(sliced.constructor, TargetTA, label);
assert.compareArray(sliced, new TargetTA(N - startIndex),
label + ", start index " + startIndex);

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.

3 participants