You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a page (parent.html) that opens another page (child.html) in a new window. That child page calls a function that was defined globally in its opener, passing in an array. In that function, a new Set is created, passing the array received from the child window to the Set constructor. This leads to the error "SCRIPT5002: Function expected" on the console, pointing to the beginning of the line where the Set constructor is called.
In Chrome and Firefox this works. In IE11 it probably doesn't throw this error because Set doesn't support putting a collection into the constructor.
I assume the problem is that the array has the prototype from the child window and is therefore not compatible with what the Set constructor expects. The error can be circumvented by wrapping the array in an Array.from() call before passing it to the Set constructor, thus first creating an array that is compatible with the execution context of the parent window. My worry is that this leads to unnecessary memory consumption though (in my original page I pass very large arrays between the windows).
This happens when I open the files from a webserver (both pages on the same domain), I haven't tried it from the local file system.
The code to reproduce this is as follows:
parent.html:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
window.myFunction = function(array) {
var set = new Set(array);
console.log(set);
};
window.open("child.html", "dialog", 'toolbar=no, location=no, status=no, scrollbars=no, menubar=no, resizable=yes, width=100, height=100');
</script>
</body>
</html>
I should probably add that I tried to raise this as an Edge bug at first but was lead here from the Edge bug tracker when I picked JavaScript as the category.
I have a page (parent.html) that opens another page (child.html) in a new window. That child page calls a function that was defined globally in its opener, passing in an array. In that function, a new Set is created, passing the array received from the child window to the Set constructor. This leads to the error "SCRIPT5002: Function expected" on the console, pointing to the beginning of the line where the Set constructor is called.
In Chrome and Firefox this works. In IE11 it probably doesn't throw this error because Set doesn't support putting a collection into the constructor.
I assume the problem is that the array has the prototype from the child window and is therefore not compatible with what the Set constructor expects. The error can be circumvented by wrapping the array in an Array.from() call before passing it to the Set constructor, thus first creating an array that is compatible with the execution context of the parent window. My worry is that this leads to unnecessary memory consumption though (in my original page I pass very large arrays between the windows).
This happens when I open the files from a webserver (both pages on the same domain), I haven't tried it from the local file system.
The code to reproduce this is as follows:
parent.html:
child.html:
The text was updated successfully, but these errors were encountered: