Skip to content

Commit aff3e07

Browse files
committed
rebase + make access checks not throwable
1 parent eb2a884 commit aff3e07

File tree

1 file changed

+88
-61
lines changed

1 file changed

+88
-61
lines changed

index.bs

Lines changed: 88 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,31 @@ different storage mechanism with a different API for such files. The entry point
6161

6262
A <dfn export id="entry">file system entry</dfn> is either a [=file entry=] or a [=directory entry=].
6363

64-
Each [=/file system entry=] has an associated <dfn for="file system entry" id=entry-query-access>query access</dfn> algorithm, which takes "`read`"
65-
or "`readwrite`" <var ignore>mode</var> and returns a {{PermissionState}}. Unless specified
66-
otherwise it returns "{{PermissionState/denied}}". The algorithm is allowed to throw.
67-
68-
Each [=/file system entry=] has an associated <dfn for="file system entry" id=entry-request-access>request access</dfn> algorithm, which takes
69-
"`read`" or "`readwrite`" <var ignore>mode</var> and returns a {{PermissionState}}. Unless specified
70-
otherwise it returns "{{PermissionState/denied}}". The algorithm is allowed to throw.
71-
72-
Note: Implementations that only implement this specification and not dependent specifications do not
73-
need to bother implementing [=/file system entry=]'s [=file system entry/query access=] and [=file system entry/request access=].
64+
Each [=/file system entry=] has an associated
65+
<dfn for="file system entry" id=entry-query-access>query access</dfn>
66+
algorithm, which takes "`read`" or "`readwrite`" <var ignore>mode</var> and
67+
returns either a {{PermissionState}} or an [=exception/error name=] that must be
68+
listed in the [=error names table=].
69+
Unless specified otherwise it returns "{{PermissionState/denied}}".
70+
71+
Each [=/file system entry=] has an associated
72+
<dfn for="file system entry" id=entry-request-access>request access</dfn>
73+
algorithm, which takes "`read`" or "`readwrite`" <var ignore>mode</var> and
74+
returns either a {{PermissionState}} or an [=exception/error name=] that must be
75+
listed in the [=error names table=].
76+
Unless specified otherwise it returns "{{PermissionState/denied}}".
77+
78+
<p class=warning> Dependent specifications may consider this API a
79+
[=powerful feature=]. However, unlike other [=powerful features=] whose
80+
[=permission request algorithm=] may throw, [=/file system entry=]'s
81+
[=file system entry/query access=] and [=file system entry/request access=]
82+
algorithms must run [=in parallel=] on the [=file system queue=] and are
83+
therefore not allowed to throw. Instead, the caller is expected to [=/reject=]
84+
as appropriate should these algorithms return an [=exception/error name=].
85+
86+
Note: Implementations that only implement this specification and not dependent
87+
specifications do not need to bother implementing [=/file system entry=]'s
88+
[=file system entry/query access=] and [=file system entry/request access=].
7489

7590
Issue(101): Make access check algorithms associated with a FileSystemHandle.
7691

@@ -504,31 +519,33 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method
504519
1. Let |result| be [=a new promise=].
505520
1. Let |locator| be [=this=]'s [=FileSystemHandle/locator=].
506521
1. Let |realm| be [=this=]'s [=relevant Realm=].
507-
1. [=Queue a storage task=] with [=this=]'s [=relevant global object=] to
508-
[=enqueue the following steps=] to the [=file system queue=]:
522+
1. Let |global| be [=this=]'s [=relevant global object=].
523+
1. [=Enqueue the following steps=] to the [=file system queue=]:
509524
1. Let |entry| be the result of [=locating an entry=] given |locator|.
510525
1. Let |access| be the result of running |entry|'s
511526
[=file system entry/request access=] given "`readwrite`".
512-
If that throws an exception, [=reject=] |result| with that exception and
513-
abort these steps.
514-
1. If |access| is not "{{PermissionState/granted}}",
515-
[=reject=] |result| with a "{{NotAllowedError}}" {{DOMException}} and
516-
abort these steps.
517-
518-
1. If |entry| is `null`, [=/reject=] |result| with a
519-
"{{NotFoundError}}" {{DOMException}} and abort.
527+
1. If |access| is not "{{PermissionState/granted}}":
528+
1. Set |requestAccessError| to |access| if |access| is an
529+
[=exception/error name=]; otherwise, "{{NotAllowedError}}".
530+
1. [=Queue a storage task=] with |global| to [=/reject=] |result| with a
531+
|requestAccessError| {{DOMException}} and abort these steps.
532+
533+
1. If |entry| is `null`, [=queue a storage task=] with |global| to [=/reject=]
534+
|result| with a "{{NotFoundError}}" {{DOMException}} and abort these steps.
520535
1. [=Assert=]: |entry| is a [=file entry=].
521536

522537
1. Let |lockResult| be the result of [=file entry/lock/take|taking a lock=]
523538
with "`shared`" on |entry|.
524-
1. If |lockResult| is "`failure`", [=reject=] |result| with a
539+
1. If |lockResult| is "`failure`", [=queue a storage task=] with |global| to
540+
[=/reject=] |result| with a
525541
"{{NoModificationAllowedError}}" {{DOMException}} and abort these steps.
526542

527-
1. Let |stream| be the result of <a>creating a new `FileSystemWritableFileStream`</a>
528-
for |entry| in |realm|.
529-
1. If |options|'s {{FileSystemCreateWritableOptions/keepExistingData}} is true:
530-
1. Set |stream|'s [=[[buffer]]=] to a copy of |entry|'s [=file entry/binary data=].
531-
1. [=/Resolve=] |result| with |stream|.
543+
1. [=Queue a storage task=] with |global| to run these steps:
544+
1. Let |stream| be the result of <a>creating a new `FileSystemWritableFileStream`</a>
545+
for |entry| in |realm|.
546+
1. If |options|'s {{FileSystemCreateWritableOptions/keepExistingData}} is true:
547+
1. Set |stream|'s [=[[buffer]]=] to a copy of |entry|'s [=file entry/binary data=].
548+
1. [=/Resolve=] |result| with |stream|.
532549

533550
1. Return |result|.
534551

@@ -562,31 +579,36 @@ The <dfn method for=FileSystemFileHandle>createSyncAccessHandle()</dfn> method s
562579
1. Let |result| be [=a new promise=].
563580
1. Let |locator| be [=this=]'s [=FileSystemHandle/locator=].
564581
1. Let |realm| be [=this=]'s [=relevant Realm=].
582+
1. Let |global| be [=this=]'s [=relevant global object=].
565583
1. [=Enqueue the following steps=] to the [=file system queue=]:
566584
1. Let |entry| be the result of [=locating an entry=] given |locator|.
567585
1. Let |access| be the result of running |entry|'s
568586
[=file system entry/request access=] given "`readwrite`".
569-
If that throws an exception, [=reject=] |result| with that exception and
570-
abort these steps.
571-
1. If |access| is not "{{PermissionState/granted}}", [=reject=] |result| with
572-
a "{{NotAllowedError}}" {{DOMException}} and abort these steps.
573-
574-
1. If |entry| is `null`, [=/reject=] |result| with a
575-
"{{NotFoundError}}" {{DOMException}} and abort.
587+
1. If |access| is not "{{PermissionState/granted}}":
588+
1. Set |requestAccessError| to |access| if |access| is an
589+
[=exception/error name=]; otherwise, "{{NotAllowedError}}".
590+
1. [=Queue a storage task=] with |global| to [=/reject=] |result| with a
591+
|requestAccessError| {{DOMException}} and abort these steps.
592+
593+
1. If |entry| is `null`, [=queue a storage task=] with |global| to [=/reject=]
594+
|result| with a "{{NotFoundError}}" {{DOMException}} and abort these steps.
576595
1. [=Assert=]: |entry| is a [=file entry=].
577596

578-
1. If |entry| does not represent a [=/file system entry=] in an [=origin private file system=],
579-
[=reject=] |result| with an "{{InvalidStateError}}" {{DOMException}} and
597+
1. If |entry| does not represent a [=/file system entry=] in an
598+
[=origin private file system=], [=queue a storage task=] with |global| to
599+
[=/reject=] |result| with an "{{InvalidStateError}}" {{DOMException}} and
580600
abort these steps.
581601

582602
1. Let |lockResult| be the result of [=file entry/lock/take|taking a lock=]
583603
with "`exclusive`" on |entry|.
584-
1. If |lockResult| is "`failure`", [=reject=] |result| with a
604+
1. If |lockResult| is "`failure`", [=queue a storage task=] with |global| to
605+
[=/reject=] |result| with a
585606
"{{NoModificationAllowedError}}" {{DOMException}} and abort these steps.
586607

587-
1. Let |handle| be the result of <a>creating a new `FileSystemSyncAccessHandle`</a>
588-
for |entry| in |realm|.
589-
1. [=/Resolve=] |result| with |handle|.
608+
1. [=Queue a storage task=] with |global| to run these steps:
609+
1. Let |handle| be the result of <a>creating a new `FileSystemSyncAccessHandle`</a>
610+
for |entry| in |realm|.
611+
1. [=/Resolve=] |result| with |handle|.
590612

591613
1. Return |result|.
592614

@@ -707,7 +729,7 @@ and its async iterator |iterator|:
707729
[=file system entry/query access=] given "`read`".
708730

709731
1. If |access| is not "{{PermissionState/granted}}",
710-
[=reject=] |promise| with a "{{NotAllowedError}}" {{DOMException}} and
732+
[=/reject=] |promise| with a "{{NotAllowedError}}" {{DOMException}} and
711733
return |promise|.
712734

713735
1. Let |child| be a [=/file system entry=] in |directory|'s [=directory entry/children=],
@@ -774,7 +796,7 @@ The <dfn method for=FileSystemDirectoryHandle>getFileHandle(|name|, |options|)</
774796
1. If |options|.{{FileSystemGetFileOptions/create}} is true:
775797
1. Let |access| be the result of running |entry|'s
776798
[=file system entry/request access=] given "`readwrite`".
777-
If that throws an exception, [=reject=] |result| with that exception and abort.
799+
If that throws an exception, [=/reject=] |result| with that exception and abort.
778800
1. Otherwise:
779801
1. Let |access| be the result of running |entry|'s
780802
[=file system entry/query access=] given "`read`".
@@ -848,7 +870,7 @@ The <dfn method for=FileSystemDirectoryHandle>getDirectoryHandle(|name|, |option
848870
1. If |options|.{{FileSystemGetDirectoryOptions/create}} is true:
849871
1. Let |access| be the result of running |entry|'s
850872
[=file system entry/request access=] given "`readwrite`".
851-
If that throws an exception, [=reject=] |result| with that exception and abort.
873+
If that throws an exception, [=/reject=] |result| with that exception and abort.
852874
1. Otherwise:
853875
1. Let |access| be the result of running |entry|'s
854876
[=file system entry/query access=] given "`read`".
@@ -915,7 +937,7 @@ The <dfn method for=FileSystemDirectoryHandle>removeEntry(|name|, |options|)</df
915937
1. Let |entry| be the result of [=locating an entry=] given |locator|.
916938
1. Let |access| be the result of running |entry|'s
917939
[=file system entry/request access=] given "`readwrite`".
918-
If that throws an exception, [=reject=] |result| with that exception and abort.
940+
If that throws an exception, [=/reject=] |result| with that exception and abort.
919941
1. If |access| is not "{{PermissionState/granted}}",
920942
[=/reject=] |result| with a "{{NotAllowedError}}" {{DOMException}} and abort.
921943

@@ -1065,24 +1087,29 @@ given a [=file entry=] |file| in a [=/Realm=] |realm|:
10651087
1. [=Enqueue the following steps=] to the [=file system queue=]:
10661088
1. Let |access| be the result of running |file|'s
10671089
[=file system entry/query access=] given "`readwrite`".
1068-
1. If |access| is not "{{PermissionState/granted}}",
1069-
[=/reject=] |closeResult| with a "{{NotAllowedError}}" {{DOMException}}
1070-
and abort these steps.
1071-
1072-
1. Run [=implementation-defined=] malware scans and safe browsing checks.
1073-
If these checks fail, [=/reject=] |closeResult| with an
1074-
"{{AbortError}}" {{DOMException}} and abort these steps.
1075-
1. Set |stream|'s [=FileSystemWritableFileStream/[[file]]=]'s
1076-
[=file entry/binary data=] to |stream|'s [=[[buffer]]=].
1077-
If that throws an exception, [=/reject=] |closeResult| with that
1078-
exception and abort these steps.
1079-
1080-
Note: It is expected that this atomically updates the contents of the
1081-
file on disk being written to.
1082-
1083-
1. [=file entry/lock/release|Release the lock=] on
1084-
|stream|'s [=FileSystemWritableFileStream/[[file]]=].
1085-
1. [=/Resolve=] |closeResult| with `undefined`.
1090+
1. If |access| is not "{{PermissionState/granted}}":
1091+
1. Set |requestAccessError| to |access| if |access| is an
1092+
[=exception/error name=]; otherwise, "{{NotAllowedError}}".
1093+
1. [=Queue a storage task=] with |file|'s [=relevant global object=] to
1094+
[=/reject=] |closeResult| with a
1095+
|requestAccessError| {{DOMException}} and abort these steps.
1096+
1097+
1. [=Queue a storage task=] with |file|'s [=relevant global object=]
1098+
to run these steps:
1099+
1. Run [=implementation-defined=] malware scans and safe browsing checks.
1100+
If these checks fail, [=/reject=] |closeResult| with an
1101+
"{{AbortError}}" {{DOMException}} and abort these steps.
1102+
1. Set |stream|'s [=FileSystemWritableFileStream/[[file]]=]'s
1103+
[=file entry/binary data=] to |stream|'s [=[[buffer]]=].
1104+
If that throws an exception, [=/reject=] |closeResult| with that
1105+
exception and abort these steps.
1106+
1107+
Note: It is expected that this atomically updates the contents of the
1108+
file on disk being written to.
1109+
1110+
1. [=file entry/lock/release|Release the lock=] on
1111+
|stream|'s [=FileSystemWritableFileStream/[[file]]=].
1112+
1. [=/Resolve=] |closeResult| with `undefined`.
10861113

10871114
1. Return |closeResult|.
10881115
1. Let |abortAlgorithm| be these steps:

0 commit comments

Comments
 (0)