| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0f23553 commit 09e2191
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ const { | |||
| 6 | 6 | MathMin, | |
| 7 | 7 | ObjectDefineProperties, | |
| 8 | 8 | ObjectDefineProperty, | |
| 9 | + PromisePrototypeThen, | ||
| 9 | 10 | PromiseReject, | |
| 10 | 11 | ReflectConstruct, | |
| 11 | 12 | RegExpPrototypeExec, | |
@@ -312,6 +313,15 @@ class Blob { | |||
| 312 | 313 | return dec.decode(await this.arrayBuffer()); | |
| 313 | 314 | } | |
| 314 | 315 | ||
| 316 | + bytes() { | ||
| 317 | + if (!isBlob(this)) | ||
| 318 | + throw new ERR_INVALID_THIS('Blob'); | ||
| 319 | + | ||
| 320 | + return PromisePrototypeThen( | ||
| 321 | + this.arrayBuffer(), | ||
| 322 | + (buffer) => new Uint8Array(buffer)); | ||
| 323 | + } | ||
| 324 | + | ||
| 315 | 325 | /** | |
| 316 | 326 | * @returns {ReadableStream} | |
| 317 | 327 | */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | 28 | assert_equals(await slicedBlob.text(), "oo"); | |
| 29 | 29 | assert_equals(charCodeBufferToString(await slicedBlob.arrayBuffer()), "oo"); | |
| 30 | + assert_equals(charCodeArrayToString(await slicedBlob.bytes()), "oo"); | ||
| 30 | 31 | ||
| 31 | 32 | const reader = slicedBlob.stream().getReader(); | |
| 32 | 33 | const { value } = await reader.read(); | |
@@ -48,6 +49,14 @@ | |||
| 48 | 49 | assert_equals(charCodeBufferToString(charCodeBuffer), "bar"); | |
| 49 | 50 | }, "arrayBuffer()"); | |
| 50 | 51 | ||
| 52 | + promise_test(async () => { | ||
| 53 | + const { bytes } = await BlobPrototypeFromDetachedFramePromise; | ||
| 54 | + const blob = new Blob(["bar"]); | ||
| 55 | + | ||
| 56 | + const charCodeBytes = await bytes.call(blob); | ||
| 57 | + assert_equals(charCodeArrayToString(charCodeBytes), "bar"); | ||
| 58 | + }, "bytes()"); | ||
| 59 | + | ||
| 51 | 60 | promise_test(async () => { | |
| 52 | 61 | const { stream } = await BlobPrototypeFromDetachedFramePromise; | |
| 53 | 62 | const blob = new Blob(["baz"]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | spec: https://w3c.github.io/FileAPI/ | |
| 2 | 2 | suggested_reviewers: | |
| 3 | 3 | - inexorabletash | |
| 4 | - - zqzhang | ||
| 5 | 4 | - jdm | |
| 6 | 5 | - mkruisselbrink | |
| 6 | + - annevk | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,45 @@ | |||
| 1 | + // META: title=Blob bytes() | ||
| 2 | + // META: script=../support/Blob.js | ||
| 3 | + 'use strict'; | ||
| 4 | + | ||
| 5 | + promise_test(async () => { | ||
| 6 | + const input_arr = new TextEncoder().encode("PASS"); | ||
| 7 | + const blob = new Blob([input_arr]); | ||
| 8 | + const uint8array = await blob.bytes(); | ||
| 9 | + assert_true(uint8array instanceof Uint8Array); | ||
| 10 | + assert_equals_typed_array(uint8array, input_arr); | ||
| 11 | + }, "Blob.bytes()") | ||
| 12 | + | ||
| 13 | + promise_test(async () => { | ||
| 14 | + const input_arr = new TextEncoder().encode(""); | ||
| 15 | + const blob = new Blob([input_arr]); | ||
| 16 | + const uint8array = await blob.bytes(); | ||
| 17 | + assert_true(uint8array instanceof Uint8Array); | ||
| 18 | + assert_equals_typed_array(uint8array, input_arr); | ||
| 19 | + }, "Blob.bytes() empty Blob data") | ||
| 20 | + | ||
| 21 | + promise_test(async () => { | ||
| 22 | + const input_arr = new TextEncoder().encode("\u08B8\u000a"); | ||
| 23 | + const blob = new Blob([input_arr]); | ||
| 24 | + const uint8array = await blob.bytes(); | ||
| 25 | + assert_equals_typed_array(uint8array, input_arr); | ||
| 26 | + }, "Blob.bytes() non-ascii input") | ||
| 27 | + | ||
| 28 | + promise_test(async () => { | ||
| 29 | + const input_arr = [8, 241, 48, 123, 151]; | ||
| 30 | + const typed_arr = new Uint8Array(input_arr); | ||
| 31 | + const blob = new Blob([typed_arr]); | ||
| 32 | + const uint8array = await blob.bytes(); | ||
| 33 | + assert_equals_typed_array(uint8array, typed_arr); | ||
| 34 | + }, "Blob.bytes() non-unicode input") | ||
| 35 | + | ||
| 36 | + promise_test(async () => { | ||
| 37 | + const input_arr = new TextEncoder().encode("PASS"); | ||
| 38 | + const blob = new Blob([input_arr]); | ||
| 39 | + const uint8array_results = await Promise.all([blob.bytes(), | ||
| 40 | + blob.bytes(), blob.bytes()]); | ||
| 41 | + for (let uint8array of uint8array_results) { | ||
| 42 | + assert_true(uint8array instanceof Uint8Array); | ||
| 43 | + assert_equals_typed_array(uint8array, input_arr); | ||
| 44 | + } | ||
| 45 | + }, "Blob.bytes() concurrent reads") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -290,10 +290,11 @@ test_blob(function() { | |||
| 290 | 290 | new Int16Array([0x4150, 0x5353]), | |
| 291 | 291 | new Uint32Array([0x53534150]), | |
| 292 | 292 | new Int32Array([0x53534150]), | |
| 293 | + new Float16Array([2.65625, 58.59375]), | ||
| 293 | 294 | new Float32Array([0xD341500000]) | |
| 294 | 295 | ]); | |
| 295 | 296 | }, { | |
| 296 | - expected: "PASSPASSPASSPASSPASSPASSPASS", | ||
| 297 | + expected: "PASSPASSPASSPASSPASSPASSPASSPASS", | ||
| 297 | 298 | type: "", | |
| 298 | 299 | desc: "Passing typed arrays as elements of the blobParts array should work." | |
| 299 | 300 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,18 @@ promise_test(async() => { | |||
| 70 | 70 | await garbageCollect(); | |
| 71 | 71 | const chunks = await read_all_chunks(stream, { perform_gc: true }); | |
| 72 | 72 | assert_array_equals(chunks, input_arr); | |
| 73 | - }, "Blob.stream() garbage collection of blob shouldn't break stream" + | ||
| 73 | + }, "Blob.stream() garbage collection of blob shouldn't break stream " + | ||
| 74 | + "consumption") | ||
| 75 | + | ||
| 76 | + promise_test(async() => { | ||
| 77 | + const input_arr = [8, 241, 48, 123, 151]; | ||
| 78 | + const typed_arr = new Uint8Array(input_arr); | ||
| 79 | + let blob = new Blob([typed_arr]); | ||
| 80 | + const chunksPromise = read_all_chunks(blob.stream()); | ||
| 81 | + // It somehow matters to do GC here instead of doing `perform_gc: true` | ||
| 82 | + await garbageCollect(); | ||
| 83 | + assert_array_equals(await chunksPromise, input_arr); | ||
| 84 | + }, "Blob.stream() garbage collection of stream shouldn't break stream " + | ||
| 74 | 85 | "consumption") | |
| 75 | 86 | ||
| 76 | 87 | promise_test(async () => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ Last update: | |||
| 16 | 16 | - dom/events: https://github.com/web-platform-tests/wpt/tree/ab8999891c/dom/events | |
| 17 | 17 | - encoding: https://github.com/web-platform-tests/wpt/tree/a58bbf6d8c/encoding | |
| 18 | 18 | - fetch/data-urls/resources: https://github.com/web-platform-tests/wpt/tree/7c79d998ff/fetch/data-urls/resources | |
| 19 | - - FileAPI: https://github.com/web-platform-tests/wpt/tree/e36dbb6f00/FileAPI | ||
| 19 | + - FileAPI: https://github.com/web-platform-tests/wpt/tree/cceaf3628d/FileAPI | ||
| 20 | 20 | - hr-time: https://github.com/web-platform-tests/wpt/tree/34cafd797e/hr-time | |
| 21 | 21 | - html/webappapis/atob: https://github.com/web-platform-tests/wpt/tree/f267e1dca6/html/webappapis/atob | |
| 22 | 22 | - html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ | |||
| 24 | 24 | "path": "fetch/data-urls/resources" | |
| 25 | 25 | }, | |
| 26 | 26 | "FileAPI": { | |
| 27 | - "commit": "e36dbb6f00fb59f9fc792f509194432e9e6d0b6d", | ||
| 27 | + "commit": "cceaf3628da950621004d9b5d8c1d1f367073347", | ||
| 28 | 28 | "path": "FileAPI" | |
| 29 | 29 | }, | |
| 30 | 30 | "hr-time": { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments