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

Side by Side Diff: test/mjsunit/harmony/unscopables.js

Issue 384963002: ES6 Unscopables (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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
« src/objects-inl.h ('K') | « src/runtime.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 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
7
8 (function TestBasics() {
rossberg 2014/07/11 11:59:07 Some of these tests should probably be run on diff
arv (Not doing code reviews) 2014/07/11 21:47:28 Our proxies do not support symbol property names s
9 var x = 1;
10 var y = 2;
11 var z = 3;
12 var object = {
13 x: 4,
14 y: 5
15 };
16
17 with (object) {
18 assertEquals(x, 4);
19 assertEquals(y, 5);
20 assertEquals(z, 3);
21 }
22
23 object[Symbol.unscopables] = {x: true};
24 with (object) {
25 assertEquals(x, 1);
26 assertEquals(y, 5);
27 assertEquals(z, 3);
28 }
29
30 object[Symbol.unscopables] = {x: 0, y: true};
31 with (object) {
32 assertEquals(x, 1);
33 assertEquals(y, 2);
34 assertEquals(z, 3);
35 }
36 })();
37
38
39 (function TestOnProto() {
40 var x = 1;
41 var y = 2;
42 var z = 3;
43 var proto = {
44 x: 4
45 };
46 var object = {
47 __proto__: proto,
48 y: 5
49 };
50
51 with (object) {
52 assertEquals(x, 4);
53 assertEquals(y, 5);
54 assertEquals(z, 3);
55 }
56
57 proto[Symbol.unscopables] = {x: true};
58 with (object) {
59 assertEquals(x, 1);
60 assertEquals(y, 5);
61 assertEquals(z, 3);
62 }
63
64 object[Symbol.unscopables] = {y: true};
65 with (object) {
66 assertEquals(x, 1);
67 assertEquals(y, 2);
68 assertEquals(z, 3);
69 }
70
71 proto[Symbol.unscopables] = {y: true};
72 object[Symbol.unscopables] = {x: true};
73 with (object) {
74 assertEquals(x, 4);
75 assertEquals(y, 5);
76 assertEquals(z, 3);
77 }
78 })();
79
80
81 (function TestNonObject() {
82 var x = 1;
83 var y = 2;
84 var object = {
85 x: 3,
86 y: 4
87 };
88
89 object[Symbol.unscopables] = 'xy';
90 with (object) {
91 assertEquals(x, 3);
92 assertEquals(y, 4);
93 }
94
95 object[Symbol.unscopables] = null;
96 with (object) {
97 assertEquals(x, 3);
98 assertEquals(y, 4);
99 }
100 })();
101
102
103 (function TestChangeDuringWith() {
rossberg 2014/07/11 11:59:07 It would be good to have a variation of this test
arv (Not doing code reviews) 2014/07/11 21:47:28 Done.
104 var x = 1;
105 var y = 2;
106 var object = {
107 x: 3,
108 y: 4
109 };
110
111 with (object) {
112 assertEquals(3, x);
113 assertEquals(4, y);
114 object[Symbol.unscopables] = {x: true};
115 assertEquals(1, x);
116 assertEquals(4, y);
117 }
118 })();
119
120
121 var global = this;
122 (function TestGlobal() {
123 global.values = 'global.values';
124 Array.prototype.values = 'Array.prototype.values';
125 Array.prototype[Symbol.unscopables] = {values: true};
126 Array.prototype.__proto__ = {values: 42};
127 var array = [];
128 with (array) {
129 assertEquals(values, 42);
130 }
131 })();
132
133
134 (function TestAccessorReceiver() {
rossberg 2014/07/11 11:59:07 Hm, this test doesn't use unscopables at all...
arv (Not doing code reviews) 2014/07/11 21:47:29 Since --harmony-unscopables changes how with works
135 var x = 'local variable';
136
137 var proto = {
138 get x() {
139 assertEquals(this, object);
140 return this._x;
141 },
142 _x: 'proto'
143 };
144 var object = {
145 __proto__: proto,
146 _x: 'object'
147 };
148
149 with (object) {
150 assertEquals(x, 'object');
151 }
152 })();
153
154
155 (function TestUnscopablesGetter() {
156 var x = 'local variable';
157 var object = {
158 x: 'object'
159 };
160
161 var callCount = 0;
162 Object.defineProperty(object, Symbol.unscopables, {
163 get: function() {
164 callCount++;
165 return {};
166 },
167 configurable: true
168 });
169 with (object) {
170 assertEquals(x, 'object');
171 }
172 // Once for HasBinding and once for GetBindingValue
173 assertEquals(callCount, 2);
174
175 callCount = 0;
176 Object.defineProperty(object, Symbol.unscopables, {
rossberg 2014/07/11 11:59:07 It would definitely be good to have variants of th
arv (Not doing code reviews) 2014/07/11 21:47:28 Done.
177 get: function() {
178 callCount++;
179 return callCount === 1 ? {x: true} : {};
180 }
181 });
182 with (object) {
183 assertEquals(x, 'local variable');
184 }
185 // Once for HasBinding
186 assertEquals(callCount, 1);
187
188 callCount = 0;
189 Object.defineProperty(object, Symbol.unscopables, {
190 get: function() {
191 callCount++;
192 return callCount === 1 ? {} : {x: true};
193 }
194 });
195 with (object) {
196 assertEquals(x, undefined);
197 }
198 // Once for HasBinding, once for GetBindingValue.
199 assertEquals(callCount, 2);
200 })();
OLDNEW
« src/objects-inl.h ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698