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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 414 |
415 var getTrap = function(t, key) { | 415 var getTrap = function(t, key) { |
416 if (key === "length") return Symbol(); | 416 if (key === "length") return Symbol(); |
417 if (key === "2") return "baz"; | 417 if (key === "2") return "baz"; |
418 if (key === "3") return "bar"; | 418 if (key === "3") return "bar"; |
419 }; | 419 }; |
420 var target = []; | 420 var target = []; |
421 var proxy = new Proxy(target, {get: getTrap}); | 421 var proxy = new Proxy(target, {get: getTrap}); |
422 var replacer = (key, val) => key === "goo" ? proxy : val; | 422 var replacer = (key, val) => key === "goo" ? proxy : val; |
423 var object = {foo: true, goo: false}; | 423 var object = {foo: true, goo: false}; |
424 assertThrows(() => JSON.stringify(object, replacer)); | 424 assertThrows(() => JSON.stringify(object, replacer), TypeError); |
425 | 425 |
426 | 426 |
427 // Replacer returns a callable proxy | 427 // Replacer returns a callable proxy |
428 | 428 |
429 log.length = 0; | 429 log.length = 0; |
430 var target = () => 666; | 430 var target = () => 666; |
431 var proxy = new Proxy(target, handler); | 431 var proxy = new Proxy(target, handler); |
432 var replacer = (key, val) => key === "1" ? proxy : val; | 432 var replacer = (key, val) => key === "1" ? proxy : val; |
433 | 433 |
434 assertEquals('["foo",null]', JSON.stringify(["foo", 42], replacer)); | 434 assertEquals('["foo",null]', JSON.stringify(["foo", 42], replacer)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 501 |
502 var result = JSON.parse('{"foo":0,"bar":1}', reviver); | 502 var result = JSON.parse('{"foo":0,"bar":1}', reviver); |
503 assertEquals({foo: 0, bar: proxy}, result); | 503 assertEquals({foo: 0, bar: proxy}, result); |
504 assertSame(result.bar, proxy); | 504 assertSame(result.bar, proxy); |
505 assertEquals(3, log.length); | 505 assertEquals(3, log.length); |
506 for (var i in log) assertSame(target, log[i][1]); | 506 for (var i in log) assertSame(target, log[i][1]); |
507 | 507 |
508 assertEquals(["get", target, "length", proxy], log[0]); | 508 assertEquals(["get", target, "length", proxy], log[0]); |
509 assertEquals(["get", target, "0", proxy], log[1]); | 509 assertEquals(["get", target, "0", proxy], log[1]); |
510 assertEquals(["deleteProperty", target, "0"], log[2]); | 510 assertEquals(["deleteProperty", target, "0"], log[2]); |
OLD | NEW |