Skip to content

Commit e7cd37d

Browse files
committed
Disallow mixing objects from different contexts.
1 parent cf165b8 commit e7cd37d

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

module.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ static PyObject *object_call(ObjectData *self, PyObject *args, PyObject *kwds) {
137137
} else if (item == Py_None) {
138138
} else if (PyUnicode_Check(item)) {
139139
} else if (PyObject_IsInstance(item, (PyObject *)&Object)) {
140+
ObjectData *object = (ObjectData *)item;
141+
if (object->context != self->context) {
142+
PyErr_Format(PyExc_ValueError, "Can not mix JS objects from different contexts.");
143+
return NULL;
144+
}
140145
} else {
141146
PyErr_Format(PyExc_ValueError,
142147
"Unsupported type of argument %d when calling quickjs object: %s.",

setup.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33

44
from setuptools import setup, Extension
55

6+
67
def get_c_sources(include_headers=False):
7-
sources=['module.c'] + glob.glob("third-party/*.c")
8-
if include_headers:
9-
sources += glob.glob("third-party/*.h")
10-
return sources
8+
sources = ['module.c'] + glob.glob("third-party/*.c")
9+
if include_headers:
10+
sources += glob.glob("third-party/*.h")
11+
return sources
12+
1113

12-
_quickjs = Extension('_quickjs',
13-
define_macros=[('CONFIG_VERSION', '"2019-07-09"')],
14-
# HACK.
15-
# See https://github.com/pypa/packaging-problems/issues/84.
16-
sources=get_c_sources(include_headers=("sdist" in sys.argv)),
17-
headers=glob.glob("third-party/*.h"))
14+
_quickjs = Extension(
15+
'_quickjs',
16+
define_macros=[('CONFIG_VERSION', '"2019-07-09"')],
17+
# HACK.
18+
# See https://github.com/pypa/packaging-problems/issues/84.
19+
sources=get_c_sources(include_headers=("sdist" in sys.argv)),
20+
headers=glob.glob("third-party/*.h"))
1821

1922
long_description = """
2023
Thin Python wrapper around https://bellard.org/quickjs/ .
@@ -24,7 +27,7 @@ def get_c_sources(include_headers=False):
2427
author_email="petter.strandmark@gmail.com",
2528
name='quickjs',
2629
url='https://github.com/PetterS/quickjs',
27-
version='1.1.1',
30+
version='1.1.2',
2831
description='Wrapping the quickjs C library.',
2932
long_description=long_description,
3033
packages=["quickjs"],

test_quickjs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ def test_time_limit(self):
263263
f.set_time_limit(-1)
264264
f()
265265

266+
def test_wrong_context(self):
267+
context1 = quickjs.Context()
268+
context2 = quickjs.Context()
269+
f = context1.eval("(function(x) { return x.a; })")
270+
d = context2.eval("({a: 1})")
271+
with self.assertRaisesRegex(ValueError, "Can not mix JS objects from different contexts."):
272+
f(d)
273+
266274

267275
class Strings(unittest.TestCase):
268276
def test_unicode(self):

0 commit comments

Comments
 (0)