From fa6287c21c8a0559eb959bc6d0dcc818e0b804a8 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 26 Sep 2017 22:44:31 +0800 Subject: [PATCH 01/47] fix texture url on native --- jsb/jsb-loader.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jsb/jsb-loader.js b/jsb/jsb-loader.js index 0df24411f4..d380758abc 100644 --- a/jsb/jsb-loader.js +++ b/jsb/jsb-loader.js @@ -82,6 +82,7 @@ function loadImage (item, callback) { else if (url.match(jsb.urlRegExp)) { jsb.loadRemoteImg(url, function(succeed, tex) { if (succeed) { + tex.url = url; callback && callback(null, tex); } else { @@ -92,6 +93,7 @@ function loadImage (item, callback) { else { var addImageCallback = function (tex) { if (tex instanceof cc.Texture2D) { + tex.url = url; callback && callback(null, tex); } else { From f3cddb11cbcf313052ff3ef4cc3676b75bf42d49 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 27 Sep 2017 13:46:13 +0800 Subject: [PATCH 02/47] update SystemEvent.EventType code --- cocos2d/core/event-manager/CCSystemEvent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/event-manager/CCSystemEvent.js b/cocos2d/core/event-manager/CCSystemEvent.js index 98c12f1e0b..4f00ba1218 100644 --- a/cocos2d/core/event-manager/CCSystemEvent.js +++ b/cocos2d/core/event-manager/CCSystemEvent.js @@ -28,7 +28,7 @@ var EventTarget = require('../event/event-target'); /** * !#en The event type supported by SystemEvent * !#zh SystemEvent 支持的事件类型 - * @enum SystemEvent.EventType + * @class SystemEvent.EventType * @static * @namespace SystemEvent */ From 899211ed186e253cc1f906baf530c15022255085 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 28 Sep 2017 17:23:44 +0800 Subject: [PATCH 03/47] fix memory leak of texture --- cocos2d/core/load-pipeline/CCLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index 2451757eda..38e0a2d75a 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -761,7 +761,7 @@ proto.release = function (asset) { } } else if (asset instanceof cc.Texture2D) { - cc.textureCache.removeTextureForKey(item.url); + cc.textureCache.removeTextureForKey(item.rawUrl || item.url); } } } From 6e4a674a45da1cf124457b8b70b0e770818ebe8c Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 28 Sep 2017 17:26:26 +0800 Subject: [PATCH 04/47] add remove toggleItems tips for fireball/issues/6416 --- cocos2d/core/components/CCToggleGroup.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCToggleGroup.js b/cocos2d/core/components/CCToggleGroup.js index bcf0c96edf..12669dbfcd 100644 --- a/cocos2d/core/components/CCToggleGroup.js +++ b/cocos2d/core/components/CCToggleGroup.js @@ -61,7 +61,8 @@ var ToggleGroup = cc.Class({ * @property {Array} toggleItems */ toggleItems: { - get: function (){ + get: function () { + cc.warn("The ToggleGroup.toggleItems api will be removed in v2.0, please obtain toggles in other ways. \uD83D\uDE30"); return this._toggleItems; } } From ffde44e863e8e80f8c2f62be2c9b918fa2625deb Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 28 Sep 2017 18:08:57 +0800 Subject: [PATCH 05/47] update remove toggleItems tips for fireball/issues/6416 --- DebugInfos.js | 4 +++- cocos2d/core/components/CCToggleGroup.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DebugInfos.js b/DebugInfos.js index 2efd3fe0c0..e2f02ab944 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -617,7 +617,9 @@ if (CC_DEBUG) { "8300": "Should only one camera exists, please check your project.", //cc.Camera.enabled "8301": "Camera does not support Canvas Mode.", //cc.Camera.enabled // AudioEngine: 8400 - "8400": "Wrong type arguments, 'filePath' must be a String." // cc.audioEngine.play + "8400": "Wrong type arguments, 'filePath' must be a String.", // cc.audioEngine.play + // ToggleGroup: 8500 + "8500": "The ToggleGroup.toggleItems api will be removed in v2.0, please obtain toggles in other ways. \uD83D\uDE30", }; cc._LogInfos = logs; } diff --git a/cocos2d/core/components/CCToggleGroup.js b/cocos2d/core/components/CCToggleGroup.js index 12669dbfcd..68b63a507d 100644 --- a/cocos2d/core/components/CCToggleGroup.js +++ b/cocos2d/core/components/CCToggleGroup.js @@ -62,7 +62,7 @@ var ToggleGroup = cc.Class({ */ toggleItems: { get: function () { - cc.warn("The ToggleGroup.toggleItems api will be removed in v2.0, please obtain toggles in other ways. \uD83D\uDE30"); + cc.warnID(8500); return this._toggleItems; } } From bcd93d3d16b7fb4794671e599b70dd136670ece3 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 6 Oct 2017 15:25:34 +0800 Subject: [PATCH 06/47] [JSB] use key to schedule to avoid memory leak in scheduleOnce --- jsb/jsb-etc.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 89ec3f4b43..7ebd6a08d4 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -55,6 +55,7 @@ cc.js.mixin(cc.path, { }); // cc.Scheduler +var _callbackId = 0 | 998 * Math.random(); cc.Scheduler.prototype.schedule = function (callback, target, interval, repeat, delay, paused) { if (delay === undefined || paused === undefined) { paused = !!repeat; @@ -65,7 +66,13 @@ cc.Scheduler.prototype.schedule = function (callback, target, interval, repeat, repeat = isFinite(repeat) ? repeat : cc.macro.REPEAT_FOREVER; } delay = delay || 0; - this.scheduleCallbackForTarget(target, callback, interval, repeat, delay, paused); + var instanceId = target.__instanceId || target.uuid; + cc.assertID(instanceId, 1510); + if (!callback.__callbackId) { + callback.__callbackId = _callbackId++; + } + var key = instanceId + '_' + callback.__callbackId; + this._schedule(target, callback, interval, repeat, delay, paused, key); }; cc.Scheduler.prototype.scheduleUpdate = cc.Scheduler.prototype.scheduleUpdateForTarget; cc.Scheduler.prototype._unschedule = cc.Scheduler.prototype.unschedule; @@ -75,7 +82,10 @@ cc.Scheduler.prototype.unschedule = function (callback, target) { target = callback; callback = tmp; } - this._unschedule(target, callback); + var instanceId = target.__instanceId || target.uuid; + cc.assertID(instanceId && callback.__callbackId, 1510); + var key = instanceId + '_' + callback.__callbackId; + this._unschedule(key, target); }; // Node From 5c27b585fa4d5779ee15538825188f8658a2b640 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 6 Oct 2017 08:59:23 -0500 Subject: [PATCH 07/47] Use 0 instead of random seed for _callbackId --- jsb/jsb-etc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 7ebd6a08d4..5d13357da1 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -55,7 +55,7 @@ cc.js.mixin(cc.path, { }); // cc.Scheduler -var _callbackId = 0 | 998 * Math.random(); +var _callbackId = 0; cc.Scheduler.prototype.schedule = function (callback, target, interval, repeat, delay, paused) { if (delay === undefined || paused === undefined) { paused = !!repeat; From c1ed179bb9b1b144a2ee1a75d1d9797f7d9cb084 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Sat, 7 Oct 2017 18:27:31 +0800 Subject: [PATCH 08/47] fix wrongly determine android build version as Opera --- cocos2d/core/platform/CCSys.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index f52e9bd0db..f9949dcca1 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -589,7 +589,7 @@ else { /* Determine the browser type */ (function(){ var typeReg1 = /mqqbrowser|micromessenger|qq|sogou|qzone|liebao|maxthon|ucbrowser|360 aphone|360browser|baiduboxapp|baidubrowser|maxthon|mxbrowser|miuibrowser/i; - var typeReg2 = /qqbrowser|chrome|safari|firefox|trident|opera|opr|oupeng/i; + var typeReg2 = /qqbrowser|chrome|safari|firefox|trident|opera|opr\/|oupeng/i; var browserTypes = typeReg1.exec(ua); if(!browserTypes) browserTypes = typeReg2.exec(ua); var browserType = browserTypes ? browserTypes[0].toLowerCase() : sys.BROWSER_TYPE_UNKNOWN; @@ -598,14 +598,14 @@ else { else if (browserType === "safari" && isAndroid) browserType = sys.BROWSER_TYPE_ANDROID; else if (browserType === "qq" && ua.match(/android.*applewebkit/i)) - brwoserType = sys.BROWSER_TYPE_ANDROID; + browserType = sys.BROWSER_TYPE_ANDROID; else if (browserType === "trident") browserType = sys.BROWSER_TYPE_IE; else if (browserType === "360 aphone") browserType = sys.BROWSER_TYPE_360; else if (browserType === "mxbrowser") browserType = sys.BROWSER_TYPE_MAXTHON; - else if (browserType === "opr") + else if (browserType === "opr/") browserType = sys.BROWSER_TYPE_OPERA; sys.browserType = browserType; @@ -619,7 +619,7 @@ else { /* Determine the browser version number */ (function(){ var versionReg1 = /(mqqbrowser|micromessenger|qq|sogou|qzone|liebao|maxthon|uc|360 aphone|360|baiduboxapp|baidu|maxthon|mxbrowser|miui)(mobile)?(browser)?\/?([\d.]+)/i; - var versionReg2 = /(qqbrowser|chrome|safari|firefox|trident|opera|opr|oupeng)(mobile)?(browser)?\/?([\d.]+)/i; + var versionReg2 = /(qqbrowser|chrome|safari|firefox|trident|opera|opr\/|oupeng)(mobile)?(browser)?\/?([\d.]+)/i; var tmp = ua.match(versionReg1); if(!tmp) tmp = ua.match(versionReg2); sys.browserVersion = tmp ? tmp[4] : ""; From 928964bd70d9454303c88f21d904ea188588714f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 9 Oct 2017 15:26:01 +0800 Subject: [PATCH 09/47] Fix 0 id causing assert failure issue --- jsb/jsb-etc.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 7ebd6a08d4..1bbf2754d0 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -67,7 +67,7 @@ cc.Scheduler.prototype.schedule = function (callback, target, interval, repeat, } delay = delay || 0; var instanceId = target.__instanceId || target.uuid; - cc.assertID(instanceId, 1510); + cc.assertID(!isNaN(instanceId), 1510); if (!callback.__callbackId) { callback.__callbackId = _callbackId++; } @@ -83,7 +83,7 @@ cc.Scheduler.prototype.unschedule = function (callback, target) { callback = tmp; } var instanceId = target.__instanceId || target.uuid; - cc.assertID(instanceId && callback.__callbackId, 1510); + cc.assertID(!isNaN(instanceId) && !isNaN(callback.__callbackId), 1510); var key = instanceId + '_' + callback.__callbackId; this._unschedule(key, target); }; @@ -100,6 +100,7 @@ cc.view.setOrientation = function () {}; var _windowTimeIntervalId = 0; var _windowTimeFunHash = {}; var WindowTimeFun = function (code) { + this.__instanceId = cc.ClassManager.getNewInstanceId(); this._intervalId = _windowTimeIntervalId++; this._code = code; }; From cb834c99e791dff45d440a99d4316b4d384643f2 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 9 Oct 2017 15:29:59 +0800 Subject: [PATCH 10/47] fixed radial sprite culling --- cocos2d/core/sprites/CCScale9Sprite.js | 29 +++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js index fcc6ddf1f5..c53f49f990 100644 --- a/cocos2d/core/sprites/CCScale9Sprite.js +++ b/cocos2d/core/sprites/CCScale9Sprite.js @@ -753,10 +753,29 @@ var fillQuadGeneratorRadial = { } sprite._vertCount = count; - cornerId[0] = 0; // bl - cornerId[1] = 2; // br - cornerId[2] = 4; // tl - cornerId[3] = 6; // tr + var minx = Infinity, miny = Infinity, maxx = -Infinity, maxy = -Infinity; + var x, y; + for (var i = 0, l = offset; i < l; i+=2) { + x = vertices[i]; + y = vertices[i+1]; + if (x <= minx) { + minx = x; + cornerId[0] = i; + } + else if (x >= maxx) { + maxx = x; + cornerId[1] = i; + } + + if (y <= miny) { + miny = y; + cornerId[2] = i; + } + else if (y >= maxy) { + maxy = y; + cornerId[3] = i; + } + } }, _generateTriangle: function(wt, offset, vert0, vert1, vert2) { @@ -1423,7 +1442,7 @@ cc.Scale9Sprite = _ccsg.Node.extend({ // x2, y2 rightBottom // x3, y3 leftTop // x4, y4 rightTop - var vert = this._isTriangle ? this._rawVerts : this._vertices, + var vert = this._vertices, x0 = vert[cornerId[0]], x1 = vert[cornerId[1]], x2 = vert[cornerId[2]], x3 = vert[cornerId[3]], y0 = vert[cornerId[0] + 1], y1 = vert[cornerId[1] + 1], y2 = vert[cornerId[2] + 1], y3 = vert[cornerId[3] + 1]; if (((x0-vl) & (x1-vl) & (x2-vl) & (x3-vl)) >> 31 || // All outside left From 2bb573b3dbc3b762fc122692db645f6312504e7d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 9 Oct 2017 15:48:00 +0800 Subject: [PATCH 11/47] Use undefined for id validation --- jsb/jsb-etc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 692ede1665..225d56346e 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -67,7 +67,7 @@ cc.Scheduler.prototype.schedule = function (callback, target, interval, repeat, } delay = delay || 0; var instanceId = target.__instanceId || target.uuid; - cc.assertID(!isNaN(instanceId), 1510); + cc.assertID(instanceId !== undefined, 1510); if (!callback.__callbackId) { callback.__callbackId = _callbackId++; } @@ -83,7 +83,7 @@ cc.Scheduler.prototype.unschedule = function (callback, target) { callback = tmp; } var instanceId = target.__instanceId || target.uuid; - cc.assertID(!isNaN(instanceId) && !isNaN(callback.__callbackId), 1510); + cc.assertID(instanceId !== undefined && callback.__callbackId !== undefined, 1510); var key = instanceId + '_' + callback.__callbackId; this._unschedule(key, target); }; From 806c0ec2d469dbb8379f6cc04f6aea307b9a8a6c Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 10 Oct 2017 01:08:04 +0800 Subject: [PATCH 12/47] event listener should not add more than once when using once --- cocos2d/ToMerge/qunit/test-event-system.js | 37 --------------- cocos2d/core/event/event-target.js | 38 +++++++++------- test/qunit/unit-es5/test-event-system.js | 52 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 53 deletions(-) create mode 100644 test/qunit/unit-es5/test-event-system.js diff --git a/cocos2d/ToMerge/qunit/test-event-system.js b/cocos2d/ToMerge/qunit/test-event-system.js index aa1dd99a41..d81bbe4fe0 100644 --- a/cocos2d/ToMerge/qunit/test-event-system.js +++ b/cocos2d/ToMerge/qunit/test-event-system.js @@ -48,43 +48,6 @@ test('emit', function () { cb1.once('callback1 should be invoked by fire event'); }); -test('once', function () { - var target = new cc.EventTarget(); - var fireEvent = new cc.Event('fire'); - var cb1 = new Callback(); - - // once - target.once('fire', cb1.enable()); - target.dispatchEvent(fireEvent); - cb1.once('should be invoked if registered by once') - .disable('should only invoke once 1'); - target.dispatchEvent(fireEvent); - - // once + on - var cb2 = new Callback().enable(); - - target.once('fire', cb1.enable()); - target.on('fire', cb2); - - target.dispatchEvent(fireEvent); - cb1.once('should be invoked if registered by once and before other callback'); - cb2.once('should still be invoked if previous event was removed'); - - cb1.disable('should only invoke once 2'); - target.dispatchEvent(fireEvent); - cb2.once('should not remove common event'); - - // on + once - - target.once('fire', cb1.enable()); - target.dispatchEvent(fireEvent); - cb2.once(); - cb1.once('should be invoked if registered by once and after other callback') - .disable('should only invoke once 3'); - target.dispatchEvent(fireEvent); - cb2.once(); -}); - test('test useCapture in on/off', function () { var target = new cc.EventTarget(); var event = new cc.Event('fire'); diff --git a/cocos2d/core/event/event-target.js b/cocos2d/core/event/event-target.js index e3b742882c..9475583110 100644 --- a/cocos2d/core/event/event-target.js +++ b/cocos2d/core/event/event-target.js @@ -162,7 +162,7 @@ proto._addEventFlag = function (type, listeners, useCapture) { cache[type] |= flag; }; -proto._removeEventFlag = function (type, listeners, useCapture) { +proto._purgeEventFlag = function (type, listeners, useCapture) { var cache = this._hasListenerCache; if (!cache || listeners.has(type)) { @@ -175,7 +175,7 @@ proto._removeEventFlag = function (type, listeners, useCapture) { if (cache[type] === 0) { delete cache[type]; } -} +}; proto._resetFlagForTarget = function (target, listeners, useCapture) { var cache = this._hasListenerCache; @@ -206,13 +206,8 @@ proto.hasEventListener = function (type, checkCapture) { var cache = this._hasListenerCache; if (!cache) return false; - var flag = cache[type]; - if (checkCapture && (flag & CAPTURING_FLAG)) - return true; - if (!checkCapture && (flag & BUBBLING_FLAG)) - return true; - - return false; + var flag = checkCapture ? CAPTURING_FLAG : BUBBLING_FLAG; + return (cache[type] & flag) > 0; }; @@ -322,7 +317,7 @@ proto.off = function (type, callback, target, useCapture) { fastRemove(target.__eventTargets, this); } - this._removeEventFlag(type, listeners, useCapture); + this._purgeEventFlag(type, listeners, useCapture); } } @@ -376,12 +371,23 @@ proto.targetOff = function (target) { * }, node); */ proto.once = function (type, callback, target, useCapture) { - var self = this; - var cb = function (event) { - self.off(type, cb, target, useCapture); - callback.call(this, event); - }; - this.on(type, cb, target, useCapture); + var eventType_hasOnceListener = '__ONCE_FLAG:' + type; + var listeners = useCapture ? this._capturingListeners : this._bubblingListeners; + var hasOnceListener = listeners && listeners.has(eventType_hasOnceListener, callback, target); + if (!hasOnceListener) { + var self = this; + var onceWrapper = function (event) { + self.off(type, onceWrapper, target, useCapture); + listeners.remove(eventType_hasOnceListener, callback, target); + callback.call(this, event); + }; + this.on(type, onceWrapper, target, useCapture); + if (!listeners) { + // obtain new created listeners + listeners = useCapture ? this._capturingListeners : this._bubblingListeners; + } + listeners.add(eventType_hasOnceListener, callback, target); + } }; /** diff --git a/test/qunit/unit-es5/test-event-system.js b/test/qunit/unit-es5/test-event-system.js new file mode 100644 index 0000000000..af13041ef2 --- /dev/null +++ b/test/qunit/unit-es5/test-event-system.js @@ -0,0 +1,52 @@ + +module('EventTarget'); + +test('once', function () { + var target = new cc.EventTarget(); + var fireEvent = new cc.Event('fire'); + var cb1 = new Callback(); + + // once + target.once('fire', cb1.enable()); + target.dispatchEvent(fireEvent); + cb1.once('should be invoked if registered by once') + .disable('should only invoke once 1'); + target.dispatchEvent(fireEvent); + + // once + on + var cb2 = new Callback().enable(); + + target.once('fire', cb1.enable()); + target.on('fire', cb2); + + target.dispatchEvent(fireEvent); + cb1.once('should be invoked if registered by once and before other callback'); + cb2.once('should still be invoked if previous event was removed'); + + cb1.disable('should only invoke once 2'); + target.dispatchEvent(fireEvent); + cb2.once('should not remove common event'); + + // on + once + + target.once('fire', cb1.enable()); + target.dispatchEvent(fireEvent); + cb2.once(); + cb1.once('should be invoked if registered by once and after other callback') + .disable('should only invoke once 3'); + target.dispatchEvent(fireEvent); + cb2.once(); +}); + +test('call "once" twice', function () { + var target = new cc.EventTarget(); + var cb1 = new Callback().enable(); + var ctx = {}; + + target.once('fire', cb1, ctx, true); + target.once('fire', cb1, ctx, true); + target.emit('fire'); + cb1.once('should be invoked only once') + .disable('should only invoke once'); + target.emit('fire'); +}); From 5dea89a6272de07410d9d014968965a15df054da Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 10 Oct 2017 09:40:33 +0800 Subject: [PATCH 13/47] small optimization --- cocos2d/core/load-pipeline/binary-downloader.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cocos2d/core/load-pipeline/binary-downloader.js b/cocos2d/core/load-pipeline/binary-downloader.js index 3272675ebf..287e434528 100644 --- a/cocos2d/core/load-pipeline/binary-downloader.js +++ b/cocos2d/core/load-pipeline/binary-downloader.js @@ -71,8 +71,7 @@ if (_IEFilter) { var byteMapping = {}; for (var i = 0; i < 256; i++) { for (var j = 0; j < 256; j++) { - byteMapping[ String.fromCharCode(i + j * 256) ] = - String.fromCharCode(i) + String.fromCharCode(j); + byteMapping[ String.fromCharCode(i + j * 256) ] = String.fromCharCode(i, j); } } var rawBytes = IEBinaryToArray_ByteStr(binary); From fc13234a5cf59c17fd778083a2ed6e241fa88f54 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 10 Oct 2017 16:26:30 +0800 Subject: [PATCH 14/47] update unschedule code jsb-etc.js fix fireball/issues/6432 --- jsb/jsb-etc.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 225d56346e..93dafcce0b 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -82,8 +82,12 @@ cc.Scheduler.prototype.unschedule = function (callback, target) { target = callback; callback = tmp; } + if (callback.__callbackId === undefined) { + return; + } + var instanceId = target.__instanceId || target.uuid; - cc.assertID(instanceId !== undefined && callback.__callbackId !== undefined, 1510); + cc.assertID(instanceId !== undefined, 1510); var key = instanceId + '_' + callback.__callbackId; this._unschedule(key, target); }; From e5d8a288ab4459d74d3eaa29106ef82f5d889ceb Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 10 Oct 2017 18:01:33 +0800 Subject: [PATCH 15/47] Reverts ...args --- jsb/index.js | 4 ++-- jsb/jsb-action.js | 9 ++++++--- jsb/jsb-etc.js | 17 ++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/jsb/index.js b/jsb/index.js index d78c3f8a6b..23d5f91171 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -29,8 +29,8 @@ var originLog = console.log; // overwrite original console.log try { - console.log = function (...args) { - originLog(cc.js.formatStr.apply(null, args)); + console.log = function () { + originLog.call(console, cc.js.formatStr.apply(null, arguments)); }; } catch (e) { diff --git a/jsb/jsb-action.js b/jsb/jsb-action.js index cb550ff937..fe49f619ff 100644 --- a/jsb/jsb-action.js +++ b/jsb/jsb-action.js @@ -295,10 +295,13 @@ cc.ActionManager.prototype.addAction = function (action, target, paused) { function actionMgrFuncReplacer (funcName, targetPos) { var proto = cc.ActionManager.prototype; var oldFunc = proto[funcName]; - proto[funcName] = function (...args) { - for (var i = 0; i < args.length; i++) { + proto[funcName] = function () { + var args = []; + for (var i = 0; i < arguments.length; i++) { if (i === targetPos) - args[i] = getSGTarget(args[i]); + args[i] = getSGTarget(arguments[i]); + else + args[i] = arguments[i]; } if (!args[targetPos]) { return; diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index bed29cb65b..829410c9e2 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -87,14 +87,13 @@ WindowTimeFun.prototype.fun = function () { @param {number} delay @return {number} */ -window.setTimeout = function (code, delay, ...args) { +window.setTimeout = function (code, delay) { var target = new WindowTimeFun(code); - if (args.length > 0) { - target._args = args; - } + if (arguments.length > 2) + target._args = Array.prototype.slice.call(arguments, 2); var original = target.fun; target.fun = function () { - original.call(this); + original.apply(this, arguments); clearTimeout(target._intervalId); }; cc.director.getScheduler().schedule(target.fun, target, delay / 1000, 0, 0, false); @@ -108,11 +107,11 @@ window.setTimeout = function (code, delay, ...args) { @param {number} delay @return {number} */ -window.setInterval = function (code, delay, ...args) { +window.setInterval = function (code, delay) { var target = new WindowTimeFun(code); - if (args.length > 0) { - target._args = args; - } + if (arguments.length > 2) + target._args = Array.prototype.slice.call(arguments, 2); + cc.director.getScheduler().schedule(target.fun, target, delay / 1000, cc.macro.REPEAT_FOREVER, 0, false); _windowTimeFunHash[target._intervalId] = target; return target._intervalId; From cdad460e9d6b4b53811a5a9c3fa000cc7c4bb270 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 11 Oct 2017 09:53:24 +0800 Subject: [PATCH 16/47] fix api doc --- cocos2d/core/components/CCEditBox.js | 1 + cocos2d/core/components/CCSprite.js | 2 +- cocos2d/core/components/CCVideoPlayer.js | 29 ++++++++++++------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index 65f9b779de..18423d9aec 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -644,4 +644,5 @@ cc.EditBox = module.exports = EditBox; * // when you don't need editbox anymore * editbox.node.destroy(); * @method destroy + * @return {Boolean} whether it is the first time the destroy being called */ diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 596123a8f3..7da5d38c33 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -28,7 +28,7 @@ var Base = require('./CCRendererUnderSG'); /** * !#en Enum for sprite type. * !#zh Sprite 类型 - * @enum Sprite.SpriteType + * @enum Sprite.Type */ /** * !#en The simple type. diff --git a/cocos2d/core/components/CCVideoPlayer.js b/cocos2d/core/components/CCVideoPlayer.js index 07dce51579..8c341f5997 100644 --- a/cocos2d/core/components/CCVideoPlayer.js +++ b/cocos2d/core/components/CCVideoPlayer.js @@ -369,6 +369,21 @@ var VideoPlayer = cc.Class({ } return false; } + + /** + * !#en if you don't need the VideoPlayer and it isn't in any running Scene, you should + * call the destroy method on this component or the associated node explicitly. + * Otherwise, the created DOM element won't be removed from web page. + * !#zh + * 如果你不再使用 VideoPlayer,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。 + * 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。 + * @example + * videoplayer.node.parent = null; // or videoplayer.node.removeFromParent(false); + * // when you don't need videoplayer anymore + * videoplayer.node.destroy(); + * @method destroy + * @return {Boolean} whether it is the first time the destroy being called + */ }); cc.VideoPlayer = module.exports = VideoPlayer; @@ -443,17 +458,3 @@ cc.VideoPlayer = module.exports = VideoPlayer; * @param {Event.EventCustom} event * @param {VideoPlayer} event.detail - The VideoPlayer component. */ - -/** - * !#en if you don't need the VideoPlayer and it isn't in any running Scene, you should - * call the destroy method on this component or the associated node explicitly. - * Otherwise, the created DOM element won't be removed from web page. - * !#zh - * 如果你不再使用 VideoPlayer,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。 - * 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。 - * @example - * videoplayer.node.parent = null; // or videoplayer.node.removeFromParent(false); - * // when you don't need videoplayer anymore - * videoplayer.node.destroy(); - * @method destroy - */ From 7cdc0a78f45f349cd284454a0b64195fe94657f4 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 11 Oct 2017 17:19:03 +0800 Subject: [PATCH 17/47] Stop bail out iOS UIWebView for webgl --- cocos2d/core/platform/CCSys.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cocos2d/core/platform/CCSys.js b/cocos2d/core/platform/CCSys.js index f9949dcca1..319b9a35af 100644 --- a/cocos2d/core/platform/CCSys.js +++ b/cocos2d/core/platform/CCSys.js @@ -722,12 +722,6 @@ else { if (cc.create3DContext(document.createElement("CANVAS"))) { _supportWebGL = true; } - if (_supportWebGL && sys.os === sys.OS_IOS && sys.osMainVersion === 9) { - // Not activating WebGL in iOS 9 UIWebView because it may crash when entering background - if (!win.indexedDB) { - _supportWebGL = false; - } - } if (_supportWebGL && sys.os === sys.OS_ANDROID) { var browserVer = parseFloat(sys.browserVersion); switch (sys.browserType) { From 29ec80449c088128eac7df023565e1f8be42c16a Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 11 Oct 2017 21:48:36 -0500 Subject: [PATCH 18/47] fix TiledMap break --- cocos2d/tilemap/CCSGTMXLayer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 44f75d87c4..a84c652ce9 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -130,8 +130,8 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ } var tw = tileset._tileSize.width, th = tileset._tileSize.height, - imageW = tex._contentSize.width, - imageH = tex._contentSize.height, + imageW = tex.width, + imageH = tex.height, spacing = tileset.spacing, margin = tileset.margin, From bb338fe0e062affd590ffb0f43f52cccdb9ce985 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 13 Oct 2017 17:09:47 +0800 Subject: [PATCH 19/47] support native modules --- cocos2d/core/graphics/index.js | 2 +- gulp/tasks/engine.js | 76 +++++++++++++++++++++++++++++++--- gulp/tasks/watch.js | 6 ++- gulpfile.js | 59 ++------------------------ modules.json | 21 ++++++---- 5 files changed, 93 insertions(+), 71 deletions(-) diff --git a/cocos2d/core/graphics/index.js b/cocos2d/core/graphics/index.js index 85b69fd1de..22540071ed 100644 --- a/cocos2d/core/graphics/index.js +++ b/cocos2d/core/graphics/index.js @@ -26,7 +26,7 @@ 'use strict'; var GraphicsNode; -if (!cc.sys.isNative) { +if (!CC_JSB) { GraphicsNode = _ccsg.GraphicsNode = require('./graphics-node'); } else { diff --git a/gulp/tasks/engine.js b/gulp/tasks/engine.js index 39477de6e4..f8f0e9829d 100644 --- a/gulp/tasks/engine.js +++ b/gulp/tasks/engine.js @@ -41,6 +41,62 @@ const Chalk = require('chalk'); const HandleErrors = require('../util/handleErrors'); const Optimizejs = require('gulp-optimize-js'); +var jsbSkipModules = [ + '../../cocos2d/core/CCGame', + '../../cocos2d/core/CCDrawingPrimitives.js', + '../../cocos2d/core/textures/CCTexture2D', + '../../cocos2d/core/sprites/CCSpriteFrame', + '../../cocos2d/core/load-pipeline/audio-downloader', + '../../cocos2d/core/physics/platform/CCPhysicsDebugDraw.js', + '../../cocos2d/core/physics/platform/CCPhysicsUtils.js', + '../../cocos2d/core/physics/platform/CCPhysicsAABBQueryCallback.js', + '../../cocos2d/core/physics/platform/CCPhysicsRayCastCallback.js', + '../../cocos2d/core/physics/platform/CCPhysicsContactListner.js', + '../../cocos2d/core/camera/CCSGCameraNode.js', + '../../cocos2d/core/label/CCSGLabel.js', + '../../cocos2d/core/label/CCSGLabelCanvasRenderCmd.js', + '../../cocos2d/core/label/CCSGLabelWebGLRenderCmd.js', + '../../cocos2d/core/videoplayer/CCSGVideoPlayer.js', + '../../cocos2d/core/webview/CCSGWebView.js', + '../../cocos2d/core/editbox/CCSGEditBox.js', + '../../cocos2d/core/graphics/graphics-node.js', + '../../cocos2d/core/graphics/graphics-webgl-cmd.js', + '../../cocos2d/core/graphics/graphics-canvas-cmd.js', + '../../cocos2d/core/graphics/earcut.js', + '../../cocos2d/core/graphics/helper.js', + '../../cocos2d/audio/CCAudio', + '../../cocos2d/shape-nodes/CCDrawNode.js', + '../../cocos2d/clipping-nodes/CCClippingNode.js', + '../../cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js', + '../../cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js', + '../../cocos2d/particle/CCSGParticleSystem.js', + '../../cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js', + '../../cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js', + '../../cocos2d/tilemap/CCSGTMXTiledMap.js', + '../../cocos2d/tilemap/CCTMXXMLParser.js', + '../../cocos2d/tilemap/CCSGTMXObjectGroup.js', + '../../cocos2d/tilemap/CCSGTMXObject.js', + '../../cocos2d/tilemap/CCSGTMXLayer.js', + '../../cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js', + '../../cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js', + '../../cocos2d/motion-streak/CCSGMotionStreak.js', + '../../cocos2d/motion-streak/CCSGMotionStreakWebGLRenderCmd.js', + '../../cocos2d/render-texture/CCRenderTexture.js', + '../../cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js', + '../../cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js', + '../../extensions/spine/SGSkeleton', + '../../extensions/spine/SGSkeletonAnimation', + '../../extensions/spine/SGSkeletonCanvasRenderCmd', + '../../extensions/spine/SGSkeletonWebGLRenderCmd', + '../../extensions/spine/lib/spine', + '../../extensions/dragonbones/lib/dragonBones', + '../../extensions/dragonbones/CCFactory', + '../../extensions/dragonbones/CCArmatureDisplay', + '../../extensions/dragonbones/CCSlot', + '../../extensions/dragonbones/CCTextureData', + '../../external/box2d/box2d.js', +]; + exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) { var outDir = Path.dirname(outputFile); var outFile = Path.basename(outputFile); @@ -150,14 +206,16 @@ exports.buildPreview = function (sourceFile, outputFile, callback) { .on('end', callback); }; -exports.buildJsbPreview = function (sourceFile, outputFile, jsbSkipModules, callback) { +exports.buildJsbPreview = function (sourceFile, outputFile, excludes, callback) { var FixJavaScriptCore = require('../util/fix-jsb-javascriptcore'); var outFile = Path.basename(outputFile); var outDir = Path.dirname(outputFile); + excludes = excludes.concat(jsbSkipModules); + var bundler = createBundler(sourceFile); - jsbSkipModules.forEach(function (module) { + excludes.forEach(function (module) { bundler.ignore(require.resolve(module)); }); bundler.bundle() @@ -174,14 +232,16 @@ exports.buildJsbPreview = function (sourceFile, outputFile, jsbSkipModules, call .on('end', callback); }; -exports.buildJsb = function (sourceFile, outputFile, jsbSkipModules, callback) { +exports.buildJsb = function (sourceFile, outputFile, excludes, callback) { var FixJavaScriptCore = require('../util/fix-jsb-javascriptcore'); var outFile = Path.basename(outputFile); var outDir = Path.dirname(outputFile); + excludes = excludes.concat(jsbSkipModules); + var bundler = createBundler(sourceFile); - jsbSkipModules.forEach(function (module) { + excludes.forEach(function (module) { bundler.ignore(require.resolve(module)); }); bundler.bundle() @@ -198,14 +258,16 @@ exports.buildJsb = function (sourceFile, outputFile, jsbSkipModules, callback) { .on('end', callback); }; -exports.buildJsbMin = function (sourceFile, outputFile, jsbSkipModules, callback) { +exports.buildJsbMin = function (sourceFile, outputFile, excludes, callback) { var FixJavaScriptCore = require('../util/fix-jsb-javascriptcore'); var outFile = Path.basename(outputFile); var outDir = Path.dirname(outputFile); + excludes = excludes.concat(jsbSkipModules); + var bundler = createBundler(sourceFile); - jsbSkipModules.forEach(function (module) { + excludes.forEach(function (module) { bundler.ignore(require.resolve(module)); }); bundler.bundle() @@ -221,3 +283,5 @@ exports.buildJsbMin = function (sourceFile, outputFile, jsbSkipModules, callback .pipe(Gulp.dest(outDir)) .on('end', callback); }; + +exports.jsbSkipModules = jsbSkipModules; diff --git a/gulp/tasks/watch.js b/gulp/tasks/watch.js index 091bb11d7d..c71fa2d504 100644 --- a/gulp/tasks/watch.js +++ b/gulp/tasks/watch.js @@ -5,6 +5,8 @@ var Fs = require('fs'); var Path = require('path'); var through = require('through'); +var Engine = require('./engine'); + // var source = require('vinyl-source-stream'); // var buffer = require('vinyl-buffer'); // var sourcemaps = require('gulp-sourcemaps'); @@ -91,7 +93,7 @@ exports.preview = function (sourceFile, outputFile) { }); }; -exports.jsbPolyfill = function (sourceFile, outputFile, skipModules) { +exports.jsbPolyfill = function (sourceFile, outputFile) { return watchFile({ entries: sourceFile, dest: outputFile, @@ -101,6 +103,6 @@ exports.jsbPolyfill = function (sourceFile, outputFile, skipModules) { return prefix; }, - skips: skipModules + skips: Engine.jsbSkipModules }); }; \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index fe7c7150b5..7667e7ea61 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -52,73 +52,22 @@ gulp.task('build-html5-preview', function (done) { gulp.task('build-html5', ['build-html5-preview', 'build-html5-dev', 'build-html5-min']); -var jsbSkipModules = [ - '../../cocos2d/core/CCGame', - '../../cocos2d/core/CCDrawingPrimitives.js', - '../../cocos2d/core/textures/CCTexture2D', - '../../cocos2d/core/sprites/CCSpriteFrame', - '../../cocos2d/core/load-pipeline/audio-downloader', - '../../cocos2d/core/physics/platform/CCPhysicsDebugDraw.js', - '../../cocos2d/core/physics/platform/CCPhysicsUtils.js', - '../../cocos2d/core/physics/platform/CCPhysicsAABBQueryCallback.js', - '../../cocos2d/core/physics/platform/CCPhysicsRayCastCallback.js', - '../../cocos2d/core/physics/platform/CCPhysicsContactListner.js', - '../../cocos2d/core/camera/CCSGCameraNode.js', - '../../cocos2d/core/label/CCSGLabel.js', - '../../cocos2d/core/label/CCSGLabelCanvasRenderCmd.js', - '../../cocos2d/core/label/CCSGLabelWebGLRenderCmd.js', - '../../cocos2d/core/videoplayer/CCSGVideoPlayer.js', - '../../cocos2d/core/webview/CCSGWebView.js', - '../../cocos2d/core/editbox/CCSGEditBox.js', - '../../cocos2d/audio/CCAudio', - '../../cocos2d/shape-nodes/CCDrawNode.js', - '../../cocos2d/clipping-nodes/CCClippingNode.js', - '../../cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js', - '../../cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js', - '../../cocos2d/particle/CCSGParticleSystem.js', - '../../cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js', - '../../cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js', - '../../cocos2d/tilemap/CCSGTMXTiledMap.js', - '../../cocos2d/tilemap/CCTMXXMLParser.js', - '../../cocos2d/tilemap/CCSGTMXObjectGroup.js', - '../../cocos2d/tilemap/CCSGTMXObject.js', - '../../cocos2d/tilemap/CCSGTMXLayer.js', - '../../cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js', - '../../cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js', - '../../cocos2d/motion-streak/CCSGMotionStreak.js', - '../../cocos2d/motion-streak/CCSGMotionStreakWebGLRenderCmd.js', - '../../cocos2d/render-texture/CCRenderTexture.js', - '../../cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js', - '../../cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js', - '../../extensions/spine/SGSkeleton', - '../../extensions/spine/SGSkeletonAnimation', - '../../extensions/spine/SGSkeletonCanvasRenderCmd', - '../../extensions/spine/SGSkeletonWebGLRenderCmd', - '../../extensions/spine/lib/spine', - '../../extensions/dragonbones/lib/dragonBones', - '../../extensions/dragonbones/CCFactory', - '../../extensions/dragonbones/CCArmatureDisplay', - '../../extensions/dragonbones/CCSlot', - '../../extensions/dragonbones/CCTextureData', - '../../external/box2d/box2d.js', -]; - gulp.task('build-jsb-dev', function (done) { Engine.buildJsb([ './jsb/index.js', - ], './bin/jsb_polyfill.dev.js', jsbSkipModules, done); + ], './bin/jsb_polyfill.dev.js', [], done); }); gulp.task('build-jsb-min', function (done) { Engine.buildJsbMin([ './jsb/index.js', - ], './bin/jsb_polyfill.js', jsbSkipModules, done); + ], './bin/jsb_polyfill.js', [], done); }); gulp.task('build-jsb-preview', function (done) { Engine.buildJsbPreview([ './jsb/index.js', - ], './bin/jsb_polyfill-for-preview.js', jsbSkipModules, done); + ], './bin/jsb_polyfill-for-preview.js', [], done); }); gulp.task('build-jsb', ['build-jsb-preview', 'build-jsb-dev', 'build-jsb-min']); @@ -203,7 +152,7 @@ gulp.task('watch-preview', function () { gulp.task('watch-jsb-polyfill', function () { Watch.jsbPolyfill([ './jsb/index.js', - ], './bin/jsb_polyfill.dev.js', jsbSkipModules); + ], './bin/jsb_polyfill.dev.js'); }); gulp.task('watch-dev-files', ['watch-preview', 'watch-jsb-polyfill']); diff --git a/modules.json b/modules.json index 018b90f95f..b8f992ee40 100644 --- a/modules.json +++ b/modules.json @@ -59,7 +59,8 @@ { "name": "Spine Skeleton", "entries": [ - "./extensions/spine/index.js" + "./extensions/spine/index.js", + "./jsb/jsb-spine.js" ] }, { @@ -131,19 +132,22 @@ { "name": "EditorBox", "entries": [ - "./cocos2d/core/components/CCEditBox.js" + "./cocos2d/core/components/CCEditBox.js", + "./jsb/jsb-editbox.js" ] }, { "name": "VideoPlayer", "entries": [ - "./cocos2d/core/components/CCVideoPlayer.js" + "./cocos2d/core/components/CCVideoPlayer.js", + "./jsb/jsb-videoplayer.js" ] }, { "name": "WebView", "entries": [ - "./cocos2d/core/components/CCWebView.js" + "./cocos2d/core/components/CCWebView.js", + "./jsb/jsb-webview.js" ] }, { @@ -155,7 +159,8 @@ { "name": "AudioSource", "entries": [ - "./cocos2d/core/components/CCAudioSource.js" + "./cocos2d/core/components/CCAudioSource.js", + "./jsb/jsb-audio.js" ] }, { @@ -198,13 +203,15 @@ { "name": "DragonBones", "entries": [ - "./extensions/dragonbones/index.js" + "./extensions/dragonbones/index.js", + "./jsb/jsb-dragonbones.js" ] }, { "name": "Physics", "entries": [ - "./cocos2d/core/physics/index.js" + "./cocos2d/core/physics/index.js", + "./jsb/jsb-box2d.js" ], "dependencies": ["Collider"] }, From 32903ba9da1faf7597c9a6e03e409bc5746c8ed1 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 16 Oct 2017 17:09:39 +0800 Subject: [PATCH 20/47] add Native NetWork module --- modules.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules.json b/modules.json index b8f992ee40..207e0cbdd2 100644 --- a/modules.json +++ b/modules.json @@ -246,5 +246,8 @@ "entries": [ "./cocos2d/core/collider/CCIntersection.js" ] + }, + { + "name": "Native NetWork" } ] From 0968a41087999157af96c0925ee220fd6ddf496a Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 16 Oct 2017 17:09:59 +0800 Subject: [PATCH 21/47] refine jsb modules --- jsb/jsb-editbox.js | 95 ++++++++++++++++++++++++++++++++ jsb/jsb-enums.js | 120 ----------------------------------------- jsb/jsb-videoplayer.js | 15 ++++++ jsb/jsb-webview.js | 12 +++++ 4 files changed, 122 insertions(+), 120 deletions(-) diff --git a/jsb/jsb-editbox.js b/jsb/jsb-editbox.js index 581149e1ca..60119e2e25 100644 --- a/jsb/jsb-editbox.js +++ b/jsb/jsb-editbox.js @@ -59,3 +59,98 @@ _p.getTabIndex = function () { return -1; }; _p.setFocus = function () {}; _p.isFocused = function () { return false; }; _p.stayOnTop = function () {}; + + + +cc.EditBox.InputMode = cc.Enum({ + + ANY: 0, + + /** + * The user is allowed to enter an e-mail address. + */ + EMAIL_ADDR: 1, + + /** + * The user is allowed to enter an integer value. + */ + NUMERIC: 2, + + /** + * The user is allowed to enter a phone number. + */ + PHONE_NUMBER: 3, + + /** + * The user is allowed to enter a URL. + */ + URL: 4, + + /** + * The user is allowed to enter a real number value. + * This extends kEditBoxInputModeNumeric by allowing a decimal point. + */ + DECIMAL: 5, + + /** + * The user is allowed to enter any text, except for line breaks. + */ + SINGLE_LINE: 6 +}); + +/** + * Enum for the EditBox's input flags + * @readonly + * @enum {number} + * @memberof cc.EditBox + */ +cc.EditBox.InputFlag = cc.Enum({ + /** + * Indicates that the text entered is confidential data that should be + * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE. + */ + PASSWORD: 0, + + /** + * Indicates that the text entered is sensitive data that the + * implementation must never store into a dictionary or table for use + * in predictive, auto-completing, or other accelerated input schemes. + * A credit card number is an example of sensitive data. + */ + SENSITIVE: 1, + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each word should be capitalized. + */ + INITIAL_CAPS_WORD: 2, + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each sentence should be capitalized. + */ + INITIAL_CAPS_SENTENCE: 3, + + /** + * Capitalize all characters automatically. + */ + INITIAL_CAPS_ALL_CHARACTERS: 4, + + /** + * Don't do anything with the input text. + */ + DEFAULT: 5 +}); + +/** + * Enum for keyboard return types + * @readonly + * @enum {number} + */ +cc.EditBox.KeyboardReturnType = cc.Enum({ + DEFAULT: 0, + DONE: 1, + SEND: 2, + SEARCH: 3, + GO: 4 +}); \ No newline at end of file diff --git a/jsb/jsb-enums.js b/jsb/jsb-enums.js index 3a8d104da4..d2302b7de3 100644 --- a/jsb/jsb-enums.js +++ b/jsb/jsb-enums.js @@ -25,126 +25,6 @@ 'use strict'; -//FIXME: should delete this line after implementing the VideoPlayer on Mac and Windows -if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) { - cc.VideoPlayer = {}; -} - -//FIXME: should delete this line after implementing the VideoPlayer on Mac and Windows -if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) { - cc.WebView = {}; -} - -cc.VideoPlayer.EventType = { - PLAYING: 0, - PAUSED: 1, - STOPPED: 2, - COMPLETED: 3, - META_LOADED: 4, - CLICKED: 5, - READY_TO_PLAY: 6 -}; - -cc.WebView.EventType = { - LOADING: 0, - LOADED: 1, - ERROR: 2, - JS_EVALUATED: 3 -}; - -cc.EditBox.InputMode = cc.Enum({ - - ANY: 0, - - /** - * The user is allowed to enter an e-mail address. - */ - EMAIL_ADDR: 1, - - /** - * The user is allowed to enter an integer value. - */ - NUMERIC: 2, - - /** - * The user is allowed to enter a phone number. - */ - PHONE_NUMBER: 3, - - /** - * The user is allowed to enter a URL. - */ - URL: 4, - - /** - * The user is allowed to enter a real number value. - * This extends kEditBoxInputModeNumeric by allowing a decimal point. - */ - DECIMAL: 5, - - /** - * The user is allowed to enter any text, except for line breaks. - */ - SINGLE_LINE: 6 -}); - -/** - * Enum for the EditBox's input flags - * @readonly - * @enum {number} - * @memberof cc.EditBox - */ -cc.EditBox.InputFlag = cc.Enum({ - /** - * Indicates that the text entered is confidential data that should be - * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE. - */ - PASSWORD: 0, - - /** - * Indicates that the text entered is sensitive data that the - * implementation must never store into a dictionary or table for use - * in predictive, auto-completing, or other accelerated input schemes. - * A credit card number is an example of sensitive data. - */ - SENSITIVE: 1, - - /** - * This flag is a hint to the implementation that during text editing, - * the initial letter of each word should be capitalized. - */ - INITIAL_CAPS_WORD: 2, - - /** - * This flag is a hint to the implementation that during text editing, - * the initial letter of each sentence should be capitalized. - */ - INITIAL_CAPS_SENTENCE: 3, - - /** - * Capitalize all characters automatically. - */ - INITIAL_CAPS_ALL_CHARACTERS: 4, - - /** - * Don't do anything with the input text. - */ - DEFAULT: 5 -}); - -/** - * Enum for keyboard return types - * @readonly - * @enum {number} - */ -cc.EditBox.KeyboardReturnType = cc.Enum({ - DEFAULT: 0, - DONE: 1, - SEND: 2, - SEARCH: 3, - GO: 4 -}); - /** * Enum for text alignment * @readonly diff --git a/jsb/jsb-videoplayer.js b/jsb/jsb-videoplayer.js index 7b0b2ba7e6..ab7d40ebc3 100644 --- a/jsb/jsb-videoplayer.js +++ b/jsb/jsb-videoplayer.js @@ -24,3 +24,18 @@ ****************************************************************************/ cc.VideoPlayer = ccui.VideoPlayer; + +//FIXME: should delete this line after implementing the VideoPlayer on Mac and Windows +if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) { + cc.VideoPlayer = {}; +} + +cc.VideoPlayer.EventType = { + PLAYING: 0, + PAUSED: 1, + STOPPED: 2, + COMPLETED: 3, + META_LOADED: 4, + CLICKED: 5, + READY_TO_PLAY: 6 +}; diff --git a/jsb/jsb-webview.js b/jsb/jsb-webview.js index 8b8c1cd1b9..0065697b57 100644 --- a/jsb/jsb-webview.js +++ b/jsb/jsb-webview.js @@ -24,3 +24,15 @@ ****************************************************************************/ cc.WebView = ccui.WebView; + +//FIXME: should delete this line after implementing the VideoPlayer on Mac and Windows +if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) { + cc.WebView = {}; +} + +cc.WebView.EventType = { + LOADING: 0, + LOADED: 1, + ERROR: 2, + JS_EVALUATED: 3 +}; \ No newline at end of file From d1e56cb58ad95149acf8c1063e6abdef8c727d4f Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Oct 2017 15:46:44 +0800 Subject: [PATCH 22/47] Removes fake console.log since it's implemented in native code now. --- jsb/index.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/jsb/index.js b/jsb/index.js index 23d5f91171..3859bbd5a5 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -25,17 +25,6 @@ 'use strict'; -var originLog = console.log; - -// overwrite original console.log -try { - console.log = function () { - originLog.call(console, cc.js.formatStr.apply(null, arguments)); - }; -} -catch (e) { -} - function defineMacro (name, defaultValue) { // if "global_defs" not preprocessed by uglify, just declare them globally, // this may happened in release version's preview page. From 9a59f75c24fb5159a36dc9b8c36d96c9e5dcae8c Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Oct 2017 15:55:13 +0800 Subject: [PATCH 23/47] CC_JSB condition check for console.time --- polyfill/misc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyfill/misc.js b/polyfill/misc.js index 31c4065874..aa62b6bb68 100644 --- a/polyfill/misc.js +++ b/polyfill/misc.js @@ -14,7 +14,7 @@ if (!Number.isInteger) { }; } -if (!console.time) { +if (CC_JSB || !console.time) { var Timer = window.performance || Date; var _timerTable = Object.create(null); console.time = function (label) { From a112586420e4853b277e3a55ea9199ae05775d41 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 18 Oct 2017 11:01:06 +0800 Subject: [PATCH 24/47] fix CCSlider api error --- cocos2d/core/components/CCSlider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCSlider.js b/cocos2d/core/components/CCSlider.js index 293b73035a..1a4ef837d8 100644 --- a/cocos2d/core/components/CCSlider.js +++ b/cocos2d/core/components/CCSlider.js @@ -225,7 +225,7 @@ cc.Slider = module.exports = Slider; * Note: This event is emitted from the node to which the component belongs. * !#zh * 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。 - * @event slider + * @event slide * @param {Event.EventCustom} event * @param {Slider} event.detail - The slider component. */ From 62841321a5dd57b0fc4b8b1f24d05d6dccf1f016 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Thu, 19 Oct 2017 17:32:03 +0800 Subject: [PATCH 25/47] fallback function if not support Function --- cocos2d/core/assets/CCPrefab.js | 16 ++- cocos2d/core/component-scheduler.js | 20 +++- cocos2d/core/node-activator.js | 11 +- cocos2d/core/platform/CCClass.js | 173 +++++++++++++++++++++------ cocos2d/core/platform/CCObject.js | 47 +++++--- cocos2d/core/platform/_CCClass.js | 2 +- cocos2d/core/platform/attribute.js | 2 +- cocos2d/core/platform/deserialize.js | 113 ++++++++++++++++- index.js | 27 +++-- jsb/index.js | 28 +++-- 10 files changed, 346 insertions(+), 93 deletions(-) diff --git a/cocos2d/core/assets/CCPrefab.js b/cocos2d/core/assets/CCPrefab.js index 7d8341ff7c..926b3b789e 100644 --- a/cocos2d/core/assets/CCPrefab.js +++ b/cocos2d/core/assets/CCPrefab.js @@ -94,10 +94,18 @@ var Prefab = cc.Class({ }, _instantiate: function () { - // instantiate node - var node = this._doInstantiate(); - // initialize node - this.data._instantiate(node); + var node; + if (cc.supportJit) { + // instantiate node + node = this._doInstantiate(); + // initialize node + this.data._instantiate(node); + } + else { + // instantiate node + node = this.data._instantiate(); + } + // link prefab in editor if (CC_EDITOR || CC_TEST) { // This operation is not necessary, but some old prefab asset may not contain complete data. diff --git a/cocos2d/core/component-scheduler.js b/cocos2d/core/component-scheduler.js index 5f0bbfd910..7a02a2b988 100644 --- a/cocos2d/core/component-scheduler.js +++ b/cocos2d/core/component-scheduler.js @@ -38,6 +38,18 @@ var callUpdateInTryCatch = CC_EDITOR && callerFunctor('update', 'dt'); var callLateUpdateInTryCatch = CC_EDITOR && callerFunctor('lateUpdate', 'dt'); var callOnDisableInTryCatch = CC_EDITOR && callerFunctor('onDisable'); +var supportJit = cc.supportJit; +var callStart = supportJit ? 'c.start();c._objFlags|=' + IsStartCalled : function (c) { + c.start(); + c._objFlags |= IsStartCalled; +}; +var callUpdate = supportJit ? 'c.update(dt)' : function (c, dt) { + c.update(dt); +}; +var callLateUpdate = supportJit ? 'c.lateUpdate(dt)' : function (c, dt) { + c.lateUpdate(dt); +}; + function sortedIndex (array, comp) { var order = comp.constructor._executionOrder; var id = comp.__instanceId; @@ -204,7 +216,7 @@ function enableInEditor (comp) { } function createInvokeImpl (funcOrCode, useDt) { - if (CC_EDITOR) { + if (typeof funcOrCode === 'function') { if (useDt) { return function (iterator, dt) { var array = iterator.array; @@ -253,11 +265,11 @@ function createInvokeImpl (funcOrCode, useDt) { function ctor () { // invokers this.startInvoker = new OneOffInvoker(createInvokeImpl( - CC_EDITOR ? callStartInTryCatch : 'c.start();c._objFlags|=' + IsStartCalled)); + CC_EDITOR ? callStartInTryCatch : callStart)); this.updateInvoker = new ReusableInvoker(createInvokeImpl( - CC_EDITOR ? callUpdateInTryCatch : 'c.update(dt)', true)); + CC_EDITOR ? callUpdateInTryCatch : callUpdate, true)); this.lateUpdateInvoker = new ReusableInvoker(createInvokeImpl( - CC_EDITOR ? callLateUpdateInTryCatch : 'c.lateUpdate(dt)', true)); + CC_EDITOR ? callLateUpdateInTryCatch : callLateUpdate, true)); // components deferred to next frame this.scheduleInNextFrame = []; diff --git a/cocos2d/core/node-activator.js b/cocos2d/core/node-activator.js index 686c40ce80..adf5a7e7c4 100644 --- a/cocos2d/core/node-activator.js +++ b/cocos2d/core/node-activator.js @@ -43,6 +43,13 @@ var callResetInTryCatch = CC_EDITOR && callerFunctor('resetInEditor'); var callOnFocusInTryCatch = CC_EDITOR && callerFunctor('onFocusInEditor'); var callOnLostFocusInTryCatch = CC_EDITOR && callerFunctor('onLostFocusInEditor'); +var supportJit = cc.supportJit; +var callPreload = supportJit ? 'c.__preload();' : function (c) { c.__preload(); } +var callOnLoad = supportJit ? ('c.onLoad();c._objFlags|=' + IsOnLoadCalled) : function (c) { + c.onLoad(); + c._objFlags|= IsOnLoadCalled; +} + // for __preload: use internally, no sort var UnsortedInvoker = cc.Class({ extends: CompScheduler.LifeCycleInvoker, @@ -62,10 +69,10 @@ var UnsortedInvoker = cc.Class({ }); var invokePreload = CompScheduler.createInvokeImpl( - CC_EDITOR ? callPreloadInTryCatch : 'c.__preload();' + CC_EDITOR ? callPreloadInTryCatch : callPreload ); var invokeOnLoad = CompScheduler.createInvokeImpl( - CC_EDITOR ? callOnLoadInTryCatch : ('c.onLoad();c._objFlags|=' + IsOnLoadCalled) + CC_EDITOR ? callOnLoadInTryCatch : callOnLoad ); var activateTasksPool = new JS.Pool(MAX_POOL_SIZE); diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 4118d0cc5b..4d7674d1a7 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -396,33 +396,37 @@ function getNewValueTypeCode (value) { var clsName = JS.getClassName(value); var type = value.constructor; var res = 'new ' + clsName + '('; - var i; - if (type === cc.Mat3 || type === cc.Mat4) { - var data = value.data; - for (i = 0; i < data.length; i++) { - res += data[i]; - if (i < data.length - 1) { - res += ','; - } + for (var i = 0; i < type.__props__.length; i++) { + var prop = type.__props__[i]; + var propVal = value[prop]; + if (typeof propVal === 'object') { + cc.errorID(3641, clsName); + return 'new ' + clsName + '()'; } - } - else { - for (i = 0; i < type.__props__.length; i++) { - var prop = type.__props__[i]; - var propVal = value[prop]; - if (typeof propVal === 'object') { - cc.errorID(3641, clsName); - return 'new ' + clsName + '()'; - } - res += propVal; - if (i < type.__props__.length - 1) { - res += ','; - } + res += propVal; + if (i < type.__props__.length - 1) { + res += ','; } } return res + ')'; } +function getNewValueType (value) { + var clsName = JS.getClassName(value); + var type = value.constructor; + var res = new type(); + for (var i = 0; i < type.__props__.length; i++) { + var prop = type.__props__[i]; + var propVal = value[prop]; + if (typeof propVal === 'object') { + cc.errorID(3641, clsName); + return res; + } + res[prop] = propVal; + } + return res; +} + // TODO - move escapeForJS, IDENTIFIER_RE, getNewValueTypeCode to misc.js or a new source file // convert a normal string including newlines, quotes and unicode characters into a string literal @@ -434,17 +438,7 @@ function escapeForJS (s) { replace(/\u2029/g, '\\u2029'); } -// simple test variable name -var IDENTIFIER_RE = /^[$A-Za-z_][0-9A-Za-z_$]*$/; -function compileProps (actualClass) { - // init deferred properties - var attrs = Attr.getClassAttrs(actualClass); - var propList = actualClass.__props__; - if (propList === null) { - deferredInitializer.init(); - propList = actualClass.__props__; - } - +function getInitPropsJit (attrs, propList) { // functions for generated code var F = []; var func = ''; @@ -498,7 +492,6 @@ function compileProps (actualClass) { // console.log(func); // } - // Overwite __initProps__ to avoid compile again. var initProps; if (F.length === 0) { initProps = Function(func); @@ -506,14 +499,81 @@ function compileProps (actualClass) { else { initProps = Function('F', 'return (function(){\n' + func + '})')(F); } + + return initProps; +} + +function getInitProps (attrs, propList) { + // functions for generated code + + function func () { + var F = []; + + for (var i = 0; i < propList.length; i++) { + var prop = propList[i]; + var attrKey = prop + DELIMETER + 'default'; + if (attrKey in attrs) { // getter does not have default + var expression; + var def = attrs[attrKey]; + if (typeof def === 'object' && def) { + if (def instanceof cc.ValueType) { + expression = getNewValueType(def); + } + else if (Array.isArray(def)) { + expression = []; + } + else { + expression = {}; + } + } + else if (typeof def === 'function') { + var index = F.length; + F.push(def); + expression = F[index](); + if (CC_EDITOR) { + try { + this[prop] = expression; + } + catch(err) { + cc._throw(e); + } + continue; + } + } + else { + // number, boolean, null, undefined, string + expression = def; + } + + this[prop] = expression; + } + } + } + + return func; +} + +// simple test variable name +var IDENTIFIER_RE = /^[$A-Za-z_][0-9A-Za-z_$]*$/; +function compileProps (actualClass) { + // init deferred properties + var attrs = Attr.getClassAttrs(actualClass); + var propList = actualClass.__props__; + if (propList === null) { + deferredInitializer.init(); + propList = actualClass.__props__; + } + + // Overwite __initProps__ to avoid compile again. + var initProps = cc.supportJit ? getInitPropsJit(attrs, propList) : getInitProps(attrs, propList); actualClass.prototype.__initProps__ = initProps; + // call instantiateProps immediately, no need to pass actualClass into it anymore // (use call to manually bind `this` because `this` may not instanceof actualClass) initProps.call(this); } -function _createCtor (ctors, baseClass, className, options) { - // bound super calls +var _createCtor = cc.supportJit ? function (ctors, baseClass, className, options) { var superCallBounded = baseClass && boundSuperCalls(baseClass, options, className); var ctorName = CC_DEV ? normalizeClassName_DEV(className) : 'CCClass'; @@ -552,7 +612,48 @@ function _createCtor (ctors, baseClass, className, options) { body += '}'; return Function(body)(); -} +} : function (ctors, baseClass, className, options) { + var superCallBounded = baseClass && boundSuperCalls(baseClass, options, className); + + return function CCClass () { + if (superCallBounded) { + this._super=null; + } + + this.__initProps__(CCClass); + + var args = arguments; + var self = this; + function init () { + if (ctorLen === 1) { + CCClass.__ctors__[0].apply(self, args); + } + else { + var cs = CCClass.__ctors__; + for (var i = 0; i < ctorLen; i++) { + cs[i].apply(self, args);; + } + } + } + + // call user constructors + var ctorLen = ctors.length; + if (ctorLen > 0) { + var useTryCatch = ! (className && className.startsWith('cc.')); + if (useTryCatch) { + try { + init(); + } + catch(e) { + cc._throw(e); + } + } + else { + init(); + } + } + }; +}; function _validateCtor_DEV (ctor, baseClass, className, options) { if (CC_EDITOR && baseClass) { diff --git a/cocos2d/core/platform/CCObject.js b/cocos2d/core/platform/CCObject.js index 8c7d193d48..f3e1781f3a 100644 --- a/cocos2d/core/platform/CCObject.js +++ b/cocos2d/core/platform/CCObject.js @@ -339,25 +339,38 @@ function compileDestruct (obj, ctor) { } // compile code var skipId = obj instanceof cc._BaseNode || obj instanceof cc.Component; - var func = ''; - for (key in propsToReset) { - if (skipId && key === '_id') { - continue; + + if (cc.supportJit) { + var func = ''; + for (key in propsToReset) { + if (skipId && key === '_id') { + continue; + } + var statement; + if (CCClass.IDENTIFIER_RE.test(key)) { + statement = 'o.' + key + '='; + } + else { + statement = 'o[' + CCClass.escapeForJS(key) + ']='; + } + var val = propsToReset[key]; + if (val === '') { + val = '""'; + } + func += (statement + val + ';\n'); } - var statement; - if (CCClass.IDENTIFIER_RE.test(key)) { - statement = 'o.' + key + '='; - } - else { - statement = 'o[' + CCClass.escapeForJS(key) + ']='; - } - var val = propsToReset[key]; - if (val === '') { - val = '""'; - } - func += (statement + val + ';\n'); + return Function('o', func); + } + else { + return function (o) { + for (key in propsToReset) { + if (skipId && key === '_id') { + continue; + } + o[key] = propsToReset[key]; + } + }; } - return Function('o', func); } /** diff --git a/cocos2d/core/platform/_CCClass.js b/cocos2d/core/platform/_CCClass.js index 2b50d3757a..d66de087d1 100644 --- a/cocos2d/core/platform/_CCClass.js +++ b/cocos2d/core/platform/_CCClass.js @@ -69,7 +69,7 @@ Class.extend = function (props) { // The dummy Class constructor var TheClass; - if (cc.game && cc.game.config && cc.game.config[cc.game.CONFIG_KEY.exposeClassName]) { + if (cc.supportJit && cc.game && cc.game.config && cc.game.config[cc.game.CONFIG_KEY.exposeClassName]) { var ctor = "return (function " + (props._className || "Class") + "(arg0,arg1,arg2,arg3,arg4) {\n" + "this.__instanceId = cc.ClassManager.getNewInstanceId();\n" + diff --git a/cocos2d/core/platform/attribute.js b/cocos2d/core/platform/attribute.js index d4a809aa71..da5ef14f0f 100644 --- a/cocos2d/core/platform/attribute.js +++ b/cocos2d/core/platform/attribute.js @@ -30,7 +30,7 @@ const DELIMETER = '$_$'; function createAttrsSingle (owner, ownerCtor, superAttrs) { var AttrsCtor; - if (CC_DEV) { + if (CC_DEV && cc.supportJit) { var ctorName = ownerCtor.name; if (owner === ownerCtor) { ctorName += '_ATTRS'; diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index 0289609d85..0074c1f36a 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -496,7 +496,7 @@ var _Deserializer = (function () { // } // } - function compileObjectType (sources, defaultValue, accessorToSet, propNameLiteralToSet, assumeHavePropIfIsValue) { + var compileObjectType = cc.supportJit ? function (sources, defaultValue, accessorToSet, propNameLiteralToSet, assumeHavePropIfIsValue) { if (defaultValue instanceof cc.ValueType) { // fast case if (!assumeHavePropIfIsValue) { @@ -518,9 +518,38 @@ var _Deserializer = (function () { } sources.push('}else o' + accessorToSet + '=null;'); } - } + } : function (s, o, t, prop, defaultValue, propName, assumeHavePropIfIsValue) { + if (defaultValue instanceof cc.ValueType) { + var ctor = defaultValue.constructor; + + if (assumeHavePropIfIsValue) { + s._deserializeTypedObject(o[propName], prop, ctor); + } + else { + if (prop) { + s._deserializeTypedObject(o[propName], prop, ctor); + } + else { + o[propName] = null; + } + } + } + else { + if (prop) { + if (CC_EDITOR || CC_TEST) { + s._deserializeObjField(o, prop, propName, t&&o); + } + else { + s._deserializeObjField(o, prop, propName); + } + } + else { + o[propName] = null; + } + } + }; - function compileDeserialize (self, klass) { + var compileDeserialize = cc.supportJit ? function (self, klass) { var RAW_TYPE = Attr.DELIMETER + 'rawType'; var EDITOR_ONLY = Attr.DELIMETER + 'editorOnly'; var SERIALIZABLE = Attr.DELIMETER + 'serializable'; @@ -619,7 +648,83 @@ var _Deserializer = (function () { sources.push('s._deserializePrimitiveObject(o._$erialized,d);'); } return Function('s', 'o', 'd', 'k', 't', sources.join('')); - } + } : function (self, klass) { + var RAW_TYPE = Attr.DELIMETER + 'rawType'; + var EDITOR_ONLY = Attr.DELIMETER + 'editorOnly'; + var SERIALIZABLE = Attr.DELIMETER + 'serializable'; + var DEFAULT = Attr.DELIMETER + 'default'; + var SAVE_URL_AS_ASSET = Attr.DELIMETER + 'saveUrlAsAsset'; + var FORMERLY_SERIALIZED_AS = Attr.DELIMETER + 'formerlySerializedAs'; + var attrs = Attr.getClassAttrs(klass); + + var props = klass.__props__; + var fastMode = Misc.BUILTIN_CLASSID_RE.test(JS._getClassId(klass)); + + return function (s, o, d, k, t) { + var prop; + for (var p = 0; p < props.length; p++) { + var propName = props[p]; + var rawType = attrs[propName + RAW_TYPE]; + if (!rawType) { + if ((CC_PREVIEW || (CC_EDITOR && self._ignoreEditorOnly)) && attrs[propName + EDITOR_ONLY]) { + var mayUsedInPersistRoot = (propName === '_id' && cc.isChildClassOf(klass, cc.Node)); + if (!mayUsedInPersistRoot) { + continue; // skip editor only if in preview + } + } + if (attrs[propName + SERIALIZABLE] === false) { + continue; // skip nonSerialized + } + + var propNameToRead = propName; + if (attrs[propName + FORMERLY_SERIALIZED_AS]) { + propNameToRead = attrs[propName + FORMERLY_SERIALIZED_AS]; + } + + prop = d[propNameToRead]; + + if (typeof prop !== 'undefined') { + // function undefined object(null) string boolean number + var defaultValue = CCClass.getDefault(attrs[propName + DEFAULT]); + if (fastMode) { + var defaultType = typeof defaultValue; + var isPrimitiveType = (defaultType === 'string' && !attrs[propName + SAVE_URL_AS_ASSET]) || + defaultType === 'number' || + defaultType === 'boolean'; + if (isPrimitiveType) { + o[propName] = prop; + } + else { + compileObjectType(s, o, t, prop, defaultValue, propName, true); + } + } + else { + if (typeof prop !== 'object') { + o[propName] = prop; + } + else { + compileObjectType(s, o, t, prop, defaultValue, propName, false); + } + } + } + } + else { + // always load raw objects even if property not serialized + // 这里假定每个asset都有uuid,每个json只能包含一个asset,只能包含一个rawProp + if (s.result.rawProp) { + cc.error("not support multi raw object in a file"); + } + s.result.rawProp = propName; + } + } + if (props[props.length - 1] === '_$erialized') { + // deep copy original serialized data + o._$erialized=JSON.parse(JSON.stringify(d)); + // parse the serialized data as primitive javascript object, so its __id__ will be dereferenced + s._deserializePrimitiveObject(o._$erialized,d); + } + } + }; function unlinkUnusedPrefab (self, serialized, obj) { var uuid = serialized['asset'] && serialized['asset'].__uuid__; diff --git a/index.js b/index.js index 1538bc3456..5bca974237 100644 --- a/index.js +++ b/index.js @@ -110,21 +110,21 @@ function defineMacro (name, defaultValue) { // if "global_defs" not preprocessed by uglify, just declare them globally, // this may happened in release version's preview page. // (use evaled code to prevent mangle by uglify) - return 'if(typeof ' + name + '=="undefined")' + - name + '=' + defaultValue + ';'; + if (typeof window[name] == 'undefined') { + window[name] = defaultValue; + } } function defined (name) { - return 'typeof ' + name + '=="object"'; + return typeof window[name] == 'object'; } -Function( - defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')) + - defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions') + - defineMacro('CC_PREVIEW', '!CC_EDITOR') + - defineMacro('CC_DEV', true) + // (CC_EDITOR && !CC_BUILD) || CC_PREVIEW || CC_TEST - defineMacro('CC_DEBUG', true) + // CC_DEV || Debug Build - defineMacro('CC_JSB', defined('jsb')) + - defineMacro('CC_BUILD', false) -)(); + +defineMacro('CC_TEST', defined('tap') || defined('QUnit')); +defineMacro('CC_EDITOR', defined('Editor') && defined('process') && ('electron' in process.versions)); +defineMacro('CC_PREVIEW', !CC_EDITOR); +defineMacro('CC_DEV', true); // (CC_EDITOR && !CC_BUILD) || CC_PREVIEW || CC_TEST +defineMacro('CC_DEBUG', true); // CC_DEV || Debug Build +defineMacro('CC_JSB', defined('jsb')); +defineMacro('CC_BUILD', false); // PREDEFINE @@ -138,6 +138,9 @@ Function( */ cc = {}; +// check whether support jit +cc.supportJit = Function('') !== undefined; + // The namespace for original nodes rendering in scene graph. _ccsg = {}; diff --git a/jsb/index.js b/jsb/index.js index 3859bbd5a5..ead122e2c2 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -25,25 +25,29 @@ 'use strict'; +// check whether support jit +cc.supportJit = Function('') !== undefined; + function defineMacro (name, defaultValue) { // if "global_defs" not preprocessed by uglify, just declare them globally, // this may happened in release version's preview page. // (use evaled code to prevent mangle by uglify) - return 'if(typeof ' + name + '=="undefined")' + - name + '=' + defaultValue + ';'; + if (typeof window[name] == 'undefined') { + window[name] = defaultValue; + } } function defined (name) { - return 'typeof ' + name + '=="object"'; + return typeof window[name] == 'object'; } -Function( - defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')) + - defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions') + - defineMacro('CC_PREVIEW', '!CC_EDITOR') + - defineMacro('CC_DEV', true) + // (CC_EDITOR && !CC_BUILD) || CC_PREVIEW || CC_TEST - defineMacro('CC_DEBUG', true) + // CC_DEV || Debug Build - defineMacro('CC_JSB', defined('jsb')) + - defineMacro('CC_BUILD', false) -)(); + +defineMacro('CC_TEST', defined('tap') || defined('QUnit')); +defineMacro('CC_EDITOR', defined('Editor') && defined('process') && ('electron' in process.versions)); +defineMacro('CC_PREVIEW', !CC_EDITOR); +defineMacro('CC_DEV', true); // (CC_EDITOR && !CC_BUILD) || CC_PREVIEW || CC_TEST +defineMacro('CC_DEBUG', true); // CC_DEV || Debug Build +defineMacro('CC_JSB', defined('jsb')); +defineMacro('CC_BUILD', false); + if (!cc.ClassManager) { cc.ClassManager = window.ClassManager; From dc7ae7fc8f4ac3e8caae576613fc04958fe78efd Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 20 Oct 2017 09:29:45 +0800 Subject: [PATCH 26/47] refine code --- cocos2d/core/node-activator.js | 2 +- cocos2d/core/platform/CCClass.js | 33 ++++++++++++++++---------------- index.js | 2 +- jsb/index.js | 2 +- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cocos2d/core/node-activator.js b/cocos2d/core/node-activator.js index adf5a7e7c4..23987801f5 100644 --- a/cocos2d/core/node-activator.js +++ b/cocos2d/core/node-activator.js @@ -47,7 +47,7 @@ var supportJit = cc.supportJit; var callPreload = supportJit ? 'c.__preload();' : function (c) { c.__preload(); } var callOnLoad = supportJit ? ('c.onLoad();c._objFlags|=' + IsOnLoadCalled) : function (c) { c.onLoad(); - c._objFlags|= IsOnLoadCalled; + c._objFlags |= IsOnLoadCalled; } // for __preload: use internally, no sort diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 4d7674d1a7..1f7d159a96 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -622,34 +622,35 @@ var _createCtor = cc.supportJit ? function (ctors, baseClass, className, options this.__initProps__(CCClass); - var args = arguments; - var self = this; - function init () { - if (ctorLen === 1) { - CCClass.__ctors__[0].apply(self, args); - } - else { - var cs = CCClass.__ctors__; - for (var i = 0; i < ctorLen; i++) { - cs[i].apply(self, args);; - } - } - } - // call user constructors var ctorLen = ctors.length; + var cs = CCClass.__ctors__; if (ctorLen > 0) { var useTryCatch = ! (className && className.startsWith('cc.')); if (useTryCatch) { try { - init(); + if (ctorLen === 1) { + cs[0].apply(this, arguments); + } + else { + for (var i = 0; i < ctorLen; i++) { + cs[i].apply(this, arguments);; + } + } } catch(e) { cc._throw(e); } } else { - init(); + if (ctorLen === 1) { + cs[0].apply(this, arguments); + } + else { + for (var i = 0; i < ctorLen; i++) { + cs[i].apply(this, arguments);; + } + } } } }; diff --git a/index.js b/index.js index 5bca974237..47cb5d2e27 100644 --- a/index.js +++ b/index.js @@ -139,7 +139,7 @@ defineMacro('CC_BUILD', false); cc = {}; // check whether support jit -cc.supportJit = Function('') !== undefined; +cc.supportJit = typeof Function('') === 'function'; // The namespace for original nodes rendering in scene graph. _ccsg = {}; diff --git a/jsb/index.js b/jsb/index.js index ead122e2c2..a1712c471a 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -26,7 +26,7 @@ 'use strict'; // check whether support jit -cc.supportJit = Function('') !== undefined; +cc.supportJit = typeof Function('') === 'function'; function defineMacro (name, defaultValue) { // if "global_defs" not preprocessed by uglify, just declare them globally, From 93910fbb9a63558ed3235db1445e8f3f03767dd0 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 20 Oct 2017 10:29:48 +0800 Subject: [PATCH 27/47] fixed window is not defined when load editor from bash --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 47cb5d2e27..815918e434 100644 --- a/index.js +++ b/index.js @@ -106,16 +106,17 @@ /** * @property {Boolean} CC_TEST - Running in the engine's unit test. */ +var _global = typeof window === 'undefined' ? global : window; function defineMacro (name, defaultValue) { // if "global_defs" not preprocessed by uglify, just declare them globally, // this may happened in release version's preview page. // (use evaled code to prevent mangle by uglify) - if (typeof window[name] == 'undefined') { - window[name] = defaultValue; + if (typeof _global[name] == 'undefined') { + _global[name] = defaultValue; } } function defined (name) { - return typeof window[name] == 'object'; + return typeof _global[name] == 'object'; } defineMacro('CC_TEST', defined('tap') || defined('QUnit')); From 27df2eae6a23a562cc524719d79db3126eff7b57 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 20 Oct 2017 16:42:38 +0800 Subject: [PATCH 28/47] refine register animation event --- cocos2d/animation/animation-animator.js | 13 +------ cocos2d/animation/animation-state.js | 6 ++++ cocos2d/core/components/CCAnimation.js | 45 ++++++++----------------- 3 files changed, 21 insertions(+), 43 deletions(-) diff --git a/cocos2d/animation/animation-animator.js b/cocos2d/animation/animation-animator.js index a2489497ed..dbdbd61ff9 100644 --- a/cocos2d/animation/animation-animator.js +++ b/cocos2d/animation/animation-animator.js @@ -52,24 +52,13 @@ p.stopStatesExcept = function (state) { } }; -p.on = function (type, callback, target, useCapture) { - var array = this._anims.array; - for (var i = 0; i < array.length; ++i) { - array[i].on(type, callback, target, useCapture); - } -} - p.addAnimation = function (anim) { var index = this._anims.array.indexOf(anim); if (index === -1) { this._anims.push(anim); } - var listeners = this.animation._listeners; - for (var i = 0, l = listeners.length; i < l; i++) { - var listener = listeners[i]; - anim.on(listener[0], listener[1], listener[2], listener[3]); - } + anim._setListeners(this.animation); }; p.removeAnimation = function (anim) { diff --git a/cocos2d/animation/animation-state.js b/cocos2d/animation/animation-state.js index 28ca78ea55..97a58064f1 100644 --- a/cocos2d/animation/animation-state.js +++ b/cocos2d/animation/animation-state.js @@ -143,6 +143,12 @@ var proto = AnimationState.prototype; cc.js.mixin(proto, cc.EventTarget.prototype); +proto._setListeners = function (target) { + this._capturingListeners = target ? target._capturingListeners : null; + this._bubblingListeners = target ? target._bubblingListeners : null; + this._hasListenerCache = target ? target._hasListenerCache : null; +}; + proto.onPlay = function () { // replay this.setTime(0); diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index 46d8ae3f55..fbd2a466a1 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -71,6 +71,8 @@ var Animation = cc.Class({ }, ctor: function () { + cc.EventTarget.call(this); + // The actual implement for Animation this._animator = null; @@ -78,8 +80,6 @@ var Animation = cc.Class({ this._didInit = false; this._currentClip = null; - - this._listeners = []; }, properties: { @@ -532,22 +532,15 @@ var Animation = cc.Class({ */ on: function (type, callback, target, useCapture) { this._init(); - var listeners = this._listeners; - for (var i = 0, l = listeners.length; i < l; i++) { - var listener = listeners[i]; - if (listener[0] === type && - listener[1] === callback && - listener[2] === target && - listener[3] === useCapture) { - return; - } + var ret = cc.EventTarget.prototype.on.call(this, type, callback, target, useCapture); + + var array = this._animator._anims.array; + for (var i = 0; i < array.length; ++i) { + array[i]._setListeners(this); } - this._animator.on(type, callback, target, useCapture); - listeners.push([type, callback, target, useCapture]); - - return callback; + return ret; }, @@ -571,23 +564,13 @@ var Animation = cc.Class({ */ off: function (type, callback, target, useCapture) { this._init(); - var listeners = this._listeners; + + cc.EventTarget.prototype.off.call(this, type, callback, target, useCapture); + var nameToState = this._nameToState; - - for (var i = listeners.length - 1; i >= 0; i--) { - var listener = listeners[i]; - if (listener[0] === type && - listener[1] === callback && - listener[2] === target && - listener[3] === useCapture) { - - for (var name in nameToState) { - var state = nameToState[name]; - state.off(type, callback, target, useCapture); - } - - listeners.splice(i, 1); - } + for (var name in nameToState) { + var state = nameToState[name]; + state._setListeners(null); } }, From cd302bbc031c97cb6cd5cb411d8246ec17663786 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 23 Oct 2017 15:10:19 +0800 Subject: [PATCH 29/47] add comment for window undefined --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 815918e434..3e08bad500 100644 --- a/index.js +++ b/index.js @@ -106,6 +106,8 @@ /** * @property {Boolean} CC_TEST - Running in the engine's unit test. */ + +// window may be undefined when first load engine from editor var _global = typeof window === 'undefined' ? global : window; function defineMacro (name, defaultValue) { // if "global_defs" not preprocessed by uglify, just declare them globally, From e0cf0a1533d6015c3cc77a202dccd778a3c96a00 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 23 Oct 2017 15:35:36 +0800 Subject: [PATCH 30/47] refine --- DebugInfos.js | 4 ++-- cocos2d/core/sprites/CCSpriteFrame.js | 8 ++++---- jsb/jsb-tex-sprite-frame.js | 1 + package.json | 1 - 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DebugInfos.js b/DebugInfos.js index 7476d4896c..ef9bda2064 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -241,9 +241,9 @@ if (CC_DEBUG) { "3116": "WebGLRenderingContext.CLAMP_TO_EDGE should be used in NPOT textures", //setTexParameters "3117": "Mimpap texture only works in POT textures", //generateMipmap //RectWidth: 3300 - "3300": "Rect width exceeds maximum margin: %s", //RectWidth + "3300": "Rect width exceeds maximum margin: %s, max x: %s, texture width: %s", //RectWidth //RectHeight: 3400 - "3400": "Rect height exceeds maximum margin: %s", //RectHeight + "3400": "Rect height exceeds maximum margin: %s, max y: %s, texture height: %s", //RectHeight //EventManager: 3500 "3500": "0 priority is forbidden for fixed priority since it's used for scene graph based priority.", //addListener "3501": "Invalid listener type!", //removeListeners diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js index 08365ad974..1a855272c8 100644 --- a/cocos2d/core/sprites/CCSpriteFrame.js +++ b/cocos2d/core/sprites/CCSpriteFrame.js @@ -452,11 +452,11 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ maxX += rect.width; maxY += rect.height; } - if (maxX > texture.getPixelWidth()) { - cc.errorID(3300, texture.url + '/' + this.name); + if (maxX > texture.width) { + cc.errorID(3300, texture.url + '/' + this.name, maxX, texture.width); } - if (maxY > texture.getPixelHeight()) { - cc.errorID(3400, texture.url + '/' + this.name); + if (maxY > texture.height) { + cc.errorID(3400, texture.url + '/' + this.name, maxY, texture.height); } }, diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index e8cc167547..172c5d3250 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -331,4 +331,5 @@ prototype.clone = function () { return cloned; }; +cc.js.getset(prototype, 'texture', prototype.getTexture, prototype.setTexture); cc.js.addon(prototype, WebSpriteFrame.prototype); diff --git a/package.json b/package.json index 7b9ece30df..7a5745c08f 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "jshint-stylish": "2.1.0", "multipipe": "0.3.0", "persistify": "^1.1.1", - "require-dir": "0.3.0", "uglify-es": "^3.0.26", "vinyl": "1.1.0", "vinyl-buffer": "1.0.0", From 9c8d7b1d21f47c3e8d4ec0972345d8e6443b22b7 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 23 Oct 2017 16:35:26 +0800 Subject: [PATCH 31/47] adjust the toggleItems code and remove toggleItems api --- cocos2d/core/components/CCToggleGroup.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/cocos2d/core/components/CCToggleGroup.js b/cocos2d/core/components/CCToggleGroup.js index 68b63a507d..6035b0f60d 100644 --- a/cocos2d/core/components/CCToggleGroup.js +++ b/cocos2d/core/components/CCToggleGroup.js @@ -54,18 +54,6 @@ var ToggleGroup = cc.Class({ tooltip: CC_DEV && 'i18n:COMPONENT.toggle_group.allowSwitchOff', default: false }, - - /** - * !#en Read only property, return the toggle items array reference managed by toggleGroup. - * !#zh 只读属性,返回 toggleGroup 管理的 toggle 数组引用 - * @property {Array} toggleItems - */ - toggleItems: { - get: function () { - cc.warnID(8500); - return this._toggleItems; - } - } }, updateToggles: function (toggle) { @@ -127,4 +115,11 @@ var ToggleGroup = cc.Class({ }); +var JS = require('../platform/js'); + +JS.get(ToggleGroup.prototype, 'toggleItems', function () { + cc.warnID(8500); + return this._toggleItems; +}); + cc.ToggleGroup = module.exports = ToggleGroup; From 70a472dd237a63885ddf4547391bb6b33d8fbee6 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 24 Oct 2017 01:02:41 +0800 Subject: [PATCH 32/47] fix and optimize jsb polyfill --- gulp/util/fix-jsb-javascriptcore.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gulp/util/fix-jsb-javascriptcore.js b/gulp/util/fix-jsb-javascriptcore.js index 3bf6c950c7..8d28be5be6 100644 --- a/gulp/util/fix-jsb-javascriptcore.js +++ b/gulp/util/fix-jsb-javascriptcore.js @@ -2,19 +2,22 @@ const ES = require('event-stream'); const Path = require('path'); const getRealTypeOfObj = (function __realTypeOfObj (obj) { - try { - if ('' + obj === '[object CallbackConstructor]') return 'function'; - } - catch (e) { - // "Cannot convert object to primitive value" + if (obj) { + if (obj.toString) { + if (obj.toString() === '[object CallbackConstructor]') + return 'function'; + } + else { + // "Cannot convert object to primitive value" + } } return 'object'; }).toString(); -const TYPEOF_SHIM = `\n${getRealTypeOfObj};\nvar __typeofVal = "";`; +const TYPEOF_SHIM = `\n${getRealTypeOfObj}\nvar __typeofVal = "";`; -const TYPEOF_REG = /typeof\s+([$A-Za-z_][0-9A-Za-z_\$\.\[\]]*)/g; -const TYPEOF_REPLACEMENT = '(__typeofVal = typeof $1, __typeofVal === "object" ? __realTypeOfObj($1) : __typeofVal)'; +const TYPEOF_REG = /typeof\s+([$A-Za-z_][0-9A-Za-z_$\.\[\]]*)([\s!=;\)])/g; +const TYPEOF_REPLACEMENT = '(__typeofVal = typeof $1, __typeofVal === "object" ? __realTypeOfObj($1) : __typeofVal)$2'; module.exports = function () { return ES.through(function (file) { From 1598f7462344d281adf35e2b7254e332df8cdb9b Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 24 Oct 2017 10:55:19 +0800 Subject: [PATCH 33/47] use temp matrix to avoid create new object --- cocos2d/core/camera/CCSGCameraNode.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/camera/CCSGCameraNode.js b/cocos2d/core/camera/CCSGCameraNode.js index d212926dc6..5522d9c461 100644 --- a/cocos2d/core/camera/CCSGCameraNode.js +++ b/cocos2d/core/camera/CCSGCameraNode.js @@ -1,3 +1,4 @@ +var tempMat = new cc.math.Matrix4(); let CameraNode = _ccsg.Node.extend({ ctor: function () { @@ -46,8 +47,10 @@ let CameraNode = _ccsg.Node.extend({ cc.renderer._breakBatch(); cc.math.glMatrixMode(cc.math.KM_GL_PROJECTION); - cc.current_stack.push(); - cc.current_stack.top.multiply(this._mat); + + tempMat.assignFrom(cc.current_stack.top); + tempMat.multiply(this._mat); + cc.current_stack.push(tempMat); }, _onAfterVisit: function () { From 329d3c98589d983862214ba4ec0cf573966e901f Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 24 Oct 2017 14:36:23 +0800 Subject: [PATCH 34/47] add interaction with WebView internal pages for fireball/issues/6490 --- cocos2d/core/components/CCWebView.js | 48 +++++++--- cocos2d/core/webview/CCSGWebView.js | 138 ++++++++++++++------------- 2 files changed, 107 insertions(+), 79 deletions(-) diff --git a/cocos2d/core/components/CCWebView.js b/cocos2d/core/components/CCWebView.js index 04943678dd..668c0df24f 100644 --- a/cocos2d/core/components/CCWebView.js +++ b/cocos2d/core/components/CCWebView.js @@ -103,14 +103,14 @@ var WebView = cc.Class({ EventType: EventType, }, - onLoad: CC_JSB && function() { + onLoad: CC_JSB && function () { if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) { this.enabled = false; } }, _createSgNode: function () { - if(CC_JSB) { + if (CC_JSB) { if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) { console.log('WebView is not supported on Mac and Windows!'); return null; @@ -132,7 +132,8 @@ var WebView = cc.Class({ if (CC_EDITOR && this._useOriginalSize) { this.node.setContentSize(sgNode.getContentSize()); this._useOriginalSize = false; - } else { + } + else { sgNode.setContentSize(this.node.getContentSize()); } }, @@ -175,11 +176,13 @@ var WebView = cc.Class({ /** * !#en - * Set javascript interface scheme. - * Note: only available on Android and iOS at the moment. + * Set javascript interface scheme (see also setOnJSCallback).
+ * Note: Only support Android and iOS, Web end usage, please go to the official document view.
+ * Please refer to the official document for more details * !#zh - * 设置 javascript 接口方案。 - * 注意:目前只能在 Android 和 iOS 上使用。 + * 设置 JavaScript 接口方案(与 'setOnJSCallback' 配套使用)。
+ * 注意:只支持 Android 和 iOS ,Web 端用法请前往官方文档查看。
+ * 详情请参阅官方文档 * @method setJavascriptInterfaceScheme * @param {String} scheme */ @@ -188,13 +191,17 @@ var WebView = cc.Class({ this._sgNode.setJavascriptInterfaceScheme(scheme); } }, + /** * !#en - * This callback called when load URL that start with javascript interface scheme. - * Note: only available on Android and iOS at the moment. + * This callback called when load URL that start with javascript + * interface scheme (see also setJavascriptInterfaceScheme).
+ * Note: Only support Android and iOS, Web end usage, please go to the official document view.
+ * Please refer to the official document for more details * !#zh - * 当加载 URL 以 JavaScript 接口方案开始时调用这个回调函数。 - * 注意:目前只能在 Android 和 iOS 上使用。 + * 当加载 URL 以 JavaScript 接口方案开始时调用这个回调函数。
+ * 注意:只支持 Android 和 iOS ,Web 端用法请前往官方文档查看。 + * 详情请参阅官方文档 * @method setOnJSCallback * @param {Function} callback */ @@ -202,7 +209,24 @@ var WebView = cc.Class({ if (this._sgNode) { this._sgNode.setOnJSCallback(callback); } - } + }, + + /** + * !#en + * Execution of WebView internal page script
+ * Please refer to the official document for more details
+ * Note: Cross domain issues need to be addressed by themselves
+ * !#zh + * 执行 WebView 内部页面脚本(详情请参阅官方文档)
+ * 注意:需要自行解决跨域问题 + * @method evaluateJS + * @param {String} str + */ + evaluateJS: function (str) { + if (this._sgNode) { + this._sgNode.evaluateJS(str); + } + }, }); diff --git a/cocos2d/core/webview/CCSGWebView.js b/cocos2d/core/webview/CCSGWebView.js index 9602b44e24..75b408b4ab 100644 --- a/cocos2d/core/webview/CCSGWebView.js +++ b/cocos2d/core/webview/CCSGWebView.js @@ -34,15 +34,15 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ } }, - setOnJSCallback: function(callback){}, - setJavascriptInterfaceScheme: function(scheme){}, - loadData: function(data, MIMEType, encoding, baseURL){}, - loadHTMLString: function(string, baseURL){}, + setOnJSCallback: function (callback) {}, + setJavascriptInterfaceScheme: function (scheme) {}, + loadData: function (data, MIMEType, encoding, baseURL) {}, + loadHTMLString: function (string, baseURL) {}, /** * Load an URL * @param {String} url */ - loadURL: function(url){ + loadURL: function (url) { this._renderCmd.updateURL(url); this._dispatchEvent(_ccsg.WebView.EventType.LOADING); }, @@ -50,18 +50,18 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ /** * Stop loading */ - stopLoading: function(){ + stopLoading: function () { cc.logID(7800); }, /** * Reload the WebView */ - reload: function(){ + reload: function () { var iframe = this._renderCmd._iframe; - if(iframe){ + if (iframe) { var win = iframe.contentWindow; - if(win && win.location) + if (win && win.location) win.location.reload(); } }, @@ -69,7 +69,7 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ /** * Determine whether to go back */ - canGoBack: function(){ + canGoBack: function () { cc.logID(7801); return true; }, @@ -77,7 +77,7 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ /** * Determine whether to go forward */ - canGoForward: function(){ + canGoForward: function () { cc.logID(7802); return true; }, @@ -85,17 +85,17 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ /** * go back */ - goBack: function(){ - try{ - if(_ccsg.WebView._polyfill.closeHistory) + goBack: function () { + try { + if (_ccsg.WebView._polyfill.closeHistory) return cc.logID(7803); var iframe = this._renderCmd._iframe; - if(iframe){ + if (iframe) { var win = iframe.contentWindow; - if(win && win.location) + if (win && win.location) win.history.back.call(win); } - }catch(err){ + } catch (err) { cc.log(err); } }, @@ -103,17 +103,17 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ /** * go forward */ - goForward: function(){ - try{ - if(_ccsg.WebView._polyfill.closeHistory) + goForward: function () { + try { + if (_ccsg.WebView._polyfill.closeHistory) return cc.logID(7804); var iframe = this._renderCmd._iframe; - if(iframe){ + if (iframe) { var win = iframe.contentWindow; - if(win && win.location) + if (win && win.location) win.history.forward.call(win); } - }catch(err){ + } catch (err) { cc.log(err); } }, @@ -122,14 +122,14 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ * In the webview execution within a period of js string * @param {String} str */ - evaluateJS: function(str){ + evaluateJS: function (str) { var iframe = this._renderCmd._iframe; - if(iframe){ + if (iframe) { var win = iframe.contentWindow; - try{ + try { win.eval(str); this._dispatchEvent(_ccsg.WebView.EventType.JS_EVALUATED); - }catch(err){ + } catch (err) { console.error(err); } } @@ -138,7 +138,7 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ /** * Limited scale */ - setScalesPageToFit: function(){ + setScalesPageToFit: function () { cc.logID(7805); }, @@ -147,7 +147,7 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ * @param {_ccsg.WebView.EventType} event * @param {Function} callback */ - setEventListener: function(event, callback){ + setEventListener: function (event, callback) { this._EventList[event] = callback; }, @@ -155,17 +155,17 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ * Delete events * @param {_ccsg.WebView.EventType} event */ - removeEventListener: function(event){ + removeEventListener: function (event) { this._EventList[event] = null; }, - _dispatchEvent: function(event) { + _dispatchEvent: function (event) { var callback = this._EventList[event]; if (callback) callback.call(this, this, this._renderCmd._iframe.src); }, - _createRenderCmd: function(){ + _createRenderCmd: function () { return new _ccsg.WebView.RenderCmd(this); }, @@ -174,7 +174,7 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ * @param {Number} width * @param {Number} height */ - setContentSize: function(width, height){ + setContentSize: function (width, height) { if (width.width !== undefined && width.height !== undefined) { height = width.height; width = width.width; @@ -188,7 +188,7 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ this._renderCmd.removeDom(); }, - setVisible: function ( visible ) { + setVisible: function (visible) { _ccsg.Node.prototype.setVisible.call(this, visible); this._renderCmd.updateVisibility(); } @@ -201,22 +201,23 @@ _ccsg.WebView.EventType = { JS_EVALUATED: 3 }; -(function(){ +(function() { var polyfill = _ccsg.WebView._polyfill = { devicePixelRatio: false, enableDiv: false }; - if(cc.sys.os === cc.sys.OS_IOS) + if (cc.sys.os === cc.sys.OS_IOS) polyfill.enableDiv = true; - if(cc.sys.isMobile){ - if(cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX){ + if (cc.sys.isMobile) { + if (cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX) { polyfill.enableBG = true; } - }else{ - if(cc.sys.browserType === cc.sys.BROWSER_TYPE_IE){ + } + else { + if (cc.sys.browserType === cc.sys.BROWSER_TYPE_IE) { polyfill.closeHistory = true; } } @@ -224,16 +225,17 @@ _ccsg.WebView.EventType = { })(); -(function(polyfill){ +(function(polyfill) { var RenderCmd; if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) { RenderCmd = _ccsg.Node.CanvasRenderCmd; - } else { + } + else { RenderCmd = _ccsg.Node.WebGLRenderCmd; } - _ccsg.WebView.RenderCmd = function(node){ + _ccsg.WebView.RenderCmd = function (node) { this._rootCtor(node); this._parent = null; @@ -250,10 +252,10 @@ _ccsg.WebView.EventType = { this.updateMatrix(); }; - proto.updateStatus = function(){ + proto.updateStatus = function () { polyfill.devicePixelRatio = cc.view.isRetinaEnabled(); var flags = _ccsg.Node._dirtyFlags, locFlag = this._dirtyFlag; - if(locFlag & flags.transformDirty){ + if (locFlag & flags.transformDirty) { //update the transform this.transform(this.getParentRenderCmd(), true); this.updateMatrix(); @@ -263,28 +265,28 @@ _ccsg.WebView.EventType = { proto.initEvent = function () { var node = this._node; - this._iframe.addEventListener("load", function(){ + this._iframe.addEventListener("load", function () { node._dispatchEvent(_ccsg.WebView.EventType.LOADED); }); - this._iframe.addEventListener("error", function(){ + this._iframe.addEventListener("error", function () { node._dispatchEvent(_ccsg.WebView.EventType.ERROR); }); }; - proto.resize = function(view){ + proto.resize = function (view) { view = view || cc.view; var node = this._node, eventManager = cc.eventManager; - if(node._parent && node._visible) + if (node._parent && node._visible) this.updateMatrix(); - else{ + else { var list = eventManager._listenersMap[cc.game.EVENT_RESIZE].getFixedPriorityListeners(); eventManager._removeListenerInVector(list, this._listener); this._listener = null; } }; - proto.updateMatrix = function(){ + proto.updateMatrix = function () { if (!this._div) return; var node = this._node, scaleX = cc.view._scaleX, scaleY = cc.view._scaleY; @@ -297,7 +299,7 @@ _ccsg.WebView.EventType = { var container = cc.game.container; var a = t.a * scaleX, b = t.b, c = t.c, d = t.d * scaleY; - var offsetX = container && container.style.paddingLeft && parseInt(container.style.paddingLeft); + var offsetX = container && container.style.paddingLeft && parseInt(container.style.paddingLeft); var offsetY = container && container.style.paddingBottom && parseInt(container.style.paddingBottom); var tx = t.tx * scaleX + offsetX, ty = t.ty * scaleY + offsetY; @@ -308,19 +310,19 @@ _ccsg.WebView.EventType = { this._div.style['-webkit-transform-origin'] = '0px 100% 0px'; }; - proto.initStyle = function(){ - if(!this._div) return; + proto.initStyle = function () { + if (!this._div) return; var div = this._div; div.style.position = "absolute"; div.style.bottom = "0px"; div.style.left = "0px"; }; - proto.updateURL = function(url){ + proto.updateURL = function (url) { var iframe = this._iframe; iframe.src = url; var self = this; - var cb = function(){ + var cb = function () { self._loaded = true; self.updateVisibility(); iframe.removeEventListener("load", cb); @@ -328,16 +330,16 @@ _ccsg.WebView.EventType = { iframe.addEventListener("load", cb); }; - proto.updateSize = function(w, h){ + proto.updateSize = function (w, h) { var div = this._div; - if(div){ - div.style["width"] = w+"px"; - div.style["height"] = h+"px"; + if (div) { + div.style["width"] = w + "px"; + div.style["height"] = h + "px"; } }; proto.createDom = function () { - if(polyfill.enableDiv){ + if (polyfill.enableDiv) { this._div = document.createElement("div"); this._div.style["-webkit-overflow"] = "auto"; this._div.style["-webkit-overflow-scrolling"] = "touch"; @@ -345,11 +347,12 @@ _ccsg.WebView.EventType = { this._div.appendChild(this._iframe); this._iframe.style.width = "100%"; this._iframe.style.height = "100%"; - }else{ + } + else { this._div = this._iframe = document.createElement("iframe"); } - if(polyfill.enableBG) + if (polyfill.enableBG) this._div.style["background"] = "#FFF"; this._div.style["background"] = "#FFF"; @@ -368,11 +371,11 @@ _ccsg.WebView.EventType = { this.initEvent(); }; - proto.removeDom = function(){ + proto.removeDom = function () { var div = this._div; - if(div){ + if (div) { var hasChild = Utils.contains(cc.game.container, div); - if(hasChild) + if (hasChild) cc.game.container.removeChild(div); } this._div = null; @@ -384,7 +387,8 @@ _ccsg.WebView.EventType = { var div = this._div; if (node.visible) { div.style.visibility = 'visible'; - } else { + } + else { div.style.visibility = 'hidden'; } }; From 1bc94e3dafab66c1a32d09384e89ee363dc21ebc Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 24 Oct 2017 15:02:39 +0800 Subject: [PATCH 35/47] refine code --- cocos2d/core/components/CCWebView.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/components/CCWebView.js b/cocos2d/core/components/CCWebView.js index 668c0df24f..26859c98e3 100644 --- a/cocos2d/core/components/CCWebView.js +++ b/cocos2d/core/components/CCWebView.js @@ -177,8 +177,8 @@ var WebView = cc.Class({ /** * !#en * Set javascript interface scheme (see also setOnJSCallback).
- * Note: Only support Android and iOS, Web end usage, please go to the official document view.
- * Please refer to the official document for more details + * Note: Supports only on the Android and iOS. For HTML5, please refer to the official documentation.
+ * Please refer to the official documentation for more details. * !#zh * 设置 JavaScript 接口方案(与 'setOnJSCallback' 配套使用)。
* 注意:只支持 Android 和 iOS ,Web 端用法请前往官方文档查看。
@@ -196,8 +196,8 @@ var WebView = cc.Class({ * !#en * This callback called when load URL that start with javascript * interface scheme (see also setJavascriptInterfaceScheme).
- * Note: Only support Android and iOS, Web end usage, please go to the official document view.
- * Please refer to the official document for more details + * Note: Supports only on the Android and iOS. For HTML5, please refer to the official documentation.
+ * Please refer to the official documentation for more details. * !#zh * 当加载 URL 以 JavaScript 接口方案开始时调用这个回调函数。
* 注意:只支持 Android 和 iOS ,Web 端用法请前往官方文档查看。 @@ -213,9 +213,9 @@ var WebView = cc.Class({ /** * !#en - * Execution of WebView internal page script
+ * Evaluates JavaScript in the context of the currently displayed page.
* Please refer to the official document for more details
- * Note: Cross domain issues need to be addressed by themselves
+ * Note: Cross domain issues need need to be resolved by yourself
* !#zh * 执行 WebView 内部页面脚本(详情请参阅官方文档)
* 注意:需要自行解决跨域问题 From 40759491705d2c65b42c75aab6bfd22a49b1b9b0 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 24 Oct 2017 15:36:59 +0800 Subject: [PATCH 36/47] fix CCWebView api error --- cocos2d/core/components/CCWebView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCWebView.js b/cocos2d/core/components/CCWebView.js index 26859c98e3..bad9bd0812 100644 --- a/cocos2d/core/components/CCWebView.js +++ b/cocos2d/core/components/CCWebView.js @@ -200,7 +200,7 @@ var WebView = cc.Class({ * Please refer to the official documentation for more details. * !#zh * 当加载 URL 以 JavaScript 接口方案开始时调用这个回调函数。
- * 注意:只支持 Android 和 iOS ,Web 端用法请前往官方文档查看。 + * 注意:只支持 Android 和 iOS,Web 端用法请前往官方文档查看。 * 详情请参阅官方文档 * @method setOnJSCallback * @param {Function} callback @@ -215,7 +215,7 @@ var WebView = cc.Class({ * !#en * Evaluates JavaScript in the context of the currently displayed page.
* Please refer to the official document for more details
- * Note: Cross domain issues need need to be resolved by yourself
+ * Note: Cross domain issues need to be resolved by yourself
* !#zh * 执行 WebView 内部页面脚本(详情请参阅官方文档)
* 注意:需要自行解决跨域问题 From 2a1ad289e3b5a18e99c1b0019132a1ca1044895f Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Tue, 24 Oct 2017 17:02:02 +0800 Subject: [PATCH 37/47] escape Unicode characters in strings and regexps --- gulp/util/utils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gulp/util/utils.js b/gulp/util/utils.js index a41839f33d..c6e288a952 100644 --- a/gulp/util/utils.js +++ b/gulp/util/utils.js @@ -43,6 +43,9 @@ exports.getUglifyOptions = function (platform, isJSB, isDebugBuild) { return { compress: { global_defs: global_defs, + }, + output: { + ascii_only: true, } }; } @@ -54,6 +57,7 @@ exports.getUglifyOptions = function (platform, isJSB, isDebugBuild) { // http://lisperator.net/uglifyjs/codegen beautify: true, indent_level: 2, + ascii_only: true, }, compress: { // https://github.com/mishoo/UglifyJS2#compressor-options From 92a9d5050758833a6b294f30bb3c6e333450bba1 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 25 Oct 2017 14:26:21 +0800 Subject: [PATCH 38/47] public inputManager for fireball/issues/6485 --- cocos2d/core/platform/CCInputManager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/core/platform/CCInputManager.js b/cocos2d/core/platform/CCInputManager.js index d75ac77a66..fea9a16b73 100644 --- a/cocos2d/core/platform/CCInputManager.js +++ b/cocos2d/core/platform/CCInputManager.js @@ -555,4 +555,5 @@ var inputManager = { } }; +cc.inputManager = inputManager; module.exports = inputManager; From c9d477edf059aec126cd19b0f5411381f5046dc6 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 25 Oct 2017 17:47:18 +0800 Subject: [PATCH 39/47] Fixes str.startswith isn't found on JSC in iOS 8. --- jsb/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jsb/index.js b/jsb/index.js index a1712c471a..df61f5f14d 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -63,6 +63,8 @@ if (CC_DEV) { // polyfills require('../polyfill/misc'); +// str.startswith isn't supported in JavaScriptCore which is shipped with iOS8. +require('../polyfill/string'); if (!(CC_EDITOR && Editor.isMainProcess)) { require('../polyfill/typescript'); } From cb3cf93a7a892f42d7823fe4df220d44c8ede710 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 25 Oct 2017 17:46:52 +0800 Subject: [PATCH 40/47] console.log fix for JavaScriptCore in iOS 8. --- CCDebugger.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/CCDebugger.js b/CCDebugger.js index 66bbca90b3..b7e4ef1a0e 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -96,8 +96,6 @@ cc.DebugMode = Enum({ * @module cc */ -var jsbLog = cc.log || console.log; - /** * !#en Init Debug setting. * !#zh 设置调试模式。 @@ -259,7 +257,14 @@ cc._initDebugSetting = function (mode) { * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. */ if (CC_JSB) { - cc.log = jsbLog; + if (scriptEngineType === "JavaScriptCore") { + // console.log has to use `console` as its context for iOS 8~9. Therefore, apply it. + cc.log = function () { + return console.log.apply(console, arguments); + }; + } else { + cc.log = console.log; + } } else if (console.log.bind) { // use bind to avoid pollute call stacks @@ -283,9 +288,16 @@ cc._initDebugSetting = function (mode) { * @param {any} msg - A JavaScript string containing zero or more substitution strings. * @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output. */ - cc.info = CC_JSB ? jsbLog : function () { - (console.info || console.log).apply(console, arguments); - }; + if (CC_JSB) { + cc.info = (scriptEngineType === "JavaScriptCore") ? function () { + (console.info || console.log).apply(console, arguments); + } : (console.info || console.log); + } else { + cc.info = function () { + (console.info || console.log).apply(console, arguments); + }; + } + } cc.warnID = genLogFunc(cc.warn, 'Warning'); From 19ee0534b0ab10b8e46941d30bdd1ce82b3ba309 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 25 Oct 2017 18:28:16 +0800 Subject: [PATCH 41/47] restore getName for fireball/issues/6505 --- cocos2d/deprecated.js | 7 +++++++ jsb/jsb-tex-sprite-frame.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 2c7f620613..b7a8108455 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -595,6 +595,13 @@ if (CC_DEV) { }); } + cc.js.get(cc.Texture2D.prototype, 'getName', function () { + cc.warnID(1400, 'texture.getName()', 'texture._glID'); + return function () { + return this._glID || null; + }; + }); + //ui if (cc.Layout) { js.obsolete(cc.Layout, 'cc.Layout.ResizeType', 'ResizeMode'); diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index ce27f9595c..500e877bcf 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -152,7 +152,7 @@ prototype.update = function (options) { if (genMipmap) { this.generateMipmap(); } -} +}; prototype.isLoaded = function () { return true; }; @@ -161,6 +161,7 @@ prototype.getPixelHeight = prototype.getPixelsHigh; prototype.description = prototype.getDescription; cc.js.get(prototype, 'pixelWidth', prototype.getPixelWidth); cc.js.get(prototype, 'pixelHeight', prototype.getPixelHeight); +cc.js.get(prototype, '_glID', prototype.getName); // cc.SpriteFrame From f2ddfee76844f1a86f4759fa96a8cbe78eb5408c Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 25 Oct 2017 21:02:54 +0800 Subject: [PATCH 42/47] fix potential memory leak when node detached from parent without cleanup --- cocos2d/core/utils/scene-graph-helper.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cocos2d/core/utils/scene-graph-helper.js b/cocos2d/core/utils/scene-graph-helper.js index 734e6bf183..56ec38a13d 100644 --- a/cocos2d/core/utils/scene-graph-helper.js +++ b/cocos2d/core/utils/scene-graph-helper.js @@ -27,15 +27,23 @@ var SceneGraphUtils = { removeSgNode: function () { - var node = this._sgNode; - if (node) { - var parent = node._parent; + var sgNode = this._sgNode; + if (sgNode) { + var parent = sgNode._parent; if (parent) { - parent.removeChild(node); + parent.removeChild(sgNode); } - node.release(); - if (this._sgNode._entity) { - this._sgNode._entity = null; + else { + // cleanup was skipped when its node was detaching + if (CC_JSB) { + sgNode.cleanup(); + } + else { + sgNode.performRecursive(_ccsg.Node.performType.cleanup); + } + } + if (sgNode._entity) { + sgNode._entity = null; } } }, From c0c80948c9b50945f79b88eb5a0cee7bd80ac4bc Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 25 Oct 2017 21:15:02 +0800 Subject: [PATCH 43/47] typo --- cocos2d/core/utils/misc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/utils/misc.js b/cocos2d/core/utils/misc.js index f2d26ba72d..c1360b9725 100644 --- a/cocos2d/core/utils/misc.js +++ b/cocos2d/core/utils/misc.js @@ -125,7 +125,7 @@ misc.imagePool.get = function () { }; misc.imagePool._smallImg = "data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA="; // Avoid problems on windows IE kernels, Edge, Firefox and Linux Firefox -if ((sys.os === sys.OS_WINDOWS || sys.os === sys.OS_LINUX) && sys.browser !== sys.BROWSER_TYPE_CHROME) { +if ((sys.os === sys.OS_WINDOWS || sys.os === sys.OS_LINUX) && sys.browserType !== sys.BROWSER_TYPE_CHROME) { misc.imagePool.resize(0); } From 44a53f5404e97004fad6ea36c406b7a27d4f876a Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 26 Oct 2017 10:03:57 +0800 Subject: [PATCH 44/47] fix ci --- cocos2d/core/CCNode.js | 3 +-- test/qunit/unit-es5/test-node.js | 27 --------------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 386ef2bf6d..f345764f6a 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1018,8 +1018,7 @@ var Node = cc.Class({ this._parent = null; } } - else if (CC_TEST ? (/* make CC_JSB mockable*/ Function('return CC_JSB'))() : CC_JSB) { - this._sgNode.release(); + else if (CC_JSB) { this._sgNode._entity = null; this._sgNode = null; } diff --git a/test/qunit/unit-es5/test-node.js b/test/qunit/unit-es5/test-node.js index 8f40d2512c..3b411c84d8 100644 --- a/test/qunit/unit-es5/test-node.js +++ b/test/qunit/unit-es5/test-node.js @@ -365,33 +365,6 @@ test('attach events', function () { cc.engine.off('node-detach-from-scene', onDetach); }); -test('release sg node', function () { - var isJSB = CC_JSB; - CC_JSB = true; - - var parent = new cc.Node(); - var child = new cc.Node(); - child.parent = parent; - - var childReleased = false; - var parentReleased = false; - - child._sgNode.release = function () { - childReleased = true; - }; - parent._sgNode.release = function () { - parentReleased = true; - }; - - parent.destroy(); - cc.Object._deferredDestroy(); - - strictEqual(parentReleased, true, 'should release parent sg node'); - strictEqual(childReleased, true, 'should release child sg node'); - - CC_JSB = isJSB; -}); - test('getBoundingBox', function () { var node = new cc.Node(); node.anchorX = 0.5; From 321470a9c3f51f153a30459a5925faaa916fa8f9 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 26 Oct 2017 17:08:52 +0800 Subject: [PATCH 45/47] fix CCEditBox event api --- cocos2d/core/components/CCEditBox.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/components/CCEditBox.js b/cocos2d/core/components/CCEditBox.js index 65f9b779de..6fe29cd21a 100644 --- a/cocos2d/core/components/CCEditBox.js +++ b/cocos2d/core/components/CCEditBox.js @@ -395,7 +395,7 @@ var EditBox = cc.Class({ /** * !#en The event handler to be called when EditBox began to edit text. * !#zh 开始编辑文本输入框触发的事件回调。 - * @property {Component.EventHandler} editingDidBegan + * @property {Component.EventHandler[]} editingDidBegan */ editingDidBegan: { default: [], @@ -405,7 +405,7 @@ var EditBox = cc.Class({ /** * !#en The event handler to be called when EditBox text changes. * !#zh 编辑文本输入框时触发的事件回调。 - * @property {Component.EventHandler} textChanged + * @property {Component.EventHandler[]} textChanged */ textChanged: { default: [], @@ -415,7 +415,7 @@ var EditBox = cc.Class({ /** * !#en The event handler to be called when EditBox edit ends. * !#zh 结束编辑文本输入框时触发的事件回调。 - * @property {Component.EventHandler} editingDidEnded + * @property {Component.EventHandler[]} editingDidEnded */ editingDidEnded: { default: [], @@ -425,7 +425,7 @@ var EditBox = cc.Class({ /** * !#en The event handler to be called when return key is pressed. Windows is not supported. * !#zh 当用户按下回车按键时的事件回调,目前不支持 windows 平台 - * @property {Component.EventHandler} editingReturn + * @property {Component.EventHandler[]} editingReturn */ editingReturn: { default: [], From 2c9db1b3e64381ceb99755f71efa39550921ff11 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 26 Oct 2017 22:12:21 +0800 Subject: [PATCH 46/47] Removes unused jsb.(un)registerNativeRef --- jsb/jsb-dragonbones.js | 8 ++------ jsb/jsb-loader.js | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/jsb/jsb-dragonbones.js b/jsb/jsb-dragonbones.js index 949a3a359c..fe7b674712 100644 --- a/jsb/jsb-dragonbones.js +++ b/jsb/jsb-dragonbones.js @@ -43,13 +43,9 @@ proto.removeEvent = function(type, listener, target) { var armatureProto = dragonBones.Armature.prototype; armatureProto.addEventListener = function (type, listener, target) { - var display = this.display; - jsb.registerNativeRef(this, display); - display.addEvent(type, listener, target); + this.display.addEvent(type, listener, target); }; armatureProto.removeEventListener = function (type, listener, target) { - var display = this.display; - jsb.unregisterNativeRef(this, display); - display.removeEvent(type, listener, target); + this.display.removeEvent(type, listener, target); }; diff --git a/jsb/jsb-loader.js b/jsb/jsb-loader.js index d380758abc..ad576b35ea 100644 --- a/jsb/jsb-loader.js +++ b/jsb/jsb-loader.js @@ -99,7 +99,6 @@ function loadImage (item, callback) { else { callback && callback(new Error('Load image failed: ' + url)); } - jsb.unregisterNativeRef(cc.textureCache, addImageCallback); }; cc.textureCache._addImageAsync(url, addImageCallback); } From e3a588169cd85a4340f087a6e44f311ad7cbffe5 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 26 Oct 2017 10:48:13 +0800 Subject: [PATCH 47/47] working on texture --- cocos2d/core/assets/CCAsset.js | 1 + cocos2d/core/load-pipeline/pack-downloader.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/assets/CCAsset.js b/cocos2d/core/assets/CCAsset.js index 2bf06afd3b..96655a46ee 100644 --- a/cocos2d/core/assets/CCAsset.js +++ b/cocos2d/core/assets/CCAsset.js @@ -183,6 +183,7 @@ cc.Asset = cc.Class({ /** * Set native file name for this asset. + * @seealso nativeUrl * * @method _setRawAsset * @param {String} filename diff --git a/cocos2d/core/load-pipeline/pack-downloader.js b/cocos2d/core/load-pipeline/pack-downloader.js index 739ba23f77..0dbd87ff13 100644 --- a/cocos2d/core/load-pipeline/pack-downloader.js +++ b/cocos2d/core/load-pipeline/pack-downloader.js @@ -100,7 +100,7 @@ module.exports = { if (Array.isArray(packedJson)) { unpackerData.unpacker = new Unpackers.JsonUnpacker(); } - else if (packedJson.type === TextureUnpacker.ID) { + else if (packedJson.type === Unpackers.TextureUnpacker.ID) { unpackerData.unpacker = new Unpackers.TextureUnpacker(); } unpackerData.unpacker.load(packIndices[packUuid], packedJson);