From f40b2a00bc1e7c78b9ba495fe5553e766b1c4759 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 26 Jun 2017 12:01:55 +0800 Subject: [PATCH] Strict assert for sequence construction --- DebugInfos.js | 2 ++ cocos2d/actions/CCActionInterval.js | 16 +++++++++ jsb/jsb-action.js | 50 +++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/DebugInfos.js b/DebugInfos.js index 889d3c36ac..5c05246271 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -20,6 +20,8 @@ if (CC_DEV) { "1016": "cc.RotateTo.reverse(): it should be overridden in subclass.", //RotateTo.reverse "1017": "cc.GridAction.getGrid(): it should be overridden in subclass.", //ActionGrid.getGrid "1018": "Grid size must be (1,1)", //ActionGrid3D.initWithSize + "1019": "Failed to construct, Sequence construction needs two or more actions", //ActionInterval.sequence + "1020": "Failed to construct, Spawn construction needs two or more actions", //ActionInterval.spawn //configuration: 1100 "1100": "Expected 'data' dict, but not found. Config file: %s", //loadConfigFile "1101": "Please load the resource first : %s", //loadConfigFile_2 diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index 21ece7466f..531a2f6dde 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -313,6 +313,10 @@ cc.Sequence = cc.ActionInterval.extend({ this._actions = []; var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + if (paramArray.length === 1) { + cc.errorID(1019); + return; + } var last = paramArray.length - 1; if ((last >= 0) && (paramArray[last] == null)) cc.logID(1015); @@ -444,6 +448,10 @@ cc.Sequence = cc.ActionInterval.extend({ // todo: It should be use new cc.sequence = function (/*Multiple Arguments*/tempArray) { var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + if (paramArray.length === 1) { + cc.errorID(1019); + return null; + } var last = paramArray.length - 1; if ((last >= 0) && (paramArray[last] == null)) cc.logID(1015); @@ -731,6 +739,10 @@ cc.Spawn = cc.ActionInterval.extend({ this._two = null; var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + if (paramArray.length === 1) { + cc.errorID(1020); + return; + } var last = paramArray.length - 1; if ((last >= 0) && (paramArray[last] == null)) cc.logID(1015); @@ -825,6 +837,10 @@ cc.Spawn = cc.ActionInterval.extend({ */ cc.spawn = function (/*Multiple Arguments*/tempArray) { var paramArray = (tempArray instanceof Array) ? tempArray : arguments; + if (paramArray.length === 1) { + cc.errorID(1020); + return null; + } if ((paramArray.length > 0) && (paramArray[paramArray.length - 1] == null)) cc.logID(1015); diff --git a/jsb/jsb-action.js b/jsb/jsb-action.js index b79985b470..c272a4d874 100644 --- a/jsb/jsb-action.js +++ b/jsb/jsb-action.js @@ -53,8 +53,6 @@ var actionArr = [ 'Place', 'CallFunc', 'DelayTime', - 'Sequence', - 'Spawn', 'Speed', 'Repeat', 'RepeatForever', @@ -117,6 +115,54 @@ if (!ENABLE_GC_FOR_NATIVE_OBJECTS) { } } +cc.Sequence.prototype._ctor = function (...args) { + var paramArray = (args[0] instanceof Array) ? args[0] : args; + if (paramArray.length === 1) { + cc.errorID(1019); + return; + } + var last = paramArray.length - 1; + if ((last >= 0) && (paramArray[last] == null)) + cc.logID(1015); + + if (last >= 0) { + this.init(paramArray); + } + + if (!ENABLE_GC_FOR_NATIVE_OBJECTS) { + this.retain(); + this._retained = true; + } +}; + +cc.sequence = function (...args) { + var paramArray = (args[0] instanceof Array) ? args[0] : args; + return new cc.Sequence(paramArray); +} + +cc.Spawn.prototype._ctor = function (...args) { + var paramArray = (args[0] instanceof Array) ? args[0] : args; + if (paramArray.length === 1) + cc.errorID(1020); + var last = paramArray.length - 1; + if ((last >= 0) && (paramArray[last] == null)) + cc.logID(1015); + + if (last >= 0) { + this.init(paramArray); + } + + if (!ENABLE_GC_FOR_NATIVE_OBJECTS) { + this.retain(); + this._retained = true; + } +}; + +cc.spawn = function (...args) { + var paramArray = (args[0] instanceof Array) ? args[0] : args; + return new cc.Spawn(paramArray); +} + cc.targetedAction = function (target, action) { return new cc.TargetedAction(target, action); };