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

Clarify "for each enumerable own property" in structured clone #557

Closed
shvaikalesh opened this issue Jan 25, 2016 · 10 comments · Fixed by #764
Closed

Clarify "for each enumerable own property" in structured clone #557

shvaikalesh opened this issue Jan 25, 2016 · 10 comments · Fixed by #764
Labels

Comments

@shvaikalesh
Copy link
Contributor

Please, see internal structured cloning algorithm, step 8:

for each enumerable own property in input

Should it invoke [[OwnPropertyKeys]] and filter by enumerability (and copy properties with symbols as keys) or just call EnumerableOwnNames?

I have tested the algorithm in Safari 9, Chrome 47 and Firefox 46 and it seems they are doing EnumerableOwnNames.

@zcorpan zcorpan added the clarification Standard could be clearer label Jan 25, 2016
@domenic
Copy link
Member

domenic commented Jan 28, 2016

There are a few differentiating features between the two choices:

  • In the rare instance someone chose to explicitly define an enumerable symbol-named property, should it be included? (EnumerableOwnNames says no)
    • Relatedly, if the key is a Symbol, should [[GetOwnProperty]] be triggered or no? Observable by proxies. (EnumerableOwnNames says no.)
  • Should the order be for-in order, or the well-defined order given by [[OwnPropertyKeys]]? (EnumerableOwnNames says for-in order)

@ajklein, any comments? It sounds like we should just spec EnumerableOwnNames.

@shvaikalesh
Copy link
Contributor Author

Should the order be for-in order, or the well-defined order given by [[OwnPropertyKeys]]? (EnumerableOwnNames says for-in order)

Correct me if I am wrong, but for in calls [[Enumerate]] which calls [[OwnPropertyKeys]]. They both sort the output keys in the same well-defined way.

@domenic
Copy link
Member

domenic commented Jan 28, 2016

(Please stop linking to the outdated spec; use https://tc39.github.io/ecma262/.)

[[Enumerate]] does obtain its keys "as if by calling its [[OwnPropertyKeys]] internal method", but the ordering it returns them in is implementation-defined: "The mechanics and order of enumerating the properties is not specified but must conform to the rules specified below."

@shvaikalesh
Copy link
Contributor Author

The mechanics and order of enumerating the properties is not specified but must conform to the rules specified below.

Sorry, missed that.

Regarding proxies: structured clone throws on Proxies in Firefox. This may be related to #575.

@annevk
Copy link
Member

annevk commented Feb 29, 2016

Fixed by #727.

@shvaikalesh my apologies for not asking you for review while working on that PR. Review of the revived algorithm that is in terms of the current ECMAScript standard would be most welcome.

@annevk annevk closed this as completed Feb 29, 2016
@domenic
Copy link
Member

domenic commented Feb 29, 2016

Hmm it appears actually #727 changed things to be all own string properties, eliminating the enumerable qualifier :-/. That is probably bad?

@annevk
Copy link
Member

annevk commented Feb 29, 2016

Isn't that what implementations actually do though?

@annevk
Copy link
Member

annevk commented Feb 29, 2016

Run

<script>
 var y = { test: "TEST" }
 x = Object.create(y)
 w(x)
 onmessage = e => w(e.data)
 postMessage(x, "*")
</script>

in Live DOM Viewer. First logs x having one property, then zero.

@domenic
Copy link
Member

domenic commented Feb 29, 2016

That's not enumerability you're testing; that's own-ness.

https://jsbin.com/radumu/edit?html,output shows that non-enumerable properties are not copied. Whereas in the new spec they are.

It seems like you need a check. I'll work on a quick PR.

@annevk annevk reopened this Feb 29, 2016
@annevk
Copy link
Member

annevk commented Feb 29, 2016

Fair. (Not around to review, will land tomorrow.)

domenic added a commit that referenced this issue Feb 29, 2016
Closes #557, fixing a regression introduced in
bfb960c where the enumerability of a
property was no longer checked (even in a vague way like the spec's
previous "for each enumerable own property").
domenic added a commit that referenced this issue Feb 29, 2016
Closes #557, fixing a regression introduced in
bfb960c where the enumerability of a
property was no longer checked (even in a vague way like the spec's
previous "for each enumerable own property").
annevk pushed a commit that referenced this issue Mar 1, 2016
Closes #557, fixing a regression introduced in
bfb960c where the enumerability of a
property was no longer checked (even in a vague way like the spec's
previous "for each enumerable own property").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants