Repository: denoland/deno
Pull request: feat(ext/web): add `Blob.prototype.bytes()`

<!--
Before submitting a PR, please read https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label.
-->

spec PR: https://github.com/w3c/FileAPI/pull/198


Changed files:
filename: cli/tsc/dts/lib.dom.d.ts
patch: @@ -3121,6 +3121,8 @@ interface Blob {
     readonly type: string;
     /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */
     arrayBuffer(): Promise<ArrayBuffer>;
+    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */
+    bytes(): Promise<Uint8Array>;
     /** [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) */

filename: cli/tsc/dts/lib.webworker.d.ts
patch: @@ -1007,6 +1007,8 @@ interface Blob {
     readonly type: string;
     /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */
     arrayBuffer(): Promise<ArrayBuffer>;
+    /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */
+    bytes(): Promise<Uint8Array>;
     /** [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) */

filename: ext/web/09_file.js
patch: @@ -387,14 +387,9 @@ class Blob {
   }
 
   /**
-   * @returns {Promise<string>}
+   * @param {number} size
+   * @returns {Promise<Uint8Array>}
    */
-  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<string>}
+   */
+  async text() {
+    webidl.assertBranded(this, BlobPrototype);
+    const buffer = await this.#u8Array(this.size);
+    return core.decode(buffer);
+  }
+
   /**
    * @returns {Promise<ArrayBuffer>}
    */
@@ -422,6 +426,14 @@ class Blob {
     return TypedArrayPrototypeGetBuffer(buf);
   }
 
+  /**
+   * @returns {Promise<Uint8Array>}
+   */
+  async bytes() {
+    webidl.assertBranded(this, BlobPrototype);
+    return await this.#u8Array(this.size);
+  }
+
   [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
     return inspect(
       createFilteredInspectProxy({

filename: ext/web/lib.deno_web.d.ts
patch: @@ -533,6 +533,7 @@ declare interface Blob {
   readonly size: number;
   readonly type: string;
   arrayBuffer(): Promise<ArrayBuffer>;
+  bytes(): Promise<Uint8Array>;
   slice(start?: number, end?: number, contentType?: string): Blob;
   stream(): ReadableStream<Uint8Array>;
   text(): Promise<string>;

filename: tests/wpt/runner/expectation.json
patch: @@ -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",