Skip to content

Testing plan for JSON-parse-with-source #4096

Open
@ioannad

Description

Proposal README
Proposal rendered spec

For testing the tests, the proposal is shipped in v8.


  • Tests for new function JSON.isRawJSON:
    • Boilerplate:
      • Function length.
      • Function name.
      • Property descriptor.
      • Function is not a constructor.
    • Can be invoked as a function with success cases:
      • An instance created by a call to JSON.rawJSON.
      • Some objects without an [[IsRawJSON]] internal slot: {}, [].
      • Some non-Objects: null, undefinded, a Boolean, a symbol, a number.
  • Tests for new function JSON.rawJSON:
    • Boilerplate:
      • Function length.
      • Function name.
      • Function is not a constructor.
      • Property descriptor.
    • Can be invoked as a function
      • Success cases
        • Number, negative number, string, true, false, null
        • Returned object has the correct shape (null prototype, rawJSON own property)
        • Returned object is frozen
      • Failure cases, throwing:
        • SyntaxError in case of:
          • The empty string.
          • A string starting or ending with a tab, a linefeed, a carriage return, or a space.
          • A non-Array object literal: {}.
          • An Array literal: [1].
        • TypeError when trying to extend a rawJSON result object.
  • Tests for the new abstract operations in the algorithm of JSON.parse, each test should have a callable reviver argument:
    • For paths in CreateJSONParseRecord, only success cases (normal output), a test for each branch:
      • an Array literal
      • an Object literal
      • an Object literal with a repeated key
      • NullLiteral, BooleanLiteral, NumericLiteral, StringLiteral, ArrayLiteral, ObjectLiteral, UnaryExpression
      • a combination of all the above success cases nested
    • For paths in InternalizeJSONProperty, and the interaction with JSON.stringify, test with a reviver that modifies the holder object, as mentioned in tc39 issue 39:
      • [array and plain object] overwrite of not-yet-processed entry should result in absence of source for that entry
        • primitive to non-primitive
        • non-primitive to primitive
        • non-primitive to a clone (same date but different identity)
        • primitive to a different primitive
      • [array and plain object] overwrite and restoration of not-yet-processed entry should preserve source for that entry
        • primitive
        • non-primitive
      • [array] splicing out an item should result in absence of source from the affected index forward
        • ...but restoring items at their original index should preserve source
  • Test the overall intended functionality with examples from the proposal README and slides (linked in README).
    • Test that reviver function is applied to the source, not the parsed value, by roundtripping:
      • JSON.parse(" 9999999999999999", (key, val) => BigInt(val)) // → 9999999999999999n
      • other?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions