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.
2) 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/XXXXX.app/jsb_debugger.js:175:TypeError: 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.
3) 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
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 ‘https://github.com/cocos2d/cocos2d-x/pull/1832’ and tried using the patched versions of SpiderMonkey, but that didn’t fix anything as far as I could tell.