Coder Social home page Coder Social logo

proposal-for-in-order's People

Contributors

bakkot avatar kriyszig avatar noahlt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proposal-for-in-order's Issues

Set proposal to Stage 2

This achieved Stage 2 in June 2019.

Also, should be nice to report a tracking issue for Stage 3 requesting the sign off from the reviewers. From the notes:

  • POK & NLT are reviewing together as Stripe
  • looking to ask WH and potentially other for the required additional reviewers

Stage 4 Tracking

This proposal achieved stage 3 at the October 2019 meeting. This is a tracking issue for getting stage 4 per the TC39 process.

  • committee consensus
  • open PR to the spec
  • all editors have approved the spec PR
  • test262 tests
    • written
    • merged
  • two compliant implementations
    • SpiderMonkey
    • v8
    • ChakraCore
    • JSC
  • significant in-the-field experience

How does this affect Object.keys()?

By my reading of the spec for Object.keys(), plus this spec, this seems to make Object.keys() behave similarly to Reflect.ownKeys(), except for taking enumerability into account. In particular it delegates to [[OwnPropertyKeys]], and thus (for ordinary objects) follows the array-indices, chronological string properties, chronological symbol properties order.

This is a bit hard to make out because the spec in this repo contains a lot of machinery to deal with the prototype chain and mutations during iteration, but for Object.keys() where none of those things are a problem, I think it just ends up as [[OwnPropertyKeys]].

Assuming this is intended, I think it could be a bit more explicit:

  • Update the README to mention the impact on Object.keys().
  • Make sure test262 tests also test Object.keys().
  • Potentially consider simplifying the spec for Object.keys(), which after this proposal will go through a lot of indirections, but I think in the end you just want to delete the final re-ordering step of EnumerableOwnPropertyNames.

Repo ownership transfer

Since this proposal advanced to Stage 1 in September 2018, could you transfer ownership to TC39-transfer so we can get it into the TC39 org? (Additionally, you should add that it reached stage 1 in 09/2018 in the README somewhere! Here's the notes link)

for-in extension?

Since for-in is getting looked at I thought I'd ask what'd people's opinion be on having a version of for-in that only looks at own properties instead of traversing the entire prototype chain.

Someone has already attempted to talk about this with @littledan, but as you can see the discussion ended quickly.

I have also tested object property iteration performance in V8 and as can be seen for-in outperforms the alternative by a huge margin in cases where the prototype chain lacks any enumerable properties.

Historically, people had to resort to a more imperative style of iterating over object keys like so:

const _has = Object.prototype.hasOwnProperty;

for (const key in obj) {
  if (_has.call(obj, key)) continue;
  // ...
}

// or

for (const key in obj) {
  if (Object.prototype.hasOwnProperty.call(obj, key)) continue;
  // ...
}

Of course this misses the "fast path" in V8 and most likely other engines if there is a single enumerable property in the prototype chain, but Object.{keys,values,entries} can also not be made faster than they already are due to having to manifest an array of the keys instead of lazily enumerating them like for-in.

Writing the above example this way:

for own (const ownKey in obj) {
  // ...
}

Having an alternative syntax that is more declarative and enables better optimizations would be delightful.

Covering the write-to-property common case

Current proposed spec text says

the iterator must behave [...] until either O or an object in its prototype chain has its [[SetPrototypeOf]], [[DefineOwnProperty]], or [[Delete]] internal method invoked

Unfortunately, [[DefineOwnProperty]] is invoked even if you're just doing an ordinary write to an existing enumerable data property. I'd like to put that in the deterministic case. One idea: say

its [[SetPrototypeOf]], [[Delete]], or [[DefineOwnProperty]] internal method invoked, except if [[DefineOwnProperty]] was invoked as step 3.d.iv of OrdinarySetWithOwnDescriptor

That could be expanded to include the case where an property is added to the object being iterated (but not a property added to its prototype) by saying

its [[SetPrototypeOf]], [[Delete]], or [[DefineOwnProperty]] internal method invoked, except if [[DefineOwnProperty]] was invoked in step 3.d.iv of OrdinarySetWithOwnDescriptor or if [[DefineOwnProperty]] was invoked with receiver O in step 3.e.ii of OrdinarySetWithOwnDescriptor

but that's getting really ugly.

Figure out how to allow setting properties without falling of spec'd path

Current spec text says

the iterator must behave as if it were the iterator given by CreateForInIterator ( O ) until either O or an object in its prototype chain has its [[SetPrototypeOf]], [[DefineOwnProperty]], or [[Delete]] internal method invoked

Unfortunately, the [[DefineOwnProperty]] method is triggered during OrdinarySet, both when updating an existing own property and when setting a new property. That means the spec text, as written, allows engines to do whatever they want as soon as sets or updates a property on the object or its prototype. And that means that one of the real constraints is not captured, namely, "properties which are added to the base object being iterated after iteration begins are not returned".

I (or someone) should figure out how to avoid this. Maybe it is possible to say something like "[[DefineOwnProperty]], except when called via OrdinarySet on O"?

Stage 3 Tracking

This proposal achieved stage 2 at the June 2019 meeting. This is a tracking issue for getting stage 3 per the process.

  • Complete spec text
  • Designated reviewers sign-off:
    • Pieter Ouwerkerk and Noah Tye from Stripe
    • someone else TBD
  • Editor sign-off
  • Basic test262 tests in a PR (may or may not be a requirement, but I want to do this before going for stage 3)
  • Committee consensus

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.