OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 testStringify('{"x":123,"y":{"a":"a(proxy)","b":"b(proxy)","c":"c(proxy)"}}', | 122 testStringify('{"x":123,"y":{"a":"a(proxy)","b":"b(proxy)","c":"c(proxy)"}}', |
123 parent3); | 123 parent3); |
124 | 124 |
125 | 125 |
126 // Empty proxy. | 126 // Empty proxy. |
127 | 127 |
128 var handler4 = { | 128 var handler4 = { |
129 get: function(target, name) { | 129 get: function(target, name) { |
130 return 0; | 130 return 0; |
131 }, | 131 }, |
132 enumerate: function(target) { | |
133 return [][Symbol.iterator](); | |
134 }, | |
135 has: function() { | 132 has: function() { |
136 return true; | 133 return true; |
137 }, | 134 }, |
138 getOwnPropertyDescriptor: function(target, name) { | 135 getOwnPropertyDescriptor: function(target, name) { |
139 return { enumerable: false }; | 136 return { enumerable: false }; |
140 } | 137 } |
141 } | 138 } |
142 | 139 |
143 var proxy4 = new Proxy({}, handler4); | 140 var proxy4 = new Proxy({}, handler4); |
144 testStringify('{}', proxy4); | 141 testStringify('{}', proxy4); |
145 testStringify('{"a":{}}', { a: proxy4 }); | 142 testStringify('{"a":{}}', { a: proxy4 }); |
146 | 143 |
147 | 144 |
148 // Proxy that provides a toJSON function that uses this. | 145 // Proxy that provides a toJSON function that uses this. |
149 | 146 |
150 var handler5 = { | 147 var handler5 = { |
151 get: function(target, name) { | 148 get: function(target, name) { |
152 if (name == 'z') return 97000; | 149 if (name == 'z') return 97000; |
153 return function(key) { return key.charCodeAt(0) + this.z; }; | 150 return function(key) { return key.charCodeAt(0) + this.z; }; |
154 }, | 151 }, |
155 enumerate: function(target) { | 152 ownKeys: function(target) { |
156 return ['toJSON', 'z'][Symbol.iterator](); | 153 return ['toJSON', 'z']; |
157 }, | 154 }, |
158 has: function() { | 155 has: function() { |
159 return true; | 156 return true; |
160 }, | 157 }, |
161 getOwnPropertyDescriptor: function(target, name) { | 158 getOwnPropertyDescriptor: function(target, name) { |
162 return { enumerable: true }; | 159 return { enumerable: true }; |
163 } | 160 } |
164 } | 161 } |
165 | 162 |
166 var proxy5 = new Proxy({}, handler5); | 163 var proxy5 = new Proxy({}, handler5); |
167 testStringify('{"a":97097}', { a: proxy5 }); | 164 testStringify('{"a":97097}', { a: proxy5 }); |
168 | 165 |
169 | 166 |
170 // Proxy that provides a toJSON function that returns undefined. | 167 // Proxy that provides a toJSON function that returns undefined. |
171 | 168 |
172 var handler6 = { | 169 var handler6 = { |
173 get: function(target, name) { | 170 get: function(target, name) { |
174 return function(key) { return undefined; }; | 171 return function(key) { return undefined; }; |
175 }, | 172 }, |
176 enumerate: function(target) { | 173 ownKeys: function(target) { |
177 return ['toJSON'][Symbol.iterator](); | 174 return ['toJSON']; |
178 }, | 175 }, |
179 has: function() { | 176 has: function() { |
180 return true; | 177 return true; |
181 }, | 178 }, |
182 getOwnPropertyDescriptor: function(target, name) { | 179 getOwnPropertyDescriptor: function(target, name) { |
183 return { enumerable: true }; | 180 return { enumerable: true }; |
184 } | 181 } |
185 } | 182 } |
186 | 183 |
187 var proxy6 = new Proxy({}, handler6); | 184 var proxy6 = new Proxy({}, handler6); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 498 |
502 var result = JSON.parse('{"foo":0,"bar":1}', reviver); | 499 var result = JSON.parse('{"foo":0,"bar":1}', reviver); |
503 assertEquals({foo: 0, bar: proxy}, result); | 500 assertEquals({foo: 0, bar: proxy}, result); |
504 assertSame(result.bar, proxy); | 501 assertSame(result.bar, proxy); |
505 assertEquals(3, log.length); | 502 assertEquals(3, log.length); |
506 for (var i in log) assertSame(target, log[i][1]); | 503 for (var i in log) assertSame(target, log[i][1]); |
507 | 504 |
508 assertEquals(["get", target, "length", proxy], log[0]); | 505 assertEquals(["get", target, "length", proxy], log[0]); |
509 assertEquals(["get", target, "0", proxy], log[1]); | 506 assertEquals(["get", target, "0", proxy], log[1]); |
510 assertEquals(["deleteProperty", target, "0"], log[2]); | 507 assertEquals(["deleteProperty", target, "0"], log[2]); |
OLD | NEW |