Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"SCRIPT5002: Function expected" when passing array from other window to Set constructor #1987

Closed
Shepard opened this issue Nov 11, 2016 · 4 comments
Labels

Comments

@Shepard
Copy link

Shepard commented Nov 11, 2016

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>
@Shepard
Copy link
Author

Shepard commented Nov 11, 2016

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.

@dilijev
Copy link
Contributor

dilijev commented Nov 15, 2016

Hi @Shepard, thanks for the issue. It looks like this is an issue with DOM APIs. You can open a bug on the Edge tracker under that category. Please see: https://github.com/Microsoft/ChakraCore/wiki/External-Issues#but-the-edge-issue-tracker-sent-me-here

@Shepard
Copy link
Author

Shepard commented Nov 18, 2016

@dilijev
Copy link
Contributor

dilijev commented Nov 19, 2016

Thanks! Closing this issue as External.

@dilijev dilijev closed this as completed Nov 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants