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: replace indexOf with typedArrayIndexOf for IE11 support #417

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

gesinger
Copy link
Contributor

@gesinger gesinger commented Jul 5, 2022

No description provided.

Comment on lines +1 to +19
// IE11 doesn't support indexOf for TypedArrays.
// Once IE11 support is dropped, this function should be removed.
var typedArrayIndexOf = (typedArray, element, fromIndex) => {
if (!typedArray) {
return -1;
}

var currentIndex = fromIndex;

for (; currentIndex < typedArray.length; currentIndex++) {
if (typedArray[currentIndex] === element) {
return currentIndex;
}
}

return -1;
};

module.exports = { typedArrayIndexOf };
Copy link
Contributor

@pszemus pszemus Jul 6, 2022

Choose a reason for hiding this comment

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

Function does not support negative fromIndex whereas indexOf does. Let's hope nobody uses it that way.

Copy link
Contributor

@pszemus pszemus left a comment

Choose a reason for hiding this comment

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

@gesinger You could also replace for loop with typedArrayIndexOf for PRIV frames.

@gesinger
Copy link
Contributor Author

gesinger commented Jul 6, 2022

@gesinger You could also replace for loop with typedArrayIndexOf for PRIV frames.

I didn't change PRIV for now because the behavior is slightly different, in that it takes a subarray of the typed array from a non-existent area in the event that 0 is not found. Although the behavior is not great, I didn't want to potentially break anything and the logic becomes a bit more complex with typedArrayIndexOf. It'll be a good opportunity to change the logic for PRIV as a whole in the next major version.

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

3 participants