Expand has checks (#1271)

This commit is contained in:
Jaco
2021-12-01 18:11:03 +02:00
committed by GitHub
parent 82a63887a6
commit bda848f484
4 changed files with 10 additions and 3 deletions
+7
View File
@@ -1,8 +1,15 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// import { xglobal } from '@polkadot/x-global';
import { cryptoWaitReady } from './crypto';
// This would not be a great idea since it would poluse the global namespace
// if (typeof BigInt !== 'function' || typeof BigInt.asIntN !== 'function') {
// (xglobal as Record<string, unknown>).BigInt = () => Number.NaN;
// }
// start init process immediately
cryptoWaitReady().catch((): void => {
// shouldn't happen, logged above
+1 -1
View File
@@ -6,7 +6,7 @@
* @description Creates a new instance of BigInt in environments that do support it
*/
export function _n (n: string | number | bigint | boolean): bigint {
return typeof BigInt === 'function'
return typeof BigInt === 'function' && typeof BigInt.asIntN === 'function'
? BigInt(n)
: Number.NaN as unknown as bigint;
}
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
export const hasBigInt = typeof BigInt !== 'undefined';
export const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
export const hasBuffer = typeof Buffer !== 'undefined';
export const hasDirname = typeof __dirname !== 'undefined';
export const hasProcess = typeof process === 'object';
+1 -1
View File
@@ -7,7 +7,7 @@ export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |
// helper to protect against older bundlers
export function _n (n: string | number | bigint | boolean): bigint {
return typeof BigInt === 'function'
return typeof BigInt === 'function' && typeof BigInt.asIntN === 'function'
? BigInt(n)
: Number.NaN as unknown as bigint;
}