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

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

Issue 807893002: ES6: Update unscopables to match spec (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup Created 6 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 | « test/mjsunit/es6/unscopables.js ('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
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-proxies 5 // Flags: --harmony-proxies
6 6
7 7
8 // TODO(arv): Once proxies can intercept symbols, add more tests. 8 // TODO(arv): Once proxies can intercept symbols, add more tests.
9 9
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 68
69 function TestUseProxyAsUnscopables() { 69 function TestUseProxyAsUnscopables() {
70 var x = 1; 70 var x = 1;
71 var object = { 71 var object = {
72 x: 2 72 x: 2
73 }; 73 };
74 var calls = 0; 74 var calls = 0;
75 var proxy = Proxy.create({ 75 var proxy = Proxy.create({
76 has: function(key) { 76 has: function(key) {
77 assertUnreachable();
78 },
79 getPropertyDescriptor: function(key) {
77 calls++; 80 calls++;
78 assertEquals('x', key); 81 assertEquals('x', key);
79 return calls === 2; 82 return {
80 }, 83 value: calls === 2 ? true : undefined,
81 getPropertyDescriptor: function(key) { 84 configurable: true,
82 assertUnreachable(); 85 enumerable: true,
86 writable: true,
87 };
83 } 88 }
84 }); 89 });
85 90
86 object[Symbol.unscopables] = proxy; 91 object[Symbol.unscopables] = proxy;
87 92
88 with (object) { 93 with (object) {
89 assertEquals(2, x); 94 assertEquals(2, x);
90 assertEquals(1, x); 95 assertEquals(1, x);
91 } 96 }
92 97
93 // HasBinding, HasBinding 98 // HasBinding, HasBinding
94 assertEquals(2, calls); 99 assertEquals(2, calls);
95 } 100 }
96 TestUseProxyAsUnscopables(); 101 TestUseProxyAsUnscopables();
97 102
98 103
99 function TestThrowInHasUnscopables() { 104 function TestThrowInHasUnscopables() {
100 var x = 1; 105 var x = 1;
101 var object = { 106 var object = {
102 x: 2 107 x: 2
103 }; 108 };
104 109
105 function CustomError() {} 110 function CustomError() {}
106 111
107 var calls = 0; 112 var calls = 0;
108 var proxy = Proxy.create({ 113 var proxy = Proxy.create({
109 has: function(key) { 114 has: function(key) {
115 assertUnreachable();
116 },
117 getPropertyDescriptor: function(key) {
110 if (calls++ === 0) { 118 if (calls++ === 0) {
111 throw new CustomError(); 119 throw new CustomError();
112 } 120 }
113 assertUnreachable(); 121 assertUnreachable();
114 },
115 getPropertyDescriptor: function(key) {
116 assertUnreachable();
117 } 122 }
118 }); 123 });
119 124
120 object[Symbol.unscopables] = proxy; 125 object[Symbol.unscopables] = proxy;
121 126
122 assertThrows(function() { 127 assertThrows(function() {
123 with (object) { 128 with (object) {
124 x; 129 x;
125 } 130 }
126 }, CustomError); 131 }, CustomError);
(...skipping 16 matching lines...) Expand all
143 148
144 global.x = 2; 149 global.x = 2;
145 assertEquals(2, global.x); 150 assertEquals(2, global.x);
146 assertEquals(2, x); 151 assertEquals(2, x);
147 152
148 x = 3; 153 x = 3;
149 assertEquals(3, global.x); 154 assertEquals(3, global.x);
150 assertEquals(3, x); 155 assertEquals(3, x);
151 } 156 }
152 TestGlobalShouldIgnoreUnscopables(); 157 TestGlobalShouldIgnoreUnscopables();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/unscopables.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698