diff --git a/CCDebugger.js b/CCDebugger.js index 8ff56bb3b4..e59b724c39 100644 --- a/CCDebugger.js +++ b/CCDebugger.js @@ -439,9 +439,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). diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index acdc4632f5..0872824337 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -626,7 +626,8 @@ cc.Audio = cc._Class.extend({ /** * cc.audioEngine is the singleton object, it provide simple audio APIs. - * @namespace + * @class audioEngine + * @static */ cc.audioEngine = { _currMusic: null, @@ -636,12 +637,14 @@ cc.Audio = cc._Class.extend({ /** * Indicates whether any background music can be played or not. + * @method willPlayMusic * @returns {boolean} true if the background music is playing, otherwise false */ willPlayMusic: function(){return false;}, /** * Play music. + * @method playMusic * @param {String} url The path of the music file without filename extension. * @param {Boolean} loop Whether the music loop or not. * @example @@ -666,6 +669,7 @@ cc.Audio = cc._Class.extend({ /** * Stop playing music. + * @method stopMusic * @param {Boolean} [releaseData] If release the music data or not.As default value is false. * @example * //example @@ -682,6 +686,7 @@ cc.Audio = cc._Class.extend({ /** * Pause playing music. + * @method pauseMusic * @example * //example * cc.audioEngine.pauseMusic(); @@ -694,6 +699,7 @@ cc.Audio = cc._Class.extend({ /** * Resume playing music. + * @method resumeMusic * @example * //example * cc.audioEngine.resumeMusic(); @@ -706,6 +712,7 @@ cc.Audio = cc._Class.extend({ /** * Rewind playing music. + * @method rewindMusic * @example * //example * cc.audioEngine.rewindMusic(); @@ -720,6 +727,7 @@ cc.Audio = cc._Class.extend({ /** * The volume of the music max value is 1.0,the min value is 0.0 . + * @method getMusicVolume * @return {Number} * @example * //example @@ -731,6 +739,7 @@ cc.Audio = cc._Class.extend({ /** * Set the volume of music. + * @method setMusicVolume * @param {Number} volume Volume must be in 0.0~1.0 . * @example * //example @@ -751,6 +760,7 @@ cc.Audio = cc._Class.extend({ /** * Whether the music is playing. + * @method isMusicPlaying * @return {Boolean} If is playing return true,or return false. * @example * //example @@ -775,6 +785,7 @@ cc.Audio = cc._Class.extend({ _effectVolume: 1, /** * Play sound effect. + * @method playEffect * @param {String} url The path of the sound effect with filename extension. * @param {Boolean} loop Whether to loop the effect playing, default value is false * @return {Number|null} the audio id @@ -827,6 +838,7 @@ cc.Audio = cc._Class.extend({ /** * Set the volume of sound effects. + * @method setEffectsVolume * @param {Number} volume Volume must be in 0.0~1.0 . * @example * //example @@ -851,6 +863,7 @@ cc.Audio = cc._Class.extend({ /** * The volume of the effects max value is 1.0,the min value is 0.0 . + * @method getEffectsVolume * @return {Number} * @example * //example @@ -862,6 +875,7 @@ cc.Audio = cc._Class.extend({ /** * Pause playing sound effect. + * @method pauseEffect * @param {Number} cc.Audio The return value of function playEffect. * @example * //example @@ -875,6 +889,7 @@ cc.Audio = cc._Class.extend({ /** * Pause all playing sound effect. + * @method pauseAllEffects * @example * //example * cc.audioEngine.pauseAllEffects(); @@ -893,6 +908,7 @@ cc.Audio = cc._Class.extend({ /** * Resume playing sound effect. + * @method resumeEffect * @param {Number} cc.Audio The return value of function playEffect. * @audioID * //example @@ -905,6 +921,7 @@ cc.Audio = cc._Class.extend({ /** * Resume all playing sound effect + * @method resumeAllEffects * @example * //example * cc.audioEngine.resumeAllEffects(); @@ -921,6 +938,7 @@ cc.Audio = cc._Class.extend({ /** * Stop playing sound effect. + * @method stopEffect * @param {Number} cc.Audio The return value of function playEffect. * @example * //example @@ -933,6 +951,7 @@ cc.Audio = cc._Class.extend({ /** * Stop all playing sound effects. + * @method stopAllEffects * @example * //example * cc.audioEngine.stopAllEffects(); @@ -949,6 +968,7 @@ cc.Audio = cc._Class.extend({ /** * Unload the preloaded effect from internal buffer + * @method unloadEffect * @param {String} url * @example * //example @@ -968,6 +988,7 @@ cc.Audio = cc._Class.extend({ /** * End music and effects. + * @method end */ end: function(){ this.stopMusic(); diff --git a/cocos2d/core/base-nodes/CCAtlasNode.js b/cocos2d/core/base-nodes/CCAtlasNode.js index f7f47f2253..9fa71339d7 100644 --- a/cocos2d/core/base-nodes/CCAtlasNode.js +++ b/cocos2d/core/base-nodes/CCAtlasNode.js @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -EventTarget = require("../cocos2d/core/event/event-target"); +var EventTarget = cc.EventTarget; /** *

cc.AtlasNode is a subclass of ccsg.Node, it knows how to render a TextureAtlas object.

diff --git a/cocos2d/core/components/CCAnimation.js b/cocos2d/core/components/CCAnimation.js index 794a68f6c2..f8edaef626 100644 --- a/cocos2d/core/components/CCAnimation.js +++ b/cocos2d/core/components/CCAnimation.js @@ -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) { diff --git a/cocos2d/core/components/CCAudioSource.js b/cocos2d/core/components/CCAudioSource.js index e3a62f1ac1..80c88ae3f1 100644 --- a/cocos2d/core/components/CCAudioSource.js +++ b/cocos2d/core/components/CCAudioSource.js @@ -26,7 +26,7 @@ /** * Audio Source. - * @class AudioScource + * @class AudioSource * @extends Component */ diff --git a/cocos2d/core/platform/CCConfig.js b/cocos2d/core/platform/CCConfig.js index e82d40309e..cd2fbf2495 100644 --- a/cocos2d/core/platform/CCConfig.js +++ b/cocos2d/core/platform/CCConfig.js @@ -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'; /** *

diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js index b91df6bbfb..f4a1d5f162 100644 --- a/cocos2d/core/platform/js.js +++ b/cocos2d/core/platform/js.js @@ -46,7 +46,7 @@ function _copyprop(name, source, target) { /** * This module provides some JavaScript utilities. * - * @module js + * @module cc.js */ var js = { diff --git a/cocos2d/core/platform/utils.js b/cocos2d/core/platform/utils.js index 18e86b7c0b..fb34510757 100644 --- a/cocos2d/core/platform/utils.js +++ b/cocos2d/core/platform/utils.js @@ -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) { diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index f2bf1f13f5..b2e83104bc 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -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); @@ -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); diff --git a/polyfill/index.js b/polyfill/index.js deleted file mode 100644 index 7cdd8d008f..0000000000 --- a/polyfill/index.js +++ /dev/null @@ -1,2 +0,0 @@ -require('./bind'); -require('./string'); diff --git a/predefine.js b/predefine.js index 67043f93df..6fee5427e2 100644 --- a/predefine.js +++ b/predefine.js @@ -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'); diff --git a/test/qunit/lib/polyfill-for-phantom.js b/test/qunit/lib/polyfill-for-phantom.js new file mode 100644 index 0000000000..2612406315 --- /dev/null +++ b/test/qunit/lib/polyfill-for-phantom.js @@ -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 ''; }; +} diff --git a/test/qunit/lib/qunit-runner.html b/test/qunit/lib/qunit-runner.html index 0fcdfa3bfc..b05e359afe 100644 --- a/test/qunit/lib/qunit-runner.html +++ b/test/qunit/lib/qunit-runner.html @@ -18,23 +18,7 @@ qunit references: - +

diff --git a/test/qunit/unit/_polyfill-for-phantom.js b/test/qunit/unit/_polyfill-for-phantom.js deleted file mode 100644 index 09ebd1c9e8..0000000000 --- a/test/qunit/unit/_polyfill-for-phantom.js +++ /dev/null @@ -1,18 +0,0 @@ -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); - }; -}