aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-09 21:47:18 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-09 21:47:18 -0700
commit1e8b9258b2ac77f6db1b42ce82928fed86ffc77d (patch)
treeb51e89e810de5877817ede5ec7075e4ec7957259
parentc7c5dc14384f81a2d245870d2848c0512193690d (diff)
downloadbun-1e8b9258b2ac77f6db1b42ce82928fed86ffc77d.tar.gz
bun-1e8b9258b2ac77f6db1b42ce82928fed86ffc77d.tar.zst
bun-1e8b9258b2ac77f6db1b42ce82928fed86ffc77d.zip
Expose bindings for `Map`
-rw-r--r--src/bun.js/bindings/bindings.cpp29
-rw-r--r--src/bun.js/bindings/bindings.zig54
-rw-r--r--src/bun.js/bindings/headers-cpp.h16
-rw-r--r--src/bun.js/bindings/headers.h13
-rw-r--r--src/bun.js/bindings/headers.zig5
5 files changed, 112 insertions, 5 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index 0d4416535..b0078503b 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -90,6 +90,7 @@
#include "DOMFormData.h"
#include "JSDOMFormData.h"
#include "ZigGeneratedClasses.h"
+#include "JavaScriptCore/JSMapInlines.h"
template<typename UWSResponse>
static void copyToUWS(WebCore::FetchHeaders* headers, UWSResponse* res)
@@ -4121,3 +4122,31 @@ CPP_DECL WebCore__DOMFormData* WebCore__DOMFormData__fromJS(JSC__JSValue JSValue
{
return WebCoreCast<WebCore::JSDOMFormData, WebCore__DOMFormData>(JSValue1);
}
+
+#pragma mark - JSC::JSMap
+
+CPP_DECL JSC__JSValue JSC__JSMap__create(JSC__JSGlobalObject* arg0)
+{
+ JSC::JSMap* map = JSC::JSMap::create(arg0->vm(), arg0->mapStructure());
+ return JSC::JSValue::encode(map);
+}
+CPP_DECL JSC__JSValue JSC__JSMap__get_(JSC__JSMap* map, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2)
+{
+ JSC::JSValue value = JSC::JSValue::decode(JSValue2);
+
+ return JSC::JSValue::encode(map->get(arg1, value));
+}
+CPP_DECL bool JSC__JSMap__has(JSC__JSMap* map, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2)
+{
+ JSC::JSValue value = JSC::JSValue::decode(JSValue2);
+ return map->has(arg1, value);
+}
+CPP_DECL bool JSC__JSMap__remove(JSC__JSMap* map, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2)
+{
+ JSC::JSValue value = JSC::JSValue::decode(JSValue2);
+ return map->remove(arg1, value);
+}
+CPP_DECL void JSC__JSMap__set(JSC__JSMap* map, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__JSValue JSValue3)
+{
+ map->set(arg1, JSC::JSValue::decode(JSValue2), JSC::JSValue::decode(JSValue3));
+}
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 278fb56dd..7de50f436 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -2760,6 +2760,60 @@ pub const JSArrayIterator = struct {
}
};
+pub const JSMap = opaque {
+ pub const shim = Shimmer("JSC", "JSMap", @This());
+ pub const Type = JSMap;
+ const cppFn = shim.cppFn;
+
+ pub const include = "JavaScriptCore/JSMap.h";
+ pub const name = "JSC::JSMap";
+ pub const namespace = "JSC";
+
+ pub fn create(globalObject: *JSGlobalObject) JSValue {
+ return cppFn("create", .{globalObject});
+ }
+
+ pub fn set(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue, value: JSValue) void {
+ return cppFn("set", .{ this, globalObject, key, value });
+ }
+
+ pub fn get_(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue) JSValue {
+ return cppFn("get", .{ this, globalObject, key });
+ }
+
+ pub fn get(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue) ?JSValue {
+ const value = get_(this, globalObject, key);
+ if (value.isEmpty()) {
+ return null;
+ }
+ return value;
+ }
+
+ pub fn has(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue) bool {
+ return cppFn("has", .{ this, globalObject, key });
+ }
+
+ pub fn remove(this: *JSMap, globalObject: *JSGlobalObject, key: JSValue) bool {
+ return cppFn("remove", .{ this, globalObject, key });
+ }
+
+ pub fn fromJS(value: JSValue) ?*JSMap {
+ if (value.jsTypeLoose() == .JSMap) {
+ return bun.cast(*JSMap, value.asEncoded().asPtr.?);
+ }
+
+ return null;
+ }
+
+ pub const Extern = [_][]const u8{
+ "create",
+ "set",
+ "get_",
+ "has",
+ "remove",
+ };
+};
+
pub const JSValueReprInt = i64;
pub const JSValue = enum(JSValueReprInt) {
zero = 0,
diff --git a/src/bun.js/bindings/headers-cpp.h b/src/bun.js/bindings/headers-cpp.h
index f90e2f0d9..553d0ae36 100644
--- a/src/bun.js/bindings/headers-cpp.h
+++ b/src/bun.js/bindings/headers-cpp.h
@@ -1,4 +1,4 @@
-//-- AUTOGENERATED FILE -- 1681462444
+//-- AUTOGENERATED FILE -- 1683691290
// clang-format off
#pragma once
@@ -96,6 +96,14 @@ extern "C" const size_t JSC__JSFunction_object_align_ = alignof(JSC::JSFunction)
extern "C" const size_t JSC__JSGlobalObject_object_size_ = sizeof(JSC::JSGlobalObject);
extern "C" const size_t JSC__JSGlobalObject_object_align_ = alignof(JSC::JSGlobalObject);
+#ifndef INCLUDED_JavaScriptCore_JSMap_h
+#define INCLUDED_JavaScriptCore_JSMap_h
+#include "JavaScriptCore/JSMap.h"
+#endif
+
+extern "C" const size_t JSC__JSMap_object_size_ = sizeof(JSC::JSMap);
+extern "C" const size_t JSC__JSMap_object_align_ = alignof(JSC::JSMap);
+
#ifndef INCLUDED_JavaScriptCore_JSValue_h
#define INCLUDED_JavaScriptCore_JSValue_h
#include "JavaScriptCore/JSValue.h"
@@ -168,8 +176,8 @@ extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleC
extern "C" const size_t Bun__Timer_object_size_ = sizeof(Bun__Timer);
extern "C" const size_t Bun__Timer_object_align_ = alignof(Bun__Timer);
-const size_t sizes[40] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Crypto__getRandomValues), sizeof(Crypto__randomUUID), sizeof(Crypto__timingSafeEqual), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink)};
+const size_t sizes[41] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSMap), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Crypto__getRandomValues), sizeof(Crypto__randomUUID), sizeof(Crypto__timingSafeEqual), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink)};
-const char* names[40] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__DOMFormData", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "JSC__JSModuleLoader", "WebCore__AbortSignal", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__JSFunction", "JSC__JSGlobalObject", "JSC__JSValue", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "FFI__ptr", "Reader__u8", "Reader__u16", "Reader__u32", "Reader__ptr", "Reader__i8", "Reader__i16", "Reader__i32", "Reader__f32", "Reader__f64", "Reader__i64", "Reader__u64", "Reader__intptr", "Crypto__getRandomValues", "Crypto__randomUUID", "Crypto__timingSafeEqual", "Zig__GlobalObject", "Bun__Path", "ArrayBufferSink", "HTTPSResponseSink", "HTTPResponseSink", "FileSink"};
+const char* names[41] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__DOMFormData", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "JSC__JSModuleLoader", "WebCore__AbortSignal", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__JSFunction", "JSC__JSGlobalObject", "JSC__JSMap", "JSC__JSValue", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "FFI__ptr", "Reader__u8", "Reader__u16", "Reader__u32", "Reader__ptr", "Reader__i8", "Reader__i16", "Reader__i32", "Reader__f32", "Reader__f64", "Reader__i64", "Reader__u64", "Reader__intptr", "Crypto__getRandomValues", "Crypto__randomUUID", "Crypto__timingSafeEqual", "Zig__GlobalObject", "Bun__Path", "ArrayBufferSink", "HTTPSResponseSink", "HTTPResponseSink", "FileSink"};
-const size_t aligns[40] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Crypto__getRandomValues), alignof(Crypto__randomUUID), alignof(Crypto__timingSafeEqual), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink)};
+const size_t aligns[41] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSMap), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Crypto__getRandomValues), alignof(Crypto__randomUUID), alignof(Crypto__timingSafeEqual), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink)};
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index b547edc44..c8c374b7f 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1681462444
+//-- AUTOGENERATED FILE -- 1683691290
#pragma once
#include <stddef.h>
@@ -55,6 +55,7 @@ typedef void* JSClassRef;
typedef bJSC__JSObject JSC__JSObject; // JSC::JSObject
typedef WebSocketClient WebSocketClient;
typedef struct WebCore__AbortSignal WebCore__AbortSignal; // WebCore::AbortSignal
+ typedef struct JSC__JSMap JSC__JSMap; // JSC::JSMap
typedef WebSocketHTTPSClient WebSocketHTTPSClient;
typedef JSClassRef JSClassRef;
typedef bJSC__VM JSC__VM; // JSC::VM
@@ -81,6 +82,7 @@ typedef void* JSClassRef;
#ifdef __cplusplus
namespace JSC {
+ class JSMap;
class JSCell;
class JSObject;
class JSGlobalObject;
@@ -113,6 +115,7 @@ typedef void* JSClassRef;
typedef SystemError SystemError;
typedef ZigString ZigString;
typedef int64_t JSC__JSValue;
+ using JSC__JSMap = JSC::JSMap;
using JSC__JSCell = JSC::JSCell;
using JSC__JSObject = JSC::JSObject;
using JSC__JSGlobalObject = JSC::JSGlobalObject;
@@ -276,6 +279,14 @@ CPP_DECL void JSC__JSGlobalObject__reload(JSC__JSGlobalObject* arg0);
CPP_DECL bool JSC__JSGlobalObject__startRemoteInspector(JSC__JSGlobalObject* arg0, unsigned char* arg1, uint16_t arg2);
CPP_DECL JSC__VM* JSC__JSGlobalObject__vm(JSC__JSGlobalObject* arg0);
+#pragma mark - JSC::JSMap
+
+CPP_DECL JSC__JSValue JSC__JSMap__create(JSC__JSGlobalObject* arg0);
+CPP_DECL JSC__JSValue JSC__JSMap__get_(JSC__JSMap* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2);
+CPP_DECL bool JSC__JSMap__has(JSC__JSMap* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2);
+CPP_DECL bool JSC__JSMap__remove(JSC__JSMap* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2);
+CPP_DECL void JSC__JSMap__set(JSC__JSMap* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__JSValue JSValue3);
+
#pragma mark - JSC::JSValue
CPP_DECL void JSC__JSValue___then(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__JSValue(* ArgFn3)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1), JSC__JSValue(* ArgFn4)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1)) __attribute__((nonnull (3, 4)));
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index a33799c1b..3f943ab27 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -191,6 +191,11 @@ pub extern fn JSC__JSGlobalObject__queueMicrotaskJob(arg0: *bindings.JSGlobalObj
pub extern fn JSC__JSGlobalObject__reload(arg0: *bindings.JSGlobalObject) void;
pub extern fn JSC__JSGlobalObject__startRemoteInspector(arg0: *bindings.JSGlobalObject, arg1: [*c]u8, arg2: u16) bool;
pub extern fn JSC__JSGlobalObject__vm(arg0: *bindings.JSGlobalObject) *bindings.VM;
+pub extern fn JSC__JSMap__create(arg0: *bindings.JSGlobalObject) JSC__JSValue;
+pub extern fn JSC__JSMap__get_(arg0: ?*bindings.JSMap, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) JSC__JSValue;
+pub extern fn JSC__JSMap__has(arg0: ?*bindings.JSMap, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) bool;
+pub extern fn JSC__JSMap__remove(arg0: ?*bindings.JSMap, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) bool;
+pub extern fn JSC__JSMap__set(arg0: ?*bindings.JSMap, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue, JSValue3: JSC__JSValue) void;
pub extern fn JSC__JSValue___then(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue, ArgFn3: ?*const fn (*bindings.JSGlobalObject, *bindings.CallFrame) callconv(.C) JSC__JSValue, ArgFn4: ?*const fn (*bindings.JSGlobalObject, *bindings.CallFrame) callconv(.C) JSC__JSValue) void;
pub extern fn JSC__JSValue__asArrayBuffer_(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, arg2: ?*Bun__ArrayBuffer) bool;
pub extern fn JSC__JSValue__asBigIntCompare(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject, JSValue2: JSC__JSValue) u8;