Skip to content

Commit

Permalink
"Cache" the compiled lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Apr 27, 2024
1 parent c38d4fa commit b93a3b2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions purlfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b93a3b2

Please sign in to comment.