| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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(); |
| OLD | NEW |