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-proxies
8 // TODO(arv): Once proxies can intercept symbols, add more tests.
11 function TestBasics() {
14 var proxy = Proxy.create({
15 getPropertyDescriptor: function(key) {
33 // One 'x' for HasBinding and one for GetBindingValue
34 assertEquals(['assertEquals', 'x', 'x'], log);
39 function TestInconsistent() {
43 var proxy = Proxy.create({
44 getPropertyDescriptor: function(key) {
46 if (key === 'x' && calls < 1) {
60 assertEquals(void 0, x);
63 // One 'x' for HasBinding and one for GetBindingValue
64 assertEquals(['assertEquals', 'x', 'x'], log);
69 function TestUseProxyAsUnscopables() {
75 var proxy = Proxy.create({
78 assertEquals('x', key);
81 getPropertyDescriptor: function(key) {
86 object[Symbol.unscopables] = proxy;
93 // HasBinding, HasBinding
94 assertEquals(2, calls);
96 TestUseProxyAsUnscopables();
99 function TestThrowInHasUnscopables() {
105 function CustomError() {}
108 var proxy = Proxy.create({
111 throw new CustomError();
115 getPropertyDescriptor: function(key) {
120 object[Symbol.unscopables] = proxy;
122 assertThrows(function() {
128 TestThrowInHasUnscopables();
132 function TestGlobalShouldIgnoreUnscopables() {
134 var proxy = Proxy.create({
135 getPropertyDescriptor: function() {
139 global[Symbol.unscopables] = proxy;
141 assertEquals(1, global.x);
145 assertEquals(2, global.x);
149 assertEquals(3, global.x);
152 TestGlobalShouldIgnoreUnscopables();