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.
5 // Flags: --harmony-unscopables
6 // Flags: --harmony-proxies
9 // TODO(arv): Once proxies can intercept symbols, add more tests.
12 function TestBasics() {
15 var proxy = Proxy.create({
16 getPropertyDescriptor: function(key) {
34 // One 'x' for HasBinding and one for GetBindingValue
35 assertEquals(['assertEquals', 'x', 'x'], log);
40 function TestInconsistent() {
44 var proxy = Proxy.create({
45 getPropertyDescriptor: function(key) {
47 if (key === 'x' && calls < 1) {
61 assertEquals(void 0, x);
64 // One 'x' for HasBinding and one for GetBindingValue
65 assertEquals(['assertEquals', 'x', 'x'], log);
70 function TestUseProxyAsUnscopables() {
76 var proxy = Proxy.create({
79 assertEquals('x', key);
82 getPropertyDescriptor: function(key) {
87 object[Symbol.unscopables] = proxy;
94 // HasBinding, HasBinding
95 assertEquals(2, calls);
97 TestUseProxyAsUnscopables();
100 function TestThrowInHasUnscopables() {
106 function CustomError() {}
109 var proxy = Proxy.create({
112 throw new CustomError();
116 getPropertyDescriptor: function(key) {
121 object[Symbol.unscopables] = proxy;
123 assertThrows(function() {
129 TestThrowInHasUnscopables();
133 function TestGlobalShouldIgnoreUnscopables() {
135 var proxy = Proxy.create({
136 getPropertyDescriptor: function() {
140 global[Symbol.unscopables] = proxy;
142 assertEquals(1, global.x);
146 assertEquals(2, global.x);
150 assertEquals(3, global.x);
153 TestGlobalShouldIgnoreUnscopables();