Merge pull request #598 from pandamicro/develop

Fix crash caused by some action create functions not referencing sub action
This commit is contained in:
pandamicro
2017-04-24 12:12:12 +08:00
committed by GitHub
4 changed files with 83 additions and 120 deletions
@@ -346,82 +346,6 @@ bool js_cocos2dx_CCMenu_create(JSContext *cx, uint32_t argc, jsval *vp)
return false;
}
bool js_cocos2dx_CCSequence_create(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (argc > 0) {
Vector<FiniteTimeAction*> array;
JS::RootedObject actions(cx, args.get(0).toObjectOrNull());
if (argc == 1 && JS_IsArrayObject(cx, actions)) {
bool ok = true;
ok &= jsval_to_ccvector(cx, args.get(0), &array);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
} else {
uint32_t i = 0;
while (i < argc) {
js_proxy_t *proxy;
JS::RootedObject tmpObj(cx, args.get(i).toObjectOrNull());
proxy = jsb_get_js_proxy(tmpObj);
cocos2d::FiniteTimeAction *item = (cocos2d::FiniteTimeAction*)(proxy ? proxy->ptr : nullptr);
TEST_NATIVE_OBJECT(cx, item)
array.pushBack(item);
i++;
}
}
auto ret = new (std::nothrow) cocos2d::Sequence;
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Sequence>(ret);
// link the native object with the javascript object
JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, ret, typeClass, "cocos2d::Sequence"));
auto ok = ret->init(array);
if (ok)
{
args.rval().set(OBJECT_TO_JSVAL(jsobj));
return true;
}
}
JS_ReportError(cx, "wrong number of arguments");
return false;
}
bool js_cocos2dx_CCSpawn_create(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (argc > 0) {
Vector<FiniteTimeAction*> array;
JS::RootedObject actions(cx, args.get(0).toObjectOrNull());
if (argc == 1 && JS_IsArrayObject(cx, actions)) {
bool ok = true;
ok &= jsval_to_ccvector(cx, args.get(0), &array);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
} else {
uint32_t i = 0;
while (i < argc) {
js_proxy_t *proxy;
JS::RootedObject tmpObj(cx, args[i].toObjectOrNull());
proxy = jsb_get_js_proxy(tmpObj);
cocos2d::FiniteTimeAction *item = (cocos2d::FiniteTimeAction*)(proxy ? proxy->ptr : nullptr);
TEST_NATIVE_OBJECT(cx, item)
array.pushBack(item);
i++;
}
}
auto ret = new (std::nothrow) cocos2d::Spawn;
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Spawn>(ret);
// link the native object with the javascript object
JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, ret, typeClass, "cocos2d::Spawn"));
auto ok = ret->init(array);
if (ok)
{
args.rval().set(OBJECT_TO_JSVAL(jsobj));
return true;
}
}
JS_ReportError(cx, "wrong number of arguments");
return false;
}
// TODO: This function is deprecated. The new API is "new MenuItemToggle" instead of "MenuItemToggle.create"
// There are not js tests for this function. Impossible to know weather it works Ok.
bool js_cocos2dx_CCMenuItemToggle_create(JSContext *cx, uint32_t argc, jsval *vp)
@@ -5596,12 +5520,6 @@ void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject global)
JS_GetProperty(cx, ccObj, "MenuItemToggle", &tmpVal);
tmpObj = tmpVal.toObjectOrNull();
JS_DefineFunction(cx, tmpObj, "_create", js_cocos2dx_CCMenuItemToggle_create, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_GetProperty(cx, ccObj, "Sequence", &tmpVal);
tmpObj = tmpVal.toObjectOrNull();
JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCSequence_create, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_GetProperty(cx, ccObj, "Spawn", &tmpVal);
tmpObj = tmpVal.toObjectOrNull();
JS_DefineFunction(cx, tmpObj, "create", js_cocos2dx_CCSpawn_create, 0, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj.set(jsb_cocos2d_Scene_prototype);
JS_DefineFunction(cx, tmpObj, "init", js_cocos2dx_CCScene_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE);
@@ -752,8 +752,6 @@ for (var a in easeActions) {
// Action2d
cc.action = cc.Action.create;
cc.speed = cc.Speed.create;
cc.follow = cc.Follow.create;
cc.cardinalSplineTo = cc.CardinalSplineTo.create;
cc.cardinalSplineBy = cc.CardinalSplineBy.create;
cc.catmullRomTo = cc.CatmullRomTo.create;
@@ -764,21 +762,12 @@ cc.toggleVisibility = cc.ToggleVisibility.create;
cc.removeSelf = cc.RemoveSelf.create;
cc.flipX = cc.FlipX.create;
cc.flipY = cc.FlipY.create;
// cc.place = cc.Place.create;
cc.callFunc = cc.CallFunc.create;
cc.actionInterval = cc.ActionInterval.create;
cc.sequence = cc.Sequence.create;
cc.repeat = cc.Repeat.create;
cc.repeatForever = cc.RepeatForever.create;
cc.spawn = cc.Spawn.create;
cc.rotateTo = cc.RotateTo.create;
cc.rotateBy = cc.RotateBy.create;
//cc.moveBy = cc.MoveBy.create;
//cc.moveTo = cc.MoveTo.create;
cc.skewTo = cc.SkewTo.create;
cc.skewBy = cc.SkewBy.create;
//cc.jumpBy = cc.JumpBy.create;
//cc.jumpTo = cc.JumpTo.create;
cc.bezierBy = cc.BezierBy.create;
cc.bezierTo = cc.BezierTo.create;
cc.scaleTo = cc.ScaleTo.create;
@@ -791,7 +780,6 @@ cc.tintTo = cc.TintTo.create;
cc.tintBy = cc.TintBy.create;
cc.delayTime = cc.DelayTime.create;
cc.reverseTime = cc.ReverseTime.create;
cc.targetedAction = cc.TargetedAction.create;
cc.Place._create = cc.Place.create;
cc.place = cc.Place.create = function(posOrX, y){
@@ -905,7 +893,6 @@ cc.Speed.prototype.getSpeed = cc.ActionInterval.prototype.getSpeed = function()
//
// Node API
//
cc.Node.prototype.setUserData = function (data) {
this.userData = data;
};
@@ -197,15 +197,21 @@ _p._ctor = function(tmxFile, resourcePath){
/************************ Actions *************************/
cc.Speed.prototype._ctor = function(action, speed) {
cc.Speed.prototype._ctor = function (action, speed) {
speed !== undefined && this.initWithAction(action, speed);
};
cc.speed = cc.Speed.create = function (action, speed) {
return new cc.Speed(action, speed);
};
cc.Follow.prototype._ctor = function (followedNode, rect) {
if(followedNode)
if (followedNode)
rect ? this.initWithTarget(followedNode, rect)
: this.initWithTarget(followedNode);
};
cc.follow = cc.Follow.create = function (followedNode, rect) {
return new cc.Follow(followedNode, rect);
};
cc.CardinalSplineTo.prototype._ctor = cc.CardinalSplineBy.prototype._ctor = function(duration, points, tension) {
tension !== undefined && this.initWithDuration(duration, points, tension);
@@ -287,45 +293,89 @@ cc.ActionInterval.prototype._ctor = function(d) {
d !== undefined && this.initWithDuration(d);
};
cc.Sequence.prototype._ctor = function(tempArray) {
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
var last = paramArray.length - 1;
if ((last >= 0) && (paramArray[last] == null))
cc.Sequence.prototype._ctor = function(...args) {
var actions = (args[0] instanceof Array) ? args[0] : args;
var last = actions.length - 1;
if ((last >= 0) && (actions[last] == null))
cc.log('parameters should not be ending with null in Javascript');
if (last >= 0) {
var prev = paramArray[0];
if (last >= 1) {
var prev = actions[0];
for (var i = 1; i < last; i++) {
if (paramArray[i]) {
prev = cc.Sequence.create(prev, paramArray[i]);
if (actions[i]) {
prev = new cc.Sequence(prev, actions[i]);
}
}
this.initWithTwoActions(prev, paramArray[last]);
this.initWithTwoActions(prev, actions[last]);
}
};
cc.sequence = cc.Sequence.create = function (...args) {
var actions = (args[0] instanceof Array) ? args[0] : args;
var last = actions.length - 1;
if ((last >= 0) && (actions[last] == null))
cc.log('parameters should not be ending with null in Javascript');
if (last >= 1) {
var prev = actions[0];
for (var i = 1; i < last; i++) {
if (actions[i]) {
prev = new cc.Sequence(prev, actions[i]);
}
}
return new cc.Sequence(prev, actions[last]);
}
else {
return null;
}
};
cc.Repeat.prototype._ctor = function(action, times) {
cc.Repeat.prototype._ctor = function (action, times) {
times !== undefined && this.initWithAction(action, times);
};
cc.RepeatForever.prototype._ctor = function(action) {
action !== undefined && this.initWithAction(action);
cc.repeat = cc.Repeat.create = function (action, times) {
return new cc.Repeat(action, times);
};
cc.Spawn.prototype._ctor = function(tempArray) {
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
var last = paramArray.length - 1;
if ((last >= 0) && (paramArray[last] == null))
cc.RepeatForever.prototype._ctor = function (action) {
action !== undefined && this.initWithAction(action);
};
cc.repeatForever = cc.RepeatForever.create = function (action) {
return new cc.RepeatForever(action);
};
cc.Spawn.prototype._ctor = function (...args) {
var actions = (args[0] instanceof Array) ? args[0] : args;
var last = actions.length - 1;
if ((last >= 0) && (actions[last] == null))
cc.log('parameters should not be ending with null in Javascript');
if (last >= 0) {
var prev = paramArray[0];
if (last >= 1) {
var prev = actions[0];
for (var i = 1; i < last; i++) {
if (paramArray[i]) {
prev = cc.Spawn.create(prev, paramArray[i]);
if (actions[i]) {
prev = new cc.Spawn(prev, actions[i]);
}
}
this.initWithTwoActions(prev, paramArray[last]);
this.initWithTwoActions(prev, actions[last]);
}
};
cc.spawn = cc.Spawn.create = function (...args) {
var actions = (args[0] instanceof Array) ? args[0] : args;
var last = actions.length - 1;
if ((last >= 0) && (actions[last] == null))
cc.log('parameters should not be ending with null in Javascript');
if (last >= 1) {
var prev = actions[0];
for (var i = 1; i < last; i++) {
if (actions[i]) {
prev = new cc.Spawn(prev, actions[i]);
}
}
return new cc.Spawn(prev, actions[last]);
}
else {
return null;
}
};
@@ -405,9 +455,12 @@ cc.ReverseTime.prototype._ctor = function(action) {
action && this.initWithAction(action);
};*/
cc.TargetedAction.prototype._ctor = function(target, action) {
cc.TargetedAction.prototype._ctor = function (target, action) {
action && this.initWithTarget(target, action);
};
cc.targetedAction = cc.TargetedAction.create = function (target, action) {
return new cc.TargetedAction(target, action);
};
/************************ Nodes *************************/
+5
View File
@@ -84,6 +84,11 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat
Image::[initWithString initWithImageData getData$ getMipmaps initWithRawData],
Sequence::[create],
Spawn::[create],
Speed::[create],
Follow::[create],
Repeat::[create],
RepeatForever::[create],
TargetedAction::[create],
RotateTo::[calculateAngles],
GLProgram::[getProgram setUniformLocationWith(1|2|3|4)fv setUniformLocationWith(2|3|4)iv setUniformLocationWithMatrix(2|3|4)fv],
GLProgramState::[setUniformVec4 setVertexAttribPointer],