Skip to content

Commit c534869

Browse files
committed
Allow passing None to a JS function.
1 parent 40c3195 commit c534869

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

module.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static PyObject *object_call(ObjectData *self, PyObject *args, PyObject *kwds) {
9898
if (PyBool_Check(item)) {
9999
} else if (PyLong_Check(item)) {
100100
} else if (PyFloat_Check(item)) {
101+
} else if (item == Py_None) {
101102
} else if (PyUnicode_Check(item)) {
102103
} else if (PyObject_IsInstance(item, (PyObject *)&Object)) {
103104
} else {
@@ -119,6 +120,8 @@ static PyObject *object_call(ObjectData *self, PyObject *args, PyObject *kwds) {
119120
jsargs[i] = JS_MKVAL(JS_TAG_INT, PyLong_AsLong(item));
120121
} else if (PyFloat_Check(item)) {
121122
jsargs[i] = JS_NewFloat64(self->context->context, PyFloat_AsDouble(item));
123+
} else if (item == Py_None) {
124+
jsargs[i] = JS_NULL;
122125
} else if (PyUnicode_Check(item)) {
123126
jsargs[i] = JS_NewString(self->context->context, PyUnicode_AsUTF8(item));
124127
} else if (PyObject_IsInstance(item, (PyObject *)&Object)) {

quickjs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __call__(self, *args):
2626

2727
def _call(self, *args):
2828
def convert_arg(arg):
29-
if isinstance(arg, (str, bool, float, int)):
29+
if isinstance(arg, (type(None), str, bool, float, int)):
3030
return arg
3131
else:
3232
# More complex objects are passed through JSON.

test_quickjs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_identity(self):
175175
return x;
176176
}
177177
""")
178-
for x in [True, [1], {"a": 2}, 1, 1.5, "hej"]:
178+
for x in [True, [1], {"a": 2}, 1, 1.5, "hej", None]:
179179
self.assertEqual(identity(x), x)
180180

181181
def test_bool(self):

0 commit comments

Comments
 (0)