Coder Social home page Coder Social logo

Reviver can modify holder object, like inserting new object / array, which breaks invariant of parsing information about proposal-json-parse-with-source HOT 6 CLOSED

Constellation avatar Constellation commented on June 19, 2024
Reviver can modify holder object, like inserting new object / array, which breaks invariant of parsing information

from proposal-json-parse-with-source.

Comments (6)

Constellation avatar Constellation commented on June 19, 2024

We observed invariant failures in JSC's prototype implementation, and we found that V8 crashes with the above example with --harmony-json-parse-with-source

from proposal-json-parse-with-source.

syg avatar syg commented on June 19, 2024

This looks like ultimately the same root cause as #35, which was also noticed during V8's implementation.

@gibson042 @mathiasbynens Needless to say this and #35 is a hard blocker for shipping.

from proposal-json-parse-with-source.

gibson042 avatar gibson042 commented on June 19, 2024

Nice find, @Constellation! This is a counterexample to our claim that bottom-up invocation renders moot the concern about divergence between live values and the source text from which they are derived, and will require a normative change to fix. I'll make a PR to take a shallow snapshot of arrays and other objects and suppress source in the context passed to the reviver for entries that have diverged and raise it for approval at the next TC39 plenary. We'll also want to cover this with test cases:

  • [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

from proposal-json-parse-with-source.

mhofman avatar mhofman commented on June 19, 2024

What about deletion and recreation of an already processed object property? Values would be the same but order wouldn't.

from proposal-json-parse-with-source.

mhofman avatar mhofman commented on June 19, 2024

Would it be web compatible to use the snapshot of objects and arrays for the entries passed to the reviver, and ignore mutations past snapshot time?

I mean which legitimate code mutates the object through the reviver?

from proposal-json-parse-with-source.

gibson042 avatar gibson042 commented on June 19, 2024

What about deletion and recreation of an already processed object property? Values would be the same but order wouldn't.

My plan is to preserve source in that case:

const reorderedSource = JSON.parse(
  '{ "foo": 0, "bar": 1, "baz": 2 }',
  function reviver(key, value, {source}) {
    if (key === "foo") {
      // Reposition the "bar" property.
      const barVal = this.bar;
      delete this.bar;
      this.bar = barVal;
    }
    return key ? source : value;
  },
);
assert.strictEqual(reorderedSource.bar, "1");

Would it be web compatible to use the snapshot of objects and arrays for the entries passed to the reviver, and ignore mutations past snapshot time?

I mean which legitimate code mutates the object through the reviver?

I don't think it would be (as evidenced in part by these two issues), and at any rate such a change is out of scope for this proposal.

from proposal-json-parse-with-source.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.