Title: [197295] trunk/Source/_javascript_Core
Revision
197295
Author
[email protected]
Date
2016-02-28 10:40:35 -0800 (Sun, 28 Feb 2016)

Log Message

ProxyObject.[[GetOwnProperty]] is partially broken because it doesn't propagate information back to the slot
https://bugs.webkit.org/show_bug.cgi?id=154768

Reviewed by Ryosuke Niwa.

This fixes a big bug with ProxyObject.[[GetOwnProperty]]:
http://www.ecma-international.org/ecma-262/6.0/index.html#sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p
We weren't correctly propagating the result of this operation to the
out PropertySlot& parameter. This patch fixes that and adds tests.

* runtime/ObjectConstructor.cpp:
(JSC::objectConstructorGetOwnPropertyDescriptor):
I added a missing exception check after object allocation
because I saw that it was missing while reading the code.

* runtime/PropertyDescriptor.cpp:
(JSC::PropertyDescriptor::setUndefined):
(JSC::PropertyDescriptor::slowGetterSetter):
(JSC::PropertyDescriptor::getter):
* runtime/PropertyDescriptor.h:
(JSC::PropertyDescriptor::attributes):
(JSC::PropertyDescriptor::value):
* runtime/ProxyObject.cpp:
(JSC::ProxyObject::performInternalMethodGetOwnProperty):
* tests/es6.yaml:
* tests/stress/proxy-get-own-property.js:
(let.handler.getOwnPropertyDescriptor):
(set get let.handler.return):
(set get let.handler.getOwnPropertyDescriptor):
(set get let):
(set get let.a):
(let.b):
(let.setter):
(let.getter):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (197294 => 197295)


--- trunk/Source/_javascript_Core/ChangeLog	2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-02-28 18:40:35 UTC (rev 197295)
@@ -1,3 +1,40 @@
+2016-02-28  Saam barati  <[email protected]>
+
+        ProxyObject.[[GetOwnProperty]] is partially broken because it doesn't propagate information back to the slot
+        https://bugs.webkit.org/show_bug.cgi?id=154768
+
+        Reviewed by Ryosuke Niwa.
+
+        This fixes a big bug with ProxyObject.[[GetOwnProperty]]:
+        http://www.ecma-international.org/ecma-262/6.0/index.html#sec-proxy-object-internal-methods-and-internal-slots-getownproperty-p
+        We weren't correctly propagating the result of this operation to the
+        out PropertySlot& parameter. This patch fixes that and adds tests.
+
+        * runtime/ObjectConstructor.cpp:
+        (JSC::objectConstructorGetOwnPropertyDescriptor):
+        I added a missing exception check after object allocation
+        because I saw that it was missing while reading the code.
+
+        * runtime/PropertyDescriptor.cpp:
+        (JSC::PropertyDescriptor::setUndefined):
+        (JSC::PropertyDescriptor::slowGetterSetter):
+        (JSC::PropertyDescriptor::getter):
+        * runtime/PropertyDescriptor.h:
+        (JSC::PropertyDescriptor::attributes):
+        (JSC::PropertyDescriptor::value):
+        * runtime/ProxyObject.cpp:
+        (JSC::ProxyObject::performInternalMethodGetOwnProperty):
+        * tests/es6.yaml:
+        * tests/stress/proxy-get-own-property.js:
+        (let.handler.getOwnPropertyDescriptor):
+        (set get let.handler.return):
+        (set get let.handler.getOwnPropertyDescriptor):
+        (set get let):
+        (set get let.a):
+        (let.b):
+        (let.setter):
+        (let.getter):
+
 2016-02-27  Andy VanWagoner  <[email protected]>
 
         Intl.Collator uses POSIX locale (detected by js/intl-collator.html on iOS Simulator)

Modified: trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp (197294 => 197295)


--- trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2016-02-28 18:40:35 UTC (rev 197295)
@@ -232,6 +232,8 @@
         return jsUndefined();
 
     JSObject* description = constructEmptyObject(exec);
+    if (exec->hadException())
+        return jsUndefined();
     if (!descriptor.isAccessorDescriptor()) {
         description->putDirect(exec->vm(), exec->propertyNames().value, descriptor.value() ? descriptor.value() : jsUndefined(), 0);
         description->putDirect(exec->vm(), exec->propertyNames().writable, jsBoolean(descriptor.writable()), 0);

Modified: trunk/Source/_javascript_Core/runtime/PropertyDescriptor.cpp (197294 => 197295)


--- trunk/Source/_javascript_Core/runtime/PropertyDescriptor.cpp	2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/_javascript_Core/runtime/PropertyDescriptor.cpp	2016-02-28 18:40:35 UTC (rev 197295)
@@ -72,6 +72,21 @@
     m_attributes = ReadOnly | DontDelete | DontEnum;
 }
 
+GetterSetter* PropertyDescriptor::slowGetterSetter(ExecState* exec)
+{
+    VM& vm = exec->vm();
+    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+    GetterSetter* getterSetter = GetterSetter::create(vm, globalObject);
+    if (exec->hadException())
+        return nullptr;
+    if (m_getter && !m_getter.isUndefined())
+        getterSetter->setGetter(vm, globalObject, jsCast<JSObject*>(m_getter));
+    if (m_setter && !m_setter.isUndefined())
+        getterSetter->setSetter(vm, globalObject, jsCast<JSObject*>(m_setter));
+
+    return getterSetter;
+}
+
 JSValue PropertyDescriptor::getter() const
 {
     ASSERT(isAccessorDescriptor());

Modified: trunk/Source/_javascript_Core/runtime/PropertyDescriptor.h (197294 => 197295)


--- trunk/Source/_javascript_Core/runtime/PropertyDescriptor.h	2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/_javascript_Core/runtime/PropertyDescriptor.h	2016-02-28 18:40:35 UTC (rev 197295)
@@ -59,6 +59,7 @@
     JS_EXPORT_PRIVATE bool isAccessorDescriptor() const;
     unsigned attributes() const { return m_attributes; }
     JSValue value() const { return m_value; }
+    GetterSetter* slowGetterSetter(ExecState*); // Be aware that this will lazily allocate a GetterSetter object. It's much better to use getter() and setter() individually if possible.
     JS_EXPORT_PRIVATE JSValue getter() const;
     JS_EXPORT_PRIVATE JSValue setter() const;
     JSObject* getterObject() const;

Modified: trunk/Source/_javascript_Core/runtime/ProxyObject.cpp (197294 => 197295)


--- trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/_javascript_Core/runtime/ProxyObject.cpp	2016-02-28 18:40:35 UTC (rev 197295)
@@ -138,7 +138,6 @@
 bool ProxyObject::performInternalMethodGetOwnProperty(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
 {
     VM& vm = exec->vm();
-    slot.setValue(this, None, jsUndefined()); // We do this to protect against any bad actors. Nobody should depend on this value.
     JSValue handlerValue = this->handler();
     if (handlerValue.isNull()) {
         throwVMTypeError(exec, ASCIILiteral("Proxy 'handler' is null. It should be an Object."));
@@ -211,6 +210,16 @@
         }
     }
 
+    if (trapResultAsDescriptor.isAccessorDescriptor()) {
+        GetterSetter* getterSetter = trapResultAsDescriptor.slowGetterSetter(exec);
+        if (exec->hadException())
+            return false;
+        slot.setGetterSlot(this, trapResultAsDescriptor.attributes(), getterSetter);
+    } else if (trapResultAsDescriptor.isDataDescriptor())
+        slot.setValue(this, trapResultAsDescriptor.attributes(), trapResultAsDescriptor.value());
+    else
+        slot.setValue(this, trapResultAsDescriptor.attributes(), jsUndefined()); // We use undefined because it's the default value in object properties.
+
     return true;
 }
 

Modified: trunk/Source/_javascript_Core/tests/es6.yaml (197294 => 197295)


--- trunk/Source/_javascript_Core/tests/es6.yaml	2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/_javascript_Core/tests/es6.yaml	2016-02-28 18:40:35 UTC (rev 197295)
@@ -925,7 +925,7 @@
 - path: es6/Proxy_get_handler_instances_of_proxies.js
   cmd: runES6 :normal
 - path: es6/Proxy_getOwnPropertyDescriptor_handler.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_getPrototypeOf_handler.js
   cmd: runES6 :fail
 - path: es6/Proxy_has_handler.js

Modified: trunk/Source/_javascript_Core/tests/stress/proxy-get-own-property.js (197294 => 197295)


--- trunk/Source/_javascript_Core/tests/stress/proxy-get-own-property.js	2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/_javascript_Core/tests/stress/proxy-get-own-property.js	2016-02-28 18:40:35 UTC (rev 197295)
@@ -263,3 +263,189 @@
         called = false;
     }
 }
+
+{
+    let target = {};
+    Object.defineProperty(target, "x", {
+        enumerable: false,
+        configurable: false,
+        writable: true,
+        value: 50
+    });
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {enumerable: false, value: 45};
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let desc = Object.getOwnPropertyDescriptor(proxy, "x");
+        assert(desc.configurable === false);
+        assert(desc.enumerable === false);
+        assert(desc.writable === false);
+        assert(desc.value === 45);
+    }
+}
+
+{
+    let target = {};
+    Object.defineProperty(target, "x", {
+        enumerable: false,
+        configurable: false,
+        writable: true
+    });
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {enumerable: false, value: 45};
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let desc = Object.getOwnPropertyDescriptor(proxy, "x");
+        assert(desc.configurable === false);
+        assert(desc.enumerable === false);
+        assert(desc.writable === false);
+        assert(desc.value === 45);
+    }
+}
+
+{
+    let target = {};
+    Object.defineProperty(target, "x", {
+        enumerable: true,
+        configurable: true,
+        writable: true
+    });
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {configurable: true, value: 45, enumerable: true};
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let desc = Object.getOwnPropertyDescriptor(proxy, "x");
+        assert(desc.configurable === true);
+        assert(desc.enumerable === true);
+        assert(desc.writable === false);
+        assert(desc.value === 45);
+    }
+}
+
+{
+    let target = {};
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {configurable: true, value: 45, enumerable: true};
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let desc = Object.getOwnPropertyDescriptor(proxy, "x");
+        assert(desc.configurable === true);
+        assert(desc.enumerable === true);
+        assert(desc.writable === false);
+        assert(desc.value === 45);
+    }
+}
+
+{
+    let target = {};
+    Object.defineProperty(target, "x", {
+        get: function() { return 25; },
+        set: function() { return 50; },
+        configurable: false
+    });
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {configurable: false, set:function(){}, get:function(){} };
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.getOwnPropertyDescriptor(proxy, "x");
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Result from 'getOwnPropertyDescriptor' fails the IsCompatiblePropertyDescriptor test.");
+        }
+        assert(threw);
+    }
+}
+
+{
+    let target = {};
+    Object.defineProperty(target, "x", {
+        get: function() { return 25; },
+        set: function() { return 50; },
+        configurable: true
+    });
+    let a = function() { };
+    let b = function() {}
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {configurable: true, set: a, get: b };
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Object.getOwnPropertyDescriptor(proxy, "x");
+        assert(result.configurable);
+        assert(result.set === a);
+        assert(result.get === b);
+    }
+}
+
+{
+    let target = {};
+    Object.defineProperty(target, "x", {
+        get: function() { return 25; },
+        set: function() { return 50; },
+        configurable: false
+    });
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {configurable: false, set:function(){}, get:function(){} };
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.getOwnPropertyDescriptor(proxy, "x");
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Result from 'getOwnPropertyDescriptor' fails the IsCompatiblePropertyDescriptor test.");
+        }
+        assert(threw);
+    }
+}
+
+{
+    let target = {};
+    let setter = function() { };
+    let getter = function() { };
+    Object.defineProperty(target, "x", {
+        get: getter,
+        set: setter,
+        configurable: false
+    });
+    let handler = {
+        getOwnPropertyDescriptor: function(theTarget, propName) {
+            return {
+                configurable: false, 
+                set: setter, 
+                get: getter
+            };
+        }
+    };
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let desc = Object.getOwnPropertyDescriptor(proxy, "x");
+        assert(desc.configurable === false);
+        assert(desc.get === getter);
+        assert(desc.set === setter);
+        assert(desc.enumerable === false);
+        assert(desc.writable === undefined);
+    }
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to