Skip to content

Commit b345282

Browse files
dslee414a-sullyannevk
authored
Update FileSystemSyncAccessHandle async methods to sync (#55)
* Update index.bs Update FileSystemSyncAccessHandle methods all sync. * Update index.bs Change the return type to `undefined` from `void` * Fix typo for FileSystemSyncAccessHandle.file * Update index.bs Co-authored-by: Anne van Kesteren <[email protected]> Co-authored-by: Austin Sullivan <[email protected]> Co-authored-by: Anne van Kesteren <[email protected]>
1 parent ad813af commit b345282

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed

index.bs

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,8 @@ The <dfn method for=FileSystemFileHandle>createWritable(|options|)</dfn> method,
375375
further {{FileSystemSyncAccessHandle}}s or {{FileSystemWritableFileStream}}s
376376
for the entry, until the access handle is closed.
377377

378-
The returned {{FileSystemSyncAccessHandle}} offers synchronous {{FileSystemSyncAccessHandle/read()}} and
379-
{{FileSystemSyncAccessHandle/write()}} methods. This allows for higher performance for critical methods on
380-
contexts where asynchronous operations come with high overhead, e.g., WebAssembly.
378+
The returned {{FileSystemSyncAccessHandle}} offers synchronous methods. This allows for higher performance
379+
on contexts where asynchronous operations come with high overhead, e.g., WebAssembly.
381380

382381
For the time being, this method will only succeed when the |fileHandle| belongs to the
383382
[=origin private file system=].
@@ -1035,10 +1034,10 @@ interface FileSystemSyncAccessHandle {
10351034
unsigned long long write([AllowShared] BufferSource buffer,
10361035
optional FileSystemReadWriteOptions options = {});
10371036

1038-
Promise<undefined> truncate([EnforceRange] unsigned long long newSize);
1039-
Promise<unsigned long long> getSize();
1040-
Promise<undefined> flush();
1041-
Promise<undefined> close();
1037+
undefined truncate([EnforceRange] unsigned long long newSize);
1038+
unsigned long long getSize();
1039+
undefined flush();
1040+
undefined close();
10421041
};
10431042

10441043
</xmp>
@@ -1052,9 +1051,8 @@ a string that may exclusively be "`open`" or "`closed`".
10521051
A {{FileSystemSyncAccessHandle}} is an object that is capable of reading from/writing to,
10531052
as well as obtaining and changing the size of, a single file.
10541053

1055-
The {{FileSystemSyncAccessHandle/read()}} and {{FileSystemSyncAccessHandle/write()}} methods are synchronous.
1056-
This allows for higher performance for critical methods on contexts where asynchronous
1057-
operations come with high overhead, e.g., WebAssembly.
1054+
A {{FileSystemSyncAccessHandle}} offers synchronous methods. This allows for higher performance on
1055+
contexts where asynchronous operations come with high overhead, e.g., WebAssembly.
10581056

10591057
<div algorithm>
10601058
To <dfn>create a new FileSystemSyncAccessHandle</dfn> given a [=file entry=] |file|
@@ -1114,7 +1112,7 @@ these steps:
11141112
The <dfn method for=FileSystemSyncAccessHandle>write(|buffer|, {{FileSystemReadWriteOptions}}: |options|)</dfn> method, when invoked, must run
11151113
these steps:
11161114

1117-
1. If [=this=].[=[[state]]=] is "`closed`", throw a {{InvalidStateError}}.
1115+
1. If [=this=].[=[[state]]=] is "`closed`", throw an {{InvalidStateError}}.
11181116
1. Let |writePosition| be |options|.{{FileSystemReadWriteOptions/at}}.
11191117
1. Let |fileContents| be a copy of [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=].
11201118
1. Let |oldSize| be |fileContents|'s [=byte sequence/length=].
@@ -1161,26 +1159,21 @@ these steps:
11611159
The <dfn method for=FileSystemSyncAccessHandle>truncate(|newSize|)</dfn> method, when invoked, must run
11621160
these steps:
11631161

1164-
1. If [=this=].[=[[state]]=] is "`closed`", return [=a promise rejected with=] an {{InvalidStateError}}.
1162+
1. If [=this=].[=[[state]]=] is "`closed`", throw an {{InvalidStateError}}.
11651163
1. Let |fileContents| be a copy of [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=].
1166-
1. Let |p| be [=a new promise=] created in the [=relevant Realm=] of [=this=].
1167-
1. Run the following steps [=in parallel=]:
1168-
1. Let |oldSize| be the [=byte sequence/length=] of [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=].
1169-
1. If |newSize| is larger than |oldSize|:
1170-
1. If |newSize| &minus; |oldSize| exceeds the available [=storage quota=], [=/reject=] |p|
1171-
with a {{QuotaExceededError}} and abort.
1172-
1. Set [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s to a [=byte sequence=] formed by concatenating
1173-
|fileContents| with a [=byte sequence=]
1174-
containing |newSize| &minus; |oldSize| 0x00 bytes.
1175-
1. If the operations modifying the [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=] in the previous steps
1176-
failed, [=/reject=] |p| with a {{InvalidStateError}} and abort.
1177-
1. Otherwise, if |newSize| is smaller than |oldSize|:
1178-
1. Set [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s to a [=byte sequence=] containing the first |newSize| bytes
1179-
in |fileContents|.
1180-
1. If the operations modifying the [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=] in the previous steps
1181-
failed, [=/reject=] |p| with a {{InvalidStateError}} and abort.
1182-
1. [=/Resolve=] |p|.
1183-
1. Return |p|.
1164+
1. 1. Let |oldSize| be the [=byte sequence/length=] of [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=].
1165+
1. If |newSize| is larger than |oldSize|:
1166+
1. If |newSize| &minus; |oldSize| exceeds the available [=storage quota=], throw a {{QuotaExceededError}}.
1167+
1. Set [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s to a [=byte sequence=] formed by concatenating
1168+
|fileContents| with a [=byte sequence=]
1169+
containing |newSize| &minus; |oldSize| 0x00 bytes.
1170+
1. If the operations modifying the [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=] in the previous steps
1171+
failed, throw an {{InvalidStateError}}.
1172+
1. Otherwise, if |newSize| is smaller than |oldSize|:
1173+
1. Set [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s to a [=byte sequence=] containing the first |newSize| bytes
1174+
in |fileContents|.
1175+
1. If the operations modifying the [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=] in the previous steps
1176+
failed, throw an {{InvalidStateError}}.
11841177

11851178
</div>
11861179

@@ -1195,12 +1188,8 @@ these steps:
11951188
The <dfn method for=FileSystemSyncAccessHandle>getSize()</dfn> method, when invoked, must run
11961189
these steps:
11971190

1198-
1. If [=this=].[=[[state]]=] is "`closed`", return [=a promise rejected with=] an {{InvalidStateError}}.
1199-
1. Let |p| be [=a new promise=] created in the [=relevant Realm=] of [=this=].
1200-
1. Run the following steps [=in parallel=]:
1201-
1. Let |size| be the [=byte sequence/length=] of [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=].
1202-
1. [=/Resolve=] |p| with |size|.
1203-
1. Return |p|.
1191+
1. If [=this=].[=[[state]]=] is "`closed`", throw an {{InvalidStateError}}.
1192+
1. Return [=this=].[=FileSystemSyncAccessHandle/[[file]]=]'s [=file entry/binary data=]'s [=byte sequence/length=].
12041193

12051194

12061195
</div>
@@ -1233,11 +1222,7 @@ these steps:
12331222
The <dfn method for=FileSystemSyncAccessHandle>close()</dfn> method, when invoked, must run
12341223
these steps:
12351224

1236-
1. Let |p| be [=a new promise=] created in the [=relevant Realm=] of [=this=].
1237-
1. Run the following steps [=in parallel=]:
1238-
1. Set [=this=].[=[[state]]=] to "`closed`".
1239-
1. [=/Resolve=] |p|.
1240-
1. Return |p|.
1225+
1. Set [=this=].[=[[state]]=] to "`closed`".
12411226

12421227
</div>
12431228

0 commit comments

Comments
 (0)