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

Skip to content

Support registering to globalThis #1316

Description

@anuraaga

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsHelpCommunity contributions are welcome for this feature!enhancement

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions