-
Notifications
You must be signed in to change notification settings - Fork 410
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
Infinite loop in Safari #79
Comments
Okay, thanks for the report. I'll take a look this weekend. What version of iOS? |
I had this issue on Safari 10.1 on my mac using macOS 10.12.4 |
Apologies for the delay. Is the following Object.keys({ '250': 0.5, '1000': 0.1 }).length === 2 |
|
Thanks, Martin. Please could you also tell me if running the following code fixes this issue if (Object.keys({'250': 0.5, '1000': 0.1}).length !== 2) {
Array.prototype.unshift = function () {
Array.prototype.splice.apply(this, Array.prototype.concat.apply([0, 0], arguments));
return this.length;
};
Array.prototype.shift = function () {
return Array.prototype.splice.call(this, 0, 1)[0];
};
} |
@MikeMcl That code works, but I don't think it's a good idea to change the Array prototype in a library. Other libraries may be depending upon other behavior. A better method is something like this. var shift, unshift;
if (Object.keys({'250': 0.5, '1000': 0.1}).length == 2) {
unshift = Function.prototype.call.bind(Array.prototype.unshift)
shift = Function.prototype.call.bind(Array.prototype.shift)
} else {
unshift = function(arr, /*new array elements */) {
Array.prototype.splice.apply(arr, Array.prototype.concat.apply([0, 0], Array.prototype.slice.call(arguments, 1));
return arr.length
}
shift = function (arr) {
return Array.prototype.splice.call(arr, 0, 1)[0];
};
} And then you can use the shift(myArr)
unshift(myArr, 3) |
Thanks for testing the code and for offering another possible solution. My preference would be to not have to make changes to my libraries to work around bugs elsewhere. Changing the prototype seems reasonable to me here because if the bug is present then the built-in For example, if the bug is present var arr = [0, 2147483648];
arr.shift();
arr[1] = 1;
// arr should be [2147483648, 1] but is [2147483648] in Safari |
I understand, but think about if every library owner has the same idea. Most code bases use 50-100 libraries. If every library overrides the Array prototype, it will be very inefficient and very unpredictable. |
FWIW, Safari 11.0 on Mac doesn't have this issue. It may also be fixed on 10.x updates. 11 is due for imminent release with new High Sierra update. |
@numbergames Thanks for the info. |
I was having a look to see if this could be globally fixed with JavaScript I didn't find a global fix, but I did come up with something that may be useful, though I can't test it as I don't have access to Safari. https://github.com/Xotic750/create-array-fix-x Link to tests https://rawgit.com/Xotic750/create-array-fix-x/master/tests/index.html |
Got an infinite loop while using
pow
Seems related to MikeMcl/bignumber.js#120
The text was updated successfully, but these errors were encountered: