diff options
author | 2022-11-19 23:37:52 -0800 | |
---|---|---|
committer | 2022-11-19 23:37:52 -0800 | |
commit | 2f1e9b2eb8ab4f210dd356735f5b610deb89987b (patch) | |
tree | 45067ccc7a4ae7d61e73f0f08c98840ac87ec4ba | |
parent | c68b11e8cbf493723d0b2e029fe6e10d1fe7e83d (diff) | |
download | bun-2f1e9b2eb8ab4f210dd356735f5b610deb89987b.tar.gz bun-2f1e9b2eb8ab4f210dd356735f5b610deb89987b.tar.zst bun-2f1e9b2eb8ab4f210dd356735f5b610deb89987b.zip |
[streams] Fix exception in `WritableStream`
cc @Electroid
-rw-r--r-- | src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp | 7 | ||||
-rw-r--r-- | src/bun.js/builtins/js/StreamInternals.js | 5 | ||||
-rw-r--r-- | test/bun.js/streams.test.js | 70 |
3 files changed, 39 insertions, 43 deletions
diff --git a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp index 7886b5678..a957a7c2b 100644 --- a/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp +++ b/src/bun.js/builtins/cpp/StreamInternalsBuiltins.cpp @@ -362,16 +362,13 @@ const char* const s_streamInternalsEnqueueValueWithSizeCode = const JSC::ConstructAbility s_streamInternalsPeekQueueValueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_streamInternalsPeekQueueValueCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_streamInternalsPeekQueueValueCodeImplementationVisibility = JSC::ImplementationVisibility::Public; -const int s_streamInternalsPeekQueueValueCodeLength = 116; +const int s_streamInternalsPeekQueueValueCodeLength = 81; static const JSC::Intrinsic s_streamInternalsPeekQueueValueCodeIntrinsic = JSC::NoIntrinsic; const char* const s_streamInternalsPeekQueueValueCode = "(function (queue)\n" \ "{\n" \ " \"use strict\";\n" \ - "\n" \ - " @assert(queue.content.isNotEmpty());\n" \ - "\n" \ - " return queue.peek()?.value;\n" \ + " return queue.content.peek()?.value;\n" \ "})\n" \ ; diff --git a/src/bun.js/builtins/js/StreamInternals.js b/src/bun.js/builtins/js/StreamInternals.js index 5e447c29c..78bcdcfb3 100644 --- a/src/bun.js/builtins/js/StreamInternals.js +++ b/src/bun.js/builtins/js/StreamInternals.js @@ -256,10 +256,7 @@ function enqueueValueWithSize(queue, value, size) function peekQueueValue(queue) { "use strict"; - - @assert(queue.content.isNotEmpty()); - - return queue.peek()?.value; + return queue.content.peek()?.value; } function resetQueue(queue) diff --git a/test/bun.js/streams.test.js b/test/bun.js/streams.test.js index 75ac964ca..bb676041b 100644 --- a/test/bun.js/streams.test.js +++ b/test/bun.js/streams.test.js @@ -13,40 +13,42 @@ import { gc } from "./gc"; beforeEach(() => gc()); afterEach(() => gc()); -// This test hangs, TODO: fix it -// describe("WritableStream", () => { -// it("works", async () => { -// try { -// var chunks = []; -// var writable = new WritableStream({ -// write(chunk, controller) { -// chunks.push(chunk); -// }, -// close(er) { -// console.log("closed"); -// console.log(er); -// }, -// abort(reason) { -// console.log("aborted!"); -// console.log(reason); -// }, -// }); -// var writer = writable.getWriter(); - -// writer.write(new Uint8Array([1, 2, 3])); -// writer.write(new Uint8Array([4, 5, 6])); -// await writer.close(); - -// expect(JSON.stringify(Array.from(Buffer.concat(chunks)))).toBe( -// JSON.stringify([1, 2, 3, 4, 5, 6]) -// ); -// } catch (e) { -// console.log(e); -// console.log(e.stack); -// throw e; -// } -// }); -// }); +describe("WritableStream", () => { + it("works", async () => { + try { + var chunks = []; + var writable = new WritableStream({ + write(chunk, controller) { + chunks.push(chunk); + }, + close(er) { + console.log("closed"); + console.log(er); + }, + abort(reason) { + console.log("aborted!"); + console.log(reason); + }, + }); + + var writer = writable.getWriter(); + + writer.write(new Uint8Array([1, 2, 3])); + + writer.write(new Uint8Array([4, 5, 6])); + + await writer.close(); + + expect(JSON.stringify(Array.from(Buffer.concat(chunks)))).toBe( + JSON.stringify([1, 2, 3, 4, 5, 6]), + ); + } catch (e) { + console.log(e); + console.log(e.stack); + throw e; + } + }); +}); describe("ReadableStream.prototype.tee", () => { it("class", () => { |