ungap / raw-json

JSON.rawJSON and isRawJSON ponyfill
MIT License
24 stars 0 forks source link

Even in case of object, `reviver` should accept `context` argument #5

Closed zloirock closed 1 day ago

zloirock commented 2 days ago
Снимок экрана 2024-10-24 в 02 19 19

It can be easily fixed.

WebReflection commented 1 day ago

uhm ... I've thought the whole point of context was to exist only when a primitive is passed?

quoting MDN which I am not going to fix anymore or contribute to for the time being:

A context object that holds state relevant to the current expression being revived. It is a new object for each invocation of the reviver function. It is only passed when reviving primitive values, but not when value is an object or array. It contains the following property: source

are those pages broken? 'cause to me, and accordingly with the discussion around this proposal I've read, that is the expected behavior, it's impossible otherwise to disambiguate primitives from objects ... so who is right?

zloirock commented 1 day ago

https://tc39.es/proposal-json-parse-with-source/#sec-internalizejsonproperty steps 2 and 6.

WebReflection commented 1 day ago

I see ... so:

  1. the MDN page is wrong/misleading
  2. the context is always passed, it's the source property that is eventually added ... that's weird but I guess it reasons well in terms of fixed arity for the reviver

Thanks, this is indeed easy to fix.