mirror of https://github.com/axmolengine/axmol.git
issue #1549: Added "ccdictionary_to_jsval" function, now TMXOrthoObjectsTest and TMXIsoObjectsTest don't crash.
This commit is contained in:
parent
26af535521
commit
449c719d96
|
@ -1062,8 +1062,16 @@ jsval ccarray_to_jsval(JSContext* cx, CCArray *arr) {
|
||||||
CCObject *obj = arr->objectAtIndex(i);
|
CCObject *obj = arr->objectAtIndex(i);
|
||||||
|
|
||||||
CCString *testString = dynamic_cast<cocos2d::CCString *>(obj);
|
CCString *testString = dynamic_cast<cocos2d::CCString *>(obj);
|
||||||
|
CCDictionary* testDict = NULL;
|
||||||
|
CCArray* testArray = NULL;
|
||||||
|
// XXX: Only supports string, since all data read from plist files will be stored as string in cocos2d-x
|
||||||
|
// Do we need to convert string to js base type ?
|
||||||
if(testString) {
|
if(testString) {
|
||||||
arrElement = c_string_to_jsval(cx, testString->getCString());
|
arrElement = c_string_to_jsval(cx, testString->getCString());
|
||||||
|
} else if (testDict = dynamic_cast<cocos2d::CCDictionary*>(obj)) {
|
||||||
|
arrElement = ccdictionary_to_jsval(cx, testDict);
|
||||||
|
} else if (testArray = dynamic_cast<cocos2d::CCArray*>(obj)) {
|
||||||
|
arrElement = ccarray_to_jsval(cx, testArray);
|
||||||
} else {
|
} else {
|
||||||
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCObject>(cx, obj);
|
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCObject>(cx, obj);
|
||||||
arrElement = OBJECT_TO_JSVAL(proxy->obj);
|
arrElement = OBJECT_TO_JSVAL(proxy->obj);
|
||||||
|
@ -1076,6 +1084,40 @@ jsval ccarray_to_jsval(JSContext* cx, CCArray *arr) {
|
||||||
return OBJECT_TO_JSVAL(jsretArr);
|
return OBJECT_TO_JSVAL(jsretArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsval ccdictionary_to_jsval(JSContext* cx, CCDictionary* dict)
|
||||||
|
{
|
||||||
|
JSObject* jsRet = JS_NewObject(cx, NULL, NULL, NULL);
|
||||||
|
CCDictElement* pElement = NULL;
|
||||||
|
CCDICT_FOREACH(dict, pElement)
|
||||||
|
{
|
||||||
|
jsval dictElement;
|
||||||
|
CCString* obj = dynamic_cast<CCString*>(pElement->getObject());
|
||||||
|
|
||||||
|
CCString *testString = dynamic_cast<cocos2d::CCString *>(obj);
|
||||||
|
CCDictionary* testDict = NULL;
|
||||||
|
CCArray* testArray = NULL;
|
||||||
|
// XXX: Only supports string, since all data read from plist files will be stored as string in cocos2d-x
|
||||||
|
// Do we need to convert string to js base type ?
|
||||||
|
if(testString) {
|
||||||
|
dictElement = c_string_to_jsval(cx, testString->getCString());
|
||||||
|
} else if (testDict = dynamic_cast<cocos2d::CCDictionary*>(obj)) {
|
||||||
|
dictElement = ccdictionary_to_jsval(cx, testDict);
|
||||||
|
} else if (testArray = dynamic_cast<cocos2d::CCArray*>(obj)) {
|
||||||
|
dictElement = ccarray_to_jsval(cx, testArray);
|
||||||
|
} else {
|
||||||
|
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCObject>(cx, obj);
|
||||||
|
dictElement = OBJECT_TO_JSVAL(proxy->obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* key = pElement->getStrKey();
|
||||||
|
if (key && strlen(key) > 0)
|
||||||
|
{
|
||||||
|
JS_SetProperty(cx, jsRet, key, &dictElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OBJECT_TO_JSVAL(jsRet);
|
||||||
|
}
|
||||||
|
|
||||||
jsval long_long_to_jsval(JSContext* cx, long long v) {
|
jsval long_long_to_jsval(JSContext* cx, long long v) {
|
||||||
JSObject *tmp = JS_NewUint32Array(cx, 2);
|
JSObject *tmp = JS_NewUint32Array(cx, 2);
|
||||||
uint32_t *data = (uint32_t *)JS_GetArrayBufferViewData(tmp, cx);
|
uint32_t *data = (uint32_t *)JS_GetArrayBufferViewData(tmp, cx);
|
||||||
|
|
|
@ -189,6 +189,7 @@ ccColor3B jsval_to_cccolor3b(JSContext *cx, jsval v);
|
||||||
JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, CCPoint **points, int *numPoints);
|
JSBool jsval_to_ccarray_of_CCPoint(JSContext* cx, jsval v, CCPoint **points, int *numPoints);
|
||||||
CCArray* jsval_to_ccarray(JSContext* cx, jsval v);
|
CCArray* jsval_to_ccarray(JSContext* cx, jsval v);
|
||||||
jsval ccarray_to_jsval(JSContext* cx, CCArray *arr);
|
jsval ccarray_to_jsval(JSContext* cx, CCArray *arr);
|
||||||
|
jsval ccdictionary_to_jsval(JSContext* cx, CCDictionary* dict);
|
||||||
// from native
|
// from native
|
||||||
jsval long_long_to_jsval(JSContext* cx, long long v);
|
jsval long_long_to_jsval(JSContext* cx, long long v);
|
||||||
jsval std_string_to_jsval(JSContext* cx, std::string& v);
|
jsval std_string_to_jsval(JSContext* cx, std::string& v);
|
||||||
|
|
Loading…
Reference in New Issue