From 28e72d2780f0f8e3f32019c4f149e2f21dae9836 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:20:59 -0700 Subject: [PATCH] [release/8.0] [browser] ENVIRONMENT_IS_WEB is also true on WebWorker (#91627) * ENVIRONMENT_IS_WEB is now also true on WebWorker * noExitRuntime stay false on pthread --------- Co-authored-by: pavelsavara --- src/mono/wasm/runtime/globals.ts | 2 +- src/mono/wasm/runtime/loader/globals.ts | 2 +- src/mono/wasm/runtime/polyfills.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/runtime/globals.ts b/src/mono/wasm/runtime/globals.ts index b14bafd5ed2d7b..66948642bbc55c 100644 --- a/src/mono/wasm/runtime/globals.ts +++ b/src/mono/wasm/runtime/globals.ts @@ -15,8 +15,8 @@ export let Module: DotnetModuleInternal; export let INTERNAL: any; export const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string"; -export const ENVIRONMENT_IS_WEB = typeof window == "object"; export const ENVIRONMENT_IS_WORKER = typeof importScripts == "function"; +export const ENVIRONMENT_IS_WEB = typeof window == "object" || (ENVIRONMENT_IS_WORKER && !ENVIRONMENT_IS_NODE); export const ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; // these are imported and re-exported from emscripten internals export let ENVIRONMENT_IS_PTHREAD: boolean; diff --git a/src/mono/wasm/runtime/loader/globals.ts b/src/mono/wasm/runtime/loader/globals.ts index 55974cf4c51777..88b0d472de3ca8 100644 --- a/src/mono/wasm/runtime/loader/globals.ts +++ b/src/mono/wasm/runtime/loader/globals.ts @@ -16,8 +16,8 @@ import { hasDebuggingEnabled } from "./config"; import { logDownloadStatsToConsole, purgeUnusedCacheEntriesAsync } from "./assetsCache"; export const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string"; -export const ENVIRONMENT_IS_WEB = typeof window == "object"; export const ENVIRONMENT_IS_WORKER = typeof importScripts == "function"; +export const ENVIRONMENT_IS_WEB = typeof window == "object" || (ENVIRONMENT_IS_WORKER && !ENVIRONMENT_IS_NODE); export const ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; export let runtimeHelpers: RuntimeHelpers = {} as any; diff --git a/src/mono/wasm/runtime/polyfills.ts b/src/mono/wasm/runtime/polyfills.ts index fbf3a400f136c4..2ce605955db512 100644 --- a/src/mono/wasm/runtime/polyfills.ts +++ b/src/mono/wasm/runtime/polyfills.ts @@ -4,7 +4,7 @@ import MonoWasmThreads from "consts:monoWasmThreads"; import type { EmscriptenReplacements } from "./types/internal"; import type { TypedArray } from "./types/emscripten"; -import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_WEB, INTERNAL, Module, loaderHelpers, runtimeHelpers } from "./globals"; +import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_PTHREAD, ENVIRONMENT_IS_WEB, INTERNAL, Module, loaderHelpers, runtimeHelpers } from "./globals"; import { replaceEmscriptenPThreadLibrary } from "./pthreads/shared/emscripten-replacements"; const dummyPerformance = { @@ -30,7 +30,7 @@ export function initializeReplacements(replacements: EmscriptenReplacements): vo replacements.fetch = loaderHelpers.fetch_like; // misc - replacements.noExitRuntime = ENVIRONMENT_IS_WEB; + replacements.noExitRuntime = ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_PTHREAD; // threads if (MonoWasmThreads) {