Skip to content

Commit

Permalink
Remove global window and navigator usages from the core code.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Apr 7, 2016
1 parent 1e3e14e commit 1e4886a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
4 changes: 0 additions & 4 deletions examples/node/domstubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ DOMElement.prototype = {
},
}

global.window = global;

global.navigator = { userAgent: 'node' };

global.document = {
childNodes : [],

Expand Down
2 changes: 1 addition & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
},

_scheduleNext: function InternalRenderTask__scheduleNext() {
if (this.useRequestAnimationFrame) {
if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
window.requestAnimationFrame(this._nextBound);
} else {
Promise.resolve(undefined).then(this._nextBound);
Expand Down
14 changes: 7 additions & 7 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,20 @@ FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
//#if !(MOZCENTRAL || CHROME)
Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
get: function () {
if (typeof navigator === 'undefined') {
// node.js - we can pretend sync font loading is supported.
return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
}

var supported = false;

// 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.
var userAgent = window.navigator.userAgent;
var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
if (m && m[1] >= 14) {
supported = true;
}
// TODO other browsers
if (userAgent === 'node') {
supported = true;
}
return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
},
enumerable: true,
Expand Down Expand Up @@ -378,8 +379,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
var fontName = this.loadedName;

// Add the font-face rule to the document
var url = ('url(data:' + this.mimetype + ';base64,' +
window.btoa(data) + ');');
var url = ('url(data:' + this.mimetype + ';base64,' + btoa(data) + ');');
var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';

if (this.options.fontRegistry) {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'use strict';

var useRequireEnsure = false;
if (typeof module !== 'undefined' && module.require) {
if (typeof window === 'undefined') {
// node.js - disable worker and set require.ensure.
isWorkerDisabled = true;
if (typeof require.ensure === 'undefined') {
Expand Down

0 comments on commit 1e4886a

Please sign in to comment.