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

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

Issue 384963002: ES6 Unscopables (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use new GetHolder Created 6 years, 4 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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-unscopables
6 // Flags: --harmony-proxies
7
8
9 // TODO(arv): Once proxies can intercept symbols, add more tests.
10
11
12 (function TestBasics() {
13 var log = [];
14
15 var proxy = Proxy.create({
16 getPropertyDescriptor: function(key) {
17 log.push(key);
18 print(key);
19 if (key === 'x') {
20 return {
21 value: 1,
22 configurable: true
23 };
24 }
25 return undefined;
26 }
27 });
28
29 var x = 'local';
30
31 with (proxy) {
32 assertEquals(1, x);
33 }
34
35 // One 'x' for HasBinding and two for GetBindingValue
36 assertEquals(['assertEquals', 'x', 'x', 'x'], log);
37 })();
38
39
40 (function TestInconsistent() {
41 var log = [];
42 var calls = 0;
43
44 var proxy = Proxy.create({
45 getPropertyDescriptor: function(key) {
46 log.push(key);
47 if (key === 'x' && calls < 2) {
48 calls++;
49 return {
50 value: 1,
51 configurable: true
52 };
53 }
54 return undefined;
55 }
56 });
57
58 var x = 'local';
59
60 with (proxy) {
61 assertEquals(void 0, x);
62 }
63
64 // One 'x' for HasBinding and two for GetBindingValue
65 assertEquals(['assertEquals', 'x', 'x', 'x'], log);
66 })();
67
68
69 (function TestInconsistent2() {
70 var log = [];
71 var calls = 0;
72
73 var proxy = Proxy.create({
74 getPropertyDescriptor: function(key) {
75 log.push(key);
76 if (key === 'x' && calls < 1) {
77 calls++;
78 return {
79 value: 1,
80 configurable: true
81 };
82 }
83 return undefined;
84 }
85 });
86
87 var x = 'local';
88
89 with (proxy) {
90 assertEquals(void 0, x);
91 }
92
93 // One 'x' for HasBinding and one for GetBindingValue, the second one from
94 // previous test is not called since the proxy reported that there is no 'x'
95 // property when we did GetBindingValue.
96 assertEquals(['assertEquals', 'x', 'x'], log);
97 })();
98
99
100 (function TestUseProxyAsUnscopables() {
101 var x = 1;
102 var object = {
103 x: 2
104 };
105 var calls = 0;
106 var proxy = Proxy.create({
107 has: function(key) {
108 calls++;
109 assertEquals('x', key);
110 return calls === 3;
111 },
112 getPropertyDescriptor: function(key) {
113 assertUnreachable();
114 return undefined;
115 }
116 });
117
118 object[Symbol.unscopables] = proxy;
119
120 with (object) {
121 assertEquals(2, x);
122 assertEquals(1, x);
123 }
124
125 // HasBinding, GetBindingValue, HasBinding
126 assertEquals(3, calls);
127 })();
OLDNEW
« src/unscopables.h ('K') | « src/unscopables.h ('k') | test/mjsunit/harmony/unscopables.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698