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
c1e75744
Commit
c1e75744
authored
May 30, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encapsulate the details of pyproxy
parent
544ed5a6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
12 deletions
+17
-12
src/js2python.c
src/js2python.c
+2
-3
src/pyodide.js
src/pyodide.js
+1
-1
src/pyproxy.c
src/pyproxy.c
+14
-8
No files found.
src/js2python.c
View file @
c1e75744
...
...
@@ -62,9 +62,8 @@ EM_JS(int, __jsToPython, (int id), {
return
__pythonTrue
();
}
else
if
(
value
===
false
)
{
return
__pythonFalse
();
// TODO: Add attribute for type of object and check it here
}
else
if
(
value
[
'$$'
]
!==
undefined
)
{
return
__jsPyProxyToPython
(
value
[
'$$'
]);
}
else
if
(
Module
.
PyProxy
.
isPyProxy
(
value
))
{
return
__jsPyProxyToPython
(
Module
.
PyProxy
.
getPtr
(
value
));
}
else
if
(
value
[
'
byteLength
'
]
!==
undefined
)
{
var
bytes
=
allocate
(
value
,
'
i8
'
,
ALLOC_NORMAL
);
var
result
=
__jsBytesToPython
(
bytes
,
value
[
'
byteLength
'
]);
...
...
src/pyodide.js
View file @
c1e75744
...
...
@@ -134,7 +134,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
window
.
iodide
.
addOutputHandler
({
shouldHandle
:
(
val
)
=>
{
return
(
typeof
val
===
'
function
'
&&
val
[
'
$$
'
]
!==
undefined
);
pyodide
.
PyProxy
.
isPyProxy
(
val
)
);
},
render
:
(
val
)
=>
{
...
...
src/pyproxy.c
View file @
c1e75744
...
...
@@ -104,15 +104,21 @@ int pyproxy_apply(int ptrobj, int idargs) {
EM_JS
(
int
,
pyproxy_new
,
(
int
ptrobj
),
{
var
target
=
function
()
{};
target
[
'$$'
]
=
ptrobj
;
target
[
'$$'
]
=
{
ptr
:
ptrobj
,
type
:
'
PyProxy
'
}
;
return
Module
.
hiwire_new_value
(
new
Proxy
(
target
,
Module
.
PyProxy
));
});
EM_JS
(
int
,
PyProxy_Ready
,
(),
{
Module
.
PyProxy
=
{
getPtr:
function
(
jsobj
)
{
return
jsobj
[
'$$'
][
'
ptr
'
];
},
isPyProxy:
function
(
jsobj
)
{
return
jsobj
[
'$$'
]
!==
undefined
&&
jsobj
[
'$$'
][
'
type
'
]
===
'
PyProxy
'
;
},
isExtensible:
function
()
{
return
true
},
has:
function
(
jsobj
,
jskey
)
{
ptrobj
=
jsobj
[
'$$'
]
;
ptrobj
=
this
.
getPtr
(
jsobj
)
;
var
idkey
=
Module
.
hiwire_new_value
(
jskey
);
var
result
=
_pyproxy_has
(
ptrobj
,
idkey
)
!=
0
;
Module
.
hiwire_decref
(
idkey
);
...
...
@@ -128,7 +134,7 @@ EM_JS(int, PyProxy_Ready, (), {
}
else
if
(
jskey
===
'$$'
)
{
return
jsobj
[
'$$'
];
}
ptrobj
=
jsobj
[
'$$'
]
;
ptrobj
=
this
.
getPtr
(
jsobj
)
;
var
idkey
=
Module
.
hiwire_new_value
(
jskey
);
var
idresult
=
_pyproxy_get
(
ptrobj
,
idkey
);
var
jsresult
=
Module
.
hiwire_get_value
(
idresult
);
...
...
@@ -137,7 +143,7 @@ EM_JS(int, PyProxy_Ready, (), {
return
jsresult
;
},
set:
function
(
jsobj
,
jskey
,
jsval
)
{
ptrobj
=
jsobj
[
'$$'
]
;
ptrobj
=
this
.
getPtr
(
jsobj
)
;
var
idkey
=
Module
.
hiwire_new_value
(
jskey
);
var
idval
=
Module
.
hiwire_new_value
(
jsval
);
var
idresult
=
_pyproxy_set
(
ptrobj
,
idkey
,
idval
);
...
...
@@ -148,7 +154,7 @@ EM_JS(int, PyProxy_Ready, (), {
return
jsresult
;
},
deleteProperty:
function
(
jsobj
,
jskey
)
{
ptrobj
=
jsobj
[
'$$'
]
;
ptrobj
=
this
.
getPtr
(
jsobj
)
;
var
idkey
=
Module
.
hiwire_new_value
(
jskey
);
var
idresult
=
_pyproxy_deleteProperty
(
ptrobj
,
idkey
);
var
jsresult
=
Module
.
hiwire_get_value
(
idresult
);
...
...
@@ -157,7 +163,7 @@ EM_JS(int, PyProxy_Ready, (), {
return
jsresult
;
},
ownKeys:
function
(
jsobj
)
{
ptrobj
=
jsobj
[
'$$'
]
;
ptrobj
=
this
.
getPtr
(
jsobj
)
;
var
idresult
=
_pyproxy_ownKeys
(
ptrobj
);
var
jsresult
=
Module
.
hiwire_get_value
(
idresult
);
Module
.
hiwire_decref
(
idresult
);
...
...
@@ -166,7 +172,7 @@ EM_JS(int, PyProxy_Ready, (), {
return
jsresult
;
},
enumerate:
function
(
jsobj
)
{
ptrobj
=
jsobj
[
'$$'
]
;
ptrobj
=
this
.
getPtr
(
jsobj
)
;
var
idresult
=
_pyproxy_enumerate
(
ptrobj
);
var
jsresult
=
Module
.
hiwire_get_value
(
idresult
);
Module
.
hiwire_decref
(
idresult
);
...
...
@@ -175,7 +181,7 @@ EM_JS(int, PyProxy_Ready, (), {
return
jsresult
;
},
apply:
function
(
jsobj
,
jsthis
,
jsargs
)
{
ptrobj
=
jsobj
[
'$$'
]
;
ptrobj
=
this
.
getPtr
(
jsobj
)
;
var
idargs
=
Module
.
hiwire_new_value
(
jsargs
);
var
idresult
=
_pyproxy_apply
(
ptrobj
,
idargs
);
var
jsresult
=
Module
.
hiwire_get_value
(
idresult
);
...
...
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