Testing plan for JSON.parse Options Bag
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- testing
Research direction
Start by reading nearby test262 tests for JSON.parse and how the suite represents option validation, frozen results, and prototypes. Add coverage for the listed success, failure, and reviver edge cases, then run the relevant tests with the repository's test262 runner; done when each listed case is covered and passes.
Written by the indexing model from the issue text.
Description
Failure cases
-
opts.freezeset to non-undefined, non-Boolean throws aTypeError -
opts.preferNullPrototypeset to non-undefined, non-Boolean throws aTypeError - if any getter throws, the error it throws is propagated
Success cases
-
JSON.parse("{}", undefined)result is not frozen, prototype is notnull -
JSON.parse("{}", {})result is not frozen, prototype is notnull -
JSON.parse("{}", { freeze: true })result is frozen, prototype isnull - ...same if setting
preferNullPrototypetoundefinedin addition -
JSON.parse("{}", { freeze: false })result is not frozen, prototype is notnull - ...same if setting
preferNullPrototypetoundefinedin addition -
JSON.parse("{}", { preferNullPrototype: true })result is not frozen, prototype isnull - ...same if setting
freezetoundefinedin addition -
JSON.parse("{}", { preferNullPrototype: false })result is not frozen, prototype is notnull - ...same if setting
freezetoundefinedin addition -
JSON.parse("{}", { freeze: true, preferNullPrototype: true })result is frozen, prototype isnull -
JSON.parse("{}", { freeze: true, preferNullPrototype: false })result is frozen, prototype is notnull -
JSON.parse("{}", { freeze: false, preferNullPrototype: true })result is not frozen, prototype isnull -
JSON.parse("{}", { freeze: false, preferNullPrototype: false })result is not frozen, prototype is notnull -
JSON.parse('{ "a": { "b": { "c": {} } }}', { freeze: true })returns a frozen object; all four objects are frozen and with null prototypes -
JSON.parse('{ "a": [1, 2, 3]}', { freeze: true }); the array does not have a null prototype but the object does; the array and object are both frozen -
JSON.parse("{}", { freeze: true }) !== JSON.parse("{}", { freeze: true })
Edge cases: A primitive is never an options bag
-
JSON.parse(..., null)is just like no second argument was passed -
JSON.parse(..., 0)is just like no second argument was passed, even after puttingfreezeandpreferNullPrototypegetters onNumber.prototype -
JSON.parse(...)andJSON.parse(..., undefined)behave as if no reviver was passed, even after puttingfreezeandpreferNullPrototypeonObject.prototype
Edge cases: Callable values are revivers
-
JSON.parse(..., Object)should treatObjectas a reviver, not an options bag -
JSON.parse(..., fn)for any ordinary functionfnwith an ownfreezegetter, callsfnand does not call the getter -
JSON.parse(..., class { static get freeze() {...} }throws aTypeErrorwithout accessingfreeze -
JSON.parse(..., new Proxy(() => {...}, ...))never hits the get trap for keysfreezeorpreferNullPrototype -
JSON.parse(..., p)wherepis a revoked Proxy around a function; it is still callable so treated as a reviver and thus throwsTypeError.
Edge cases: Non callable objects are treated as options bags
-
JSON.parse("{}", Object.assign([], { freeze: true })returns a frozen object -
JSON.parse("{}", [])returns a non-frozen object -
JSON.parse("{}", Object.create(Function.prototype))not callable so returns a non-frozen object without throwing
Edge cases: option access is Get, not an own-property check
-
JSON.parse("{}", Object.create({ freeze: true })returns a frozen object -
Object.prototype.freeze = true, JSON.parse("{}", {})returns a frozen object -
Object.prototype.preferNullPrototype = 1, JSON.parse("{}", {})throws aTypeError -
JSON.parse("{}", new Proxy({}, ...)):gettrap is called onfreeze, thenpreferNullPrototype;has,getOwnPropertyDescriptorandownKeystraps are not called; the receiver passed to eachgetcall is the proxy -
JSON.parse("{}", p)wherepis a revoked proxy around a plain object throws aTypeErroronGet
Edge cases: order of operations
-
toStringis called before any getters on options bag - if
toStringthrows, options are never read - if
toStringalters values for options, those alterations are respected - if
freezeis invalid or is a throwing getter,preferNullPrototypeis never accessed -
JSON.parse("{", { freeze: 1 } )throws aTypeError(not aSyntaxError) - Each getter runs exactly once
- if
freezegetter mutatespreferNullPrototypethe new value is respected - if
preferNullPrototypegetter mutatesfreeze, the new value is NOT respected - a
freezegetter callsJSON.parse("{}", { preferNullPrototype: true })and returns true; the inner result is not frozen but does have a null prototype; the outer result is frozen.
- Dominant language
- JavaScript
- Stars
- 2.9k
- Forks
- 571
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 13
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tc39/test262
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tc39/test262#5190 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
tc39/test262#5185 · 7 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tc39/test262#5133 · 1 comment ·
Maintainers usually reply within 1 day
-
Uint8Array.prototype.toHex tests do not test for paddingPossibly taken @bakkot claimed this 24 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
tc39/test262#5130 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
all-contributors/cli#690 ·
Maintainers usually reply within 1 day
-
area: ui Bug Payload OSS
Difficulty 1/5 Under an hour Newbie friendliness 88/100
payloadcms/payload#19839 ·
Maintainers usually reply within 1 day
-
Add: C+ ClassicsOpenapproved channels:add check:passed
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AllTheMods/ATM10-Aeronautics#167 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day