Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 218 additions & 44 deletions packages/bun-types/redis.d.ts

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/bun.js/api/valkey.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default [
configurable: false,
JSType: "0b11101110",
memoryCost: true,
hasPendingActivity: true,
proto: {
connected: {
getter: "getConnected",
Expand Down Expand Up @@ -222,11 +223,12 @@ export default [
zrank: { fn: "zrank" },
zrevrank: { fn: "zrevrank" },
subscribe: { fn: "subscribe" },
duplicate: { fn: "duplicate" },
psubscribe: { fn: "psubscribe" },
unsubscribe: { fn: "unsubscribe" },
punsubscribe: { fn: "punsubscribe" },
pubsub: { fn: "pubsub" },
},
values: ["onconnect", "onclose", "connectionPromise", "hello"],
values: ["onconnect", "onclose", "connectionPromise", "hello", "subscriptionCallbackMap"],
}),
];
21 changes: 15 additions & 6 deletions src/bun.js/bindings/JSMap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ pub const JSMap = opaque {
return bun.cpp.JSC__JSMap__set(this, globalObject, key, value);
}

pub fn get_(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue) JSValue {
return bun.cpp.JSC__JSMap__get_(this, globalObject, key);
}
extern fn JSC__JSMap__get(*JSMap, *JSGlobalObject, JSValue) JSValue;

