reviver-mutates-holder-object-ccw.js (1286B)
1 /* 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/licenses/publicdomain/ 4 * Contributor: 5 * Jeff Walden <jwalden+code@mit.edu> 6 */ 7 8 //----------------------------------------------------------------------------- 9 var BUGNUMBER = 901351; 10 var summary = "Behavior when the JSON.parse reviver mutates the holder object"; 11 12 print(BUGNUMBER + ": " + summary); 13 14 /************** 15 * BEGIN TEST * 16 **************/ 17 18 // A little trickiness to account for the undefined-ness of property 19 // enumeration order. 20 var first = "unset"; 21 22 var proxyObj = null; 23 24 var obj = JSON.parse('{ "a": 0, "b": 1 }', function(prop, v) { 25 if (first === "unset") 26 { 27 first = prop; 28 var second = (prop === "a") ? "b" : "a"; 29 30 proxyObj = newGlobal().evaluate("({ c: 42, d: 17 })"); 31 Object.defineProperty(this, second, { value: proxyObj }); 32 } 33 return v; 34 }); 35 36 if (first === "a") 37 { 38 assertEq(obj.a, 0); 39 assertEq(obj.b, proxyObj); 40 assertEq(obj.b.c, 42); 41 assertEq(obj.b.d, 17); 42 } 43 else 44 { 45 assertEq(obj.a, proxyObj); 46 assertEq(obj.a.c, 42); 47 assertEq(obj.a.d, 17); 48 assertEq(obj.b, 1); 49 } 50 51 /******************************************************************************/ 52 53 if (typeof reportCompare === "function") 54 reportCompare(true, true); 55 56 print("Tests complete");