__defineGetter__/__defineSetter__ should throw exceptions
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Mar 2015 20:48:21 +0000 (20:48 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Mar 2015 20:48:21 +0000 (20:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142934

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncDefineGetter):
(JSC::objectProtoFuncDefineSetter):
Throw exceptions when these functions are used directly.

LayoutTests:

* js/property-getters-and-setters-expected.txt:
* js/script-tests/property-getters-and-setters.js:

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

LayoutTests/ChangeLog
LayoutTests/js/property-getters-and-setters-expected.txt
LayoutTests/js/script-tests/property-getters-and-setters.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ObjectPrototype.cpp

index 4530c53..ca25f3c 100644 (file)
@@ -1,3 +1,13 @@
+2015-03-23  Joseph Pecoraro  <pecoraro@apple.com>
+
+        __defineGetter__/__defineSetter__ should throw exceptions
+        https://bugs.webkit.org/show_bug.cgi?id=142934
+
+        Reviewed by Geoffrey Garen.
+
+        * js/property-getters-and-setters-expected.txt:
+        * js/script-tests/property-getters-and-setters.js:
+
 2015-03-23  Anders Carlsson  <andersca@apple.com>
 
         Make platform/mac-wk2/plugins/destroy-during-async-npp-new.html work again
index e92c9ae..531e489 100644 (file)
@@ -43,6 +43,21 @@ PASS o12.__lookupGetter__('b') is void 0
 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 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 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 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 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 configurable attribute of unconfigurable property..
+PASS o16.__defineSetter__('b', function(){}) threw exception TypeError: Attempting to configurable attribute of unconfigurable property..
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 990de2a..e5fc1a1 100644 (file)
@@ -99,3 +99,27 @@ var o13 = new Object()
 
 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(){})");
index e479fed..3bc4d3f 100644 (file)
@@ -1,5 +1,17 @@
 2015-03-23  Joseph Pecoraro  <pecoraro@apple.com>
 
+        __defineGetter__/__defineSetter__ should throw exceptions
+        https://bugs.webkit.org/show_bug.cgi?id=142934
+
+        Reviewed by Geoffrey Garen.
+
+        * runtime/ObjectPrototype.cpp:
+        (JSC::objectProtoFuncDefineGetter):
+        (JSC::objectProtoFuncDefineSetter):
+        Throw exceptions when these functions are used directly.
+
+2015-03-23  Joseph Pecoraro  <pecoraro@apple.com>
+
         Fix DO_PROPERTYMAP_CONSTENCY_CHECK enabled build
         https://bugs.webkit.org/show_bug.cgi?id=142952
 
index f092a97..00d56c6 100644 (file)
@@ -122,7 +122,9 @@ EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState* exec)
     descriptor.setGetter(get);
     descriptor.setEnumerable(true);
     descriptor.setConfigurable(true);
-    thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, exec->argument(0).toPropertyKey(exec), descriptor, false);
+
+    bool shouldThrow = true;
+    thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, exec->argument(0).toPropertyKey(exec), descriptor, shouldThrow);
 
     return JSValue::encode(jsUndefined());
 }
@@ -142,7 +144,9 @@ EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState* exec)
     descriptor.setSetter(set);
     descriptor.setEnumerable(true);
     descriptor.setConfigurable(true);
-    thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, exec->argument(0).toPropertyKey(exec), descriptor, false);
+
+    bool shouldThrow = true;
+    thisObject->methodTable(exec->vm())->defineOwnProperty(thisObject, exec, exec->argument(0).toPropertyKey(exec), descriptor, shouldThrow);
 
     return JSValue::encode(jsUndefined());
 }