FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Platforms/emscripten/node_entry.mjs at 3.15 · python/cpython · GitHub
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.4k
(2.4k)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Platforms
/
emscripten
/
node_entry.mjs
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (56 loc) · 1.82 KB
Breadcrumbs
cpython
/
Platforms
/
emscripten
/
node_entry.mjs
Copy path
File metadata and controls
62 lines (56 loc) · 1.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import
EmscriptenModule
from
"./python.mjs"
;
import
fs
from
"node:fs"
;
import
{
initializeStreams
}
from
"./streams.mjs"
;
if
(
process
?.
versions
?.
node
)
{
const
nodeVersion
=
Number
(
process
.
versions
.
node
.
split
(
"."
,
1
)
[
0
]
)
;
if
(
nodeVersion
<
18
)
{
process
.
stderr
.
write
(
`Node version must be >= 18, got version
${
process
.
version
}
\n`
,
)
;
process
.
exit
(
1
)
;
}
}
function
rootDirsToMount
(
Module
)
{
return
fs
.
readdirSync
(
"/"
)
.
filter
(
(
dir
)
=>
!
[
"dev"
,
"lib"
,
"proc"
]
.
includes
(
dir
)
)
.
map
(
(
dir
)
=>
"/"
+
dir
)
;
}
function
mountDirectories
(
Module
)
{
for
(
const
dir
of
rootDirsToMount
(
Module
)
)
{
Module
.
FS
.
mkdirTree
(
dir
)
;
Module
.
FS
.
mount
(
Module
.
FS
.
filesystems
.
NODEFS
,
{
root
:
dir
}
,
dir
)
;
}
}
const
thisProgram
=
"--this-program="
;
const
thisProgramIndex
=
process
.
argv
.
findIndex
(
(
x
)
=>
x
.
startsWith
(
thisProgram
)
,
)
;
const
settings
=
{
preRun
(
Module
)
{
// Globally expose API object so we can access it if we raise on startup.
globalThis
.
Module
=
Module
;
mountDirectories
(
Module
)
;
Module
.
FS
.
chdir
(
process
.
cwd
(
)
)
;
Object
.
assign
(
Module
.
ENV
,
process
.
env
)
;
delete
Module
.
ENV
.
PATH
;
}
,
onRuntimeInitialized
(
)
{
initializeStreams
(
Module
.
FS
)
;
}
,
// Ensure that sys.executable, sys._base_executable, etc point to python.sh
// not to this file. To properly handle symlinks, python.sh needs to compute
// its own path.
thisProgram
:
process
.
argv
[
thisProgramIndex
]
.
slice
(
thisProgram
.
length
)
,
// After python.sh come the arguments thatthe user passed to python.sh.
arguments
:
process
.
argv
.
slice
(
thisProgramIndex
+
1
)
,
}
;
try
{
await
EmscriptenModule
(
settings
)
;
}
catch
(
e
)
{
// Show JavaScript exception and traceback
console
.
warn
(
e
)
;
// Show Python exception and traceback
Module
.
PyUnstable_DumpTraceback
(
2
,
Module
.
_PyGILState_GetThisThreadState
(
)
)
;
process
.
exit
(
1
)
;
}
Back
|
FazBrowse Home
|
New Git URL