How did I lose inline JavaScript objects and all global variables?

I am working on a Umbraco site that should work in large browsers, including IE 11, and I came across a strange problem that I can only replicate on IE 11.

At some point, the script for the TinyMCE plug-in attempts to execute this code (about four calls in depth) in response to the blur event:

  function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*"); } 

and when trying to create a RegExp object, it throws an exception "The object does not support this action." cls defined and has the expected value.

During a pause (using the Visual Studio debugger) in an unhandled exception, I made a small check.

It turns out that RegExp was undefined . I found this extremely strange.

A little more research has shown that ALL built-in objects were undefined. Number, Array, Object, Math ... all of them. In addition, although I could list global keys, all values ​​were also undefined.

In more scary mode, I could use console windows or immediate windows within the problem area to create regular expression objects using the /pattern/ syntax.

But this condition is true only in the scope of the event handler. As soon as the event handler exits, all built-in objects and values ​​of global variables have been restored.

How can you even lose access to the built-in JavaScript objects without losing access to the main JavaScript parser and engine?

And, once lost, can they be restored?

+6
source share
1 answer

I also ran into this problem and suggested that you also have problems with the TinyMCE CodeMirror plugin, this problem is caused by this line in codemirror.js:

 on(window, "blur", function () { return forEachCodeMirror(onBlur); }) 

where window refers to the iframe containing the CodeMirror editor.

This iframe is inside the TinyMCE dialog box. I found that the error only occurs when the iframe (or the element inside it) loses focus at the same time that the dialog is closed, removing the iframe from the DOM. You can verify this by first clicking outside the iframe (for example, on the page overlay) before closing the dialog.

It seems that IE11 raises the blur event after it began to destroy the iframe window object. I would classify this as a bug in IE11 that will never be fixed. Since we probably don’t care about the blur event in the iframe that is removed from the DOM, we can work around the problem by changing the problem line to skip it in this case:

 on(window, "blur", function () { if (window.RegExp) return forEachCodeMirror(onBlur); }) 
+1
source

Source: https://habr.com/ru/post/1012239/


All Articles