From eb11d3d17b6b6b859c33ea6235ef6f22ebdc2ee6 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sun, 23 Jul 2023 16:38:01 +0800 Subject: [PATCH] merge from master --- lib/utils.ts | 11 +++++------ scripts/gulp-utils.js | 26 ++------------------------ 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/lib/utils.ts b/lib/utils.ts index 796bda355..065932892 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -259,13 +259,12 @@ export const promiseDefer_ = (): { p: Promise, r: (value: T) => void } => } // if `var queueMicrotask`, on Firefox globalThis.queueMicrotask is undefined even when window.queueMicrotask exists -export const queueTask_: typeof queueMicrotask | undefined = !Build.NDEBUG - ? (window as {} as typeof globalThis).queueMicrotask - && ((func: () => void): void => (window as {} as typeof globalThis).queueMicrotask(func)) - : !(Build.BTypes & BrowserType.Edge +export const queueTask_: typeof queueMicrotask | undefined = !OnFirefox || !(Build.BTypes & BrowserType.Edge || Build.BTypes & BrowserType.Firefox && Build.MinFFVer < FirefoxBrowserVer.Min$queueMicrotask - || Build.BTypes & BrowserType.Chrome && Build.MinCVer < BrowserVer.Min$queueMicrotask) || !OnFirefox - ? queueMicrotask : (window as {} as typeof globalThis).queueMicrotask.bind(window) + || Build.BTypes & BrowserType.Chrome && Build.MinCVer < BrowserVer.Min$queueMicrotask) + ? queueMicrotask + : (window as {} as typeof globalThis).queueMicrotask + && (window as {} as typeof globalThis).queueMicrotask.bind(window) /** ==== shortcuts of constant code ==== */ diff --git a/scripts/gulp-utils.js b/scripts/gulp-utils.js index 98cca2f2d..06acd3f41 100644 --- a/scripts/gulp-utils.js +++ b/scripts/gulp-utils.js @@ -717,10 +717,6 @@ exports.kAllBuildEnv = Object.entries(process.env) exports.parseBuildEnv = function (key, literalVal) { var newVal = process.env["BUILD_" + key]; - if (!newVal) { - let env_key = key.replace(/[A-Z]+[a-z\d]*/g, word => "_" + word.toUpperCase()).replace(/^_/, ""); - newVal = process.env["BUILD_" + env_key]; - } if (newVal) { let newVal2 = exports.safeJSONParse(newVal, null, key === "Commit" ? String : null); if (newVal2 == null && key === "Commit") { newVal2 = newVal } @@ -746,12 +742,10 @@ var randMap, _randSeed; exports.getRandMap = function () { return randMap } -exports.getRandom = function (id, locally, getSeed) { +exports.getRandom = function (id, _locally, getSeed) { var rand = randMap ? randMap[id] : 0; if (rand) { - if ((typeof rand === "string") === locally) { - return rand; - } + return rand; } if (!randMap) { randMap = {}; @@ -759,33 +753,17 @@ exports.getRandom = function (id, locally, getSeed) { const name = _randSeed.split("?").slice(-1)[0] name && print("Get random seed:", name) var rng; - if (!locally) { try { rng = require("seedrandom"); } catch (e) {} - } if (rng) { _randSeed = rng(_randSeed + "/" + id) } } - if (!locally) { while (!rand || Object.values(randMap).includes(rand)) { /** {@see #GlobalConsts.SecretRange} */ rand = 1e6 + (0 | ((typeof _randSeed === "function" ? _randSeed() : Math.random()) * 9e6)); } - } else { - var hash = _randSeed + id; - hash = compute_hash(hash); - hash = hash.slice(0, 7); - rand = hash; - } randMap[id] = rand; return rand; } - -function compute_hash(str) { - var crypto = require("crypto") - var md5 = crypto.createHash('sha1') - md5.update(str) - return md5.digest('hex') -}