-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Array.fill and TypedArray.fill polyfills #3103
Conversation
|
||
// implementation for typed arrays | ||
if (!Int8Array.prototype.fill) { | ||
Int8Array.prototype.fill = Array.prototype.fill; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work correctly if Array.fill
implementation was provided (not polyfilled)? might be worth splitting out the function and using it for all polyfills (including Array).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not expect a problem with this? But we only have IE to test on and that is missing both. I tested on IE and this works, and is suggested polyfill (see links I added)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your test worked.
However this code suggests it's possible that Array.fill
is provided by the browser while Int8Array.fill
isn't. Under such a circumstance this code very well may fail.
It is simple enough to make this code not fail and I don't really understand why you don't do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, currently a bit misleading because I would expect array-fill.js
to just polyfill Array#fill
. I'd put the rest in typedarray-fill.js
.
I do understand this polyfill comes from MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill But it definitely is a bit too verbose, with anti-patterns used:
|
@Maksims that's true, but this is just a polyfill for IE, not a generic code executing on all browsers. |
We got burnt on this being missing few times, and it likely gives us enough performance benefit to have the polyfill vs using the loop to work around it.