[autofix.ci] apply automated fixes

This commit is contained in:
autofix-ci[bot]
2025-07-30 06:17:18 +00:00
committed by GitHub
parent 8b2e19391c
commit b03a6344d8
4 changed files with 56 additions and 57 deletions

View File

@@ -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<JSBlob*>(argument0.value())) {
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) {
return impl.sendBlob(argument0.value());
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*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<JSBlob*>(argument0.value())) {
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) {
return impl.pingBlob(argument0.value());
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*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<JSBlob*>(argument0.value())) {
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*lexicalGlobalObject, throwScope, [&]() -> decltype(auto) {
return impl.pongBlob(argument0.value());
RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLUndefined>(*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());
}

View File

@@ -575,14 +575,14 @@ WebCore::ExceptionOr<void> 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<void> 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<const char*>(dataPtr), dataSize, Opcode::Binary);
} else {
// Send empty frame for empty blobs
this->sendWebSocketData(nullptr, 0, Opcode::Binary);
}
return {};
}
@@ -1583,18 +1583,18 @@ WebCore::ExceptionOr<void> 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<const char*>(dataPtr), dataSize, Opcode::Ping);
} else {
// Send empty frame for empty blobs
this->sendWebSocketData(nullptr, 0, Opcode::Ping);
}
return {};
}
@@ -1616,17 +1616,17 @@ WebCore::ExceptionOr<void> 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<const char*>(dataPtr), dataSize, Opcode::Pong);
} else {
// Send empty frame for empty blobs
this->sendWebSocketData(nullptr, 0, Opcode::Pong);
}
return {};
}

View File

@@ -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

View File

@@ -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<void>((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<void>((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<void>((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();
}
});
});