pub fn get(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue) bun.JSError!?JSValue {
var scope: jsc.CatchScope = undefined;
scope.init(globalObject, @src());
defer scope.deinit();

const value = JSC__JSMap__get(this, globalObject, key);

pub fn get(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue) ?JSValue {
const value = get_(this, globalObject, key);
if (value.isEmpty()) {
try scope.returnIfException();

if (value == .zero) {
Comment thread
dylan-conway marked this conversation as resolved.
Resolved
return null;
}
return value;
Expand All @@ -29,6 +34,10 @@ pub const JSMap = opaque {
return bun.cpp.JSC__JSMap__remove(this, globalObject, key);
}

pub fn size(this: *JSMap, globalObject: *JSGlobalObject) usize {
return bun.cpp.JSC__JSMap__size(this, globalObject);
}

pub fn fromJS(value: JSValue) ?*JSMap {
if (value.jsTypeLoose() == .Map) {
return bun.cast(*JSMap, value.asEncoded().asPtr.?);
Expand Down
19 changes: 17 additions & 2 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "JavaScriptCore/JSArrayInlines.h"
#include "JavaScriptCore/ErrorInstanceInlines.h"
#include "JavaScriptCore/BigIntObject.h"
#include "JavaScriptCore/OrderedHashTableHelper.h"

#include "JavaScriptCore/JSCallbackObject.h"
#include "JavaScriptCore/JSClassRef.h"
Expand Down Expand Up @@ -6401,11 +6402,20 @@ CPP_DECL JSC::EncodedJSValue JSC__JSMap__create(JSC::JSGlobalObject* arg0)
JSC::JSMap* map = JSC::JSMap::create(arg0->vm(), arg0->mapStructure());
return JSC::JSValue::encode(map);
}
CPP_DECL [[ZIG_EXPORT(nothrow)]] JSC::EncodedJSValue JSC__JSMap__get_(JSC::JSMap* map, JSC::JSGlobalObject* arg1, JSC::EncodedJSValue JSValue2)

// zero means "not found" or an exception was thrown
CPP_DECL JSC::EncodedJSValue JSC__JSMap__get(JSC::JSMap* map, JSC::JSGlobalObject* arg1, JSC::EncodedJSValue JSValue2)
{
auto& vm = arg1->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

JSC::JSValue value = JSC::JSValue::decode(JSValue2);

return JSC::JSValue::encode(map->get(arg1, value));
JSValue entryValue = map->getImpl(arg1, [&](OrderedHashMap::Storage& storage) ALWAYS_INLINE_LAMBDA {
return OrderedHashMap::Helper::find(arg1, storage, value);
});

RELEASE_AND_RETURN(scope, JSC::JSValue::encode(entryValue));
}
Comment thread
markovejnovic marked this conversation as resolved.
Resolved
CPP_DECL [[ZIG_EXPORT(nothrow)]] bool JSC__JSMap__has(JSC::JSMap* map, JSC::JSGlobalObject* arg1, JSC::EncodedJSValue JSValue2)
{
Expand All @@ -6422,6 +6432,11 @@ CPP_DECL [[ZIG_EXPORT(nothrow)]] void JSC__JSMap__set(JSC::JSMap* map, JSC::JSGl
map->set(arg1, JSC::JSValue::decode(JSValue2), JSC::JSValue::decode(JSValue3));
}

CPP_DECL [[ZIG_EXPORT(nothrow)]] uint32_t JSC__JSMap__size(JSC::JSMap* map, JSC::JSGlobalObject* arg1)
{
return map->size();
}
Comment thread
markovejnovic marked this conversation as resolved.
Resolved

CPP_DECL void JSC__VM__setControlFlowProfiler(JSC::VM* vm, bool isEnabled)
{
if (isEnabled) {
Expand Down
7 changes: 4 additions & 3 deletions src/bun.js/bindings/headers.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/deps/uws/us_socket_t.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub const us_socket_t = opaque {
};

pub fn open(this: *us_socket_t, comptime is_ssl: bool, is_client: bool, ip_addr: ?[]const u8) void {
debug("us_socket_open({d}, is_client: {})", .{ @intFromPtr(this), is_client });
debug("us_socket_open({p}, is_client: {})", .{ this, is_client });
const ssl = @intFromBool(is_ssl);

if (ip_addr) |ip| {
Expand All @@ -25,22 +25,22 @@ pub const us_socket_t = opaque {
}

pub fn pause(this: *us_socket_t, ssl: bool) void {
debug("us_socket_pause({d})", .{@intFromPtr(this)});
debug("us_socket_pause({p})", .{this});
c.us_socket_pause(@intFromBool(ssl), this);
}

pub fn @"resume"(this: *us_socket_t, ssl: bool) void {
debug("us_socket_resume({d})", .{@intFromPtr(this)});
debug("us_socket_resume({p})", .{this});
c.us_socket_resume(@intFromBool(ssl), this);
}

pub fn close(this: *us_socket_t, ssl: bool, code: CloseCode) void {
debug("us_socket_close({d}, {s})", .{ @intFromPtr(this), @tagName(code) });
debug("us_socket_close({p}, {s})", .{ this, @tagName(code) });
_ = c.us_socket_close(@intFromBool(ssl), this, code, null);
}

pub fn shutdown(this: *us_socket_t, ssl: bool) void {
debug("us_socket_shutdown({d})", .{@intFromPtr(this)});
debug("us_socket_shutdown({p})", .{this});
c.us_socket_shutdown(@intFromBool(ssl), this);
}

Expand Down Expand Up @@ -128,25 +128,25 @@ pub const us_socket_t = opaque {

pub fn write(this: *us_socket_t, ssl: bool, data: []const u8) i32 {
const rc = c.us_socket_write(@intFromBool(ssl), this, data.ptr, @intCast(data.len));
debug("us_socket_write({d}, {d}) = {d}", .{ @intFromPtr(this), data.len, rc });
debug("us_socket_write({p}, {d}) = {d}", .{ this, data.len, rc });
return rc;
}

pub fn writeFd(this: *us_socket_t, data: []const u8, file_descriptor: bun.FD) i32 {
if (bun.Environment.isWindows) @compileError("TODO: implement writeFd on Windows");
const rc = c.us_socket_ipc_write_fd(this, data.ptr, @intCast(data.len), file_descriptor.native());
debug("us_socket_ipc_write_fd({d}, {d}, {d}) = {d}", .{ @intFromPtr(this), data.len, file_descriptor.native(), rc });
debug("us_socket_ipc_write_fd({p}, {d}, {d}) = {d}", .{ this, data.len, file_descriptor.native(), rc });
return rc;
}

pub fn write2(this: *us_socket_t, ssl: bool, first: []const u8, second: []const u8) i32 {
const rc = c.us_socket_write2(@intFromBool(ssl), this, first.ptr, first.len, second.ptr, second.len);
debug("us_socket_write2({d}, {d}, {d}) = {d}", .{ @intFromPtr(this), first.len, second.len, rc });
debug("us_socket_write2({p}, {d}, {d}) = {d}", .{ this, first.len, second.len, rc });
return rc;
}

pub fn rawWrite(this: *us_socket_t, ssl: bool, data: []const u8) i32 {
debug("us_socket_raw_write({d}, {d})", .{ @intFromPtr(this), data.len });
debug("us_socket_raw_write({p}, {d})", .{ this, data.len });
return c.us_socket_raw_write(@intFromBool(ssl), this, data.ptr, @intCast(data.len));
}

Expand Down
9 changes: 9 additions & 0 deletions src/string/StringBuilder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ pub fn writable(this: *StringBuilder) []u8 {
return ptr[this.len..this.cap];
}

/// Transfer ownership of the underlying memory to a slice.
///
/// After calling this, you are responsible for freeing the underlying memory.
/// This StringBuilder should not be used after calling this function.
pub fn moveToSlice(this: *StringBuilder, into_slice: *[]u8) void {
into_slice.* = this.allocatedSlice();
this.* = .{};
}

const std = @import("std");
const Allocator = std.mem.Allocator;

Expand Down
3 changes: 2 additions & 1 deletion src/valkey/ValkeyCommand.zig
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub const Promise = struct {
self.promise.resolve(globalObject, js_value);
}

pub fn reject(self: *Promise, globalObject: *jsc.JSGlobalObject, jsvalue: jsc.JSValue) void {
pub fn reject(self: *Promise, globalObject: *jsc.JSGlobalObject, jsvalue: JSError!jsc.JSValue) void {
self.promise.reject(globalObject, jsvalue);
}

Expand All @@ -162,6 +162,7 @@ const protocol = @import("./valkey_protocol.zig");
const std = @import("std");

const bun = @import("bun");
const JSError = bun.JSError;
const jsc = bun.jsc;
const node = bun.api.node;
const Slice = jsc.ZigString.Slice;
Loading