Title: [202755] trunk
Revision
202755
Author
[email protected]
Date
2016-07-01 13:55:55 -0700 (Fri, 01 Jul 2016)

Log Message

__defineGetter__/__defineSetter__ should throw exceptions
https://bugs.webkit.org/show_bug.cgi?id=142934

Patch by Benjamin Poulain <[email protected]> on 2016-07-01
Reviewed by Mark Lam.

Source/_javascript_Core:

* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncDefineGetter):
(JSC::objectProtoFuncDefineSetter):

LayoutTests:

* js/dom/dom-properties-are-configurable-expected.txt: Added.
* js/dom/dom-properties-are-configurable.html: Added.
* js/object-literal-duplicate-properties-expected.txt:
* js/property-getters-and-setters-expected.txt:
* js/script-tests/object-literal-duplicate-properties.js:
* js/script-tests/property-getters-and-setters.js:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (202754 => 202755)


--- trunk/LayoutTests/ChangeLog	2016-07-01 20:52:30 UTC (rev 202754)
+++ trunk/LayoutTests/ChangeLog	2016-07-01 20:55:55 UTC (rev 202755)
@@ -1,5 +1,19 @@
 2016-07-01  Benjamin Poulain  <[email protected]>
 
+        __defineGetter__/__defineSetter__ should throw exceptions
+        https://bugs.webkit.org/show_bug.cgi?id=142934
+
+        Reviewed by Mark Lam.
+
+        * js/dom/dom-properties-are-configurable-expected.txt: Added.
+        * js/dom/dom-properties-are-configurable.html: Added.
+        * js/object-literal-duplicate-properties-expected.txt:
+        * js/property-getters-and-setters-expected.txt:
+        * js/script-tests/object-literal-duplicate-properties.js:
+        * js/script-tests/property-getters-and-setters.js:
+
+2016-07-01  Benjamin Poulain  <[email protected]>
+
         [JSC] Date.toGMTString should be the Date.toUTCString function
         https://bugs.webkit.org/show_bug.cgi?id=159318
 

Added: trunk/LayoutTests/js/dom/dom-properties-are-configurable-expected.txt (0 => 202755)


--- trunk/LayoutTests/js/dom/dom-properties-are-configurable-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/dom/dom-properties-are-configurable-expected.txt	2016-07-01 20:55:55 UTC (rev 202755)
@@ -0,0 +1,16 @@
+Verify that certain DOM properties are configurable
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Object.getOwnPropertyDescriptor(HTMLElement.prototype, "innerText").configurable is true
+PASS Object.getOwnPropertyDescriptor(window, "onhashchange").configurable is true
+PASS HTMLElement.prototype.__defineGetter__("innerText", function() { return "NO!" }); is undefined
+PASS window.__defineGetter__("onhashchange", function() { return "WebKit!" }); is undefined
+PASS HTMLElement.prototype.innerText is "NO!"
+PASS document.documentElement.innerText is "NO!"
+PASS window.onhashchange is "WebKit!"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/dom/dom-properties-are-configurable.html (0 => 202755)


--- trunk/LayoutTests/js/dom/dom-properties-are-configurable.html	                        (rev 0)
+++ trunk/LayoutTests/js/dom/dom-properties-are-configurable.html	2016-07-01 20:55:55 UTC (rev 202755)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+</head>
+<script>
+    description("Verify that certain DOM properties are configurable");
+
+    // Some properties known to cause issues (see rdar://problem/20807563).
+    shouldBeTrue('Object.getOwnPropertyDescriptor(HTMLElement.prototype, "innerText").configurable');
+    shouldBeTrue('Object.getOwnPropertyDescriptor(window, "onhashchange").configurable');
+    shouldBe('HTMLElement.prototype.__defineGetter__("innerText", function() { return "NO!" });', 'undefined');
+    shouldBe('window.__defineGetter__("onhashchange", function() { return "WebKit!" });', 'undefined');
+    shouldBeEqualToString('HTMLElement.prototype.innerText', 'NO!');
+    shouldBeEqualToString('document.documentElement.innerText', 'NO!');
+    shouldBeEqualToString('window.onhashchange', 'WebKit!');
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/js/object-literal-duplicate-properties-expected.txt (202754 => 202755)


