Skip to content

Commit

Permalink
fixed use of revokeObjectURL
Browse files Browse the repository at this point in the history
as exposed by Deno: denoland/deno#23085

this is an annoyingly subtle mistake, but doesn't quite warrant an
update announcement
  • Loading branch information
FND committed Mar 26, 2024
1 parent e265f77 commit 83e0e01
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions content/articles/web_fs/demo.html
Expand Up @@ -140,7 +140,7 @@ <h1>Local Notes</h1>
function generateDownloadLink(filename, content, type = "text/plain") {
// create virtual document
try {
var blob = new Blob([content], { type });
let blob = new Blob([content], { type });
var uri = URL.createObjectURL(blob);
} catch(err) { // fallback for ancient browsers
uri = `data:${type},${encodeURIComponent(content)}`;
Expand All @@ -152,7 +152,7 @@ <h1>Local Notes</h1>
el.setAttribute("href", uri);
return {
el,
release: () => blob && URL.revokeObjectURL(blob)
release: () => uri && URL.revokeObjectURL(uri)
};
}

Expand Down
6 changes: 3 additions & 3 deletions content/articles/web_fs/index.md
Expand Up @@ -106,9 +106,9 @@ download the respective file instead:
```javascript
function generateDownloadLink(filename, content, type = "text/plain") {
// create virtual document
let blob, uri;
let uri;
try {
blob = new Blob([content], { type });
let blob = new Blob([content], { type });
uri = URL.createObjectURL(blob);
} catch(err) { // fallback for ancient browsers
uri = `data:${type},${encodeURIComponent(content)}`;
Expand All @@ -120,7 +120,7 @@ function generateDownloadLink(filename, content, type = "text/plain") {
el.setAttribute("href", uri);
return {
el,
release: () => blob && URL.revokeObjectURL(blob)
release: () => uri && URL.revokeObjectURL(uri)
};
}
```
Expand Down
5 changes: 3 additions & 2 deletions content/snippets/virtual_modules/demo.html
Expand Up @@ -92,9 +92,10 @@ <h1>Worker Sample</h1>

function code2uri(txt, type = "text/javascript") {
let blob = new Blob([txt], { type });
let uri = URL.createObjectURL(blob);
return {
uri: URL.createObjectURL(blob),
release: () => URL.revokeObjectURL(blob)
uri,
release: () => URL.revokeObjectURL(uri)
};
}

Expand Down
5 changes: 3 additions & 2 deletions content/snippets/virtual_modules/index.md
Expand Up @@ -19,9 +19,10 @@ respective source code:
```javascript
function code2uri(txt, type = "text/javascript") {
let blob = new Blob([txt], { type });
let uri = URL.createObjectURL(blob);
return {
uri: URL.createObjectURL(blob),
release: () => URL.revokeObjectURL(blob)
uri,
release: () => URL.revokeObjectURL(uri)
};
}
```
Expand Down

0 comments on commit 83e0e01

Please sign in to comment.