Subj : Re: spidermonkey - wrapper code generator To : netscape.public.mozilla.jseng From : Jens Thiele Date : Fri Mar 26 2004 01:31 pm > Well, personally, I'd recommend jsgen. ;) > > If you have well-formed C++ classes, it works rather effectively. In my > case, if I have any problems or need any changes, I just pop into the > source and fix 'em up. I would suggest checking out the > source/generated source to see if it suits your tastes. > > Marcello the test app is crashing ../test test.js using debian package of spidermonkey - 1.5rc6-1 debug info: GNU gdb 5.3-debian Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-linux"... Vector2dChild(0xbffff5d4) JSTest()=0xbffff5b0 Vector2dChild(0xbffff594) JSTest()=0xbffff570 JSTestChild(0xbffff570) Vector2dChild(0xbffff554) JSTest()=0xbffff530 JSTestChild(0xbffff530) JSTestChild2(0xbffff530) Vector2dChild(0x8062444) JSTest(0, argv)=0x8062420 Vector2dChild(0x80624a4) JSTest(2)=0x8062480 Vector2dChild(0x806d85c) JSTest(3, argv)=0x806d838 yo yo JSTest::test1() test1=undefined JSTest::test2() test2=2 JSTest::test4(1,2) test4=undefined JSTest::test5(1,2,3) test5=5 JSTest::test6(1) type is int! test6=1 JSTest::test6(1) type is int! test6=1 JSTest::test6(1.2) type is double! test6=1.2 JSTest::test6(1) type is boolean! test6=true JSTest::test6(0) type is boolean! test6=false JSTest::test6(hello) type is string! test6=hello JSTest::test6(?) type is something else! test6=[object JSTest] JSTest::test6(?) type is something else! test6= function f() { return 1; } JSTest::test6(null) type is null! test6=null JSTest::test8(3) test8=undefined JSTest::test8(4) test8=undefined test=[object JSTest] [object JSTest] [object Vector2d] new v=0,0 new v=2,3 v=2,3 t.pos=0,4.484155085839415e-44 v=3,4 t.pos=0,4.484155085839415e-44 v=4,5 t.pos=0,4.484155085839415e-44 Objects can be passed into a function by reference: JSTest::test8(Vector2d(100,100)) JSTest::test8(Vector2d(100,100)) Classes can be inspected: JSTest['TEST']=4 JSTest['TEST2']=5 JSTest['TEST3']=6 JSTest['visible']=false Static variables can be retrieved: test.visible=false test.TEST=4 test.TEST2=5 test.TEST3=6 And modified: test.visible=false test2.visible=false test.visible=true test2.visible=true Static variables can be retrieved by their classname: JSTest.visible=true JSTest.TEST=4 JSTest.TEST2=5 JSTest.TEST3=6 Static functions can be called on the class name or an instance: JSTest::test3(1) JSTest.test3(1)=undefined JSTest::test3(1) test.test3(1)=undefined Subclasses are also supported: Making a JSTestChild Vector2dChild(0x806adcc) JSTest()=0x806ada8 JSTestChild(2)=0x806ada8 running an overridden function from the child class: JSTestChild::test1() running a function from the parent class: JSTest::test3(1) t.child.prototype=undefined t=[object JSTest] test=[object JSTest] test2=[object JSTestChild] JSTestChild= function JSTestChild() { [native code] } Vector2dChild(0x807067c) JSTest(0, argv)=0x8070658 new JSTest=[object JSTest] Vector2dChild(0x8070754) JSTest()=0x8070730 JSTestChild(1)=0x8070730 new JSTestChild(1)=[object JSTestChild] Vector2dChild(0x80708c0) new Vector2dChild=[object Vector2dChild] t.child=[object Vector2dChild] JSExec result ------------- undefined ~JSTestChild2(0xbffff530) [New Thread 16384 (LWP 20365)] Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 16384 (LWP 20365)] 0x4006f335 in js_SetSlotThreadSafe () from /usr/lib/libsmjs.so.1 $1 = "--- Stack: ---" #0 0x4006f335 in js_SetSlotThreadSafe () from /usr/lib/libsmjs.so.1 #1 0x4003c05f in JS_SetPrivate () from /usr/lib/libsmjs.so.1 #2 0x0804d47d in ~_JSinternalStruct (this=0xbffff56c) at JSTestChild2JS.h:43 #3 0x0804d0f0 in ~JSTestChild2 (this=0xbffff530) at example/JSTestChild2.cpp:11 #4 0x08049d11 in main (argc=2, argv=0xbffffb84) at example/test.cpp:119 #1 0x4003c05f in JS_SetPrivate () from /usr/lib/libsmjs.so.1 #2 0x0804d47d in ~_JSinternalStruct (this=0xbffff56c) at JSTestChild2JS.h:43 43 ~_JSinternalStruct() { if (o) JS_SetPrivate(NULL,o, NULL); }; $2 = "----- The source: ----" 38 39 ///// JavaScript Object Linking 40 struct _JSinternalStruct { 41 JSObject *o; 42 _JSinternalStruct() : o(NULL) {}; 43 ~_JSinternalStruct() { if (o) JS_SetPrivate(NULL,o, NULL); }; 44 }; 45 _JSinternalStruct _JSinternal; 46 JSObject *getJSObject(JSContext *cx); 47 static JSObject *newJSObject(JSContext *cx); $3 = "---- o: ---- " $4 = (JSObject *) 0x8059e70 #3 0x0804d0f0 in ~JSTestChild2 (this=0xbffff530) at example/JSTestChild2.cpp:11 11 cout << "~JSTestChild2(" << this << ")" << endl; 6 7 JSTestChild2::JSTestChild2() : JSTestChild() { 8 cout << "JSTestChild2(" << this << ")" << endl; 9 } 10 JSTestChild2::~JSTestChild2() { 11 cout << "~JSTestChild2(" << this << ")" << endl; 12 } 13 JSTestChild2::JSTestChild2(int i) { 14 cout << "JSTestChild2(" << i << ")=" << this << endl; 15 } .