Skip to content

Commit

Permalink
Core: deprecate jQuery.now
Browse files Browse the repository at this point in the history
Fixes gh-2959
Close gh-3884
  • Loading branch information
timmywil committed Jan 8, 2018
1 parent 775caeb commit 909e0c9
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/ajax/var/nonce.js
@@ -1,7 +1,5 @@
define( [
"../../core"
], function( jQuery ) {
define( function() {
"use strict";

return jQuery.now();
return Date.now();
} );
2 changes: 0 additions & 2 deletions src/core.js
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/deprecated.js
Expand Up @@ -41,4 +41,6 @@ jQuery.nodeName = nodeName;
jQuery.isWindow = isWindow;
jQuery.camelCase = camelCase;

jQuery.now = Date.now;

} );
4 changes: 2 additions & 2 deletions src/effects.js
Expand Up @@ -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
Expand Down Expand Up @@ -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 ];
Expand Down
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions test/unit/animation.js
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/core.js
Expand Up @@ -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" );
} );

Expand Down
6 changes: 6 additions & 0 deletions test/unit/deprecated.js
Expand Up @@ -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" );
} );
2 changes: 0 additions & 2 deletions test/unit/effects.js
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions test/unit/tween.js
Expand Up @@ -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;
Expand Down

0 comments on commit 909e0c9

Please sign in to comment.