tor-browser

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

text-non-string-primitive.js (993B)


      1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-json.parse
      5 description: >
      6  Primitive values are coerced to strings and parsed.
      7 info: |
      8  JSON.parse ( text [ , reviver ] )
      9 
     10  1. Let JText be ? ToString(text).
     11  2. Parse JText interpreted as UTF-16 encoded Unicode points (6.1.4) as a JSON
     12  text as specified in ECMA-404. Throw a SyntaxError exception if JText is not
     13  a valid JSON text as defined in that specification.
     14 features: [Symbol]
     15 ---*/
     16 
     17 assert.throws(SyntaxError, function() {
     18  JSON.parse();
     19 });
     20 
     21 assert.throws(SyntaxError, function() {
     22  JSON.parse(undefined);
     23 });
     24 
     25 assert.sameValue(JSON.parse(null), null);
     26 assert.sameValue(JSON.parse(false), false);
     27 assert.sameValue(JSON.parse(true), true);
     28 assert.sameValue(JSON.parse(0), 0);
     29 assert.sameValue(JSON.parse(3.14), 3.14);
     30 
     31 var sym = Symbol('desc');
     32 assert.throws(TypeError, function() {
     33  JSON.parse(sym);
     34 });
     35 
     36 reportCompare(0, 0);