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

Per May 2016 TC39 consensus, Object.getOwnPropertyDescriptors is now stage 4! #582

Merged
merged 1 commit into from
Jun 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -22683,6 +22683,21 @@ <h1>Object.getOwnPropertyDescriptor ( _O_, _P_ )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-object.getownpropertydescriptors">
<h1>Object.getOwnPropertyDescriptors ( _O_ )</h1>
<p>When the `getOwnPropertyDescriptors` function is called, the following steps are taken:</p>
<emu-alg>
1. Let _obj_ be ? ToObject(_O_).
1. Let _ownKeys_ be ? _obj_.[[OwnPropertyKeys]]().
1. Let _descriptors_ be ! ObjectCreate(%ObjectPrototype%).
1. Repeat, for each element _key_ of _ownKeys_ in List order,
1. Let _desc_ be ? _obj_.[[GetOwnProperty]](_key_).
1. Let _descriptor_ be ! FromPropertyDescriptor(_desc_).
1. Perform ! CreateDataProperty(_descriptors_, _key_, _descriptor_).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we run this step also when descriptor is undefined? (Could happen if obj is a proxy, for instance.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's perfectly fine. If a Proxy chooses to expose that it is a Proxy by providing a key in [[OwnPropertyKeys]] that does not have a corresponding descriptor in [[GetOwnProperty]], I think that intentional information leak should be propagated.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you Object.getOwnpropertyDescriptor(proxy, key) and/or
Reflect.ownKeys(proxyObject) ?

On Wed, May 25, 2016 at 3:24 PM, Claude Pache [email protected]
wrote:

In spec.html
#582 (comment):

@@ -22683,6 +22683,21 @@

  •  <emu-clause id="sec-object.getownpropertydescriptors">
    
  •    <h1>Object.getOwnPropertyDescriptors ( _O_ )</h1>
    
  •    <p>When the `getOwnPropertyDescriptors` function is called, the following steps are taken:</p>
    
  •    <emu-alg>
    
  •      1. Let _obj_ be ? ToObject(_O_).
    
  •      1. Let _ownKeys_ be ? _obj_.[[OwnPropertyKeys]]().
    
  •      1. Let _descriptors_ be ! ObjectCreate(%ObjectPrototype%).
    
  •      1. Repeat, for each element _key_ of _ownKeys_ in List order,
    
  •        1. Let _desc_ be ? _obj_.[[GetOwnProperty]](_key_).
    
  •        1. Let _descriptor_ be ! FromPropertyDescriptor(_desc_).
    
  •        1. Perform ! CreateDataProperty(_descriptors_, _key_, _descriptor_).
    

Should we run this step also when descriptor is undefined? (Could
happen if obj is a proxy, for instance.)


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/tc39/ecma262/pull/582/files/55ac18633a0e68ba24b1f62288e3c77ddece58bd#r64581739

Copy link
Member Author

@ljharb ljharb May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflect.ownKeys should return the same as [[OwnPropertyKeys]], and Object.getOwnPropertyDescriptor I believe will call [[GetOwnProperty]], so I think you'd get undefined for a key from a Proxy that had this inconsistent behavior.

Copy link
Contributor

@claudepache claudepache May 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Object.defineProperties accepts undefined in place of a property descriptor, it is probably fine for Object.getOwnPropertyDescriptors to produce undefined in place of a property descriptor, so that the following code will work:

Object.defineProperties(obj2, Object.getOwnPropertyDescriptors(obj1))

I’ve checked that Object.defineProperties does indeed accept undefined in place of a descriptor since ES6 (see step 5b), but the browsers still do not. (And test262 apparently forgot to be updated.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my similarly-weak preference is that it should just pass through what the MOP gives it and not be responsible for normalizing or censoring.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My weak preference is the same as @domenic's - also, this same "issue" already exists with

const obj = {};
Reflect.ownKeys(badProxy).forEach(x => {
  Object.defineProperty(obj, x, Reflect.getOwnPropertyDescriptor(badProxy, x));
});

Copy link
Member

@bterlson bterlson Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this as normalizing or censoring. To me, if GetOwnProperty returns undefined, the property doesn't exist. The fact that previously OwnKeys said the property was there is of no consequence - maybe it doesn't exist now because the proxy is confused, or maybe there were side effects that removed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this as normalizing or censoring. To me, if GetOwnProperty returns undefined, the property doesn't exist.

I guess this is the core of our disagreement: if GetOwnProperty returns undefined, that to me means that its property descriptor is undefined. That can be true if the property doesn't exist, but it can also be true if the proxy wants to return undefined and the property does exist.

Basically, "what does it mean to exist"? :)

Copy link
Member

@bterlson bterlson Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such thing as a property with an undefined property descriptor. Proxies may change their answers about whether a property exists, but if a property exists, it has a property descriptor.

1. Return _descriptors_.
</emu-alg>
</emu-clause>

<!-- es6num="19.1.2.7" -->
<emu-clause id="sec-object.getownpropertynames">
<h1>Object.getOwnPropertyNames ( _O_ )</h1>
Expand Down