Fix math round when number > 2^52 on IE11#832
Fix math round when number > 2^52 on IE11#832TheModMaker merged 4 commits intoshaka-project:masterfrom
Conversation
TheModMaker
left a comment
There was a problem hiding this comment.
Interesting, I've never heard of this. But thanks for finding it and fixing it.
lib/polyfill/mathround.js
Outdated
| shaka.log.debug('mathRound.install'); | ||
|
|
||
| var agent = navigator.userAgent; | ||
| if (agent && agent.indexOf('rv:11.0') >= 0) { |
There was a problem hiding this comment.
It would be better to use feature detection instead of browser detection. How about:
if (Math.round(4503599627370497) != 4503599627370497) {
...
}
lib/polyfill/mathround.js
Outdated
| var original_mathRound = Math.round; | ||
| Math.round = function(number) { | ||
| var result = number; | ||
| // workaround for IE brain-dead Math.round() implementation |
There was a problem hiding this comment.
Please be more politically correct:
// Workaround for a rounding bug in IE11.| // https://stackoverflow.com/questions/12830742/javascript-math-round-bug-in-ie | ||
| if (number < 4503599627370496) { | ||
| result = original_mathRound(number); | ||
| } |
There was a problem hiding this comment.
Add a comment that includes why it doesn't need to be rounded. Something like "Otherwise, due to the precision of JavaScript numbers, the number must already be an integer."
shaka-player.uncompiled.js
Outdated
| goog.require('shaka.polyfill.Promise'); | ||
| goog.require('shaka.polyfill.VTTCue'); | ||
| goog.require('shaka.polyfill.VideoPlaybackQuality'); | ||
| goog.require('shaka.polyfill.MathRound'); |
There was a problem hiding this comment.
Alphabetize these calls.
lib/polyfill/mathround.js
Outdated
| var result = number; | ||
| // workaround for IE brain-dead Math.round() implementation | ||
| // https://stackoverflow.com/questions/12830742/javascript-math-round-bug-in-ie | ||
| if (number < 4503599627370496) { |
There was a problem hiding this comment.
This constant would be more readable as 0x10000000000000, I think. Also, please move this to a static const. Something like:
/**
Finally, please be careful about < vs <=. From the stackoverflow thread, it appears that this constant does round correctly, so we should use the original for inputs <= the constant.
|
@TheModMaker @joeyparrish Thanks for the review - fixed. |
joeyparrish
left a comment
There was a problem hiding this comment.
Looks good to me. @TheModMaker, any feedback?
TheModMaker
left a comment
There was a problem hiding this comment.
LGTM. Let me run this through our build bot.
|
All tests passed! |
Don't use math round on ie11 if number > 2^52.
|
Cherry-picked to v2.1.3. |
based on https://stackoverflow.com/questions/12830742/javascript-math-round-bug-in-ie
The issue is that the url that the dash utils provide sometimes wrong due to the Math.round on IE.
https://github.com/google/shaka-player/blob/master/lib/dash/mpd_utils.js#L101