--- trunk/LayoutTests/js/object-literal-duplicate-properties-expected.txt	2016-07-01 20:52:30 UTC (rev 202754)
+++ trunk/LayoutTests/js/object-literal-duplicate-properties-expected.txt	2016-07-01 20:55:55 UTC (rev 202755)
@@ -56,9 +56,9 @@
 PASS o = {foo:1, foo:3}; Object.seal(o); Object.defineProperty(o, 'foo', {get(){return 5}}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change access mechanism for an unconfigurable property..
 PASS 'use strict';o = {foo:1, foo:3}; Object.seal(o); Object.defineProperty(o, 'foo', {get(){return 5}}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change access mechanism for an unconfigurable property..
 PASS (function(){o = {foo:1, foo:3}; Object.seal(o); Object.defineProperty(o, 'foo', {get(){return 5}}); descriptionString(o, 'foo');})() threw exception TypeError: Attempting to change access mechanism for an unconfigurable property..
-PASS o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); is 'value:3 keys:1 [EW][Sealed]'
-PASS 'use strict';o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); is 'value:3 keys:1 [EW][Sealed]'
-PASS (function(){o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo');})() did not throw exception.
+PASS o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS 'use strict';o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS (function(){o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo');})() threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
 
 Basic + Computed
 PASS o = {['foo']:1}; descriptionString(o, 'foo'); is 'value:1 keys:1 [ECW][Extensible]'
@@ -150,9 +150,9 @@
 PASS o = {foo:1, get foo(){return 3}}; Object.seal(o); Object.defineProperty(o, 'foo', {value:5}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change access mechanism for an unconfigurable property..
 PASS 'use strict';o = {foo:1, get foo(){return 3}}; Object.seal(o); Object.defineProperty(o, 'foo', {value:5}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change access mechanism for an unconfigurable property..
 PASS (function(){o = {foo:1, get foo(){return 3}}; Object.seal(o); Object.defineProperty(o, 'foo', {value:5}); descriptionString(o, 'foo');})() threw exception TypeError: Attempting to change access mechanism for an unconfigurable property..
-PASS o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); is 'getter:function value:(3) keys:1 [E][Sealed][Frozen]'
-PASS 'use strict';o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); is 'getter:function value:(3) keys:1 [E][Sealed][Frozen]'
-PASS (function(){o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo');})() did not throw exception.
+PASS o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS 'use strict';o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo'); threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS (function(){o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5}); descriptionString(o, 'foo');})() threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
 
 Computed + Accessor
 PASS o = {['foo']:1, get foo(){return 2}}; descriptionString(o, 'foo'); is 'getter:function value:(2) keys:1 [EC][Extensible]'

Modified: trunk/LayoutTests/js/property-getters-and-setters-expected.txt (202754 => 202755)


--- trunk/LayoutTests/js/property-getters-and-setters-expected.txt	2016-07-01 20:52:30 UTC (rev 202754)
+++ trunk/LayoutTests/js/property-getters-and-setters-expected.txt	2016-07-01 20:55:55 UTC (rev 202755)
@@ -43,6 +43,21 @@
 When undefined, accessing __lookupGetter__ and __lookupSetter__ should not crash
 PASS o13.__lookupGetter__('b') is void 0
 PASS o13.__lookupSetter__('b') is void 0
+__defineGetter__ and __defineSetter__ should throw exceptions when acting on sealed objects
+PASS o14.__defineGetter__('a', function(){}) threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS o14.__defineGetter__('b', function(){}) threw exception TypeError: Attempting to define property on object that is not extensible..
+PASS o14.__defineSetter__('a', function(){}) threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS o14.__defineSetter__('b', function(){}) threw exception TypeError: Attempting to define property on object that is not extensible..
+__defineGetter__ and __defineSetter__ should throw exceptions when acting on frozen objects
+PASS o15.__defineGetter__('a', function(){}) threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS o15.__defineGetter__('b', function(){}) threw exception TypeError: Attempting to define property on object that is not extensible..
+PASS o15.__defineSetter__('a', function(){}) threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS o15.__defineSetter__('b', function(){}) threw exception TypeError: Attempting to define property on object that is not extensible..
+__defineGetter__ and __defineSetter__ should throw exceptions when acting on unconfigurable properties
+PASS o16.__defineGetter__('a', function(){}) did not throw exception.
+PASS o16.__defineSetter__('a', function(){}) did not throw exception.
+PASS o16.__defineSetter__('b', function(){}) threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
+PASS o16.__defineSetter__('b', function(){}) threw exception TypeError: Attempting to change configurable attribute of unconfigurable property..
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/script-tests/object-literal-duplicate-properties.js (202754 => 202755)


--- trunk/LayoutTests/js/script-tests/object-literal-duplicate-properties.js	2016-07-01 20:52:30 UTC (rev 202754)
+++ trunk/LayoutTests/js/script-tests/object-literal-duplicate-properties.js	2016-07-01 20:55:55 UTC (rev 202755)
@@ -121,8 +121,7 @@
 runTest("o = {foo:1, foo:3}; Object.seal(o); o.foo = 5", "'value:5 keys:1 [EW][Sealed]'");
 runTest("o = {foo:1, foo:3}; Object.seal(o); Object.defineProperty(o, 'foo', {value:5})", "'value:5 keys:1 [EW][Sealed]'");
 runTest("o = {foo:1, foo:3}; Object.seal(o); Object.defineProperty(o, 'foo', {get(){return 5}})", null);
-// FIXME: <https://webkit.org/b/142934> __defineGetter__/__defineSetter__ should throw exceptions
-runTest("o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5})", "'value:3 keys:1 [EW][Sealed]'");
+runTest("o = {foo:1, foo:3}; Object.seal(o); o.__defineGetter__('foo', function(){return 5})");
 
 // Basic properties with Computed properties.
 debug(""); debug("Basic + Computed");
@@ -158,8 +157,7 @@
 runTest("o = {foo:1, get foo(){return 3}}; Object.seal(o);", "'getter:function value:(3) keys:1 [E][Sealed][Frozen]'");
 runTest("o = {foo:1, get foo(){return 3}}; Object.seal(o); Object.defineProperty(o, 'foo', {get(){return 5}})", null);
 runTest("o = {foo:1, get foo(){return 3}}; Object.seal(o); Object.defineProperty(o, 'foo', {value:5})", null);
-// FIXME: <https://webkit.org/b/142934> __defineGetter__/__defineSetter__ should throw exceptions
-runTest("o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5})", "'getter:function value:(3) keys:1 [E][Sealed][Frozen]'");
+runTest("o = {foo:1, get foo(){return 3}}; Object.seal(o); o.__defineGetter__('foo', function(){return 5})");
 
 // Computed properties with Accessor properties.
 debug(""); debug("Computed + Accessor");

Modified: trunk/LayoutTests/js/script-tests/property-getters-and-setters.js (202754 => 202755)


--- trunk/LayoutTests/js/script-tests/property-getters-and-setters.js	2016-07-01 20:52:30 UTC (rev 202754)
+++ trunk/LayoutTests/js/script-tests/property-getters-and-setters.js	2016-07-01 20:55:55 UTC (rev 202755)
@@ -99,3 +99,27 @@
 
 shouldBe("o13.__lookupGetter__('b')", "void 0");
 shouldBe("o13.__lookupSetter__('b')", "void 0");
+
+debug("__defineGetter__ and __defineSetter__ should throw exceptions when acting on sealed objects");
+var o14 = {a:14};
+Object.seal(o14);
+shouldThrow("o14.__defineGetter__('a', function(){})");
+shouldThrow("o14.__defineGetter__('b', function(){})");
+shouldThrow("o14.__defineSetter__('a', function(){})");
+shouldThrow("o14.__defineSetter__('b', function(){})");
+
+debug("__defineGetter__ and __defineSetter__ should throw exceptions when acting on frozen objects");
+var o15 = {a:15};
+Object.freeze(o15);
+shouldThrow("o15.__defineGetter__('a', function(){})");
+shouldThrow("o15.__defineGetter__('b', function(){})");
+shouldThrow("o15.__defineSetter__('a', function(){})");
+shouldThrow("o15.__defineSetter__('b', function(){})");
+
+debug("__defineGetter__ and __defineSetter__ should throw exceptions when acting on unconfigurable properties");
+var o16 = {a:16};
+Object.defineProperty(o16, "b", {value: 16, configurable: false});
+shouldNotThrow("o16.__defineGetter__('a', function(){})");
+shouldNotThrow("o16.__defineSetter__('a', function(){})");
+shouldThrow("o16.__defineSetter__('b', function(){})");
+shouldThrow("o16.__defineSetter__('b', function(){})");

Modified: trunk/Source/_javascript_Core/ChangeLog (202754 => 202755)


--- trunk/Source/_javascript_Core/ChangeLog	2016-07-01 20:52:30 UTC (rev 202754)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-07-01 20:55:55 UTC (rev 202755)
@@ -1,3 +1,14 @@
+2016-07-01  Benjamin Poulain  <[email protected]>
+
+        __defineGetter__/__defineSetter__ should throw exceptions
+        https://bugs.webkit.org/show_bug.cgi?id=142934
+
+        Reviewed by Mark Lam.
+
+        * runtime/ObjectPrototype.cpp:
+        (JSC::objectProtoFuncDefineGetter):
+        (JSC::objectProtoFuncDefineSetter):
+
 2016-07-01  Jon Davis  <[email protected]>
 
         Moved Web Animations and Resource Timing feature entries to WebCore.

Modified: trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp (202754 => 202755)


--- trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2016-07-01 20:52:30 UTC (rev 202754)
+++ trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp	2016-07-01 20:55:55 UTC (rev 202755)
@@ -145,7 +145,7 @@
     descriptor.setEnumerable(true);
     descriptor.setConfigurable(true);
 
-    bool shouldThrow = false;
+    bool shouldThrow = true;
     thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
 
     return JSValue::encode(jsUndefined());
@@ -171,7 +171,7 @@
     descriptor.setEnumerable(true);
     descriptor.setConfigurable(true);
 
-    bool shouldThrow = false;
+    bool shouldThrow = true;
     thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow);
 
     return JSValue::encode(jsUndefined());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to