Fix `IN_NODE`: avoid error with unrelated global. (#1849)

This commit is contained in:
Ian Clester 2021-09-19 19:37:44 -04:00 committed by GitHub
parent f03db870a2
commit d7106294ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -19,6 +19,12 @@ substitutions:
error, it will return an empty list instead of raising a `SyntaxError`.
{pr}`1819`
### Javascript package
- {{Fix}} {any}`loadPyodide <globalThis.loadPyodide>` no longer fails in the
presence of a user-defined global named `process`.
{pr}`1849`
### Python / JavaScript type conversions
- {{Enhancement}} Updated the calling convention when a Javascript function is

View File

@ -1,7 +1,9 @@
import { Module } from "./module.js";
const IN_NODE =
typeof process !== "undefined" && process.release.name !== "undefined";
typeof process !== "undefined" &&
process.release &&
process.release.name === "node";
/** @typedef {import('./pyproxy.js').PyProxy} PyProxy */
/** @private */
@ -68,7 +70,7 @@ if (globalThis.document) {
// This is async only for consistency
globalThis.importScripts(url);
};
} else if (typeof process !== "undefined" && process.release.name === "node") {
} else if (IN_NODE) {
const pathPromise = import("path").then((M) => M.default);
const fetchPromise = import("node-fetch").then((M) => M.default);
const vmPromise = import("vm").then((M) => M.default);