New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parallel Object and Reflect methods? #1

Open
ljharb opened this Issue Jan 11, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@ljharb
Copy link

ljharb commented Jan 11, 2019

This is the first proxy trap added after Reflect exists, thus the only precedent here is “legacy”.

The current pattern is that Reflect has a method for every Proxy trap, but most of the Reflect methods have a corresponding Object method, that doesn’t take a target.

If a new Reflect method is added, would an Object method be added too? If not, what’s the precedent you’d wish to establish in the future for new Proxy traps?

@bakkot

This comment has been minimized.

Copy link
Owner

bakkot commented Jan 11, 2019

I think I'd prefer it in both places. The fact that freeze is on Object but not Reflect is my main motivation - it would be weird to me to see Reflect.freezePrototype(class); Object.freeze(instance).

But I don't have much intuition either way.

@ljharb

This comment has been minimized.

Copy link

ljharb commented Jan 11, 2019

Makes perfect sense to me, and is my preference :-)

@ljharb

This comment has been minimized.

Copy link

ljharb commented Jan 11, 2019

Although that brings up an interesting point; maybe they don’t belong on Reflect at all?

@bakkot

This comment has been minimized.

Copy link
Owner

bakkot commented Jan 11, 2019

I originally thought about just doing Object.freezePrototypeOf, but I think there really does need to be at least one new proxy trap (or at least a modification to an existing one) corresponding to "freeze prototype, but do not prevent extensions". (You can get by without a "is prototype frozen" trap because the setPrototypeOf trap is already permitted to return false.)

And any new proxy trap needs a corresponding method on Reflect, so that

let logAllTraps = Object.fromEntries(
  Reflect.ownKeys(Reflect).map(k => [
    k,
    (...args) => {
      console.log(k, args);
      return Reflect[k](...args);
    }
  ])
);
new Proxy({}, logAllTraps);

and similar tricks continue to work.

@ljharb

This comment has been minimized.

Copy link

ljharb commented Jan 11, 2019

So it seems like, with this design path, we’d have:

  • Object.freezePrototypeOf
  • Reflect.freezePrototypeOf
  • Object.isPrototypeOfFrozen
    ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment