Skip to content

Commit

Permalink
merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Jul 23, 2023
1 parent 2842af5 commit eb11d3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
11 changes: 5 additions & 6 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,12 @@ export const promiseDefer_ = <T> (): { p: Promise<T>, 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 ==== */

Expand Down
26 changes: 2 additions & 24 deletions scripts/gulp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -746,46 +742,28 @@ 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 = {};
_randSeed = 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')
}

0 comments on commit eb11d3d

Please # to comment.