Title: [203004] trunk
Revision
203004
Author
[email protected]
Date
2016-07-08 13:52:15 -0700 (Fri, 08 Jul 2016)

Log Message

Object.defineProperty() should maintain existing getter / setter if not overridden in the new descriptor
https://bugs.webkit.org/show_bug.cgi?id=159576
<rdar://problem/27242197>

Reviewed by Mark Lam.

Source/_javascript_Core:

Object.defineProperty() should maintain existing getter / setter if not
overridden in the new descriptor. Previously, if the property is a had
a custom getter / setter, and if the new descriptor only had a setter
(or only a getter), JSC would clear the existing getter (or setter).
This behavior did not match the EcmaScript specification or Firefox /
Chrome. This patch fixes the issue.

This fixes searching and search suggestions on www.iciba.com.

* runtime/JSObject.cpp:
(JSC::validateAndApplyPropertyDescriptor):

LayoutTests:

Add test coverage.

* js/dom/customAccessor-defineProperty-expected.txt: Added.
* js/dom/customAccessor-defineProperty.html: Added.
* js/dom/customAccessor-defineProperty_getterOnly-expected.txt: Added.
* js/dom/customAccessor-defineProperty_getterOnly.html: Added.
* js/dom/customAccessor-defineProperty_setterOnly-expected.txt: Added.
* js/dom/customAccessor-defineProperty_setterOnly.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (203003 => 203004)


--- trunk/LayoutTests/ChangeLog	2016-07-08 20:14:34 UTC (rev 203003)
+++ trunk/LayoutTests/ChangeLog	2016-07-08 20:52:15 UTC (rev 203004)
@@ -1,3 +1,20 @@
+2016-07-08  Chris Dumez  <[email protected]>
+
+        Object.defineProperty() should maintain existing getter / setter if not overridden in the new descriptor
+        https://bugs.webkit.org/show_bug.cgi?id=159576
+        <rdar://problem/27242197>
+
+        Reviewed by Mark Lam.
+
+        Add test coverage.
+
+        * js/dom/customAccessor-defineProperty-expected.txt: Added.
+        * js/dom/customAccessor-defineProperty.html: Added.
+        * js/dom/customAccessor-defineProperty_getterOnly-expected.txt: Added.
+        * js/dom/customAccessor-defineProperty_getterOnly.html: Added.
+        * js/dom/customAccessor-defineProperty_setterOnly-expected.txt: Added.
+        * js/dom/customAccessor-defineProperty_setterOnly.html: Added.
+
 2016-07-08  Andy Estes  <[email protected]>
 
         [Content Filtering] Load blocked pages more like other error pages are loaded

Added: trunk/LayoutTests/js/dom/customAccessor-defineProperty-expected.txt (0 => 203004)


--- trunk/LayoutTests/js/dom/customAccessor-defineProperty-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/dom/customAccessor-defineProperty-expected.txt	2016-07-08 20:52:15 UTC (rev 203004)
@@ -0,0 +1,22 @@
+Tests that using defineProperty() on a custom accessor
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+oldDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")
+PASS oldDescriptor.get is an instance of Function
+PASS oldDescriptor.set is an instance of Function
+PASS oldDescriptor.enumerable is true
+PASS oldDescriptor.configurable is true
+
+Object.defineProperty(HTMLInputElement.prototype, "value", { get: newGetter, set: newSetter, enumerable: false, configurable: false })
+
+newDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")
+PASS newDescriptor.get is newGetter
+PASS newDescriptor.set is newSetter
+PASS newDescriptor.enumerable is false
+PASS newDescriptor.configurable is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/dom/customAccessor-defineProperty.html (0 => 203004)


