Opened 6 years ago

Last modified 2 years ago

#16537 assigned enhancement

json.parse and reviver vs. strict

Reported by: mm Owned by: dylan
Priority: undecided Milestone: 1.15
Component: Core Version: 1.8.2
Keywords: Cc:
Blocked By: Blocking:

Description

behavior of second parameter is inconsistent:

MDC: JSON.parse(text[, reviver]) dojo: parse: function(str, strict)

now it is not very clear from API docs, that second param is used as reviver.

  1. with native-parser and ommited it parses with "unknown strictness", depending on browser implementation.
  2. with native-parser set to true it is ignored (not a function)
  3. with non-native when true supplied parses in "strict"
  4. with non-native and function, parsing in strict and ingoring the reviver function

little bit less confusing is this documentation: dojo: http://dojotoolkit.org/reference-guide/1.8/dojo/json.html#dojo-json

it is more clear that strict is used only with non-native.

Suggestion 0: please update API docs to clearly explain this. maybe rename the parameter and name it reviverOrString and explain usage in both modes

Suggestion 1: extract regexp literal out of function for better performance. (see http://jsperf.com/regexp-test-search-vs-indexof/14)

Suggestion 2: please fix the test case with few more mustThrow, and test for NaN, Infinities and other Border values, in both native and non-native.

Change History (4)

comment:1 Changed 6 years ago by bill

Component: GeneralCore
Owner: set to Kris Zyp
Status: newassigned

comment:2 Changed 6 years ago by mm

please, no comments on this ? for months ?

comment:3 Changed 3 years ago by dylan

Milestone: tbd1.12
Owner: changed from Kris Zyp to dylan

comment:4 Changed 2 years ago by dylan

Milestone: 1.131.15

Ticket planning... move current 1.13 tickets out to 1.15 to make it easier to move tickets into the 1.13 milestone.

Note: See TracTickets for help on using tickets.