Browse Source

use new Date().getTime() when not in a node.js environment.

Ben Houston 12 years ago
parent
commit
c337d8beb7
1 changed files with 20 additions and 5 deletions
  1. 20 5
      utils/npm/header.js

+ 20 - 5
utils/npm/header.js

@@ -9,13 +9,28 @@ if( window.performance === undefined ) {
 
 }
 
-if( ( window.performance.now === undefined ) && ( process !== undefined ) && ( process.hrtime !== undefined ) ) {
+if( window.performance.now === undefined ) {
 
-	window.performance.now = function () {
+	// check if we are in a Node.js environment
+	if( ( process !== undefined ) && ( process.hrtime !== undefined ) ) {
 
-		var time = process.hrtime();
-		return ( time[0] + time[1] / 1e9 ) * 1000;
+		window.performance.now = function () {
 
-	};
+			var time = process.hrtime();
+			return ( time[0] + time[1] / 1e9 ) * 1000;
+
+		};
+
+	}
+	// if not Node.js revert to using the Date class
+	else {
+
+		window.performance.now = function() {
+
+			return new Date().getTime();
+
+		};
+
+	}
 
 }