Monday, August 20, 2007

javascript (spidermonkey) embedding pitfalls

Here is some experiences I had with Mozilla's spidermonkey during my attempts to embedded it into zoloFisher and zoloFighter.

1. the engine is built for speed, not much around user friendliness. Examples will be, engine provides INT_TO_JSVAL, FLOAT_TO_JSVAL macros, but if you look at them, they simply uses part of the bits ON THE VALUE itself to mark them as int or float (or object). So what value you can put in them are restricted, the macros are just a faster way to make jsvals when permits. To be on the safe side, always use the js_MakeNumber functions to make an object out of it.

2. If you compile with VC++, certain macros are not compiled correctly (visual c++ problem). So if you ever wondering why some exception was generated during GC under certain conditions or why 'new Array()' won't work, move 2 of the macros in jsobj.h, OBJ_SET_PROPERTY and OBJ_GET_PROPERTY, make them functions (VC++ still sucks in compile, but great to use).

3. Last but not the least, when compile, always define XP_WIN

No comments: