Skip to content

Remove TypedArray fill polyfill #4241

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

Closed
Tyriar opened this issue Oct 30, 2022 · 0 comments · Fixed by #4249
Closed

Remove TypedArray fill polyfill #4241

Tyriar opened this issue Oct 30, 2022 · 0 comments · Fixed by #4249
Labels
type/debt Technical debt that could slow us down in the long run

Comments

@Tyriar
Copy link
Member

Tyriar commented Oct 30, 2022

/**
* polyfill for TypedArray.fill
* This is needed to support .fill in all safari versions and IE 11.
*/
export function fill<T extends TypedArray>(array: T, value: number, start?: number, end?: number): T {
// all modern engines that support .fill
if (array.fill) {
return array.fill(value, start, end) as T;
}
return fillFallback(array, value, start, end);
}
export function fillFallback<T extends TypedArray>(array: T, value: number, start: number = 0, end: number = array.length): T {
// safari and IE 11
// since IE 11 does not support Array.prototype.fill either
// we cannot use the suggested polyfill from MDN
// instead we simply fall back to looping
if (start >= array.length) {
return array;
}
start = (array.length + start) % array.length;
if (end >= array.length) {
end = array.length;
} else {
end = (array.length + end) % array.length;
}
for (let i = start; i < end; ++i) {
array[i] = value;
}
return array;
}

@Tyriar Tyriar added the type/debt Technical debt that could slow us down in the long run label Oct 30, 2022
Tyriar added a commit to Tyriar/xterm.js that referenced this issue Oct 31, 2022
Tyriar added a commit to Tyriar/xterm.js that referenced this issue Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/debt Technical debt that could slow us down in the long run
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant