Replace 'global' with 'globalThis'

This commit is contained in:
Daniel Huigens 2020-04-27 21:52:21 +02:00
parent 5b148089c3
commit cde282d4f1
13 changed files with 35 additions and 35 deletions

4
package-lock.json generated
View File

@ -4920,8 +4920,8 @@
} }
}, },
"web-stream-tools": { "web-stream-tools": {
"version": "github:openpgpjs/web-stream-tools#b70529205ecaa41139311e874bdab0f8a9358a94", "version": "github:openpgpjs/web-stream-tools#5e6cb1a976d50c421091907615cf7cce77ac4f2a",
"from": "github:openpgpjs/web-stream-tools#b70529205ecaa41139311e874bdab0f8a9358a94", "from": "github:openpgpjs/web-stream-tools#5e6cb1a976d50c421091907615cf7cce77ac4f2a",
"dev": true, "dev": true,
"requires": { "requires": {
"@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.5", "@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.5",

View File

@ -74,7 +74,7 @@
"sinon": "^4.3.0", "sinon": "^4.3.0",
"text-encoding-utf-8": "^1.0.2", "text-encoding-utf-8": "^1.0.2",
"tweetnacl": "github:openpgpjs/tweetnacl-js#3dae25bd3eaa77173f3405676b595721dde92eec", "tweetnacl": "github:openpgpjs/tweetnacl-js#3dae25bd3eaa77173f3405676b595721dde92eec",
"web-stream-tools": "github:openpgpjs/web-stream-tools#b70529205ecaa41139311e874bdab0f8a9358a94", "web-stream-tools": "github:openpgpjs/web-stream-tools#5e6cb1a976d50c421091907615cf7cce77ac4f2a",
"whatwg-fetch": "^2.0.3" "whatwg-fetch": "^2.0.3"
}, },
"dependencies": { "dependencies": {

View File

@ -216,10 +216,10 @@ export default {
* @memberof module:config * @memberof module:config
* @property {Set<Integer>} reject_hash_algorithms Reject insecure hash algorithms {@link module:enums.hash} * @property {Set<Integer>} reject_hash_algorithms Reject insecure hash algorithms {@link module:enums.hash}
*/ */
rejectHashAlgorithms: new global.Set([enums.hash.md5, enums.hash.ripemd]), rejectHashAlgorithms: new globalThis.Set([enums.hash.md5, enums.hash.ripemd]),
/** /**
* @memberof module:config * @memberof module:config
* @property {Set<Integer>} reject_message_hash_algorithms Reject insecure message hash algorithms {@link module:enums.hash} * @property {Set<Integer>} reject_message_hash_algorithms Reject insecure message hash algorithms {@link module:enums.hash}
*/ */
rejectMessageHashAlgorithms: new global.Set([enums.hash.md5, enums.hash.ripemd, enums.hash.sha1]) rejectMessageHashAlgorithms: new globalThis.Set([enums.hash.md5, enums.hash.ripemd, enums.hash.sha1])
}; };

View File

@ -15,7 +15,7 @@ function LocalStorage() {}
* if config is null the default config will be used * if config is null the default config will be used
*/ */
LocalStorage.prototype.read = function () { LocalStorage.prototype.read = function () {
const raw = global.localStorage.getItem("config"); const raw = globalThis.localStorage.getItem("config");
const cf = (raw === null ? null : JSON.parse(raw)); const cf = (raw === null ? null : JSON.parse(raw));
if (cf === null) { if (cf === null) {
this.config = this.default_config; this.config = this.default_config;
@ -29,7 +29,7 @@ LocalStorage.prototype.read = function () {
* Writes the config to HTML5 local storage * Writes the config to HTML5 local storage
*/ */
LocalStorage.prototype.write = function () { LocalStorage.prototype.write = function () {
global.localStorage.setItem("config", JSON.stringify(this.config)); globalThis.localStorage.setItem("config", JSON.stringify(this.config));
}; };
export default LocalStorage; export default LocalStorage;

View File

@ -39,7 +39,7 @@ export function keyFromPublic(indutnyCurve, pub) {
} }
/** /**
* Load elliptic on demand to global.openpgp.elliptic * Load elliptic on demand to globalThis.openpgp.elliptic
* @returns {Promise<elliptic>} * @returns {Promise<elliptic>}
*/ */
async function loadEllipticPromise() { async function loadEllipticPromise() {
@ -50,10 +50,10 @@ async function loadEllipticPromise() {
const mainUrl = URL.createObjectURL(new Blob([ellipticContents], { type: 'text/javascript' })); const mainUrl = URL.createObjectURL(new Blob([ellipticContents], { type: 'text/javascript' }));
await loadScript(mainUrl); await loadScript(mainUrl);
URL.revokeObjectURL(mainUrl); URL.revokeObjectURL(mainUrl);
if (!global.openpgp.elliptic) { if (!globalThis.openpgp.elliptic) {
throw new Error('Elliptic library failed to load correctly'); throw new Error('Elliptic library failed to load correctly');
} }
return global.openpgp.elliptic; return globalThis.openpgp.elliptic;
} }
let ellipticPromise; let ellipticPromise;

View File

@ -186,7 +186,7 @@ export default {
if (util.getWebCrypto()) { if (util.getWebCrypto()) {
let keyPair; let keyPair;
let keyGenOpt; let keyGenOpt;
if ((global.crypto && global.crypto.subtle) || global.msCrypto) { if ((globalThis.crypto && globalThis.crypto.subtle) || globalThis.msCrypto) {
// current standard spec // current standard spec
keyGenOpt = { keyGenOpt = {
name: 'RSASSA-PKCS1-v1_5', name: 'RSASSA-PKCS1-v1_5',
@ -198,7 +198,7 @@ export default {
}; };
keyPair = webCrypto.generateKey(keyGenOpt, true, ['sign', 'verify']); keyPair = webCrypto.generateKey(keyGenOpt, true, ['sign', 'verify']);
keyPair = await promisifyIE11Op(keyPair, 'Error generating RSA key pair.'); keyPair = await promisifyIE11Op(keyPair, 'Error generating RSA key pair.');
} else if (global.crypto && global.crypto.webkitSubtle) { } else if (globalThis.crypto && globalThis.crypto.webkitSubtle) {
// outdated spec implemented by old Webkit // outdated spec implemented by old Webkit
keyGenOpt = { keyGenOpt = {
name: 'RSA-OAEP', name: 'RSA-OAEP',

View File

@ -41,8 +41,8 @@ export default {
const buf = new Uint8Array(length); const buf = new Uint8Array(length);
if (typeof crypto !== 'undefined' && crypto.getRandomValues) { if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
crypto.getRandomValues(buf); crypto.getRandomValues(buf);
} else if (typeof global !== 'undefined' && typeof global.msCrypto === 'object' && typeof global.msCrypto.getRandomValues === 'function') { } else if (typeof globalThis !== 'undefined' && typeof globalThis.msCrypto === 'object' && typeof globalThis.msCrypto.getRandomValues === 'function') {
global.msCrypto.getRandomValues(buf); globalThis.msCrypto.getRandomValues(buf);
} else if (nodeCrypto) { } else if (nodeCrypto) {
const bytes = nodeCrypto.randomBytes(buf.length); const bytes = nodeCrypto.randomBytes(buf.length);
buf.set(bytes); buf.set(bytes);

View File

@ -32,7 +32,7 @@ import config from './config';
*/ */
function HKP(keyServerBaseUrl) { function HKP(keyServerBaseUrl) {
this._baseUrl = keyServerBaseUrl || config.keyserver; this._baseUrl = keyServerBaseUrl || config.keyserver;
this._fetch = typeof global.fetch === 'function' ? global.fetch : require('node-fetch'); this._fetch = typeof globalThis.fetch === 'function' ? globalThis.fetch : require('node-fetch');
} }
/** /**

View File

@ -37,8 +37,8 @@ function LocalStore(prefix) {
prefix = prefix || 'openpgp-'; prefix = prefix || 'openpgp-';
this.publicKeysItem = prefix + this.publicKeysItem; this.publicKeysItem = prefix + this.publicKeysItem;
this.privateKeysItem = prefix + this.privateKeysItem; this.privateKeysItem = prefix + this.privateKeysItem;
if (typeof global !== 'undefined' && global.localStorage) { if (typeof globalThis !== 'undefined' && globalThis.localStorage) {
this.storage = global.localStorage; this.storage = globalThis.localStorage;
} else { } else {
this.storage = new (require('node-localstorage').LocalStorage)(config.nodeStore); this.storage = new (require('node-localstorage').LocalStorage)(config.nodeStore);
} }

View File

@ -48,9 +48,9 @@ import './polyfills';
import util from './util'; import util from './util';
let toNativeReadable; let toNativeReadable;
if (global.ReadableStream) { if (globalThis.ReadableStream) {
try { try {
toNativeReadable = createReadableStreamWrapper(global.ReadableStream); toNativeReadable = createReadableStreamWrapper(globalThis.ReadableStream);
} catch (e) {} } catch (e) {}
} }

View File

@ -5,14 +5,14 @@
* @module polyfills * @module polyfills
*/ */
if (typeof global !== 'undefined') { if (typeof globalThis !== 'undefined') {
/******************************************************************** /********************************************************************
* NOTE: This list is duplicated in Gruntfile.js, * * NOTE: This list is duplicated in Gruntfile.js, *
* so that these polyfills are only included in the compat bundle. * * so that these polyfills are only included in the compat bundle. *
********************************************************************/ ********************************************************************/
try { try {
if (typeof global.fetch === 'undefined') { if (typeof globalThis.fetch === 'undefined') {
require('whatwg-fetch'); require('whatwg-fetch');
} }
if (typeof Array.prototype.fill === 'undefined') { if (typeof Array.prototype.fill === 'undefined') {
@ -48,11 +48,11 @@ if (typeof global !== 'undefined') {
if (typeof TextEncoder === 'undefined') { if (typeof TextEncoder === 'undefined') {
const nodeUtil = require('util') || {}; const nodeUtil = require('util') || {};
global.TextEncoder = nodeUtil.TextEncoder; globalThis.TextEncoder = nodeUtil.TextEncoder;
global.TextDecoder = nodeUtil.TextDecoder; globalThis.TextDecoder = nodeUtil.TextDecoder;
} }
if (typeof TextEncoder === 'undefined') { if (typeof TextEncoder === 'undefined') {
const textEncoding = require('text-encoding-utf-8'); const textEncoding = require('text-encoding-utf-8');
global.TextEncoder = textEncoding.TextEncoder; globalThis.TextEncoder = textEncoding.TextEncoder;
global.TextDecoder = textEncoding.TextDecoder; globalThis.TextDecoder = textEncoding.TextDecoder;
} }

View File

@ -52,7 +52,7 @@ export default {
*/ */
restoreStreams: function(obj, streaming) { restoreStreams: function(obj, streaming) {
if (Object.prototype.toString.call(obj) === '[object MessagePort]') { if (Object.prototype.toString.call(obj) === '[object MessagePort]') {
return new (streaming === 'web' ? global.ReadableStream : stream.ReadableStream)({ return new (streaming === 'web' ? globalThis.ReadableStream : stream.ReadableStream)({
pull(controller) { pull(controller) {
return new Promise(resolve => { return new Promise(resolve => {
obj.onmessage = evt => { obj.onmessage = evt => {
@ -486,7 +486,7 @@ export default {
return; return;
} }
return typeof global !== 'undefined' && global.crypto && global.crypto.subtle; return typeof globalThis !== 'undefined' && globalThis.crypto && globalThis.crypto.subtle;
}, },
/** /**
@ -501,12 +501,12 @@ export default {
return; return;
} }
if (typeof global !== 'undefined') { if (typeof globalThis !== 'undefined') {
if (global.crypto) { if (globalThis.crypto) {
return global.crypto.subtle || global.crypto.webkitSubtle; return globalThis.crypto.subtle || globalThis.crypto.webkitSubtle;
} }
if (global.msCrypto) { if (globalThis.msCrypto) {
return global.msCrypto.subtle; return globalThis.msCrypto.subtle;
} }
} }
}, },
@ -515,8 +515,8 @@ export default {
* Detect Node.js runtime. * Detect Node.js runtime.
*/ */
detectNode: function() { detectNode: function() {
return typeof global.process === 'object' && return typeof globalThis.process === 'object' &&
typeof global.process.versions === 'object'; typeof globalThis.process.versions === 'object';
}, },
/** /**

View File

@ -31,7 +31,7 @@ import * as keyMod from './key';
* @constructor * @constructor
*/ */
function WKD() { function WKD() {
this._fetch = typeof global.fetch === 'function' ? global.fetch : require('node-fetch'); this._fetch = typeof globalThis.fetch === 'function' ? globalThis.fetch : require('node-fetch');
} }
/** /**