Skip to content

Commit 59a9b65

Browse files
authored
Merge pull request #1351 from mathjax/feature/hasown-polyfill
Provide hasOwn polyfill configuration option.
2 parents 6f058dc + 495b97b commit 59a9b65

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

components/mjs/startup/hasown.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {MathJax} from '#js/components/global.js';
2+
3+
if (!Object.hasOwn && MathJax.config.startup.polyfillHasOwn) {
4+
Object.hasOwn = function (el, prop) {
5+
if (typeof el === 'undefined' || el === null) {
6+
throw new TypeError('Cannot convert undefined or null to object');
7+
}
8+
return Object.prototype.hasOwnProperty.call(Object(el), prop);
9+
}
10+
}

components/mjs/startup/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './hasown.js'; // Can be removed with ES2024 implementation of Object.hasown
12
import './lib/startup.js';
23

34
import {combineDefaults} from '#js/components/global.js';

ts/components/startup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ if (typeof MathJax._.startup === 'undefined') {
620620
typeset: true,
621621
ready: Startup.defaultReady.bind(Startup),
622622
pageReady: Startup.defaultPageReady.bind(Startup),
623+
polyfillHasOwn: true, // Can be removed with ES2024 implementation of Object.hasown
623624
});
624625
combineWithMathJax({
625626
startup: Startup,

0 commit comments

Comments
 (0)