Expand has checks (#1271)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user