Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
8d37d095
Commit
8d37d095
authored
Sep 19, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make work on Chrome
parent
836d981a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
5 deletions
+48
-5
src/pyodide.js
src/pyodide.js
+48
-5
No files found.
src/pyodide.js
View file @
8d37d095
...
...
@@ -32,6 +32,46 @@ var languagePluginLoader = new Promise((resolve, reject) => {
}
};
let
preloadWasm
=
()
=>
{
// On Chrome, we have to instantiate wasm asynchronously. Since that can't
// be done synchronously within the call to dlopen, we instantiate every .so
// that comes our way up front, caching it in the `preloadedWasm`
// dictionary.
let
promise
=
new
Promise
((
resolve
)
=>
resolve
());
let
FS
=
pyodide
.
_module
.
FS
;
function
recurseDir
(
rootpath
)
{
let
dirs
;
try
{
dirs
=
FS
.
readdir
(
rootpath
);
}
catch
{
return
;
}
for
(
entry
of
dirs
)
{
if
(
entry
.
startsWith
(
'
.
'
))
{
continue
;
}
const
path
=
rootpath
+
entry
;
if
(
entry
.
endsWith
(
'
.so
'
))
{
if
(
Module
[
'
preloadedWasm
'
][
path
]
===
undefined
)
{
promise
=
promise
.
then
(
()
=>
Module
[
'
loadWebAssemblyModule
'
](
FS
.
readFile
(
path
),
true
)
).
then
(
(
module
)
=>
{
Module
[
'
preloadedWasm
'
][
path
]
=
module
;
}
);
}
}
else
if
(
FS
.
isDir
(
FS
.
lookupPath
(
path
).
node
.
mode
))
{
recurseDir
(
path
+
'
/
'
);
}
}
}
recurseDir
(
'
/
'
);
return
promise
;
}
let
_loadPackage
=
(
names
)
=>
{
// DFS to find all dependencies of the requested packages
let
packages
=
window
.
pyodide
.
_module
.
packages
.
dependencies
;
...
...
@@ -91,7 +131,12 @@ var languagePluginLoader = new Promise((resolve, reject) => {
}
delete
window
.
pyodide
.
_module
.
monitorRunDependencies
;
const
packageList
=
Array
.
from
(
Object
.
keys
(
toLoad
)).
join
(
'
,
'
);
resolve
(
`Loaded
${
packageList
}
`
);
if
(
!
isFirefox
)
{
preloadWasm
().
then
(()
=>
{
resolve
(
`Loaded
${
packageList
}
`
)
});
}
else
{
resolve
(
`Loaded
${
packageList
}
`
);
}
}
};
...
...
@@ -182,11 +227,9 @@ var languagePluginLoader = new Promise((resolve, reject) => {
Module
.
noImageDecoding
=
true
;
Module
.
noAudioDecoding
=
true
;
Module
.
noWasmDecoding
=
true
;
Module
.
preloadedWasm
=
{};
let
isFirefox
=
navigator
.
userAgent
.
toLowerCase
().
indexOf
(
'
firefox
'
)
>
-
1
;
if
(
isFirefox
)
{
console
.
log
(
"
Skipping wasm decoding
"
);
Module
.
noWasmDecoding
=
true
;
}
let
wasm_promise
=
WebAssembly
.
compileStreaming
(
fetch
(
wasmURL
));
Module
.
instantiateWasm
=
(
info
,
receiveInstance
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment