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
758ef4af
Commit
758ef4af
authored
Feb 15, 2019
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix conversion from jsproxy to dict
parent
18bcd9e6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
6 deletions
+37
-6
src/hiwire.c
src/hiwire.c
+16
-4
src/jsproxy.c
src/jsproxy.c
+9
-0
test/test_python.py
test/test_python.py
+12
-2
No files found.
src/hiwire.c
View file @
758ef4af
...
...
@@ -189,7 +189,11 @@ EM_JS(int, hiwire_get_global, (int idname), {
EM_JS
(
int
,
hiwire_get_member_string
,
(
int
idobj
,
int
idkey
),
{
var
jsobj
=
Module
.
hiwire_get_value
(
idobj
);
var
jskey
=
UTF8ToString
(
idkey
);
if
(
jskey
in
jsobj
)
{
return
Module
.
hiwire_new_value
(
jsobj
[
jskey
]);
}
else
{
return
-
1
;
}
});
EM_JS
(
void
,
hiwire_set_member_string
,
(
int
idobj
,
int
ptrkey
,
int
idval
),
{
...
...
@@ -217,7 +221,11 @@ EM_JS(void, hiwire_set_member_int, (int idobj, int idx, int idval), {
EM_JS
(
int
,
hiwire_get_member_obj
,
(
int
idobj
,
int
ididx
),
{
var
jsobj
=
Module
.
hiwire_get_value
(
idobj
);
var
jsidx
=
Module
.
hiwire_get_value
(
ididx
);
if
(
jsidx
in
jsobj
)
{
return
Module
.
hiwire_new_value
(
jsobj
[
jsidx
]);
}
else
{
return
-
1
;
}
});
EM_JS
(
void
,
hiwire_set_member_obj
,
(
int
idobj
,
int
ididx
,
int
idval
),
{
...
...
@@ -309,7 +317,11 @@ EM_JS(int, hiwire_get_iterator, (int idobj), {
if
(
typeof
jsobj
.
next
===
'
function
'
)
{
return
Module
.
hiwire_new_value
(
jsobj
);
}
else
if
(
typeof
jsobj
[
Symbol
.
iterator
]
===
'
function
'
)
{
return
Module
.
hiwire_new_value
(
jsobj
[
Symbol
.
iterator
]())
return
Module
.
hiwire_new_value
(
jsobj
[
Symbol
.
iterator
]());
}
else
{
return
Module
.
hiwire_new_value
(
Object
.
entries
(
jsobj
)[
Symbol
.
iterator
]()
);
}
return
-
1
;
// clang-format on
...
...
src/jsproxy.c
View file @
758ef4af
...
...
@@ -62,6 +62,11 @@ JsProxy_GetAttr(PyObject* o, PyObject* attr_name)
int
idresult
=
hiwire_get_member_string
(
self
->
js
,
(
int
)
key
);
Py_DECREF
(
str
);
if
(
idresult
==
-
1
)
{
PyErr_SetString
(
PyExc_AttributeError
,
key
);
return
NULL
;
}
if
(
hiwire_is_function
(
idresult
))
{
hiwire_decref
(
idresult
);
return
JsBoundMethod_cnew
(
self
->
js
,
key
);
...
...
@@ -250,6 +255,10 @@ JsProxy_subscript(PyObject* o, PyObject* pyidx)
int
ididx
=
python2js
(
pyidx
);
int
idresult
=
hiwire_get_member_obj
(
self
->
js
,
ididx
);
hiwire_decref
(
ididx
);
if
(
idresult
==
-
1
)
{
PyErr_SetObject
(
PyExc_KeyError
,
pyidx
);
return
NULL
;
}
PyObject
*
pyresult
=
js2python
(
idresult
);
hiwire_decref
(
idresult
);
return
pyresult
;
...
...
test/test_python.py
View file @
758ef4af
...
...
@@ -368,7 +368,7 @@ def test_jsproxy(selenium):
"""
from js import TEST
del TEST.y
TEST.y"""
)
is
Non
e
hasattr(TEST, 'y')"""
)
is
Fals
e
selenium
.
run_js
(
"""
class Point {
...
...
@@ -382,7 +382,7 @@ def test_jsproxy(selenium):
"""
from js import TEST
del TEST['y']
TEST['y']"""
)
is
Non
e
'y' in TEST"""
)
is
Fals
e
assert
selenium
.
run
(
"""
from js import TEST
...
...
@@ -393,6 +393,16 @@ def test_jsproxy(selenium):
from js import TEST
TEST != 'foo'
"""
)
selenium
.
run_js
(
"""
window.TEST = {foo: 'bar', baz: 'bap'}
"""
)
assert
selenium
.
run
(
"""
from js import TEST
dict(TEST) == {'foo': 'bar', 'baz': 'bap'}
"""
)
is
True
def
test_jsproxy_iter
(
selenium
):
...
...
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