Title: [197539] trunk/Source/_javascript_Core
Revision
197539
Author
[email protected]
Date
2016-03-03 18:25:30 -0800 (Thu, 03 Mar 2016)

Log Message

Add Proxy tests for exceptions that depend on an object being non-extensible and having configurable properties
https://bugs.webkit.org/show_bug.cgi?id=154745

Reviewed by Geoffrey Garen.

This patch is mostly an implementation of Proxy.[[OwnPropertyKeys]] 
with respect to section 9.5.11 of the ECMAScript spec.
https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys

This patch also changes call sites of getOwnPropertyNames and
getPropertyNames to expect that an exception can be thrown.

* dfg/DFGOperations.cpp:
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::iteratorEntries):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::execute):
* runtime/IntlObject.cpp:
(JSC::supportedLocales):
* runtime/JSCJSValue.h:
* runtime/JSCJSValueInlines.h:
(JSC::JSValue::get):
(JSC::JSValue::put):
* runtime/JSONObject.cpp:
(JSC::Stringifier::Holder::appendNextProperty):
(JSC::Walker::walk):
* runtime/JSObject.cpp:
(JSC::JSObject::getPropertyNames):
(JSC::JSObject::getGenericPropertyNames):
* runtime/JSObject.h:
(JSC::makeIdentifier):
(JSC::createListFromArrayLike):
* runtime/JSPropertyNameEnumerator.h:
(JSC::propertyNameEnumerator):
* runtime/JSPropertyNameIterator.cpp:
(JSC::JSPropertyNameIterator::create):
* runtime/MapConstructor.cpp:
(JSC::constructMap):
* runtime/ObjectConstructor.cpp:
(JSC::defineProperties):
(JSC::objectConstructorSeal):
(JSC::objectConstructorFreeze):
(JSC::objectConstructorIsSealed):
(JSC::objectConstructorIsFrozen):
(JSC::ownPropertyKeys):
* runtime/ProxyObject.cpp:
(JSC::ProxyObject::getOwnPropertySlotByIndex):
(JSC::ProxyObject::deleteProperty):
(JSC::ProxyObject::deletePropertyByIndex):
(JSC::ProxyObject::defineOwnProperty):
(JSC::ProxyObject::performGetOwnPropertyNames):
(JSC::ProxyObject::getOwnPropertyNames):
(JSC::ProxyObject::getOwnNonIndexPropertyNames):
(JSC::ProxyObject::getStructurePropertyNames):
(JSC::ProxyObject::getGenericPropertyNames):
(JSC::ProxyObject::visitChildren):
* runtime/ProxyObject.h:
(JSC::ProxyObject::create):
(JSC::ProxyObject::createStructure):
* runtime/Structure.cpp:
(JSC::Structure::Structure):
(JSC::Structure::add):
(JSC::Structure::getPropertyNamesFromStructure):
(JSC::Structure::checkConsistency):
(JSC::Structure::canCachePropertyNameEnumerator):
(JSC::Structure::canAccessPropertiesQuicklyForEnumeration):
(JSC::Structure::canAccessPropertiesQuickly): Deleted.
* runtime/Structure.h:
* runtime/WeakMapConstructor.cpp:
(JSC::constructWeakMap):
* tests/es6.yaml:
* tests/stress/proxy-own-keys.js: Added.
(assert):
(throw.new.Error.let.handler.ownKeys):
(throw.new.Error):
(assert.let.handler.get ownKeys):
(assert.let.handler.ownKeys):
(let.handler.ownKeys):
(i.catch):
(shallowEq):
(let.handler.getOwnPropertyDescriptor):
(i.set assert):
(set add):
(set assert):
(set if):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (197538 => 197539)


--- trunk/Source/_javascript_Core/ChangeLog	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-03-04 02:25:30 UTC (rev 197539)
@@ -1,3 +1,91 @@
+2016-03-03  Saam Barati  <[email protected]>
+
+        Add Proxy tests for exceptions that depend on an object being non-extensible and having configurable properties
+        https://bugs.webkit.org/show_bug.cgi?id=154745
+
+        Reviewed by Geoffrey Garen.
+
+        This patch is mostly an implementation of Proxy.[[OwnPropertyKeys]] 
+        with respect to section 9.5.11 of the ECMAScript spec.
+        https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
+
+        This patch also changes call sites of getOwnPropertyNames and
+        getPropertyNames to expect that an exception can be thrown.
+
+        * dfg/DFGOperations.cpp:
+        * inspector/JSInjectedScriptHost.cpp:
+        (Inspector::JSInjectedScriptHost::iteratorEntries):
+        * interpreter/Interpreter.cpp:
+        (JSC::Interpreter::execute):
+        * runtime/IntlObject.cpp:
+        (JSC::supportedLocales):
+        * runtime/JSCJSValue.h:
+        * runtime/JSCJSValueInlines.h:
+        (JSC::JSValue::get):
+        (JSC::JSValue::put):
+        * runtime/JSONObject.cpp:
+        (JSC::Stringifier::Holder::appendNextProperty):
+        (JSC::Walker::walk):
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::getPropertyNames):
+        (JSC::JSObject::getGenericPropertyNames):
+        * runtime/JSObject.h:
+        (JSC::makeIdentifier):
+        (JSC::createListFromArrayLike):
+        * runtime/JSPropertyNameEnumerator.h:
+        (JSC::propertyNameEnumerator):
+        * runtime/JSPropertyNameIterator.cpp:
+        (JSC::JSPropertyNameIterator::create):
+        * runtime/MapConstructor.cpp:
+        (JSC::constructMap):
+        * runtime/ObjectConstructor.cpp:
+        (JSC::defineProperties):
+        (JSC::objectConstructorSeal):
+        (JSC::objectConstructorFreeze):
+        (JSC::objectConstructorIsSealed):
+        (JSC::objectConstructorIsFrozen):
+        (JSC::ownPropertyKeys):
+        * runtime/ProxyObject.cpp:
+        (JSC::ProxyObject::getOwnPropertySlotByIndex):
+        (JSC::ProxyObject::deleteProperty):
+        (JSC::ProxyObject::deletePropertyByIndex):
+        (JSC::ProxyObject::defineOwnProperty):
+        (JSC::ProxyObject::performGetOwnPropertyNames):
+        (JSC::ProxyObject::getOwnPropertyNames):
+        (JSC::ProxyObject::getOwnNonIndexPropertyNames):
+        (JSC::ProxyObject::getStructurePropertyNames):
+        (JSC::ProxyObject::getGenericPropertyNames):
+        (JSC::ProxyObject::visitChildren):
+        * runtime/ProxyObject.h:
+        (JSC::ProxyObject::create):
+        (JSC::ProxyObject::createStructure):
+        * runtime/Structure.cpp:
+        (JSC::Structure::Structure):
+        (JSC::Structure::add):
+        (JSC::Structure::getPropertyNamesFromStructure):
+        (JSC::Structure::checkConsistency):
+        (JSC::Structure::canCachePropertyNameEnumerator):
+        (JSC::Structure::canAccessPropertiesQuicklyForEnumeration):
+        (JSC::Structure::canAccessPropertiesQuickly): Deleted.
+        * runtime/Structure.h:
+        * runtime/WeakMapConstructor.cpp:
+        (JSC::constructWeakMap):
+        * tests/es6.yaml:
+        * tests/stress/proxy-own-keys.js: Added.
+        (assert):
+        (throw.new.Error.let.handler.ownKeys):
+        (throw.new.Error):
+        (assert.let.handler.get ownKeys):
+        (assert.let.handler.ownKeys):
+        (let.handler.ownKeys):
+        (i.catch):
+        (shallowEq):
+        (let.handler.getOwnPropertyDescriptor):
+        (i.set assert):
+        (set add):
+        (set assert):
+        (set if):
+
 2016-03-03  Keith Miller  <[email protected]>
 
         Array prototype JS builtins should support Symbol.species

Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -410,7 +410,7 @@
     }
 
     // Use this since we know that the value is out of bounds.
-    return JSValue::encode(JSValue(base).get(exec, index));
+    return JSValue::encode(JSValue(base).get(exec, static_cast<unsigned>(index)));
 }
 
 EncodedJSValue JIT_OPERATION operationGetByValArrayInt(ExecState* exec, JSArray* base, int32_t index)

Modified: trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -448,9 +448,11 @@
         iterator = setIterator->clone(exec);
     else if (JSStringIterator* stringIterator = jsDynamicCast<JSStringIterator*>(value))
         iterator = stringIterator->clone(exec);
-    else if (JSPropertyNameIterator* propertyNameIterator = jsDynamicCast<JSPropertyNameIterator*>(value))
+    else if (JSPropertyNameIterator* propertyNameIterator = jsDynamicCast<JSPropertyNameIterator*>(value)) {
         iterator = propertyNameIterator->clone(exec);
-    else
+        if (UNLIKELY(exec->hadException()))
+            return JSValue();
+    } else
         return jsUndefined();
 
     unsigned numberToFetch = 5;

Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -891,7 +891,7 @@
                     continue;
                 }
                 case JSONPPathEntryTypeLookup: {
-                    baseObject = baseObject.get(callFrame, JSONPPath[i].m_pathIndex);
+                    baseObject = baseObject.get(callFrame, static_cast<unsigned>(JSONPPath[i].m_pathIndex));
                     if (callFrame->hadException())
                         return jsUndefined();
                     continue;

Modified: trunk/Source/_javascript_Core/runtime/IntlObject.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/IntlObject.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/IntlObject.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -944,6 +944,8 @@
     // 7. Let keys be subset.[[OwnPropertyKeys]]().
     PropertyNameArray keys(&state, PropertyNameMode::Strings);
     supportedLocales->getOwnPropertyNames(supportedLocales, &state, keys, EnumerationMode());
+    if (state.hadException())
+        return jsUndefined();
 
     PropertyDescriptor desc;
     desc.setConfigurable(false);

Modified: trunk/Source/_javascript_Core/runtime/JSCJSValue.h (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/JSCJSValue.h	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValue.h	2016-03-04 02:25:30 UTC (rev 197539)
@@ -275,6 +275,7 @@
     JSValue get(ExecState*, PropertyName, PropertySlot&) const;
     JSValue get(ExecState*, unsigned propertyName) const;
     JSValue get(ExecState*, unsigned propertyName, PropertySlot&) const;
+    JSValue get(ExecState*, uint64_t propertyName) const;
 
     bool getPropertySlot(ExecState*, PropertyName, PropertySlot&) const;
 

Modified: trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h	2016-03-04 02:25:30 UTC (rev 197539)
@@ -778,6 +778,13 @@
     return jsUndefined();
 }
 
+ALWAYS_INLINE JSValue JSValue::get(ExecState* exec, uint64_t propertyName) const
+{
+    if (LIKELY(propertyName <= std::numeric_limits<unsigned>::max()))
+        return get(exec, static_cast<unsigned>(propertyName));
+    return get(exec, Identifier::from(exec, static_cast<double>(propertyName)));
+}
+
 inline void JSValue::put(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
 {
     if (UNLIKELY(!isCell())) {

Modified: trunk/Source/_javascript_Core/runtime/JSONObject.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/JSONObject.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/JSONObject.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -439,6 +439,8 @@
             else {
                 PropertyNameArray objectPropertyNames(exec, PropertyNameMode::Strings);
                 m_object->methodTable()->getOwnPropertyNames(m_object.get(), exec, objectPropertyNames, EnumerationMode());
+                if (UNLIKELY(exec->hadException()))
+                    return false;
                 m_propertyNames = objectPropertyNames.releaseData();
             }
             m_size = m_propertyNames->propertyNameVector().size();
@@ -656,6 +658,8 @@
                 indexStack.append(0);
                 propertyStack.append(PropertyNameArray(m_exec, PropertyNameMode::Strings));
                 object->methodTable()->getOwnPropertyNames(object, m_exec, propertyStack.last(), EnumerationMode());
+                if (UNLIKELY(m_exec->hadException()))
+                    return jsNull();
             }
             objectStartVisitMember:
             FALLTHROUGH;

Modified: trunk/Source/_javascript_Core/runtime/JSObject.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -1591,6 +1591,8 @@
 void JSObject::getPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
 {
     object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, propertyNames, mode);
+    if (UNLIKELY(exec->hadException()))
+        return;
 
     if (object->prototype().isNull())
         return;
@@ -1603,6 +1605,8 @@
             break;
         }
         prototype->methodTable(vm)->getOwnPropertyNames(prototype, exec, propertyNames, mode);
+        if (UNLIKELY(exec->hadException()))
+            return;
         JSValue nextProto = prototype->prototype();
         if (nextProto.isNull())
             break;
@@ -3025,6 +3029,8 @@
 {
     VM& vm = exec->vm();
     object->methodTable(vm)->getOwnPropertyNames(object, exec, propertyNames, EnumerationMode(mode, JSObjectPropertiesMode::Exclude));
+    if (UNLIKELY(exec->hadException()))
+        return;
 
     if (object->prototype().isNull())
         return;
@@ -3036,6 +3042,8 @@
             break;
         }
         prototype->methodTable(vm)->getOwnPropertyNames(prototype, exec, propertyNames, mode);
+        if (UNLIKELY(exec->hadException()))
+            return;
         JSValue nextProto = prototype->prototype();
         if (nextProto.isNull())
             break;

Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/JSObject.h	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h	2016-03-04 02:25:30 UTC (rev 197539)
@@ -41,6 +41,7 @@
 #include "PropertyStorage.h"
 #include "PutDirectIndexMode.h"
 #include "PutPropertySlot.h"
+#include "RuntimeType.h"
 
 #include "Structure.h"
 #include "VM.h"
@@ -1533,6 +1534,37 @@
     return name;
 }
 
+// Section 7.3.17 of the spec. 
+template <typename AddFunction> // Add function should have a type like: (JSValue, RuntimeType) -> bool
+void createListFromArrayLike(ExecState* exec, JSValue arrayLikeValue, RuntimeTypeMask legalTypesFilter, const String& errorMessage, AddFunction addFunction)
+{
+    VM& vm = exec->vm();
+    Vector<JSValue> result;
+    JSValue lengthProperty = arrayLikeValue.get(exec, exec->vm().propertyNames->length);
+    if (vm.exception())
+        return;
+    double lengthAsDouble = lengthProperty.toLength(exec);
+    if (vm.exception())
+        return;
+    RELEASE_ASSERT(lengthAsDouble >= 0.0 && lengthAsDouble == std::trunc(lengthAsDouble));
+    uint64_t length = static_cast<uint64_t>(lengthAsDouble);
+    for (uint64_t index = 0; index < length; index++) {
+        JSValue  next = arrayLikeValue.get(exec, index);
+        if (vm.exception())
+            return;
+
+        RuntimeType type = runtimeTypeForValue(next);
+        if (!(type & legalTypesFilter)) {
+            throwTypeError(exec, errorMessage);
+            return;
+        }
+
+        bool exitEarly = addFunction(next, type);
+        if (exitEarly)
+            return;
+    }
+}
+
 bool validateAndApplyPropertyDescriptor(ExecState*, JSObject*, PropertyName, bool isExtensible,
     const PropertyDescriptor& descriptor, bool isCurrentDefined, const PropertyDescriptor& current, bool throwException);
 

Modified: trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.h (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.h	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/JSPropertyNameEnumerator.h	2016-03-04 02:25:30 UTC (rev 197539)
@@ -117,17 +117,21 @@
 
     PropertyNameArray propertyNames(exec, PropertyNameMode::Strings);
 
-    if (structure->canAccessPropertiesQuickly() && indexedLength == base->getArrayLength()) {
+    if (structure->canAccessPropertiesQuicklyForEnumeration() && indexedLength == base->getArrayLength()) {
         base->methodTable(vm)->getStructurePropertyNames(base, exec, propertyNames, EnumerationMode());
+        ASSERT(!exec->hadException());
 
         numberStructureProperties = propertyNames.size();
 
         base->methodTable(vm)->getGenericPropertyNames(base, exec, propertyNames, EnumerationMode());
+        ASSERT(!exec->hadException());
     } else {
         // Generic property names vector contains all indexed property names.
         // So disable indexed property enumeration phase by setting |indexedLength| to 0.
         indexedLength = 0;
         base->methodTable(vm)->getPropertyNames(base, exec, propertyNames, EnumerationMode());
+        if (UNLIKELY(exec->hadException()))
+            return nullptr;
     }
 
     ASSERT(propertyNames.size() < UINT32_MAX);

Modified: trunk/Source/_javascript_Core/runtime/JSPropertyNameIterator.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/JSPropertyNameIterator.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/JSPropertyNameIterator.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -59,7 +59,10 @@
 
 JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, Structure* structure, JSObject* iteratedObject)
 {
-    return JSPropertyNameIterator::create(exec, structure, iteratedObject, propertyNameEnumerator(exec, iteratedObject));
+    JSPropertyNameEnumerator* enumerator = propertyNameEnumerator(exec, iteratedObject);
+    if (UNLIKELY(exec->hadException()))
+        return nullptr;
+    return JSPropertyNameIterator::create(exec, structure, iteratedObject, enumerator);
 }
 
 JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, Structure* structure, JSObject* iteratedObject, JSPropertyNameEnumerator* enumerator)

Modified: trunk/Source/_javascript_Core/runtime/MapConstructor.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/MapConstructor.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/MapConstructor.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -108,13 +108,13 @@
             return JSValue::encode(jsUndefined());
         }
 
