Title: [254205] trunk
Revision
254205
Author
[email protected]
Date
2020-01-08 10:58:39 -0800 (Wed, 08 Jan 2020)

Log Message

Proxy's [[OwnPropertyKeys]] is correct only in PropertyNameMode::StringsAndSymbols
https://bugs.webkit.org/show_bug.cgi?id=205772

Reviewed by Ross Kirsling.

JSTests:

* test262/expectations.yaml: Mark 12 test cases as passing.

Source/_javascript_Core:

This change fixes two spec compatibility issues:
(steps 8-11 of https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys)

1. If Object.getOwnPropertyNames is called on Proxy with "ownKeys" trap,
symbol keys of Proxy's target are ignored during invariants validation.

2. If Object.getOwnPropertySymbols is called on Proxy with "ownKeys" trap,
string keys of Proxy's target are ignored during invariants validation.

Given that per spec `uncheckedResultKeys` contains both strings and symbols,
`seenKeys` and explanation comment about it is removed.

Specifying PrivateSymbolMode::Exclude eliminates any chance of false TypeErrors
during invariants validation, since user code can't possibly return a private symbol
from "ownKeys" trap, yet an object with private symbols can be Proxy's target.

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

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (254204 => 254205)


--- trunk/JSTests/ChangeLog	2020-01-08 17:13:39 UTC (rev 254204)
+++ trunk/JSTests/ChangeLog	2020-01-08 18:58:39 UTC (rev 254205)
@@ -1,5 +1,14 @@
 2020-01-08  Alexey Shvayka  <[email protected]>
 
+        Proxy's [[OwnPropertyKeys]] is correct only in PropertyNameMode::StringsAndSymbols
+        https://bugs.webkit.org/show_bug.cgi?id=205772
+
+        Reviewed by Ross Kirsling.
+
+        * test262/expectations.yaml: Mark 12 test cases as passing.
+
+2020-01-08  Alexey Shvayka  <[email protected]>
+
         RegExp.prototype[Symbol.replace] does not support named capture groups
         https://bugs.webkit.org/show_bug.cgi?id=205783
 

Modified: trunk/JSTests/test262/expectations.yaml (254204 => 254205)


--- trunk/JSTests/test262/expectations.yaml	2020-01-08 17:13:39 UTC (rev 254204)
+++ trunk/JSTests/test262/expectations.yaml	2020-01-08 18:58:39 UTC (rev 254205)
@@ -1158,24 +1158,6 @@
 test/built-ins/Number/proto-from-ctor-realm.js:
   default: 'Test262Error: Expected SameValue(«0», «0») to be true'
   strict mode: 'Test262Error: Expected SameValue(«0», «0») to be true'
-test/built-ins/Object/getOwnPropertyNames/proxy-invariant-absent-not-configurable-symbol-key.js:
-  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-test/built-ins/Object/getOwnPropertyNames/proxy-invariant-not-extensible-absent-symbol-key.js:
-  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-test/built-ins/Object/getOwnPropertyNames/proxy-invariant-not-extensible-extra-symbol-key.js:
-  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-test/built-ins/Object/getOwnPropertySymbols/proxy-invariant-absent-not-configurable-string-key.js:
-  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-test/built-ins/Object/getOwnPropertySymbols/proxy-invariant-not-extensible-absent-string-key.js:
-  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-test/built-ins/Object/getOwnPropertySymbols/proxy-invariant-not-extensible-extra-string-key.js:
-  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
 test/built-ins/Object/internals/DefineOwnProperty/consistent-value-function-arguments.js:
   default: 'Test262Error: Expected SameValue(«null», «[object Arguments]») to be true'
 test/built-ins/Object/internals/DefineOwnProperty/consistent-value-function-caller.js:

Modified: trunk/Source/_javascript_Core/ChangeLog (254204 => 254205)


--- trunk/Source/_javascript_Core/ChangeLog	2020-01-08 17:13:39 UTC (rev 254204)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-01-08 18:58:39 UTC (rev 254205)
@@ -1,5 +1,31 @@
 2020-01-08  Alexey Shvayka  <[email protected]>
 
+        Proxy's [[OwnPropertyKeys]] is correct only in PropertyNameMode::StringsAndSymbols
+        https://bugs.webkit.org/show_bug.cgi?id=205772
+
+        Reviewed by Ross Kirsling.
+
+        This change fixes two spec compatibility issues:
+        (steps 8-11 of https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys)
+
+        1. If Object.getOwnPropertyNames is called on Proxy with "ownKeys" trap,
+        symbol keys of Proxy's target are ignored during invariants validation.
+
+        2. If Object.getOwnPropertySymbols is called on Proxy with "ownKeys" trap,
+        string keys of Proxy's target are ignored during invariants validation.
+
+        Given that per spec `uncheckedResultKeys` contains both strings and symbols,
+        `seenKeys` and explanation comment about it is removed.
+
+        Specifying PrivateSymbolMode::Exclude eliminates any chance of false TypeErrors
+        during invariants validation, since user code can't possibly return a private symbol
+        from "ownKeys" trap, yet an object with private symbols can be Proxy's target.
+
+        * runtime/ProxyObject.cpp:
+        (JSC::ProxyObject::performGetOwnPropertyNames):
+
+2020-01-08  Alexey Shvayka  <[email protected]>
+
         RegExp.prototype[Symbol.replace] does not support named capture groups
         https://bugs.webkit.org/show_bug.cgi?id=205783
 

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.cpp (254204 => 254205)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2020-01-08 17:13:39 UTC (rev 254204)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2020-01-08 18:58:39 UTC (rev 254205)
@@ -956,8 +956,6 @@
 
     HashSet<UniquedStringImpl*> uncheckedResultKeys;
     {
-        HashSet<RefPtr<UniquedStringImpl>> seenKeys;
-
         RuntimeTypeMask resultFilter = 0;
         switch (propertyNames.propertyNameMode()) {
         case PropertyNameMode::Symbols:
@@ -979,23 +977,14 @@
             Identifier ident = value.toPropertyKey(globalObject);
             RETURN_IF_EXCEPTION(scope, doExitEarly);
 
-            // If trapResult contains any duplicate entries, throw a TypeError exception.
-            //    
-            // Per spec[1], filtering by type should occur _after_ [[OwnPropertyKeys]], so duplicates
-            // are tracked in a separate hashtable from uncheckedResultKeys (which only contain the
-            // keys filtered by type).
-            //
-            // [1] Per https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeysmust not contain any duplicate names"_s);
-            if (!seenKeys.add(ident.impl()).isNewEntry) {
+            if (!uncheckedResultKeys.add(ident.impl()).isNewEntry) {
                 throwTypeError(globalObject, scope, "Proxy handler's 'ownKeys' trap result must not contain any duplicate names"_s);
                 return doExitEarly;
             }
 
-            if (!(type & resultFilter))
-                return dontExitEarly;
+            if (type & resultFilter)
+                propertyNames.add(ident.impl());
 
-            uncheckedResultKeys.add(ident.impl());
-            propertyNames.add(ident.impl());
             return dontExitEarly;
         };
 
@@ -1007,7 +996,7 @@
     bool targetIsExensible = target->isExtensible(globalObject);
     RETURN_IF_EXCEPTION(scope, void());
 
-    PropertyNameArray targetKeys(vm, propertyNames.propertyNameMode(), propertyNames.privateSymbolMode());
+    PropertyNameArray targetKeys(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Exclude);
     target->methodTable(vm)->getOwnPropertyNames(target, globalObject, targetKeys, enumerationMode);
     RETURN_IF_EXCEPTION(scope, void());
     Vector<UniquedStringImpl*> targetConfigurableKeys;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to