Skip to content

Commit

Permalink
Merge pull request #6022 from video-dev/bugfix/is-safe-integer-polyfill
Browse files Browse the repository at this point in the history
Add polyfill for isSafeInteger
  • Loading branch information
robwalch authored Dec 7, 2023
2 parents 5e972ca + e0d2692 commit 094db5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ const babelTsWithPresetEnvTargets = ({ targets, stripConsole }) =>
'isFiniteNumber',
path.resolve('src/polyfills/number'),
);
} else if (
espath.get('callee').matchesPattern('Number.isSafeInteger')
) {
espath.node.callee = importHelper.addNamed(
espath,
'isSafeInteger',
path.resolve('src/polyfills/number'),
);
} else if (
espath.get('callee').matchesPattern('Number.MAX_SAFE_INTEGER')
) {
Expand Down
8 changes: 8 additions & 0 deletions src/polyfills/number.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// https://caniuse.com/mdn-javascript_builtins_number_isfinite
export const isFiniteNumber =
Number.isFinite ||
function (value) {
return typeof value === 'number' && isFinite(value);
};

// https://caniuse.com/mdn-javascript_builtins_number_issafeinteger
export const isSafeInteger =
Number.isSafeInteger ||
function (value) {
return typeof value === 'number' && Math.abs(value) <= MAX_SAFE_INTEGER;
};

export const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
4 changes: 2 additions & 2 deletions src/utils/mp4-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ export function getStartDTS(
// convert base time to seconds
const startTime = baseTime / scale;
if (
isFinite(startTime) &&
Number.isFinite(startTime) &&
(result === null || startTime < result)
) {
return startTime;
Expand All @@ -560,7 +560,7 @@ export function getStartDTS(
);
if (
start !== null &&
isFinite(start) &&
Number.isFinite(start) &&
(result === null || start < result)
) {
return start;
Expand Down

0 comments on commit 094db5e

Please sign in to comment.