<!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>[197295] 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/197295">197295</a></dd>
<dt>Author</dt> <dd>sbarati@apple.com</dd>
<dt>Date</dt> <dd>2016-02-28 10:40:35 -0800 (Sun, 28 Feb 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>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):</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="#trunkSourceJavaScriptCoreruntimePropertyDescriptorcpp">trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimePropertyDescriptorh">trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeProxyObjectcpp">trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoretestses6yaml">trunk/Source/JavaScriptCore/tests/es6.yaml</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstressproxygetownpropertyjs">trunk/Source/JavaScriptCore/tests/stress/proxy-get-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 (197294 => 197295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-02-28 18:40:35 UTC (rev 197295)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-02-28 Saam barati <sbarati@apple.com>
+
+ 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):
+
</ins><span class="cx"> 2016-02-27 Andy VanWagoner <thetalecrafter@gmail.com>
</span><span class="cx">
</span><span class="cx"> Intl.Collator uses POSIX locale (detected by js/intl-collator.html on iOS Simulator)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeObjectConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp (197294 => 197295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp        2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/JavaScriptCore/runtime/ObjectConstructor.cpp        2016-02-28 18:40:35 UTC (rev 197295)
</span><span class="lines">@@ -232,6 +232,8 @@
</span><span class="cx"> return jsUndefined();
</span><span class="cx">
</span><span class="cx"> JSObject* description = constructEmptyObject(exec);
</span><ins>+ if (exec->hadException())
+ return jsUndefined();
</ins><span class="cx"> if (!descriptor.isAccessorDescriptor()) {
</span><span class="cx"> description->putDirect(exec->vm(), exec->propertyNames().value, descriptor.value() ? descriptor.value() : jsUndefined(), 0);
</span><span class="cx"> description->putDirect(exec->vm(), exec->propertyNames().writable, jsBoolean(descriptor.writable()), 0);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimePropertyDescriptorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.cpp (197294 => 197295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.cpp        2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.cpp        2016-02-28 18:40:35 UTC (rev 197295)
</span><span class="lines">@@ -72,6 +72,21 @@
</span><span class="cx"> m_attributes = ReadOnly | DontDelete | DontEnum;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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;
+}
+
</ins><span class="cx"> JSValue PropertyDescriptor::getter() const
</span><span class="cx"> {
</span><span class="cx"> ASSERT(isAccessorDescriptor());
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimePropertyDescriptorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.h (197294 => 197295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.h        2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/JavaScriptCore/runtime/PropertyDescriptor.h        2016-02-28 18:40:35 UTC (rev 197295)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx"> JS_EXPORT_PRIVATE bool isAccessorDescriptor() const;
</span><span class="cx"> unsigned attributes() const { return m_attributes; }
</span><span class="cx"> JSValue value() const { return m_value; }
</span><ins>+ 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.
</ins><span class="cx"> JS_EXPORT_PRIVATE JSValue getter() const;
</span><span class="cx"> JS_EXPORT_PRIVATE JSValue setter() const;
</span><span class="cx"> JSObject* getterObject() const;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeProxyObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp (197294 => 197295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp        2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp        2016-02-28 18:40:35 UTC (rev 197295)
</span><span class="lines">@@ -138,7 +138,6 @@
</span><span class="cx"> bool ProxyObject::performInternalMethodGetOwnProperty(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
</span><span class="cx"> {
</span><span class="cx"> VM& vm = exec->vm();
</span><del>- slot.setValue(this, None, jsUndefined()); // We do this to protect against any bad actors. Nobody should depend on this value.
</del><span class="cx"> JSValue handlerValue = this->handler();
</span><span class="cx"> if (handlerValue.isNull()) {
</span><span class="cx"> throwVMTypeError(exec, ASCIILiteral("Proxy 'handler' is null. It should be an Object."));
</span><span class="lines">@@ -211,6 +210,16 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ 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.
+
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestses6yaml"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/es6.yaml (197294 => 197295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/es6.yaml        2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/JavaScriptCore/tests/es6.yaml        2016-02-28 18:40:35 UTC (rev 197295)
</span><span class="lines">@@ -925,7 +925,7 @@
</span><span class="cx"> - path: es6/Proxy_get_handler_instances_of_proxies.js
</span><span class="cx"> cmd: runES6 :normal
</span><span class="cx"> - path: es6/Proxy_getOwnPropertyDescriptor_handler.js
</span><del>- cmd: runES6 :fail
</del><ins>+ cmd: runES6 :normal
</ins><span class="cx"> - path: es6/Proxy_getPrototypeOf_handler.js
</span><span class="cx"> cmd: runES6 :fail
</span><span class="cx"> - path: es6/Proxy_has_handler.js
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressproxygetownpropertyjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/stress/proxy-get-own-property.js (197294 => 197295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/proxy-get-own-property.js        2016-02-28 14:57:46 UTC (rev 197294)
+++ trunk/Source/JavaScriptCore/tests/stress/proxy-get-own-property.js        2016-02-28 18:40:35 UTC (rev 197295)
</span><span class="lines">@@ -263,3 +263,189 @@
</span><span class="cx"> called = false;
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
+{
+ 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);
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>