mirror of
https://github.com/tweenjs/tween.js.git
synced 2025-12-08 20:16:12 +00:00
Ensure compatibility with ECMAScript 2015 modules
The module evaluation context of ECMAScript 2015 modules is not the global context. As such `this` does not point to the global `window` object. This is problematic for users of ECMAScript 2015 modules as the included `window.performance.now` polyfill will fail to work. Instead of `this`, the polyfill should be added to the global `window` object directly. This is unproblematic because the following code assumes that `performance.now` will be available under the global `window` object, i.e. the code was never execution environment agnostic. Furthermore, established polyfills like the one from Paul Irish also directly register the polyfill on the global `window` object. Fixes #209 [1] https://gist.github.com/paulirish/5438650
This commit is contained in:
parent
dbcdac705d
commit
0adef8e4a5
16
src/Tween.js
16
src/Tween.js
@ -8,10 +8,10 @@
|
||||
*/
|
||||
|
||||
// performance.now polyfill
|
||||
( function ( root ) {
|
||||
( function () {
|
||||
|
||||
if ( 'performance' in root === false ) {
|
||||
root.performance = {};
|
||||
if ( 'performance' in window === false ) {
|
||||
window.performance = {};
|
||||
}
|
||||
|
||||
// IE 8
|
||||
@ -19,16 +19,16 @@
|
||||
return new Date().getTime();
|
||||
} );
|
||||
|
||||
if ( 'now' in root.performance === false ) {
|
||||
var offset = root.performance.timing && root.performance.timing.navigationStart ? performance.timing.navigationStart
|
||||
: Date.now();
|
||||
if ( 'now' in window.performance === false ) {
|
||||
var offset = window.performance.timing && window.performance.timing.navigationStart ? window.performance.timing.navigationStart
|
||||
: Date.now();
|
||||
|
||||
root.performance.now = function () {
|
||||
window.performance.now = function () {
|
||||
return Date.now() - offset;
|
||||
};
|
||||
}
|
||||
|
||||
} )( this );
|
||||
} )();
|
||||
|
||||
var TWEEN = TWEEN || ( function () {
|
||||
|
||||
|
||||
@ -1,17 +1,12 @@
|
||||
// Make the tests work outside of browsers. The included polyfill will
|
||||
// automatically include a perf.now() implementation
|
||||
global.window = {};
|
||||
|
||||
// We will unit test both the original library and the minified version
|
||||
var TWEEN_uncompressed = require('../../src/Tween.js');
|
||||
var TWEEN_min = require('../../build/tween.min.js');
|
||||
var getTests = require('./tests');
|
||||
|
||||
// Make the tests work outside of browsers.
|
||||
global.window = {
|
||||
performance: {
|
||||
now: function() {
|
||||
return Date.now();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
'tween': getTests(TWEEN_uncompressed),
|
||||
'tween_min': getTests(TWEEN_min)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user