diff --git a/cli/tsc/dts/lib.dom.d.ts b/cli/tsc/dts/lib.dom.d.ts index f0af1798cfb35f..1fa8798cb3734b 100644 --- a/cli/tsc/dts/lib.dom.d.ts +++ b/cli/tsc/dts/lib.dom.d.ts @@ -3121,6 +3121,8 @@ interface Blob { readonly type: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */ arrayBuffer(): Promise; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */ + bytes(): Promise; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */ slice(start?: number, end?: number, contentType?: string): Blob; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */ diff --git a/cli/tsc/dts/lib.webworker.d.ts b/cli/tsc/dts/lib.webworker.d.ts index 7ffd63c4b2cbc9..3f722c1b0bc3f9 100644 --- a/cli/tsc/dts/lib.webworker.d.ts +++ b/cli/tsc/dts/lib.webworker.d.ts @@ -1007,6 +1007,8 @@ interface Blob { readonly type: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */ arrayBuffer(): Promise; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */ + bytes(): Promise; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */ slice(start?: number, end?: number, contentType?: string): Blob; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */ diff --git a/ext/web/09_file.js b/ext/web/09_file.js index 482a1401221333..7c1d79ce315b24 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -387,14 +387,9 @@ class Blob { } /** - * @returns {Promise} + * @param {number} size + * @returns {Promise} */ - async text() { - webidl.assertBranded(this, BlobPrototype); - const buffer = await this.#u8Array(this.size); - return core.decode(buffer); - } - async #u8Array(size) { const bytes = new Uint8Array(size); const partIterator = toIterator(this[_parts]); @@ -413,6 +408,15 @@ class Blob { return bytes; } + /** + * @returns {Promise} + */ + async text() { + webidl.assertBranded(this, BlobPrototype); + const buffer = await this.#u8Array(this.size); + return core.decode(buffer); + } + /** * @returns {Promise} */ @@ -422,6 +426,14 @@ class Blob { return TypedArrayPrototypeGetBuffer(buf); } + /** + * @returns {Promise} + */ + async bytes() { + webidl.assertBranded(this, BlobPrototype); + return await this.#u8Array(this.size); + } + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { return inspect( createFilteredInspectProxy({ diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index 36c77ef81826d9..2fdf1c880f9c2a 100644 --- a/ext/web/lib.deno_web.d.ts +++ b/ext/web/lib.deno_web.d.ts @@ -533,6 +533,7 @@ declare interface Blob { readonly size: number; readonly type: string; arrayBuffer(): Promise; + bytes(): Promise; slice(start?: number, end?: number, contentType?: string): Blob; stream(): ReadableStream; text(): Promise; diff --git a/tests/wpt/runner/expectation.json b/tests/wpt/runner/expectation.json index e80fbf92220941..74eef815944dc2 100644 --- a/tests/wpt/runner/expectation.json +++ b/tests/wpt/runner/expectation.json @@ -10109,8 +10109,8 @@ "Blob-text.any.worker.html": true, "Blob-in-worker.worker.html": true, "Blob-constructor-dom.window.html": false, - "Blob-bytes.any.html": false, - "Blob-bytes.any.worker.html": false, + "Blob-bytes.any.html": true, + "Blob-bytes.any.worker.html": true, "Blob-constructor-endings.html": false }, "file": { @@ -10183,9 +10183,6 @@ "filereader_result.any.worker.html": true }, "idlharness.any.html": [ - "Blob interface: operation bytes()", - "Blob interface: new Blob([\"TEST\"]) must inherit property \"bytes()\" with the proper type", - "Blob interface: new File([\"myFileBits\"], \"myFileName\") must inherit property \"bytes()\" with the proper type", "FileList interface: existence and properties of interface object", "FileList interface object length", "FileList interface object name", @@ -10196,9 +10193,6 @@ "FileList interface: attribute length" ], "idlharness.any.worker.html": [ - "Blob interface: operation bytes()", - "Blob interface: new Blob([\"TEST\"]) must inherit property \"bytes()\" with the proper type", - "Blob interface: new File([\"myFileBits\"], \"myFileName\") must inherit property \"bytes()\" with the proper type", "FileList interface: existence and properties of interface object", "FileList interface object length", "FileList interface object name", @@ -10220,7 +10214,6 @@ ], "FileReaderSync.worker.html": false, "idlharness.worker.html": [ - "Blob interface: operation bytes()", "FileList interface: existence and properties of interface object", "FileList interface object length", "FileList interface object name", @@ -10265,7 +10258,6 @@ "Service worker test setup" ], "idlharness.html": [ - "Blob interface: operation bytes()", "FileList interface: existence and properties of interface object", "FileList interface object length", "FileList interface object name",