Skip to content

Commit 7dc2f52

Browse files
authored
gh-146197: Include a bit more information in sys._emscripten_info.runtime (#146346)
1 parent daa159f commit 7dc2f52

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

Python/sysmodule.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,20 +3878,38 @@ static PyStructSequence_Desc emscripten_info_desc = {
38783878

38793879
EM_JS(char *, _Py_emscripten_runtime, (void), {
38803880
var info;
3881-
if (typeof navigator == 'object') {
3881+
if (typeof process === "object") {
3882+
if (process.versions?.bun) {
3883+
info = `bun v${process.versions.bun}`;
3884+
} else if (process.versions?.deno) {
3885+
info = `deno v${process.versions.deno}`;
3886+
} else {
3887+
// As far as I can tell, every JavaScript runtime puts "node" in
3888+
// process.release.name. Pyodide once checked for
3889+
//
3890+
// process.release.name === "node"
3891+
//
3892+
// and this is apparently part of the reason other runtimes started
3893+
// lying about it. Similar to the situation with userAgent.
3894+
//
3895+
// But just in case some other JS runtime decides to tell us what it
3896+
// is, we'll pick it up.
3897+
const name = process.release?.name ?? "node";
3898+
info = `${name} ${process.version}`;
3899+
}
3900+
// Include v8 version if we know it
3901+
if (process.versions?.v8) {
3902+
info += ` (v8 ${process.versions.v8})`;
3903+
}
3904+
} else if (typeof navigator === "object") {
38823905
info = navigator.userAgent;
3883-
} else if (typeof process == 'object') {
3884-
info = "Node.js ".concat(process.version);
38853906
} else {
38863907
info = "UNKNOWN";
38873908
}
3888-
var len = lengthBytesUTF8(info) + 1;
3889-
var res = _malloc(len);
3890-
if (res) stringToUTF8(info, res, len);
38913909
#if __wasm64__
3892-
return BigInt(res);
3910+
return BigInt(stringToNewUTF8(info));
38933911
#else
3894-
return res;
3912+
return stringToNewUTF8(info);
38953913
#endif
38963914
});
38973915

0 commit comments

Comments
 (0)