Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-22377

Prototype.js can still break the standard Array.from method

    XMLWordPrintable

Details

    • Medium
    • N/A
    • N/A

    Description

      The fix we did in XWIKI-20183 is not perfect. We restore the original Array.from using a setTimeout(() => {}, 0) hoping that our callback is called after the Prototpye.js code is loaded (and Array.from is overridden). This happens most of the time in practice because Prototype.js is cached. But it is possible that our callback is called to early, when Prototype.js is not cached and / or the network is slow. I can reproduce this consistently using Chrome with cache disabled and setting throttling to "Slow 4G" or even "Fast 4G".

      This issue causes for instance the MathJax macro to fail. I used this content to reproduce:

      Normal Wiki text followed by a formula
      
      {{mathjax}}
      \begin{eqnarray}
      1 & = & a x + b y\label{eq:first} \\
      0 & = & c x + d y\label{eq:second}
      \end{eqnarray}
      {{/mathjax}}
      
      Solving equation {{mathjax}}\ref{eq:second}{{/mathjax}} for {{mathjax}}x{{/mathjax}} and substituting back into equation {{mathjax}}\ref{eq:first}{{/mathjax}} yields
      
      {{mathjax}}
      \begin{equation}
      y = \frac{c}{cb-ad}
      \end{equation}
      {{/mathjax}}
      

      The failure is in tex-chtml.js at this line:

      Array.from(this._fallback)[0].item(c, u)
      

      where this._fallback is an iterable object, as per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol . Prototype's implementation of Array.from is too old to support iterable objects.

      As a result the MathJax macro shows "Math input error", and the JavaScript exception is:

      Cannot read properties of undefined (reading 'item')
      

      because Prototype's Array.from returns an empty array when given an iterable object.

      Attachments

        Issue Links

          Activity

            People

              mflorea Marius Dumitru Florea
              mflorea Marius Dumitru Florea
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: