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

Normative: Throw TypeError if proxy [[OwnPropertyKeys]] returns duplicate entries #833

Merged
merged 1 commit into from
Aug 10, 2017

Conversation

bterlson
Copy link
Member

@bterlson bterlson commented Mar 3, 2017

Proxy [[OwnPropertyKeys]] now throws if the trap returns an array with duplicate entries and reverts a few of the changes made to handle duplicate property keys in a few places. See also discussion in #461. I believe this is needs-consensus, though I haven't heard arguments against this.

/cc @anba

@bterlson bterlson added the needs consensus This needs committee consensus before it can be eligible to be merged. label Mar 3, 2017
@@ -16564,7 +16572,7 @@
for (const key of Reflect.ownKeys(obj)) {
if (typeof key === "symbol") continue;
const desc = Reflect.getOwnPropertyDescriptor(obj, key);
if (desc && !visited.has(key)) {
if (desc) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this polyfill code might need more tweaking - does it still need visited at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

We still need to track when the same property key is also present in the prototype chain.

@annevk
Copy link
Member

annevk commented Mar 3, 2017

Assuming this can only happen for proxy objects, this should be no problem from HTML's perspective.

@anba
Copy link
Contributor

anba commented Mar 3, 2017

Does anyone remember why we call [[GetOwnProperty]] for every property key instead of throwing an exception when we detected the first invariant violation? Was this added just to make sure the possible side-effects of [[GetOwnProperty]] are executed?

@bterlson
Copy link
Member Author

bterlson commented Mar 3, 2017

@annevk just to make double-sure, you mean "duplicate keys" can only happen with proxies, or making duplicate keys a type error is only for proxies? just want to make sure HTML doesn't depend on duplicate keys anywhere...

@bterlson
Copy link
Member Author

bterlson commented Mar 3, 2017

@anba I don't recall, but possibly @allenwb does.

@annevk
Copy link
Member

annevk commented Mar 3, 2017

@bterlson the former. I think we already made sure that proxy-using objects never returned duplicate keys, though maybe now this change is made we should start enforcing that in IDL too more clearly.

@leobalter leobalter added the needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 label Mar 22, 2017
@leobalter
Copy link
Member

We need volunteers to update the current tests on test262. I'm willing to support w/ reviews

@ajklein
Copy link
Contributor

ajklein commented Mar 22, 2017

What if the text said "If trapResult contains any entries a and b for which SameValue(a, b) is true, throw a TypeError". That's still one line, but at least refers to the right spec machinery.

@bterlson
Copy link
Member Author

Removing needs-consensus as we got consensus in March. Still need tests though I think.

@bterlson bterlson removed the needs consensus This needs committee consensus before it can be eligible to be merged. label May 25, 2017
@rwaldron rwaldron added the has consensus This has committee consensus. label Aug 4, 2017
rwaldron added a commit to rwaldron/test262 that referenced this pull request Aug 4, 2017
@rwaldron
Copy link
Contributor

rwaldron commented Aug 4, 2017

tc39/test262@a775c24

rwaldron added a commit to rwaldron/test262 that referenced this pull request Aug 4, 2017
@leobalter leobalter removed the needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 label Aug 10, 2017
@leobalter
Copy link
Member

Tests are up and landed into Test262

@bterlson :shipit:

@bterlson
Copy link
Member Author

YES!

@bterlson bterlson merged commit 5d77057 into tc39:master Aug 10, 2017
zdobersek pushed a commit to Igalia/webkit that referenced this pull request Apr 8, 2019
[JSC] throw if 'ownKeys' Proxy trap result contains duplicate keys
https://bugs.webkit.org/show_bug.cgi?id=185211

Reviewed by Saam Barati.

This is for the normative spec change in tc39/ecma262#833

This changes several assertions to expect a TypeError to be thrown (in some cases,
changing thee expected message).

* es6/Proxy_ownKeys_duplicates.js:
(handler):
(shouldThrow):
(test):
* stress/Object_static_methods_Object.getOwnPropertyDescriptors-proxy.js:
(shouldThrow):
* stress/proxy-own-keys.js:
(i.catch):
(assert):

LayoutTests/imported/w3c:
[JSC] throw if 'ownKeys' Proxy trap result contains duplicate keys
https://bugs.webkit.org/show_bug.cgi?id=185211

Reviewed by Saam Barati.

This is for the normative spec change in tc39/ecma262#833

Change some test expectations which were previously expected to fail.

* web-platform-tests/fetch/api/headers/headers-record-expected.txt:

Source/JavaScriptCore:
[JSC] throw if ownKeys Proxy trap result contains duplicate keys
https://bugs.webkit.org/show_bug.cgi?id=185211

Reviewed by Saam Barati.

Implements the normative spec change in tc39/ecma262#833

This involves tracking duplicate keys returned from the ownKeys trap in yet
another HashTable, and may incur a minor performance penalty in some cases. This
is not expected to significantly affect web performance.

* runtime/ProxyObject.cpp:
(JSC::ProxyObject::performGetOwnPropertyNames):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@243933 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus This has committee consensus.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants