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

Support globalThis in getGlobal() for better compatibility #2819

Merged
merged 1 commit into from
Nov 22, 2021

Conversation

simonihmig
Copy link
Contributor

globalThis is the actual ECMAScript standard for the global object, so this should be returned by getGlobal() when available. The existing code (taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) is good as a replacement when globalThis is not available, but when it is, we should return it directly! See a similar example in Ember.js.

This fixes a real world issue I had when running xstate in a rather exotic environment (GraalVM running JS inside a Java server), which correctly supports globalThis, but does not support global (which is node.js specific!) or self.

@changeset-bot
Copy link

changeset-bot bot commented Nov 15, 2021

🦋 Changeset detected

Latest commit: 0d51d33

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ghost
Copy link

ghost commented Nov 15, 2021

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

Copy link
Member

@davidkpiano davidkpiano left a comment

Choose a reason for hiding this comment

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

This makes sense to me. @Andarist Any unforeseen issues?

@davidkpiano davidkpiano merged commit fdc9499 into statelyai:main Nov 22, 2021
This was referenced Nov 22, 2021
@Andarist
Copy link
Member

I wouldn't predict this setup 😅

GraalVM running JS inside a Java server

but the change looks OK - I'm glad it fixes a real issue 👍 didn't know that there envs that only support this as a "global" variable

@simonihmig simonihmig deleted the globalthis branch November 22, 2021 15:20
@simonihmig
Copy link
Contributor Author

didn't know that there envs that only support this as a "global" variable

AFAIK globalThis is the only global object that is defined in the ECMAScript spec itself. So from an engine's standpoint, this choice probably makes sense.

Anyways, thanks for the quick review and PR acceptance! 👍

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

Successfully merging this pull request may close these issues.

None yet

3 participants