static bool js_cocos2dx_CCTableView_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { // save the delegate JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]); JSB_TableViewDelegate* nativeDelegate = new JSB_TableViewDelegate(); nativeDelegate->setJSDelegate(jsDelegate); __Dictionary* userDict = static_cast<__Dictionary*>(cobj->getUserObject()); if (NULL == userDict) { userDict = new __Dictionary(); cobj->setUserObject(userDict); userDict->release(); } userDict->setObject(nativeDelegate, KEY_TABLEVIEW_DELEGATE); cobj->setDelegate(nativeDelegate); nativeDelegate->release(); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); return false; }
static bool js_cocos2dx_CCTableView_setDelegate(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::extension::TableView* cobj = (cocos2d::extension::TableView *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { // save the delegate JS::RootedObject jsDelegate(cx, args.get(0).toObjectOrNull()); JSB_TableViewDelegate* nativeDelegate = new (std::nothrow) JSB_TableViewDelegate(); nativeDelegate->setJSDelegate(jsDelegate); JS_SetProperty(cx, obj, "_delegate", args.get(0)); __Dictionary* userDict = static_cast<__Dictionary*>(cobj->getUserObject()); if (NULL == userDict) { userDict = new (std::nothrow) __Dictionary(); cobj->setUserObject(userDict); userDict->release(); } userDict->setObject(nativeDelegate, KEY_TABLEVIEW_DELEGATE); cobj->setDelegate(nativeDelegate); nativeDelegate->release(); args.rval().setUndefined(); return true; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); return false; }