| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0887fa0 commit b8bdaf8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,6 +56,7 @@ const { | |||
| 56 | 56 | ERR_INVALID_ARG_TYPE, | |
| 57 | 57 | ERR_INVALID_ARG_VALUE, | |
| 58 | 58 | ERR_INVALID_THIS, | |
| 59 | + ERR_INVALID_STATE, | ||
| 59 | 60 | ERR_BUFFER_TOO_LARGE, | |
| 60 | 61 | }, | |
| 61 | 62 | } = require('internal/errors'); | |
@@ -74,6 +75,7 @@ const { queueMicrotask } = require('internal/process/task_queues'); | |||
| 74 | 75 | const kHandle = Symbol('kHandle'); | |
| 75 | 76 | const kType = Symbol('kType'); | |
| 76 | 77 | const kLength = Symbol('kLength'); | |
| 78 | + const kNotCloneable = Symbol('kNotCloneable'); | ||
| 77 | 79 | ||
| 78 | 80 | const disallowedTypeCharacters = /[^\u{0020}-\u{007E}]/u; | |
| 79 | 81 | ||
@@ -186,6 +188,11 @@ class Blob { | |||
| 186 | 188 | } | |
| 187 | 189 | ||
| 188 | 190 | [kClone]() { | |
| 191 | + if (this[kNotCloneable]) { | ||
| 192 | + // We do not currently allow file-backed Blobs to be cloned or passed across | ||
| 193 | + // worker threads. | ||
| 194 | + throw new ERR_INVALID_STATE.TypeError('File-backed Blobs are not cloneable'); | ||
| 195 | + } | ||
| 189 | 196 | const handle = this[kHandle]; | |
| 190 | 197 | const type = this[kType]; | |
| 191 | 198 | const length = this[kLength]; | |
@@ -438,7 +445,9 @@ function createBlobFromFilePath(path, options) { | |||
| 438 | 445 | return lazyDOMException('The blob could not be read', 'NotReadableError'); | |
| 439 | 446 | } | |
| 440 | 447 | const { 0: blob, 1: length } = maybeBlob; | |
| 441 | - return createBlob(blob, length, options?.type); | ||
| 448 | + const res = createBlob(blob, length, options?.type); | ||
| 449 | + res[kNotCloneable] = true; | ||
| 450 | + return res; | ||
| 442 | 451 | } | |
| 443 | 452 | ||
| 444 | 453 | module.exports = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ const common = require('../common'); | |||
| 4 | 4 | const { | |
| 5 | 5 | strictEqual, | |
| 6 | 6 | rejects, | |
| 7 | + throws, | ||
| 7 | 8 | } = require('assert'); | |
| 8 | 9 | const { TextDecoder } = require('util'); | |
| 9 | 10 | const { | |
@@ -99,3 +100,14 @@ writeFileSync(testfile3, ''); | |||
| 99 | 100 | const reader = stream.getReader(); | |
| 100 | 101 | await rejects(() => reader.read(), { name: 'NotReadableError' }); | |
| 101 | 102 | })().then(common.mustCall()); | |
| 103 | + | ||
| 104 | + (async () => { | ||
| 105 | + // We currently do not allow File-backed blobs to be cloned or transfered | ||
| 106 | + // across worker threads. This is largely because the underlying FdEntry | ||
| 107 | + // is bound to the Environment/Realm under which is was created. | ||
| 108 | + const blob = await openAsBlob(__filename); | ||
| 109 | + throws(() => structuredClone(blob), { | ||
| 110 | + code: 'ERR_INVALID_STATE', | ||
| 111 | + message: 'Invalid state: File-backed Blobs are not cloneable' | ||
| 112 | + }); | ||
| 113 | + })().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments