mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Restore the btoa
/atob
polyfills for Node.js
These were removed in PR 9170, since they were unused in the browsers that we'll support in PDF.js version `2.0`. However looking at the output of Travis, where a subset of the unit-tests are run using Node.js, there's warnings about `btoa` being undefined. This doesn't appear to cause any errors, which probably explains why we didn't notice this before (despite PR 9201).
This commit is contained in:
parent
ba0a3aebd0
commit
0e1b5589e7
16 changed files with 73 additions and 28 deletions
|
@ -15,11 +15,12 @@
|
|||
|
||||
import {
|
||||
arrayByteLength, arraysToBytes, assert, createPromiseCapability, info,
|
||||
InvalidPDFException, isNodeJS, MessageHandler, MissingPDFException,
|
||||
PasswordException, setVerbosityLevel, UnexpectedResponseException,
|
||||
UnknownErrorException, UNSUPPORTED_FEATURES, warn, XRefParseException
|
||||
InvalidPDFException, MessageHandler, MissingPDFException, PasswordException,
|
||||
setVerbosityLevel, UnexpectedResponseException, UnknownErrorException,
|
||||
UNSUPPORTED_FEATURES, warn, XRefParseException
|
||||
} from '../shared/util';
|
||||
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
||||
import isNodeJS from '../shared/is_node';
|
||||
import { Ref } from './primitives';
|
||||
|
||||
var WorkerTask = (function WorkerTaskClosure() {
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
/* globals __non_webpack_require__ */
|
||||
|
||||
import {
|
||||
createObjectURL, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, isNodeJS,
|
||||
isNum, OPS, Util, warn
|
||||
createObjectURL, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, ImageKind, isNum, OPS,
|
||||
Util, warn
|
||||
} from '../shared/util';
|
||||
import { DOMSVGFactory } from './dom_utils';
|
||||
import isNodeJS from '../shared/is_node';
|
||||
|
||||
var SVGGraphics = function() {
|
||||
throw new Error('Not implemented: SVGGraphics');
|
||||
|
|
|
@ -31,7 +31,8 @@ var pdfjsDisplaySVG = require('./display/svg.js');
|
|||
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
if (pdfjsSharedUtil.isNodeJS()) {
|
||||
const isNodeJS = require('./shared/is_node.js');
|
||||
if (isNodeJS()) {
|
||||
var PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
||||
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFNodeStream);
|
||||
} else if (typeof Response !== 'undefined' && 'body' in Response.prototype &&
|
||||
|
|
|
@ -22,6 +22,7 @@ if ((typeof PDFJSDev === 'undefined' ||
|
|||
(typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked)) {
|
||||
|
||||
var globalScope = require('./global_scope');
|
||||
const isNodeJS = require('./is_node');
|
||||
|
||||
var userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || '';
|
||||
var isAndroid = /Android/.test(userAgent);
|
||||
|
@ -41,6 +42,28 @@ if (typeof PDFJS === 'undefined') {
|
|||
|
||||
PDFJS.compatibilityChecked = true;
|
||||
|
||||
// Support: Node.js
|
||||
(function checkNodeBtoa() {
|
||||
if (globalScope.btoa || !isNodeJS()) {
|
||||
return;
|
||||
}
|
||||
globalScope.btoa = function(chars) {
|
||||
// eslint-disable-next-line no-undef
|
||||
return Buffer.from(chars, 'binary').toString('base64');
|
||||
};
|
||||
})();
|
||||
|
||||
// Support: Node.js
|
||||
(function checkNodeAtob() {
|
||||
if (globalScope.atob || !isNodeJS()) {
|
||||
return;
|
||||
}
|
||||
globalScope.atob = function(input) {
|
||||
// eslint-disable-next-line no-undef
|
||||
return Buffer.from(input, 'base64').toString('binary');
|
||||
};
|
||||
})();
|
||||
|
||||
// Checks if possible to use URL.createObjectURL()
|
||||
// Support: IE, Chrome on iOS
|
||||
(function checkOnBlobSupport() {
|
||||
|
|
19
src/shared/is_node.js
Normal file
19
src/shared/is_node.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* Copyright 2018 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals module, process */
|
||||
|
||||
module.exports = function isNodeJS() {
|
||||
return typeof process === 'object' && process + '' === '[object process]';
|
||||
};
|
|
@ -1089,11 +1089,6 @@ function isSpace(ch) {
|
|||
return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
|
||||
}
|
||||
|
||||
function isNodeJS() {
|
||||
// eslint-disable-next-line no-undef
|
||||
return typeof process === 'object' && process + '' === '[object process]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Promise Capability object.
|
||||
*
|
||||
|
@ -1633,7 +1628,6 @@ export {
|
|||
isNum,
|
||||
isString,
|
||||
isSpace,
|
||||
isNodeJS,
|
||||
isSameOrigin,
|
||||
createValidAbsoluteUrl,
|
||||
isLittleEndian,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue