Skip to content

Change goog.now() to Date.now() #4623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/auth/src/autheventmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ fireauth.AuthEventManager.prototype.unsubscribe = function(handler) {
fireauth.AuthEventManager.prototype.hasProcessedAuthEvent_ =
function(authEvent) {
// Prevent duplicate event tracker from growing too large.
if (goog.now() - this.lastProcessedEventTime_ >=
if (Date.now() - this.lastProcessedEventTime_ >=
fireauth.AuthEventManager.EVENT_DUPLICATION_CACHE_DURATION) {
this.processedEvents_ = {};
this.lastProcessedEventTime_ = 0;
Expand Down Expand Up @@ -417,7 +417,7 @@ fireauth.AuthEventManager.prototype.saveProcessedAuthEvent_ =
this.processedEvents_[
/** @type {string} */ (authEvent.getUid())] = true;
// Save last processing time.
this.lastProcessedEventTime_ = goog.now();
this.lastProcessedEventTime_ = Date.now();
}
};

Expand Down
14 changes: 7 additions & 7 deletions packages/auth/src/cacherequest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,7 +42,7 @@ fireauth.CacheRequest = function() {
/** @private {?goog.Promise} The cached returned promise result. */
this.cachedResult_ = null;
/** @private {number} The expiration timestamp of the cached result. */
this.expirationTime_ = goog.now();
this.expirationTime_ = Date.now();
/** @private {number} The time to live from the caching point in time. */
this.ttl_ = 0;
/** @private {boolean} Whether to cache errors too. */
Expand All @@ -62,7 +62,7 @@ fireauth.CacheRequest.prototype.cache =
this.func_ = func;
this.self_ = self;
this.arguments_ = args;
this.expirationTime_ = goog.now();
this.expirationTime_ = Date.now();
this.ttl_ = ttl;
this.cacheErrors_ = !!opt_cacheErrors;

Expand All @@ -79,9 +79,9 @@ fireauth.CacheRequest.prototype.run = function() {
throw new Error('No available configuration cached!');
}
// If the result is not cached or the cache result is outdated.
if (!this.cachedResult_ || goog.now() >= this.expirationTime_) {
if (!this.cachedResult_ || Date.now() >= this.expirationTime_) {
// Set expiration of current request.
this.expirationTime_ = goog.now() + this.ttl_;
this.expirationTime_ = Date.now() + this.ttl_;
// Get new result and cache it.
this.cachedResult_ =
this.func_.apply(this.self_, this.arguments_).then(function(result) {
Expand All @@ -93,7 +93,7 @@ fireauth.CacheRequest.prototype.run = function() {
if (!self.cacheErrors_) {
// Do not cache errors if errors are not to be cached.
// This will bust the cached result. Otherwise the error is cached.
self.expirationTime_ = goog.now();
self.expirationTime_ = Date.now();
}
// Throw the returned error.
throw error;
Expand All @@ -108,5 +108,5 @@ fireauth.CacheRequest.prototype.run = function() {
fireauth.CacheRequest.prototype.purge = function() {
// Purge the cached results.
this.cachedResult_ = null;
this.expirationTime_ = goog.now();
this.expirationTime_ = Date.now();
};
2 changes: 1 addition & 1 deletion packages/auth/src/rpchandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ fireauth.RpcHandler.prototype.requestAuthEndpoint_ = function(
uri.setParameterValue('key', this.getApiKey());
// Check whether to append cachebuster to request.
if (opt_cachebuster) {
uri.setParameterValue('cb', goog.now().toString());
uri.setParameterValue('cb', Date.now().toString());
}
// Firebase allows GET endpoints.
var isGet = httpMethod == fireauth.RpcHandler.HttpMethod.GET;
Expand Down
6 changes: 3 additions & 3 deletions packages/auth/test/proactiverefresh_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,7 +71,7 @@ function setUp() {
// Operation to practively refresh.
operation = goog.testing.recordFunction(function() {
// Record last run time.
lastTimestamp = goog.now();
lastTimestamp = Date.now();
if (!forceRetryError) {
// Do not force error retry. Resolve successfully.
return goog.Promise.resolve();
Expand All @@ -84,7 +84,7 @@ function setUp() {
// Operation which throws an unrecoverable error.
unrecoverableOperation = goog.testing.recordFunction(function() {
// Record last run time.
lastTimestamp = goog.now();
lastTimestamp = Date.now();
// Throw unrecoverable error.
return goog.Promise.reject(
new fireauth.AuthError(fireauth.authenum.Error.INTERNAL_ERROR));
Expand Down