Path: blob/main/src/minimum_runtime_check.js
6165 views
/**1* @license2* Copyright 2024 The Emscripten Authors3* SPDX-License-Identifier: MIT4*/56#if ASSERTIONS78(function() {9// "30.0.0" -> 30000010function humanReadableVersionToPacked(str) {11str = str.split('-')[0]; // Remove any trailing part from e.g. "12.53.3-alpha"12var vers = str.split('.').slice(0, 3);13while(vers.length < 3) vers.push('00');14vers = vers.map((n, i, arr) => n.padStart(2, '0'));15return vers.join('');16}17// 300000 -> "30.0.0"18var packedVersionToHumanReadable = n => [n / 10000 | 0, (n / 100 | 0) % 100, n % 100].join('.');1920var TARGET_NOT_SUPPORTED = {{{ TARGET_NOT_SUPPORTED }}};2122// Note: We use a typeof check here instead of optional chaining using23// globalThis because older browsers might not have globalThis defined.24var currentNodeVersion = typeof process !== 'undefined' && process.versions?.node ? humanReadableVersionToPacked(process.versions.node) : TARGET_NOT_SUPPORTED;25#if MIN_NODE_VERSION == TARGET_NOT_SUPPORTED26if (currentNodeVersion < TARGET_NOT_SUPPORTED) {27throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');28}29#endif30if (currentNodeVersion < {{{ MIN_NODE_VERSION }}}) {31throw new Error(`This emscripten-generated code requires node v${ packedVersionToHumanReadable({{{ MIN_NODE_VERSION }}}) } (detected v${packedVersionToHumanReadable(currentNodeVersion)})`);32}3334var userAgent = typeof navigator !== 'undefined' && navigator.userAgent;35if (!userAgent) {36return;37}3839var currentSafariVersion = userAgent.includes("Safari/") && !userAgent.includes("Chrome/") && userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/) ? humanReadableVersionToPacked(userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/)[1]) : TARGET_NOT_SUPPORTED;40#if MIN_SAFARI_VERSION == TARGET_NOT_SUPPORTED41if (currentSafariVersion < TARGET_NOT_SUPPORTED) {42throw new Error(`This page was compiled without support for Safari browser. Pass -sMIN_SAFARI_VERSION=${currentSafariVersion} or lower to enable support for this browser.`);43}44#endif45if (currentSafariVersion < {{{ MIN_SAFARI_VERSION }}}) {46throw new Error(`This emscripten-generated code requires Safari v${ packedVersionToHumanReadable({{{ MIN_SAFARI_VERSION }}}) } (detected v${currentSafariVersion})`);47}4849var currentFirefoxVersion = userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/) ? parseFloat(userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED;50#if MIN_FIREFOX_VERSION == TARGET_NOT_SUPPORTED51if (currentFirefoxVersion < TARGET_NOT_SUPPORTED) {52throw new Error(`This page was compiled without support for Firefox browser. Pass -sMIN_FIREFOX_VERSION=${currentFirefoxVersion} or lower to enable support for this browser.`);53}54#endif55if (currentFirefoxVersion < {{{ MIN_FIREFOX_VERSION }}}) {56throw new Error(`This emscripten-generated code requires Firefox v{{{ MIN_FIREFOX_VERSION }}} (detected v${currentFirefoxVersion})`);57}5859var currentChromeVersion = userAgent.match(/Chrome\/(\d+(?:\.\d+)?)/) ? parseFloat(userAgent.match(/Chrome\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED;60#if MIN_CHROME_VERSION == TARGET_NOT_SUPPORTED61if (currentChromeVersion < TARGET_NOT_SUPPORTED) {62throw new Error(`This page was compiled without support for Chrome browser. Pass -sMIN_CHROME_VERSION=${currentChromeVersion} or lower to enable support for this browser.`);63}64#endif65if (currentChromeVersion < {{{ MIN_CHROME_VERSION }}}) {66throw new Error(`This emscripten-generated code requires Chrome v{{{ MIN_CHROME_VERSION }}} (detected v${currentChromeVersion})`);67}68})();6970#endif717273