Skip to content
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

Reflect #313

Closed
wants to merge 48 commits into from
Closed

Reflect #313

wants to merge 48 commits into from

Conversation

Victorystick
Copy link
Contributor

The Reflect global is, as far as I know, a part of the ES6 spec. I was a bit surprised not to find it in the es6-shim. Is there any reason as to why it isn't? If not, I'd consider giving it a go.

I'd like to use this PR to discuss Reflect implementation.

@ljharb
Copy link
Collaborator

ljharb commented Dec 29, 2014

The vast majority of the things on Reflect simply can't be shimmed, as I recall - it needs to support Proxies, Symbols, etc - all sorts of unshimmable things.

I'm happy to add it if:
a) everything we provide on it is 100% spec-compliant
b) No engine implements Proxy, Symbol, etc before implementing any applicable Reflect methods
c) Somebody testing for the presence of global Reflect won't run into trouble with only some of the methods defined.
d) It works cross-realm in the appropriate fashions (which iirc is just iframes atm)

Is there any JS engine that's implemented any part of Reflect yet?


// Reflect
if (!globals.Reflect) {
globals.Reflect = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflect itself should be set with defineProperty rather than an ! check, to ensure that enumerability is correct, and to allow for later overriding if a faulty implementation is detected.

In addition, all the properties on Reflect should be added with defineProperties, for the same reason.

@ljharb
Copy link
Collaborator

ljharb commented Dec 29, 2014

I stopped halfway through the tests because it seems like you wanted to discuss the PR before adding the rest of them - this is awesome, and I really appreciate the work you put in!

Let's make sure we've fleshed out consequences here in this thread first, but let's proceed with the goal of merging this ASAP in mind :-)

@ljharb ljharb self-assigned this Dec 29, 2014
@ljharb
Copy link
Collaborator

ljharb commented Dec 30, 2014

@zloirock thanks, good call!

@Victorystick
Copy link
Contributor Author

Looking at ES6 Compat table, it seems that Reflect has been implemented at least partially by the IE team in their Technical Preview and by EchoJS.

@ljharb
Copy link
Collaborator

ljharb commented Dec 31, 2014

Awesome, when I do my testing, I'll test with IE 11 as well.

@ljharb
Copy link
Collaborator

ljharb commented Jan 17, 2015

I think I'm primarily waiting for bindContext to be removed before a final rereview and merge.

return internal_get(target, key, receiver);
}),

getOwnPropertyDescriptor: throwUnlessTargetIsObject(Object.getOwnPropertyDescriptor),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The es6-shim needs to work in ES3 engines, which don't have property descriptors, a shimmable setPrototypeOf, Object.isExtensible, and a number of others.

Each Reflect method that can't work as-is in shimmed ES3 needs to be conditionally added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of Reflect is inside the if (supportsDescriptors) block along with Set and Map. Therefore I suppose that the descriptor support exists. Can't I be sure Object.getOwnPropertyDescriptor exists?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize. In that case, then the comment changes to be, any Reflect methods that don't require descriptors should be defined even when they're not supported :-) but that can be a followup, since that at least won't be broken anywhere. Thanks for clarifying!

@ljharb
Copy link
Collaborator

ljharb commented Jan 22, 2015

OK, we're down to the primary blocker being that any Reflect method that can't work in ES3 (ie, ones that use property descriptors, or setPrototypeOf, etc) need to be conditionally added.

Thanks a lot for being persistent on this, this is going to be great to have!

@zloirock
Copy link

Latest spec draft adds newTarget argument to Reflect.construct. It can't be fully polyfilled, but result should be created from newTarget.prototype.

@ljharb
Copy link
Collaborator

ljharb commented Jan 22, 2015

Anything that can't be fully polyfilled in any engine needs to go in the es6-sham, not the es6-shim. However, if it can be fully polyfilled in true ES5 engines (via Object.create) then that's great

@Victorystick
Copy link
Contributor Author

I set out with the intention of polyfilling Reflect in an ES5 environment, since it is so dependent on the Object property methods.

@ljharb
Copy link
Collaborator

ljharb commented Jan 22, 2015

OK - so this looks good to go, as long as it's freshly rebased on top of the latest master! ( ゚◡゚)/

Followup item is to pull as much Reflect functionality as possible into ES3 engines.

@Victorystick
Copy link
Contributor Author

This should be it. 👍

@ljharb
Copy link
Collaborator

ljharb commented Jan 27, 2015

@Victorystick It looks great and I'm ready to merge it, but I still see a merge commit (37e8818) - can you do a rebase onto latest master (as opposed to a merge with latest master)?

@ljharb
Copy link
Collaborator

ljharb commented Jan 29, 2015

I'm anxious to merge this, so unless you're already in progress I'll make a new branch and rebase it myself (your name will remain on all the commits).

ljharb added a commit to ljharb/es6-shim that referenced this pull request Jan 29, 2015
(From local rebased 'reflect' branch)
@ljharb
Copy link
Collaborator

ljharb commented Jan 29, 2015

Merged via dd6b1b2

@ljharb ljharb closed this Jan 29, 2015
@ljharb
Copy link
Collaborator

ljharb commented Jan 29, 2015

Thanks so much for contributing this, and working through all the back and forths with me!

@Victorystick
Copy link
Contributor Author

No worries. Thank you!

@Victorystick Victorystick deleted the reflect branch January 29, 2015 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants