[ES6] Implement Proxy.[[DefineOwnProperty]]
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2016 01:07:04 +0000 (01:07 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2016 01:07:04 +0000 (01:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154759

Reviewed by Geoffrey Garen and Mark Lam.

This patch is a straight forward implementation of Proxy.[[DefineOwnProperty]]
with respect to section 9.5.6 of the ECMAScript spec.
https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc

* runtime/ObjectConstructor.cpp:
(JSC::objectConstructorGetOwnPropertyDescriptor):
(JSC::objectConstructorGetOwnPropertyDescriptors):
* runtime/ObjectConstructor.h:
(JSC::constructEmptyObject):
(JSC::constructObjectFromPropertyDescriptor):
* runtime/ProxyObject.cpp:
(JSC::ProxyObject::isExtensible):
(JSC::ProxyObject::performDefineOwnProperty):
(JSC::ProxyObject::defineOwnProperty):
(JSC::ProxyObject::visitChildren):
* runtime/ProxyObject.h:
* tests/es6.yaml:
* tests/stress/proxy-define-own-property.js: Added.
(assert):
(throw.new.Error):
(assert.let.handler.get defineProperty):
(assert.let.handler.defineProperty):
(let.handler.defineProperty):
(i.catch):
(assert.try.):
(assert.set get catch):
(assert.let.setter):
(assert.let.getter):
(assert.set get let.handler.defineProperty):
(assert.set get let):
(assert.):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197533 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ObjectConstructor.cpp
Source/JavaScriptCore/runtime/ObjectConstructor.h
Source/JavaScriptCore/runtime/ProxyObject.cpp
Source/JavaScriptCore/runtime/ProxyObject.h
Source/JavaScriptCore/tests/es6.yaml
Source/JavaScriptCore/tests/stress/proxy-define-own-property.js [new file with mode: 0644]

index 772d608..27187c9 100644 (file)
@@ -1,3 +1,42 @@
+2016-03-03  Saam barati  <sbarati@apple.com>
+
+        [ES6] Implement Proxy.[[DefineOwnProperty]]
+        https://bugs.webkit.org/show_bug.cgi?id=154759
+
+        Reviewed by Geoffrey Garen and Mark Lam.
+
+        This patch is a straight forward implementation of Proxy.[[DefineOwnProperty]]
+        with respect to section 9.5.6 of the ECMAScript spec.
+        https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-defineownproperty-p-desc
+
+        * runtime/ObjectConstructor.cpp:
+        (JSC::objectConstructorGetOwnPropertyDescriptor):
+        (JSC::objectConstructorGetOwnPropertyDescriptors):
+        * runtime/ObjectConstructor.h:
+        (JSC::constructEmptyObject):
+        (JSC::constructObjectFromPropertyDescriptor):
+        * runtime/ProxyObject.cpp:
+        (JSC::ProxyObject::isExtensible):
+        (JSC::ProxyObject::performDefineOwnProperty):
+        (JSC::ProxyObject::defineOwnProperty):
+        (JSC::ProxyObject::visitChildren):
+        * runtime/ProxyObject.h:
+        * tests/es6.yaml:
+        * tests/stress/proxy-define-own-property.js: Added.
+        (assert):
+        (throw.new.Error):
+        (assert.let.handler.get defineProperty):
+        (assert.let.handler.defineProperty):
+        (let.handler.defineProperty):
+        (i.catch):
+        (assert.try.):
+        (assert.set get catch):
+        (assert.let.setter):
+        (assert.let.getter):
+        (assert.set get let.handler.defineProperty):
+        (assert.set get let):
+        (assert.):
+
 2016-03-03  Keith Miller  <keith_miller@apple.com>
 
         [ES6] Add support for Symbol.toPrimitive
index 75ddd18..20d0d24 100644 (file)
@@ -224,23 +224,10 @@ JSValue objectConstructorGetOwnPropertyDescriptor(ExecState* exec, JSObject* obj
     if (exec->hadException())
         return jsUndefined();
 
-    JSObject* description = constructEmptyObject(exec);
-    if (exec->hadException())
+    JSObject* result = constructObjectFromPropertyDescriptor(exec, descriptor);
+    if (!result)
         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);
-    } else {
-        ASSERT(descriptor.getter());
-        ASSERT(descriptor.setter());
-        description->putDirect(exec->vm(), exec->propertyNames().get, descriptor.getter(), 0);
-        description->putDirect(exec->vm(), exec->propertyNames().set, descriptor.setter(), 0);
-    }
-    
-    description->putDirect(exec->vm(), exec->propertyNames().enumerable, jsBoolean(descriptor.enumerable()), 0);
-    description->putDirect(exec->vm(), exec->propertyNames().configurable, jsBoolean(descriptor.configurable()), 0);
-
-    return description;
+    return result;
 }
 
 JSValue objectConstructorGetOwnPropertyDescriptors(ExecState* exec, JSObject* object)
index 6a12f56..9fa64d4 100644 (file)
@@ -91,6 +91,32 @@ inline JSObject* constructEmptyObject(ExecState* exec)
     return constructEmptyObject(exec, exec->lexicalGlobalObject()->objectPrototype());
 }
 
+// Section 6.2.4.4 of the ES6 specification.
+// https://tc39.github.io/ecma262/#sec-frompropertydescriptor
+inline JSObject* constructObjectFromPropertyDescriptor(ExecState* exec, const PropertyDescriptor& descriptor)
+{
+    VM& vm = exec->vm();
+    JSObject* description = constructEmptyObject(exec);
+    if (vm.exception())
+        return nullptr;
+
+    if (!descriptor.isAccessorDescriptor()) {
+        description->putDirect(vm, vm.propertyNames->value, descriptor.value() ? descriptor.value() : jsUndefined(), 0);
+        description->putDirect(vm, vm.propertyNames->writable, jsBoolean(descriptor.writable()), 0);
+    } else {
+        ASSERT(descriptor.getter());
+        ASSERT(descriptor.setter());
+        description->putDirect(vm, vm.propertyNames->get, descriptor.getter(), 0);
+        description->putDirect(vm, vm.propertyNames->set, descriptor.setter(), 0);
+    }
+    
+    description->putDirect(vm, vm.propertyNames->enumerable, jsBoolean(descriptor.enumerable()), 0);
+    description->putDirect(vm, vm.propertyNames->configurable, jsBoolean(descriptor.configurable()), 0);
+
+    return description;
+}
+
+
 JSObject* objectConstructorFreeze(ExecState*, JSObject*);
 JSValue objectConstructorGetPrototypeOf(ExecState*, JSObject*);
 JSValue objectConstructorGetOwnPropertyDescriptor(ExecState*, JSObject*, const Identifier&);
index 6b0ba5e..3b7562d 100644 (file)
@@ -708,6 +708,99 @@ bool ProxyObject::isExtensible(JSObject* object, ExecState* exec)
     return jsCast<ProxyObject*>(object)->performIsExtensible(exec);
 }
 
+bool ProxyObject::performDefineOwnProperty(ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
+{
+    VM& vm = exec->vm();
+
+    JSObject* target = this->target();
+    auto performDefaultDefineOwnProperty = [&] {
+        return target->methodTable(vm)->defineOwnProperty(target, exec, propertyName, descriptor, shouldThrow);
+    };
+
+    if (vm.propertyNames->isPrivateName(Identifier::fromUid(&vm, propertyName.uid())))
+        return performDefaultDefineOwnProperty();
+
+    JSValue handlerValue = this->handler();
+    if (handlerValue.isNull()) {
+        throwVMTypeError(exec, ASCIILiteral("Proxy 'handler' is null. It should be an Object."));
+        return false;
+    }
+
+    JSObject* handler = jsCast<JSObject*>(handlerValue);
+    CallData callData;
+    CallType callType;
+    JSValue definePropertyMethod = handler->getMethod(exec, callData, callType, vm.propertyNames->defineProperty, ASCIILiteral("'defineProperty' property of a Proxy's handler should be callable."));
+    if (vm.exception())
+        return false;
+
+    if (definePropertyMethod.isUndefined())
+        return performDefaultDefineOwnProperty();
+
+    JSObject* descriptorObject = constructObjectFromPropertyDescriptor(exec, descriptor);
+    if (vm.exception())
+        return false;
+
+    MarkedArgumentBuffer arguments;
+    arguments.append(target);
+    arguments.append(identifierToSafePublicJSValue(vm, Identifier::fromUid(&vm, propertyName.uid())));
+    arguments.append(descriptorObject);
+    JSValue trapResult = call(exec, definePropertyMethod, callType, callData, handler, arguments);
+    if (vm.exception())
+        return false;
+
+    bool trapResultAsBool = trapResult.toBoolean(exec);
+    if (vm.exception())
+        return false;
+
+    if (!trapResultAsBool)
+        return false;
+
+    PropertyDescriptor targetDescriptor;
+    bool isTargetDescriptorDefined = target->getOwnPropertyDescriptor(exec, propertyName, targetDescriptor);
+    if (vm.exception())
+        return false;
+
+    bool targetIsExtensible = target->isExtensible(exec);
+    if (vm.exception())
+        return false;
+    bool settingConfigurableToFalse = descriptor.configurablePresent() && !descriptor.configurable();
+
+    if (!isTargetDescriptorDefined) {
+        if (!targetIsExtensible) {
+            throwVMTypeError(exec, ASCIILiteral("Proxy's 'defineProperty' trap returned true even though getOwnPropertyDescriptor of the Proxy's target returned undefined and the target is non-extensible."));
+            return false;
+        }
+        if (settingConfigurableToFalse) {
+            throwVMTypeError(exec, ASCIILiteral("Proxy's 'defineProperty' trap returned true for a non-configurable field even though getOwnPropertyDescriptor of the Proxy's target returned undefined."));
+            return false;
+        }
+
+        return true;
+    } 
+
+    ASSERT(isTargetDescriptorDefined);
+    bool isCurrentDefined = isTargetDescriptorDefined;
+    const PropertyDescriptor& current = targetDescriptor;
+    bool throwException = false;
+    bool isCompatibleDescriptor = validateAndApplyPropertyDescriptor(exec, nullptr, propertyName, targetIsExtensible, descriptor, isCurrentDefined, current, throwException);
+    if (!isCompatibleDescriptor) {
+        throwVMTypeError(exec, ASCIILiteral("Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor."));
+        return false;
+    }
+    if (settingConfigurableToFalse && targetDescriptor.configurable()) {
+        throwVMTypeError(exec, ASCIILiteral("Proxy's 'defineProperty' trap did not define a non-configurable property on its target even though the input descriptor to the trap said it must do so."));
+        return false;
+    }
+    
+    return true;
+}
+
+bool ProxyObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool shouldThrow)
+{
+    ProxyObject* thisObject = jsCast<ProxyObject*>(object);
+    return thisObject->performDefineOwnProperty(exec, propertyName, descriptor, shouldThrow);
+}
+
 void ProxyObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     ProxyObject* thisObject = jsCast<ProxyObject*>(cell);
index 0036170..abb7576 100644 (file)
@@ -71,6 +71,7 @@ private:
     static bool deletePropertyByIndex(JSCell*, ExecState*, unsigned propertyName);
     static bool preventExtensions(JSObject*, ExecState*);
     static bool isExtensible(JSObject*, ExecState*);
+    static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
     static void visitChildren(JSCell*, SlotVisitor&);
 
     bool getOwnPropertySlotCommon(ExecState*, PropertyName, PropertySlot&);
@@ -82,6 +83,7 @@ private:
     void performPut(ExecState*, JSValue putValue, JSValue thisValue, PropertyName, PerformDefaultPutFunction);
     bool performPreventExtensions(ExecState*);
     bool performIsExtensible(ExecState*);
+    bool performDefineOwnProperty(ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
 
     WriteBarrier<JSObject> m_target;
     WriteBarrier<Unknown> m_handler;
index 021fd83..ad11910 100644 (file)
 - path: es6/Proxy_constructor_requires_new.js
   cmd: runES6 :normal
 - path: es6/Proxy_defineProperty_handler.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/Proxy_deleteProperty_handler.js
   cmd: runES6 :normal
 - path: es6/Proxy_enumerate_handler.js
diff --git a/Source/JavaScriptCore/tests/stress/proxy-define-own-property.js b/Source/JavaScriptCore/tests/stress/proxy-define-own-property.js
new file mode 100644 (file)
index 0000000..0a25d46
--- /dev/null
@@ -0,0 +1,614 @@
+function assert(b) {
+    if (!b)
+        throw new Error("Bad assertion.");
+}
+
+{
+    let target = {};
+    let handler = {
+        defineProperty: 25
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.defineProperty(proxy, "x", {
+                enumerable: true,
+                configurable: true,
+                value: 55
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: 'defineProperty' property of a Proxy's handler should be callable.");
+        }
+
+        assert(threw);
+    }
+
+}
+
+{
+    let target = {};
+    let error = null;
+    let handler = {
+        get defineProperty() {
+            error = new Error;
+            throw error;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.defineProperty(proxy, "x", {
+                enumerable: true,
+                configurable: true,
+                value: 55
+            });
+        } catch(e) {
+            threw = true;
+            assert(e === error);
+        }
+
+        assert(threw);
+    }
+}
+
+{
+    let target = {};
+    let error = null;
+    let handler = {
+        defineProperty: function() {
+            error = new Error;
+            throw error;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Object.defineProperty(proxy, "x", {
+                enumerable: true,
+                configurable: true,
+                value: 55
+            });
+        } catch(e) {
+            threw = true;
+            assert(e === error);
+        }
+
+        assert(threw);
+    }
+}
+
+{
+    let target = {};
+    let handler = {
+        defineProperty: null
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        Object.defineProperty(proxy, "x", {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === i);
+            assert(pDesc.configurable === true);
+            assert(pDesc.enumerable === true);
+        }
+    }
+}
+
+{
+    let target = {};
+    let handler = {
+        defineProperty: undefined
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+        assert(result);
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === i);
+            assert(pDesc.configurable === true);
+            assert(pDesc.enumerable === true);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            called = true;
+            return Reflect.defineProperty(theTarget, propName, descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+        assert(result);
+        assert(called);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === i);
+            assert(pDesc.configurable === true);
+            assert(pDesc.enumerable === true);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            called = true;
+            Reflect.defineProperty(theTarget, propName, descriptor);
+            return false;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+        assert(!result);
+        assert(called);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === i);
+            assert(pDesc.configurable === true);
+            assert(pDesc.enumerable === true);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            called = true;
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, "x", {
+                enumerable: true,
+                configurable: false,
+                value: i
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy's 'defineProperty' trap returned true for a non-configurable field even though getOwnPropertyDescriptor of the Proxy's target returned undefined.");
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    Object.preventExtensions(target);
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            called = true;
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, "x", {
+                enumerable: true,
+                configurable: true,
+                value: i
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy's 'defineProperty' trap returned true even though getOwnPropertyDescriptor of the Proxy's target returned undefined and the target is non-extensible.");
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === "x");
+            assert(descriptor.configurable === false);
+            called = true;
+            return Reflect.defineProperty(theTarget, "x", {
+                enumerable: true,
+                configurable: true,
+                value: descriptor.value
+            });
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        try {
+            Reflect.defineProperty(proxy, "x", {
+                enumerable: true,
+                configurable: false,
+                value: i
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy's 'defineProperty' trap did not define a non-configurable property on its target even though the input descriptor to the trap said it must do so.");
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === i);
+            assert(pDesc.configurable === true);
+            assert(pDesc.enumerable === true);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    Object.defineProperty(target, "x", {
+        configurable: false,
+        writable: true,
+        value: 55
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === "x");
+            assert(descriptor.configurable === true);
+            called = true;
+            Reflect.defineProperty(theTarget, "x", {
+                enumerable: true,
+                configurable: true,
+                value: descriptor.value
+            });
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, "x", {
+                configurable: true,
+                writable: false,
+                value: 45
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor.");
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === 55);
+            assert(pDesc.configurable === false);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    Object.defineProperty(target, "x", {
+        configurable: false,
+        writable: true,
+        value: 55
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === "x");
+            assert(descriptor.configurable === true);
+            called = true;
+            Reflect.defineProperty(theTarget, "x", descriptor);
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, "x", {
+                configurable: true,
+                set:function(){},
+                get:function(){}
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor.");
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === 55);
+            assert(pDesc.configurable === false);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let setter = function(){};
+    let getter = function(){};
+    Object.defineProperty(target, "x", {
+        configurable: false,
+        get: getter,
+        set: setter
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === "x");
+            assert(descriptor.configurable === true);
+            called = true;
+            Reflect.defineProperty(theTarget, "x", descriptor);
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, "x", {
+                configurable: true,
+                value: 45
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === "TypeError: Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor.");
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === undefined);
+            assert(pDesc.configurable === false);
+            assert(pDesc.get === getter);
+            assert(pDesc.set === setter);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let setter = function(){};
+    let getter = function(){};
+    Object.defineProperty(target, "x", {
+        configurable: false,
+        get: getter,
+        set: setter
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === "x");
+            assert(descriptor.configurable === true);
+            called = true;
+            return Reflect.defineProperty(theTarget, "x", descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            configurable: true,
+            value: 45
+        });
+        assert(!result);
+        assert(called);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, "x");
+            assert(pDesc.value === undefined);
+            assert(pDesc.configurable === false);
+            assert(pDesc.get === getter);
+            assert(pDesc.set === setter);
+        }
+    }
+}
+
+{
+    let error = false;
+    let target = new Proxy({}, {
+        getOwnPropertyDescriptor: function() {
+            error = new Error;
+            throw error;
+        }
+    });
+
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            return Reflect.defineProperty(theTarget, propName, descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, "x", {
+                configurable: true,
+                value: 45
+            });
+        } catch(e) {
+            threw = true;
+            assert(e === error);
+        }
+        assert(threw);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, "x", {
+        writable: true,
+        configurable: false,
+        value: 55
+    });
+
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(theTarget === target);
+            return Reflect.defineProperty(theTarget, propName, descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            configurable: false,
+            value: 55
+        });
+        assert(result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, "x", {
+        writable: false,
+        configurable: false,
+        value: 55
+    });
+
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(theTarget === target);
+            return Reflect.defineProperty(theTarget, propName, descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            writable: false,
+            configurable: false,
+            value: 55
+        });
+        assert(result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, "x", {
+        writable: false,
+        configurable: false,
+        value: 55
+    });
+
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(theTarget === target);
+            return Reflect.defineProperty(theTarget, propName, descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            writable: false,
+            configurable: false,
+            value: "not 55"
+        });
+        assert(!result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, "x", {
+        writable: false,
+        configurable: false,
+        value: 55
+    });
+
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(theTarget === target);
+            return Reflect.defineProperty(theTarget, propName, descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i < 500; i++) {
+        let result = Reflect.defineProperty(proxy, "x", {
+            writable: true,
+            configurable: false,
+            value: "whatever value goes here."
+        });
+        assert(!result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}