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

Adding globalThis #39

Closed
benjamingr opened this issue Jul 16, 2019 · 6 comments
Closed

Adding globalThis #39

benjamingr opened this issue Jul 16, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@benjamingr
Copy link

Hey,

I want to try contributing some code to Hermes because it looks like a fun project and a lot more manageable to push code to than V8 (or other big engines).

globalThis is a new canonical way to access the global variable.

Do you have plans to support this (standard) feature and if so - would you be interested in a PR for this?

(I totally get if the answer is "no" because of scoping and I didn't see any other exposed glboal - even though it's standard JS)

@ljharb
Copy link

ljharb commented Jul 16, 2019

globalThis is the only standard JS global :-) the others are part of node or browsers.

@avp
Copy link
Contributor

avp commented Jul 16, 2019

While globalThis isn't part of the standard yet (still in Stage 3 of the TC39 proposal process), it's already gained some amount of adoption and it seems reasonable to plan to add it to Hermes. We'll work on adding the property to the global object soon.

If you need access to the global object before globalThis is added to Hermes, you can use the Function constructor (which will be a little slower but should produce the correct output):

let global = (new Function('return this'))();

@ljharb
Copy link

ljharb commented Jul 16, 2019

@avp it's shipping in every browser https://twitter.com/mathias/status/1151140681374547969 so the stage isn't really relevant; it'll be stage 4 relatively soon. Glad to hear you're adding it :-)

@dulinriley dulinriley added the enhancement New feature or request label Jul 16, 2019
@dulinriley
Copy link
Contributor

It’s a shame that globalThis is a property that is writable, if it was a keyword we could compile it to GetGlobalObject in HBC.

@avp
Copy link
Contributor

avp commented Jul 17, 2019

d088f6f adds this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants