<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[197533] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/197533">197533</a></dd>
<dt>Author</dt> <dd>sbarati@apple.com</dd>
<dt>Date</dt> <dd>2016-03-03 17:07:04 -0800 (Thu, 03 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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.):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeObjectConstructorcpp">trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeObjectConstructorh">trunk/Source/JavaScriptCore/runtime/ObjectConstructor.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeProxyObjectcpp">trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeProxyObjecth">trunk/Source/JavaScriptCore/runtime/ProxyObject.h</a></li>
<li><a href="#trunkSourceJavaScriptCoretestses6yaml">trunk/Source/JavaScriptCore/tests/es6.yaml</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressproxydefineownpropertyjs">trunk/Source/JavaScriptCore/tests/stress/proxy-define-own-property.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (197532 => 197533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-03-04 00:54:21 UTC (rev 197532)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-03-04 01:07:04 UTC (rev 197533)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2016-03-03  Saam barati  &lt;sbarati@apple.com&gt;
+
+        [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.):
+
</ins><span class="cx"> 2016-03-03  Keith Miller  &lt;keith_miller@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [ES6] Add support for Symbol.toPrimitive
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeObjectConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp (197532 => 197533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp        2016-03-04 00:54:21 UTC (rev 197532)
+++ trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp        2016-03-04 01:07:04 UTC (rev 197533)
</span><span class="lines">@@ -224,23 +224,10 @@
</span><span class="cx">     if (exec-&gt;hadException())
</span><span class="cx">         return jsUndefined();
</span><span class="cx"> 
</span><del>-    JSObject* description = constructEmptyObject(exec);
-    if (exec-&gt;hadException())
</del><ins>+    JSObject* result = constructObjectFromPropertyDescriptor(exec, descriptor);
+    if (!result)
</ins><span class="cx">         return jsUndefined();
</span><del>-    if (!descriptor.isAccessorDescriptor()) {
-        description-&gt;putDirect(exec-&gt;vm(), exec-&gt;propertyNames().value, descriptor.value() ? descriptor.value() : jsUndefined(), 0);
-        description-&gt;putDirect(exec-&gt;vm(), exec-&gt;propertyNames().writable, jsBoolean(descriptor.writable()), 0);
-    } else {
-        ASSERT(descriptor.getter());
-        ASSERT(descriptor.setter());
-        description-&gt;putDirect(exec-&gt;vm(), exec-&gt;propertyNames().get, descriptor.getter(), 0);
-        description-&gt;putDirect(exec-&gt;vm(), exec-&gt;propertyNames().set, descriptor.setter(), 0);
-    }
-    
-    description-&gt;putDirect(exec-&gt;vm(), exec-&gt;propertyNames().enumerable, jsBoolean(descriptor.enumerable()), 0);
-    description-&gt;putDirect(exec-&gt;vm(), exec-&gt;propertyNames().configurable, jsBoolean(descriptor.configurable()), 0);
-
-    return description;
</del><ins>+    return result;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> JSValue objectConstructorGetOwnPropertyDescriptors(ExecState* exec, JSObject* object)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeObjectConstructorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ObjectConstructor.h (197532 => 197533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ObjectConstructor.h        2016-03-04 00:54:21 UTC (rev 197532)
+++ trunk/Source/JavaScriptCore/runtime/ObjectConstructor.h        2016-03-04 01:07:04 UTC (rev 197533)
</span><span class="lines">@@ -91,6 +91,32 @@
</span><span class="cx">     return constructEmptyObject(exec, exec-&gt;lexicalGlobalObject()-&gt;objectPrototype());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// Section 6.2.4.4 of the ES6 specification.
+// https://tc39.github.io/ecma262/#sec-frompropertydescriptor
+inline JSObject* constructObjectFromPropertyDescriptor(ExecState* exec, const PropertyDescriptor&amp; descriptor)
+{
+    VM&amp; vm = exec-&gt;vm();
+    JSObject* description = constructEmptyObject(exec);
+    if (vm.exception())
+        return nullptr;
+
+    if (!descriptor.isAccessorDescriptor()) {
+        description-&gt;putDirect(vm, vm.propertyNames-&gt;value, descriptor.value() ? descriptor.value() : jsUndefined(), 0);
+        description-&gt;putDirect(vm, vm.propertyNames-&gt;writable, jsBoolean(descriptor.writable()), 0);
+    } else {
+        ASSERT(descriptor.getter());
+        ASSERT(descriptor.setter());
+        description-&gt;putDirect(vm, vm.propertyNames-&gt;get, descriptor.getter(), 0);
+        description-&gt;putDirect(vm, vm.propertyNames-&gt;set, descriptor.setter(), 0);
+    }
+    
+    description-&gt;putDirect(vm, vm.propertyNames-&gt;enumerable, jsBoolean(descriptor.enumerable()), 0);
+    description-&gt;putDirect(vm, vm.propertyNames-&gt;configurable, jsBoolean(descriptor.configurable()), 0);
+
+    return description;
+}
+
+
</ins><span class="cx"> JSObject* objectConstructorFreeze(ExecState*, JSObject*);
</span><span class="cx"> JSValue objectConstructorGetPrototypeOf(ExecState*, JSObject*);
</span><span class="cx"> JSValue objectConstructorGetOwnPropertyDescriptor(ExecState*, JSObject*, const Identifier&amp;);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeProxyObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp (197532 => 197533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp        2016-03-04 00:54:21 UTC (rev 197532)
+++ trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp        2016-03-04 01:07:04 UTC (rev 197533)
</span><span class="lines">@@ -708,6 +708,99 @@
</span><span class="cx">     return jsCast&lt;ProxyObject*&gt;(object)-&gt;performIsExtensible(exec);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool ProxyObject::performDefineOwnProperty(ExecState* exec, PropertyName propertyName, const PropertyDescriptor&amp; descriptor, bool shouldThrow)
+{
+    VM&amp; vm = exec-&gt;vm();
+
+    JSObject* target = this-&gt;target();
+    auto performDefaultDefineOwnProperty = [&amp;] {
+        return target-&gt;methodTable(vm)-&gt;defineOwnProperty(target, exec, propertyName, descriptor, shouldThrow);
+    };
+
+    if (vm.propertyNames-&gt;isPrivateName(Identifier::fromUid(&amp;vm, propertyName.uid())))
+        return performDefaultDefineOwnProperty();
+
+    JSValue handlerValue = this-&gt;handler();
+    if (handlerValue.isNull()) {
+        throwVMTypeError(exec, ASCIILiteral(&quot;Proxy 'handler' is null. It should be an Object.&quot;));
+        return false;
+    }
+
+    JSObject* handler = jsCast&lt;JSObject*&gt;(handlerValue);
+    CallData callData;
+    CallType callType;
+    JSValue definePropertyMethod = handler-&gt;getMethod(exec, callData, callType, vm.propertyNames-&gt;defineProperty, ASCIILiteral(&quot;'defineProperty' property of a Proxy's handler should be callable.&quot;));
+    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(&amp;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-&gt;getOwnPropertyDescriptor(exec, propertyName, targetDescriptor);
+    if (vm.exception())
+        return false;
+
+    bool targetIsExtensible = target-&gt;isExtensible(exec);
+    if (vm.exception())
+        return false;
+    bool settingConfigurableToFalse = descriptor.configurablePresent() &amp;&amp; !descriptor.configurable();
+
+    if (!isTargetDescriptorDefined) {
+        if (!targetIsExtensible) {
+            throwVMTypeError(exec, ASCIILiteral(&quot;Proxy's 'defineProperty' trap returned true even though getOwnPropertyDescriptor of the Proxy's target returned undefined and the target is non-extensible.&quot;));
+            return false;
+        }
+        if (settingConfigurableToFalse) {
+            throwVMTypeError(exec, ASCIILiteral(&quot;Proxy's 'defineProperty' trap returned true for a non-configurable field even though getOwnPropertyDescriptor of the Proxy's target returned undefined.&quot;));
+            return false;
+        }
+
+        return true;
+    } 
+
+    ASSERT(isTargetDescriptorDefined);
+    bool isCurrentDefined = isTargetDescriptorDefined;
+    const PropertyDescriptor&amp; current = targetDescriptor;
+    bool throwException = false;
+    bool isCompatibleDescriptor = validateAndApplyPropertyDescriptor(exec, nullptr, propertyName, targetIsExtensible, descriptor, isCurrentDefined, current, throwException);
+    if (!isCompatibleDescriptor) {
+        throwVMTypeError(exec, ASCIILiteral(&quot;Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor.&quot;));
+        return false;
+    }
+    if (settingConfigurableToFalse &amp;&amp; targetDescriptor.configurable()) {
+        throwVMTypeError(exec, ASCIILiteral(&quot;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.&quot;));
+        return false;
+    }
+    
+    return true;
+}
+
+bool ProxyObject::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor&amp; descriptor, bool shouldThrow)
+{
+    ProxyObject* thisObject = jsCast&lt;ProxyObject*&gt;(object);
+    return thisObject-&gt;performDefineOwnProperty(exec, propertyName, descriptor, shouldThrow);
+}
+
</ins><span class="cx"> void ProxyObject::visitChildren(JSCell* cell, SlotVisitor&amp; visitor)
</span><span class="cx"> {
</span><span class="cx">     ProxyObject* thisObject = jsCast&lt;ProxyObject*&gt;(cell);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeProxyObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ProxyObject.h (197532 => 197533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ProxyObject.h        2016-03-04 00:54:21 UTC (rev 197532)
+++ trunk/Source/JavaScriptCore/runtime/ProxyObject.h        2016-03-04 01:07:04 UTC (rev 197533)
</span><span class="lines">@@ -71,6 +71,7 @@
</span><span class="cx">     static bool deletePropertyByIndex(JSCell*, ExecState*, unsigned propertyName);
</span><span class="cx">     static bool preventExtensions(JSObject*, ExecState*);
</span><span class="cx">     static bool isExtensible(JSObject*, ExecState*);
</span><ins>+    static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&amp;, bool shouldThrow);
</ins><span class="cx">     static void visitChildren(JSCell*, SlotVisitor&amp;);
</span><span class="cx"> 
</span><span class="cx">     bool getOwnPropertySlotCommon(ExecState*, PropertyName, PropertySlot&amp;);
</span><span class="lines">@@ -82,6 +83,7 @@
</span><span class="cx">     void performPut(ExecState*, JSValue putValue, JSValue thisValue, PropertyName, PerformDefaultPutFunction);
</span><span class="cx">     bool performPreventExtensions(ExecState*);
</span><span class="cx">     bool performIsExtensible(ExecState*);
</span><ins>+    bool performDefineOwnProperty(ExecState*, PropertyName, const PropertyDescriptor&amp;, bool shouldThrow);
</ins><span class="cx"> 
</span><span class="cx">     WriteBarrier&lt;JSObject&gt; m_target;
</span><span class="cx">     WriteBarrier&lt;Unknown&gt; m_handler;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestses6yaml"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/es6.yaml (197532 => 197533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/es6.yaml        2016-03-04 00:54:21 UTC (rev 197532)
+++ trunk/Source/JavaScriptCore/tests/es6.yaml        2016-03-04 01:07:04 UTC (rev 197533)
</span><span class="lines">@@ -915,7 +915,7 @@
</span><span class="cx"> - path: es6/Proxy_constructor_requires_new.js
</span><span class="cx">   cmd: runES6 :normal
</span><span class="cx"> - path: es6/Proxy_defineProperty_handler.js
</span><del>-  cmd: runES6 :fail
</del><ins>+  cmd: runES6 :normal
</ins><span class="cx"> - path: es6/Proxy_deleteProperty_handler.js
</span><span class="cx">   cmd: runES6 :normal
</span><span class="cx"> - path: es6/Proxy_enumerate_handler.js
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressproxydefineownpropertyjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/proxy-define-own-property.js (0 => 197533)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/proxy-define-own-property.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/proxy-define-own-property.js        2016-03-04 01:07:04 UTC (rev 197533)
</span><span class="lines">@@ -0,0 +1,614 @@
</span><ins>+function assert(b) {
+    if (!b)
+        throw new Error(&quot;Bad assertion.&quot;);
+}
+
+{
+    let target = {};
+    let handler = {
+        defineProperty: 25
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i &lt; 500; i++) {
+        let threw = false;
+        try {
+            Object.defineProperty(proxy, &quot;x&quot;, {
+                enumerable: true,
+                configurable: true,
+                value: 55
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === &quot;TypeError: 'defineProperty' property of a Proxy's handler should be callable.&quot;);
+        }
+
+        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 &lt; 500; i++) {
+        let threw = false;
+        try {
+            Object.defineProperty(proxy, &quot;x&quot;, {
+                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 &lt; 500; i++) {
+        let threw = false;
+        try {
+            Object.defineProperty(proxy, &quot;x&quot;, {
+                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 &lt; 500; i++) {
+        Object.defineProperty(proxy, &quot;x&quot;, {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            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 &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+        assert(result);
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            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 &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+        assert(result);
+        assert(called);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            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 &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            enumerable: true,
+            configurable: true,
+            value: i
+        });
+        assert(!result);
+        assert(called);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            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 &lt; 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, &quot;x&quot;, {
+                enumerable: true,
+                configurable: false,
+                value: i
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === &quot;TypeError: Proxy's 'defineProperty' trap returned true for a non-configurable field even though getOwnPropertyDescriptor of the Proxy's target returned undefined.&quot;);
+        }
+        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 &lt; 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, &quot;x&quot;, {
+                enumerable: true,
+                configurable: true,
+                value: i
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === &quot;TypeError: Proxy's 'defineProperty' trap returned true even though getOwnPropertyDescriptor of the Proxy's target returned undefined and the target is non-extensible.&quot;);
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === &quot;x&quot;);
+            assert(descriptor.configurable === false);
+            called = true;
+            return Reflect.defineProperty(theTarget, &quot;x&quot;, {
+                enumerable: true,
+                configurable: true,
+                value: descriptor.value
+            });
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i &lt; 500; i++) {
+        try {
+            Reflect.defineProperty(proxy, &quot;x&quot;, {
+                enumerable: true,
+                configurable: false,
+                value: i
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === &quot;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.&quot;);
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            assert(pDesc.value === i);
+            assert(pDesc.configurable === true);
+            assert(pDesc.enumerable === true);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    Object.defineProperty(target, &quot;x&quot;, {
+        configurable: false,
+        writable: true,
+        value: 55
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === &quot;x&quot;);
+            assert(descriptor.configurable === true);
+            called = true;
+            Reflect.defineProperty(theTarget, &quot;x&quot;, {
+                enumerable: true,
+                configurable: true,
+                value: descriptor.value
+            });
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i &lt; 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, &quot;x&quot;, {
+                configurable: true,
+                writable: false,
+                value: 45
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === &quot;TypeError: Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor.&quot;);
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            assert(pDesc.value === 55);
+            assert(pDesc.configurable === false);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    Object.defineProperty(target, &quot;x&quot;, {
+        configurable: false,
+        writable: true,
+        value: 55
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === &quot;x&quot;);
+            assert(descriptor.configurable === true);
+            called = true;
+            Reflect.defineProperty(theTarget, &quot;x&quot;, descriptor);
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i &lt; 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, &quot;x&quot;, {
+                configurable: true,
+                set:function(){},
+                get:function(){}
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === &quot;TypeError: Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor.&quot;);
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            assert(pDesc.value === 55);
+            assert(pDesc.configurable === false);
+        }
+    }
+}
+
+{
+    let target = {};
+    let called = false;
+    let setter = function(){};
+    let getter = function(){};
+    Object.defineProperty(target, &quot;x&quot;, {
+        configurable: false,
+        get: getter,
+        set: setter
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === &quot;x&quot;);
+            assert(descriptor.configurable === true);
+            called = true;
+            Reflect.defineProperty(theTarget, &quot;x&quot;, descriptor);
+            return true;
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i &lt; 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, &quot;x&quot;, {
+                configurable: true,
+                value: 45
+            });
+        } catch(e) {
+            threw = true;
+            assert(e.toString() === &quot;TypeError: Proxy's 'defineProperty' trap did not define a property on its target that is compatible with the trap's input descriptor.&quot;);
+        }
+        assert(called);
+        assert(threw);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            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, &quot;x&quot;, {
+        configurable: false,
+        get: getter,
+        set: setter
+    });
+    let handler = {
+        defineProperty: function(theTarget, propName, descriptor) {
+            assert(propName === &quot;x&quot;);
+            assert(descriptor.configurable === true);
+            called = true;
+            return Reflect.defineProperty(theTarget, &quot;x&quot;, descriptor);
+        }
+    };
+
+    let proxy = new Proxy(target, handler);
+    for (let i = 0; i &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            configurable: true,
+            value: 45
+        });
+        assert(!result);
+        assert(called);
+        called = false;
+
+        for (let obj of [target, proxy]) {
+            let pDesc = Object.getOwnPropertyDescriptor(obj, &quot;x&quot;);
+            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 &lt; 500; i++) {
+        let threw = false;
+        try {
+            Reflect.defineProperty(proxy, &quot;x&quot;, {
+                configurable: true,
+                value: 45
+            });
+        } catch(e) {
+            threw = true;
+            assert(e === error);
+        }
+        assert(threw);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, &quot;x&quot;, {
+        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 &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            configurable: false,
+            value: 55
+        });
+        assert(result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, &quot;x&quot;, {
+        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 &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            writable: false,
+            configurable: false,
+            value: 55
+        });
+        assert(result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, &quot;x&quot;, {
+        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 &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            writable: false,
+            configurable: false,
+            value: &quot;not 55&quot;
+        });
+        assert(!result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}
+
+{
+    let target = {};
+    Reflect.defineProperty(target, &quot;x&quot;, {
+        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 &lt; 500; i++) {
+        let result = Reflect.defineProperty(proxy, &quot;x&quot;, {
+            writable: true,
+            configurable: false,
+            value: &quot;whatever value goes here.&quot;
+        });
+        assert(!result);
+        assert(target.x === 55);
+        delete target.x;
+        assert(target.x === 55);
+    }
+}
</ins></span></pre>
</div>
</div>

</body>
</html>