Hermes: Adding globalThis

Created on 16 Jul 2019  路  6Comments  路  Source: facebook/hermes

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)

enhancement

Most helpful comment

d088f6f5fdfd56e0dd946dc53533462fd3505102 adds this.

All 6 comments

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

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'))();

@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 :-)

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

d088f6f5fdfd56e0dd946dc53533462fd3505102 adds this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akrger picture akrger  路  6Comments

tsengvn picture tsengvn  路  4Comments

AMorgaut picture AMorgaut  路  6Comments

ghost picture ghost  路  5Comments

jacque006 picture jacque006  路  4Comments