From b03a6344d88e3311291a168656babccd79bf5446 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 30 Jul 2025 06:17:18 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- src/bun.js/bindings/webcore/JSWebSocket.cpp | 24 ++++----- src/bun.js/bindings/webcore/WebSocket.cpp | 22 ++++---- src/http/websocket_client.zig | 12 ++--- test/js/web/websocket/websocket-blob.test.ts | 55 ++++++++++---------- 4 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/bun.js/bindings/webcore/JSWebSocket.cpp b/src/bun.js/bindings/webcore/JSWebSocket.cpp index 55c60e7422..4032df34c2 100644 --- a/src/bun.js/bindings/webcore/JSWebSocket.cpp +++ b/src/bun.js/bindings/webcore/JSWebSocket.cpp @@ -640,14 +640,14 @@ static inline JSC::EncodedJSValue jsWebSocketPrototypeFunction_send3Body(JSC::JS UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - + // Check if the argument is a JSBlob using jsDynamicCast if (jsDynamicCast(argument0.value())) { - RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { - return impl.sendBlob(argument0.value()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { + return impl.sendBlob(argument0.value()); }))); } - + throwArgumentTypeError(*lexicalGlobalObject, throwScope, 0, "data"_s, "WebSocket"_s, "send"_s, "Blob"_s); return JSValue::encode(jsUndefined()); } @@ -755,14 +755,14 @@ static inline JSC::EncodedJSValue jsWebSocketPrototypeFunction_ping4Body(JSC::JS UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - + // Check if the argument is a JSBlob using jsDynamicCast if (jsDynamicCast(argument0.value())) { - RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { - return impl.pingBlob(argument0.value()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { + return impl.pingBlob(argument0.value()); }))); } - + throwArgumentTypeError(*lexicalGlobalObject, throwScope, 0, "data"_s, "WebSocket"_s, "ping"_s, "Blob"_s); return JSValue::encode(jsUndefined()); } @@ -851,14 +851,14 @@ static inline JSC::EncodedJSValue jsWebSocketPrototypeFunction_pong4Body(JSC::JS UNUSED_PARAM(callFrame); auto& impl = castedThis->wrapped(); EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0); - + // Check if the argument is a JSBlob using jsDynamicCast if (jsDynamicCast(argument0.value())) { - RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { - return impl.pongBlob(argument0.value()); + RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) { + return impl.pongBlob(argument0.value()); }))); } - + throwArgumentTypeError(*lexicalGlobalObject, throwScope, 0, "data"_s, "WebSocket"_s, "pong"_s, "Blob"_s); return JSValue::encode(jsUndefined()); } diff --git a/src/bun.js/bindings/webcore/WebSocket.cpp b/src/bun.js/bindings/webcore/WebSocket.cpp index 3fc0c3e8e2..988a66fb86 100644 --- a/src/bun.js/bindings/webcore/WebSocket.cpp +++ b/src/bun.js/bindings/webcore/WebSocket.cpp @@ -575,14 +575,14 @@ WebCore::ExceptionOr WebCore::WebSocket::send(Blob& binaryData) // For now, we'll skip this since the old implementation was incomplete return {}; } - + // Use the Zig blob implementation to get the data // The blob's impl() returns a void* pointer to the Zig blob structure void* blobImpl = binaryData.impl(); if (!blobImpl) { return Exception { InvalidStateError }; } - + // TODO: Get the actual blob data and send it // For now, we'll return an error since we need to implement the Zig integration return Exception { NotSupportedError }; @@ -595,18 +595,18 @@ WebCore::ExceptionOr WebCore::WebSocket::sendBlob(JSC::JSValue blobValue) if (m_state == CLOSING || m_state == CLOSED) { return {}; } - + // Get the blob data and send it using existing binary data path void* dataPtr = Blob__getDataPtr(JSC::JSValue::encode(blobValue)); size_t dataSize = Blob__getSize(JSC::JSValue::encode(blobValue)); - + if (dataPtr && dataSize > 0) { this->sendWebSocketData(static_cast(dataPtr), dataSize, Opcode::Binary); } else { // Send empty frame for empty blobs this->sendWebSocketData(nullptr, 0, Opcode::Binary); } - + return {}; } @@ -1583,18 +1583,18 @@ WebCore::ExceptionOr WebCore::WebSocket::pingBlob(JSC::JSValue blobValue) if (m_state == CLOSING || m_state == CLOSED) { return {}; } - + // Get the blob data and send it using existing binary data path void* dataPtr = Blob__getDataPtr(JSC::JSValue::encode(blobValue)); size_t dataSize = Blob__getSize(JSC::JSValue::encode(blobValue)); - + if (dataPtr && dataSize > 0) { this->sendWebSocketData(static_cast(dataPtr), dataSize, Opcode::Ping); } else { // Send empty frame for empty blobs this->sendWebSocketData(nullptr, 0, Opcode::Ping); } - + return {}; } @@ -1616,17 +1616,17 @@ WebCore::ExceptionOr WebCore::WebSocket::pongBlob(JSC::JSValue blobValue) if (m_state == CLOSING || m_state == CLOSED) { return {}; } - + // Get the blob data and send it using existing binary data path void* dataPtr = Blob__getDataPtr(JSC::JSValue::encode(blobValue)); size_t dataSize = Blob__getSize(JSC::JSValue::encode(blobValue)); - + if (dataPtr && dataSize > 0) { this->sendWebSocketData(static_cast(dataPtr), dataSize, Opcode::Pong); } else { // Send empty frame for empty blobs this->sendWebSocketData(nullptr, 0, Opcode::Pong); } - + return {}; } diff --git a/src/http/websocket_client.zig b/src/http/websocket_client.zig index 458adfb899..e6ef2d8f37 100644 --- a/src/http/websocket_client.zig +++ b/src/http/websocket_client.zig @@ -983,7 +983,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { fn hasTCP(this: *WebSocket) bool { return !this.tcp.isClosed() and !this.tcp.isShutdown(); } - + pub fn writeBlob( this: *WebSocket, blob_value: jsc.JSValue, @@ -993,9 +993,9 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { this.dispatchAbruptClose(ErrorCode.ended); return; } - + const opcode: Opcode = @enumFromInt(op); - + // Cast the JSValue to a Blob if (blob_value.as(jsc.WebCore.Blob)) |blob| { // Get the shared view of the blob data @@ -1006,10 +1006,10 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { _ = this.sendData(bytes, !this.hasBackpressure(), opcode); return; } - + // Send the blob data similar to writeBinaryData const bytes = Copy{ .bytes = data }; - + // Fast path for small blobs const frame_size = WebsocketHeader.frameSizeIncludingMask(data.len); if (!this.hasBackpressure() and frame_size < stack_frame_size) { @@ -1018,7 +1018,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { _ = this.enqueueEncodedBytes(this.tcp, inline_buf[0..frame_size]); return; } - + _ = this.sendData(bytes, !this.hasBackpressure(), opcode); } else { // Invalid blob, close connection diff --git a/test/js/web/websocket/websocket-blob.test.ts b/test/js/web/websocket/websocket-blob.test.ts index 6822b31c9f..eeaf19518b 100644 --- a/test/js/web/websocket/websocket-blob.test.ts +++ b/test/js/web/websocket/websocket-blob.test.ts @@ -1,5 +1,4 @@ -import { test, expect } from "bun:test"; -import { bunEnv, bunExe } from "harness"; +import { expect, test } from "bun:test"; test("WebSocket should send Blob data", async () => { const server = Bun.serve({ @@ -32,33 +31,33 @@ test("WebSocket should send Blob data", async () => { try { const url = `ws://localhost:${server.port}`; - + const promise = new Promise((resolve, reject) => { const ws = new WebSocket(url); let messageReceived = false; ws.onopen = () => { console.log("Client: WebSocket opened"); - + // Set binary type to arraybuffer for consistent testing ws.binaryType = "arraybuffer"; - + // Create a blob with test data const testData = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in bytes const blob = new Blob([testData], { type: "application/octet-stream" }); - + console.log("Sending blob with length:", blob.size); ws.send(blob); }; - ws.onmessage = (event) => { + ws.onmessage = event => { console.log("Client received message:", event.data); messageReceived = true; - + if (event.data instanceof ArrayBuffer) { const received = new Uint8Array(event.data); console.log("Received bytes:", Array.from(received)); - + // Verify we received the correct data expect(received).toEqual(new Uint8Array([72, 101, 108, 108, 111])); resolve(); @@ -67,12 +66,12 @@ test("WebSocket should send Blob data", async () => { } }; - ws.onerror = (error) => { + ws.onerror = error => { console.error("WebSocket error:", error); reject(error); }; - ws.onclose = (event) => { + ws.onclose = event => { console.log("Client: WebSocket closed", event.code, event.reason); if (!messageReceived) { reject(new Error("Connection closed without receiving message")); @@ -113,7 +112,7 @@ test("WebSocket should send empty Blob", async () => { try { const url = `ws://localhost:${server.port}`; - + const promise = new Promise((resolve, reject) => { const ws = new WebSocket(url); let messageReceived = false; @@ -121,22 +120,22 @@ test("WebSocket should send empty Blob", async () => { ws.onopen = () => { // Set binary type to arraybuffer for consistent testing ws.binaryType = "arraybuffer"; - + // Create an empty blob const blob = new Blob([], { type: "application/octet-stream" }); - + console.log("Sending empty blob with length:", blob.size); ws.send(blob); }; - ws.onmessage = (event) => { + ws.onmessage = event => { console.log("Client received message:", event.data); messageReceived = true; - + if (event.data instanceof ArrayBuffer) { const received = new Uint8Array(event.data); console.log("Received bytes length:", received.length); - + // Verify we received empty data expect(received.length).toBe(0); resolve(); @@ -145,12 +144,12 @@ test("WebSocket should send empty Blob", async () => { } }; - ws.onerror = (error) => { + ws.onerror = error => { console.error("WebSocket error:", error); reject(error); }; - ws.onclose = (event) => { + ws.onclose = event => { console.log("Client: WebSocket closed", event.code, event.reason); if (!messageReceived) { reject(new Error("Connection closed without receiving message")); @@ -192,21 +191,21 @@ test("WebSocket should ping with Blob", async () => { try { const url = `ws://localhost:${server.port}`; - + const promise = new Promise((resolve, reject) => { const ws = new WebSocket(url); let pongReceived = false; ws.onopen = () => { console.log("Client: WebSocket opened"); - + // Set binary type to arraybuffer for consistent testing ws.binaryType = "arraybuffer"; - + // Create a blob with ping data const pingData = new Uint8Array([80, 73, 78, 71]); // "PING" in bytes const blob = new Blob([pingData], { type: "application/octet-stream" }); - + console.log("Sending ping with blob"); (ws as any).ping(blob); }; @@ -214,11 +213,11 @@ test("WebSocket should ping with Blob", async () => { ws.addEventListener("pong", (event: any) => { console.log("Client received pong:", event.data); pongReceived = true; - + if (event.data instanceof ArrayBuffer) { const received = new Uint8Array(event.data); console.log("Received pong bytes:", Array.from(received)); - + // Verify we received the correct ping data back expect(received).toEqual(new Uint8Array([80, 73, 78, 71])); resolve(); @@ -227,12 +226,12 @@ test("WebSocket should ping with Blob", async () => { } }); - ws.onerror = (error) => { + ws.onerror = error => { console.error("WebSocket error:", error); reject(error); }; - ws.onclose = (event) => { + ws.onclose = event => { console.log("Client: WebSocket closed", event.code, event.reason); if (!pongReceived) { reject(new Error("Connection closed without receiving pong")); @@ -252,4 +251,4 @@ test("WebSocket should ping with Blob", async () => { } finally { server.stop(); } -}); \ No newline at end of file +});