Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jareguo committed Feb 5, 2016
1 parent 67d3235 commit 6c6a1d8
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 55 deletions.
12 changes: 9 additions & 3 deletions CCDebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,15 @@ cc._initDebugSetting = function (mode) {
* @param {any} obj - 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.warn = function(){
return console.warn.apply(console, arguments);
};
if (console.warn.bind) {
// use bind to avoid pollute call stacks
cc.warn = console.warn.bind(console);
}
else {
cc.warn = function() {
return console.warn.apply(console, arguments);
};
}
if(mode === cc.DebugMode.INFO) {
/**
* Outputs a message to the Cocos Creator Console (editor) or Web Console (runtime).
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/base-nodes/CCAtlasNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
THE SOFTWARE.
****************************************************************************/

EventTarget = require("../cocos2d/core/event/event-target");
var EventTarget = cc.EventTarget;

/**
* <p>cc.AtlasNode is a subclass of ccsg.Node, it knows how to render a TextureAtlas object. </p>
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/components/CCAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ var Animation = cc.Class({

/**
* Resumes an animation named name. If no name is supplied then resumes all paused animations that were started with this Animation.
* @method pause
* @method resume
* @param {String} [name] - The animation to resumes, if not supplied then resumes all paused animations.
*/
resume: function (name) {
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/CCConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @type {String}
* @name cc.ENGINE_VERSION
*/
window['CocosEngine'] = cc.ENGINE_VERSION = 'Cocos Creator v0.7';
window['CocosEngine'] = cc.ENGINE_VERSION = 'Cocos Creator v0.8.0';

/**
* <p>
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function _copyprop(name, source, target) {
/**
* This module provides some JavaScript utilities.
*
* @module js
* @module cc.js
*/
var js = {

Expand Down
21 changes: 15 additions & 6 deletions cocos2d/core/platform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ module.exports = {
);
},

callInNextTick: function (callback, p1, p2) {
if (callback) {
setTimeout(function () {
callback(p1, p2);
}, 1);
callInNextTick: CC_EDITOR ?
function (callback, p1, p2) {
if (callback) {
process.nextTick(function () {
callback(p1, p2);
});
}
}
:
function (callback, p1, p2) {
if (callback) {
setTimeout(function () {
callback(p1, p2);
}, 0);
}
}
}
};

if (CC_DEV) {
Expand Down
17 changes: 14 additions & 3 deletions cocos2d/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ if (CC_DEV) {
return cc.js.array.copy;
});



Object.defineProperty(cc._ComponentInSG.prototype, 'visible', {
get: function () {
cc.warn('The "visible" property of %s is deprecated, use "enabled" instead please.', cc.js.getClassName(this));
return this.enabled;
},
set: function (value) {
var printWarning = this.visible;
this.enabled = value;
}
});

function deprecateEnum (obj, oldPath, newPath, hasTypePrefixBefore) {
hasTypePrefixBefore = hasTypePrefixBefore !== false;
var enumDef = eval(newPath);
Expand Down Expand Up @@ -233,14 +246,12 @@ if (CC_DEV) {
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.MODE', 'cc.ParticleSystem.EmitterMode');
deprecateEnum(cc.ProgressTimer, 'cc.ProgressTimer.TYPE', 'cc.ProgressTimer.Type');
deprecateEnum(cc.game, 'cc.game.DEBUG_MODE', 'cc.DebugMode');
deprecateEnum(cc, 'cc', 'cc.Texture2D.WrapMode', false);
if (_ccsg.EditBox) {
deprecateEnum(cc, 'cc.KEYBOARD_RETURNTYPE', '_ccsg.EditBox.KeyboardReturnType');
deprecateEnum(cc, 'cc.EDITBOX_INPUT_MODE', '_ccsg.EditBox.InputMode');
deprecateEnum(cc, 'cc.EDITBOX_INPUT_FLAG', '_ccsg.EditBox.InputFlag');
}
cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
deprecateEnum(cc, 'cc', 'cc.Texture2D.WrapMode', false);
});

function markAsRemoved (ownerCtor, removedProps, ownerName) {
ownerName = ownerName || js.getClassName(ownerCtor);
Expand Down
2 changes: 0 additions & 2 deletions polyfill/index.js

This file was deleted.

6 changes: 4 additions & 2 deletions predefine.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ if (CC_DEV) {
cc._Test = {};
}

// predefine some modules for cocos
// polyfills
/* require('./polyfill/bind'); */
require('./polyfill/string');

require('./polyfill');
// predefine some modules for cocos
require('./cocos2d/core/platform/js');
require('./cocos2d/core/value-types');
require('./cocos2d/core/utils');
Expand Down
64 changes: 64 additions & 0 deletions test/qunit/lib/polyfill-for-phantom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
if (typeof CustomEvent === 'undefined') {
CustomEvent = function () {

}
}

if (typeof Set == 'undefined') {
// very simple polyfill
Set = function () {
this.values = [];
};
Set.prototype.has = function (value) {
return this.values.indexOf(value) !== -1;
};
Set.prototype.add = function (value) {
this.values.push(value);
};
}

// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind.html
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
//return function () {};
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}

var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};

// test this.prototype in case of native functions binding:
// - https://gist.github.com/jacomyal/4b7ae101a1cf6b985c60
if (this.prototype)
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();

return fBound;
};
}

var isPhantomJS = window.navigator.userAgent.indexOf('PhantomJS') !== -1;
if (isPhantomJS) {
QUnit.config.notrycatch = true;
window.onerror = function (msg, url, line, column, error) {
if (error) {
console.error(error.stack);
}
else {
console.error(msg + '.\n' + url + ':' + line);
}
};
// polyfill
var video = document.createElement("video");
video.constructor.prototype.canPlayType = function () { return ''; };
}
18 changes: 1 addition & 17 deletions test/qunit/lib/qunit-runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,7 @@
<script src="../test/qunit/lib/assert-deep-close.js"></script>
<script src="../test/qunit/lib/qunit-assert-callback.js"></script>
<script src="../test/qunit/lib/qunit-large-module.js"></script>
<script>
var isPhantomJS = window.navigator.userAgent.indexOf('PhantomJS') !== -1;
if (isPhantomJS) {
QUnit.config.notrycatch = true;
window.onerror = function (msg, url, line, column, error) {
if (error) {
console.error(error.stack);
}
else {
console.error(msg + '.\n' + url + ':' + line);
}
};
// polyfill
var video = document.createElement("video");
video.constructor.prototype.canPlayType = function () { return ''; };
}
</script>
<script src="../test/qunit/lib/polyfill-for-phantom.js"></script>
</head>
<body>
<div id="qunit"></div>
Expand Down
18 changes: 0 additions & 18 deletions test/qunit/unit/_polyfill-for-phantom.js

This file was deleted.

0 comments on commit 6c6a1d8

Please sign in to comment.