Skip to content

Commit

Permalink
Replace 'global' with 'globalThis'
Browse files Browse the repository at this point in the history
  • Loading branch information
twiss committed Feb 9, 2021
1 parent 5b14808 commit cde282d
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ export default {
* @memberof module:config
* @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
* @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])
};
4 changes: 2 additions & 2 deletions src/config/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
6 changes: 3 additions & 3 deletions src/crypto/public_key/elliptic/indutnyKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>}
*/
async function loadEllipticPromise() {
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/public_key/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/hkp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/keyring/localstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/openpgp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Expand Down
12 changes: 6 additions & 6 deletions src/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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;
}
18 changes: 9 additions & 9 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
},

/**
Expand All @@ -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;
}
}
},
Expand All @@ -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';
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/wkd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit cde282d

Please sign in to comment.