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

Side by Side Diff: test/mjsunit/harmony/proxies-get.js

Issue 1482283002: [runtime] [proxy] implementing [[Get]] trap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: position of static Created 5 years 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/objects.cc ('k') | test/mjsunit/harmony/proxies-get-prototype-of.js » ('j') | 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 (function testBasicFunctionality() {
8 var target = {
9 target_one: 1,
10 property: "value"
11 };
12
13 var handler = {handler:1};
14
15 var proxy = new Proxy(target, handler);
16 assertEquals("value", proxy.property);
17 assertEquals(undefined, proxy.nothing);
18 assertEquals(undefined, proxy.handler);
19
20 handler.get = function() { return "value 2" };
21 assertEquals("value 2", proxy.property);
22 assertEquals("value 2", proxy.nothing);
23 assertEquals("value 2", proxy.handler);
24
25 var handler2 = new Proxy({get: function() { return "value 3" }},{});
26 var proxy2 = new Proxy(target, handler2);
27 assertEquals("value 3", proxy2.property);
28 assertEquals("value 3", proxy2.nothing);
29 assertEquals("value 3", proxy2.handler);
30 })();
31
32 (function testThrowOnGettingTrap() {
33 var handler = new Proxy({}, {get: function(){ throw Error() }});
34 var proxy = new Proxy({}, handler);
35 assertThrows("proxy.property", Error);
36 })();
37
38 (function testFallback() {
39 var target = {property:"value"};
40 var proxy = new Proxy(target, {});
41 assertEquals("value", proxy.property);
42 assertEquals(undefined, proxy.property2);
43 })();
44
45 (function testFallbackUndefinedTrap() {
46 var handler = new Proxy({}, {get: function(){ return undefined }});
47 var target = {property:"value"};
48 var proxy = new Proxy(target, handler);
49 assertEquals("value", proxy.property);
50 assertEquals(undefined, proxy.property2);
51 })();
52
53 (function testFailingInvariant() {
54 var target = {};
55 var handler = { get: function(){ return "value" }}
56 var proxy = new Proxy(target, handler);
57 assertEquals("value", proxy.property);
58 assertEquals("value", proxy.key);
59 assertEquals("value", proxy.key2);
60 assertEquals("value", proxy.key3);
61
62 // Define a non-configurable, non-writeable property on the target for
63 // which the handler will return a different value.
64 Object.defineProperty(target, "key", {
65 configurable: false,
66 writable: false,
67 value: "different value"
68 });
69 assertEquals("value", proxy.property);
70 assertThrows(function(){ proxy.key }, TypeError);
71 assertEquals("value", proxy.key2);
72 assertEquals("value", proxy.key3);
73
74 // Define a non-configurable getter on the target for which the handler
75 // will return a value, according to the spec we do not throw.
76 Object.defineProperty(target, "key2", {
77 configurable: false,
78 get: function() { return "different value" }
79 });
80 assertEquals("value", proxy.property);
81 assertThrows(function(){ proxy.key }, TypeError);
82 assertEquals("value", proxy.key2);
83 assertEquals("value", proxy.key3);
84
85 // Define a non-configurable setter without a corresponding getter on the
86 // target for which the handler will return a value.
87 Object.defineProperty(target, "key3", {
88 configurable: false,
89 set: function() { }
90 });
91 assertEquals("value", proxy.property);
92 assertThrows(function(){ proxy.key }, TypeError);
93 assertEquals("value", proxy.key2);
94 assertThrows(function(){ proxy.key3 }, TypeError);
95 })();
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/harmony/proxies-get-prototype-of.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698