RoamUniverse / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

Segfault when trying to create JS functions from Python objects with __call__ #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What I'm trying achieve is to provide a mock jQuery object to V8, which is
both a function and has methods/properties. I may be doing something wrong,
since I've just started learning about V8 and PyV8. Anyways, I've gotten
the issue down to the following test case, which segfaults on Ubuntu Karmic
with the latest PyV8 from SVN (boost is 1.40).

Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyV8
>>> class JQuery(object):
...     def __call__(self, *args, **kwargs):
...         print '__call__():', args, kwargs
...     def test(self, *args, **kwargs):
...         print 'test():', args, kwargs
...
>>> globals = PyV8.JSClass()
>>> setattr(globals, '$', JQuery())
>>>
>>> with PyV8.JSContext(globals) as ctx:
...     ctx.eval('$.test("calling", "test")');
...     ctx.eval('$("calling", "__call__")');
...
test(): ('calling', 'test') {}
Segmentation fault

So $.test() works fine, but $() doesn't; is there a better way to be doing
this?

Original issue reported on code.google.com by sciyoshi on 30 Dec 2009 at 12:49

GoogleCodeExporter commented 9 years ago
Here's the backtrace:

#0  0x00613ac5 in boost::python::api::object_base::operator= (args=...) at
/usr/include/boost/python/object_core.hpp:501
#1  operator= (args=...) at /usr/include/boost/python/object_core.hpp:311
#2  CPythonObject::Caller (args=...) at src/Wrapper.cpp:371
#3  0x0063b9d0 in v8::internal::HandleApiCallAsFunctionOrConstructor(bool,
v8::internal::Arguments) () from /usr/local/lib/python2.6/dist-packages/_PyV8.so
#4  0x082f37bc in ?? ()
#5  0x00afb6e0 in ?? ()
#6  0xb7eee135 in ?? ()

I can provide more info if needed...

Original comment by sciyoshi on 30 Dec 2009 at 12:51

GoogleCodeExporter commented 9 years ago

Original comment by flier...@gmail.com on 30 Dec 2009 at 2:35

GoogleCodeExporter commented 9 years ago
The root cause is that v8 handle the '$("calling", "__call__")' as a 
constructor style function 
call, but the __call__ method assume the method should be call like  
'$.__call__("calling", 
"__call__")'. 

Please check out the latest source from SVN after revision #184, or use the 
private build in 
attachment to verify it on Windows.

Thanks

Original comment by flier...@gmail.com on 30 Dec 2009 at 3:11

Attachments:

GoogleCodeExporter commented 9 years ago
Looks like that fixed it, thanks!

Original comment by sciyoshi on 30 Dec 2009 at 9:58