Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/src/minimum_runtime_check.js
6165 views
1
/**
2
* @license
3
* Copyright 2024 The Emscripten Authors
4
* SPDX-License-Identifier: MIT
5
*/
6
7
#if ASSERTIONS
8
9
(function() {
10
// "30.0.0" -> 300000
11
function humanReadableVersionToPacked(str) {
12
str = str.split('-')[0]; // Remove any trailing part from e.g. "12.53.3-alpha"
13
var vers = str.split('.').slice(0, 3);
14
while(vers.length < 3) vers.push('00');
15
vers = vers.map((n, i, arr) => n.padStart(2, '0'));
16
return vers.join('');
17
}
18
// 300000 -> "30.0.0"
19
var packedVersionToHumanReadable = n => [n / 10000 | 0, (n / 100 | 0) % 100, n % 100].join('.');
20
21
var TARGET_NOT_SUPPORTED = {{{ TARGET_NOT_SUPPORTED }}};
22
23
// Note: We use a typeof check here instead of optional chaining using
24
// globalThis because older browsers might not have globalThis defined.
25
var currentNodeVersion = typeof process !== 'undefined' && process.versions?.node ? humanReadableVersionToPacked(process.versions.node) : TARGET_NOT_SUPPORTED;
26
#if MIN_NODE_VERSION == TARGET_NOT_SUPPORTED
27
if (currentNodeVersion < TARGET_NOT_SUPPORTED) {
28
throw 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?)');
29
}
30
#endif
31
if (currentNodeVersion < {{{ MIN_NODE_VERSION }}}) {
32
throw new Error(`This emscripten-generated code requires node v${ packedVersionToHumanReadable({{{ MIN_NODE_VERSION }}}) } (detected v${packedVersionToHumanReadable(currentNodeVersion)})`);
33
}
34
35
var userAgent = typeof navigator !== 'undefined' && navigator.userAgent;
36
if (!userAgent) {
37
return;
38
}
39
40
var currentSafariVersion = userAgent.includes("Safari/") && !userAgent.includes("Chrome/") && userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/) ? humanReadableVersionToPacked(userAgent.match(/Version\/(\d+\.?\d*\.?\d*)/)[1]) : TARGET_NOT_SUPPORTED;
41
#if MIN_SAFARI_VERSION == TARGET_NOT_SUPPORTED
42
if (currentSafariVersion < TARGET_NOT_SUPPORTED) {
43
throw new Error(`This page was compiled without support for Safari browser. Pass -sMIN_SAFARI_VERSION=${currentSafariVersion} or lower to enable support for this browser.`);
44
}
45
#endif
46
if (currentSafariVersion < {{{ MIN_SAFARI_VERSION }}}) {
47
throw new Error(`This emscripten-generated code requires Safari v${ packedVersionToHumanReadable({{{ MIN_SAFARI_VERSION }}}) } (detected v${currentSafariVersion})`);
48
}
49
50
var currentFirefoxVersion = userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/) ? parseFloat(userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED;
51
#if MIN_FIREFOX_VERSION == TARGET_NOT_SUPPORTED
52
if (currentFirefoxVersion < TARGET_NOT_SUPPORTED) {
53
throw new Error(`This page was compiled without support for Firefox browser. Pass -sMIN_FIREFOX_VERSION=${currentFirefoxVersion} or lower to enable support for this browser.`);
54
}
55
#endif
56
if (currentFirefoxVersion < {{{ MIN_FIREFOX_VERSION }}}) {
57
throw new Error(`This emscripten-generated code requires Firefox v{{{ MIN_FIREFOX_VERSION }}} (detected v${currentFirefoxVersion})`);
58
}
59
60
var currentChromeVersion = userAgent.match(/Chrome\/(\d+(?:\.\d+)?)/) ? parseFloat(userAgent.match(/Chrome\/(\d+(?:\.\d+)?)/)[1]) : TARGET_NOT_SUPPORTED;
61
#if MIN_CHROME_VERSION == TARGET_NOT_SUPPORTED
62
if (currentChromeVersion < TARGET_NOT_SUPPORTED) {
63
throw new Error(`This page was compiled without support for Chrome browser. Pass -sMIN_CHROME_VERSION=${currentChromeVersion} or lower to enable support for this browser.`);
64
}
65
#endif
66
if (currentChromeVersion < {{{ MIN_CHROME_VERSION }}}) {
67
throw new Error(`This emscripten-generated code requires Chrome v{{{ MIN_CHROME_VERSION }}} (detected v${currentChromeVersion})`);
68
}
69
})();
70
71
#endif
72
73