From 909e0c99251ee56ec35db0e08d5b1e6219ac8fbc Mon Sep 17 00:00:00 2001 From: Timmy Willison <4timmywil@gmail.com> Date: Mon, 11 Dec 2017 12:39:11 -0500 Subject: [PATCH] Core: deprecate jQuery.now Fixes gh-2959 Close gh-3884 --- src/ajax/var/nonce.js | 6 ++---- src/core.js | 2 -- src/deprecated.js | 2 ++ src/effects.js | 4 ++-- src/event.js | 2 +- test/unit/animation.js | 2 -- test/unit/core.js | 4 ++-- test/unit/deprecated.js | 6 ++++++ test/unit/effects.js | 2 -- test/unit/tween.js | 2 -- 10 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/ajax/var/nonce.js b/src/ajax/var/nonce.js index 6e23708a8..33d0cffb6 100644 --- a/src/ajax/var/nonce.js +++ b/src/ajax/var/nonce.js @@ -1,7 +1,5 @@ -define( [ - "../../core" -], function( jQuery ) { +define( function() { "use strict"; - return jQuery.now(); + return Date.now(); } ); diff --git a/src/core.js b/src/core.js index 97b4de2fc..06d0e83ad 100644 --- a/src/core.js +++ b/src/core.js @@ -424,8 +424,6 @@ jQuery.extend( { return proxy; }, - now: Date.now, - // jQuery.support is not used in Core but other projects attach their // properties to it so it needs to exist. support: support diff --git a/src/deprecated.js b/src/deprecated.js index 08c95538f..74907a289 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -41,4 +41,6 @@ jQuery.nodeName = nodeName; jQuery.isWindow = isWindow; jQuery.camelCase = camelCase; +jQuery.now = Date.now; + } ); diff --git a/src/effects.js b/src/effects.js index 1dec60e01..ec82d59f6 100644 --- a/src/effects.js +++ b/src/effects.js @@ -45,7 +45,7 @@ function createFxNow() { window.setTimeout( function() { fxNow = undefined; } ); - return ( fxNow = jQuery.now() ); + return ( fxNow = Date.now() ); } // Generate parameters to create a standard animation @@ -653,7 +653,7 @@ jQuery.fx.tick = function() { i = 0, timers = jQuery.timers; - fxNow = jQuery.now(); + fxNow = Date.now(); for ( ; i < timers.length; i++ ) { timer = timers[ i ]; diff --git a/src/event.js b/src/event.js index 071deb645..b10c43f8d 100644 --- a/src/event.js +++ b/src/event.js @@ -553,7 +553,7 @@ jQuery.Event = function( src, props ) { } // Create a timestamp if incoming event doesn't have one - this.timeStamp = src && src.timeStamp || jQuery.now(); + this.timeStamp = src && src.timeStamp || Date.now(); // Mark it as fixed this[ jQuery.expando ] = true; diff --git a/test/unit/animation.js b/test/unit/animation.js index 3c5e711d7..dfa00ac8d 100644 --- a/test/unit/animation.js +++ b/test/unit/animation.js @@ -19,13 +19,11 @@ QUnit.module( "animation", { this._oldInterval = jQuery.fx.interval; jQuery.fx.step = {}; jQuery.fx.interval = 10; - jQuery.now = Date.now; jQuery.Animation.prefilters = [ defaultPrefilter ]; jQuery.Animation.tweeners = { "*": [ defaultTweener ] }; }, teardown: function() { this.sandbox.restore(); - jQuery.now = Date.now; jQuery.fx.stop(); jQuery.fx.interval = this._oldInterval; window.requestAnimationFrame = oldRaf; diff --git a/test/unit/core.js b/test/unit/core.js index 276830ace..6778b14e9 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -190,10 +190,10 @@ QUnit.test( "globalEval execution after script injection (#7862)", function( ass script.src = baseURL + "mock.php?action=wait&wait=2&script=1"; - now = jQuery.now(); + now = Date.now(); document.body.appendChild( script ); - jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";" ); + jQuery.globalEval( "var strictEvalTest = " + Date.now() + ";" ); assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" ); } ); diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js index 6e44b3a45..962cad4fa 100644 --- a/test/unit/deprecated.js +++ b/test/unit/deprecated.js @@ -202,3 +202,9 @@ QUnit.test( "jQuery.camelCase()", function( assert ) { assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val ); } ); } ); + +QUnit.test( "jQuery.now", function( assert ) { + assert.expect( 1 ); + + assert.ok( typeof jQuery.now() === "number", "jQuery.now is a function" ); +} ); diff --git a/test/unit/effects.js b/test/unit/effects.js index c5f8d53c3..d023dc8c1 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -19,11 +19,9 @@ QUnit.module( "effects", { this._oldInterval = jQuery.fx.interval; jQuery.fx.step = {}; jQuery.fx.interval = 10; - jQuery.now = Date.now; }, teardown: function() { this.sandbox.restore(); - jQuery.now = Date.now; jQuery.fx.stop(); jQuery.fx.interval = this._oldInterval; window.requestAnimationFrame = oldRaf; diff --git a/test/unit/tween.js b/test/unit/tween.js index 28fcfad25..5d3d49d18 100644 --- a/test/unit/tween.js +++ b/test/unit/tween.js @@ -15,11 +15,9 @@ QUnit.module( "tween", { this._oldInterval = jQuery.fx.interval; jQuery.fx.step = {}; jQuery.fx.interval = 10; - jQuery.now = Date.now; }, teardown: function() { this.sandbox.restore(); - jQuery.now = Date.now; jQuery.fx.stop(); jQuery.fx.interval = this._oldInterval; window.requestAnimationFrame = oldRaf; -- 2.39.5