parse-with-source-ccw.js (1431B)
1 // |reftest| skip-if(!JSON.hasOwnProperty('isRawJSON')||!xulRuntime.shell) 2 3 (function checkCrossCompartmentWrappers() { 4 var gbl = newGlobal({newCompartment: true}); 5 6 // the created context object should be wrapped in this compartment 7 gbl.eval("context = JSON.parse('4.0', (k,v,context) => context);"); 8 assertEq(isCCW(gbl.context), true); 9 // an object created in the reviver function should be wrapped in this compartment 10 gbl.eval("sourceV = JSON.parse('4.0', (k,v,context) => { return {}; });"); 11 assertEq(isCCW(gbl.sourceV), true); 12 13 // objects created by a reviver in this compartment should be wrapped in 14 // the other compartment 15 gbl.rev = (k,v,c) => { return {v}}; 16 gbl.eval("v2 = JSON.parse('4.0', rev);"); 17 assertEq(gbl.eval("isCCW(v2)"), true); 18 19 gbl.eval("objCCW = {};"); 20 assertEq(JSON.isRawJSON(gbl.objCCW), false, "isRawJSON() should accept CCW arguments"); 21 rawJSONCCW = gbl.eval("JSON.rawJSON(455);"); 22 assertEq(JSON.isRawJSON(rawJSONCCW), true, "isRawJSON() should return true for wrapped rawJSON objects"); 23 24 assertEq(rawJSONCCW.rawJSON, "455", "rawJSON object enumerable property should be visible through CCW"); 25 26 objWithCCW = { ccw: rawJSONCCW, raw: JSON.rawJSON(true) }; 27 assertEq(JSON.stringify(objWithCCW), '{"ccw":455,"raw":true}'); 28 assertEq(isCCW(rawJSONCCW), true); 29 })(); 30 31 if (typeof reportCompare == 'function') 32 reportCompare(0, 0);