tor-browser

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

value-boolean-object.js (1022B)


      1 // Copyright (C) 2012 Ecma International. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-serializejsonproperty
      5 description: >
      6  Boolean objects are converted to primitives using [[BooleanData]].
      7 info: |
      8  JSON.stringify ( value [ , replacer [ , space ] ] )
      9 
     10  [...]
     11  12. Return ? SerializeJSONProperty(the empty String, wrapper).
     12 
     13  SerializeJSONProperty ( key, holder )
     14 
     15  [...]
     16  4. If Type(value) is Object, then
     17    [...]
     18    c. Else if value has a [[BooleanData]] internal slot, then
     19      i. Set value to value.[[BooleanData]].
     20  [...]
     21  6. If value is true, return "true".
     22  7. If value is false, return "false".
     23 ---*/
     24 
     25 assert.sameValue(JSON.stringify(new Boolean(true)), 'true');
     26 
     27 assert.sameValue(
     28  JSON.stringify({
     29    toJSON: function() {
     30      return {key: new Boolean(false)};
     31    },
     32  }),
     33  '{"key":false}'
     34 );
     35 
     36 assert.sameValue(JSON.stringify([1], function(_k, v) {
     37  return v === 1 ? new Boolean(true) : v;
     38 }), '[true]');
     39 
     40 reportCompare(0, 0);