diff --git a/docs/index.bs b/docs/index.bs index 0a280725..c681b8d4 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -1606,6 +1606,10 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ Note: {{RouterCondition/_or}} and {{RouterCondition/not}} might have the other {{RouterCondition/_or}} or {{RouterCondition/not}} inside. To avoid spending much resources by the nested condition or performance penalty on evaluation, depth of such nested conditions can be limited. + A count router condition result is a [=struct=] that consists of: + * A total count (a number). + * A depth (a number). +

{{InstallEvent/addRoutes(rules)|event.addRoutes(rules)}}

@@ -1620,6 +1624,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ 1. If running the [=Verify Router Condition=] algorithm with |rule|["{{RouterRule/condition}}"] and |serviceWorker| returns false, return [=a promise rejected with=] a {{TypeError}}. 1. Append |rule| to |routerRules|. 1. If |routerRules| [=list/contains=] a {{RouterRule}} whose {{RouterRule/source}} is either of "{{RouterSourceEnum/fetch-event}}" or "{{RouterSourceEnum/race-network-and-fetch-handler}}", and |serviceWorker|'s [=set of event types to handle=] does not [=set/contain=] {{ServiceWorkerGlobalScope/fetch!!event}}, return [=a promise rejected with=] a {{TypeError}}. + 1. If running the [=Check Router Registration Limit=] with |serviceWorker| returns false, return [=a promise rejected with=] a {{TypeError}}. 1. Set |serviceWorker|'s [=service worker/list of router rules=] to |routerRules|. 1. Return [=a promise resolved with=] undefined. @@ -3409,14 +3414,14 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ Note: To limit the resource usage and a condition evaluation time, |orConditions|'s [=list/size=] can be limited. 1. For each |orCondition| of |orConditions|: - 1. If running the [=Verify Router Condition=] algorithm with |orCondition| and |serviceWorker| returns false, return false. + 1. If running the [=Verify Router Condition=] algorithm with |orCondition| and |serviceWorker| and |registeredRuleCount| returns false, return false. 1. Set |hasCondition| to true. 1. If |condition|["{{RouterCondition/not}}"] [=map/exists=], then: 1. If |hasCondition| is true, return false. Note: For ease of understanding the router rule, the "not" condition is mutually exclusive with other conditions. - 1. If running the [=Verify Router Condition=] algorithm with |condition|["{{RouterCondition/not}}"] and |serviceWorker| returns false, return false. + 1. If running the [=Verify Router Condition=] algorithm with |condition|["{{RouterCondition/not}}"] and |serviceWorker| and |registeredRuleCount| returns false, return false. 1. Set |hasCondition| to true. 1. If |hasCondition| is true, then: 1. Increament |serviceWorker|'s [=service worker/router rule count=] by one. @@ -3468,6 +3473,53 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ 1. Return true.
+
+

Check Router Registration Limit

+ : Input + :: |serviceWorker|, a [=/service worker=] + : Output + :: a boolean + + 1. Let |result| be a [=count router condition result=]. + 1. Set |result|'s [=count router condition result/total count=] to 0. + 1. Set |result|'s [=count router condition result/depth=] to 1. + 1. Let |maxRuleCount| be 1024. + 1. Let |maxDepth| be 10. + 1. [=list/For each=] |rule| of |serviceWorker|'s [=service worker/list of router rules=]: + 1. Let |currentResult| be the result of running [=Count Router Inner Conditions=] with |rule|["{{RouterRule/condition}}"], |result|, |maxRuleCount|, and |maxDepth|. + 1. If |currentResult|'s [=count router condition result/total count=] exceeds |maxRuleCount|, return false. + 1. If |currentResult|'s [=count router condition result/depth=] exceeds |maxDepth|, return false. + 1. Set |result|'s [=count router condition result/total count=] to |currentResult|'s [=count router condition result/total count=]. + 1. return true. +
+ +
+

Count Router Inner Conditions

+ : Input + :: |condition|, a {{RouterCondition}} + :: |result|, a [=count router condition result=] + :: |maxCount|, a number + :: |maxDepth|, a number + : Output + :: |result|, a [=count router condition result=] + + 1. Increment |result|'s [=count router condition result/total count=] by one. + 1. If |result|'s [=count router condition result/total count=] exceeds |maxCount|, return |result|. + 1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|. + 1. If |condition|["{{RouterCondition/_or}}"] [=map/exists=], then: + 1. Increment |result|'s [=count router condition result/depth=] by one. + 1. For each |orCondition| of |condition|["{{RouterCondition/_or}}"]: + 1. Set |result| to be the result of running [=Count Router Inner Conditions=] with |orCondition|, |result|, |maxCount|, and |maxDepth|. + 1. If |result|'s [=count router condition result/total count=] exceeds |maxCount|, return |result|. + 1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|. + 1. Else if |condition|["{{RouterCondition/not}}"] [=map/exists=], then: + 1. Increment |result|'s [=count router condition result/depth=] by one. + 1. Let |result| be the result of running [=Count Router Inner Conditions=] with |condition|["{{RouterCondition/not}}"], |result|, |maxCount|, and |maxDepth|. + 1. If |result|'s [=count router condition result/total count=] exceeds |maxCount|, return |result|. + 1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|. + 1. Return |result|. +
+

Get Router Source

: Input