Clock (start, getDelta) broken in Node.js r74, ‘performance.now’ not defined

The functionality of THREE.Clock broke in release r74 when attempting to run in Node.js (installed via npm package ‘three’). Functions like .start() & .getDelta() complain about ReferenceError: performance is not defined (as in performance.now()).

I might be missing something, but it would seem the changes in 71ddb80 removed the polyfill for performance.now necessary to run THREE (Clock) in Node; as far as I can tell, Node.js doesn’t have a global performance implemented.
I am not sure if/how much issues #7787, or #7800 are involved.

Running w/ r74 (current broken state):

$ node
> var THREE = require('three');
undefined
> var myclock = new THREE.Clock();
undefined
> myclock.start()
ReferenceError: performance is not defined
    at THREE.Clock.start (/data/users/rlinsalata/workspaces/js_ws/node_playground/node_modules/three/three.js:7911:20)
    at repl:1:10
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)

> myclock.getDelta()
ReferenceError: performance is not defined
    at THREE.Clock.start (/data/users/rlinsalata/workspaces/js_ws/node_playground/node_modules/three/three.js:7911:20)
    at THREE.Clock.getDelta (/data/users/rlinsalata/workspaces/js_ws/node_playground/node_modules/three/three.js:7938:9)
    at repl:1:10
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
> THREE.REVISION
'74'

Running w/ r73 (old working state):

$ node
> var THREE = require('three');
> THREE.REVISION
'73'
> var myclock = new THREE.Clock();
> myclock.start()
> myclock.getDelta()
20.876
> myclock.getDelta()
1.437
> myclock.getDelta()
4.405

Version Info:
Three version r74
npm package ‘three’ three@0.74
Node v5.2.0
Ubuntu 14.04

Author: Fantashit

2 thoughts on “Clock (start, getDelta) broken in Node.js r74, ‘performance.now’ not defined

  1. For me, not working on iOS8 based devices. I have added this r73 polyfill and works again:

    //
    
    if ( self.performance === undefined ) {
    
        self.performance = {};
    
    }
    
    if ( self.performance.now === undefined ) {
    
        ( function () {
    
            var start = Date.now();
    
            self.performance.now = function () {
    
                return Date.now() - start;
    
            }
    
        } )();
    
    }
    

Comments are closed.