issue #1653: JS_ValueToInt32, JS_ValueToECMAInt32 --> jsval_to_int32

Using JSB_PRECONDITION2 to check the return value of js api.
Reporting an error when binding api return JS_FALSE.
This commit is contained in:
James Chen 2013-01-11 17:44:39 +08:00
parent 273ffcc571
commit 7f4146f3e2
6 changed files with 183 additions and 211 deletions

View File

@ -1,6 +1,7 @@
#include "cocos2d.h" #include "cocos2d.h"
#include "cocos2d_specifics.hpp" #include "cocos2d_specifics.hpp"
#include <typeinfo> #include <typeinfo>
#include "js_bindings_config.h"
schedFunc_proxy_t *_schedFunc_target_ht = NULL; schedFunc_proxy_t *_schedFunc_target_ht = NULL;
schedTarget_proxy_t *_schedTarget_native_ht = NULL; schedTarget_proxy_t *_schedTarget_native_ht = NULL;
@ -181,9 +182,10 @@ JSBool js_cocos2dx_CCNode_getChildren(JSContext *cx, uint32_t argc, jsval *vp)
} }
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsarr)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsarr));
}
return JS_TRUE; return JS_TRUE;
} }
}
JS_ReportError(cx, "Error in js_cocos2dx_CCNode_getChildren");
return JS_FALSE; return JS_FALSE;
} }
@ -243,6 +245,7 @@ JSBool js_cocos2dx_CCMenu_create(JSContext *cx, uint32_t argc, jsval *vp)
JS_SET_RVAL(cx, vp, jsret); JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -281,6 +284,7 @@ JSBool js_cocos2dx_CCSequence_create(JSContext *cx, uint32_t argc, jsval *vp)
JS_SET_RVAL(cx, vp, jsret); JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -319,6 +323,7 @@ JSBool js_cocos2dx_CCSpawn_create(JSContext *cx, uint32_t argc, jsval *vp)
JS_SET_RVAL(cx, vp, jsret); JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -331,6 +336,7 @@ JSBool js_cocos2dx_CCMenuItem_create(JSContext *cx, uint32_t argc, jsval *vp)
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -475,17 +481,20 @@ JSBool js_cocos2dx_CCMenuItemLabel_create(JSContext *cx, uint32_t argc, jsval *v
JSBool js_cocos2dx_CCMenuItemAtlasFont_create(JSContext *cx, uint32_t argc, jsval *vp) JSBool js_cocos2dx_CCMenuItemAtlasFont_create(JSContext *cx, uint32_t argc, jsval *vp)
{ {
if (argc >= 5) { if (argc >= 5) {
JSBool ok = JS_TRUE;
jsval *argv = JS_ARGV(cx, vp); jsval *argv = JS_ARGV(cx, vp);
JSStringWrapper arg0(argv[0]); JSStringWrapper arg0(argv[0]);
JSStringWrapper arg1(argv[1]); JSStringWrapper arg1(argv[1]);
int arg2; if (!JS_ValueToInt32(cx, argv[2], &arg2)) return JS_FALSE; int arg2; ok &= jsval_to_int32(cx, argv[2], &arg2);
int arg3; if (!JS_ValueToInt32(cx, argv[3], &arg3)) return JS_FALSE; int arg3; ok &= jsval_to_int32(cx, argv[3], &arg3);
int arg4; if (!JS_ValueToInt32(cx, argv[4], &arg4)) return JS_FALSE; int arg4; ok &= jsval_to_int32(cx, argv[4], &arg4);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cocos2d::CCMenuItemAtlasFont* ret = cocos2d::CCMenuItemAtlasFont::create(arg0, arg1, arg2, arg3, arg4); cocos2d::CCMenuItemAtlasFont* ret = cocos2d::CCMenuItemAtlasFont::create(arg0, arg1, arg2, arg3, arg4);
JSObject *obj = bind_menu_item<cocos2d::CCMenuItemAtlasFont>(cx, ret, (argc >= 6 ? argv[5] : JSVAL_VOID), (argc == 7 ? argv[6] : JSVAL_VOID)); JSObject *obj = bind_menu_item<cocos2d::CCMenuItemAtlasFont>(cx, ret, (argc >= 6 ? argv[5] : JSVAL_VOID), (argc == 7 ? argv[6] : JSVAL_VOID));
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -540,6 +549,7 @@ JSBool js_cocos2dx_CCMenuItemToggle_create(JSContext *cx, uint32_t argc, jsval *
JS_SET_RVAL(cx, vp, jsret); JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -581,10 +591,7 @@ JSBool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp)
cocos2d::CCArray* arg0; cocos2d::CCArray* arg0;
if (argc > 0) { if (argc > 0) {
ok &= jsval_to_ccarray(cx, argv[0], &arg0); ok &= jsval_to_ccarray(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
} }
cocos2d::CCAnimation* ret; cocos2d::CCAnimation* ret;
double arg1 = 0.0f; double arg1 = 0.0f;
@ -596,7 +603,7 @@ JSBool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp)
} else if (argc == 3) { } else if (argc == 3) {
unsigned int loops; unsigned int loops;
JS_ValueToNumber(cx, argv[1], &arg1); JS_ValueToNumber(cx, argv[1], &arg1);
JS_ValueToECMAUint32(cx, argv[1], &loops); jsval_to_uint32(cx, argv[1], &loops);
ret = cocos2d::CCAnimation::create(arg0, arg1, loops); ret = cocos2d::CCAnimation::create(arg0, arg1, loops);
} else if (argc == 1) { } else if (argc == 1) {
ret = cocos2d::CCAnimation::createWithSpriteFrames(arg0); ret = cocos2d::CCAnimation::createWithSpriteFrames(arg0);
@ -620,6 +627,7 @@ JSBool js_cocos2dx_CCAnimation_create(JSContext *cx, uint32_t argc, jsval *vp)
JS_SET_RVAL(cx, vp, jsret); JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -629,10 +637,8 @@ JSBool js_cocos2dx_CCLayerMultiplex_create(JSContext *cx, uint32_t argc, jsval *
cocos2d::CCArray* arg0; cocos2d::CCArray* arg0;
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
ok &= jsvals_variadic_to_ccarray(cx, argv, argc, &arg0); ok &= jsvals_variadic_to_ccarray(cx, argv, argc, &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
cocos2d::CCLayerMultiplex* ret = cocos2d::CCLayerMultiplex::createWithArray(arg0); cocos2d::CCLayerMultiplex* ret = cocos2d::CCLayerMultiplex::createWithArray(arg0);
jsval jsret; jsval jsret;
do { do {
@ -743,6 +749,7 @@ JSBool js_cocos2dx_CCNode_copy(JSContext *cx, uint32_t argc, jsval *vp)
return JS_TRUE; return JS_TRUE;
} }
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -1137,8 +1144,7 @@ JSBool js_CCNode_unschedule(JSContext *cx, uint32_t argc, jsval *vp)
js_proxy_t *proxy; js_proxy_t *proxy;
JS_GET_NATIVE_PROXY(proxy, obj); JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::CCNode *node = (cocos2d::CCNode *)(proxy ? proxy->ptr : NULL); cocos2d::CCNode *node = (cocos2d::CCNode *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2(node, cx, JS_FALSE, "Invalid Native Object");
if(!node) return JS_FALSE;
CCScheduler *sched = node->getScheduler(); CCScheduler *sched = node->getScheduler();
@ -1562,6 +1568,7 @@ JSBool js_cocos2dx_retain(JSContext *cx, uint32_t argc, jsval *vp)
return JS_TRUE; return JS_TRUE;
} }
} }
JS_ReportError(cx, "Invalid Native Object.");
return JS_FALSE; return JS_FALSE;
} }
@ -1576,6 +1583,7 @@ JSBool js_cocos2dx_release(JSContext *cx, uint32_t argc, jsval *vp)
return JS_TRUE; return JS_TRUE;
} }
} }
JS_ReportError(cx, "Invalid Native Object.");
return JS_FALSE; return JS_FALSE;
} }
@ -1601,6 +1609,8 @@ JSBool js_cocos2dx_CCSet_constructor(JSContext *cx, uint32_t argc, jsval *vp)
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "Error in js_cocos2dx_CCSet_constructor");
return JS_FALSE; return JS_FALSE;
} }
@ -1616,10 +1626,8 @@ JSBool js_cocos2dx_CCNode_setPosition(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
cobj->setPosition(arg0); cobj->setPosition(arg0);
return JS_TRUE; return JS_TRUE;
} if (argc == 2) { } if (argc == 2) {
@ -1651,10 +1659,7 @@ JSBool js_cocos2dx_CCSprite_setPosition(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
cobj->setPosition(arg0); cobj->setPosition(arg0);
return JS_TRUE; return JS_TRUE;
} if (argc == 2) { } if (argc == 2) {
@ -1695,6 +1700,7 @@ JSBool js_cocos2dx_CCTMXLayer_tileFlagsAt(JSContext *cx, uint32_t argc, jsval *v
JS_SET_RVAL(cx, vp, jsret); JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE; return JS_FALSE;
} }
@ -1885,10 +1891,8 @@ JSBool js_cocos2dx_ccpAdd(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpAdd(arg0, arg1); CCPoint ret = ccpAdd(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -1911,10 +1915,7 @@ JSBool js_cocos2dx_ccpDistance(JSContext *cx, uint32_t argc, jsval *vp)
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
float ret = ccpDistance(arg0, arg1); float ret = ccpDistance(arg0, arg1);
jsval jsret = DOUBLE_TO_JSVAL(ret); jsval jsret = DOUBLE_TO_JSVAL(ret);
@ -1937,10 +1938,7 @@ JSBool js_cocos2dx_ccpClamp(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
cocos2d::CCPoint arg2; cocos2d::CCPoint arg2;
ok &= jsval_to_ccpoint(cx, argv[2], &arg2); ok &= jsval_to_ccpoint(cx, argv[2], &arg2);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpClamp(arg0, arg1, arg2); CCPoint ret = ccpClamp(arg0, arg1, arg2);
@ -1960,10 +1958,7 @@ JSBool js_cocos2dx_ccpLengthSQ(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
float ret = ccpLengthSQ(arg0); float ret = ccpLengthSQ(arg0);
jsval jsret = DOUBLE_TO_JSVAL(ret); jsval jsret = DOUBLE_TO_JSVAL(ret);
@ -1983,10 +1978,7 @@ JSBool js_cocos2dx_ccpLength(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
float ret = ccpLength(arg0); float ret = ccpLength(arg0);
@ -2007,10 +1999,7 @@ JSBool js_cocos2dx_ccpNeg(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpNeg(arg0); CCPoint ret = ccpNeg(arg0);
@ -2033,10 +2022,8 @@ JSBool js_cocos2dx_ccpSub(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpSub(arg0, arg1); CCPoint ret = ccpSub(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -2056,10 +2043,8 @@ JSBool js_cocos2dx_ccpMult(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 2) { if (argc == 2) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
double arg1; double arg1;
if( ! JS_ValueToNumber(cx, argv[1], &arg1) ) { if( ! JS_ValueToNumber(cx, argv[1], &arg1) ) {
return JS_FALSE; return JS_FALSE;
@ -2087,10 +2072,8 @@ JSBool js_cocos2dx_ccpMidpoint(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpMidpoint(arg0, arg1); CCPoint ret = ccpMidpoint(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -2113,10 +2096,8 @@ JSBool js_cocos2dx_ccpDot(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
float ret = ccpDot(arg0, arg1); float ret = ccpDot(arg0, arg1);
jsval jsret = DOUBLE_TO_JSVAL(ret); jsval jsret = DOUBLE_TO_JSVAL(ret);
@ -2138,10 +2119,8 @@ JSBool js_cocos2dx_ccpCross(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
float ret = ccpCross(arg0, arg1); float ret = ccpCross(arg0, arg1);
jsval jsret = DOUBLE_TO_JSVAL(ret); jsval jsret = DOUBLE_TO_JSVAL(ret);
@ -2161,10 +2140,8 @@ JSBool js_cocos2dx_ccpPerp(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpPerp(arg0); CCPoint ret = ccpPerp(arg0);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -2185,10 +2162,8 @@ JSBool js_cocos2dx_ccpRPerp(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpRPerp(arg0); CCPoint ret = ccpRPerp(arg0);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -2211,10 +2186,8 @@ JSBool js_cocos2dx_ccpProject(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpProject(arg0, arg1); CCPoint ret = ccpProject(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -2236,10 +2209,8 @@ JSBool js_cocos2dx_ccpRotate(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
cocos2d::CCPoint arg1; cocos2d::CCPoint arg1;
ok &= jsval_to_ccpoint(cx, argv[1], &arg1); ok &= jsval_to_ccpoint(cx, argv[1], &arg1);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpRotate(arg0, arg1); CCPoint ret = ccpRotate(arg0, arg1);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -2259,10 +2230,8 @@ JSBool js_cocos2dx_ccpNormalize(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 1) { if (argc == 1) {
cocos2d::CCPoint arg0; cocos2d::CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
CCPoint ret = ccpNormalize(arg0); CCPoint ret = ccpNormalize(arg0);
jsval jsret = ccpoint_to_jsval(cx, ret); jsval jsret = ccpoint_to_jsval(cx, ret);
@ -2317,8 +2286,8 @@ JSBool js_cocos2dx_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
if (argc == 2) if (argc == 2)
{ {
GLenum src, dst; GLenum src, dst;
JS_ValueToInt32(cx, argv[0], (int32_t*)&src); jsval_to_int32(cx, argv[0], (int32_t*)&src);
JS_ValueToInt32(cx, argv[1], (int32_t*)&dst); jsval_to_int32(cx, argv[1], (int32_t*)&dst);
ccBlendFunc blendFunc = {src, dst}; ccBlendFunc blendFunc = {src, dst};
cobj->setBlendFunc(blendFunc); cobj->setBlendFunc(blendFunc);
return JS_TRUE; return JS_TRUE;
@ -2381,13 +2350,12 @@ JSBool js_cocos2dx_CCTexture2D_setTexParameters(JSContext *cx, uint32_t argc, js
GLint arg0, arg1, arg2, arg3; GLint arg0, arg1, arg2, arg3;
ok &= JS_ValueToInt32(cx, *argvp++, &arg0); ok &= jsval_to_int32(cx, *argvp++, &arg0);
ok &= JS_ValueToInt32(cx, *argvp++, &arg1); ok &= jsval_to_int32(cx, *argvp++, &arg1);
ok &= JS_ValueToInt32(cx, *argvp++, &arg2); ok &= jsval_to_int32(cx, *argvp++, &arg2);
ok &= JS_ValueToInt32(cx, *argvp++, &arg3); ok &= jsval_to_int32(cx, *argvp++, &arg3);
if( ! ok ) JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
return JS_FALSE;
ccTexParams param = { arg0, arg1, arg2, arg3 }; ccTexParams param = { arg0, arg1, arg2, arg3 };
@ -2419,7 +2387,7 @@ JSBool js_cocos2dx_CCMenu_alignItemsInRows(JSContext *cx, uint32_t argc, jsval *
JS_SET_RVAL(cx, vp, JSVAL_VOID); JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "Error in js_cocos2dx_CCMenu_alignItemsInRows");
return JS_FALSE; return JS_FALSE;
} }
@ -2440,7 +2408,7 @@ JSBool js_cocos2dx_CCMenu_alignItemsInColumns(JSContext *cx, uint32_t argc, jsva
JS_SET_RVAL(cx, vp, JSVAL_VOID); JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "Error in js_cocos2dx_CCMenu_alignItemsInColumns");
return JS_FALSE; return JS_FALSE;
} }
@ -2460,10 +2428,7 @@ JSBool js_cocos2dx_CCTMXLayer_getTileFlagsAt(JSContext *cx, uint32_t argc, jsval
ccTMXTileFlags flags; ccTMXTileFlags flags;
CCPoint arg0; CCPoint arg0;
ok &= jsval_to_ccpoint(cx, argv[0], &arg0); ok &= jsval_to_ccpoint(cx, argv[0], &arg0);
if (!ok) { JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
// TODO: Need to use JSB_PRECONDITION2 like which was done in cocos2d-iphone.
return JS_FALSE;
}
cobj->tileGIDAt(arg0, &flags); cobj->tileGIDAt(arg0, &flags);
JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)flags)); JS_SET_RVAL(cx, vp, UINT_TO_JSVAL((uint32_t)flags));
@ -2494,11 +2459,7 @@ JSBool js_cocos2dx_CCDrawNode_drawPolygon(JSContext *cx, uint32_t argc, jsval *v
// Points // Points
ok &= JS_ValueToObject(cx, *argvp++, &argArray); ok &= JS_ValueToObject(cx, *argvp++, &argArray);
if( ! (argArray && JS_IsArrayObject(cx, argArray) ) ) JSB_PRECONDITION2( (argArray && JS_IsArrayObject(cx, argArray)) , cx, JS_FALSE, "Vertex should be anArray object");
{
JS_ReportError(cx, "Vertex should be anArray object");
return JS_FALSE;
}
// Color 4F // Color 4F
ok &= jsval_to_cccolor4f(cx, *argvp++, &argFillColor); ok &= jsval_to_cccolor4f(cx, *argvp++, &argFillColor);
@ -2509,10 +2470,7 @@ JSBool js_cocos2dx_CCDrawNode_drawPolygon(JSContext *cx, uint32_t argc, jsval *v
// Color Border (4F) // Color Border (4F)
ok &= jsval_to_cccolor4f(cx, *argvp++, &argBorderColor); ok &= jsval_to_cccolor4f(cx, *argvp++, &argBorderColor);
if( ! ok ) JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error parsing arguments");
{
return JS_FALSE;
}
{ {
uint32_t l; uint32_t l;

View File

@ -1 +1 @@
85427ffdec174f7577dee7163935cbc734493d9f 9594a5677c70358b9e128381d6481eeed0e80723

View File

@ -1 +1 @@
825cd16f3b0732605930ab87034b777db43baa6f 4364383f6fa186d74f05b8deff211e841ab0d2e1

View File

@ -168,13 +168,13 @@ void JSB_CCPhysicsDebugNode_finalize(JSFreeOp *fop, JSObject *obj)
// Arguments: cpSpace* // Arguments: cpSpace*
// Ret value: CCPhysicsDebugNode* (o) // Ret value: CCPhysicsDebugNode* (o)
JSBool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_CCPhysicsDebugNode_debugNodeForCPSpace__static(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3( argc == 1, cx, JS_FALSE, "Invalid number of arguments" ); JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" );
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
cpSpace* arg0; cpSpace* arg0;
ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 );
JSB_PRECONDITION3(ok, cx, JS_FALSE, "Error processing arguments"); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
CCPhysicsDebugNode* ret = CCPhysicsDebugNode::create(arg0); CCPhysicsDebugNode* ret = CCPhysicsDebugNode::create(arg0);
jsval jsret; jsval jsret;
@ -208,13 +208,13 @@ JSBool JSB_CCPhysicsDebugNode_setSpace_(JSContext *cx, uint32_t argc, jsval *vp)
CCPhysicsDebugNode* real = (CCPhysicsDebugNode *)(proxy ? proxy->ptr : NULL); CCPhysicsDebugNode* real = (CCPhysicsDebugNode *)(proxy ? proxy->ptr : NULL);
TEST_NATIVE_OBJECT(cx, real) TEST_NATIVE_OBJECT(cx, real)
JSB_PRECONDITION3( argc == 1, cx, JS_FALSE, "Invalid number of arguments" ); JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" );
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
cpSpace* arg0; cpSpace* arg0;
ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 ); ok &= jsval_to_opaque( cx, *argvp++, (void**)&arg0 );
JSB_PRECONDITION3(ok, cx, JS_FALSE, "Error processing arguments"); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
real->setSpace(arg0); real->setSpace(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID); JS_SET_RVAL(cx, vp, JSVAL_VOID);
@ -229,7 +229,7 @@ JSBool JSB_CCPhysicsDebugNode_space(JSContext *cx, uint32_t argc, jsval *vp) {
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, jsthis); js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, jsthis);
CCPhysicsDebugNode* real = (CCPhysicsDebugNode *)(proxy ? proxy->ptr : NULL); CCPhysicsDebugNode* real = (CCPhysicsDebugNode *)(proxy ? proxy->ptr : NULL);
TEST_NATIVE_OBJECT(cx, real) TEST_NATIVE_OBJECT(cx, real)
JSB_PRECONDITION3( argc == 0, cx, JS_FALSE, "Invalid number of arguments" ); JSB_PRECONDITION2( argc == 0, cx, JS_FALSE, "Invalid number of arguments" );
cpSpace* ret_val; cpSpace* ret_val;
ret_val = real->getSpace(); ret_val = real->getSpace();
@ -844,7 +844,7 @@ JSBool __jsb_cpSpace_addCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp,
JSBool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==7, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==7, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
@ -860,7 +860,7 @@ JSBool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
// method // method
JSBool JSB_cpSpace_addCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpSpace_addCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==6, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==6, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
@ -913,7 +913,7 @@ JSBool __jsb_cpSpace_removeCollisionHandler(JSContext *cx, jsval *vp, jsval *arg
// Free function // Free function
JSBool JSB_cpSpaceRemoveCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpSpaceRemoveCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==3, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==3, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
@ -928,7 +928,7 @@ JSBool JSB_cpSpaceRemoveCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp
// method // method
JSBool JSB_cpSpace_removeCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpSpace_removeCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==2, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==2, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
@ -944,7 +944,7 @@ JSBool JSB_cpSpace_removeCollisionHandler(JSContext *cx, uint32_t argc, jsval *v
// Arguments: cpBody* // Arguments: cpBody*
// Ret value: cpBody* // Ret value: cpBody*
JSBool JSB_cpSpace_addBody(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_addBody(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -971,7 +971,7 @@ JSBool JSB_cpSpace_addBody(JSContext *cx, uint32_t argc, jsval *vp) {
// Arguments: cpConstraint* // Arguments: cpConstraint*
// Ret value: cpConstraint* // Ret value: cpConstraint*
JSBool JSB_cpSpace_addConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_addConstraint(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -998,7 +998,7 @@ JSBool JSB_cpSpace_addConstraint(JSContext *cx, uint32_t argc, jsval *vp) {
// Arguments: cpShape* // Arguments: cpShape*
// Ret value: cpShape* // Ret value: cpShape*
JSBool JSB_cpSpace_addShape(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_addShape(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -1025,7 +1025,7 @@ JSBool JSB_cpSpace_addShape(JSContext *cx, uint32_t argc, jsval *vp) {
// Arguments: cpShape* // Arguments: cpShape*
// Ret value: cpShape* // Ret value: cpShape*
JSBool JSB_cpSpace_addStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_addStaticShape(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -1054,7 +1054,7 @@ JSBool JSB_cpSpace_addStaticShape(JSContext *cx, uint32_t argc, jsval *vp) {
// Arguments: cpBody* // Arguments: cpBody*
// Ret value: void // Ret value: void
JSBool JSB_cpSpace_removeBody(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_removeBody(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -1077,7 +1077,7 @@ JSBool JSB_cpSpace_removeBody(JSContext *cx, uint32_t argc, jsval *vp) {
// Arguments: cpConstraint* // Arguments: cpConstraint*
// Ret value: void // Ret value: void
JSBool JSB_cpSpace_removeConstraint(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_removeConstraint(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -1100,7 +1100,7 @@ JSBool JSB_cpSpace_removeConstraint(JSContext *cx, uint32_t argc, jsval *vp) {
// Arguments: cpShape* // Arguments: cpShape*
// Ret value: void // Ret value: void
JSBool JSB_cpSpace_removeShape(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_removeShape(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -1123,7 +1123,7 @@ JSBool JSB_cpSpace_removeShape(JSContext *cx, uint32_t argc, jsval *vp) {
// Arguments: cpShape* // Arguments: cpShape*
// Ret value: void // Ret value: void
JSBool JSB_cpSpace_removeStaticShape(JSContext *cx, uint32_t argc, jsval *vp) { JSBool JSB_cpSpace_removeStaticShape(JSContext *cx, uint32_t argc, jsval *vp) {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsthis);
@ -1173,7 +1173,7 @@ JSBool __jsb_cpArbiter_getBodies(JSContext *cx, jsval *vp, jsval *argvp, cpArbit
// Free function // Free function
JSBool JSB_cpArbiterGetBodies(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpArbiterGetBodies(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
@ -1187,7 +1187,7 @@ JSBool JSB_cpArbiterGetBodies(JSContext *cx, uint32_t argc, jsval *vp)
// Method // Method
JSBool JSB_cpArbiter_getBodies(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpArbiter_getBodies(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==0, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==0, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
@ -1228,7 +1228,7 @@ JSBool __jsb_cpArbiter_getShapes(JSContext *cx, jsval *vp, jsval *argvp, cpArbit
// function // function
JSBool JSB_cpArbiterGetShapes(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpArbiterGetShapes(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
@ -1242,7 +1242,7 @@ JSBool JSB_cpArbiterGetShapes(JSContext *cx, uint32_t argc, jsval *vp)
// method // method
JSBool JSB_cpArbiter_getShapes(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpArbiter_getShapes(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==0, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==0, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
@ -1259,7 +1259,7 @@ JSBool JSB_cpArbiter_getShapes(JSContext *cx, uint32_t argc, jsval *vp)
// Manually added to identify static vs dynamic bodies // Manually added to identify static vs dynamic bodies
JSBool JSB_cpBody_constructor(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpBody_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==2, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==2, cx, JS_FALSE, "Invalid number of arguments");
JSObject *jsobj = JS_NewObject(cx, JSB_cpBody_class, JSB_cpBody_object, NULL); JSObject *jsobj = JS_NewObject(cx, JSB_cpBody_class, JSB_cpBody_object, NULL);
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
@ -1302,7 +1302,7 @@ JSBool __jsb_cpBody_getUserData(JSContext *cx, jsval *vp, jsval *argvp, cpBody *
// free function // free function
JSBool JSB_cpBodyGetUserData(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpBodyGetUserData(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
cpBody *body; cpBody *body;
@ -1315,7 +1315,7 @@ JSBool JSB_cpBodyGetUserData(JSContext *cx, uint32_t argc, jsval *vp)
// method // method
JSBool JSB_cpBody_getUserData(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpBody_getUserData(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==0, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==0, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
@ -1346,7 +1346,7 @@ JSBool __jsb_cpBody_setUserData(JSContext *cx, jsval *vp, jsval *argvp, cpBody *
// free function // free function
JSBool JSB_cpBodySetUserData(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpBodySetUserData(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==2, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==2, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
cpBody *body; cpBody *body;
@ -1358,7 +1358,7 @@ JSBool JSB_cpBodySetUserData(JSContext *cx, uint32_t argc, jsval *vp)
// method // method
JSBool JSB_cpBody_setUserData(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpBody_setUserData(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
@ -1373,14 +1373,14 @@ JSBool JSB_cpBody_setUserData(JSContext *cx, uint32_t argc, jsval *vp)
// cpFloat cpAreaForPoly(const int numVerts, const cpVect *verts); // cpFloat cpAreaForPoly(const int numVerts, const cpVect *verts);
JSBool JSB_cpAreaForPoly(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpAreaForPoly(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
cpVect *verts; cpVect *verts;
int numVerts; int numVerts;
ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts); ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts);
JSB_PRECONDITION3(ok, cx, JS_FALSE, "Error parsing array"); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error parsing array");
cpFloat area = cpAreaForPoly(numVerts, verts); cpFloat area = cpAreaForPoly(numVerts, verts);
@ -1393,7 +1393,7 @@ JSBool JSB_cpAreaForPoly(JSContext *cx, uint32_t argc, jsval *vp)
// cpFloat cpMomentForPoly(cpFloat m, int numVerts, const cpVect *verts, cpVect offset); // cpFloat cpMomentForPoly(cpFloat m, int numVerts, const cpVect *verts, cpVect offset);
JSBool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==3, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==3, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
cpVect *verts; cpVect offset; cpVect *verts; cpVect offset;
@ -1404,7 +1404,7 @@ JSBool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp)
ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts); ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts);
ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &offset ); ok &= jsval_to_cpVect( cx, *argvp++, (cpVect*) &offset );
JSB_PRECONDITION3(ok, cx, JS_FALSE, "Error parsing args"); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error parsing args");
cpFloat moment = cpMomentForPoly((cpFloat)m, numVerts, verts, offset); cpFloat moment = cpMomentForPoly((cpFloat)m, numVerts, verts, offset);
@ -1417,14 +1417,14 @@ JSBool JSB_cpMomentForPoly(JSContext *cx, uint32_t argc, jsval *vp)
// cpVect cpCentroidForPoly(const int numVerts, const cpVect *verts); // cpVect cpCentroidForPoly(const int numVerts, const cpVect *verts);
JSBool JSB_cpCentroidForPoly(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpCentroidForPoly(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;
cpVect *verts; cpVect *verts;
int numVerts; int numVerts;
ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts); ok &= jsval_to_array_of_cpvect( cx, *argvp++, &verts, &numVerts);
JSB_PRECONDITION3(ok, cx, JS_FALSE, "Error parsing args"); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error parsing args");
cpVect centroid = cpCentroidForPoly(numVerts, verts); cpVect centroid = cpCentroidForPoly(numVerts, verts);
@ -1452,7 +1452,7 @@ JSObject* JSB_cpBase_object = NULL;
// Constructor // Constructor
JSBool JSB_cpBase_constructor(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpBase_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3( argc==1, cx, JS_FALSE, "Invalid arguments. Expecting 1"); JSB_PRECONDITION2( argc==1, cx, JS_FALSE, "Invalid arguments. Expecting 1");
JSObject *jsobj = JS_NewObject(cx, JSB_cpBase_class, JSB_cpBase_object, NULL); JSObject *jsobj = JS_NewObject(cx, JSB_cpBase_class, JSB_cpBase_object, NULL);
@ -1484,7 +1484,7 @@ JSBool JSB_cpBase_getHandle(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
JSB_PRECONDITION3(argc==0, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==0, cx, JS_FALSE, "Invalid number of arguments");
struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis);
void *handle = proxy->handle; void *handle = proxy->handle;
@ -1498,7 +1498,7 @@ JSBool JSB_cpBase_setHandle(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* jsthis = (JSObject *)JS_THIS_OBJECT(cx, vp);
JSB_PRECONDITION( jsthis, "Invalid jsthis object"); JSB_PRECONDITION( jsthis, "Invalid jsthis object");
JSB_PRECONDITION3(argc==1, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
@ -1549,7 +1549,7 @@ void JSB_cpBase_createClass(JSContext *cx, JSObject* globalObj, const char* name
// Constructor // Constructor
JSBool JSB_cpPolyShape_constructor(JSContext *cx, uint32_t argc, jsval *vp) JSBool JSB_cpPolyShape_constructor(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JSB_PRECONDITION3(argc==3, cx, JS_FALSE, "Invalid number of arguments"); JSB_PRECONDITION2(argc==3, cx, JS_FALSE, "Invalid number of arguments");
JSObject *jsobj = JS_NewObject(cx, JSB_cpPolyShape_class, JSB_cpPolyShape_object, NULL); JSObject *jsobj = JS_NewObject(cx, JSB_cpPolyShape_class, JSB_cpPolyShape_object, NULL);
jsval *argvp = JS_ARGV(cx,vp); jsval *argvp = JS_ARGV(cx,vp);
JSBool ok = JS_TRUE; JSBool ok = JS_TRUE;

View File

@ -28,7 +28,7 @@
/** @def JSB_ASSERT_ON_FAIL /** @def JSB_ASSERT_ON_FAIL
Wheter or not to assert when the arguments or conversions are incorrect. Whether or not to assert when the arguments or conversions are incorrect.
It is recommened to turn it off in Release mode. It is recommened to turn it off in Release mode.
*/ */
#ifndef JSB_ASSERT_ON_FAIL #ifndef JSB_ASSERT_ON_FAIL
@ -39,42 +39,36 @@
#if JSB_ASSERT_ON_FAIL #if JSB_ASSERT_ON_FAIL
#define JSB_PRECONDITION( condition, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0) #define JSB_PRECONDITION( condition, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0)
#define JSB_PRECONDITION2( condition, context, ret_value, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0) #define JSB_PRECONDITION2( condition, context, ret_value, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0)
#define JSB_PRECONDITION3( condition, context, ret_value, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0)
#define ASSERT( condition, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0) #define ASSERT( condition, error_msg) do { NSCAssert( condition, [NSString stringWithUTF8String:error_msg] ); } while(0)
#else #else
#define JSB_PRECONDITION( condition, error_msg) do { \ #define JSB_PRECONDITION( condition, ...) do { \
if( ! (condition) ) { \ if( ! (condition) ) { \
cocos2d::CCLog("jsb: ERROR in %s: %s\n", __FUNCTION__, error_msg); \ cocos2d::CCLog("jsb: ERROR: File %s: Line: %d, Function: %s", __FILE__, __LINE__, __FUNCTION__ ); \
cocos2d::CCLog(__VA_ARGS__); \
JSContext* globalContext = ScriptingCore::getInstance()->getGlobalContext(); \
if( ! JS_IsExceptionPending( globalContext ) ) { \
JS_ReportError( globalContext, __VA_ARGS__ ); \
} \
return JS_FALSE; \ return JS_FALSE; \
} \ } \
} while(0) } while(0)
#define JSB_PRECONDITION2( condition, context, ret_value, ...) do { \
if( ! (condition) ) { \
cocos2d::CCLog("jsb: ERROR: File %s: Line: %d, Function: %s", __FILE__, __LINE__, __FUNCTION__ ); \
cocos2d::CCLog(__VA_ARGS__); \
if( ! JS_IsExceptionPending( context ) ) { \
JS_ReportError( context, __VA_ARGS__ ); \
} \
return ret_value; \
} \
} while(0)
#define ASSERT( condition, error_msg) do { \ #define ASSERT( condition, error_msg) do { \
if( ! (condition) ) { \ if( ! (condition) ) { \
cocos2d::CCLog("jsb: ERROR in %s: %s\n", __FUNCTION__, error_msg); \ CCLOG("jsb: ERROR in %s: %s\n", __FUNCTION__, error_msg); \
return false; \ return false; \
} \ } \
} while(0) } while(0)
#define JSB_PRECONDITION2( condition, context, ret_value, error_msg) do { \
if( ! (condition) ) { \
cocos2d::CCLog("jsb: ERROR in %s: %s\n", __FUNCTION__, error_msg); \
JS_ReportPendingException( context ); \
return ret_value; \
} \
} while(0)
#define JSB_PRECONDITION3( condition, context, ret_value, error_msg) do { \
if( ! (condition) ) { \
cocos2d::CCLog("jsb: ERROR in %s: %s\n", __FUNCTION__, error_msg); \
JS_ReportError( context, error_msg ); \
return ret_value; \
} \
} while(0)
#define JSB_PRECONDITION( condition, error_msg) do { \
if( ! (condition) ) { \
cocos2d::CCLog("jsb: ERROR in %s: %s\n", __FUNCTION__, error_msg); \
return JS_FALSE; \
} \
} while(0)
#endif #endif
@ -140,5 +134,25 @@ return JS_FALSE; \
#define JSB_INCLUDE_COCOSDENSHION 1 #define JSB_INCLUDE_COCOSDENSHION 1
#endif // JSB_INCLUDE_COCOSDENSHION #endif // JSB_INCLUDE_COCOSDENSHION
/** @def JSB_ENABLE_DEBUGGER
Set this to 1 to enable the debugger
*/
#ifndef JSB_ENABLE_DEBUGGER
#define JSB_ENABLE_DEBUGGER 0
#endif // JSB_ENABLE_DEBUGGER
#if JSB_ENABLE_DEBUGGER
#define JSB_ENSURE_AUTOCOMPARTMENT(cx, obj) \
JSAutoCompartment ac(cx, obj)
#else
#define JSB_ENSURE_AUTOCOMPARTMENT(cx, obj)
#endif
/** @def JSB_INCLUDE_SYSTEM
Whether or not it should include bindings for system components like LocalStorage
*/
#ifndef JSB_INCLUDE_SYSTEM
#define JSB_INCLUDE_SYSTEM 1
#endif // JSB_INCLUDE_SYSTEM
#endif // __JS_BINDINGS_CONFIG_H #endif // __JS_BINDINGS_CONFIG_H

View File

@ -28,7 +28,7 @@ JSBool jsval_to_opaque( JSContext *cx, jsval vp, void **r)
#else #else
assert( sizeof(int)==4); assert( sizeof(int)==4);
int32_t ret; int32_t ret;
if( ! JS_ValueToInt32(cx, vp, &ret ) ) if( ! jsval_to_int32(cx, vp, &ret ) )
return JS_FALSE; return JS_FALSE;
#endif #endif
*r = (void*)ret; *r = (void*)ret;
@ -43,7 +43,7 @@ JSBool jsval_to_int( JSContext *cx, jsval vp, int *ret )
long *tmp = (long*)ret; long *tmp = (long*)ret;
*tmp = 0; *tmp = 0;
#endif #endif
return JS_ValueToInt32(cx, vp, (int32_t*)ret); return jsval_to_int32(cx, vp, (int32_t*)ret);
} }
// XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???) // XXX: sizeof(long) == 8 in 64 bits on OS X... apparently on Windows it is 32 bits (???)
@ -130,7 +130,7 @@ JSBool jsval_to_c_class( JSContext *cx, jsval vp, void **out_native, struct jsb_
{ {
JSObject *jsobj; JSObject *jsobj;
JSBool ok = JS_ValueToObject(cx, vp, &jsobj); JSBool ok = JS_ValueToObject(cx, vp, &jsobj);
JSB_PRECONDITION3(ok, cx, JS_FALSE, "Error converting jsval to object"); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error converting jsval to object");
struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsobj); struct jsb_c_proxy_s *proxy = jsb_get_c_proxy_for_jsobject(jsobj);
*out_native = proxy->handle; *out_native = proxy->handle;
@ -147,7 +147,7 @@ JSBool jsval_to_uint( JSContext *cx, jsval vp, unsigned int *ret )
long *tmp = (long*)ret; long *tmp = (long*)ret;
*tmp = 0; *tmp = 0;
#endif #endif
return JS_ValueToInt32(cx, vp, (int32_t*)ret); return jsval_to_int32(cx, vp, (int32_t*)ret);
} }
jsval int_to_jsval( JSContext *cx, int number ) jsval int_to_jsval( JSContext *cx, int number )