-        JSValue key = nextItem.get(exec, 0);
+        JSValue key = nextItem.get(exec, static_cast<unsigned>(0));
         if (exec->hadException()) {
             iteratorClose(exec, iterator);
             return JSValue::encode(jsUndefined());
         }
 
-        JSValue value = nextItem.get(exec, 1);
+        JSValue value = nextItem.get(exec, static_cast<unsigned>(1));
         if (exec->hadException()) {
             iteratorClose(exec, iterator);
             return JSValue::encode(jsUndefined());

Modified: trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -408,6 +408,8 @@
 {
     PropertyNameArray propertyNames(exec, PropertyNameMode::StringsAndSymbols);
     asObject(properties)->methodTable(exec->vm())->getOwnPropertyNames(asObject(properties), exec, propertyNames, EnumerationMode(DontEnumPropertiesMode::Exclude));
+    if (UNLIKELY(exec->hadException()))
+        return jsNull();
     size_t numProperties = propertyNames.size();
     Vector<PropertyDescriptor> descriptors;
     MarkedArgumentBuffer markBuffer;
@@ -478,6 +480,8 @@
     // 2. For each named own property name P of O,
     PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols);
     object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include));
+    if (UNLIKELY(exec->hadException()))
+        return JSValue::encode(obj);
     PropertyNameArray::const_iterator end = properties.end();
     for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
         Identifier propertyName = *iter;
@@ -514,6 +518,8 @@
     // 2. For each named own property name P of O,
     PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols);
     object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include));
+    if (UNLIKELY(exec->hadException()))
+        return object;
     PropertyNameArray::const_iterator end = properties.end();
     for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
         Identifier propertyName = *iter;
@@ -580,6 +586,8 @@
     // 2. For each named own property name P of O,
     PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols);
     object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include));
+    if (UNLIKELY(exec->hadException()))
+        return JSValue::encode(JSValue());
     PropertyNameArray::const_iterator end = properties.end();
     for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
         Identifier propertyName = *iter;
@@ -616,6 +624,8 @@
     // 2. For each named own property name P of O,
     PropertyNameArray properties(exec, PropertyNameMode::StringsAndSymbols);
     object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(DontEnumPropertiesMode::Include));
+    if (UNLIKELY(exec->hadException()))
+        return JSValue::encode(JSValue());
     PropertyNameArray::const_iterator end = properties.end();
     for (PropertyNameArray::const_iterator iter = properties.begin(); iter != end; ++iter) {
         Identifier propertyName = *iter;
@@ -661,6 +671,8 @@
 {
     PropertyNameArray properties(exec, propertyNameMode);
     object->methodTable(exec->vm())->getOwnPropertyNames(object, exec, properties, EnumerationMode(dontEnumPropertiesMode));
+    if (exec->hadException())
+        return nullptr;
 
     JSArray* keys = constructEmptyArray(exec, 0);
 

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -341,8 +341,6 @@
 {
     ProxyObject* thisObject = jsCast<ProxyObject*>(object);
     Identifier ident = Identifier::from(exec, propertyName); 
-    if (exec->hadException())
-        return false;
     return thisObject->getOwnPropertySlotCommon(exec, ident.impl(), slot);
 }
 
@@ -587,7 +585,7 @@
 {
     ProxyObject* thisObject = jsCast<ProxyObject*>(cell);
     auto performDefaultDelete = [&] () -> bool {
-        JSObject* target = jsCast<JSObject*>(thisObject->target());
+        JSObject* target = thisObject->target();
         return target->methodTable(exec->vm())->deleteProperty(target, exec, propertyName);
     };
     return thisObject->performDelete(exec, propertyName, performDefaultDelete);
@@ -597,10 +595,8 @@
 {
     ProxyObject* thisObject = jsCast<ProxyObject*>(cell);
     Identifier ident = Identifier::from(exec, propertyName); 
-    if (exec->hadException())
-        return false;
     auto performDefaultDelete = [&] () -> bool {
-        JSObject* target = jsCast<JSObject*>(thisObject->target());
+        JSObject* target = thisObject->target();
         return target->methodTable(exec->vm())->deletePropertyByIndex(target, exec, propertyName);
     };
     return thisObject->performDelete(exec, ident.impl(), performDefaultDelete);
@@ -801,6 +797,164 @@
     return thisObject->performDefineOwnProperty(exec, propertyName, descriptor, shouldThrow);
 }
 
+void ProxyObject::performGetOwnPropertyNames(ExecState* exec, PropertyNameArray& trapResult, EnumerationMode enumerationMode)
+{
+    VM& vm = exec->vm();
+    JSValue handlerValue = this->handler();
+    if (handlerValue.isNull()) {
+        throwVMTypeError(exec, ASCIILiteral("Proxy 'handler' is null. It should be an Object."));
+        return;
+    }
+
+    JSObject* handler = jsCast<JSObject*>(handlerValue);
+    CallData callData;
+    CallType callType;
+    JSValue ownKeysMethod = handler->getMethod(exec, callData, callType, makeIdentifier(vm, "ownKeys"), ASCIILiteral("'ownKeys' property of a Proxy's handler should be callable."));
+    if (exec->hadException())
+        return;
+    JSObject* target = this->target();
+    if (ownKeysMethod.isUndefined()) {
+        target->methodTable(exec->vm())->getOwnPropertyNames(target, exec, trapResult, enumerationMode);
+        return;
+    }
+
+    MarkedArgumentBuffer arguments;
+    arguments.append(target);
+    JSValue arrayLikeObject = call(exec, ownKeysMethod, callType, callData, handler, arguments);
+    if (exec->hadException())
+        return;
+
+    PropertyNameMode propertyNameMode = trapResult.mode();
+    RuntimeTypeMask resultFilter = 0;
+    switch (propertyNameMode) {
+    case PropertyNameMode::Symbols:
+        resultFilter = TypeSymbol;
+        break;
+    case PropertyNameMode::Strings:
+        resultFilter = TypeString;
+        break;
+    case PropertyNameMode::StringsAndSymbols:
+        resultFilter = TypeSymbol | TypeString;
+        break;
+    }
+    ASSERT(resultFilter);
+    RuntimeTypeMask dontThrowAnExceptionTypeFilter = TypeString | TypeSymbol;
+    HashMap<UniquedStringImpl*, unsigned> uncheckedResultKeys;
+    unsigned totalSize = 0;
+
+    auto addPropName = [&] (JSValue value, RuntimeType type) -> bool {
+        static const bool doExitEarly = true;
+        static const bool dontExitEarly = false;
+
+        if (!(type & resultFilter))
+            return dontExitEarly;
+
+        Identifier ident = value.toPropertyKey(exec);
+        if (exec->hadException())
+            return doExitEarly;
+
+        ++uncheckedResultKeys.add(ident.impl(), 0).iterator->value;
+        ++totalSize;
+
+        trapResult.add(ident.impl());
+
+        return dontExitEarly;
+    };
+
+    createListFromArrayLike(exec, arrayLikeObject, dontThrowAnExceptionTypeFilter, ASCIILiteral("Proxy handler's 'ownKeys' method must return a array-like object containing only Strings and Symbols."), addPropName);
+    if (exec->hadException())
+        return;
+
+    bool targetIsExensible = target->isExtensible(exec);
+
+    PropertyNameArray targetKeys(&vm, propertyNameMode);
+    target->methodTable(vm)->getOwnPropertyNames(target, exec, targetKeys, enumerationMode);
+    if (exec->hadException())
+        return;
+    Vector<UniquedStringImpl*> targetConfigurableKeys;
+    Vector<UniquedStringImpl*> targetNonConfigurableKeys;
+    for (const Identifier& ident : targetKeys) {
+        PropertyDescriptor descriptor;
+        bool isPropertyDefined = target->getOwnPropertyDescriptor(exec, ident.impl(), descriptor); 
+        if (exec->hadException())
+            return;
+        if (isPropertyDefined && !descriptor.configurable())
+            targetNonConfigurableKeys.append(ident.impl());
+        else
+            targetConfigurableKeys.append(ident.impl());
+    }
+
+    auto removeIfContainedInUncheckedResultKeys = [&] (UniquedStringImpl* impl) -> bool {
+        static const bool isContainedIn = true;
+        static const bool isNotContainedIn = false;
+
+        auto iter = uncheckedResultKeys.find(impl);
+        if (iter == uncheckedResultKeys.end())
+            return isNotContainedIn;
+
+        unsigned& count = iter->value;
+        if (count == 0)
+            return isNotContainedIn;
+
+        --count;
+        --totalSize;
+        return isContainedIn;
+    };
+
+    for (UniquedStringImpl* impl : targetNonConfigurableKeys) {
+        bool contains = removeIfContainedInUncheckedResultKeys(impl);
+        if (!contains) {
+            throwVMTypeError(exec, makeString("Proxy object's 'target' has the non-configurable property '", String(impl), "' that was not in the result from the 'ownKeys' trap."));
+            return;
+        }
+    }
+
+    if (targetIsExensible)
+        return;
+
+    for (UniquedStringImpl* impl : targetConfigurableKeys) {
+        bool contains = removeIfContainedInUncheckedResultKeys(impl);
+        if (!contains) {
+            throwVMTypeError(exec, makeString("Proxy object's non-extensible 'target' has configurable property '", String(impl), "' that was not in the result from the 'ownKeys' trap."));
+            return;
+        }
+    }
+
+#ifndef NDEBUG
+    unsigned sum = 0;
+    for (unsigned keyCount : uncheckedResultKeys.values())
+        sum += keyCount;
+    ASSERT(sum == totalSize);
+#endif
+
+    if (totalSize) {
+        throwVMTypeError(exec, ASCIILiteral("Proxy handler's 'ownKeys' method returned a key that was not present in its target or it returned duplicate keys."));
+        return;
+    }
+}
+
+void ProxyObject::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNameArray, EnumerationMode enumerationMode)
+{
+    ProxyObject* thisObject = jsCast<ProxyObject*>(object);
+    thisObject->performGetOwnPropertyNames(exec, propertyNameArray, enumerationMode);
+}
+
+void ProxyObject::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
+{
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+void ProxyObject::getStructurePropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
+{
+    // We should always go down the getOwnPropertyNames path.
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+void ProxyObject::getGenericPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
+{
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
 void ProxyObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     ProxyObject* thisObject = jsCast<ProxyObject*>(cell);

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.h (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.h	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.h	2016-03-04 02:25:30 UTC (rev 197539)
@@ -28,6 +28,7 @@
 
 #include "JSGlobalObject.h"
 #include "JSObject.h"
+#include "RuntimeType.h"
 
 namespace JSC {
 
@@ -35,7 +36,9 @@
 public:
     typedef JSNonFinalObject Base;
 
-    const static unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | TypeOfShouldCallGetCallData | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero;
+    // We lie an say we override getPropertyNames() because it prevents
+    // property name enumeration caching.
+    const static unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | TypeOfShouldCallGetCallData | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | OverridesGetPropertyNames;
 
     static ProxyObject* create(ExecState* exec, Structure* structure, JSValue target, JSValue handler)
     {
@@ -47,7 +50,11 @@
 
     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
     {
-        return Structure::create(vm, globalObject, prototype, TypeInfo(ProxyObjectType, StructureFlags), info(), NonArray | MayHaveIndexedAccessors);
+        Structure* result = Structure::create(vm, globalObject, prototype, TypeInfo(ProxyObjectType, StructureFlags), info(), NonArray | MayHaveIndexedAccessors);
+        result->setIsQuickPropertyAccessAllowedForEnumeration(false);
+        RELEASE_ASSERT(!result->canAccessPropertiesQuicklyForEnumeration());
+        RELEASE_ASSERT(!result->canCachePropertyNameEnumerator());
+        return result;
     }
 
     DECLARE_EXPORT_INFO;
@@ -72,6 +79,10 @@
     static bool preventExtensions(JSObject*, ExecState*);
     static bool isExtensible(JSObject*, ExecState*);
     static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
+    static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
+    static NO_RETURN_DUE_TO_CRASH void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
+    static NO_RETURN_DUE_TO_CRASH void getStructurePropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
+    static NO_RETURN_DUE_TO_CRASH void getGenericPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
     static void visitChildren(JSCell*, SlotVisitor&);
 
     bool getOwnPropertySlotCommon(ExecState*, PropertyName, PropertySlot&);
@@ -84,6 +95,7 @@
     bool performPreventExtensions(ExecState*);
     bool performIsExtensible(ExecState*);
     bool performDefineOwnProperty(ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
+    void performGetOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode);
 
     WriteBarrier<JSObject> m_target;
     WriteBarrier<Unknown> m_handler;

Modified: trunk/Source/_javascript_Core/runtime/Structure.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/Structure.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/Structure.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -201,7 +201,7 @@
     setHasGetterSetterProperties(classInfo->hasStaticSetterOrReadonlyProperties());
     setHasCustomGetterSetterProperties(false);
     setHasReadOnlyOrGetterSetterPropertiesExcludingProto(classInfo->hasStaticSetterOrReadonlyProperties());
-    setHasNonEnumerableProperties(false);
+    setIsQuickPropertyAccessAllowedForEnumeration(true);
     setAttributesInPrevious(0);
     setDidPreventExtensions(false);
     setDidTransition(false);
@@ -233,7 +233,7 @@
     setHasGetterSetterProperties(m_classInfo->hasStaticSetterOrReadonlyProperties());
     setHasCustomGetterSetterProperties(false);
     setHasReadOnlyOrGetterSetterPropertiesExcludingProto(m_classInfo->hasStaticSetterOrReadonlyProperties());
-    setHasNonEnumerableProperties(false);
+    setIsQuickPropertyAccessAllowedForEnumeration(true);
     setAttributesInPrevious(0);
     setDidPreventExtensions(false);
     setDidTransition(false);
@@ -264,7 +264,7 @@
     setHasGetterSetterProperties(previous->hasGetterSetterProperties());
     setHasCustomGetterSetterProperties(previous->hasCustomGetterSetterProperties());
     setHasReadOnlyOrGetterSetterPropertiesExcludingProto(previous->hasReadOnlyOrGetterSetterPropertiesExcludingProto());
-    setHasNonEnumerableProperties(previous->hasNonEnumerableProperties());
+    setIsQuickPropertyAccessAllowedForEnumeration(previous->isQuickPropertyAccessAllowedForEnumeration());
     setAttributesInPrevious(0);
     setDidPreventExtensions(previous->didPreventExtensions());
     setDidTransition(true);
@@ -986,7 +986,7 @@
 
     checkConsistency();
     if (attributes & DontEnum)
-        setHasNonEnumerableProperties(true);
+        setIsQuickPropertyAccessAllowedForEnumeration(false);
 
     auto rep = propertyName.uid();
 
@@ -1044,7 +1044,7 @@
 
     PropertyTable::iterator end = propertyTable()->end();
     for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter) {
-        ASSERT(hasNonEnumerableProperties() || !(iter->attributes & DontEnum));
+        ASSERT(!isQuickPropertyAccessAllowedForEnumeration() || !(iter->attributes & DontEnum));
         if (!(iter->attributes & DontEnum) || mode.includeDontEnumProperties()) {
             if (iter->key->isSymbol() && !propertyNames.includeSymbolProperties())
                 continue;
@@ -1311,7 +1311,7 @@
     if (!propertyTable())
         return;
 
-    if (!hasNonEnumerableProperties()) {
+    if (isQuickPropertyAccessAllowedForEnumeration()) {
         PropertyTable::iterator end = propertyTable()->end();
         for (PropertyTable::iterator iter = propertyTable()->begin(); iter != end; ++iter) {
             ASSERT(!(iter->attributes & DontEnum));
@@ -1381,9 +1381,9 @@
     return true;
 }
     
-bool Structure::canAccessPropertiesQuickly() const
+bool Structure::canAccessPropertiesQuicklyForEnumeration() const
 {
-    if (hasNonEnumerableProperties())
+    if (!isQuickPropertyAccessAllowedForEnumeration())
         return false;
     if (hasGetterSetterProperties())
         return false;

Modified: trunk/Source/_javascript_Core/runtime/Structure.h (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/Structure.h	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/Structure.h	2016-03-04 02:25:30 UTC (rev 197539)
@@ -377,7 +377,7 @@
     void setCachedPropertyNameEnumerator(VM&, JSPropertyNameEnumerator*);
     JSPropertyNameEnumerator* cachedPropertyNameEnumerator() const;
     bool canCachePropertyNameEnumerator() const;
-    bool canAccessPropertiesQuickly() const;
+    bool canAccessPropertiesQuicklyForEnumeration() const;
 
     void getPropertyNamesFromStructure(VM&, PropertyNameArray&, EnumerationMode);
 
@@ -577,7 +577,7 @@
     DEFINE_BITFIELD(bool, isPinnedPropertyTable, IsPinnedPropertyTable, 1, 2);
     DEFINE_BITFIELD(bool, hasGetterSetterProperties, HasGetterSetterProperties, 1, 3);
     DEFINE_BITFIELD(bool, hasReadOnlyOrGetterSetterPropertiesExcludingProto, HasReadOnlyOrGetterSetterPropertiesExcludingProto, 1, 4);
-    DEFINE_BITFIELD(bool, hasNonEnumerableProperties, HasNonEnumerableProperties, 1, 5);
+    DEFINE_BITFIELD(bool, isQuickPropertyAccessAllowedForEnumeration, IsQuickPropertyAccessAllowedForEnumeration, 1, 5);
     DEFINE_BITFIELD(unsigned, attributesInPrevious, AttributesInPrevious, 14, 6);
     DEFINE_BITFIELD(bool, didPreventExtensions, DidPreventExtensions, 1, 20);
     DEFINE_BITFIELD(bool, didTransition, DidTransition, 1, 21);

Modified: trunk/Source/_javascript_Core/runtime/WeakMapConstructor.cpp (197538 => 197539)


--- trunk/Source/_javascript_Core/runtime/WeakMapConstructor.cpp	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/runtime/WeakMapConstructor.cpp	2016-03-04 02:25:30 UTC (rev 197539)
@@ -106,13 +106,13 @@
             return JSValue::encode(jsUndefined());
         }
 
-        JSValue key = nextItem.get(exec, 0);
+        JSValue key = nextItem.get(exec, static_cast<unsigned>(0));
         if (exec->hadException()) {
             iteratorClose(exec, iterator);
             return JSValue::encode(jsUndefined());
         }
 
-        JSValue value = nextItem.get(exec, 1);
+        JSValue value = nextItem.get(exec, static_cast<unsigned>(1));
         if (exec->hadException()) {
             iteratorClose(exec, iterator);
             return JSValue::encode(jsUndefined());

Modified: trunk/Source/_javascript_Core/tests/es6.yaml (197538 => 197539)


--- trunk/Source/_javascript_Core/tests/es6.yaml	2016-03-04 01:58:34 UTC (rev 197538)
+++ trunk/Source/_javascript_Core/tests/es6.yaml	2016-03-04 02:25:30 UTC (rev 197539)
@@ -935,7 +935,7 @@
 - path: es6/Proxy_internal_defineProperty_calls_[[Set]].js
   cmd: runES6 :fail
 - path: es6/Proxy_internal_defineProperty_calls_SetIntegrityLevel.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_deleteProperty_calls_Array.prototype.copyWithin.js
   cmd: runES6 :normal
 - path: es6/Proxy_internal_deleteProperty_calls_Array.prototype.pop.js
@@ -985,9 +985,9 @@
 - path: es6/Proxy_internal_get_calls_JSON.stringify.js
   cmd: runES6 :fail
 - path: es6/Proxy_internal_get_calls_Object.assign.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_get_calls_Object.defineProperties.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_get_calls_Promise_resolve_functions.js
   cmd: runES6 :normal
 - path: es6/Proxy_internal_get_calls_RegExp.prototype.flags.js
@@ -1027,11 +1027,11 @@
 - path: es6/Proxy_internal_getOwnPropertyDescriptor_calls_Object.prototype.hasOwnProperty.js
   cmd: runES6 :normal
 - path: es6/Proxy_internal_ownKeys_calls_SerializeJSONObject.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_ownKeys_calls_SetIntegrityLevel.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_ownKeys_calls_TestIntegrityLevel.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_internal_set_calls_Array.from.js
   cmd: runES6 :normal
 - path: es6/Proxy_internal_set_calls_Array.of.js
@@ -1059,7 +1059,7 @@
 - path: es6/Proxy_JSON.stringify_support.js
   cmd: runES6 :fail
 - path: es6/Proxy_ownKeys_handler.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_preventExtensions_handler.js
   cmd: runES6 :normal
 - path: es6/Proxy_Proxy.revocable.js

Added: trunk/Source/_javascript_Core/tests/stress/proxy-own-keys.js (0 => 197539)


--- trunk/Source/_javascript_Core/tests/stress/proxy-own-keys.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/proxy-own-keys.js	2016-03-04 02:25:30 UTC (rev 197539)
@@ -0,0 +1,560 @@
+function assert(b) {
+    if (!b)
+        throw new Error("Bad assertion.");
+}
+
+{
+    let error = null;
+    let target = { };
+    let handler = {
+        ownKeys: function() {
+            error = new Error;
+            throw error;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e === error);
+        }
+        assert(threw);
+    }
+}
+
+{
+    let error = null;
+    let target = { };
+    let handler = {
+        get ownKeys() {
+            error = new Error;
+            throw error;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e === error);
+        }
+        assert(threw);
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return ["1", 2, 3];
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy handler's 'ownKeys' method must return a array-like object containing only Strings and Symbols.");
+        }
+        assert(threw);
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = { };
+    Object.defineProperty(target, "x", {
+        configurable: false,
+        enumerable: true,
+        value: 400
+    });
+    let called = false;
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return [];
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy object's 'target' has the non-configurable property 'x' that was not in the result from the 'ownKeys' trap.");
+        }
+        assert(threw);
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = { };
+    Object.defineProperty(target, "x", {
+        configurable: true,
+        enumerable: true,
+        value: 400
+    });
+    Object.preventExtensions(target);
+    let called = false;
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return [];
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy object's non-extensible 'target' has configurable property 'x' that was not in the result from the 'ownKeys' trap.");
+        }
+        assert(threw);
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = { };
+    Object.defineProperty(target, "x", {
+        configurable: true,
+        enumerable: true,
+        value: 400
+    });
+    Object.preventExtensions(target);
+    let called = false;
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return ["x", "y"];
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy handler's 'ownKeys' method returned a key that was not present in its target or it returned duplicate keys.");
+        }
+        assert(threw);
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = { };
+    Object.defineProperty(target, "x", {
+        configurable: true,
+        enumerable: true,
+        value: 400
+    });
+    Object.preventExtensions(target);
+    let called = false;
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return ["x", "x"];
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy handler's 'ownKeys' method returned a key that was not present in its target or it returned duplicate keys.");
+        }
+        assert(threw);
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = { };
+    let handler = {
+        ownKeys: 45
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: 'ownKeys' property of a Proxy's handler should be callable.");
+        }
+        assert(threw);
+    }
+}
+
+function shallowEq(a, b) {
+    if (a.length !== b.length)
+        return false;
+    for (let i = 0; i < a.length; i++) {
+        if (a[i] !== b[i])
+            return false;
+    }
+
+    return true;
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let arr = ["a", "b", "c"];
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Object.keys(proxy);
+        assert(result !== arr);
+        assert(shallowEq(result, arr));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let arr = ["a", "b", "c"];
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.ownKeys(proxy);
+        assert(result !== arr);
+        assert(shallowEq(result, arr));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Object.getOwnPropertySymbols(proxy);
+        assert(shallowEq(result, [s1, s2]));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Object.keys(proxy);
+        assert(shallowEq(result, ["a", "b", "c"]));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.ownKeys(proxy);
+        assert(shallowEq(result, ["a", "b", "c", s1, s2]));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        getOwnPropertyDescriptor: () => {
+            return { enumerable: true, configurable: true }
+        },
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let set = new Set;
+        for (let p in proxy)
+            set.add(p);
+        assert(set.size === 3);
+        assert(set.has("a"));
+        assert(set.has("b"));
+        assert(set.has("c"));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        getOwnPropertyDescriptor: () => {
+            return { enumerable: true, configurable: true }
+        },
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let set = new Set;
+        for (let p in proxy)
+            set.add(p);
+        if (i === 40) { // Make sure we don't cache the result.
+            arr.push("d");
+        }
+        assert(set.size === i > 40 ? 4 : 3);
+        assert(set.has("a"));
+        assert(set.has("b"));
+        assert(set.has("c"));
+        if (i > 40)
+            assert(set.has("d"));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        getOwnPropertyDescriptor: () => {
+            return { enumerable: true, configurable: true }
+        },
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    let proxyish = Object.create(proxy, {
+        d: { enumerable: true, configurable: true }
+    });
+    for (let i = 0; i < 500; i++) {
+        let set = new Set;
+        for (let p in proxyish)
+            set.add(p);
+        assert(set.size === 4);
+        assert(set.has("a"));
+        assert(set.has("b"));
+        assert(set.has("c"));
+        assert(set.has("d"));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let target = {
+        x: 40
+    };
+    let called = false;
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        getOwnPropertyDescriptor: () => {
+            return { enumerable: true, configurable: true }
+        },
+        ownKeys: function(theTarget) {
+            called = true;
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    let proxyish = Object.create(proxy, {
+        d: { enumerable: true, configurable: true }
+    });
+    for (let i = 0; i < 500; i++) {
+        let set = new Set;
+        for (let p in proxyish)
+            set.add(p);
+        assert(set.size === 4);
+        assert(set.has("a"));
+        assert(set.has("b"));
+        assert(set.has("c"));
+        assert(set.has("d"));
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let called = false;
+    let target = {x: 20, y: 40};
+    let handler = {
+        ownKeys: null
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let keys = Object.keys(proxy);
+        assert(keys.indexOf("x") !== -1);
+        assert(keys.indexOf("y") !== -1);
+    }
+}
+
+{
+    let called = false;
+    let target = new Proxy({}, {
+        ownKeys: function(theTarget) {
+            called = true;
+            return Reflect.ownKeys(theTarget);
+        }
+    });
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        ownKeys: function(theTarget) {
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let keys = Object.keys(proxy);
+        assert(called);
+        called = false;
+    }
+}
+
+{
+    let error = null;
+    let target = new Proxy({}, {
+        ownKeys: function(theTarget) {
+            error = new Error;
+            throw error;
+        }
+    });
+    let s1 = Symbol();
+    let s2 = Symbol();
+    let arr = ["a", "b", s1, "c", s2];
+    let handler = {
+        ownKeys: function(theTarget) {
+            return arr;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.keys(proxy);
+        } catch(e) {
+            threw = true;
+            assert(e === error);
+        }
+        assert(threw);
+        error = null;
+    }
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to