Skip to content

Commit 1e4886a

Browse files
committed
Remove global window and navigator usages from the core code.
1 parent 1e3e14e commit 1e4886a

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

examples/node/domstubs.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ DOMElement.prototype = {
120120
},
121121
}
122122

123-
global.window = global;
124-
125-
global.navigator = { userAgent: 'node' };
126-
127123
global.document = {
128124
childNodes : [],
129125

src/display/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
20022002
},
20032003

20042004
_scheduleNext: function InternalRenderTask__scheduleNext() {
2005-
if (this.useRequestAnimationFrame) {
2005+
if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
20062006
window.requestAnimationFrame(this._nextBound);
20072007
} else {
20082008
Promise.resolve(undefined).then(this._nextBound);

src/display/font_loader.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,20 @@ FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' &&
308308
//#if !(MOZCENTRAL || CHROME)
309309
Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
310310
get: function () {
311+
if (typeof navigator === 'undefined') {
312+
// node.js - we can pretend sync font loading is supported.
313+
return shadow(FontLoader, 'isSyncFontLoadingSupported', true);
314+
}
315+
311316
var supported = false;
312317

313318
// User agent string sniffing is bad, but there is no reliable way to tell
314319
// if font is fully loaded and ready to be used with canvas.
315-
var userAgent = window.navigator.userAgent;
316-
var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
320+
var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
317321
if (m && m[1] >= 14) {
318322
supported = true;
319323
}
320324
// TODO other browsers
321-
if (userAgent === 'node') {
322-
supported = true;
323-
}
324325
return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
325326
},
326327
enumerable: true,
@@ -378,8 +379,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
378379
var fontName = this.loadedName;
379380

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

385385
if (this.options.fontRegistry) {

src/frameworks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'use strict';
2121

2222
var useRequireEnsure = false;
23-
if (typeof module !== 'undefined' && module.require) {
23+
if (typeof window === 'undefined') {
2424
// node.js - disable worker and set require.ensure.
2525
isWorkerDisabled = true;
2626
if (typeof require.ensure === 'undefined') {

0 commit comments

Comments
 (0)