diff --git a/components/mjs/startup/hasown.js b/components/mjs/startup/hasown.js new file mode 100644 index 000000000..b886b536b --- /dev/null +++ b/components/mjs/startup/hasown.js @@ -0,0 +1,10 @@ +import {MathJax} from '#js/components/global.js'; + +if (!Object.hasOwn && MathJax.config.startup.polyfillHasOwn) { + Object.hasOwn = function (el, prop) { + if (typeof el === 'undefined' || el === null) { + throw new TypeError('Cannot convert undefined or null to object'); + } + return Object.prototype.hasOwnProperty.call(Object(el), prop); + } +} diff --git a/components/mjs/startup/init.js b/components/mjs/startup/init.js index f34d29799..8ae46803d 100644 --- a/components/mjs/startup/init.js +++ b/components/mjs/startup/init.js @@ -1,3 +1,4 @@ +import './hasown.js'; import './lib/startup.js'; import {combineDefaults} from '#js/components/global.js'; diff --git a/ts/components/startup.ts b/ts/components/startup.ts index 777bd5c70..49cf0e3bf 100644 --- a/ts/components/startup.ts +++ b/ts/components/startup.ts @@ -620,6 +620,7 @@ if (typeof MathJax._.startup === 'undefined') { typeset: true, ready: Startup.defaultReady.bind(Startup), pageReady: Startup.defaultPageReady.bind(Startup), + polyfillHasOwn: true, }); combineWithMathJax({ startup: Startup,