--- trunk/LayoutTests/js/dom/customAccessor-defineProperty.html	                        (rev 0)
+++ trunk/LayoutTests/js/dom/customAccessor-defineProperty.html	2016-07-08 20:52:15 UTC (rev 203004)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests that using defineProperty() on a custom accessor");
+
+evalAndLog('oldDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")');
+shouldBeType("oldDescriptor.get", "Function");
+shouldBeType("oldDescriptor.set", "Function");
+shouldBeTrue('oldDescriptor.enumerable');
+shouldBeTrue('oldDescriptor.configurable');
+
+function newGetter() { }
+function newSetter() { }
+debug('');
+evalAndLog('Object.defineProperty(HTMLInputElement.prototype, "value", { get: newGetter, set: newSetter, enumerable: false, configurable: false })');
+
+debug('');
+evalAndLog('newDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")');
+shouldBe("newDescriptor.get", "newGetter");
+shouldBe("newDescriptor.set", "newSetter");
+shouldBeFalse('newDescriptor.enumerable');
+shouldBeFalse('newDescriptor.configurable');
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/js/dom/customAccessor-defineProperty_getterOnly-expected.txt (0 => 203004)


--- trunk/LayoutTests/js/dom/customAccessor-defineProperty_getterOnly-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/dom/customAccessor-defineProperty_getterOnly-expected.txt	2016-07-08 20:52:15 UTC (rev 203004)
@@ -0,0 +1,23 @@
+Tests that using defineProperty() does not clear existing setter if the new descriptor only has a getter
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+oldDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")
+PASS oldDescriptor.get is an instance of Function
+PASS oldDescriptor.set is an instance of Function
+PASS oldDescriptor.enumerable is true
+PASS oldDescriptor.configurable is true
+
+Override only the getter
+Object.defineProperty(HTMLInputElement.prototype, "value", { get: newGetter })
+
+newDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")
+PASS newDescriptor.get is newGetter
+PASS newDescriptor.set is oldDescriptor.set
+PASS newDescriptor.enumerable is true
+PASS newDescriptor.configurable is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/dom/customAccessor-defineProperty_getterOnly.html (0 => 203004)


--- trunk/LayoutTests/js/dom/customAccessor-defineProperty_getterOnly.html	                        (rev 0)
+++ trunk/LayoutTests/js/dom/customAccessor-defineProperty_getterOnly.html	2016-07-08 20:52:15 UTC (rev 203004)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests that using defineProperty() does not clear existing setter if the new descriptor only has a getter");
+
+evalAndLog('oldDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")');
+shouldBeType("oldDescriptor.get", "Function");
+shouldBeType("oldDescriptor.set", "Function");
+shouldBeTrue('oldDescriptor.enumerable');
+shouldBeTrue('oldDescriptor.configurable');
+
+function newGetter() { }
+debug('');
+debug('Override only the getter');
+evalAndLog('Object.defineProperty(HTMLInputElement.prototype, "value", { get: newGetter })');
+
+debug('');
+evalAndLog('newDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")');
+shouldBe("newDescriptor.get", "newGetter");
+shouldBe("newDescriptor.set", "oldDescriptor.set");
+shouldBeTrue('newDescriptor.enumerable');
+shouldBeTrue('newDescriptor.configurable');
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/js/dom/customAccessor-defineProperty_setterOnly-expected.txt (0 => 203004)


--- trunk/LayoutTests/js/dom/customAccessor-defineProperty_setterOnly-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/dom/customAccessor-defineProperty_setterOnly-expected.txt	2016-07-08 20:52:15 UTC (rev 203004)
@@ -0,0 +1,23 @@
+Tests that using defineProperty() does not clear existing getter if the new descriptor only has a setter
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+oldDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")
+PASS oldDescriptor.get is an instance of Function
+PASS oldDescriptor.set is an instance of Function
+PASS oldDescriptor.enumerable is true
+PASS oldDescriptor.configurable is true
+
+Override only the setter
+Object.defineProperty(HTMLInputElement.prototype, "value", { set: newSetter })
+
+newDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")
+PASS newDescriptor.get is oldDescriptor.get
+PASS newDescriptor.set is newSetter
+PASS newDescriptor.enumerable is true
+PASS newDescriptor.configurable is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/dom/customAccessor-defineProperty_setterOnly.html (0 => 203004)


--- trunk/LayoutTests/js/dom/customAccessor-defineProperty_setterOnly.html	                        (rev 0)
+++ trunk/LayoutTests/js/dom/customAccessor-defineProperty_setterOnly.html	2016-07-08 20:52:15 UTC (rev 203004)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests that using defineProperty() does not clear existing getter if the new descriptor only has a setter");
+
+evalAndLog('oldDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")');
+shouldBeType("oldDescriptor.get", "Function");
+shouldBeType("oldDescriptor.set", "Function");
+shouldBeTrue('oldDescriptor.enumerable');
+shouldBeTrue('oldDescriptor.configurable');
+
+function newSetter() { }
+debug('');
+debug('Override only the setter');
+evalAndLog('Object.defineProperty(HTMLInputElement.prototype, "value", { set: newSetter })');
+
+debug('');
+evalAndLog('newDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")');
+shouldBe("newDescriptor.get", "oldDescriptor.get");
+shouldBe("newDescriptor.set", "newSetter");
+shouldBeTrue('newDescriptor.enumerable');
+shouldBeTrue('newDescriptor.configurable');
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/_javascript_Core/ChangeLog (203003 => 203004)


--- trunk/Source/_javascript_Core/ChangeLog	2016-07-08 20:14:34 UTC (rev 203003)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-07-08 20:52:15 UTC (rev 203004)
@@ -1,3 +1,23 @@
+2016-07-08  Chris Dumez  <[email protected]>
+
+        Object.defineProperty() should maintain existing getter / setter if not overridden in the new descriptor
+        https://bugs.webkit.org/show_bug.cgi?id=159576
+        <rdar://problem/27242197>
+
+        Reviewed by Mark Lam.
+
+        Object.defineProperty() should maintain existing getter / setter if not
+        overridden in the new descriptor. Previously, if the property is a had
+        a custom getter / setter, and if the new descriptor only had a setter
+        (or only a getter), JSC would clear the existing getter (or setter).
+        This behavior did not match the EcmaScript specification or Firefox /
+        Chrome. This patch fixes the issue.
+
+        This fixes searching and search suggestions on www.iciba.com.
+
+        * runtime/JSObject.cpp:
+        (JSC::validateAndApplyPropertyDescriptor):
+
 2016-07-08  Michael Saboff  <[email protected]>
 
         Dumping the object graph doesn't work with verbose GC logging

Modified: trunk/Source/_javascript_Core/runtime/JSObject.cpp (203003 => 203004)


--- trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-07-08 20:14:34 UTC (rev 203003)
+++ trunk/Source/_javascript_Core/runtime/JSObject.cpp	2016-07-08 20:52:15 UTC (rev 203004)
@@ -3056,9 +3056,14 @@
         return false;
     GetterSetter* getterSetter;
     bool getterSetterChanged = false;
-    if (accessor.isCustomGetterSetter())
+    if (accessor.isCustomGetterSetter()) {
         getterSetter = GetterSetter::create(exec->vm(), exec->lexicalGlobalObject());
-    else {
+        auto* customGetterSetter = jsCast<CustomGetterSetter*>(accessor);
+        if (customGetterSetter->setter())
+            getterSetter->setSetter(exec->vm(), exec->lexicalGlobalObject(), getCustomGetterSetterFunctionForGetterSetter(exec, propertyName, customGetterSetter, JSCustomGetterSetterFunction::Type::Setter));
+        if (customGetterSetter->getter())
+            getterSetter->setGetter(exec->vm(), exec->lexicalGlobalObject(), getCustomGetterSetterFunctionForGetterSetter(exec, propertyName, customGetterSetter, JSCustomGetterSetterFunction::Type::Getter));
+    } else {
         ASSERT(accessor.isGetterSetter());
         getterSetter = asGetterSetter(accessor);
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to