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

Array methods should respect the realm of the this. #293

Open
jdalton opened this issue Oct 7, 2014 · 9 comments
Open

Array methods should respect the realm of the this. #293

jdalton opened this issue Oct 7, 2014 · 9 comments

Comments

@jdalton
Copy link
Contributor

jdalton commented Oct 7, 2014

For example see step 9 of this https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.filter

var i = document.createElement('iframe');
i.name = 'iframe';
i.style.display = 'none';
document.body.insertBefore(i, document.body.firstChild);

var f = frames.iframe;
f.document.write('<script><\/script>');
f.document.close();

var otherArray = f.Array(1,2,3);
var sliced = Array.prototype.slice.call(otherArray, 2);

console.log(sliced instanceof Array);  // should be `false`
console.log(sliced instanceof f.Array); // should be `true`
@ljharb ljharb self-assigned this Oct 7, 2014
@ljharb
Copy link
Collaborator

ljharb commented Oct 7, 2014

Is there any way to test this without an iframe (in node)? The spec specifies "exotic Array object" only - is an Array from another iframe exotic?

@ljharb ljharb removed their assignment Oct 7, 2014
@domenic
Copy link

domenic commented Oct 7, 2014

Realms are a red herring. Subclasses are the more interesting case where consulting this.constructor matters.

@jdalton
Copy link
Contributor Author

jdalton commented Oct 7, 2014

Is there any way to test this without an iframe (in node)?

Yap, you can use require('vm').

@jdalton
Copy link
Contributor Author

jdalton commented Oct 7, 2014

There's the perf side to consider; wrapping all those methods would be hella bad for that. Maybe this is one that es6-shim opts out of and just documents the lack of support.

@ljharb
Copy link
Collaborator

ljharb commented Oct 7, 2014

Indeed, that's one of my main concerns. At the least, we can ensure that our actual shims do the right thing, even if we choose not to detect and override every existing Array method :-)

@Yaffle
Copy link
Contributor

Yaffle commented Oct 31, 2014

Array.prototype.map.call(document.querySelectorAll("*"), function (e) {
  return e.tagName;
});

am i right, that this code should throw error (because NodeList is not constructable) according to spec?

@domenic
Copy link

domenic commented Oct 31, 2014

@Yaffle yes, I believe so.

@Yaffle
Copy link
Contributor

Yaffle commented Oct 31, 2014

seems, this was discussed here:
https://esdiscuss.org/topic/array-prototype-slice-web-compat-issue#content-17
OK, i am not using Array.prototype.map for NodeLists anyway, so I am fine with it.

@ljharb
Copy link
Collaborator

ljharb commented Oct 31, 2014

Wow, that's a shame, that's a really common existing pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants