Skip to content

Commit

Permalink
Fix JS example. Fixes #40
Browse files Browse the repository at this point in the history
A variable declared inside a while block is not in scope for the
actual test. Move the declaration outside.

Also, add a few {}, fix indenting, and make something an arrow
function for consistency.

No changes to actual normative spec text, just the examples.
  • Loading branch information
inexorabletash committed Jun 27, 2023
1 parent 2b9e928 commit c58c0e3
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ directory is selected with an <{input}> element:

```js
document.querySelector('#b').addEventListener('change', e => {
for (file entry of e.target.files)
for (file entry of e.target.files) {
console.log(file.name, file.webkitRelativePath);
}
});
```
</div>
Expand All @@ -385,8 +386,9 @@ Enumerating entries using {{HTMLInputElement/webkitEntries}}:

```js
document.querySelector('#a').addEventListener('change', e => {
for (const entry of e.target.webkitEntries)
for (const entry of e.target.webkitEntries) {
handleEntry(entry);
}
});
```
</div>
Expand Down Expand Up @@ -813,25 +815,25 @@ The <dfn method for=FileSystemDirectoryEntry>readEntries(|successCallback|, |err
<div class=example>
Enumerating a directory:
```js
let reader = dirEntry.createReader();
let doBatch = function() {
const reader = dirEntry.createReader();
const doBatch = () => {

// Read a batch.
reader.readEntries(entries => {
// Read a batch.
reader.readEntries(entries => {

// Complete?
if (entries.length === 0) {
return;
}
// Complete?
if (entries.length === 0) {
return;
}

// Process the batch.
entries.forEach(handleEntry);
// Process the batch.
entries.forEach(handleEntry);

// Read the next batch.
doBatch();
// Read the next batch.
doBatch();

}, error => console.warn(error));
};
}, error => console.warn(error));
};

// Start reading
doBatch();
Expand Down Expand Up @@ -872,8 +874,9 @@ async function* getEntriesAsAsyncIterator(dirEntry) {
reader.readEntries(resolve, reject);
});

let entries;
do {
const entries = await getNextBatch();
entries = await getNextBatch();
for (const entry of entries) {
yield entry;
}
Expand All @@ -888,8 +891,9 @@ using `for-await-of`:
async function show(entry) {
console.log(entry.fullPath);
if (entry.isDirectory) {
for await (const e of getEntriesAsAsyncIterator(entry))
for await (const e of getEntriesAsAsyncIterator(entry)) {
await show(e);
}
}
}
```
Expand Down

0 comments on commit c58c0e3

Please sign in to comment.