From cde282d4f1dec6ccf3bb3458e26cfadfdc469b41 Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Mon, 27 Apr 2020 21:52:21 +0200 Subject: [PATCH] Replace 'global' with 'globalThis' --- package-lock.json | 4 ++-- package.json | 2 +- src/config/config.js | 4 ++-- src/config/localStorage.js | 4 ++-- src/crypto/public_key/elliptic/indutnyKey.js | 6 +++--- src/crypto/public_key/rsa.js | 4 ++-- src/crypto/random.js | 4 ++-- src/hkp.js | 2 +- src/keyring/localstore.js | 4 ++-- src/openpgp.js | 4 ++-- src/polyfills.js | 12 ++++++------ src/util.js | 18 +++++++++--------- src/wkd.js | 2 +- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1ce15039..2ddfc8f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4920,8 +4920,8 @@ } }, "web-stream-tools": { - "version": "github:openpgpjs/web-stream-tools#b70529205ecaa41139311e874bdab0f8a9358a94", - "from": "github:openpgpjs/web-stream-tools#b70529205ecaa41139311e874bdab0f8a9358a94", + "version": "github:openpgpjs/web-stream-tools#5e6cb1a976d50c421091907615cf7cce77ac4f2a", + "from": "github:openpgpjs/web-stream-tools#5e6cb1a976d50c421091907615cf7cce77ac4f2a", "dev": true, "requires": { "@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.5", diff --git a/package.json b/package.json index beb37fab..c6df4c71 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "sinon": "^4.3.0", "text-encoding-utf-8": "^1.0.2", "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" }, "dependencies": { diff --git a/src/config/config.js b/src/config/config.js index b5a1c5aa..aacb3b76 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -216,10 +216,10 @@ export default { * @memberof module:config * @property {Set} 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 * @property {Set} 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]) }; diff --git a/src/config/localStorage.js b/src/config/localStorage.js index fb6e20f0..8b1f0947 100644 --- a/src/config/localStorage.js +++ b/src/config/localStorage.js @@ -15,7 +15,7 @@ function LocalStorage() {} * if config is null the default config will be used */ LocalStorage.prototype.read = function () { - const raw = global.localStorage.getItem("config"); + const raw = globalThis.localStorage.getItem("config"); const cf = (raw === null ? null : JSON.parse(raw)); if (cf === null) { this.config = this.default_config; @@ -29,7 +29,7 @@ LocalStorage.prototype.read = function () { * Writes the config to HTML5 local storage */ LocalStorage.prototype.write = function () { - global.localStorage.setItem("config", JSON.stringify(this.config)); + globalThis.localStorage.setItem("config", JSON.stringify(this.config)); }; export default LocalStorage; diff --git a/src/crypto/public_key/elliptic/indutnyKey.js b/src/crypto/public_key/elliptic/indutnyKey.js index 30f2170b..f92790ce 100644 --- a/src/crypto/public_key/elliptic/indutnyKey.js +++ b/src/crypto/public_key/elliptic/indutnyKey.js @@ -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} */ async function loadEllipticPromise() { @@ -50,10 +50,10 @@ async function loadEllipticPromise() { const mainUrl = URL.createObjectURL(new Blob([ellipticContents], { type: 'text/javascript' })); await loadScript(mainUrl); URL.revokeObjectURL(mainUrl); - if (!global.openpgp.elliptic) { + if (!globalThis.openpgp.elliptic) { throw new Error('Elliptic library failed to load correctly'); } - return global.openpgp.elliptic; + return globalThis.openpgp.elliptic; } let ellipticPromise; diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index 17e80ed7..26e49d70 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -186,7 +186,7 @@ export default { if (util.getWebCrypto()) { let keyPair; let keyGenOpt; - if ((global.crypto && global.crypto.subtle) || global.msCrypto) { + if ((globalThis.crypto && globalThis.crypto.subtle) || globalThis.msCrypto) { // current standard spec keyGenOpt = { name: 'RSASSA-PKCS1-v1_5', @@ -198,7 +198,7 @@ export default { }; keyPair = webCrypto.generateKey(keyGenOpt, true, ['sign', 'verify']); 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 keyGenOpt = { name: 'RSA-OAEP', diff --git a/src/crypto/random.js b/src/crypto/random.js index 741dd50a..d372d628 100644 --- a/src/crypto/random.js +++ b/src/crypto/random.js @@ -41,8 +41,8 @@ export default { const buf = new Uint8Array(length); if (typeof crypto !== 'undefined' && crypto.getRandomValues) { crypto.getRandomValues(buf); - } else if (typeof global !== 'undefined' && typeof global.msCrypto === 'object' && typeof global.msCrypto.getRandomValues === 'function') { - global.msCrypto.getRandomValues(buf); + } else if (typeof globalThis !== 'undefined' && typeof globalThis.msCrypto === 'object' && typeof globalThis.msCrypto.getRandomValues === 'function') { + globalThis.msCrypto.getRandomValues(buf); } else if (nodeCrypto) { const bytes = nodeCrypto.randomBytes(buf.length); buf.set(bytes); diff --git a/src/hkp.js b/src/hkp.js index f2b1ff05..82cdba84 100644 --- a/src/hkp.js +++ b/src/hkp.js @@ -32,7 +32,7 @@ import config from './config'; */ function HKP(keyServerBaseUrl) { 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'); } /** diff --git a/src/keyring/localstore.js b/src/keyring/localstore.js index 293fb9e8..6ef3bcc4 100644 --- a/src/keyring/localstore.js +++ b/src/keyring/localstore.js @@ -37,8 +37,8 @@ function LocalStore(prefix) { prefix = prefix || 'openpgp-'; this.publicKeysItem = prefix + this.publicKeysItem; this.privateKeysItem = prefix + this.privateKeysItem; - if (typeof global !== 'undefined' && global.localStorage) { - this.storage = global.localStorage; + if (typeof globalThis !== 'undefined' && globalThis.localStorage) { + this.storage = globalThis.localStorage; } else { this.storage = new (require('node-localstorage').LocalStorage)(config.nodeStore); } diff --git a/src/openpgp.js b/src/openpgp.js index 911f1fdb..50b1d0b1 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -48,9 +48,9 @@ import './polyfills'; import util from './util'; let toNativeReadable; -if (global.ReadableStream) { +if (globalThis.ReadableStream) { try { - toNativeReadable = createReadableStreamWrapper(global.ReadableStream); + toNativeReadable = createReadableStreamWrapper(globalThis.ReadableStream); } catch (e) {} } diff --git a/src/polyfills.js b/src/polyfills.js index 7fb386fa..630b286f 100644 --- a/src/polyfills.js +++ b/src/polyfills.js @@ -5,14 +5,14 @@ * @module polyfills */ -if (typeof global !== 'undefined') { +if (typeof globalThis !== 'undefined') { /******************************************************************** * NOTE: This list is duplicated in Gruntfile.js, * * so that these polyfills are only included in the compat bundle. * ********************************************************************/ try { - if (typeof global.fetch === 'undefined') { + if (typeof globalThis.fetch === 'undefined') { require('whatwg-fetch'); } if (typeof Array.prototype.fill === 'undefined') { @@ -48,11 +48,11 @@ if (typeof global !== 'undefined') { if (typeof TextEncoder === 'undefined') { const nodeUtil = require('util') || {}; - global.TextEncoder = nodeUtil.TextEncoder; - global.TextDecoder = nodeUtil.TextDecoder; + globalThis.TextEncoder = nodeUtil.TextEncoder; + globalThis.TextDecoder = nodeUtil.TextDecoder; } if (typeof TextEncoder === 'undefined') { const textEncoding = require('text-encoding-utf-8'); - global.TextEncoder = textEncoding.TextEncoder; - global.TextDecoder = textEncoding.TextDecoder; + globalThis.TextEncoder = textEncoding.TextEncoder; + globalThis.TextDecoder = textEncoding.TextDecoder; } diff --git a/src/util.js b/src/util.js index 0b2cfc8c..4f689ae4 100644 --- a/src/util.js +++ b/src/util.js @@ -52,7 +52,7 @@ export default { */ restoreStreams: function(obj, streaming) { 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) { return new Promise(resolve => { obj.onmessage = evt => { @@ -486,7 +486,7 @@ export default { 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; } - if (typeof global !== 'undefined') { - if (global.crypto) { - return global.crypto.subtle || global.crypto.webkitSubtle; + if (typeof globalThis !== 'undefined') { + if (globalThis.crypto) { + return globalThis.crypto.subtle || globalThis.crypto.webkitSubtle; } - if (global.msCrypto) { - return global.msCrypto.subtle; + if (globalThis.msCrypto) { + return globalThis.msCrypto.subtle; } } }, @@ -515,8 +515,8 @@ export default { * Detect Node.js runtime. */ detectNode: function() { - return typeof global.process === 'object' && - typeof global.process.versions === 'object'; + return typeof globalThis.process === 'object' && + typeof globalThis.process.versions === 'object'; }, /** diff --git a/src/wkd.js b/src/wkd.js index 4c9c6b11..5c8bc9d8 100644 --- a/src/wkd.js +++ b/src/wkd.js @@ -31,7 +31,7 @@ import * as keyMod from './key'; * @constructor */ function WKD() { - this._fetch = typeof global.fetch === 'function' ? global.fetch : require('node-fetch'); + this._fetch = typeof globalThis.fetch === 'function' ? globalThis.fetch : require('node-fetch'); } /**