Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support registering to globalThis #1316

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

Open
anuraaga opened this issue Jun 12, 2024 · 2 comments
Open

Support registering to globalThis #1316

anuraaga opened this issue Jun 12, 2024 · 2 comments
Labels
enhancement NeedsHelp Community contributions are welcome for this feature!

Comments

@anuraaga
Copy link

I am using a gopherjs binary with QuickJS, which uses globalThis for its global. I wonder if it's possible to support globalThis in the prelude to work out of the box with QuickJS.

throw new Error("no global object found");

if (typeof window !== "undefined") { /* web page */
    $global = window;
} else if (typeof self !== "undefined") { /* web worker */
    $global = self;
} else if (typeof global !== "undefined") { /* Node.js */
    $global = global;
    $global.require = require;
} else if (typeof globalThis !== "undefined") { /* QuickJS */
  $global = globalThis;
} else { /* others (e.g. Nashorn) */
    $global = this;
}

It's not difficult to shim though so not a big deal either way.

https://github.com/wasilibs/go-prettier/blob/main/buildtools/wasm/global.ts#L1
(globalThis as any).self = globalThis;

@nevkontakte
Copy link
Member

Yeah, that seems reasonable. If you don't mind sending a PR, I'll be happy to merge it :)

@nevkontakte nevkontakte added enhancement NeedsHelp Community contributions are welcome for this feature! labels Jun 12, 2024
@BrownNPC
Copy link

BrownNPC commented Oct 25, 2024

Any updates @anuraaga did you get the code working on quickjs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement NeedsHelp Community contributions are welcome for this feature!
Projects
None yet
Development

No branches or pull requests

3 participants