tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

eval-json-differences.js (1066B)


      1 load(libdir + "asserts.js");
      2 
      3 // eval({__proto__}) changes [[Prototype]]
      4 var obj = eval('({"__proto__": null})');
      5 assertEq(Object.getPrototypeOf(obj), null);
      6 assertEq(Object.prototype.hasOwnProperty.call(obj, "__proto__"), false);
      7 
      8 // JSON.parse({__proto__}) creates new property __proto__
      9 obj = JSON.parse('{"__proto__": null}');
     10 assertEq(Object.getPrototypeOf(obj), Object.prototype);
     11 assertEq(Object.prototype.hasOwnProperty.call(obj, "__proto__"), true);
     12 
     13 // If __proto__ appears more than once as quoted or unquoted property name in an
     14 // object initializer expression, that's an error.
     15 //(No other property name has this restriction.)"
     16 assertThrowsInstanceOf(() =>
     17    eval('({ "__proto__" : null, "__proto__" : null })'), SyntaxError);
     18 
     19 assertThrowsInstanceOf(() =>
     20    eval('  ({ "__proto__" : null, "__proto__" : null })'), SyntaxError);
     21 
     22 // JSON.parse doesn't care about duplication, the last definition counts.
     23 obj = JSON.parse('{"__proto__": null, "__proto__": 5}');
     24 assertEq(Object.getPrototypeOf(obj), Object.prototype);
     25 assertEq(obj["__proto__"], 5);