tbodt / v8py

Write Python APIs, then call them from JavaScript using the V8 engine.
GNU Lesser General Public License v3.0
440 stars 28 forks source link

Classes that contain things other than methods, booleans, numbers and strings cause a segfault #13

Open tbodt opened 7 years ago

tbodt commented 7 years ago

Examples:

class Test:
    class Inner:
        pass
    mapping = {'a': 'b'}
    thing = ['a', 'b']
tbodt commented 7 years ago

Making this work as expected wouldn't be easy, since exactly one FunctionTemplate is created for each class, and V8 requires that everything other than functions, booleans, numbers, and strings be created in a context. Maybe a special context could be created for these things? But that would allow communication between contexts where that might not be intended:

class Thing:
    thing = []
a = v8py.Context()
a.expose(Thing)
a.eval('Thing.thing.push("hello")')
b = v8py.Context()
b.expose(Thing)
a.eval('Thing.thing') #=> ['hello']

The solution is probably to ignore or issue a warning for these things.

cc @buffer

tbodt commented 6 years ago

@desertkun has found that using a context would not actually help, since you can only set templates and primitives as template attributes anyway. https://github.com/tbodt/v8py/issues/24#issuecomment-396599646