How to debug in js-binding?

How to debug in js-binding?
0.0 0


How to debug in js-binding?



I’ve spent the best part of a day looking into this (on iOS) and at the moment, I cannot get anything to work. For the purposes of documenting what I’ve done, and seeing if anyone else has any suggestions, here’s the write up.

I looked at the following areas:

  • I set #define JSB_ENABLE_DEBUGGER 1 in js_bindings_config.h.
  • I added ScriptingCore::getInstance->enableDebugger ; to my AppDelegate startup code, before the first runScript call. This is where the problems started to occur.
  1. The line JS_WrapObject; in ScriptingCore::enableDebugger causes the following error to be output to the console:
    Cocos2d: JS: :0:too much recursion

Maybe this is the root cause of nothing else working, but I don’t understand what it means, or how to prevent it, short of removing that code. What does JS_WrapObject do anyway? I could find no documentation for it.

  1. If you are running on a real device, you then get the following error from the **JS_CallFunctionName *** method:
    Cocos2d: JS: /var/mobile/Applications/4EFA31FD-BB44-4AFF-B810-648BE538CAB1/ Debugger: argument must be an object from a different compartment
    Having read all about SpiderMonkey compartments and the debugger API, I still can’t figure out in the code why this error should occur, enableDebugger looks ok to me, but I obviously lack knowledge somewhere. My guess would be that NewGlobalObject isn’t actually creating the debugGlobal_ member in a new compartment for some reason.
  2. If you are running in the simulator however, you get an assertion thrown by the SpiderMonkey code :
    **** Compartment mismatch 0xb1dcc00 vs. 0xb195e00
    Assertion failure: false (compartment mismatched), at …/jscntxtinlines.h:204
My guess here is that there’s a bug in the SpiderMonkey JS\_CallFunctionName implementation. Generally, all the arguments to a Javascript function are going to need to be references to objects within the same compartment. However, in this case, since the first argument is a reference to the debugee global object, and is passed to **var tmp = new Debugger ;** in **jsb\_debugger.js**, it’s expected to be in a different compartment!

This seems to contradict the release build error though. That says the objects need to be in different compartments, implying they are in the same compartment. The debug build assert claims the objects need to be in the same compartment though, implying they are in different compartments! Which is it?

I followed the thread on ‘’ and tried using the patched versions of SpiderMonkey, but that didn’t fix anything as far as I could tell.

At this point, I’ve given up. There is currently no viable debugging options for Javascript code running under Cocos2d-x using the JSB. Someone please correct me if I’m wrong.




Is there any update on this topic ?
I am trying to port a cocos2d-html5 app to cocos2d-x, and js-debugging would definitely help :wink:



here is a tutorial