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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-proxies
6
7 var target = {};
8 var configurable_desc = {
9 value: 123,
10 configurable: true,
11 writable: true,
12 enumerable: false,
13 };
14 Object.defineProperty(target, "configurable", configurable_desc);
15 var nonconfigurable_desc = {
16 value: 234,
17 configurable: false,
18 writable: false,
19 enumerable: true
20 }
21 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.
22
23 var proxied_desc = {
24 value: 345,
25 configurable: true
26 };
27
28 var handler = {
29 "getOwnPropertyDescriptor": function(target, name) {
30 if (name === "proxied") {
31 return proxied_desc;
32 }
33 if (name === "return_null") {
34 return null;
35 }
36 return Object.getOwnPropertyDescriptor(target, name);
37 }
38 };
39
40 var proxy = new Proxy(target, handler);
41
42 // 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
43
44 assertEquals(configurable_desc,
45 Object.getOwnPropertyDescriptor(proxy, "configurable"));
46 assertEquals(nonconfigurable_desc,
47 Object.getOwnPropertyDescriptor(proxy, "nonconfigurable"));
48 assertEquals({ value: proxied_desc.value,
49 configurable: proxied_desc.configurable,
50 enumerable: false,
51 writable: false },
52 Object.getOwnPropertyDescriptor(proxy, "proxied"));
53
54 assertThrows('Object.getOwnPropertyDescriptor(proxy, "return_null")');
55
56 handler.getOwnPropertyDescriptor = undefined;
57 assertEquals(configurable_desc,
58 Object.getOwnPropertyDescriptor(proxy, "configurable"));
59
60 handler.getOwnPropertyDescriptor = function(target, name) {
61 return {value: 456, configurable: true, writable: true}
62 };
63 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
64
65 // Checking invariants mentioned explicitly by the ES spec:
66
67 // "A property cannot be reported as non-existent, if it exists as a
68 // non-configurable own property of the target object."
69 handler.getOwnPropertyDescriptor = function(target, name) { return undefined; };
70 assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")');
71 assertEquals(undefined, Object.getOwnPropertyDescriptor(proxy, "configurable"));
72
73 // "A property cannot be reported as non-configurable, if it does not exist
74 // as an own property of the target object or if it exists as a configurable
75 // own property of the target object."
76 handler.getOwnPropertyDescriptor = function(target, name) {
77 return {value: 234, configurable: false, enumerable: true};
78 };
79 assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonexistent")');
80 assertThrows('Object.getOwnPropertyDescriptor(proxy, "configurable")');
81 assertEquals(
82 false,
83 Object.getOwnPropertyDescriptor(proxy, "nonconfigurable").configurable);
84
85 // "A property cannot be reported as non-existent, if it exists as an own
86 // property of the target object and the target object is not extensible."
87 Object.seal(target);
88 handler.getOwnPropertyDescriptor = function(target, name) { return undefined; };
89 assertThrows('Object.getOwnPropertyDescriptor(proxy, "configurable")');
90 assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonconfigurable")');
91 assertEquals(undefined, Object.getOwnPropertyDescriptor(proxy, "nonexistent"));
92
93 // "A property cannot be reported as existent, if it does not exist as an
94 // own property of the target object and the target object is not extensible."
95 var existent_desc = {value: "yes"};
96 handler.getOwnPropertyDescriptor = function() { return existent_desc; };
97 assertThrows('Object.getOwnPropertyDescriptor(proxy, "nonexistent")');
98 assertEquals(
99 {value: "yes", writable: false, enumerable: false, configurable: false},
100 Object.getOwnPropertyDescriptor(proxy, "configurable"));
OLDNEW
« 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