diff --git a/common/config/rush/npm-shrinkwrap.json b/common/config/rush/npm-shrinkwrap.json index d130f09..cd61928 100644 --- a/common/config/rush/npm-shrinkwrap.json +++ b/common/config/rush/npm-shrinkwrap.json @@ -10,7 +10,7 @@ "dependencies": { "@istanbuljs/nyc-config-typescript": "^1.0.2", "@microsoft/api-extractor": "^7.34.4", - "@nevware21/ts-utils": ">= 0.9.3 < 2.x", + "@nevware21/ts-utils": ">= 0.9.5 < 2.x", "@rollup/plugin-commonjs": "^24.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", @@ -624,9 +624,9 @@ } }, "node_modules/@nevware21/ts-utils": { - "version": "0.9.4", - "resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.9.4.tgz", - "integrity": "sha512-dvU51sDoIdU3k0EBnODmdGya4xpU4vkK97OYIy+nviB613g3+GcErx8ceTGTjBJXjS7PUI1FR5mUOK40cyeqxg==", + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.9.5.tgz", + "integrity": "sha512-hCUM1/HKLcHKWeTjX/ervVOp6eim+XEdFI3U7NUU+yec7XPQTxe4sDujPY5unlTQ2CHpxTewRo7mIyaRdMFlUw==", "peerDependencies": { "typescript": ">=1" } @@ -854,11 +854,11 @@ "node_modules/@rush-temp/ts-async": { "version": "0.0.0", "resolved": "file:projects/ts-async.tgz", - "integrity": "sha512-u7tZtkVh3ni+/xUHjjwSGke35MTYKdVkXGejwhG8peLEhDeW+XAh0LA6rNXB64Xi9kyXBlX2FgZLpehxmj4JHw==", + "integrity": "sha512-P8heB4ydRbA83sYmrXRqmng/9FMLSRbuQ5NCOqe4zULOorhM6YWlVe7Vuc3cij+tuY/OJNnlTx+QYpj4t4FApw==", "dependencies": { "@istanbuljs/nyc-config-typescript": "^1.0.2", "@microsoft/api-extractor": "^7.34.4", - "@nevware21/ts-utils": ">= 0.9.3 < 2.x", + "@nevware21/ts-utils": ">= 0.9.5 < 2.x", "@rollup/plugin-commonjs": "^24.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", @@ -8180,9 +8180,9 @@ } }, "@nevware21/ts-utils": { - "version": "0.9.4", - "resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.9.4.tgz", - "integrity": "sha512-dvU51sDoIdU3k0EBnODmdGya4xpU4vkK97OYIy+nviB613g3+GcErx8ceTGTjBJXjS7PUI1FR5mUOK40cyeqxg==", + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.9.5.tgz", + "integrity": "sha512-hCUM1/HKLcHKWeTjX/ervVOp6eim+XEdFI3U7NUU+yec7XPQTxe4sDujPY5unlTQ2CHpxTewRo7mIyaRdMFlUw==", "requires": {} }, "@puppeteer/browsers": { @@ -8307,11 +8307,11 @@ }, "@rush-temp/ts-async": { "version": "file:projects\\ts-async.tgz", - "integrity": "sha512-u7tZtkVh3ni+/xUHjjwSGke35MTYKdVkXGejwhG8peLEhDeW+XAh0LA6rNXB64Xi9kyXBlX2FgZLpehxmj4JHw==", + "integrity": "sha512-P8heB4ydRbA83sYmrXRqmng/9FMLSRbuQ5NCOqe4zULOorhM6YWlVe7Vuc3cij+tuY/OJNnlTx+QYpj4t4FApw==", "requires": { "@istanbuljs/nyc-config-typescript": "^1.0.2", "@microsoft/api-extractor": "^7.34.4", - "@nevware21/ts-utils": ">= 0.9.3 < 2.x", + "@nevware21/ts-utils": ">= 0.9.5 < 2.x", "@rollup/plugin-commonjs": "^24.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", diff --git a/lib/package.json b/lib/package.json index 28777e6..a302b90 100644 --- a/lib/package.json +++ b/lib/package.json @@ -72,7 +72,7 @@ }, "dependencies": { - "@nevware21/ts-utils": ">= 0.9.3 < 2.x" + "@nevware21/ts-utils": ">= 0.9.5 < 2.x" }, "peerDependencies": { "typescript": ">=1" diff --git a/lib/src/promise/base.ts b/lib/src/promise/base.ts index 129dde1..0242c73 100644 --- a/lib/src/promise/base.ts +++ b/lib/src/promise/base.ts @@ -9,7 +9,7 @@ import { arrForEach, arrSlice, dumpObj, getKnownSymbol, hasSymbol, isFunction, isPromiseLike, isUndefined, throwTypeError, WellKnownSymbols, objToString, scheduleTimeout, ITimerHandler, getWindow, isNode, - getGlobal, ILazyValue, getLazy, getInst, objDefine, objDefineProp + getGlobal, ILazyValue, objDefine, objDefineProp, lazySafeGetInst } from "@nevware21/ts-utils"; import { doAwait } from "./await"; import { _addDebugState, _debugLog, _promiseDebugEnabled } from "./debug"; @@ -29,7 +29,7 @@ let _currentPromiseId: number[] = []; let _uniquePromiseId = 0; let _unhandledRejectionTimeout = 10; -let _hasPromiseRejectionEvent: ILazyValue; +let _hasPromiseRejectionEvent: ILazyValue; function dumpFnObj(value: any) { if (isFunction(value)) { @@ -63,7 +63,7 @@ export function _createPromise(newPromise: PromiseCreatorFn, processor: Promi let _unHandledRejectionHandler: ITimerHandler = null; let _thePromise: IPromise; - !_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = getLazy(() => !!getInst(STR_PROMISE + "RejectionEvent"))); + !_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = lazySafeGetInst(STR_PROMISE + "RejectionEvent")); // https://tc39.es/ecma262/#sec-promise.prototype.then const _then = (onResolved?: ResolvedPromiseHandler, onRejected?: RejectedPromiseHandler): IPromise => { @@ -216,7 +216,7 @@ export function _createPromise(newPromise: PromiseCreatorFn, processor: Promi objDefine(theEvt, "promise", { g: () => _thePromise }); theEvt.reason = _settledValue; return theEvt; - }, _hasPromiseRejectionEvent.v); + }, !!_hasPromiseRejectionEvent.v); } } } diff --git a/lib/src/promise/event.ts b/lib/src/promise/event.ts index 5410cc9..3a0f827 100644 --- a/lib/src/promise/event.ts +++ b/lib/src/promise/event.ts @@ -6,7 +6,7 @@ * Licensed under the MIT license. */ -import { dumpObj, getDocument, getInst, getLazy, ILazyValue } from "@nevware21/ts-utils"; +import { dumpObj, getDocument, safeGetLazy, ILazyValue, getInst } from "@nevware21/ts-utils"; const DISPATCH_EVENT = "dispatchEvent"; let _hasInitEvent: ILazyValue; @@ -22,14 +22,14 @@ let _hasInitEvent: ILazyValue; export function emitEvent(target: any, evtName: string, populateEvent: (theEvt: Event | any) => Event | any, useNewEvent: boolean) { let doc = getDocument(); - !_hasInitEvent && (_hasInitEvent = getLazy(() => { + !_hasInitEvent && (_hasInitEvent = safeGetLazy(() => { let evt: any; if (doc && doc.createEvent) { evt = doc.createEvent("Event"); } return (!!evt && evt.initEvent); - })); + }, null)); let theEvt: Event = _hasInitEvent.v ? doc.createEvent("Event") : (useNewEvent ? new Event(evtName) : {} as Event); populateEvent && populateEvent(theEvt); diff --git a/lib/src/promise/nativePromise.ts b/lib/src/promise/nativePromise.ts index 01f6035..6e08aab 100644 --- a/lib/src/promise/nativePromise.ts +++ b/lib/src/promise/nativePromise.ts @@ -11,7 +11,7 @@ import { _createAllPromise, _createRejectedPromise, _createResolvedPromise } fro import { IPromise } from "../interfaces/IPromise"; import { ePromiseState, STRING_STATES } from "../internal/state"; import { PromiseExecutor } from "../interfaces/types"; -import { dumpObj, getInst, getLazy, ILazyValue, isFunction, objDefineProp, throwTypeError } from "@nevware21/ts-utils"; +import { dumpObj, lazySafeGetInst, ILazyValue, isFunction, objDefineProp, throwTypeError } from "@nevware21/ts-utils"; import { STR_PROMISE } from "../internal/constants"; let _isPromiseSupported: ILazyValue; @@ -30,13 +30,7 @@ let _isPromiseSupported: ILazyValue; * @param timeout - Optional timeout to wait before processing the items, defaults to zero. */ export function createNativePromise(executor: PromiseExecutor, timeout?: number): IPromise { - !_isPromiseSupported && (_isPromiseSupported = getLazy(() => { - try { - return getInst(STR_PROMISE); - } catch(e) { - // eslint-disable-next-line no-empty - } - })); + !_isPromiseSupported && (_isPromiseSupported = lazySafeGetInst(STR_PROMISE)); const PrmCls = _isPromiseSupported.v; if (!PrmCls) { diff --git a/package.json b/package.json index dd1d85d..938eea8 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "node": ">= 0.8.0" }, "dependencies": { - "@nevware21/ts-utils": ">= 0.9.3 < 2.x" + "@nevware21/ts-utils": ">= 0.9.5 < 2.x" }, "peerDependencies": { "typescript": ">=1"