I'm embedding SpiderMonkey and am attempting to use JS_BindCallable
. However, I have a JSObject *
that I want to use as the newThis
, yet the function takes a JSRawObject
. The documentation on JSRawObject
seems sparse and the header files haven't provided any clues.
It appears to compile if I simply pass it a JSObject *
, without crashing, but I'm not sure why, and that makes me uncomfortable. Further, it doesn't seem to work - not sure if that's because of this issue or because of something else. In particular, I'm doing this:
JSObject *result = JS_NewObject(cx, NULL, NULL, NULL);
//create .finish() callable
int props = JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE;
JS_DefineFunction(cx, result, "finish", my_native_func, 0, props);
//bind finish to always use 'this'
jsval jsvFinishFuncObj;
JS_GetProperty(cx, result, "finish", &jsvFinishFuncObj);
JSObject *finishFuncObj = JSVAL_TO_OBJECT(jsvFinishFuncObj);
JS_BindCallable(cx, finishFuncObj, result);