Remove global window and navigator usages from the core code.

This commit is contained in:
Yury Delendik 2016-04-06 10:38:48 -05:00
parent 1e3e14e6b2
commit 1e4886a15a
4 changed files with 9 additions and 13 deletions

View File

@ -120,10 +120,6 @@ DOMElement.prototype = {
}, },
} }
global.window = global;
global.navigator = { userAgent: 'node' };
global.document = { global.document = {
childNodes : [], childNodes : [],

View File

@ -2002,7 +2002,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
}, },
_scheduleNext: function InternalRenderTask__scheduleNext() { _scheduleNext: function InternalRenderTask__scheduleNext() {
if (this.useRequestAnimationFrame) { if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
window.requestAnimationFrame(this._nextBound); window.requestAnimationFrame(this._nextBound);
} else { } else {
Promise.resolve(undefined).then(this._nextBound); Promise.resolve(undefined).then(this._nextBound);

View File

@ -308,19 +308,20 @@ FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
//#if !(MOZCENTRAL || CHROME) //#if !(MOZCENTRAL || CHROME)
Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', { Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
get: function () { get: function () {
if (typeof navigator === 'undefined') {
// node.js - we can pretend sync font loading is supported.
return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
}
var supported = false; var supported = false;
// User agent string sniffing is bad, but there is no reliable way to tell // User agent string sniffing is bad, but there is no reliable way to tell
// if font is fully loaded and ready to be used with canvas. // if font is fully loaded and ready to be used with canvas.
var userAgent = window.navigator.userAgent; var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
if (m && m[1] >= 14) { if (m && m[1] >= 14) {
supported = true; supported = true;
} }
// TODO other browsers // TODO other browsers
if (userAgent === 'node') {
supported = true;
}
return shadow(FontLoader, 'isSyncFontLoadingSupported', supported); return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
}, },
enumerable: true, enumerable: true,
@ -378,8 +379,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
var fontName = this.loadedName; var fontName = this.loadedName;
// Add the font-face rule to the document // Add the font-face rule to the document
var url = ('url(data:' + this.mimetype + ';base64,' + var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
window.btoa(data) + ');');
var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}'; var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
if (this.options.fontRegistry) { if (this.options.fontRegistry) {

View File

@ -20,7 +20,7 @@
'use strict'; 'use strict';
var useRequireEnsure = false; var useRequireEnsure = false;
if (typeof module !== 'undefined' && module.require) { if (typeof window === 'undefined') {
// node.js - disable worker and set require.ensure. // node.js - disable worker and set require.ensure.
isWorkerDisabled = true; isWorkerDisabled = true;
if (typeof require.ensure === 'undefined') { if (typeof require.ensure === 'undefined') {