Skip to content

Commit 4e10a29

Browse files
authored
Editorial: modernize algorithms
Declare types, stop using / for two-tuples, and use syntax for lists. Fixes #222.
1 parent b4cafb5 commit 4e10a29

File tree

1 file changed

+38
-44
lines changed

1 file changed

+38
-44
lines changed

index.bs

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ The <dfn method for=CookieStore>get(|options|)</dfn> method steps are:
545545
1. Let |origin| be |settings|'s [=environment settings object/origin=].
546546
1. If |origin| is an [=opaque origin=], then return [=a promise rejected with=] a "{{SecurityError}}" {{DOMException}}.
547547
1. Let |url| be |settings|'s [=environment/creation URL=].
548-
1. If |options| is empty, then return [=a promise rejected with=] a {{TypeError}}.
549-
1. If |options|["{{CookieStoreGetOptions/url}}"] is present, then run these steps:
548+
1. If |options| [=map/is empty=], then return [=a promise rejected with=] a {{TypeError}}.
549+
1. If |options|["{{CookieStoreGetOptions/url}}"] [=map/exists=]:
550550
1. Let |parsed| be the result of [=basic URL parser|parsing=] |options|["{{CookieStoreGetOptions/url}}"] with |settings|'s [=environment settings object/API base URL=].
551551
1. If [=/this=]'s [=/relevant global object=] is a {{Window}} object and |parsed| does not [=url/equal=] |url| with [=url/equals/exclude fragments=] set to true,
552552
then return [=a promise rejected with=] a {{TypeError}}.
@@ -603,7 +603,7 @@ The <dfn method for=CookieStore>getAll(|options|)</dfn> method steps are:
603603
1. Let |origin| be |settings|'s [=environment settings object/origin=].
604604
1. If |origin| is an [=opaque origin=], then return [=a promise rejected with=] a "{{SecurityError}}" {{DOMException}}.
605605
1. Let |url| be |settings|'s [=environment/creation URL=].
606-
1. If |options|["{{CookieStoreGetOptions/url}}"] is present, then run these steps:
606+
1. If |options|["{{CookieStoreGetOptions/url}}"] [=map/exists=]:
607607
1. Let |parsed| be the result of [=basic URL parser|parsing=] |options|["{{CookieStoreGetOptions/url}}"] with |settings|'s [=environment settings object/API base URL=].
608608
1. If [=/this=]'s [=/relevant global object=] is a {{Window}} object and |parsed| does not [=url/equal=] |url| with [=url/equals/exclude fragments=] set to true,
609609
then return [=a promise rejected with=] a {{TypeError}}.
@@ -648,20 +648,17 @@ The <dfn method for=CookieStore>set(|name|, |value|)</dfn> method steps are:
648648
1. Let |origin| be |settings|'s [=environment settings object/origin=].
649649
1. If |origin| is an [=opaque origin=], then return [=a promise rejected with=] a "{{SecurityError}}" {{DOMException}}.
650650
1. Let |url| be |settings|'s [=environment/creation URL=].
651-
1. Let |domain| be null.
652-
1. Let |path| be "/".
653-
1. Let |sameSite| be {{CookieSameSite/strict}}.
654-
1. Let |partitioned| be false.
655651
1. Let |p| be [=a new promise=].
656652
1. Run the following steps [=in parallel=]:
657653
1. Let |r| be the result of running [=set a cookie=] with
658654
|url|,
659655
|name|,
660656
|value|,
661-
|domain|,
662-
|path|,
663-
|sameSite|, and
664-
|partitioned|.
657+
null,
658+
null,
659+
"`/`",
660+
"{{CookieSameSite/strict}}", and
661+
false.
665662
1. If |r| is failure, then [=reject=] |p| with a {{TypeError}} and abort these steps.
666663
1. [=/Resolve=] |p| with undefined.
667664
1. Return |p|.
@@ -818,7 +815,7 @@ The <dfn method for=CookieStoreManager>getSubscriptions()</dfn> method steps are
818815
1. Let |p| be [=a new promise=].
819816
1. Run the following steps [=in parallel=]:
820817
1. Let |subscriptions| be |registration|'s associated [=cookie change subscription list=].
821-
1. Let |result| be a new [=/list=].
818+
1. Let |result| be « ».
822819
1. [=list/For each=] |subscription| in |subscriptions|, run these steps:
823820
1. [=list/Append=] «[ "name" → |subscription|'s [=cookie change subscription/name=], "url" → |subscription|'s [=cookie change subscription/url=]]» to |result|.
824821
1. [=/Resolve=] |p| with |result|.
@@ -1017,16 +1014,16 @@ and return a [=byte sequence=] corresponding to the closest `cookie-date` repres
10171014

10181015
<div algorithm>
10191016

1020-
To <dfn>query cookies</dfn> given a [=/URL=] |url| and [=/string=]-or-null |name|:
1017+
To <dfn>query cookies</dfn> given a [=/URL=] |url| and [=/scalar value string=]-or-null |name|:
10211018

10221019
1. Perform the steps defined in [[RFC6265BIS-14#name-retrieval-model|Cookies § Retrieval Model]] to compute the "cookie-string from a given cookie store"
10231020
with |url| as <var ignore>request-uri</var>.
10241021
The |cookie-string| itself is ignored, but the intermediate |cookie-list| is used in subsequent steps.
10251022

10261023
For the purposes of the steps, the |cookie-string| is being generated for a "non-HTTP" API.
10271024

1028-
1. Let |list| be a new [=/list=].
1029-
1. [=list/For each=] |cookie| in |cookie-list|, run these steps:
1025+
1. Let |list| be « ».
1026+
1. [=list/For each=] |cookie| of |cookie-list|:
10301027
1. Assert: |cookie|'s [=cookie/http-only-flag=] is false.
10311028
1. If |name| is non-null:
10321029
1. [=Normalize=] |name|.
@@ -1057,16 +1054,14 @@ Note: One implementation is known to expose information beyond _name_ and _value
10571054

10581055
<div algorithm>
10591056

1060-
To <dfn>set a cookie</dfn> with
1061-
|url|,
1062-
|name|,
1063-
|value|,
1064-
optional |expires|,
1065-
|domain|,
1066-
|path|,
1067-
|sameSite|, and
1068-
|partitioned|
1069-
run the following steps:
1057+
To <dfn>set a cookie</dfn> given a [=/URL=] |url|,
1058+
[=/scalar value string=] |name|,
1059+
[=/scalar value string=] |value|,
1060+
{{DOMHighResTimeStamp}}-or-null |expires|,
1061+
[=/scalar value string=]-or-null |domain|,
1062+
[=/scalar value string=] |path|,
1063+
[=/string=] |sameSite|, and
1064+
[=/boolean=] |partitioned|:
10701065

10711066
1. [=Normalize=] |name|.
10721067
1. [=Normalize=] |value|.
@@ -1084,34 +1079,34 @@ run the following steps:
10841079
1. Let |encodedValue| be the result of [=UTF-8 encode|UTF-8 encoding=] |value|.
10851080
1. If the [=byte sequence=] [=byte sequence/length=] of |encodedName| plus the [=byte sequence=] [=byte sequence/length=] of |encodedValue| is greater than the <a for=cookie>maximum name/value pair size</a>, then return failure.
10861081
1. Let |host| be |url|'s [=url/host=]
1087-
1. Let |attributes| be a new [=/list=].
1088-
1. If |domain| is not null, then run these steps:
1082+
1. Let |attributes| be « ».
1083+
1. If |domain| is non-null:
10891084
1. If |domain| starts with U+002E (.), then return failure.
10901085
1. If |name|, [=byte-lowercased=], [=byte sequence/starts with=] \``__host-`\`, then return failure.
10911086
1. If |domain| [=is a registrable domain suffix of or is equal to|is not a registrable domain suffix of and is not equal to=] |host|, then return failure.
10921087
1. Let |parsedDomain| be the result of [=host parser|host parsing=] |domain|.
10931088
1. Assert: |parsedDomain| is not failure.
10941089
1. Let |encodedDomain| be the result of [=UTF-8 encode|UTF-8 encoding=] |parsedDomain|.
10951090
1. If the [=byte sequence=] [=byte sequence/length=] of |encodedDomain| is greater than the [=cookie/maximum attribute value size=], then return failure.
1096-
1. [=list/Append=] \``Domain`\`/|encodedDomain| to |attributes|.
1097-
1. If |expires| is given, then [=list/append=] \``Expires`\`/|expires| ([=date serialized=]) to |attributes|.
1091+
1. [=list/Append=] (\``Domain`\`, |encodedDomain|) to |attributes|.
1092+
1. If |expires| is non-null, then [=list/append=] (\``Expires`\`, |expires| ([=date serialized=])) to |attributes|.
10981093
1. If |path| is the empty string, then set |path| to the [=/serialized cookie default path=] of |url|.
10991094
1. If |path| does not start with U+002F (/), then return failure.
11001095
1. If |path| is not U+002F (/), and |name|, [=byte-lowercased=], [=byte sequence/starts with=] \``__host-`\`, then return failure.
11011096
1. Let |encodedPath| be the result of [=UTF-8 encode|UTF-8 encoding=] |path|.
11021097
1. If the [=byte sequence=] [=byte sequence/length=] of |encodedPath| is greater than the [=cookie/maximum attribute value size=], then return failure.
1103-
1. [=list/Append=] \``Path`\`/|encodedPath| to |attributes|.
1104-
1. [=list/Append=] \``Secure`\`/\`\` to |attributes|.
1098+
1. [=list/Append=] (\``Path`\`, |encodedPath|) to |attributes|.
1099+
1. [=list/Append=] (\``Secure`\`, \`\`) to |attributes|.
11051100
1. Switch on |sameSite|:
11061101
<dl class=switch>
11071102
: "{{CookieSameSite/none}}"
1108-
:: [=list/Append=] \``SameSite`\`/\``None`\` to |attributes|.
1103+
:: [=list/Append=] (\``SameSite`\`, \``None`\`) to |attributes|.
11091104
: "{{CookieSameSite/strict}}"
1110-
:: [=list/Append=] \``SameSite`\`/\``Strict`\` to |attributes|.
1105+
:: [=list/Append=] (\``SameSite`\`, \``Strict`\`) to |attributes|.
11111106
: "{{CookieSameSite/lax}}"
1112-
:: [=list/Append=] \``SameSite`\`/\``Lax`\` to |attributes|.
1107+
:: [=list/Append=] (\``SameSite`\`, \``Lax`\`) to |attributes|.
11131108
</dl>
1114-
1. If |partitioned| is true, [=list/Append=] \``Partitioned`\`/\`\` to |attributes|.
1109+
1. If |partitioned| is true, [=list/Append=] (``Partitioned`\`, \`\`) to |attributes|.
11151110
1. Perform the steps defined in [[RFC6265BIS-14#name-storage-model|Cookies § Storage Model]] for when the user agent "receives a cookie" with
11161111
|url| as <var ignore>request-uri</var>,
11171112
|encodedName| as <var ignore>cookie-name</var>,
@@ -1133,13 +1128,12 @@ run the following steps:
11331128

11341129
<div algorithm>
11351130

1136-
To <dfn>delete a cookie</dfn> with
1137-
|url|,
1138-
|name|,
1139-
|domain|,
1140-
|path|, and
1141-
|partitioned|
1142-
run the following steps:
1131+
To <dfn>delete a cookie</dfn> given
1132+
a [=/URL=] |url|,
1133+
[=/scalar value string=] |name|,
1134+
[=/scalar value string=]-or-null |domain|,
1135+
[=/scalar value string=] |path|, and
1136+
[=/boolean=] |partitioned|:
11431137

11441138
1. Let |expires| be the earliest representable date represented [=as a timestamp=].
11451139

@@ -1239,8 +1233,8 @@ To <dfn>fire a change event</dfn> named |type| with |changes| at |target|, run t
12391233

12401234
To <dfn>prepare lists</dfn> from |changes|, run the following steps:
12411235

1242-
1. Let |changedList| be a new [=/list=].
1243-
1. Let |deletedList| be a new [=/list=].
1236+
1. Let |changedList| be « ».
1237+
1. Let |deletedList| be « ».
12441238
1. [=set/For each=] |change| in |changes|, run these steps:
12451239
1. Let |item| be the result of running [=create a CookieListItem=] from |change|'s cookie.
12461240
1. If |change|'s type is *changed*, then [=list/append=] |item| to |changedList|.

0 commit comments

Comments
 (0)