From 4eb448417c484b7716a29a0d06c428c1f6d011c5 Mon Sep 17 00:00:00 2001 From: Nev <54870357+MSNev@users.noreply.github.com> Date: Tue, 25 Apr 2023 17:32:14 -0700 Subject: [PATCH] [Bug] SCRIPT5009: 'Promise' is undefined #50 (#51) --- common/config/rush/npm-shrinkwrap.json | 52 +++++++++++++------------- lib/src/internal/constants.ts | 9 +++++ lib/src/promise/base.ts | 5 ++- lib/src/promise/nativePromise.ts | 20 +++++++--- 4 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 lib/src/internal/constants.ts diff --git a/common/config/rush/npm-shrinkwrap.json b/common/config/rush/npm-shrinkwrap.json index 0a0469c..d130f09 100644 --- a/common/config/rush/npm-shrinkwrap.json +++ b/common/config/rush/npm-shrinkwrap.json @@ -1084,9 +1084,9 @@ "integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==" }, "node_modules/@types/node": { - "version": "18.16.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.0.tgz", - "integrity": "sha512-BsAaKhB+7X+H4GnSjGhJG9Qi8Tw+inU9nJDwmD5CgOmBLEI6ArdhikpLX7DjbjDRDTbqZzU2LSQNZg8WGPiSZQ==" + "version": "18.16.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.1.tgz", + "integrity": "sha512-DZxSZWXxFfOlx7k7Rv4LAyiMroaxa3Ly/7OOzZO8cBNho0YzAi4qlbrx8W27JGqG57IgR/6J7r+nOJWw6kcvZA==" }, "node_modules/@types/resolve": { "version": "1.20.2", @@ -2479,9 +2479,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.371", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.371.tgz", - "integrity": "sha512-jlBzY4tFcJaiUjzhRTCWAqRvTO/fWzjA3Bls0mykzGZ7zvcMP7h05W6UcgzfT9Ca1SW2xyKDOFRyI0pQeRNZGw==" + "version": "1.4.372", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.372.tgz", + "integrity": "sha512-MrlFq/j+TYHOjeWsWGYfzevc25HNeJdsF6qaLFrqBTRWZQtWkb1myq/Q2veLWezVaa5OcSZ99CFwTT4aF4Mung==" }, "node_modules/elliptic": { "version": "6.5.4", @@ -5990,9 +5990,9 @@ } }, "node_modules/puppeteer": { - "version": "19.11.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.11.0.tgz", - "integrity": "sha512-xE0BTOFIR/fEXEHQNfGGMWGr3IQBB2AY760K+pE11kjBKe5P0jivzWG1LHr0TA1/xiHxu9nAhQzv5zh2Dy0YEQ==", + "version": "19.11.1", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.11.1.tgz", + "integrity": "sha512-39olGaX2djYUdhaQQHDZ0T0GwEp+5f9UB9HmEP0qHfdQHIq0xGQZuAZ5TLnJIc/88SrPLpEflPC+xUqOTv3c5g==", "hasInstallScript": true, "dependencies": { "@puppeteer/browsers": "0.5.0", @@ -6000,13 +6000,13 @@ "https-proxy-agent": "5.0.1", "progress": "2.0.3", "proxy-from-env": "1.1.0", - "puppeteer-core": "19.11.0" + "puppeteer-core": "19.11.1" } }, "node_modules/puppeteer-core": { - "version": "19.11.0", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.11.0.tgz", - "integrity": "sha512-UBlwpyTEKcaOt7bIWWhlhIXDlFbR1wVBcxpMibBhImwagkwDB8ld8ehT5dOdfKIcCHjxXzVEaMtgDKzfwcf7Rg==", + "version": "19.11.1", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.11.1.tgz", + "integrity": "sha512-qcuC2Uf0Fwdj9wNtaTZ2OvYRraXpAK+puwwVW8ofOhOgLPZyz1c68tsorfIZyCUOpyBisjr+xByu7BMbEYMepA==", "dependencies": { "@puppeteer/browsers": "0.5.0", "chromium-bidi": "0.4.7", @@ -8521,9 +8521,9 @@ "integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==" }, "@types/node": { - "version": "18.16.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.0.tgz", - "integrity": "sha512-BsAaKhB+7X+H4GnSjGhJG9Qi8Tw+inU9nJDwmD5CgOmBLEI6ArdhikpLX7DjbjDRDTbqZzU2LSQNZg8WGPiSZQ==" + "version": "18.16.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.1.tgz", + "integrity": "sha512-DZxSZWXxFfOlx7k7Rv4LAyiMroaxa3Ly/7OOzZO8cBNho0YzAi4qlbrx8W27JGqG57IgR/6J7r+nOJWw6kcvZA==" }, "@types/resolve": { "version": "1.20.2", @@ -9594,9 +9594,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "electron-to-chromium": { - "version": "1.4.371", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.371.tgz", - "integrity": "sha512-jlBzY4tFcJaiUjzhRTCWAqRvTO/fWzjA3Bls0mykzGZ7zvcMP7h05W6UcgzfT9Ca1SW2xyKDOFRyI0pQeRNZGw==" + "version": "1.4.372", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.372.tgz", + "integrity": "sha512-MrlFq/j+TYHOjeWsWGYfzevc25HNeJdsF6qaLFrqBTRWZQtWkb1myq/Q2veLWezVaa5OcSZ99CFwTT4aF4Mung==" }, "elliptic": { "version": "6.5.4", @@ -12257,22 +12257,22 @@ "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==" }, "puppeteer": { - "version": "19.11.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.11.0.tgz", - "integrity": "sha512-xE0BTOFIR/fEXEHQNfGGMWGr3IQBB2AY760K+pE11kjBKe5P0jivzWG1LHr0TA1/xiHxu9nAhQzv5zh2Dy0YEQ==", + "version": "19.11.1", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.11.1.tgz", + "integrity": "sha512-39olGaX2djYUdhaQQHDZ0T0GwEp+5f9UB9HmEP0qHfdQHIq0xGQZuAZ5TLnJIc/88SrPLpEflPC+xUqOTv3c5g==", "requires": { "@puppeteer/browsers": "0.5.0", "cosmiconfig": "8.1.3", "https-proxy-agent": "5.0.1", "progress": "2.0.3", "proxy-from-env": "1.1.0", - "puppeteer-core": "19.11.0" + "puppeteer-core": "19.11.1" } }, "puppeteer-core": { - "version": "19.11.0", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.11.0.tgz", - "integrity": "sha512-UBlwpyTEKcaOt7bIWWhlhIXDlFbR1wVBcxpMibBhImwagkwDB8ld8ehT5dOdfKIcCHjxXzVEaMtgDKzfwcf7Rg==", + "version": "19.11.1", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.11.1.tgz", + "integrity": "sha512-qcuC2Uf0Fwdj9wNtaTZ2OvYRraXpAK+puwwVW8ofOhOgLPZyz1c68tsorfIZyCUOpyBisjr+xByu7BMbEYMepA==", "requires": { "@puppeteer/browsers": "0.5.0", "chromium-bidi": "0.4.7", diff --git a/lib/src/internal/constants.ts b/lib/src/internal/constants.ts new file mode 100644 index 0000000..f03a5e9 --- /dev/null +++ b/lib/src/internal/constants.ts @@ -0,0 +1,9 @@ +/* + * @nevware21/ts-async + * https://github.com/nevware21/ts-async + * + * Copyright (c) 2023 Nevware21 + * Licensed under the MIT license. + */ + +export const STR_PROMISE = "Promise"; \ No newline at end of file diff --git a/lib/src/promise/base.ts b/lib/src/promise/base.ts index d45f60b..129dde1 100644 --- a/lib/src/promise/base.ts +++ b/lib/src/promise/base.ts @@ -20,6 +20,7 @@ import { } from "../interfaces/types"; import { ePromiseState, STRING_STATES } from "../internal/state"; import { emitEvent } from "./event"; +import { STR_PROMISE } from "../internal/constants"; const NODE_UNHANDLED_REJECTION = "unhandledRejection"; const UNHANDLED_REJECTION = NODE_UNHANDLED_REJECTION.toLowerCase(); @@ -62,7 +63,7 @@ export function _createPromise(newPromise: PromiseCreatorFn, processor: Promi let _unHandledRejectionHandler: ITimerHandler = null; let _thePromise: IPromise; - !_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = getLazy(() => !!getInst("PromiseRejectionEvent"))); + !_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = getLazy(() => !!getInst(STR_PROMISE + "RejectionEvent"))); // https://tc39.es/ecma262/#sec-promise.prototype.then const _then = (onResolved?: ResolvedPromiseHandler, onRejected?: RejectedPromiseHandler): IPromise => { @@ -247,7 +248,7 @@ export function _createPromise(newPromise: PromiseCreatorFn, processor: Promi (function _initialize() { if (!isFunction(executor)) { - throwTypeError("Promise: executor is not a function - " + dumpFnObj(executor)); + throwTypeError(STR_PROMISE + ": executor is not a function - " + dumpFnObj(executor)); } const _rejectFn = _createSettleIfFn(ePromiseState.Rejected, ePromiseState.Pending); diff --git a/lib/src/promise/nativePromise.ts b/lib/src/promise/nativePromise.ts index c284718..01f6035 100644 --- a/lib/src/promise/nativePromise.ts +++ b/lib/src/promise/nativePromise.ts @@ -12,16 +12,16 @@ 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 { STR_PROMISE } from "../internal/constants"; -const PrmCls = Promise; -let _isPromiseSupported: ILazyValue; +let _isPromiseSupported: ILazyValue; /** * Creates a Promise instance that when resolved or rejected will execute it's pending chained operations using the * available native Promise implementation. * If runtime does not support native `Promise` class (or no polyfill is available) this function will fallback to using * `createAsyncPromise` which will resolve them __asynchronously__ using the optional provided timeout value to - * schedule when the chained items will be ececuted. + * schedule when the chained items will be executed. * @group Alias * @group Promise * @group Native @@ -30,13 +30,21 @@ 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(() => !!getInst("Promise"))); - if (!_isPromiseSupported.v) { + !_isPromiseSupported && (_isPromiseSupported = getLazy(() => { + try { + return getInst(STR_PROMISE); + } catch(e) { + // eslint-disable-next-line no-empty + } + })); + + const PrmCls = _isPromiseSupported.v; + if (!PrmCls) { return createAsyncPromise(executor); } if (!isFunction(executor)) { - throwTypeError("Promise: executor is not a function - " + dumpObj(executor)); + throwTypeError(STR_PROMISE + ": executor is not a function - " + dumpObj(executor)); } let _state = ePromiseState.Pending;