Compare commits

...

2 Commits

Author SHA1 Message Date
Jarred Sumner
0cfa1bc0c0 Fix assertion failure in debugger with websocket server 2025-02-08 22:53:34 -08:00
Jarred Sumner
30cbfb7a68 Remove a .vscode/launch.json config that is rarely used 2025-02-08 22:52:54 -08:00
3 changed files with 17 additions and 78 deletions

13
.vscode/launch.json generated vendored
View File

@@ -7,19 +7,6 @@
// - "cppvsdbg" is used instead of "lldb" on Windows, because "lldb" is too slow
"version": "0.2.0",
"configurations": [
{
"type": "bun",
"request": "launch",
"name": "[js] bun test [file]",
"runtime": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}",
"env": {
"BUN_DEBUG_QUIET_LOGS": "1",
"BUN_DEBUG_jest": "1",
"BUN_GARBAGE_COLLECTOR_LEVEL": "1",
},
},
// bun test [file]
{
"type": "lldb",

View File

@@ -4955,16 +4955,9 @@ pub const ServerWebSocket = struct {
}
{
var js_string = message_value.toString(globalThis);
if (globalThis.hasException()) {
return .zero;
}
const view = js_string.view(globalThis);
const slice = view.toSlice(bun.default_allocator);
const slice = try message_value.toSlice(globalThis, bun.default_allocator);
defer slice.deinit();
defer js_string.ensureStillAlive();
const buffer = slice.slice();
const result = if (!publish_to_self and !this.isClosed())
@@ -5024,16 +5017,9 @@ pub const ServerWebSocket = struct {
return globalThis.throw("publishText requires a non-empty message", .{});
}
var js_string = message_value.toString(globalThis);
if (globalThis.hasException()) {
return .zero;
}
const view = js_string.view(globalThis);
const slice = view.toSlice(bun.default_allocator);
const slice = try message_value.toSlice(globalThis, bun.default_allocator);
defer slice.deinit();
defer js_string.ensureStillAlive();
const buffer = slice.slice();
const result = if (!publish_to_self and !this.isClosed())
@@ -5278,16 +5264,9 @@ pub const ServerWebSocket = struct {
}
{
var js_string = message_value.toString(globalThis);
if (globalThis.hasException()) {
return .zero;
}
const view = js_string.view(globalThis);
const slice = view.toSlice(bun.default_allocator);
const slice = try message_value.toSlice(globalThis, bun.default_allocator);
defer slice.deinit();
defer js_string.ensureStillAlive();
const buffer = slice.slice();
switch (this.websocket().send(buffer, .text, compress, true)) {
.backpressure => {
@@ -5338,16 +5317,9 @@ pub const ServerWebSocket = struct {
return globalThis.throw("sendText expects a string", .{});
}
var js_string = message_value.toString(globalThis);
if (globalThis.hasException()) {
return .zero;
}
const view = js_string.view(globalThis);
const slice = view.toSlice(bun.default_allocator);
const slice = try message_value.toSlice(globalThis, bun.default_allocator);
defer slice.deinit();
defer js_string.ensureStillAlive();
const buffer = slice.slice();
switch (this.websocket().send(buffer, .text, compress, true)) {
.backpressure => {
@@ -6184,16 +6156,9 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
}
{
var js_string = message_value.toString(globalThis);
if (globalThis.hasException()) {
return .zero;
}
const view = js_string.view(globalThis);
const slice = view.toSlice(bun.default_allocator);
const slice = try message_value.toSlice(globalThis, bun.default_allocator);
defer slice.deinit();
defer js_string.ensureStillAlive();
const buffer = slice.slice();
return JSValue.jsNumber(
// if 0, return 0

View File

@@ -1788,23 +1788,18 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
return globalThis.throwValue(JSC.toTypeError(.ERR_INVALID_ARG_TYPE, "write() expects a string, ArrayBufferView, or ArrayBuffer", .{}, globalThis));
}
const str = arg.toString(globalThis);
if (globalThis.hasException()) {
return .zero;
}
const str = try arg.toBunString2(globalThis);
const view = str.view(globalThis);
if (view.isEmpty()) {
if (str.isEmpty()) {
return JSC.JSValue.jsNumber(0);
}
defer str.ensureStillAlive();
if (view.is16Bit()) {
return this.sink.writeUTF16(.{ .temporary = bun.ByteList.initConst(std.mem.sliceAsBytes(view.utf16SliceAligned())) }).toJS(globalThis);
defer str.deref();
if (!str.is8Bit()) {
return this.sink.writeUTF16(.{ .temporary = bun.ByteList.initConst(std.mem.sliceAsBytes(str.utf16())) }).toJS(globalThis);
}
return this.sink.writeLatin1(.{ .temporary = bun.ByteList.initConst(view.slice()) }).toJS(globalThis);
return this.sink.writeLatin1(.{ .temporary = bun.ByteList.initConst(str.latin1()) }).toJS(globalThis);
}
pub fn writeUTF8(globalThis: *JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
@@ -1832,22 +1827,14 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
const arg = args[0];
const str = arg.toString(globalThis);
if (globalThis.hasException()) {
return .zero;
const str = try arg.toBunString2(globalThis);
defer str.deref();
if (!str.is8Bit()) {
return this.sink.writeUTF16(.{ .temporary = bun.ByteList.initConst(std.mem.sliceAsBytes(str.utf16())) }).toJS(globalThis);
}
const view = str.view(globalThis);
if (view.isEmpty()) {
return JSC.JSValue.jsNumber(0);
}
defer str.ensureStillAlive();
if (str.is16Bit()) {
return this.sink.writeUTF16(.{ .temporary = view.utf16SliceAligned() }).toJS(globalThis);
}
return this.sink.writeLatin1(.{ .temporary = view.slice() }).toJS(globalThis);
return this.sink.writeLatin1(.{ .temporary = str.latin1() }).toJS(globalThis);
}
pub fn close(globalThis: *JSGlobalObject, sink_ptr: ?*anyopaque) callconv(.C) JSValue {