From b919bb02b7c1e676f58f81af140b69313d5d2d3f Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 10 Sep 2025 12:35:02 -0400 Subject: [PATCH 1/2] Provide hasOwn polyfill configuration option. --- components/mjs/startup/hasown.js | 10 ++++++++++ components/mjs/startup/init.js | 1 + ts/components/startup.ts | 1 + 3 files changed, 12 insertions(+) create mode 100644 components/mjs/startup/hasown.js 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..9d19beed2 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: false, }); combineWithMathJax({ startup: Startup, From 5651923006c451dbc78826bb628407ad4630e306 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 15 Sep 2025 08:28:40 -0400 Subject: [PATCH 2/2] Make the polyfill opt-out rather than opt-in --- ts/components/startup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/components/startup.ts b/ts/components/startup.ts index 9d19beed2..49cf0e3bf 100644 --- a/ts/components/startup.ts +++ b/ts/components/startup.ts @@ -620,7 +620,7 @@ if (typeof MathJax._.startup === 'undefined') { typeset: true, ready: Startup.defaultReady.bind(Startup), pageReady: Startup.defaultPageReady.bind(Startup), - polyfillHasOwn: false, + polyfillHasOwn: true, }); combineWithMathJax({ startup: Startup,