Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js

Issue 1451703003: [proxies] Wire up Object.getOwnPropertyDescriptor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js
diff --git a/test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js b/test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js
new file mode 100644
index 0000000000000000000000000000000000000000..d68afecc6bcb2e497bfacdbeddc6dc2287a3980d
--- /dev/null
+++ b/test/mjsunit/harmony/proxy/proxy-getOwnPropertyDescriptor.js
@@ -0,0 +1,100 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-proxies
+
+var target = {};
+var configurable_desc = {
+ value: 123,
+ configurable: true,
+ writable: true,
+ enumerable: false,
+};
+Object.defineProperty(target, "configurable", configurable_desc);
+var nonconfigurable_desc = {
+ value: 234,
+ configurable: false,
+ writable: false,
+ enumerable: true
+}
+Object.defineProperty(target, "nonconfigurable", nonconfigurable_desc);
Camillo Bruni 2015/11/16 16:15:40 I'd repeat this exact test with an empty proxy: ne
Jakob Kummerow 2015/11/17 12:42:51 This isn't a test... I guess you mean lines 44/46.
+
+var proxied_desc = {
+ value: 345,
+ configurable: true
+};
+
+var handler = {
+ "getOwnPropertyDescriptor": function(target, name) {
+ if (name === "proxied") {
+ return proxied_desc;
+ }
+ if (name === "return_null") {
+ return null;
+ }
+ return Object.getOwnPropertyDescriptor(target, name);
+ }
+};
+
+var proxy = new Proxy(target, handler);
+
+// Checking basic functionality:
Camillo Bruni 2015/11/16 16:15:40 Maybe this is too much work... I tried to order th
Jakob Kummerow 2015/11/17 12:42:51 Done, added a third section that specifically trig
+
+assertEquals(configurable_desc,
+ Object.getOwnPropertyDescriptor(proxy, "configurable"));
+assertEquals(nonconfigurable_desc,
+ Object.getOwnPropertyDescriptor(proxy, "nonconfigurable"));
+assertEquals({ value: proxied_desc.value,
+ configurable: proxied_desc.configurable,
+ enumerable: false,
+ writable: false },
+ Object.getOwnPropertyDescriptor(proxy, "proxied"));
+
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "return_null")');
+
+handler.getOwnPropertyDescriptor = undefined;
+assertEquals(configurable_desc,
+ Object.getOwnPropertyDescriptor(proxy, "configurable"));
+
+handler.getOwnPropertyDescriptor = function(target, name) {
+ return {value: 456, configurable: true, writable: true}
+};
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")');
Camillo Bruni 2015/11/16 16:15:40 please add a comment why this should throw, I end
Jakob Kummerow 2015/11/17 12:42:51 Done. (It throws because nonconfigurable propertie
+
+// Checking invariants mentioned explicitly by the ES spec:
+
+// "A property cannot be reported as non-existent, if it exists as a
+// non-configurable own property of the target object."
+handler.getOwnPropertyDescriptor = function(target, name) { return undefined; };
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")');
+assertEquals(undefined, Object.getOwnPropertyDescriptor(proxy, "configurable"));
+
+// "A property cannot be reported as non-configurable, if it does not exist
+// as an own property of the target object or if it exists as a configurable
+// own property of the target object."
+handler.getOwnPropertyDescriptor = function(target, name) {
+ return {value: 234, configurable: false, enumerable: true};
+};
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonexistent")');
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "configurable")');
+assertEquals(
+ false,
+ Object.getOwnPropertyDescriptor(proxy, "nonconfigurable").configurable);
+
+// "A property cannot be reported as non-existent, if it exists as an own
+// property of the target object and the target object is not extensible."
+Object.seal(target);
+handler.getOwnPropertyDescriptor = function(target, name) { return undefined; };
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "configurable")');
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")');
+assertEquals(undefined, Object.getOwnPropertyDescriptor(proxy, "nonexistent"));
+
+// "A property cannot be reported as existent, if it does not exist as an
+// own property of the target object and the target object is not extensible."
+var existent_desc = {value: "yes"};
+handler.getOwnPropertyDescriptor = function() { return existent_desc; };
+assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonexistent")');
+assertEquals(
+ {value: "yes", writable: false, enumerable: false, configurable: false},
+ Object.getOwnPropertyDescriptor(proxy, "configurable"));
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698