From b93a3b274aa0d848358efa50ae4484aa5b8ea620 Mon Sep 17 00:00:00 2001 From: PRO-2684 <54608551+PRO-2684@users.noreply.github.com> Date: Sat, 27 Apr 2024 17:56:51 +0800 Subject: [PATCH] "Cache" the compiled lambda function --- purlfy.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/purlfy.js b/purlfy.js index 54f9520..9af9eb0 100644 --- a/purlfy.js +++ b/purlfy.js @@ -83,7 +83,7 @@ class Purlfy extends EventTarget { case "redirect": return this.redirectEnabled && this.#udfOrType(rule.ua, "string") && this.#udfOrType(rule.continue, "boolean"); case "lambda": - return this.lambdaEnabled && typeof rule.lambda === "string" && this.#udfOrType(rule.continue, "boolean"); + return this.lambdaEnabled && (typeof rule.lambda === "string" || rule.lambda instanceof this.#AsyncFunction) && this.#udfOrType(rule.continue, "boolean"); default: return false; } @@ -261,7 +261,8 @@ class Purlfy extends EventTarget { break; } try { - const lambda = new this.#AsyncFunction("url", rule.lambda); + const lambda = typeof rule.lambda === "string" ? new this.#AsyncFunction("url", rule.lambda) : rule.lambda; + rule.lambda = lambda; // "Cache" the compiled lambda function urlObj = await lambda(urlObj); shallContinue = rule.continue ?? true; } catch (e) {