Function expected" when passing array from other window to Set constructor

Confirmed Issue #9861897 • Assigned to travil

Details

Created
Nov 18, 2016
Privacy
This issue is public.
Found in
  • Microsoft Edge
Found in build #
14.14393
Reports
Reported by 2 people

Sign in to watch or report this issue.

Steps to reproduce

This bug was first opened for ChakraCore.


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>

child.html:

<!DOCTYPE html>
<html>
<head></head>
<body>

<button type="button" id="button">Click me!</button>

<script>

document.getElementById("button").addEventListener("click", function() {
    window.opener.myFunction([0, 1, 2]);
}, false);

</script>

</body>
</html>

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Status to “Confirmed”

    • I’m waiting fix too.

    • Microsoft Edge Team

      Changed Title from “Function expected" when passing array from other window to Set constructor” to “Function expected" when passing array from other window to Set constructor”

      Changed Assigned To to “travil”

    You need to sign in to your Microsoft account to add a comment.

    Sign in