[Pkg-javascript-commits] [pdf.js] 345/414: Remove global window and navigator usages from the core code.

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:38 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 1e4886a15a29596bd548d058651620c7c0e67132
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Wed Apr 6 10:38:48 2016 -0500

    Remove global window and navigator usages from the core code.
---
 examples/node/domstubs.js  |  4 ----
 src/display/api.js         |  2 +-
 src/display/font_loader.js | 14 +++++++-------
 src/frameworks.js          |  2 +-
 4 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/examples/node/domstubs.js b/examples/node/domstubs.js
index fd7add6..b654d60 100644
--- a/examples/node/domstubs.js
+++ b/examples/node/domstubs.js
@@ -120,10 +120,6 @@ DOMElement.prototype = {
   },
 }
 
-global.window = global;
-
-global.navigator = { userAgent: 'node' };
-
 global.document = {
   childNodes : [],
 
diff --git a/src/display/api.js b/src/display/api.js
index 17b280d..3dfb939 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -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);
diff --git a/src/display/font_loader.js b/src/display/font_loader.js
index e6b09bb..74f676c 100644
--- a/src/display/font_loader.js
+++ b/src/display/font_loader.js
@@ -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,
@@ -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) {
diff --git a/src/frameworks.js b/src/frameworks.js
index ac21dcb..9b5109c 100644
--- a/src/frameworks.js
+++ b/src/frameworks.js
@@ -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') {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list