tc39 / proposal-json-parse-with-source

Proposal for extending JSON.parse to expose input source text.
https://tc39.github.io/proposal-json-parse-with-source
MIT License
213 stars 9 forks source link

Expose via new callback argument vs. new function #1

Closed gibson042 closed 4 years ago

gibson042 commented 5 years ago

This proposal currently suggests invoking JSON.parse reviver functions with additional arguments, but @erights noted that he cannot remember any spec change that added arguments to either built-in function or a callback invoked by a built-in function. The specification itself has nothing to say on this issue; a note recommending that implementations do not add custom parameters to built-in functions is the closest I could find:

Implementations that add additional capabilities to the set of built-in functions are encouraged to do so by adding new functions rather than adding new parameters to existing functions.

If the committee is uncomfortable with providing new arguments to JSON.parse reviver functions, then we would need a shift to something like JSON.parseWithSource(source, reviver) or JSON.parseWithSource(source, options).

mathiasbynens commented 5 years ago

There is precedent for this and similar changes elsewhere on the Web Platform, e.g. when addEventListener started supporting an options bag (instead of just a boolean) as the third argument. I think it’s perfectly fine to make such a change.

mathiasbynens commented 5 years ago

In fact, I’d be opposed to exposing a brand new static method just for this.

gibson042 commented 5 years ago

The committee seemed most comfortable with adding arguments to existing callback invocation.

gibson042 commented 4 years ago

No objections today either; I'm considering this resolved.