aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-17 07:36:18 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-17 07:37:14 -0700
commit93b663e43d2288cea5f7b2e8f045c719427a914f (patch)
treea7849c913b6c4814636da3ea08ed98beadaad469 /src
parent65820893c966d4f8af2c0058682d30fa6330a219 (diff)
downloadbun-93b663e43d2288cea5f7b2e8f045c719427a914f.tar.gz
bun-93b663e43d2288cea5f7b2e8f045c719427a914f.tar.zst
bun-93b663e43d2288cea5f7b2e8f045c719427a914f.zip
New Zig <> C++ bindings generator. +20% faster HTTP server
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/api/bun.zig35
-rw-r--r--src/bun.js/api/ffi.zig3
-rw-r--r--src/bun.js/api/html_rewriter.zig6
-rw-r--r--src/bun.js/api/server.zig77
-rw-r--r--src/bun.js/api/transpiler.zig10
-rw-r--r--src/bun.js/base.zig148
-rw-r--r--src/bun.js/bindings/ZigConsoleClient.cpp5
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h3
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h3
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h8
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h20
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.cpp972
-rw-r--r--src/bun.js/bindings/ZigGeneratedClasses.h268
-rw-r--r--src/bun.js/bindings/ZigGeneratedCode.cpp105
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp38
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.h6
-rw-r--r--src/bun.js/bindings/bindings-generator.zig6
-rw-r--r--src/bun.js/bindings/bindings.cpp160
-rw-r--r--src/bun.js/bindings/bindings.zig267
-rw-r--r--src/bun.js/bindings/exports.zig74
-rw-r--r--src/bun.js/bindings/generated_classes.zig297
-rw-r--r--src/bun.js/bindings/generated_classes_list.zig6
-rw-r--r--src/bun.js/bindings/header-gen.zig32
-rw-r--r--src/bun.js/bindings/headers.h6
-rw-r--r--src/bun.js/bindings/headers.zig4
-rw-r--r--src/bun.js/bindings/sizes.zig11
-rw-r--r--src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h1
-rw-r--r--src/bun.js/bindings/webcore/DOMIsoSubspaces.h1
-rw-r--r--src/bun.js/bindings/webcore/FetchHeaders.cpp45
-rw-r--r--src/bun.js/bindings/webcore/FetchHeaders.h1
-rw-r--r--src/bun.js/bindings/webcore/HTTPHeaderMap.h2
-rw-r--r--src/bun.js/bindings/webcore/HTTPHeaderNames.cpp527
-rw-r--r--src/bun.js/bindings/webcore/HTTPHeaderNames.gperf2
-rw-r--r--src/bun.js/bindings/webcore/HTTPHeaderNames.h9
-rw-r--r--src/bun.js/bindings/webcore/HTTPParsers.cpp59
-rw-r--r--src/bun.js/bindings/webcore/HTTPParsers.h2
-rw-r--r--src/bun.js/builtins/BunBuiltinNames.h3
-rw-r--r--src/bun.js/generate-classes.js1360
-rw-r--r--src/bun.js/headergen/sizegen.cpp26
-rw-r--r--src/bun.js/javascript.zig5
-rw-r--r--src/bun.js/test/jest.zig8
-rw-r--r--src/bun.js/webcore/response.zig846
-rw-r--r--src/bun.js/webcore/streams.zig6
-rw-r--r--src/bundler.zig8
-rw-r--r--src/darwin_c.zig14
m---------src/deps/libarchive0
-rw-r--r--src/http_client_async.zig28
-rw-r--r--src/js_ast.zig11
-rw-r--r--src/js_lexer.zig3
-rw-r--r--src/jsc.zig2
-rw-r--r--src/mimalloc_arena.zig4
-rw-r--r--src/router.zig4
-rw-r--r--src/zlib.zig22
53 files changed, 4495 insertions, 1074 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 8408ce339..ac5366a45 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -231,7 +231,7 @@ pub fn registerMacro(
return js.JSValueMakeUndefined(ctx);
}
- if (!js.JSValueIsObject(ctx, arguments[1]) or !js.JSObjectIsFunction(ctx, arguments[1])) {
+ if (!arguments[1].?.value().isCell() or !arguments[1].?.value().isCallable(ctx.vm())) {
JSError(getAllocator(ctx), "Macro must be a function. Received: {s}", .{@tagName(js.JSValueGetType(ctx, arguments[1]))}, ctx, exception);
return js.JSValueMakeUndefined(ctx);
}
@@ -1283,20 +1283,33 @@ pub const Crypto = struct {
},
);
- pub const Class = JSC.NewClass(
+ pub const codgen = JSC.codegen(
@This(),
+ @as(string, name),
.{
- .name = name,
+ .update = JSC.wrapSync(@This(), "update"),
+ .digest = JSC.wrapSync(@This(), "digest"),
+ .finalize = finalize,
+
+ .byteLength = .{
+ .get = byteLength2,
+ },
},
.{
- .update = .{
- .rfn = JSC.wrapSync(@This(), "update"),
- },
- .digest = .{
- .rfn = JSC.wrapSync(@This(), "digest"),
+ .constructor = constructor,
+ .hash = JSC.wrapWithHasContainer(@This(), "hash", false, false, true),
+ .byteLength = .{
+ .get = byteLength,
},
- .finalize = finalize,
},
+ );
+
+ pub const Class = JSC.NewClass(
+ @This(),
+ .{
+ .name = name,
+ },
+ .{},
.{
.byteLength = .{
.get = byteLength2,
@@ -1620,12 +1633,12 @@ pub export fn Bun__escapeHTML(
globalObject: *JSGlobalObject,
callframe: *JSC.CallFrame,
) JSC.JSValue {
- const arguments = callframe.arguments();
+ const arguments = callframe.arguments(2);
if (arguments.len < 1) {
return ZigString.Empty.toValue(globalObject);
}
- const input_value = arguments[0];
+ const input_value = arguments.ptr[0];
const zig_str = input_value.getZigString(globalObject);
if (zig_str.len == 0)
return ZigString.Empty.toValue(globalObject);
diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig
index 46a4d20c8..f6bfdc5b4 100644
--- a/src/bun.js/api/ffi.zig
+++ b/src/bun.js/api/ffi.zig
@@ -183,7 +183,6 @@ pub const FFI = struct {
}
pub fn print(global: *JSGlobalObject, object: JSC.JSValue, is_callback_val: ?JSC.JSValue) JSValue {
- JSC.markBinding();
const allocator = VirtualMachine.vm.allocator;
if (is_callback_val) |is_callback| {
if (is_callback.toBoolean()) {
@@ -204,7 +203,7 @@ pub const FFI = struct {
symbols.clearAndFree(allocator);
return val;
}
-
+ JSC.markBinding();
var zig_strings = allocator.alloc(ZigString, symbols.count()) catch unreachable;
for (symbols.values()) |*function, i| {
var arraylist = std.ArrayList(u8).init(allocator);
diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig
index 7195bba94..22644dab5 100644
--- a/src/bun.js/api/html_rewriter.zig
+++ b/src/bun.js/api/html_rewriter.zig
@@ -219,7 +219,7 @@ pub const HTMLRewriter = struct {
response.cloneInto(result, getAllocator(global.ref()), global);
this.finalizeWithoutDestroy();
- return JSValue.fromRef(Response.makeMaybePooled(global.ref(), result));
+ return result.toJS(global);
}
pub fn transform(this: *HTMLRewriter, global: *JSGlobalObject, response: *Response) JSValue {
@@ -467,9 +467,7 @@ pub const HTMLRewriter = struct {
// Hold off on cloning until we're actually done.
- return JSC.JSValue.fromRef(
- Response.makeMaybePooled(sink.global.ref(), sink.response),
- );
+ return sink.response.toJS(sink.global.ref());
}
pub fn onFinishedLoading(sink: *BufferOutputSink, bytes: JSC.WebCore.Blob.Store.ReadFile.ResultType) void {
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index cc81c69e1..aaa058330 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -530,7 +530,6 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
response_ptr: ?*JSC.WebCore.Response = null,
blob: JSC.WebCore.Blob = JSC.WebCore.Blob{},
promise: ?*JSC.JSValue = null,
- response_headers: ?*JSC.FetchHeaders = null,
has_abort_handler: bool = false,
has_sendfile_ctx: bool = false,
has_called_error_handler: bool = false,
@@ -846,11 +845,6 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
JSC.C.JSValueUnprotect(this.server.globalThis.ref(), promise.asObjectRef());
}
-
- if (this.response_headers != null) {
- this.response_headers.?.deref();
- this.response_headers = null;
- }
}
pub fn finalize(this: *RequestContext) void {
this.finalizeWithoutDeinit();
@@ -876,9 +870,9 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
this: *RequestContext,
headers: *JSC.FetchHeaders,
) void {
- headers.remove(&ZigString.init("content-length"));
- headers.remove(&ZigString.init("transfer-encoding"));
- if (!ssl_enabled) headers.remove(&ZigString.init("strict-transport-security"));
+ headers.fastRemove(.ContentLength);
+ headers.fastRemove(.TransferEncoding);
+ if (!ssl_enabled) headers.fastRemove(.StrictTransportSecurity);
headers.toUWSResponse(ssl_enabled, this.resp);
}
@@ -1234,7 +1228,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
.JavaScript, .Direct => {
// uWS automatically adds the status line if needed
// we want to batch network calls as much as possible
- if (!(this.response_ptr.?.statusCode() == 200 or this.response_headers == null)) {
+ if (!(this.response_ptr.?.statusCode() == 200 and this.response_ptr.?.body.init.headers == null)) {
this.renderMetadata();
}
@@ -1626,7 +1620,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
if (response.body.init.headers) |headers_| {
this.writeHeaders(headers_);
- has_content_disposition = headers_.has(&ZigString.init("content-disposition"));
+ has_content_disposition = headers_.fastHas(.ContentDisposition);
response.body.init.headers = null;
headers_.deref();
}
@@ -1704,9 +1698,9 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
else
Blob.initEmpty(this.server.globalThis),
};
- old.resolve(&req.body, this.server.globalThis);
+ if (old == .Locked)
+ old.resolve(&req.body, this.server.globalThis);
request.unprotect();
- VirtualMachine.vm.tick();
return;
}
}
@@ -1723,15 +1717,14 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
request.ensureStillAlive();
uws.Loop.get().?.nextTick(*RequestContext, this, resolveRequestBody);
} else {
- this.request_body_buf.deinit(this.allocator);
- this.request_body_buf = .{};
+ this.request_body_buf.clearAndFree(this.allocator);
}
}
}
pub fn onPull(this: *RequestContext) void {
const request = JSC.JSValue.c(this.request_js_object);
- request.protect();
+ request.ensureStillAlive();
if (this.req.header("content-length")) |content_length| {
const len = std.fmt.parseInt(usize, content_length, 10) catch 0;
@@ -1741,11 +1734,9 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
old.Locked.callback = null;
req.body = .{ .Empty = .{} };
old.resolve(&req.body, this.server.globalThis);
- VirtualMachine.vm.tick();
-
return;
}
- request.unprotect();
+ request.ensureStillAlive();
}
if (len >= this.server.config.max_request_body_size) {
@@ -1754,11 +1745,9 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
old.Locked.callback = null;
req.body = .{ .Empty = .{} };
old.toError(error.RequestBodyTooLarge, this.server.globalThis);
-
- VirtualMachine.vm.tick();
return;
}
- request.unprotect();
+ request.ensureStillAlive();
this.resp.writeStatus("413 Request Entity Too Large");
this.resp.endWithoutBody();
@@ -1767,9 +1756,20 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
this.request_body_buf.ensureTotalCapacityPrecise(this.allocator, len) catch @panic("Out of memory while allocating request body buffer");
+ } else if (this.req.header("transfer-encoding") == null) {
+ // no content-length
+ // no transfer-encoding
+ if (request.as(Request)) |req| {
+ var old = req.body;
+ old.Locked.callback = null;
+ req.body = .{ .Empty = .{} };
+ old.resolve(&req.body, this.server.globalThis);
+ return;
+ }
}
- this.setAbortHandler();
+ request.protect();
+ this.setAbortHandler();
this.resp.onData(*RequestContext, onBodyChunk, this);
}
@@ -2096,7 +2096,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
};
request_object.url.mark();
// We keep the Request object alive for the duration of the request so that we can remove the pointer to the UWS request object.
- var args = [_]JSC.C.JSValueRef{JSC.WebCore.Request.Class.make(this.globalThis.ref(), request_object)};
+ var args = [_]JSC.C.JSValueRef{request_object.toJS(this.globalThis).asObjectRef()};
ctx.request_js_object = args[0];
const request_value = JSValue.c(args[0]);
request_value.ensureStillAlive();
@@ -2161,6 +2161,35 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
if (wait_for_promise) {
+ // Even if the user hasn't requested it, we have to start downloading the body!!
+ // terrible for performance.
+ if (request_object.body == .Locked and (request_object.body.Locked.promise == null and request_object.body.Locked.readable == null) and ((HTTP.Method.which(req.method()) orelse HTTP.Method.OPTIONS).hasBody())) {
+ const req_len: usize = brk: {
+ if (req.header("content-length")) |content_length| {
+ break :brk std.fmt.parseInt(usize, content_length, 10) catch 0;
+ }
+
+ break :brk 0;
+ };
+
+ if (req_len > this.config.max_request_body_size) {
+ resp.writeStatus("413 Request Entity Too Large");
+ resp.endWithoutBody();
+ this.finalize();
+ return;
+ }
+
+ if ((req_len > 0)) {
+ ctx.request_body_buf.ensureTotalCapacityPrecise(ctx.allocator, req_len) catch {
+ resp.writeStatus("413 Request Entity Too Large");
+ resp.endWithoutBody();
+ this.finalize();
+ return;
+ };
+ resp.onData(*RequestContext, RequestContext.onBodyChunk, ctx);
+ }
+ }
+
ctx.setAbortHandler();
ctx.pending_promises_for_abort += 1;
diff --git a/src/bun.js/api/transpiler.zig b/src/bun.js/api/transpiler.zig
index 8d6d2c141..6303f5d51 100644
--- a/src/bun.js/api/transpiler.zig
+++ b/src/bun.js/api/transpiler.zig
@@ -816,7 +816,7 @@ pub fn finalize(
this.arena.deinit();
}
-fn getParseResult(this: *Transpiler, allocator: std.mem.Allocator, code: []const u8, loader: ?Loader, macro_js_ctx: JSValue) ?Bundler.ParseResult {
+fn getParseResult(this: *Transpiler, allocator: std.mem.Allocator, code: []const u8, loader: ?Loader, macro_js_ctx: Bundler.MacroJSValueType) ?Bundler.ParseResult {
const name = this.transpiler_options.default_loader.stdinName();
const source = logger.Source.initPathString(name, code);
@@ -862,6 +862,7 @@ pub fn scan(
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
) JSC.C.JSObjectRef {
+ JSC.markBinding();
var args = JSC.Node.ArgumentsSlice.init(ctx.bunVM(), @ptrCast([*]const JSC.JSValue, arguments.ptr)[0..arguments.len]);
defer args.arena.deinit();
const code_arg = args.next() orelse {
@@ -904,7 +905,7 @@ pub fn scan(
JSAst.Expr.Data.Store.reset();
}
- const parse_result = getParseResult(this, arena.allocator(), code, loader, JSC.JSValue.zero) orelse {
+ const parse_result = getParseResult(this, arena.allocator(), code, loader, Bundler.MacroJSValueType.zero) orelse {
if ((this.bundler.log.warnings + this.bundler.log.errors) > 0) {
var out_exception = this.bundler.log.toJS(ctx.ptr(), getAllocator(ctx), "Parse error");
exception.* = out_exception.asObjectRef();
@@ -953,6 +954,8 @@ pub fn transform(
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
) JSC.C.JSObjectRef {
+ JSC.markBinding();
+
var args = JSC.Node.ArgumentsSlice.init(ctx.bunVM(), @ptrCast([*]const JSC.JSValue, arguments.ptr)[0..arguments.len]);
defer args.arena.deinit();
const code_arg = args.next() orelse {
@@ -1066,13 +1069,12 @@ pub fn transformSync(
defer {
this.bundler = prev_bundler;
}
-
var parse_result = getParseResult(
this,
arena.allocator(),
code,
loader,
- js_ctx_value,
+ if (comptime JSC.is_bindgen) Bundler.MacroJSValueType.zero else js_ctx_value,
) orelse {
if ((this.bundler.log.warnings + this.bundler.log.errors) > 0) {
var out_exception = this.bundler.log.toJS(ctx.ptr(), getAllocator(ctx), "Parse error");
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index dd4f2ffc5..a875c5306 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -2152,6 +2152,154 @@ pub fn NewClassWithInstanceType(
};
}
+// pub fn NewInstanceFunction(
+// comptime className: []const u8,
+// comptime functionName: []const u8,
+// comptime InstanceType: type,
+// comptime target: anytype,
+// ) type {
+// return struct {
+// pub const shim = JSC.Shimmer("ZigGenerated__" ++ className, functionName, @This());
+// pub const name = functionName;
+// pub const Type = InstanceType;
+
+// pub fn callAsFunction(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
+// var this = InstanceType.toWrapped(callframe.this()) orelse {
+// callframe.toInvalidArguments("Expected this to be a " ++ className, .{}, globalObject);
+// return JSC.JSValue.jsUndefined();
+// };
+
+// return target(globalObject, this, callframe.arguments());
+// }
+
+// pub const Export = shim.exportFunctions(.{
+// .callAsFunction = callAsFunction,
+// });
+
+// pub const symbol = Export[0].symbol_name;
+
+// comptime {
+// if (!JSC.is_bindgen) {
+// @export(callAsFunction, .{
+// .name = Export[0].symbol_name,
+// });
+// }
+// }
+// };
+// }
+
+// pub fn NewStaticFunction(
+// comptime className: []const u8,
+// comptime functionName: []const u8,
+// comptime target: anytype,
+// ) type {
+// return struct {
+// pub const shim = JSC.Shimmer("ZigGenerated__Static__" ++ className, functionName, @This());
+// pub const name = functionName;
+
+// pub fn callAsFunction(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
+// return target(globalObject, callframe.arguments());
+// }
+
+// pub const Export = shim.exportFunctions(.{
+// .callAsFunction = callAsFunction,
+// });
+
+// pub const symbol = Export[0].symbol_name;
+
+// comptime {
+// if (!JSC.is_bindgen) {
+// @export(callAsFunction, .{
+// .name = Export[0].symbol_name,
+// });
+// }
+// }
+// };
+// }
+
+// pub fn NewStaticConstructor(
+// comptime className: []const u8,
+// comptime functionName: []const u8,
+// comptime target: anytype,
+// ) type {
+// return struct {
+// pub const shim = JSC.Shimmer("ZigGenerated__Static__" ++ className, functionName, @This());
+// pub const name = functionName;
+
+// pub fn callAsConstructor(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSValue {
+// return target(globalObject, callframe.arguments());
+// }
+
+// pub const Export = shim.exportFunctions(.{
+// .callAsConstructor = callAsConstructor,
+// });
+
+// pub const symbol = Export[0].symbol_name;
+
+// comptime {
+// if (!JSC.is_bindgen) {
+// @export(callAsConstructor, .{
+// .name = Export[0].symbol_name,
+// });
+// }
+// }
+// };
+// }
+
+// pub fn NewStaticObject(
+// comptime className: []const u8,
+// comptime function_definitions: anytype,
+// comptime property_definitions_: anytype,
+// ) type {
+// return struct {
+// const property_definitions = property_definitions_;
+// pub const shim = JSC.Shimmer("ZigGenerated", name, @This());
+// pub const name = className;
+// pub const Type = void;
+
+// const function_names = std.meta.fieldNames(@TypeOf(function_definitions));
+// pub fn getFunctions() [function_names.len]type {
+// var data: [function_names.len]type = undefined;
+// var i: usize = 0;
+// while (i < function_names.len) : (i += 1) {
+// if (strings.eqlComptime(function_names[i], "constructor")) {
+// data[i] = NewStaticConstructor(className, function_names[i], @TypeOf(function_definitions)[function_names[i]]);
+// } else {
+// data[i] = NewStaticFunction(className, function_names[i], @TypeOf(function_definitions)[function_names[i]]);
+// }
+// }
+
+// return data;
+// }
+
+// const property_names = std.meta.fieldNames(@TypeOf(property_definitions));
+// pub fn getProperties() [property_definitions.len]type {
+// var data: [property_definitions.len]type = undefined;
+// var i: usize = 0;
+// while (i < property_definitions.len) : (i += 1) {
+// const definition = property_definitions[i];
+// if (@hasField(definition, "lazyClass")) {
+// data[i] = New(className, property_names[i], @field(property_definitions, property_names[i]));
+// } else if (@hasField(definition, "lazyProperty")) {
+// data[i] = NewLazyProperty(className, property_names[i], @field(property_definitions, property_names[i]));
+// } else if (@hasField(definition, "get") and @hasField(definition, "set")) {
+// data[i] = NewStaticProperty(className, property_names[i], definition.get, definition.set);
+// } else if (@hasField(definition, "get")) {
+// data[i] = NewStaticProperty(className, property_names[i], definition.get, void{});
+// } else if (@hasField(definition, "set")) {
+// data[i] = NewStaticProperty(className, property_names[i], void{}, definition.set);
+// } else {
+// @compileError(className ++ "." ++ property_names[i] ++ " missing lazy, get, or set");
+// }
+// }
+
+// return data;
+// }
+
+// pub const entries = getProperties() ++ getFunctions();
+// };
+// }
+
const JSValue = JSC.JSValue;
const ZigString = JSC.ZigString;
diff --git a/src/bun.js/bindings/ZigConsoleClient.cpp b/src/bun.js/bindings/ZigConsoleClient.cpp
index 66d24b129..d7cf831d4 100644
--- a/src/bun.js/bindings/ZigConsoleClient.cpp
+++ b/src/bun.js/bindings/ZigConsoleClient.cpp
@@ -63,7 +63,6 @@ void Zig::ConsoleClient::messageWithTypeAndLevel(MessageType type, MessageLevel
auto count = std::min(args->argumentCount(), (size_t)255);
for (size_t i = 0; i < count; i++) {
auto val = args->argumentAt(i);
- // JSC::gcProtect(val);
jsArgs[i] = JSC::JSValue::encode(val);
}
@@ -72,10 +71,6 @@ void Zig::ConsoleClient::messageWithTypeAndLevel(MessageType type, MessageLevel
static_cast<uint32_t>(level), globalObject, jsArgs,
count);
scope.clearException();
-
- // for (size_t i = 0; i < count; i++) {
- // JSC::gcUnprotect(JSC::JSValue::decode(jsArgs[i]));
- // }
}
void Zig::ConsoleClient::count(JSGlobalObject* globalObject, const String& label)
{
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
new file mode 100644
index 000000000..94a6f0705
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h
@@ -0,0 +1,3 @@
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForRequest;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForRequestConstructor;std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForResponse;
+std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForResponseConstructor; \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
new file mode 100644
index 000000000..2f2ad27ec
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h
@@ -0,0 +1,3 @@
+std::unique_ptr<IsoSubspace> m_subspaceForRequest;
+std::unique_ptr<IsoSubspace> m_subspaceForRequestConstructor;std::unique_ptr<IsoSubspace> m_subspaceForResponse;
+std::unique_ptr<IsoSubspace> m_subspaceForResponseConstructor; \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
new file mode 100644
index 000000000..d6c138602
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureHeader.h
@@ -0,0 +1,8 @@
+JSC::Structure* JSRequestStructure() { return m_JSRequest.getInitializedOnMainThread(this); }
+ JSC::JSObject* JSRequestConstructor() { return m_JSRequest.constructorInitializedOnMainThread(this); }
+ JSC::JSValue JSRequestPrototype() { return m_JSRequest.prototypeInitializedOnMainThread(this); }
+ JSC::LazyClassStructure m_JSRequest;
+JSC::Structure* JSResponseStructure() { return m_JSResponse.getInitializedOnMainThread(this); }
+ JSC::JSObject* JSResponseConstructor() { return m_JSResponse.constructorInitializedOnMainThread(this); }
+ JSC::JSValue JSResponsePrototype() { return m_JSResponse.prototypeInitializedOnMainThread(this); }
+ JSC::LazyClassStructure m_JSResponse; \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
new file mode 100644
index 000000000..5a7fcc406
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedClasses+lazyStructureImpl.h
@@ -0,0 +1,20 @@
+void GlobalObject::initGeneratedLazyClasses() {
+ m_JSRequest.initLater(
+ [](LazyClassStructure::Initializer& init) {
+ init.setPrototype(WebCore::JSRequest::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
+ init.setStructure(WebCore::JSRequest::createStructure(init.vm, init.global, init.prototype));
+ init.setConstructor(WebCore::JSRequestConstructor::create(init.vm, init.global, WebCore::JSRequestConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSRequestPrototype*>(init.prototype)));
+ });
+ m_JSResponse.initLater(
+ [](LazyClassStructure::Initializer& init) {
+ init.setPrototype(WebCore::JSResponse::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
+ init.setStructure(WebCore::JSResponse::createStructure(init.vm, init.global, init.prototype));
+ init.setConstructor(WebCore::JSResponseConstructor::create(init.vm, init.global, WebCore::JSResponseConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::JSResponsePrototype*>(init.prototype)));
+ });
+}
+template<typename Visitor>
+void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor)
+{
+ thisObject->m_JSRequest.visit(visitor);
+ thisObject->m_JSResponse.visit(visitor);
+} \ No newline at end of file
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp
new file mode 100644
index 000000000..0c5c90cd1
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp
@@ -0,0 +1,972 @@
+
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// Generated by src/bun.js/generate-classes.js
+#include "root.h"
+
+#include "ZigGlobalObject.h"
+
+#include <JavaScriptCore/DOMJITAbstractHeap.h>
+#include "DOMJITIDLConvert.h"
+#include "DOMJITIDLType.h"
+#include "DOMJITIDLTypeFilter.h"
+#include "DOMJITHelpers.h"
+#include <JavaScriptCore/DFGAbstractHeap.h>
+
+#include "JSDOMConvertBufferSource.h"
+#include "ZigGeneratedClasses.h"
+
+
+
+
+namespace WebCore {
+
+using namespace JSC;
+using namespace Zig;
+
+extern "C" void* RequestClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+JSC_DECLARE_CUSTOM_GETTER(jsRequestConstructor);
+extern "C" void RequestClass__finalize(void*);
+
+extern "C" EncodedJSValue RequestPrototype__getArrayBuffer(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(RequestPrototype__arrayBufferCallback);
+
+
+extern "C" EncodedJSValue RequestPrototype__getBlob(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(RequestPrototype__blobCallback);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getBodyUsed(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__bodyUsedGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getCache(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__cacheGetterWrap);
+
+
+extern "C" EncodedJSValue RequestPrototype__doClone(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(RequestPrototype__cloneCallback);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getCredentials(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__credentialsGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getDestination(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__destinationGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getHeaders(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__headersGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getIntegrity(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__integrityGetterWrap);
+
+
+extern "C" EncodedJSValue RequestPrototype__getJSON(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(RequestPrototype__jsonCallback);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getMethod(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__methodGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getMode(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__modeGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getRedirect(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__redirectGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getReferrer(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__referrerGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getReferrerPolicy(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__referrerPolicyGetterWrap);
+
+
+extern "C" EncodedJSValue RequestPrototype__getText(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(RequestPrototype__textCallback);
+
+
+extern "C" JSC::EncodedJSValue RequestPrototype__getUrl(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(RequestPrototype__urlGetterWrap);
+
+
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSRequestPrototype, JSRequestPrototype::Base);
+
+
+ static const HashTableValue JSRequestPrototypeTableValues[] = {
+{ "arrayBuffer"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(RequestPrototype__arrayBufferCallback), (intptr_t)(0) } } ,
+{ "blob"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(RequestPrototype__blobCallback), (intptr_t)(0) } } ,
+{ "bodyUsed"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__bodyUsedGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "cache"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__cacheGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "clone"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(RequestPrototype__cloneCallback), (intptr_t)(1) } } ,
+{ "credentials"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__credentialsGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "destination"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__destinationGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "headers"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__headersGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "integrity"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__integrityGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "json"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(RequestPrototype__jsonCallback), (intptr_t)(0) } } ,
+{ "method"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__methodGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "mode"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__modeGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "redirect"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__redirectGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "referrer"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__referrerGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "referrerPolicy"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__referrerPolicyGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "text"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(RequestPrototype__textCallback), (intptr_t)(0) } } ,
+{ "url"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(RequestPrototype__urlGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }
+ };
+
+
+const ClassInfo JSRequestPrototype::s_info = { "Request"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSRequestPrototype) };
+
+
+
+JSC_DEFINE_CUSTOM_GETTER(jsRequestConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
+{
+ VM& vm = JSC::getVM(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto* prototype = jsDynamicCast<JSRequestPrototype*>(JSValue::decode(thisValue));
+
+ if (UNLIKELY(!prototype))
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ return JSValue::encode(globalObject->JSRequestConstructor());
+}
+
+
+
+JSC_DEFINE_HOST_FUNCTION(RequestPrototype__arrayBufferCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSRequest* thisObject = jsDynamicCast<JSRequest*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return RequestPrototype__getArrayBuffer(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(RequestPrototype__blobCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSRequest* thisObject = jsDynamicCast<JSRequest*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return RequestPrototype__getBlob(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__bodyUsedGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getBodyUsed(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__cacheGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getCache(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(RequestPrototype__cloneCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSRequest* thisObject = jsDynamicCast<JSRequest*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return RequestPrototype__doClone(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__credentialsGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getCredentials(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__destinationGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getDestination(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__headersGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_headers.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ RequestPrototype__getHeaders(thisObject->wrapped(), globalObject)
+ );
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_headers.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__integrityGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getIntegrity(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(RequestPrototype__jsonCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSRequest* thisObject = jsDynamicCast<JSRequest*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return RequestPrototype__getJSON(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__methodGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getMethod(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__modeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getMode(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__redirectGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getRedirect(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__referrerGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getReferrer(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__referrerPolicyGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = RequestPrototype__getReferrerPolicy(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(RequestPrototype__textCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSRequest* thisObject = jsDynamicCast<JSRequest*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return RequestPrototype__getText(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(RequestPrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSRequest* thisObject = jsCast<JSRequest*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_url.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ RequestPrototype__getUrl(thisObject->wrapped(), globalObject)
+ );
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_url.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+
+void JSRequestPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSRequest::info(), JSRequestPrototypeTableValues, *this);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+void JSRequestConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSRequestPrototype* prototype)
+{
+ Base::finishCreation(vm, 0, "Request"_s, PropertyAdditionMode::WithoutStructureTransition);
+
+ ASSERT(inherits(info()));
+}
+
+JSRequestConstructor* JSRequestConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSRequestPrototype* prototype) {
+ JSRequestConstructor* ptr = new (NotNull, JSC::allocateCell<JSRequestConstructor>(vm)) JSRequestConstructor(vm, structure, construct);
+ ptr->finishCreation(vm, globalObject, prototype);
+ return ptr;
+}
+
+JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSRequestConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame)
+{
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ JSC::VM &vm = globalObject->vm();
+ JSObject* newTarget = asObject(callFrame->newTarget());
+ auto* constructor = globalObject->JSRequestConstructor();
+ Structure* structure = globalObject->JSRequestStructure();
+ if (constructor != newTarget) {
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>(
+ // ShadowRealm functions belong to a different global object.
+ getFunctionRealm(globalObject, newTarget)
+ );
+ RETURN_IF_EXCEPTION(scope, {});
+ structure = InternalFunction::createSubclassStructure(
+ globalObject,
+ newTarget,
+ functionGlobalObject->JSRequestStructure()
+ );
+ }
+
+ void* ptr = RequestClass__construct(globalObject, callFrame);
+
+ if (UNLIKELY(!ptr)) {
+ return JSValue::encode(JSC::jsUndefined());
+ }
+
+ JSRequest* instance = JSRequest::create(vm, globalObject, structure, ptr);
+
+ return JSValue::encode(instance);
+}
+
+extern "C" EncodedJSValue Request__create(Zig::GlobalObject* globalObject, void* ptr) {
+ auto &vm = globalObject->vm();
+ JSC::Structure* structure = globalObject->JSRequestStructure();
+ JSRequest* instance = JSRequest::create(vm, globalObject, structure, ptr);
+ return JSValue::encode(instance);
+}
+
+void JSRequestConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSRequestPrototype* prototype)
+{
+
+}
+
+const ClassInfo JSRequestConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSRequestConstructor) };
+
+JSRequest::~JSRequest()
+{
+ if (m_ctx) {
+ RequestClass__finalize(m_ctx);
+ }
+}
+void JSRequest::destroy(JSCell* cell)
+{
+ static_cast<JSRequest*>(cell)->JSRequest::~JSRequest();
+}
+
+const ClassInfo JSRequest::s_info = { "Request"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSRequest) };
+
+void JSRequest::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+JSRequest* JSRequest::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) {
+ JSRequest* ptr = new (NotNull, JSC::allocateCell<JSRequest>(vm)) JSRequest(vm, structure, ctx);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+
+extern "C" void* Request__fromJS(JSC::EncodedJSValue value) {
+ JSRequest* object = JSC::jsDynamicCast<JSRequest*>(JSValue::decode(value));
+ if (!object)
+ return nullptr;
+
+ return object->wrapped();
+}
+
+extern "C" bool Request__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) {
+ JSRequest* object = JSC::jsDynamicCast<JSRequest*>(JSValue::decode(value));
+ if (!object)
+ return false;
+
+ object->m_ctx = ptr;
+ return true;
+}
+
+
+extern "C" const size_t Request__ptrOffset = JSRequest::offsetOfWrapped();
+
+void JSRequest::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSRequest*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+JSObject* JSRequest::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
+{
+ return JSRequestPrototype::create(vm, globalObject, JSRequestPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+}
+
+template<typename Visitor>
+void JSRequest::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSRequest* thisObject = jsCast<JSRequest*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_headers);
+ visitor.append(thisObject->m_url);
+}
+
+DEFINE_VISIT_CHILDREN(JSRequest);extern "C" void* ResponseClass__construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+JSC_DECLARE_CUSTOM_GETTER(jsResponseConstructor);
+extern "C" void ResponseClass__finalize(void*);
+
+extern "C" EncodedJSValue ResponsePrototype__getArrayBuffer(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(ResponsePrototype__arrayBufferCallback);
+
+
+extern "C" EncodedJSValue ResponsePrototype__getBlob(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(ResponsePrototype__blobCallback);
+
+
+extern "C" JSC::EncodedJSValue ResponsePrototype__getBodyUsed(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__bodyUsedGetterWrap);
+
+
+extern "C" EncodedJSValue ResponsePrototype__doClone(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(ResponsePrototype__cloneCallback);
+
+
+extern "C" JSC::EncodedJSValue ResponsePrototype__getHeaders(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__headersGetterWrap);
+
+
+extern "C" EncodedJSValue ResponsePrototype__getJSON(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(ResponsePrototype__jsonCallback);
+
+
+extern "C" JSC::EncodedJSValue ResponsePrototype__getOK(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__okGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue ResponsePrototype__getStatus(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__statusGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue ResponsePrototype__getStatusText(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__statusTextGetterWrap);
+
+
+extern "C" EncodedJSValue ResponsePrototype__getText(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);
+JSC_DECLARE_HOST_FUNCTION(ResponsePrototype__textCallback);
+
+
+extern "C" JSC::EncodedJSValue ResponsePrototype__getResponseType(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__typeGetterWrap);
+
+
+extern "C" JSC::EncodedJSValue ResponsePrototype__getURL(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);
+JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__urlGetterWrap);
+
+
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSResponsePrototype, JSResponsePrototype::Base);
+
+
+ static const HashTableValue JSResponsePrototypeTableValues[] = {
+{ "arrayBuffer"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponsePrototype__arrayBufferCallback), (intptr_t)(0) } } ,
+{ "blob"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponsePrototype__blobCallback), (intptr_t)(0) } } ,
+{ "bodyUsed"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(ResponsePrototype__bodyUsedGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "clone"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponsePrototype__cloneCallback), (intptr_t)(1) } } ,
+{ "headers"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(ResponsePrototype__headersGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "json"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponsePrototype__jsonCallback), (intptr_t)(0) } } ,
+{ "ok"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(ResponsePrototype__okGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "status"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(ResponsePrototype__statusGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "statusText"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(ResponsePrototype__statusTextGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "text"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponsePrototype__textCallback), (intptr_t)(0) } } ,
+{ "type"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(ResponsePrototype__typeGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } } ,
+{ "url"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(ResponsePrototype__urlGetterWrap), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }
+ };
+
+
+const ClassInfo JSResponsePrototype::s_info = { "Response"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSResponsePrototype) };
+
+
+
+JSC_DEFINE_CUSTOM_GETTER(jsResponseConstructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
+{
+ VM& vm = JSC::getVM(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto* prototype = jsDynamicCast<JSResponsePrototype*>(JSValue::decode(thisValue));
+
+ if (UNLIKELY(!prototype))
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ return JSValue::encode(globalObject->JSResponseConstructor());
+}
+
+
+
+JSC_DEFINE_HOST_FUNCTION(ResponsePrototype__arrayBufferCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSResponse* thisObject = jsDynamicCast<JSResponse*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return ResponsePrototype__getArrayBuffer(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(ResponsePrototype__blobCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSResponse* thisObject = jsDynamicCast<JSResponse*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return ResponsePrototype__getBlob(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__bodyUsedGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = ResponsePrototype__getBodyUsed(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(ResponsePrototype__cloneCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSResponse* thisObject = jsDynamicCast<JSResponse*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return ResponsePrototype__doClone(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__headersGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_headers.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ ResponsePrototype__getHeaders(thisObject->wrapped(), globalObject)
+ );
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_headers.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(ResponsePrototype__jsonCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSResponse* thisObject = jsDynamicCast<JSResponse*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return ResponsePrototype__getJSON(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__okGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = ResponsePrototype__getOK(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__statusGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = ResponsePrototype__getStatus(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__statusTextGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_statusText.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ ResponsePrototype__getStatusText(thisObject->wrapped(), globalObject)
+ );
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_statusText.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+
+JSC_DEFINE_HOST_FUNCTION(ResponsePrototype__textCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ JSResponse* thisObject = jsDynamicCast<JSResponse*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return ResponsePrototype__getText(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__typeGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = ResponsePrototype__getResponseType(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+
+
+JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__urlGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_url.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ ResponsePrototype__getURL(thisObject->wrapped(), globalObject)
+ );
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_url.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+
+
+void JSResponsePrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, JSResponse::info(), JSResponsePrototypeTableValues, *this);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+extern "C" JSC_DECLARE_HOST_FUNCTION(ResponseClass__constructError);
+extern "C" JSC_DECLARE_HOST_FUNCTION(ResponseClass__constructJSON);
+extern "C" JSC_DECLARE_HOST_FUNCTION(ResponseClass__constructRedirect);
+
+ static const HashTableValue JSResponseConstructorTableValues[] = {
+{ "error"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponseClass__constructError), (intptr_t)(0) } } ,
+{ "json"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponseClass__constructJSON), (intptr_t)(0) } } ,
+{ "redirect"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(ResponseClass__constructRedirect), (intptr_t)(0) } }
+ };
+
+
+void JSResponseConstructor::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSResponsePrototype* prototype)
+{
+ Base::finishCreation(vm, 0, "Response"_s, PropertyAdditionMode::WithoutStructureTransition);
+ reifyStaticProperties(vm, &JSResponseConstructor::s_info, JSResponseConstructorTableValues, *this);
+ ASSERT(inherits(info()));
+}
+
+JSResponseConstructor* JSResponseConstructor::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSResponsePrototype* prototype) {
+ JSResponseConstructor* ptr = new (NotNull, JSC::allocateCell<JSResponseConstructor>(vm)) JSResponseConstructor(vm, structure, construct);
+ ptr->finishCreation(vm, globalObject, prototype);
+ return ptr;
+}
+
+JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSResponseConstructor::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame)
+{
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ JSC::VM &vm = globalObject->vm();
+ JSObject* newTarget = asObject(callFrame->newTarget());
+ auto* constructor = globalObject->JSResponseConstructor();
+ Structure* structure = globalObject->JSResponseStructure();
+ if (constructor != newTarget) {
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>(
+ // ShadowRealm functions belong to a different global object.
+ getFunctionRealm(globalObject, newTarget)
+ );
+ RETURN_IF_EXCEPTION(scope, {});
+ structure = InternalFunction::createSubclassStructure(
+ globalObject,
+ newTarget,
+ functionGlobalObject->JSResponseStructure()
+ );
+ }
+
+ void* ptr = ResponseClass__construct(globalObject, callFrame);
+
+ if (UNLIKELY(!ptr)) {
+ return JSValue::encode(JSC::jsUndefined());
+ }
+
+ JSResponse* instance = JSResponse::create(vm, globalObject, structure, ptr);
+
+ return JSValue::encode(instance);
+}
+
+extern "C" EncodedJSValue Response__create(Zig::GlobalObject* globalObject, void* ptr) {
+ auto &vm = globalObject->vm();
+ JSC::Structure* structure = globalObject->JSResponseStructure();
+ JSResponse* instance = JSResponse::create(vm, globalObject, structure, ptr);
+ return JSValue::encode(instance);
+}
+
+void JSResponseConstructor::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, JSResponsePrototype* prototype)
+{
+
+}
+
+const ClassInfo JSResponseConstructor::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSResponseConstructor) };
+
+JSResponse::~JSResponse()
+{
+ if (m_ctx) {
+ ResponseClass__finalize(m_ctx);
+ }
+}
+void JSResponse::destroy(JSCell* cell)
+{
+ static_cast<JSResponse*>(cell)->JSResponse::~JSResponse();
+}
+
+const ClassInfo JSResponse::s_info = { "Response"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSResponse) };
+
+void JSResponse::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+JSResponse* JSResponse::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) {
+ JSResponse* ptr = new (NotNull, JSC::allocateCell<JSResponse>(vm)) JSResponse(vm, structure, ctx);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+
+extern "C" void* Response__fromJS(JSC::EncodedJSValue value) {
+ JSResponse* object = JSC::jsDynamicCast<JSResponse*>(JSValue::decode(value));
+ if (!object)
+ return nullptr;
+
+ return object->wrapped();
+}
+
+extern "C" bool Response__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) {
+ JSResponse* object = JSC::jsDynamicCast<JSResponse*>(JSValue::decode(value));
+ if (!object)
+ return false;
+
+ object->m_ctx = ptr;
+ return true;
+}
+
+
+extern "C" const size_t Response__ptrOffset = JSResponse::offsetOfWrapped();
+
+void JSResponse::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<JSResponse*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+JSObject* JSResponse::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
+{
+ return JSResponsePrototype::create(vm, globalObject, JSResponsePrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
+}
+
+template<typename Visitor>
+void JSResponse::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ JSResponse* thisObject = jsCast<JSResponse*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_headers);
+ visitor.append(thisObject->m_statusText);
+ visitor.append(thisObject->m_url);
+}
+
+DEFINE_VISIT_CHILDREN(JSResponse);
+
+} // namespace WebCore
+
diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h
new file mode 100644
index 000000000..655397493
--- /dev/null
+++ b/src/bun.js/bindings/ZigGeneratedClasses.h
@@ -0,0 +1,268 @@
+
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// Generated by src/bun.js/generate-classes.js
+#pragma once
+
+#include "root.h"
+
+namespace Zig {
+}
+
+#include "JSDOMWrapper.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+using namespace Zig;
+using namespace JSC;
+
+class JSRequest final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSRequest* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx);
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSRequest, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForRequest.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForRequest = WTFMove(space); },
+ [](auto& spaces) { return spaces.m_subspaceForRequest.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForRequest = WTFMove(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(0b11101110), StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject);
+
+ ~JSRequest();
+
+ void* wrapped() const { return m_ctx; }
+
+ void detach()
+ {
+ m_ctx = nullptr;
+ }
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+ static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSRequest, m_ctx); }
+
+ void* m_ctx { nullptr };
+
+ JSRequest(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_ctx = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+
+ DECLARE_VISIT_CHILDREN;
+
+ mutable JSC::WriteBarrier<JSC::Unknown> m_headers;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_url;
+};
+class JSRequestPrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSRequestPrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSRequestPrototype* ptr = new (NotNull, JSC::allocateCell<JSRequestPrototype>(vm)) JSRequestPrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSRequestPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+
+class JSRequestConstructor final : public JSC::InternalFunction {
+public:
+ using Base = JSC::InternalFunction;
+ static JSRequestConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSRequestPrototype* prototype);
+
+ static constexpr unsigned StructureFlags = Base::StructureFlags;
+ static constexpr bool needsDestruction = false;
+
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
+ }
+
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSRequestConstructor, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForRequestConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForRequestConstructor = WTFMove(space); },
+ [](auto& spaces) { return spaces.m_subspaceForRequestConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForRequestConstructor = WTFMove(space); });
+ }
+
+ void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSRequestPrototype* prototype);
+
+ // Must be defined for each specialization class.
+ static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+ DECLARE_EXPORT_INFO;
+
+private:
+ JSRequestConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
+ : Base(vm, structure, nativeFunction, nativeFunction)
+
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSRequestPrototype* prototype);
+};
+class JSResponse final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+ static JSResponse* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx);
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSResponse, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForResponse.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForResponse = WTFMove(space); },
+ [](auto& spaces) { return spaces.m_subspaceForResponse.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForResponse = WTFMove(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(0b11101110), StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject);
+
+ ~JSResponse();
+
+ void* wrapped() const { return m_ctx; }
+
+ void detach()
+ {
+ m_ctx = nullptr;
+ }
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+ static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(JSResponse, m_ctx); }
+
+ void* m_ctx { nullptr };
+
+ JSResponse(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_ctx = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+
+ DECLARE_VISIT_CHILDREN;
+
+ mutable JSC::WriteBarrier<JSC::Unknown> m_headers;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_statusText;
+ mutable JSC::WriteBarrier<JSC::Unknown> m_url;
+};
+class JSResponsePrototype final : public JSC::JSNonFinalObject {
+public:
+ using Base = JSC::JSNonFinalObject;
+
+ static JSResponsePrototype* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ JSResponsePrototype* ptr = new (NotNull, JSC::allocateCell<JSResponsePrototype>(vm)) JSResponsePrototype(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+private:
+ JSResponsePrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+};
+
+class JSResponseConstructor final : public JSC::InternalFunction {
+public:
+ using Base = JSC::InternalFunction;
+ static JSResponseConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSResponsePrototype* prototype);
+
+ static constexpr unsigned StructureFlags = Base::StructureFlags;
+ static constexpr bool needsDestruction = false;
+
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
+ }
+
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<JSResponseConstructor, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForResponseConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForResponseConstructor = WTFMove(space); },
+ [](auto& spaces) { return spaces.m_subspaceForResponseConstructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForResponseConstructor = WTFMove(space); });
+ }
+
+ void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSResponsePrototype* prototype);
+
+ // Must be defined for each specialization class.
+ static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+ DECLARE_EXPORT_INFO;
+
+private:
+ JSResponseConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
+ : Base(vm, structure, nativeFunction, nativeFunction)
+
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSResponsePrototype* prototype);
+};
+
+}
diff --git a/src/bun.js/bindings/ZigGeneratedCode.cpp b/src/bun.js/bindings/ZigGeneratedCode.cpp
index e5e377d82..c563597b8 100644
--- a/src/bun.js/bindings/ZigGeneratedCode.cpp
+++ b/src/bun.js/bindings/ZigGeneratedCode.cpp
@@ -1,60 +1,61 @@
-#include "root.h"
-
-#include <JavaScriptCore/DOMJITAbstractHeap.h>
-#include "DOMJITIDLConvert.h"
-#include "DOMJITIDLType.h"
-#include "DOMJITIDLTypeFilter.h"
-#include "DOMJITHelpers.h"
-#include <JavaScriptCore/DFGAbstractHeap.h>
-
-#include "JSDOMConvertBufferSource.h"
-
-using namespace JSC;
-using namespace WebCore;
-
-/* -- BEGIN DOMCall DEFINITIONS -- */
+ #include "root.h"
+
+ #include <JavaScriptCore/DOMJITAbstractHeap.h>
+ #include "DOMJITIDLConvert.h"
+ #include "DOMJITIDLType.h"
+ #include "DOMJITIDLTypeFilter.h"
+ #include "DOMJITHelpers.h"
+ #include <JavaScriptCore/DFGAbstractHeap.h>
+
+ #include "JSDOMConvertBufferSource.h"
+
+ using namespace JSC;
+ using namespace WebCore;
+
+
+ /* -- BEGIN DOMCall DEFINITIONS -- */
+
extern "C" JSC_DECLARE_HOST_FUNCTION(FFI__ptr__slowpathWrapper);
-extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*));
-
-JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1))
-{
- VM& vm = JSC::getVM(lexicalGlobalObject);
- IGNORE_WARNINGS_BEGIN("frame-address")
- CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
- IGNORE_WARNINGS_END
- JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
- return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1);
+extern "C" JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array*));
+
+JSC_DEFINE_JIT_OPERATION(FFI__ptr__fastpathWrapper, EncodedJSValue, (JSC::JSGlobalObject* lexicalGlobalObject, void* thisValue, JSC::JSUint8Array* arg1)) {
+VM& vm = JSC::getVM(lexicalGlobalObject);
+IGNORE_WARNINGS_BEGIN("frame-address")
+CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
+IGNORE_WARNINGS_END
+JSC::JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
+return FFI__ptr__fastpath(lexicalGlobalObject, thisValue, arg1);
}
-JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* frame))
-{
+JSC_DEFINE_HOST_FUNCTION(FFI__ptr__slowpathWrapper, (JSC::JSGlobalObject *globalObject, JSC::CallFrame* frame)) {
return FFI__ptr__slowpath(globalObject, JSValue::encode(frame->thisValue()), reinterpret_cast<JSC::EncodedJSValue*>(frame->addressOfArgumentsStart()), frame->argumentCount());
}
-constexpr JSC::DFG::AbstractHeapKind encodeIntoRead[4] = { JSC::DFG::Absolute, JSC::DFG::MiscFields, JSC::DFG::TypedArrayProperties };
-constexpr JSC::DFG::AbstractHeapKind encodeIntoWrite[4] = { JSC::DFG::Absolute, JSC::DFG::TypedArrayProperties };
-
-extern "C" void FFI__ptr__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value)
-{
- JSC::JSObject* thisObject = JSC::jsCast<JSC::JSObject*>(JSC::JSValue::decode(value));
- static const JSC::DOMJIT::Signature DOMJIT_ptr_signature(
- FFI__ptr__fastpathWrapper,
- thisObject->classInfo(),
- JSC::DOMJIT::Effect::forReadWriteKinds(encodeIntoRead, encodeIntoWrite),
- JSC::SpecNonIntAsDouble,
- JSC::SpecUint8Array);
- JSFunction* function = JSFunction::create(
- globalObject->vm(),
- globalObject,
- 1,
- String("ptr"_s),
- FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper,
- &DOMJIT_ptr_signature);
- thisObject->putDirect(
- globalObject->vm(),
- Identifier::fromString(globalObject->vm(), "ptr"_s),
- function,
- JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0);
+extern "C" void FFI__ptr__put(JSC::JSGlobalObject *globalObject, JSC::EncodedJSValue value) {
+ JSC::JSObject *thisObject = JSC::jsCast<JSC::JSObject *>(JSC::JSValue::decode(value));
+ static const JSC::DOMJIT::Signature DOMJIT_ptr_signature(
+ FFI__ptr__fastpathWrapper,
+ thisObject->classInfo(),
+ JSC::DOMJIT::Effect::forReadWrite(JSC::DOMJIT::HeapRange::top(), JSC::DOMJIT::HeapRange::top()),
+ JSC::SpecNonIntAsDouble,
+ JSC::SpecUint8Array
+ );
+ JSFunction* function = JSFunction::create(
+ globalObject->vm(),
+ globalObject,
+ 1,
+ String("ptr"_s),
+ FFI__ptr__slowpathWrapper, ImplementationVisibility::Public, NoIntrinsic, FFI__ptr__slowpathWrapper,
+ &DOMJIT_ptr_signature
+ );
+ thisObject->putDirect(
+ globalObject->vm(),
+ Identifier::fromString(globalObject->vm(), "ptr"_s),
+ function,
+ JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DOMJITFunction | 0
+ );
}
-/* -- END DOMCall DEFINITIONS-- */
+
+ /* -- END DOMCall DEFINITIONS-- */
+
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index c7c43c523..b0eebfecd 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -102,6 +102,8 @@
#include "ReadableStreamBuiltins.h"
#include "BunJSCModule.h"
+#include "ZigGeneratedClasses.h"
+
using JSGlobalObject = JSC::JSGlobalObject;
using Exception = JSC::Exception;
using JSValue = JSC::JSValue;
@@ -471,6 +473,28 @@ JSC_DEFINE_CUSTOM_GETTER(JSURLSearchParams_getter,
WebCore::JSURLSearchParams::getConstructor(JSC::getVM(lexicalGlobalObject), thisObject));
}
+JSC_DECLARE_CUSTOM_GETTER(JSRequest_getter);
+
+JSC_DEFINE_CUSTOM_GETTER(JSRequest_getter,
+ (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue,
+ JSC::PropertyName))
+{
+ Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject);
+ return JSC::JSValue::encode(
+ thisObject->JSRequestConstructor());
+}
+
+JSC_DECLARE_CUSTOM_GETTER(JSResponse_getter);
+
+JSC_DEFINE_CUSTOM_GETTER(JSResponse_getter,
+ (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue,
+ JSC::PropertyName))
+{
+ Zig::GlobalObject* thisObject = JSC::jsCast<Zig::GlobalObject*>(lexicalGlobalObject);
+ return JSC::JSValue::encode(
+ thisObject->JSResponseConstructor());
+}
+
JSC_DECLARE_CUSTOM_GETTER(JSErrorEvent_getter);
JSC_DEFINE_CUSTOM_GETTER(JSErrorEvent_getter,
@@ -1768,10 +1792,12 @@ void GlobalObject::finishCreation(VM& vm)
// Change prototype from null to object for synthetic modules.
m_moduleNamespaceObjectStructure.initLater(
- [] (const Initializer<Structure>& init) {
+ [](const Initializer<Structure>& init) {
init.set(JSModuleNamespaceObject::createStructure(init.vm, init.owner, init.owner->objectPrototype()));
});
+ this->initGeneratedLazyClasses();
+
m_NapiClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
init.setStructure(Zig::NapiClass::createStructure(init.vm, init.global, init.global->functionPrototype()));
@@ -2068,6 +2094,12 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "URLSearchParams"_s), JSC::CustomGetterSetter::create(vm, JSURLSearchParams_getter, nullptr),
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
+ putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Request"_s), JSC::CustomGetterSetter::create(vm, JSRequest_getter, nullptr),
+ JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
+
+ putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "Response"_s), JSC::CustomGetterSetter::create(vm, JSResponse_getter, nullptr),
+ JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
+
putDirectCustomAccessor(vm, JSC::Identifier::fromString(vm, "DOMException"_s), JSC::CustomGetterSetter::create(vm, JSDOMException_getter, nullptr),
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
@@ -2324,6 +2356,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_processObject.visit(visitor);
thisObject->m_performanceObject.visit(visitor);
+ thisObject->visitGeneratedLazyClasses<Visitor>(thisObject, visitor);
+
visitor.append(thisObject->m_readableStreamToArrayBufferResolve);
visitor.append(thisObject->m_readableStreamToText);
visitor.append(thisObject->m_readableStreamToJSON);
@@ -2645,4 +2679,6 @@ void GlobalObject::queueMicrotaskToEventLoop(JSC::JSGlobalObject& global,
}
}
+#include "ZigGeneratedClasses+lazyStructureImpl.h"
+
} // namespace Zig
diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h
index 375cc2300..9d71b91ac 100644
--- a/src/bun.js/bindings/ZigGlobalObject.h
+++ b/src/bun.js/bindings/ZigGlobalObject.h
@@ -203,6 +203,10 @@ public:
}
void handleRejectedPromises();
+ void initGeneratedLazyClasses();
+
+ template<typename Visitor>
+ void visitGeneratedLazyClasses(GlobalObject*, Visitor&);
void* bunVM() { return m_bunVM; }
bool isThreadLocalDefaultGlobalObject = false;
@@ -218,6 +222,8 @@ public:
this->m_ffiFunctions.append(JSC::Strong<JSC::JSFunction> { vm(), function });
}
+#include "ZigGeneratedClasses+lazyStructureHeader.h"
+
private:
void addBuiltinGlobals(JSC::VM&);
void finishCreation(JSC::VM&);
diff --git a/src/bun.js/bindings/bindings-generator.zig b/src/bun.js/bindings/bindings-generator.zig
index 3e5eb78cc..5e7bd3e9b 100644
--- a/src/bun.js/bindings/bindings-generator.zig
+++ b/src/bun.js/bindings/bindings-generator.zig
@@ -25,20 +25,18 @@ pub fn main() anyerror!void {
{
const paths = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "headers.h" };
const paths2 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "headers-cpp.h" };
- const paths3 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "ZigLazyStaticFunctions.h" };
const paths4 = [_][]const u8{ std.fs.path.dirname(src.file) orelse return error.BadPath, "ZigGeneratedCode.cpp" };
const cpp = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths2), .{});
const file = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths), .{});
- const static = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths3), .{});
- const staticInlines = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths4), .{});
+ const generated = try std.fs.createFileAbsolute(try std.fs.path.join(allocator, &paths4), .{});
const HeaderGenerator = HeaderGen(
Bindings,
Exports,
"src/bun.js/bindings/bindings.zig",
);
- HeaderGenerator.exec(HeaderGenerator{}, file, cpp, static, staticInlines);
+ HeaderGenerator.exec(HeaderGenerator{}, file, cpp, generated);
}
// TODO: finish this
const use_cpp_generator = false;
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index a50527bdf..86ba683a8 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -73,15 +73,24 @@
#include "JSDOMOperation.h"
#include "JSDOMWrapperCache.h"
+#include "wtf/text/AtomString.h"
+#include "HTTPHeaderNames.h"
+#include "JSDOMPromiseDeferred.h"
+
template<typename UWSResponse>
static void copyToUWS(WebCore::FetchHeaders* headers, UWSResponse* res)
{
- auto iter = headers->createIterator();
- uint32_t i = 0;
- unsigned count = 0;
- for (auto pair = iter.next(); pair; pair = iter.next()) {
- auto name = pair->key;
- auto value = pair->value;
+ auto& internalHeaders = headers->internalHeaders();
+
+ for (auto& header : internalHeaders.commonHeaders()) {
+ const auto& name = WebCore::httpHeaderNameString(header.key);
+ auto& value = header.value;
+ res->writeHeader(std::string_view(reinterpret_cast<const char*>(name.characters8()), name.length()), std::string_view(reinterpret_cast<const char*>(value.characters8()), value.length()));
+ }
+
+ for (auto& header : internalHeaders.uncommonHeaders()) {
+ auto& name = header.key;
+ auto& value = header.value;
res->writeHeader(std::string_view(reinterpret_cast<const char*>(name.characters8()), name.length()), std::string_view(reinterpret_cast<const char*>(value.characters8()), value.length()));
}
}
@@ -176,6 +185,11 @@ WebCore__FetchHeaders* WebCore__FetchHeaders__cloneThis(WebCore__FetchHeaders* h
return clone.leakRef();
}
+bool WebCore__FetchHeaders__fastHas_(WebCore__FetchHeaders* arg0, unsigned char HTTPHeaderName1)
+{
+ return arg0->fastHas(static_cast<HTTPHeaderName>(HTTPHeaderName1));
+}
+
void WebCore__FetchHeaders__copyTo(WebCore__FetchHeaders* headers, StringPointer* names, StringPointer* values, unsigned char* buf)
{
auto iter = headers->createIterator();
@@ -237,17 +251,53 @@ WebCore::FetchHeaders* WebCore__FetchHeaders__createFromPicoHeaders_(JSC__JSGlob
WebCore::FetchHeaders* WebCore__FetchHeaders__createFromUWS(JSC__JSGlobalObject* arg0, void* arg1)
{
uWS::HttpRequest req = *reinterpret_cast<uWS::HttpRequest*>(arg1);
- Vector<KeyValuePair<String, String>> pairs;
- pairs.reserveCapacity(55);
+ std::bitset<255> seenHeaderSizes;
+ // uWebSockets limits to 50 headers
+ uint32_t nameHashes[55];
+ size_t i = 0;
+
+ RefPtr<WebCore::FetchHeaders> headers = adoptRef(*new WebCore::FetchHeaders({ WebCore::FetchHeaders::Guard::None, {} }));
+ HTTPHeaderMap map = HTTPHeaderMap();
+
for (const auto& header : req) {
- auto name = WTF::String(reinterpret_cast<const LChar*>(header.first.data()), header.first.length());
- auto value = WTF::String(reinterpret_cast<const LChar*>(header.second.data()), header.second.length());
- pairs.uncheckedAppend(KeyValuePair<String, String>(name, value));
+ StringView nameView = StringView(reinterpret_cast<const LChar*>(header.first.data()), header.first.length());
+
+ uint32_t hash = nameView.hash();
+ nameHashes[i++] = hash;
+ size_t name_len = nameView.length();
+ auto value = WTF::StringView(reinterpret_cast<const LChar*>(header.second.data()), header.second.length()).toStringWithoutCopying().isolatedCopy();
+
+ if (name_len < 255) {
+ if (seenHeaderSizes[name_len]) {
+ bool found = false;
+ for (size_t j = 0; j < i; j++) {
+ if (nameHashes[j] == hash) {
+ map.add(nameView.toString(), WTF::String(WTF::StringImpl::createWithoutCopying(header.second.data(), header.second.length())));
+ found = true;
+ break;
+ }
+ }
+
+ if (found)
+ continue;
+ } else {
+ seenHeaderSizes.set(name_len);
+ }
+ } else {
+ map.add(nameView.toString(), value);
+ continue;
+ }
+
+ HTTPHeaderName name;
+
+ if (WebCore::findHTTPHeaderName(nameView, name)) {
+ map.add(name, value);
+ } else {
+ map.setUncommonHeader(nameView.toString().isolatedCopy(), value);
+ }
}
- RefPtr<WebCore::FetchHeaders> headers = adoptRef(*new WebCore::FetchHeaders({ WebCore::FetchHeaders::Guard::None, {} }));
- headers->fill(WebCore::FetchHeaders::Init(WTFMove(pairs)));
- pairs.releaseBuffer();
+ headers->setInternalHeaders(WTFMove(map));
return headers.leakRef();
}
void WebCore__FetchHeaders__deref(WebCore__FetchHeaders* arg0)
@@ -289,6 +339,21 @@ void WebCore__FetchHeaders__remove(WebCore__FetchHeaders* headers, const ZigStri
headers->remove(Zig::toString(*arg1));
}
+void WebCore__FetchHeaders__fastRemove_(WebCore__FetchHeaders* headers, unsigned char headerName)
+{
+ headers->fastRemove(static_cast<WebCore::HTTPHeaderName>(headerName));
+}
+
+void WebCore__FetchHeaders__fastGet_(WebCore__FetchHeaders* headers, unsigned char headerName, ZigString* arg2)
+{
+ auto str = headers->fastGet(static_cast<WebCore::HTTPHeaderName>(headerName));
+ if (!str) {
+ return;
+ }
+
+ *arg2 = Zig::toZigString(str);
+}
+
WebCore__DOMURL* WebCore__DOMURL__cast_(JSC__JSValue JSValue0, JSC::VM* vm)
{
return WebCoreCast<WebCore::JSDOMURL, WebCore__DOMURL>(JSValue0);
@@ -1385,7 +1450,13 @@ void JSC__JSPromise__resolve(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1,
}
JSC__JSPromise* JSC__JSPromise__resolvedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1)
{
- return JSC::JSPromise::resolvedPromise(arg0, JSC::JSValue::decode(JSValue1));
+ Zig::GlobalObject* global = reinterpret_cast<Zig::GlobalObject*>(arg0);
+ JSC::JSPromise* promise = JSC::JSPromise::create(arg0->vm(), arg0->promiseStructure());
+ promise->internalField(JSC::JSPromise::Field::Flags).set(arg0->vm(), promise, jsNumber(static_cast<unsigned>(JSC::JSPromise::Status::Fulfilled)));
+ promise->internalField(JSC::JSPromise::Field::ReactionsOrResult).set(arg0->vm(), promise, JSC::JSValue::decode(JSValue1));
+ JSC::ensureStillAliveHere(promise);
+ JSC::ensureStillAliveHere(JSC::JSValue::decode(JSValue1));
+ return promise;
}
JSC__JSValue JSC__JSPromise__result(const JSC__JSPromise* arg0, JSC__VM* arg1)
@@ -3004,14 +3075,24 @@ void WTF__URL__setUser(WTF__URL* arg0, bWTF__StringView arg1)
JSC__JSValue JSC__JSPromise__rejectedPromiseValue(JSC__JSGlobalObject* arg0,
JSC__JSValue JSValue1)
{
- return JSC::JSValue::encode(
- JSC::JSPromise::rejectedPromise(arg0, JSC::JSValue::decode(JSValue1)));
+ Zig::GlobalObject* global = reinterpret_cast<Zig::GlobalObject*>(arg0);
+ JSC::JSPromise* promise = JSC::JSPromise::create(arg0->vm(), arg0->promiseStructure());
+ promise->internalField(JSC::JSPromise::Field::Flags).set(arg0->vm(), promise, jsNumber(static_cast<unsigned>(JSC::JSPromise::Status::Rejected)));
+ promise->internalField(JSC::JSPromise::Field::ReactionsOrResult).set(arg0->vm(), promise, JSC::JSValue::decode(JSValue1));
+ JSC::ensureStillAliveHere(promise);
+ JSC::ensureStillAliveHere(JSC::JSValue::decode(JSValue1));
+ return JSC::JSValue::encode(promise);
}
JSC__JSValue JSC__JSPromise__resolvedPromiseValue(JSC__JSGlobalObject* arg0,
JSC__JSValue JSValue1)
{
- return JSC::JSValue::encode(
- JSC::JSPromise::resolvedPromise(arg0, JSC::JSValue::decode(JSValue1)));
+ Zig::GlobalObject* global = reinterpret_cast<Zig::GlobalObject*>(arg0);
+ JSC::JSPromise* promise = JSC::JSPromise::create(arg0->vm(), arg0->promiseStructure());
+ promise->internalField(JSC::JSPromise::Field::Flags).set(arg0->vm(), promise, jsNumber(static_cast<unsigned>(JSC::JSPromise::Status::Fulfilled)));
+ promise->internalField(JSC::JSPromise::Field::ReactionsOrResult).set(arg0->vm(), promise, JSC::JSValue::decode(JSValue1));
+ JSC::ensureStillAliveHere(promise);
+ JSC::ensureStillAliveHere(JSC::JSValue::decode(JSValue1));
+ return JSC::JSValue::encode(promise);
}
}
@@ -3020,3 +3101,44 @@ JSC__JSValue JSC__JSValue__createUninitializedUint8Array(JSC__JSGlobalObject* ar
JSC::JSValue value = JSC::JSUint8Array::createUninitialized(arg0, arg0->m_typedArrayUint8.get(arg0), arg1);
return JSC::JSValue::encode(value);
}
+
+enum class BuiltinNamesMap : uint8_t {
+ method,
+ headers,
+ status,
+ url,
+ body,
+};
+
+static JSC::Identifier builtinNameMap(JSC::JSGlobalObject* globalObject, unsigned char name)
+{
+ auto clientData = WebCore::clientData(globalObject->vm());
+ switch (static_cast<BuiltinNamesMap>(name)) {
+ case BuiltinNamesMap::method: {
+ return clientData->builtinNames().methodPublicName();
+ }
+ case BuiltinNamesMap::headers: {
+ return clientData->builtinNames().headersPublicName();
+ }
+ case BuiltinNamesMap::status: {
+ return clientData->builtinNames().statusPublicName();
+ }
+ case BuiltinNamesMap::url: {
+ return clientData->builtinNames().urlPublicName();
+ }
+ case BuiltinNamesMap::body: {
+ return clientData->builtinNames().bodyPublicName();
+ }
+ }
+}
+
+JSC__JSValue JSC__JSValue__fastGet_(JSC__JSValue JSValue0, JSC__JSGlobalObject* globalObject, unsigned char arg2)
+{
+ JSC::JSValue value = JSC::JSValue::decode(JSValue0);
+ if (!value.isCell()) {
+ return JSC::JSValue::encode(JSC::jsUndefined());
+ }
+
+ return JSValue::encode(
+ value.getObject()->getIfPropertyExists(globalObject, builtinNameMap(globalObject, arg2)));
+} \ No newline at end of file
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 8a131efe6..05d220da9 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -728,6 +728,161 @@ pub const FetchHeaders = opaque {
});
}
+ pub fn fastHas(
+ this: *FetchHeaders,
+ name_: HTTPHeaderName,
+ ) bool {
+ return fastHas_(this, @enumToInt(name_));
+ }
+
+ pub fn fastGet(
+ this: *FetchHeaders,
+ name_: HTTPHeaderName,
+ ) ?ZigString {
+ var str = ZigString.init("");
+ fastGet_(this, @enumToInt(name_), &str);
+ if (str.len == 0) {
+ return null;
+ }
+
+ return str;
+ }
+
+ pub fn fastHas_(
+ this: *FetchHeaders,
+ name_: u8,
+ ) bool {
+ return shim.cppFn("fastHas_", .{
+ this,
+ name_,
+ });
+ }
+
+ pub fn fastGet_(
+ this: *FetchHeaders,
+ name_: u8,
+ str: *ZigString,
+ ) void {
+ return shim.cppFn("fastGet_", .{
+ this,
+ name_,
+ str,
+ });
+ }
+
+ pub const HTTPHeaderName = enum(u8) {
+ Accept,
+ AcceptCharset,
+ AcceptEncoding,
+ AcceptLanguage,
+ AcceptRanges,
+ AccessControlAllowCredentials,
+ AccessControlAllowHeaders,
+ AccessControlAllowMethods,
+ AccessControlAllowOrigin,
+ AccessControlExposeHeaders,
+ AccessControlMaxAge,
+ AccessControlRequestHeaders,
+ AccessControlRequestMethod,
+ Age,
+ Authorization,
+ CacheControl,
+ Connection,
+ ContentDisposition,
+ ContentEncoding,
+ ContentLanguage,
+ ContentLength,
+ ContentLocation,
+ ContentRange,
+ ContentSecurityPolicy,
+ ContentSecurityPolicyReportOnly,
+ ContentType,
+ Cookie,
+ Cookie2,
+ CrossOriginEmbedderPolicy,
+ CrossOriginEmbedderPolicyReportOnly,
+ CrossOriginOpenerPolicy,
+ CrossOriginOpenerPolicyReportOnly,
+ CrossOriginResourcePolicy,
+ DNT,
+ Date,
+ DefaultStyle,
+ ETag,
+ Expect,
+ Expires,
+ Host,
+ IcyMetaInt,
+ IcyMetadata,
+ IfMatch,
+ IfModifiedSince,
+ IfNoneMatch,
+ IfRange,
+ IfUnmodifiedSince,
+ KeepAlive,
+ LastEventID,
+ LastModified,
+ Link,
+ Location,
+ Origin,
+ PingFrom,
+ PingTo,
+ Pragma,
+ ProxyAuthorization,
+ Purpose,
+ Range,
+ Referer,
+ ReferrerPolicy,
+ Refresh,
+ ReportTo,
+ SecFetchDest,
+ SecFetchMode,
+ SecWebSocketAccept,
+ SecWebSocketExtensions,
+ SecWebSocketKey,
+ SecWebSocketProtocol,
+ SecWebSocketVersion,
+ ServerTiming,
+ ServiceWorker,
+ ServiceWorkerAllowed,
+ ServiceWorkerNavigationPreload,
+ SetCookie,
+ SetCookie2,
+ SourceMap,
+ StrictTransportSecurity,
+ TE,
+ TimingAllowOrigin,
+ Trailer,
+ TransferEncoding,
+ Upgrade,
+ UpgradeInsecureRequests,
+ UserAgent,
+ Vary,
+ Via,
+ XContentTypeOptions,
+ XDNSPrefetchControl,
+ XFrameOptions,
+ XSourceMap,
+ XTempTablet,
+ XXSSProtection,
+ };
+
+ pub fn fastRemove(
+ this: *FetchHeaders,
+ header: HTTPHeaderName,
+ ) void {
+ return fastRemove_(this, @enumToInt(header));
+ }
+
+ pub fn fastRemove_(
+ this: *FetchHeaders,
+ header: u8,
+ ) void {
+ return shim.cppFn("fastRemove_", .{
+ this,
+ header,
+ });
+ }
+
pub fn remove(
this: *FetchHeaders,
name_: *const ZigString,
@@ -803,6 +958,9 @@ pub const FetchHeaders = opaque {
}
pub const Extern = [_][]const u8{
+ "fastRemove_",
+ "fastGet_",
+ "fastHas_",
"append",
"cast_",
"clone",
@@ -1602,6 +1760,15 @@ pub const JSGlobalObject = extern struct {
pub const name = "JSC::JSGlobalObject";
pub const namespace = "JSC";
+ pub fn throwInvalidArguments(
+ this: *JSGlobalObject,
+ comptime fmt: string,
+ args: anytype,
+ ) void {
+ var err = JSC.toInvalidArguments(fmt, args, this);
+ this.vm().throwError(this, err);
+ }
+
// pub fn createError(globalObject: *JSGlobalObject, error_type: ErrorType, message: *String) *JSObject {
// return cppFn("createError", .{ globalObject, error_type, message });
// }
@@ -1734,7 +1901,9 @@ pub const JSGlobalObject = extern struct {
// you most likely need to run
// make clean-jsc-bindings
// make bindings -j10
- std.debug.assert(this.bunVM_() == @ptrCast(*anyopaque, JSC.VirtualMachine.vm));
+ const assertion = this.bunVM_() == @ptrCast(*anyopaque, JSC.VirtualMachine.vm);
+ if (!assertion) @breakpoint();
+ std.debug.assert(assertion);
}
return @ptrCast(*JSC.VirtualMachine, @alignCast(std.meta.alignment(JSC.VirtualMachine), this.bunVM_()));
}
@@ -2188,6 +2357,8 @@ pub const JSValue = enum(JSValueReprInt) {
MaxJS = 0b11111111,
Event = 0b11101111,
+ DOMWrapper = 0b11101110,
+ Blob = 0b11111100,
_,
pub fn isObject(this: JSType) bool {
@@ -2396,6 +2567,10 @@ pub const JSValue = enum(JSValueReprInt) {
return FetchHeaders.cast(value);
}
+ if (comptime @hasDecl(ZigType, "fromJS") and @TypeOf(ZigType.fromJS) == fn (JSC.JSValue) ?*ZigType) {
+ return ZigType.fromJS(value);
+ }
+
return JSC.GetJSPrivateData(ZigType, value.asObjectRef());
}
@@ -2803,6 +2978,28 @@ pub const JSValue = enum(JSValueReprInt) {
return cppFn("eqlCell", .{ this, other });
}
+ pub const BuiltinName = enum(u8) {
+ method,
+ headers,
+ status,
+ url,
+ body,
+ };
+
+ // intended to be more lightweight than ZigString
+ pub fn fastGet(this: JSValue, global: *JSGlobalObject, builtin_name: BuiltinName) ?JSValue {
+ const result = fastGet_(this, global, @enumToInt(builtin_name));
+ if (result == .zero) {
+ return null;
+ }
+
+ return result;
+ }
+
+ pub fn fastGet_(this: JSValue, global: *JSGlobalObject, builtin_name: u8) JSValue {
+ return cppFn("fastGet_", .{ this, global, builtin_name });
+ }
+
// intended to be more lightweight than ZigString
pub fn getIfPropertyExistsImpl(this: JSValue, global: *JSGlobalObject, ptr: [*]const u8, len: u32) JSValue {
return cppFn("getIfPropertyExistsImpl", .{ this, global, ptr, len });
@@ -2834,12 +3031,12 @@ pub const JSValue = enum(JSValueReprInt) {
return zig_str;
}
- pub fn get(this: JSValue, global: *JSGlobalObject, property: []const u8) ?JSValue {
+ pub fn get(this: JSValue, global: *JSGlobalObject, comptime property: []const u8) ?JSValue {
const value = getIfPropertyExistsImpl(this, global, property.ptr, @intCast(u32, property.len));
return if (@enumToInt(value) != 0) value else return null;
}
- pub fn getTruthy(this: JSValue, global: *JSGlobalObject, property: []const u8) ?JSValue {
+ pub fn getTruthy(this: JSValue, global: *JSGlobalObject, comptime property: []const u8) ?JSValue {
if (get(this, global, property)) |prop| {
if (@enumToInt(prop) == 0 or prop.isUndefinedOrNull()) return null;
return prop;
@@ -3041,7 +3238,7 @@ pub const JSValue = enum(JSValueReprInt) {
return this.asNullableVoid().?;
}
- pub const Extern = [_][]const u8{ "createUninitializedUint8Array", "fromInt64NoTruncate", "fromUInt64NoTruncate", "toUInt64NoTruncate", "asPromise", "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
+ pub const Extern = [_][]const u8{ "fastGet_", "getStaticProperty", "createUninitializedUint8Array", "fromInt64NoTruncate", "fromUInt64NoTruncate", "toUInt64NoTruncate", "asPromise", "toInt64", "_then", "put", "makeWithNameAndPrototype", "parseJSON", "symbolKeyFor", "symbolFor", "getSymbolDescription", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt64", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
};
extern "c" fn Microtask__run(*Microtask, *JSGlobalObject) void;
@@ -3357,23 +3554,59 @@ pub const CallFrame = opaque {
/// The value is 6.
/// On ARM64_32, the value is something else but it really doesn't matter for our case
/// However, I don't want this to subtly break amidst future upgrades to JavaScriptCore
- const arguments_offset = 6;
- const thisValue_offset = arguments_offset - 1;
- const argumentsCount_offset = thisValue_offset - 1;
- const alignment = std.meta.alignment([]const JSC.JSValue);
+ const alignment = Sizes.Bun_CallFrame__align;
pub const name = "JSC::CallFrame";
pub fn argumentsPtr(self: *const CallFrame) [*]const JSC.JSValue {
- return @ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + arguments_offset;
+ return @ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__firstArgument;
}
pub fn callee(self: *const CallFrame) JSC.JSValue {
- return (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + arguments_offset - 1)[0];
+ return (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__callee)[0];
}
- pub fn arguments(self: *const CallFrame) []const JSC.JSValue {
- return self.argumentsPtr()[0..self.argumentsCount()];
+ pub fn arguments(self: *const CallFrame, comptime max: usize) struct { ptr: [max]JSC.JSValue, len: usize } {
+ var buf: [max]JSC.JSValue = std.mem.zeroes([max]JSC.JSValue);
+ const len = self.argumentsCount();
+ var ptr = self.argumentsPtr();
+ switch (len) {
+ 0 => {
+ return .{ .ptr = buf, .len = 0 };
+ },
+ 1 => {
+ buf[0..1].* = ptr[0..1].*;
+ return .{ .ptr = buf, .len = 1 };
+ },
+ 2 => {
+ buf[0..2].* = ptr[0..2].*;
+ return .{ .ptr = buf, .len = 2 };
+ },
+ 3 => {
+ buf[0..3].* = ptr[0..3].*;
+ return .{ .ptr = buf, .len = 3 };
+ },
+ 4 => {
+ buf[0..4].* = ptr[0..4].*;
+ return .{ .ptr = buf, .len = 4 };
+ },
+ 5 => {
+ buf[0..5].* = ptr[0..5].*;
+ return .{ .ptr = buf, .len = 5 };
+ },
+ 6 => {
+ buf[0..6].* = ptr[0..6].*;
+ return .{ .ptr = buf, .len = 6 };
+ },
+ 7 => {
+ buf[0..7].* = ptr[0..7].*;
+ return .{ .ptr = buf, .len = 7 };
+ },
+ else => {
+ buf[0..8].* = ptr[0..8].*;
+ return .{ .ptr = buf, .len = 8 };
+ },
+ }
}
pub fn argument(self: *const CallFrame, comptime i: comptime_int) JSC.JSValue {
@@ -3381,11 +3614,11 @@ pub const CallFrame = opaque {
}
pub fn this(self: *const CallFrame) JSC.JSValue {
- return (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + thisValue_offset)[0];
+ return (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__thisArgument)[0];
}
pub fn argumentsCount(self: *const CallFrame) usize {
- return (@ptrCast([*]const usize, @alignCast(alignment, self)) + argumentsCount_offset)[0];
+ return @intCast(usize, (@ptrCast([*]const JSC.JSValue, @alignCast(alignment, self)) + Sizes.Bun_CallFrame__argumentCountIncludingThis)[0].asInt32() - 1);
}
};
@@ -3759,7 +3992,8 @@ pub fn Thenable(comptime Then: type, comptime onResolve: fn (*Then, globalThis:
callframe: ?*JSC.CallFrame,
) callconv(.C) void {
@setRuntimeSafety(false);
- onResolve(@ptrCast(*Then, @alignCast(std.meta.alignment(Then), ctx.?)), globalThis, callframe.?.arguments());
+ const args_list = callframe.?.arguments(8);
+ onResolve(@ptrCast(*Then, @alignCast(std.meta.alignment(Then), ctx.?)), globalThis, args_list.ptr[0..args_list.len]);
}
pub fn reject(
@@ -3768,7 +4002,8 @@ pub fn Thenable(comptime Then: type, comptime onResolve: fn (*Then, globalThis:
callframe: ?*JSC.CallFrame,
) callconv(.C) void {
@setRuntimeSafety(false);
- onReject(@ptrCast(*Then, @alignCast(std.meta.alignment(Then), ctx.?)), globalThis, callframe.?.arguments());
+ const args_list = callframe.?.arguments(8);
+ onReject(@ptrCast(*Then, @alignCast(std.meta.alignment(Then), ctx.?)), globalThis, args_list.ptr[0..args_list.len]);
}
pub fn then(ctx: *Then, this: JSValue, globalThis: *JSGlobalObject) void {
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index e824c877f..5ff264f01 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -1268,12 +1268,12 @@ pub const ZigConsoleClient = struct {
return .{
.tag = .Boolean,
};
- } else if (value.isSymbol()) {
+ }
+
+ if (!value.isCell())
return .{
- .tag = .Symbol,
- .cell = .Symbol,
+ .tag = .NativeCode,
};
- }
const js_type = value.jsType();
@@ -1291,6 +1291,13 @@ pub const ZigConsoleClient = struct {
};
}
+ if (js_type == .DOMWrapper) {
+ return .{
+ .tag = .Private,
+ .cell = js_type,
+ };
+ }
+
if (CAPI.JSObjectGetPrivate(value.asObjectRef()) != null)
return .{
.tag = .Private,
@@ -1771,39 +1778,36 @@ pub const ZigConsoleClient = struct {
writer.writeAll(" ]");
},
.Private => {
- if (CAPI.JSObjectGetPrivate(value.asRef())) |private_data_ptr| {
- const priv_data = JSPrivateDataPtr.from(private_data_ptr);
- switch (priv_data.tag()) {
- .BuildError => {
- const build_error = priv_data.as(JS.BuildError);
- build_error.msg.writeFormat(writer_, enable_ansi_colors) catch {};
- return;
- },
- .ResolveError => {
- const resolve_error = priv_data.as(JS.ResolveError);
- resolve_error.msg.writeFormat(writer_, enable_ansi_colors) catch {};
- return;
- },
- .Response => {
- var response = priv_data.as(JSC.WebCore.Response);
- response.writeFormat(this, writer_, enable_ansi_colors) catch {};
- return;
- },
- .Request => {
- var request = priv_data.as(JSC.WebCore.Request);
- request.writeFormat(this, writer_, enable_ansi_colors) catch {};
- return;
- },
- .Blob => {
- var request = priv_data.as(JSC.WebCore.Blob);
- request.writeFormat(this, writer_, enable_ansi_colors) catch {};
- return;
- },
- else => {},
+ if (value.as(JSC.WebCore.Response)) |response| {
+ response.writeFormat(this, writer_, enable_ansi_colors) catch {};
+ return;
+ } else if (value.as(JSC.WebCore.Request)) |request| {
+ request.writeFormat(this, writer_, enable_ansi_colors) catch {};
+ return;
+ } else if (jsType != .DOMWrapper) {
+ if (CAPI.JSObjectGetPrivate(value.asRef())) |private_data_ptr| {
+ const priv_data = JSPrivateDataPtr.from(private_data_ptr);
+ switch (priv_data.tag()) {
+ .BuildError => {
+ const build_error = priv_data.as(JS.BuildError);
+ build_error.msg.writeFormat(writer_, enable_ansi_colors) catch {};
+ return;
+ },
+ .ResolveError => {
+ const resolve_error = priv_data.as(JS.ResolveError);
+ resolve_error.msg.writeFormat(writer_, enable_ansi_colors) catch {};
+ return;
+ },
+ .Blob => {
+ var request = priv_data.as(JSC.WebCore.Blob);
+ request.writeFormat(this, writer_, enable_ansi_colors) catch {};
+ return;
+ },
+ else => {},
+ }
}
}
-
- writer.writeAll("[native code]");
+ return this.printAs(.Object, Writer, writer_, value, .Event, enable_ansi_colors);
},
.NativeCode => {
writer.writeAll("[native code]");
diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig
new file mode 100644
index 000000000..700d1e53d
--- /dev/null
+++ b/src/bun.js/bindings/generated_classes.zig
@@ -0,0 +1,297 @@
+
+const JSC = @import("javascript_core");
+const Classes = @import("./generated_classes_list.zig").Classes;
+const Environment = @import("../../env.zig");
+const std = @import("std");
+
+const StaticGetterType = fn(*JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+const StaticSetterType = fn(*JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+const StaticCallbackType = fn(*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+
+
+
+pub const JSRequest = struct {
+ const Request = Classes.Request;
+ const GetterType = fn(*Request, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const SetterType = fn(*Request, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const CallbackType = fn(*Request, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+
+ /// Return the pointer to the wrapped object.
+ /// If the object does not match the type, return null.
+ pub fn fromJS(value: JSC.JSValue) ?*Request {
+ JSC.markBinding();
+ return Request__fromJS(value);
+ }
+
+ /// Create a new instance of Request
+ pub fn toJS(this: *Request, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ JSC.markBinding();
+ if (comptime Environment.allow_assert) {
+ const value__ = Request__create(globalObject, this);
+ std.debug.assert(value__.as(Request).? == this); // If this fails, likely a C ABI issue.
+ return value__;
+ } else {
+ return Request__create(globalObject, this);
+ }
+ }
+
+ /// Modify the internal ptr to point to a new instance of Request.
+ pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*Request) bool {
+ JSC.markBinding();
+ return Request__dangerouslySetPtr(value, ptr);
+ }
+
+ extern fn Request__fromJS(JSC.JSValue) ?*Request;
+
+ extern fn Request__create(globalObject: *JSC.JSGlobalObject, ptr: ?*Request) JSC.JSValue;
+
+ extern fn Request__dangerouslySetPtr(JSC.JSValue, ?*Request) bool;
+
+ comptime {
+
+ if (@TypeOf(Request.constructor) != (fn(*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*Request)) {
+ @compileLog("Request.constructor is not a constructor");
+ }
+
+ if (@TypeOf(Request.finalize) != (fn(*Request) callconv(.C) void)) {
+ @compileLog("Request.finalize is not a finalizer");
+ }
+
+ if (@TypeOf(Request.getArrayBuffer) != CallbackType)
+ @compileLog(
+ "Expected Request.getArrayBuffer to be a callback"
+ );
+ if (@TypeOf(Request.getBlob) != CallbackType)
+ @compileLog(
+ "Expected Request.getBlob to be a callback"
+ );
+ if (@TypeOf(Request.getBodyUsed) != GetterType)
+ @compileLog(
+ "Expected Request.getBodyUsed to be a getter"
+ );
+
+ if (@TypeOf(Request.getCache) != GetterType)
+ @compileLog(
+ "Expected Request.getCache to be a getter"
+ );
+
+ if (@TypeOf(Request.doClone) != CallbackType)
+ @compileLog(
+ "Expected Request.doClone to be a callback"
+ );
+ if (@TypeOf(Request.getCredentials) != GetterType)
+ @compileLog(
+ "Expected Request.getCredentials to be a getter"
+ );
+
+ if (@TypeOf(Request.getDestination) != GetterType)
+ @compileLog(
+ "Expected Request.getDestination to be a getter"
+ );
+
+ if (@TypeOf(Request.getHeaders) != GetterType)
+ @compileLog(
+ "Expected Request.getHeaders to be a getter"
+ );
+
+ if (@TypeOf(Request.getIntegrity) != GetterType)
+ @compileLog(
+ "Expected Request.getIntegrity to be a getter"
+ );
+
+ if (@TypeOf(Request.getJSON) != CallbackType)
+ @compileLog(
+ "Expected Request.getJSON to be a callback"
+ );
+ if (@TypeOf(Request.getMethod) != GetterType)
+ @compileLog(
+ "Expected Request.getMethod to be a getter"
+ );
+
+ if (@TypeOf(Request.getMode) != GetterType)
+ @compileLog(
+ "Expected Request.getMode to be a getter"
+ );
+
+ if (@TypeOf(Request.getRedirect) != GetterType)
+ @compileLog(
+ "Expected Request.getRedirect to be a getter"
+ );
+
+ if (@TypeOf(Request.getReferrer) != GetterType)
+ @compileLog(
+ "Expected Request.getReferrer to be a getter"
+ );
+
+ if (@TypeOf(Request.getReferrerPolicy) != GetterType)
+ @compileLog(
+ "Expected Request.getReferrerPolicy to be a getter"
+ );
+
+ if (@TypeOf(Request.getText) != CallbackType)
+ @compileLog(
+ "Expected Request.getText to be a callback"
+ );
+ if (@TypeOf(Request.getUrl) != GetterType)
+ @compileLog(
+ "Expected Request.getUrl to be a getter"
+ );
+
+ if (!JSC.is_bindgen) {
+@export(Request.constructor, .{.name = "RequestClass__construct"});
+ @export(Request.doClone, .{.name = "RequestPrototype__doClone"});
+ @export(Request.finalize, .{.name = "RequestClass__finalize"});
+ @export(Request.getArrayBuffer, .{.name = "RequestPrototype__getArrayBuffer"});
+ @export(Request.getBlob, .{.name = "RequestPrototype__getBlob"});
+ @export(Request.getBodyUsed, .{.name = "RequestPrototype__getBodyUsed"});
+ @export(Request.getCache, .{.name = "RequestPrototype__getCache"});
+ @export(Request.getCredentials, .{.name = "RequestPrototype__getCredentials"});
+ @export(Request.getDestination, .{.name = "RequestPrototype__getDestination"});
+ @export(Request.getHeaders, .{.name = "RequestPrototype__getHeaders"});
+ @export(Request.getIntegrity, .{.name = "RequestPrototype__getIntegrity"});
+ @export(Request.getJSON, .{.name = "RequestPrototype__getJSON"});
+ @export(Request.getMethod, .{.name = "RequestPrototype__getMethod"});
+ @export(Request.getMode, .{.name = "RequestPrototype__getMode"});
+ @export(Request.getRedirect, .{.name = "RequestPrototype__getRedirect"});
+ @export(Request.getReferrer, .{.name = "RequestPrototype__getReferrer"});
+ @export(Request.getReferrerPolicy, .{.name = "RequestPrototype__getReferrerPolicy"});
+ @export(Request.getText, .{.name = "RequestPrototype__getText"});
+ @export(Request.getUrl, .{.name = "RequestPrototype__getUrl"});
+ }
+ }
+};
+pub const JSResponse = struct {
+ const Response = Classes.Response;
+ const GetterType = fn(*Response, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const SetterType = fn(*Response, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const CallbackType = fn(*Response, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+
+ /// Return the pointer to the wrapped object.
+ /// If the object does not match the type, return null.
+ pub fn fromJS(value: JSC.JSValue) ?*Response {
+ JSC.markBinding();
+ return Response__fromJS(value);
+ }
+
+ /// Create a new instance of Response
+ pub fn toJS(this: *Response, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ JSC.markBinding();
+ if (comptime Environment.allow_assert) {
+ const value__ = Response__create(globalObject, this);
+ std.debug.assert(value__.as(Response).? == this); // If this fails, likely a C ABI issue.
+ return value__;
+ } else {
+ return Response__create(globalObject, this);
+ }
+ }
+
+ /// Modify the internal ptr to point to a new instance of Response.
+ pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*Response) bool {
+ JSC.markBinding();
+ return Response__dangerouslySetPtr(value, ptr);
+ }
+
+ extern fn Response__fromJS(JSC.JSValue) ?*Response;
+
+ extern fn Response__create(globalObject: *JSC.JSGlobalObject, ptr: ?*Response) JSC.JSValue;
+
+ extern fn Response__dangerouslySetPtr(JSC.JSValue, ?*Response) bool;
+
+ comptime {
+
+ if (@TypeOf(Response.constructor) != (fn(*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*Response)) {
+ @compileLog("Response.constructor is not a constructor");
+ }
+
+ if (@TypeOf(Response.finalize) != (fn(*Response) callconv(.C) void)) {
+ @compileLog("Response.finalize is not a finalizer");
+ }
+
+ if (@TypeOf(Response.getArrayBuffer) != CallbackType)
+ @compileLog(
+ "Expected Response.getArrayBuffer to be a callback"
+ );
+ if (@TypeOf(Response.getBlob) != CallbackType)
+ @compileLog(
+ "Expected Response.getBlob to be a callback"
+ );
+ if (@TypeOf(Response.getBodyUsed) != GetterType)
+ @compileLog(
+ "Expected Response.getBodyUsed to be a getter"
+ );
+
+ if (@TypeOf(Response.doClone) != CallbackType)
+ @compileLog(
+ "Expected Response.doClone to be a callback"
+ );
+ if (@TypeOf(Response.getHeaders) != GetterType)
+ @compileLog(
+ "Expected Response.getHeaders to be a getter"
+ );
+
+ if (@TypeOf(Response.getJSON) != CallbackType)
+ @compileLog(
+ "Expected Response.getJSON to be a callback"
+ );
+ if (@TypeOf(Response.getOK) != GetterType)
+ @compileLog(
+ "Expected Response.getOK to be a getter"
+ );
+
+ if (@TypeOf(Response.getStatus) != GetterType)
+ @compileLog(
+ "Expected Response.getStatus to be a getter"
+ );
+
+ if (@TypeOf(Response.getStatusText) != GetterType)
+ @compileLog(
+ "Expected Response.getStatusText to be a getter"
+ );
+
+ if (@TypeOf(Response.getText) != CallbackType)
+ @compileLog(
+ "Expected Response.getText to be a callback"
+ );
+ if (@TypeOf(Response.getResponseType) != GetterType)
+ @compileLog(
+ "Expected Response.getResponseType to be a getter"
+ );
+
+ if (@TypeOf(Response.getURL) != GetterType)
+ @compileLog(
+ "Expected Response.getURL to be a getter"
+ );
+
+ if (@TypeOf(Response.constructError) != StaticCallbackType)
+ @compileLog(
+ "Expected Response.constructError to be a static callback"
+ );
+ if (@TypeOf(Response.constructJSON) != StaticCallbackType)
+ @compileLog(
+ "Expected Response.constructJSON to be a static callback"
+ );
+ if (@TypeOf(Response.constructRedirect) != StaticCallbackType)
+ @compileLog(
+ "Expected Response.constructRedirect to be a static callback"
+ );
+ if (!JSC.is_bindgen) {
+@export(Response.constructError, .{.name = "ResponseClass__constructError"});
+ @export(Response.constructJSON, .{.name = "ResponseClass__constructJSON"});
+ @export(Response.constructor, .{.name = "ResponseClass__construct"});
+ @export(Response.constructRedirect, .{.name = "ResponseClass__constructRedirect"});
+ @export(Response.doClone, .{.name = "ResponsePrototype__doClone"});
+ @export(Response.finalize, .{.name = "ResponseClass__finalize"});
+ @export(Response.getArrayBuffer, .{.name = "ResponsePrototype__getArrayBuffer"});
+ @export(Response.getBlob, .{.name = "ResponsePrototype__getBlob"});
+ @export(Response.getBodyUsed, .{.name = "ResponsePrototype__getBodyUsed"});
+ @export(Response.getHeaders, .{.name = "ResponsePrototype__getHeaders"});
+ @export(Response.getJSON, .{.name = "ResponsePrototype__getJSON"});
+ @export(Response.getOK, .{.name = "ResponsePrototype__getOK"});
+ @export(Response.getResponseType, .{.name = "ResponsePrototype__getResponseType"});
+ @export(Response.getStatus, .{.name = "ResponsePrototype__getStatus"});
+ @export(Response.getStatusText, .{.name = "ResponsePrototype__getStatusText"});
+ @export(Response.getText, .{.name = "ResponsePrototype__getText"});
+ @export(Response.getURL, .{.name = "ResponsePrototype__getURL"});
+ }
+ }
+}; \ No newline at end of file
diff --git a/src/bun.js/bindings/generated_classes_list.zig b/src/bun.js/bindings/generated_classes_list.zig
new file mode 100644
index 000000000..4497fef10
--- /dev/null
+++ b/src/bun.js/bindings/generated_classes_list.zig
@@ -0,0 +1,6 @@
+const JSC = @import("javascript_core");
+
+pub const Classes = struct {
+ pub const Request = JSC.WebCore.Request;
+ pub const Response = JSC.WebCore.Response;
+};
diff --git a/src/bun.js/bindings/header-gen.zig b/src/bun.js/bindings/header-gen.zig
index 8e79dc5f9..6fb426a27 100644
--- a/src/bun.js/bindings/header-gen.zig
+++ b/src/bun.js/bindings/header-gen.zig
@@ -599,7 +599,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
}
}
- pub fn exec(comptime self: Self, file: std.fs.File, impl: std.fs.File, lazy_functions_header: std.fs.File, lazy_functions_impl: std.fs.File) void {
+ pub fn exec(comptime self: Self, file: std.fs.File, impl: std.fs.File, generated: std.fs.File) void {
const Generator = C_Generator;
validateGenerator(Generator);
var file_writer = file.writer();
@@ -655,7 +655,6 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
var impl_fourth_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
var impl_fourth_writer = impl_fourth_buffer.writer();
- var lazy_function_definitions_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
// var lazy_function_definitions_writer = lazy_function_definitions_buffer.writer();
var dom_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
@@ -910,34 +909,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
impl.writeAll("};\n") catch unreachable;
var iter = type_names.iterator();
- lazy_functions_header.writer().print(
- \\// GENERATED FILE
- \\#pragma once
- \\#include "root.h"
- \\
- \\namespace Zig {{
- \\ class GlobalObject;
- \\ class JSFFIFunction;
- \\
- \\ class LazyStaticFunctions {{
- \\ public:
- \\
- \\ void init(Zig::GlobalObject* globalObject);
- \\
- \\ template<typename Visitor>
- \\ void visit(Visitor& visitor);
- \\
- \\
- \\ /* -- BEGIN FUNCTION DEFINITIONS -- */
- \\ {s}
- \\ /* -- END FUNCTION DEFINITIONS-- */
- \\ }};
- \\
- \\}} // namespace Zig
- \\
- , .{lazy_function_definitions_buffer.items}) catch unreachable;
-
- lazy_functions_impl.writer().print(
+ generated.writer().print(
\\ #include "root.h"
\\
\\ #include <JavaScriptCore/DOMJITAbstractHeap.h>
diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h
index e422d4cb0..b466e1df2 100644
--- a/src/bun.js/bindings/headers.h
+++ b/src/bun.js/bindings/headers.h
@@ -1,5 +1,5 @@
// clang-format off
-//-- AUTOGENERATED FILE -- 1660480861
+//-- AUTOGENERATED FILE -- 1660746106
#pragma once
#include <stddef.h>
@@ -284,6 +284,9 @@ CPP_DECL WebCore__FetchHeaders* WebCore__FetchHeaders__createFromPicoHeaders_(JS
CPP_DECL WebCore__FetchHeaders* WebCore__FetchHeaders__createFromUWS(JSC__JSGlobalObject* arg0, void* arg1);
CPP_DECL JSC__JSValue WebCore__FetchHeaders__createValue(JSC__JSGlobalObject* arg0, StringPointer* arg1, StringPointer* arg2, const ZigString* arg3, uint32_t arg4);
CPP_DECL void WebCore__FetchHeaders__deref(WebCore__FetchHeaders* arg0);
+CPP_DECL void WebCore__FetchHeaders__fastGet_(WebCore__FetchHeaders* arg0, unsigned char arg1, ZigString* arg2);
+CPP_DECL bool WebCore__FetchHeaders__fastHas_(WebCore__FetchHeaders* arg0, unsigned char arg1);
+CPP_DECL void WebCore__FetchHeaders__fastRemove_(WebCore__FetchHeaders* arg0, unsigned char arg1);
CPP_DECL void WebCore__FetchHeaders__get_(WebCore__FetchHeaders* arg0, const ZigString* arg1, ZigString* arg2);
CPP_DECL bool WebCore__FetchHeaders__has(WebCore__FetchHeaders* arg0, const ZigString* arg1);
CPP_DECL void WebCore__FetchHeaders__put_(WebCore__FetchHeaders* arg0, const ZigString* arg1, const ZigString* arg2);
@@ -479,6 +482,7 @@ CPP_DECL JSC__JSValue JSC__JSValue__createTypeError(const ZigString* arg0, const
CPP_DECL JSC__JSValue JSC__JSValue__createUninitializedUint8Array(JSC__JSGlobalObject* arg0, size_t arg1);
CPP_DECL bool JSC__JSValue__eqlCell(JSC__JSValue JSValue0, JSC__JSCell* arg1);
CPP_DECL bool JSC__JSValue__eqlValue(JSC__JSValue JSValue0, JSC__JSValue JSValue1);
+CPP_DECL JSC__JSValue JSC__JSValue__fastGet_(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, unsigned char arg2);
CPP_DECL void JSC__JSValue__forEach(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, void* arg2, void (* ArgFn3)(JSC__VM* arg0, JSC__JSGlobalObject* arg1, void* arg2, JSC__JSValue JSValue3));
CPP_DECL JSC__JSValue JSC__JSValue__fromEntries(JSC__JSGlobalObject* arg0, ZigString* arg1, ZigString* arg2, size_t arg3, bool arg4);
CPP_DECL JSC__JSValue JSC__JSValue__fromInt64NoTruncate(JSC__JSGlobalObject* arg0, int64_t arg1);
diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig
index 1d563af37..6e197b8a0 100644
--- a/src/bun.js/bindings/headers.zig
+++ b/src/bun.js/bindings/headers.zig
@@ -120,6 +120,9 @@ pub extern fn WebCore__FetchHeaders__createFromPicoHeaders_(arg0: ?*JSC__JSGloba
pub extern fn WebCore__FetchHeaders__createFromUWS(arg0: ?*JSC__JSGlobalObject, arg1: ?*anyopaque) ?*bindings.FetchHeaders;
pub extern fn WebCore__FetchHeaders__createValue(arg0: ?*JSC__JSGlobalObject, arg1: [*c]StringPointer, arg2: [*c]StringPointer, arg3: [*c]const ZigString, arg4: u32) JSC__JSValue;
pub extern fn WebCore__FetchHeaders__deref(arg0: ?*bindings.FetchHeaders) void;
+pub extern fn WebCore__FetchHeaders__fastGet_(arg0: ?*bindings.FetchHeaders, arg1: u8, arg2: [*c]ZigString) void;
+pub extern fn WebCore__FetchHeaders__fastHas_(arg0: ?*bindings.FetchHeaders, arg1: u8) bool;
+pub extern fn WebCore__FetchHeaders__fastRemove_(arg0: ?*bindings.FetchHeaders, arg1: u8) void;
pub extern fn WebCore__FetchHeaders__get_(arg0: ?*bindings.FetchHeaders, arg1: [*c]const ZigString, arg2: [*c]ZigString) void;
pub extern fn WebCore__FetchHeaders__has(arg0: ?*bindings.FetchHeaders, arg1: [*c]const ZigString) bool;
pub extern fn WebCore__FetchHeaders__put_(arg0: ?*bindings.FetchHeaders, arg1: [*c]const ZigString, arg2: [*c]const ZigString) void;
@@ -272,6 +275,7 @@ pub extern fn JSC__JSValue__createTypeError(arg0: [*c]const ZigString, arg1: [*c
pub extern fn JSC__JSValue__createUninitializedUint8Array(arg0: ?*JSC__JSGlobalObject, arg1: usize) JSC__JSValue;
pub extern fn JSC__JSValue__eqlCell(JSValue0: JSC__JSValue, arg1: [*c]JSC__JSCell) bool;
pub extern fn JSC__JSValue__eqlValue(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) bool;
+pub extern fn JSC__JSValue__fastGet_(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: u8) JSC__JSValue;
pub extern fn JSC__JSValue__forEach(JSValue0: JSC__JSValue, arg1: ?*JSC__JSGlobalObject, arg2: ?*anyopaque, ArgFn3: ?fn ([*c]JSC__VM, ?*JSC__JSGlobalObject, ?*anyopaque, JSC__JSValue) callconv(.C) void) void;
pub extern fn JSC__JSValue__fromEntries(arg0: ?*JSC__JSGlobalObject, arg1: [*c]ZigString, arg2: [*c]ZigString, arg3: usize, arg4: bool) JSC__JSValue;
pub extern fn JSC__JSValue__fromInt64NoTruncate(arg0: ?*JSC__JSGlobalObject, arg1: i64) JSC__JSValue;
diff --git a/src/bun.js/bindings/sizes.zig b/src/bun.js/bindings/sizes.zig
index 385eec012..d63972fe4 100644
--- a/src/bun.js/bindings/sizes.zig
+++ b/src/bun.js/bindings/sizes.zig
@@ -1,4 +1,4 @@
-// Auto-generated by src/bun.js/headergen/sizegen.cpp at 2022-08-14 21:34:1660538097.
+// Auto-generated by src/bun.js/headergen/sizegen.cpp at 2022-08-17 02:46:1660729585.
// These are the byte sizes for the different object types with bindings in JavaScriptCore.
// This allows us to safely return stack allocated C++ types to Zig.
// It is only safe to do this when these sizes are correct.
@@ -67,8 +67,15 @@ pub const WTF__ExternalStringImpl = 40;
pub const WTF__ExternalStringImpl_align = 8;
pub const WTF__StringView = 16;
pub const WTF__StringView_align = 8;
-pub const Zig__GlobalObject = 4672;
+pub const Zig__GlobalObject = 4704;
pub const Zig__GlobalObject_align = 8;
pub const Bun_FFI_PointerOffsetToArgumentsList = 6;
pub const Bun_FFI_PointerOffsetToTypedArrayVector = 16;
pub const Bun_FFI_PointerOffsetToTypedArrayLength = 24;
+pub const Bun_CallFrame__codeBlock = 2;
+pub const Bun_CallFrame__callee = 3;
+pub const Bun_CallFrame__argumentCountIncludingThis = 4;
+pub const Bun_CallFrame__thisArgument = 5;
+pub const Bun_CallFrame__firstArgument = 6;
+pub const Bun_CallFrame__size = 8;
+pub const Bun_CallFrame__align = 8;
diff --git a/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h b/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h
index b437e5879..40b634220 100644
--- a/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h
+++ b/src/bun.js/bindings/webcore/DOMClientIsoSubspaces.h
@@ -25,6 +25,7 @@ public:
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSSinkConstructor;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSSinkController;
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForJSSink;
+#include "ZigGeneratedClasses+DOMClientIsoSubspaces.h"
/* --- bun --- */
std::unique_ptr<GCClient::IsoSubspace> m_clientSubspaceForDOMException;
diff --git a/src/bun.js/bindings/webcore/DOMIsoSubspaces.h b/src/bun.js/bindings/webcore/DOMIsoSubspaces.h
index 66b94e359..ddd488749 100644
--- a/src/bun.js/bindings/webcore/DOMIsoSubspaces.h
+++ b/src/bun.js/bindings/webcore/DOMIsoSubspaces.h
@@ -25,6 +25,7 @@ public:
std::unique_ptr<IsoSubspace> m_subspaceForJSSinkConstructor;
std::unique_ptr<IsoSubspace> m_subspaceForJSSinkController;
std::unique_ptr<IsoSubspace> m_subspaceForJSSink;
+#include "ZigGeneratedClasses+DOMIsoSubspaces.h"
/*-- BUN --*/
// std::unique_ptr<IsoSubspace> m_subspaceForTouch;
diff --git a/src/bun.js/bindings/webcore/FetchHeaders.cpp b/src/bun.js/bindings/webcore/FetchHeaders.cpp
index 26af08f1a..d4ecba216 100644
--- a/src/bun.js/bindings/webcore/FetchHeaders.cpp
+++ b/src/bun.js/bindings/webcore/FetchHeaders.cpp
@@ -67,13 +67,27 @@ static ExceptionOr<void> appendToHeaderMap(const String& name, const String& val
if (canWriteResult.hasException())
return canWriteResult.releaseException();
if (!canWriteResult.releaseReturnValue())
- return { };
+ return {};
headers.set(name, combinedValue);
- if (guard == FetchHeaders::Guard::RequestNoCors)
- removePrivilegedNoCORSRequestHeaders(headers);
+ // if (guard == FetchHeaders::Guard::RequestNoCors)
+ // removePrivilegedNoCORSRequestHeaders(headers);
- return { };
+ return {};
+}
+
+static void appendToHeaderMapFast(const String& name, const String& value, HTTPHeaderMap& headers, FetchHeaders::Guard guard)
+{
+ String combinedValue;
+ if (headers.contains(name)) {
+ combinedValue = makeString(headers.get(name), ", ", value);
+ } else {
+ combinedValue = value.isolatedCopy();
+ }
+
+ headers.append(name.isolatedCopy(), WTFMove(combinedValue));
+ // if (guard == FetchHeaders::Guard::RequestNoCors)
+ // removePrivilegedNoCORSRequestHeaders(headers);
}
static ExceptionOr<void> appendToHeaderMap(const HTTPHeaderMap::HTTPHeaderMapConstIterator::KeyValue& header, HTTPHeaderMap& headers, FetchHeaders::Guard guard)
@@ -83,16 +97,13 @@ static ExceptionOr<void> appendToHeaderMap(const HTTPHeaderMap::HTTPHeaderMapCon
if (canWriteResult.hasException())
return canWriteResult.releaseException();
if (!canWriteResult.releaseReturnValue())
- return { };
+ return {};
if (header.keyAsHTTPHeaderName)
headers.add(header.keyAsHTTPHeaderName.value(), header.value);
else
headers.add(header.key, header.value);
- if (guard == FetchHeaders::Guard::RequestNoCors)
- removePrivilegedNoCORSRequestHeaders(headers);
-
- return { };
+ return {};
}
// https://fetch.spec.whatwg.org/#concept-headers-fill
@@ -116,7 +127,7 @@ static ExceptionOr<void> fillHeaderMap(HTTPHeaderMap& headers, const FetchHeader
}
}
- return { };
+ return {};
}
ExceptionOr<Ref<FetchHeaders>> FetchHeaders::create(std::optional<Init>&& headersInit)
@@ -145,7 +156,7 @@ ExceptionOr<void> FetchHeaders::fill(const FetchHeaders& otherHeaders)
return result.releaseException();
}
- return { };
+ return {};
}
ExceptionOr<void> FetchHeaders::append(const String& name, const String& value)
@@ -161,18 +172,18 @@ ExceptionOr<void> FetchHeaders::remove(const String& name)
if (m_guard == FetchHeaders::Guard::Immutable)
return Exception { TypeError, "Headers object's guard is 'immutable'"_s };
if (m_guard == FetchHeaders::Guard::Request && isForbiddenHeaderName(name))
- return { };
+ return {};
if (m_guard == FetchHeaders::Guard::RequestNoCors && !isNoCORSSafelistedRequestHeaderName(name) && !isPriviledgedNoCORSRequestHeaderName(name))
- return { };
+ return {};
if (m_guard == FetchHeaders::Guard::Response && isForbiddenResponseHeaderName(name))
- return { };
+ return {};
m_headers.remove(name);
if (m_guard == FetchHeaders::Guard::RequestNoCors)
removePrivilegedNoCORSRequestHeaders(m_headers);
- return { };
+ return {};
}
ExceptionOr<String> FetchHeaders::get(const String& name) const
@@ -196,14 +207,14 @@ ExceptionOr<void> FetchHeaders::set(const String& name, const String& value)
if (canWriteResult.hasException())
return canWriteResult.releaseException();
if (!canWriteResult.releaseReturnValue())
- return { };
+ return {};
m_headers.set(name, normalizedValue);
if (m_guard == FetchHeaders::Guard::RequestNoCors)
removePrivilegedNoCORSRequestHeaders(m_headers);
- return { };
+ return {};
}
void FetchHeaders::filterAndFill(const HTTPHeaderMap& headers, Guard guard)
diff --git a/src/bun.js/bindings/webcore/FetchHeaders.h b/src/bun.js/bindings/webcore/FetchHeaders.h
index b116cf978..e0fc4a7ff 100644
--- a/src/bun.js/bindings/webcore/FetchHeaders.h
+++ b/src/bun.js/bindings/webcore/FetchHeaders.h
@@ -69,6 +69,7 @@ public:
String fastGet(HTTPHeaderName name) const { return m_headers.get(name); }
bool fastHas(HTTPHeaderName name) const { return m_headers.contains(name); }
+ bool fastRemove(HTTPHeaderName name) { return m_headers.remove(name); }
void fastSet(HTTPHeaderName name, const String& value) { m_headers.set(name, value); }
class Iterator {
diff --git a/src/bun.js/bindings/webcore/HTTPHeaderMap.h b/src/bun.js/bindings/webcore/HTTPHeaderMap.h
index 1fe19d311..e95c9d9f0 100644
--- a/src/bun.js/bindings/webcore/HTTPHeaderMap.h
+++ b/src/bun.js/bindings/webcore/HTTPHeaderMap.h
@@ -211,9 +211,9 @@ public:
template <class Encoder> void encode(Encoder&) const;
template <class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, HTTPHeaderMap&);
+ void setUncommonHeader(const String& name, const String& value);
private:
- void setUncommonHeader(const String& name, const String& value);
WEBCORE_EXPORT String getUncommonHeader(const String& name) const;
CommonHeadersVector m_commonHeaders;
diff --git a/src/bun.js/bindings/webcore/HTTPHeaderNames.cpp b/src/bun.js/bindings/webcore/HTTPHeaderNames.cpp
index 2846f15e5..f34a22f36 100644
--- a/src/bun.js/bindings/webcore/HTTPHeaderNames.cpp
+++ b/src/bun.js/bindings/webcore/HTTPHeaderNames.cpp
@@ -1,5 +1,5 @@
-/* C++ code produced by gperf version 3.0.3 */
-/* Command-line: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/gperf --key-positions='*' -D -n -s 2 --output-file=HTTPHeaderNames.cpp HTTPHeaderNames.gperf */
+/* C++ code produced by gperf version 3.1 */
+/* Command-line: /opt/homebrew/bin/gperf --key-positions='*' -D -n -s 2 --output-file=HTTPHeaderNames.cpp HTTPHeaderNames.gperf */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
@@ -25,7 +25,7 @@
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
-#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
+#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>."
#endif
#line 2 "HTTPHeaderNames.gperf"
@@ -150,6 +150,7 @@ static const struct HeaderNameString {
{ "Set-Cookie", 10 },
{ "Set-Cookie2", 11 },
{ "SourceMap", 9 },
+ { "Strict-Transport-Security", 25 },
{ "TE", 2 },
{ "Timing-Allow-Origin", 19 },
{ "Trailer", 7 },
@@ -168,21 +169,21 @@ static const struct HeaderNameString {
};
-#line 149 "HTTPHeaderNames.gperf"
+#line 150 "HTTPHeaderNames.gperf"
struct HeaderNameHashEntry {
const char* name;
HTTPHeaderName headerName;
};
enum
{
- TOTAL_KEYWORDS = 92,
+ TOTAL_KEYWORDS = 93,
MIN_WORD_LENGTH = 2,
MAX_WORD_LENGTH = 40,
MIN_HASH_VALUE = 5,
- MAX_HASH_VALUE = 815
+ MAX_HASH_VALUE = 709
};
-/* maximum key range = 811, duplicates = 0 */
+/* maximum key range = 705, duplicates = 0 */
#ifndef GPERF_DOWNCASE
#define GPERF_DOWNCASE 1
@@ -212,7 +213,7 @@ static unsigned char gperf_downcase[256] =
#ifndef GPERF_CASE_STRNCMP
#define GPERF_CASE_STRNCMP 1
static int
-gperf_case_strncmp (register const char *s1, register const char *s2, register unsigned int n)
+gperf_case_strncmp (const char *s1, const char *s2, size_t n)
{
for (; n > 0;)
{
@@ -232,166 +233,166 @@ gperf_case_strncmp (register const char *s1, register const char *s2, register u
class HTTPHeaderNamesHash
{
private:
- static inline unsigned int header_name_hash_function (const char *str, unsigned int len);
+ static inline unsigned int header_name_hash_function (const char *str, size_t len);
public:
- static const struct HeaderNameHashEntry *findHeaderNameImpl (const char *str, unsigned int len);
+ static const struct HeaderNameHashEntry *findHeaderNameImpl (const char *str, size_t len);
};
inline unsigned int
-HTTPHeaderNamesHash::header_name_hash_function (register const char *str, register unsigned int len)
+HTTPHeaderNamesHash::header_name_hash_function (const char *str, size_t len)
{
static const unsigned short asso_values[] =
{
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 0, 816, 816, 816, 816,
- 5, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 0, 40, 0, 115, 0,
- 120, 10, 155, 5, 816, 4, 45, 155, 5, 0,
- 30, 0, 5, 60, 5, 5, 135, 55, 50, 15,
- 60, 816, 816, 816, 816, 816, 816, 0, 40, 0,
- 115, 0, 120, 10, 155, 5, 816, 4, 45, 155,
- 5, 0, 30, 0, 5, 60, 5, 5, 135, 55,
- 50, 15, 60, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816, 816, 816, 816, 816,
- 816, 816, 816, 816, 816, 816
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 0, 710, 710, 710, 710,
+ 5, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 0, 35, 0, 95, 0,
+ 120, 10, 210, 5, 710, 4, 45, 115, 5, 0,
+ 30, 0, 5, 20, 5, 25, 195, 65, 115, 30,
+ 50, 710, 710, 710, 710, 710, 710, 0, 35, 0,
+ 95, 0, 120, 10, 210, 5, 710, 4, 45, 115,
+ 5, 0, 30, 0, 5, 20, 5, 25, 195, 65,
+ 115, 30, 50, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710, 710, 710, 710, 710,
+ 710, 710, 710, 710, 710, 710
};
- register unsigned int hval = 0;
+ unsigned int hval = 0;
switch (len)
{
default:
- hval += asso_values[(unsigned char)str[39]];
+ hval += asso_values[static_cast<unsigned char>(str[39])];
/*FALLTHROUGH*/
case 39:
- hval += asso_values[(unsigned char)str[38]];
+ hval += asso_values[static_cast<unsigned char>(str[38])];
/*FALLTHROUGH*/
case 38:
- hval += asso_values[(unsigned char)str[37]];
+ hval += asso_values[static_cast<unsigned char>(str[37])];
/*FALLTHROUGH*/
case 37:
- hval += asso_values[(unsigned char)str[36]];
+ hval += asso_values[static_cast<unsigned char>(str[36])];
/*FALLTHROUGH*/
case 36:
- hval += asso_values[(unsigned char)str[35]];
+ hval += asso_values[static_cast<unsigned char>(str[35])];
/*FALLTHROUGH*/
case 35:
- hval += asso_values[(unsigned char)str[34]];
+ hval += asso_values[static_cast<unsigned char>(str[34])];
/*FALLTHROUGH*/
case 34:
- hval += asso_values[(unsigned char)str[33]];
+ hval += asso_values[static_cast<unsigned char>(str[33])];
/*FALLTHROUGH*/
case 33:
- hval += asso_values[(unsigned char)str[32]];
+ hval += asso_values[static_cast<unsigned char>(str[32])];
/*FALLTHROUGH*/
case 32:
- hval += asso_values[(unsigned char)str[31]];
+ hval += asso_values[static_cast<unsigned char>(str[31])];
/*FALLTHROUGH*/
case 31:
- hval += asso_values[(unsigned char)str[30]];
+ hval += asso_values[static_cast<unsigned char>(str[30])];
/*FALLTHROUGH*/
case 30:
- hval += asso_values[(unsigned char)str[29]];
+ hval += asso_values[static_cast<unsigned char>(str[29])];
/*FALLTHROUGH*/
case 29:
- hval += asso_values[(unsigned char)str[28]];
+ hval += asso_values[static_cast<unsigned char>(str[28])];
/*FALLTHROUGH*/
case 28:
- hval += asso_values[(unsigned char)str[27]];
+ hval += asso_values[static_cast<unsigned char>(str[27])];
/*FALLTHROUGH*/
case 27:
- hval += asso_values[(unsigned char)str[26]];
+ hval += asso_values[static_cast<unsigned char>(str[26])];
/*FALLTHROUGH*/
case 26:
- hval += asso_values[(unsigned char)str[25]];
+ hval += asso_values[static_cast<unsigned char>(str[25])];
/*FALLTHROUGH*/
case 25:
- hval += asso_values[(unsigned char)str[24]];
+ hval += asso_values[static_cast<unsigned char>(str[24])];
/*FALLTHROUGH*/
case 24:
- hval += asso_values[(unsigned char)str[23]];
+ hval += asso_values[static_cast<unsigned char>(str[23])];
/*FALLTHROUGH*/
case 23:
- hval += asso_values[(unsigned char)str[22]];
+ hval += asso_values[static_cast<unsigned char>(str[22])];
/*FALLTHROUGH*/
case 22:
- hval += asso_values[(unsigned char)str[21]];
+ hval += asso_values[static_cast<unsigned char>(str[21])];
/*FALLTHROUGH*/
case 21:
- hval += asso_values[(unsigned char)str[20]];
+ hval += asso_values[static_cast<unsigned char>(str[20])];
/*FALLTHROUGH*/
case 20:
- hval += asso_values[(unsigned char)str[19]];
+ hval += asso_values[static_cast<unsigned char>(str[19])];
/*FALLTHROUGH*/
case 19:
- hval += asso_values[(unsigned char)str[18]];
+ hval += asso_values[static_cast<unsigned char>(str[18])];
/*FALLTHROUGH*/
case 18:
- hval += asso_values[(unsigned char)str[17]];
+ hval += asso_values[static_cast<unsigned char>(str[17])];
/*FALLTHROUGH*/
case 17:
- hval += asso_values[(unsigned char)str[16]];
+ hval += asso_values[static_cast<unsigned char>(str[16])];
/*FALLTHROUGH*/
case 16:
- hval += asso_values[(unsigned char)str[15]];
+ hval += asso_values[static_cast<unsigned char>(str[15])];
/*FALLTHROUGH*/
case 15:
- hval += asso_values[(unsigned char)str[14]];
+ hval += asso_values[static_cast<unsigned char>(str[14])];
/*FALLTHROUGH*/
case 14:
- hval += asso_values[(unsigned char)str[13]];
+ hval += asso_values[static_cast<unsigned char>(str[13])];
/*FALLTHROUGH*/
case 13:
- hval += asso_values[(unsigned char)str[12]];
+ hval += asso_values[static_cast<unsigned char>(str[12])];
/*FALLTHROUGH*/
case 12:
- hval += asso_values[(unsigned char)str[11]];
+ hval += asso_values[static_cast<unsigned char>(str[11])];
/*FALLTHROUGH*/
case 11:
- hval += asso_values[(unsigned char)str[10]];
+ hval += asso_values[static_cast<unsigned char>(str[10])];
/*FALLTHROUGH*/
case 10:
- hval += asso_values[(unsigned char)str[9]];
+ hval += asso_values[static_cast<unsigned char>(str[9])];
/*FALLTHROUGH*/
case 9:
- hval += asso_values[(unsigned char)str[8]];
+ hval += asso_values[static_cast<unsigned char>(str[8])];
/*FALLTHROUGH*/
case 8:
- hval += asso_values[(unsigned char)str[7]];
+ hval += asso_values[static_cast<unsigned char>(str[7])];
/*FALLTHROUGH*/
case 7:
- hval += asso_values[(unsigned char)str[6]];
+ hval += asso_values[static_cast<unsigned char>(str[6])];
/*FALLTHROUGH*/
case 6:
- hval += asso_values[(unsigned char)str[5]];
+ hval += asso_values[static_cast<unsigned char>(str[5])];
/*FALLTHROUGH*/
case 5:
- hval += asso_values[(unsigned char)str[4]];
+ hval += asso_values[static_cast<unsigned char>(str[4])];
/*FALLTHROUGH*/
case 4:
- hval += asso_values[(unsigned char)str[3]];
+ hval += asso_values[static_cast<unsigned char>(str[3])];
/*FALLTHROUGH*/
case 3:
- hval += asso_values[(unsigned char)str[2]];
+ hval += asso_values[static_cast<unsigned char>(str[2])];
/*FALLTHROUGH*/
case 2:
- hval += asso_values[(unsigned char)str[1]];
+ hval += asso_values[static_cast<unsigned char>(str[1])];
/*FALLTHROUGH*/
case 1:
- hval += asso_values[(unsigned char)str[0]];
+ hval += asso_values[static_cast<unsigned char>(str[0])];
break;
}
return hval;
@@ -399,257 +400,251 @@ HTTPHeaderNamesHash::header_name_hash_function (register const char *str, regist
static const struct HeaderNameHashEntry header_name_wordlist[] =
{
-#line 236 "HTTPHeaderNames.gperf"
+#line 238 "HTTPHeaderNames.gperf"
{"TE", HTTPHeaderName::TE},
-#line 185 "HTTPHeaderNames.gperf"
+#line 186 "HTTPHeaderNames.gperf"
{"Cookie", HTTPHeaderName::Cookie},
-#line 172 "HTTPHeaderNames.gperf"
+#line 173 "HTTPHeaderNames.gperf"
{"Age", HTTPHeaderName::Age},
-#line 186 "HTTPHeaderNames.gperf"
+#line 187 "HTTPHeaderNames.gperf"
{"Cookie2", HTTPHeaderName::Cookie2},
-#line 195 "HTTPHeaderNames.gperf"
+#line 196 "HTTPHeaderNames.gperf"
{"ETag", HTTPHeaderName::ETag},
-#line 217 "HTTPHeaderNames.gperf"
+#line 218 "HTTPHeaderNames.gperf"
{"Range", HTTPHeaderName::Range},
-#line 175 "HTTPHeaderNames.gperf"
+#line 176 "HTTPHeaderNames.gperf"
{"Connection", HTTPHeaderName::Connection},
-#line 211 "HTTPHeaderNames.gperf"
+#line 212 "HTTPHeaderNames.gperf"
{"Origin", HTTPHeaderName::Origin},
-#line 159 "HTTPHeaderNames.gperf"
+#line 234 "HTTPHeaderNames.gperf"
+ {"Set-Cookie", HTTPHeaderName::SetCookie},
+#line 160 "HTTPHeaderNames.gperf"
{"Accept", HTTPHeaderName::Accept},
-#line 181 "HTTPHeaderNames.gperf"
+#line 235 "HTTPHeaderNames.gperf"
+ {"Set-Cookie2", HTTPHeaderName::SetCookie2},
+#line 182 "HTTPHeaderNames.gperf"
{"Content-Range", HTTPHeaderName::ContentRange},
-#line 221 "HTTPHeaderNames.gperf"
+#line 222 "HTTPHeaderNames.gperf"
{"Report-To", HTTPHeaderName::ReportTo},
-#line 213 "HTTPHeaderNames.gperf"
+#line 214 "HTTPHeaderNames.gperf"
{"Ping-To", HTTPHeaderName::PingTo},
-#line 209 "HTTPHeaderNames.gperf"
- {"Link", HTTPHeaderName::Link},
#line 210 "HTTPHeaderNames.gperf"
+ {"Link", HTTPHeaderName::Link},
+#line 211 "HTTPHeaderNames.gperf"
{"Location", HTTPHeaderName::Location},
-#line 238 "HTTPHeaderNames.gperf"
+#line 240 "HTTPHeaderNames.gperf"
{"Trailer", HTTPHeaderName::Trailer},
-#line 184 "HTTPHeaderNames.gperf"
- {"Content-Type", HTTPHeaderName::ContentType},
-#line 233 "HTTPHeaderNames.gperf"
- {"Set-Cookie", HTTPHeaderName::SetCookie},
-#line 234 "HTTPHeaderNames.gperf"
- {"Set-Cookie2", HTTPHeaderName::SetCookie2},
-#line 180 "HTTPHeaderNames.gperf"
- {"Content-Location", HTTPHeaderName::ContentLocation},
-#line 196 "HTTPHeaderNames.gperf"
- {"Expect", HTTPHeaderName::Expect},
-#line 242 "HTTPHeaderNames.gperf"
+#line 244 "HTTPHeaderNames.gperf"
{"User-Agent", HTTPHeaderName::UserAgent},
-#line 178 "HTTPHeaderNames.gperf"
- {"Content-Language", HTTPHeaderName::ContentLanguage},
-#line 162 "HTTPHeaderNames.gperf"
- {"Accept-Language", HTTPHeaderName::AcceptLanguage},
-#line 163 "HTTPHeaderNames.gperf"
+#line 164 "HTTPHeaderNames.gperf"
{"Accept-Ranges", HTTPHeaderName::AcceptRanges},
-#line 193 "HTTPHeaderNames.gperf"
+#line 181 "HTTPHeaderNames.gperf"
+ {"Content-Location", HTTPHeaderName::ContentLocation},
+#line 185 "HTTPHeaderNames.gperf"
+ {"Content-Type", HTTPHeaderName::ContentType},
+#line 194 "HTTPHeaderNames.gperf"
{"Date", HTTPHeaderName::Date},
-#line 192 "HTTPHeaderNames.gperf"
+#line 193 "HTTPHeaderNames.gperf"
{"DNT", HTTPHeaderName::DNT},
-#line 216 "HTTPHeaderNames.gperf"
+#line 217 "HTTPHeaderNames.gperf"
{"Purpose", HTTPHeaderName::Purpose},
-#line 218 "HTTPHeaderNames.gperf"
+#line 179 "HTTPHeaderNames.gperf"
+ {"Content-Language", HTTPHeaderName::ContentLanguage},
+#line 163 "HTTPHeaderNames.gperf"
+ {"Accept-Language", HTTPHeaderName::AcceptLanguage},
+#line 219 "HTTPHeaderNames.gperf"
{"Referer", HTTPHeaderName::Referer},
-#line 244 "HTTPHeaderNames.gperf"
- {"Via", HTTPHeaderName::Via},
-#line 204 "HTTPHeaderNames.gperf"
+#line 178 "HTTPHeaderNames.gperf"
+ {"Content-Encoding", HTTPHeaderName::ContentEncoding},
+#line 205 "HTTPHeaderNames.gperf"
{"If-Range", HTTPHeaderName::IfRange},
#line 197 "HTTPHeaderNames.gperf"
- {"Expires", HTTPHeaderName::Expires},
-#line 243 "HTTPHeaderNames.gperf"
- {"Vary", HTTPHeaderName::Vary},
-#line 177 "HTTPHeaderNames.gperf"
- {"Content-Encoding", HTTPHeaderName::ContentEncoding},
-#line 240 "HTTPHeaderNames.gperf"
- {"Upgrade", HTTPHeaderName::Upgrade},
-#line 161 "HTTPHeaderNames.gperf"
+ {"Expect", HTTPHeaderName::Expect},
+#line 162 "HTTPHeaderNames.gperf"
{"Accept-Encoding", HTTPHeaderName::AcceptEncoding},
-#line 199 "HTTPHeaderNames.gperf"
- {"Icy-MetaInt", HTTPHeaderName::IcyMetaInt},
-#line 214 "HTTPHeaderNames.gperf"
+#line 215 "HTTPHeaderNames.gperf"
{"Pragma", HTTPHeaderName::Pragma},
-#line 182 "HTTPHeaderNames.gperf"
- {"Content-Security-Policy", HTTPHeaderName::ContentSecurityPolicy},
-#line 174 "HTTPHeaderNames.gperf"
- {"Cache-Control", HTTPHeaderName::CacheControl},
-#line 206 "HTTPHeaderNames.gperf"
- {"Keep-Alive", HTTPHeaderName::KeepAlive},
+#line 242 "HTTPHeaderNames.gperf"
+ {"Upgrade", HTTPHeaderName::Upgrade},
+#line 200 "HTTPHeaderNames.gperf"
+ {"Icy-MetaInt", HTTPHeaderName::IcyMetaInt},
#line 198 "HTTPHeaderNames.gperf"
- {"Host", HTTPHeaderName::Host},
-#line 245 "HTTPHeaderNames.gperf"
- {"X-Content-Type-Options", HTTPHeaderName::XContentTypeOptions},
-#line 219 "HTTPHeaderNames.gperf"
- {"Referrer-Policy", HTTPHeaderName::ReferrerPolicy},
-#line 179 "HTTPHeaderNames.gperf"
- {"Content-Length", HTTPHeaderName::ContentLength},
-#line 226 "HTTPHeaderNames.gperf"
+ {"Expires", HTTPHeaderName::Expires},
+#line 227 "HTTPHeaderNames.gperf"
{"Sec-WebSocket-Key", HTTPHeaderName::SecWebSocketKey},
-#line 173 "HTTPHeaderNames.gperf"
- {"Authorization", HTTPHeaderName::Authorization},
-#line 235 "HTTPHeaderNames.gperf"
- {"SourceMap", HTTPHeaderName::SourceMap},
-#line 224 "HTTPHeaderNames.gperf"
+#line 225 "HTTPHeaderNames.gperf"
{"Sec-WebSocket-Accept", HTTPHeaderName::SecWebSocketAccept},
-#line 160 "HTTPHeaderNames.gperf"
+#line 236 "HTTPHeaderNames.gperf"
+ {"SourceMap", HTTPHeaderName::SourceMap},
+#line 246 "HTTPHeaderNames.gperf"
+ {"Via", HTTPHeaderName::Via},
+#line 237 "HTTPHeaderNames.gperf"
+ {"Strict-Transport-Security", HTTPHeaderName::StrictTransportSecurity},
+#line 177 "HTTPHeaderNames.gperf"
+ {"Content-Disposition", HTTPHeaderName::ContentDisposition},
+#line 183 "HTTPHeaderNames.gperf"
+ {"Content-Security-Policy", HTTPHeaderName::ContentSecurityPolicy},
+#line 190 "HTTPHeaderNames.gperf"
+ {"Cross-Origin-Opener-Policy", HTTPHeaderName::CrossOriginOpenerPolicy},
+#line 245 "HTTPHeaderNames.gperf"
+ {"Vary", HTTPHeaderName::Vary},
+#line 228 "HTTPHeaderNames.gperf"
+ {"Sec-WebSocket-Protocol", HTTPHeaderName::SecWebSocketProtocol},
+#line 199 "HTTPHeaderNames.gperf"
+ {"Host", HTTPHeaderName::Host},
+#line 192 "HTTPHeaderNames.gperf"
+ {"Cross-Origin-Resource-Policy", HTTPHeaderName::CrossOriginResourcePolicy},
+#line 220 "HTTPHeaderNames.gperf"
+ {"Referrer-Policy", HTTPHeaderName::ReferrerPolicy},
+#line 201 "HTTPHeaderNames.gperf"
+ {"Icy-Metadata", HTTPHeaderName::IcyMetadata},
+#line 247 "HTTPHeaderNames.gperf"
+ {"X-Content-Type-Options", HTTPHeaderName::XContentTypeOptions},
+#line 175 "HTTPHeaderNames.gperf"
+ {"Cache-Control", HTTPHeaderName::CacheControl},
+#line 161 "HTTPHeaderNames.gperf"
{"Accept-Charset", HTTPHeaderName::AcceptCharset},
-#line 230 "HTTPHeaderNames.gperf"
+#line 207 "HTTPHeaderNames.gperf"
+ {"Keep-Alive", HTTPHeaderName::KeepAlive},
+#line 241 "HTTPHeaderNames.gperf"
+ {"Transfer-Encoding", HTTPHeaderName::TransferEncoding},
+#line 168 "HTTPHeaderNames.gperf"
+ {"Access-Control-Allow-Origin", HTTPHeaderName::AccessControlAllowOrigin},
+#line 213 "HTTPHeaderNames.gperf"
+ {"Ping-From", HTTPHeaderName::PingFrom},
+#line 180 "HTTPHeaderNames.gperf"
+ {"Content-Length", HTTPHeaderName::ContentLength},
+#line 243 "HTTPHeaderNames.gperf"
+ {"Upgrade-Insecure-Requests", HTTPHeaderName::UpgradeInsecureRequests},
+#line 231 "HTTPHeaderNames.gperf"
{"Service-Worker", HTTPHeaderName::ServiceWorker},
#line 250 "HTTPHeaderNames.gperf"
- {"X-XSS-Protection", HTTPHeaderName::XXSSProtection},
-#line 189 "HTTPHeaderNames.gperf"
- {"Cross-Origin-Opener-Policy", HTTPHeaderName::CrossOriginOpenerPolicy},
-#line 200 "HTTPHeaderNames.gperf"
- {"Icy-Metadata", HTTPHeaderName::IcyMetadata},
-#line 248 "HTTPHeaderNames.gperf"
{"X-SourceMap", HTTPHeaderName::XSourceMap},
-#line 227 "HTTPHeaderNames.gperf"
- {"Sec-WebSocket-Protocol", HTTPHeaderName::SecWebSocketProtocol},
-#line 176 "HTTPHeaderNames.gperf"
- {"Content-Disposition", HTTPHeaderName::ContentDisposition},
-#line 183 "HTTPHeaderNames.gperf"
+#line 174 "HTTPHeaderNames.gperf"
+ {"Authorization", HTTPHeaderName::Authorization},
+#line 226 "HTTPHeaderNames.gperf"
+ {"Sec-WebSocket-Extensions", HTTPHeaderName::SecWebSocketExtensions},
+#line 252 "HTTPHeaderNames.gperf"
+ {"X-XSS-Protection", HTTPHeaderName::XXSSProtection},
+#line 239 "HTTPHeaderNames.gperf"
+ {"Timing-Allow-Origin", HTTPHeaderName::TimingAllowOrigin},
+#line 170 "HTTPHeaderNames.gperf"
+ {"Access-Control-Max-Age", HTTPHeaderName::AccessControlMaxAge},
+#line 184 "HTTPHeaderNames.gperf"
{"Content-Security-Policy-Report-Only", HTTPHeaderName::ContentSecurityPolicyReportOnly},
#line 191 "HTTPHeaderNames.gperf"
- {"Cross-Origin-Resource-Policy", HTTPHeaderName::CrossOriginResourcePolicy},
-#line 212 "HTTPHeaderNames.gperf"
- {"Ping-From", HTTPHeaderName::PingFrom},
-#line 249 "HTTPHeaderNames.gperf"
+ {"Cross-Origin-Opener-Policy-Report-Only", HTTPHeaderName::CrossOriginOpenerPolicyReportOnly},
+#line 251 "HTTPHeaderNames.gperf"
{"X-Temp-Tablet", HTTPHeaderName::XTempTablet},
-#line 239 "HTTPHeaderNames.gperf"
- {"Transfer-Encoding", HTTPHeaderName::TransferEncoding},
-#line 220 "HTTPHeaderNames.gperf"
+#line 221 "HTTPHeaderNames.gperf"
{"Refresh", HTTPHeaderName::Refresh},
-#line 215 "HTTPHeaderNames.gperf"
- {"Proxy-Authorization", HTTPHeaderName::ProxyAuthorization},
-#line 167 "HTTPHeaderNames.gperf"
- {"Access-Control-Allow-Origin", HTTPHeaderName::AccessControlAllowOrigin},
-#line 237 "HTTPHeaderNames.gperf"
- {"Timing-Allow-Origin", HTTPHeaderName::TimingAllowOrigin},
-#line 207 "HTTPHeaderNames.gperf"
+#line 230 "HTTPHeaderNames.gperf"
+ {"Server-Timing", HTTPHeaderName::ServerTiming},
+#line 208 "HTTPHeaderNames.gperf"
{"Last-Event-ID", HTTPHeaderName::LastEventID},
-#line 241 "HTTPHeaderNames.gperf"
- {"Upgrade-Insecure-Requests", HTTPHeaderName::UpgradeInsecureRequests},
#line 229 "HTTPHeaderNames.gperf"
- {"Server-Timing", HTTPHeaderName::ServerTiming},
-#line 169 "HTTPHeaderNames.gperf"
- {"Access-Control-Max-Age", HTTPHeaderName::AccessControlMaxAge},
-#line 190 "HTTPHeaderNames.gperf"
- {"Cross-Origin-Opener-Policy-Report-Only", HTTPHeaderName::CrossOriginOpenerPolicyReportOnly},
-#line 225 "HTTPHeaderNames.gperf"
- {"Sec-WebSocket-Extensions", HTTPHeaderName::SecWebSocketExtensions},
-#line 194 "HTTPHeaderNames.gperf"
- {"Default-Style", HTTPHeaderName::DefaultStyle},
-#line 228 "HTTPHeaderNames.gperf"
{"Sec-WebSocket-Version", HTTPHeaderName::SecWebSocketVersion},
-#line 247 "HTTPHeaderNames.gperf"
+#line 195 "HTTPHeaderNames.gperf"
+ {"Default-Style", HTTPHeaderName::DefaultStyle},
+#line 249 "HTTPHeaderNames.gperf"
{"X-Frame-Options", HTTPHeaderName::XFrameOptions},
-#line 201 "HTTPHeaderNames.gperf"
+#line 165 "HTTPHeaderNames.gperf"
+ {"Access-Control-Allow-Credentials", HTTPHeaderName::AccessControlAllowCredentials},
+#line 202 "HTTPHeaderNames.gperf"
{"If-Match", HTTPHeaderName::IfMatch},
-#line 203 "HTTPHeaderNames.gperf"
+#line 204 "HTTPHeaderNames.gperf"
{"If-None-Match", HTTPHeaderName::IfNoneMatch},
-#line 222 "HTTPHeaderNames.gperf"
+#line 223 "HTTPHeaderNames.gperf"
{"Sec-Fetch-Dest", HTTPHeaderName::SecFetchDest},
-#line 231 "HTTPHeaderNames.gperf"
- {"Service-Worker-Allowed", HTTPHeaderName::ServiceWorkerAllowed},
-#line 164 "HTTPHeaderNames.gperf"
- {"Access-Control-Allow-Credentials", HTTPHeaderName::AccessControlAllowCredentials},
-#line 170 "HTTPHeaderNames.gperf"
+#line 171 "HTTPHeaderNames.gperf"
{"Access-Control-Request-Headers", HTTPHeaderName::AccessControlRequestHeaders},
-#line 246 "HTTPHeaderNames.gperf"
- {"X-DNS-Prefetch-Control", HTTPHeaderName::XDNSPrefetchControl},
-#line 223 "HTTPHeaderNames.gperf"
- {"Sec-Fetch-Mode", HTTPHeaderName::SecFetchMode},
-#line 208 "HTTPHeaderNames.gperf"
+#line 216 "HTTPHeaderNames.gperf"
+ {"Proxy-Authorization", HTTPHeaderName::ProxyAuthorization},
+#line 209 "HTTPHeaderNames.gperf"
{"Last-Modified", HTTPHeaderName::LastModified},
-#line 232 "HTTPHeaderNames.gperf"
- {"Service-Worker-Navigation-Preload", HTTPHeaderName::ServiceWorkerNavigationPreload},
-#line 168 "HTTPHeaderNames.gperf"
- {"Access-Control-Expose-Headers", HTTPHeaderName::AccessControlExposeHeaders},
-#line 165 "HTTPHeaderNames.gperf"
- {"Access-Control-Allow-Headers", HTTPHeaderName::AccessControlAllowHeaders},
-#line 187 "HTTPHeaderNames.gperf"
+#line 188 "HTTPHeaderNames.gperf"
{"Cross-Origin-Embedder-Policy", HTTPHeaderName::CrossOriginEmbedderPolicy},
-#line 171 "HTTPHeaderNames.gperf"
+#line 232 "HTTPHeaderNames.gperf"
+ {"Service-Worker-Allowed", HTTPHeaderName::ServiceWorkerAllowed},
+#line 224 "HTTPHeaderNames.gperf"
+ {"Sec-Fetch-Mode", HTTPHeaderName::SecFetchMode},
+#line 172 "HTTPHeaderNames.gperf"
{"Access-Control-Request-Method", HTTPHeaderName::AccessControlRequestMethod},
-#line 202 "HTTPHeaderNames.gperf"
+#line 166 "HTTPHeaderNames.gperf"
+ {"Access-Control-Allow-Headers", HTTPHeaderName::AccessControlAllowHeaders},
+#line 203 "HTTPHeaderNames.gperf"
{"If-Modified-Since", HTTPHeaderName::IfModifiedSince},
-#line 205 "HTTPHeaderNames.gperf"
+#line 169 "HTTPHeaderNames.gperf"
+ {"Access-Control-Expose-Headers", HTTPHeaderName::AccessControlExposeHeaders},
+#line 206 "HTTPHeaderNames.gperf"
{"If-Unmodified-Since", HTTPHeaderName::IfUnmodifiedSince},
-#line 188 "HTTPHeaderNames.gperf"
+#line 189 "HTTPHeaderNames.gperf"
{"Cross-Origin-Embedder-Policy-Report-Only", HTTPHeaderName::CrossOriginEmbedderPolicyReportOnly},
-#line 166 "HTTPHeaderNames.gperf"
- {"Access-Control-Allow-Methods", HTTPHeaderName::AccessControlAllowMethods}
+#line 248 "HTTPHeaderNames.gperf"
+ {"X-DNS-Prefetch-Control", HTTPHeaderName::XDNSPrefetchControl},
+#line 167 "HTTPHeaderNames.gperf"
+ {"Access-Control-Allow-Methods", HTTPHeaderName::AccessControlAllowMethods},
+#line 233 "HTTPHeaderNames.gperf"
+ {"Service-Worker-Navigation-Preload", HTTPHeaderName::ServiceWorkerNavigationPreload}
};
static const signed char lookup[] =
{
-1, -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, -1, -1, -1,
3, 4, -1, -1, -1, -1, 5, -1, -1, -1, -1, 6, -1, -1,
- -1, -1, 7, -1, -1, -1, -1, 8, -1, -1, -1, -1, 9, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 10, -1, -1, -1, -1, 11,
- -1, -1, -1, 12, 13, -1, -1, -1, -1, 14, -1, -1, -1, -1,
- 15, -1, -1, -1, 16, -1, -1, -1, -1, 17, 18, -1, -1, -1,
- -1, 19, -1, -1, -1, -1, 20, -1, -1, -1, -1, 21, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, -1,
- -1, -1, -1, 23, -1, -1, -1, -1, 24, -1, -1, -1, -1, 25,
- -1, -1, -1, -1, 26, -1, -1, -1, -1, 27, -1, -1, -1, -1,
- 28, -1, -1, -1, -1, 29, -1, -1, -1, -1, 30, -1, -1, -1,
- -1, 31, -1, -1, -1, -1, 32, -1, -1, -1, -1, 33, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, 34, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 35,
- -1, -1, -1, -1, 36, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 37, -1, -1, -1, -1, 38, -1, -1, -1, 39, 40, -1, -1, -1,
- -1, 41, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, -1, -1,
- -1, -1, 43, -1, -1, 44, -1, -1, -1, -1, -1, -1, 45, -1,
- -1, -1, -1, 46, -1, -1, -1, 47, 48, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 49, 50, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 51, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 52, -1, -1, -1, -1, 53, -1, -1,
- -1, 54, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, 56, -1,
- -1, -1, -1, 57, -1, -1, -1, -1, 58, -1, -1, -1, -1, 59,
- -1, -1, -1, -1, 60, -1, -1, -1, -1, 61, -1, -1, -1, -1,
- 62, -1, -1, -1, -1, 63, -1, -1, -1, -1, 64, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 65, -1, -1,
- -1, -1, 66, -1, -1, -1, -1, -1, -1, -1, -1, -1, 67, -1,
- -1, -1, -1, 68, -1, -1, -1, -1, 69, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 70, 71, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 72, 73, -1, -1, -1, -1, 74, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, 75, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 7, -1, -1, -1, 8, 9, -1, -1, -1, 10, 11, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 12, -1, -1, -1, -1, 13,
+ -1, -1, -1, 14, 15, -1, -1, -1, -1, 16, -1, -1, -1, -1,
+ 17, -1, -1, -1, -1, 18, -1, -1, -1, -1, 19, -1, -1, -1,
+ -1, 20, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 21, -1, -1, -1, -1, 22, -1, -1, -1, -1, 23, -1,
+ -1, -1, -1, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, 25, -1, -1, -1, -1, 26, -1, -1, -1, -1,
+ 27, -1, -1, -1, -1, 28, -1, -1, -1, -1, 29, -1, -1, -1,
+ -1, 30, -1, -1, -1, -1, 31, -1, -1, -1, -1, 32, -1, -1,
+ -1, -1, 33, -1, -1, -1, -1, 34, -1, -1, -1, -1, -1, -1,
+ -1, 35, 36, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 37,
+ -1, -1, -1, -1, 38, -1, -1, -1, -1, 39, -1, -1, -1, -1,
+ 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1,
+ -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, 44, 45, -1, -1,
+ -1, -1, 46, -1, -1, -1, -1, -1, -1, -1, -1, -1, 47, -1,
+ -1, -1, -1, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1, 49,
+ -1, -1, -1, -1, 50, -1, -1, -1, -1, 51, -1, -1, -1, 52,
+ 53, -1, -1, -1, -1, 54, -1, -1, -1, -1, 55, -1, -1, -1,
+ -1, 56, -1, -1, -1, -1, 57, -1, -1, -1, 58, -1, -1, -1,
+ -1, -1, 59, -1, -1, -1, -1, 60, -1, -1, -1, -1, -1, -1,
+ -1, -1, 61, 62, -1, -1, -1, -1, 63, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, 64, -1, -1, -1, -1, 65, -1, -1, -1, -1,
+ 66, -1, -1, -1, -1, 67, -1, -1, -1, -1, 68, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 69, -1, -1, -1, -1, 70, -1, -1,
+ -1, 71, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 72, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, 76, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, 77, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 73, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 74, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 75, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 76, -1, -1, -1, -1, -1, -1, -1, -1, -1, 77,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 78, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 79, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 81, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, 78, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 82, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 83, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 84, -1, -1, -1, -1, 85, -1, -1,
+ -1, -1, 86, -1, -1, -1, -1, 87, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, 79, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, 80, -1, -1, -1, -1, 81, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 82, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 83, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 84, -1, -1,
- -1, -1, 85, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 86, -1, -1, -1, -1, 87,
+ -1, -1, -1, -1, 88, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 88, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 89, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 89, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 90, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 90, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, 91
+ 91, -1, -1, -1, -1, -1, -1, -1, -1, 92
};
const struct HeaderNameHashEntry *
-HTTPHeaderNamesHash::findHeaderNameImpl (register const char *str, register unsigned int len)
+HTTPHeaderNamesHash::findHeaderNameImpl (const char *str, size_t len)
{
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
@@ -657,11 +652,11 @@ HTTPHeaderNamesHash::findHeaderNameImpl (register const char *str, register unsi
if (key <= MAX_HASH_VALUE)
{
- register int index = lookup[key];
+ int index = lookup[key];
if (index >= 0)
{
- register const char *s = header_name_wordlist[index].name;
+ const char *s = header_name_wordlist[index].name;
if ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
return &header_name_wordlist[index];
@@ -670,7 +665,7 @@ HTTPHeaderNamesHash::findHeaderNameImpl (register const char *str, register unsi
}
return 0;
}
-#line 251 "HTTPHeaderNames.gperf"
+#line 253 "HTTPHeaderNames.gperf"
bool findHTTPHeaderName(StringView stringView, HTTPHeaderName& headerName)
{
diff --git a/src/bun.js/bindings/webcore/HTTPHeaderNames.gperf b/src/bun.js/bindings/webcore/HTTPHeaderNames.gperf
index 66a4b24e8..2b7bcee4f 100644
--- a/src/bun.js/bindings/webcore/HTTPHeaderNames.gperf
+++ b/src/bun.js/bindings/webcore/HTTPHeaderNames.gperf
@@ -120,6 +120,7 @@ static const struct HeaderNameString {
{ "Set-Cookie", 10 },
{ "Set-Cookie2", 11 },
{ "SourceMap", 9 },
+ { "Strict-Transport-Security", 25 },
{ "TE", 2 },
{ "Timing-Allow-Origin", 19 },
{ "Trailer", 7 },
@@ -233,6 +234,7 @@ Service-Worker-Navigation-Preload, HTTPHeaderName::ServiceWorkerNavigationPreloa
Set-Cookie, HTTPHeaderName::SetCookie
Set-Cookie2, HTTPHeaderName::SetCookie2
SourceMap, HTTPHeaderName::SourceMap
+Strict-Transport-Security, HTTPHeaderName::StrictTransportSecurity
TE, HTTPHeaderName::TE
Timing-Allow-Origin, HTTPHeaderName::TimingAllowOrigin
Trailer, HTTPHeaderName::Trailer
diff --git a/src/bun.js/bindings/webcore/HTTPHeaderNames.h b/src/bun.js/bindings/webcore/HTTPHeaderNames.h
index 066d40e90..92dff5c19 100644
--- a/src/bun.js/bindings/webcore/HTTPHeaderNames.h
+++ b/src/bun.js/bindings/webcore/HTTPHeaderNames.h
@@ -33,7 +33,7 @@
namespace WebCore {
-enum class HTTPHeaderName {
+enum class HTTPHeaderName : uint8_t {
Accept,
AcceptCharset,
AcceptEncoding,
@@ -111,6 +111,7 @@ enum class HTTPHeaderName {
SetCookie,
SetCookie2,
SourceMap,
+ StrictTransportSecurity,
TE,
TimingAllowOrigin,
Trailer,
@@ -128,7 +129,7 @@ enum class HTTPHeaderName {
XXSSProtection,
};
-const unsigned numHTTPHeaderNames = 92;
+const unsigned numHTTPHeaderNames = 93;
const size_t minHTTPHeaderNameLength = 2;
const size_t maxHTTPHeaderNameLength = 40;
@@ -219,6 +220,7 @@ template<> struct EnumTraits<WebCore::HTTPHeaderName> {
WebCore::HTTPHeaderName::SetCookie,
WebCore::HTTPHeaderName::SetCookie2,
WebCore::HTTPHeaderName::SourceMap,
+ WebCore::HTTPHeaderName::StrictTransportSecurity,
WebCore::HTTPHeaderName::TE,
WebCore::HTTPHeaderName::TimingAllowOrigin,
WebCore::HTTPHeaderName::Trailer,
@@ -233,8 +235,7 @@ template<> struct EnumTraits<WebCore::HTTPHeaderName> {
WebCore::HTTPHeaderName::XFrameOptions,
WebCore::HTTPHeaderName::XSourceMap,
WebCore::HTTPHeaderName::XTempTablet,
- WebCore::HTTPHeaderName::XXSSProtection
- >;
+ WebCore::HTTPHeaderName::XXSSProtection>;
};
} // namespace WTF
diff --git a/src/bun.js/bindings/webcore/HTTPParsers.cpp b/src/bun.js/bindings/webcore/HTTPParsers.cpp
index 77a287b36..d3e4d4c3a 100644
--- a/src/bun.js/bindings/webcore/HTTPParsers.cpp
+++ b/src/bun.js/bindings/webcore/HTTPParsers.cpp
@@ -849,35 +849,36 @@ size_t parseHTTPRequestBody(const uint8_t* data, size_t length, Vector<uint8_t>&
// Implements <https://fetch.spec.whatwg.org/#forbidden-header-name>.
bool isForbiddenHeaderName(const String& name)
{
- HTTPHeaderName headerName;
- if (findHTTPHeaderName(name, headerName)) {
- switch (headerName) {
- case HTTPHeaderName::AcceptCharset:
- case HTTPHeaderName::AcceptEncoding:
- case HTTPHeaderName::AccessControlRequestHeaders:
- case HTTPHeaderName::AccessControlRequestMethod:
- case HTTPHeaderName::Connection:
- case HTTPHeaderName::ContentLength:
- case HTTPHeaderName::Cookie:
- case HTTPHeaderName::Cookie2:
- case HTTPHeaderName::Date:
- case HTTPHeaderName::DNT:
- case HTTPHeaderName::Expect:
- case HTTPHeaderName::Host:
- case HTTPHeaderName::KeepAlive:
- case HTTPHeaderName::Origin:
- case HTTPHeaderName::Referer:
- case HTTPHeaderName::TE:
- case HTTPHeaderName::Trailer:
- case HTTPHeaderName::TransferEncoding:
- case HTTPHeaderName::Upgrade:
- case HTTPHeaderName::Via:
- return true;
- default:
- break;
- }
- }
- return startsWithLettersIgnoringASCIICase(name, "sec-"_s) || startsWithLettersIgnoringASCIICase(name, "proxy-"_s);
+ return false;
+ // HTTPHeaderName headerName;
+ // if (findHTTPHeaderName(name, headerName)) {
+ // switch (headerName) {
+ // case HTTPHeaderName::AcceptCharset:
+ // case HTTPHeaderName::AcceptEncoding:
+ // case HTTPHeaderName::AccessControlRequestHeaders:
+ // case HTTPHeaderName::AccessControlRequestMethod:
+ // case HTTPHeaderName::Connection:
+ // case HTTPHeaderName::ContentLength:
+ // case HTTPHeaderName::Cookie:
+ // case HTTPHeaderName::Cookie2:
+ // case HTTPHeaderName::Date:
+ // case HTTPHeaderName::DNT:
+ // case HTTPHeaderName::Expect:
+ // case HTTPHeaderName::Host:
+ // case HTTPHeaderName::KeepAlive:
+ // case HTTPHeaderName::Origin:
+ // case HTTPHeaderName::Referer:
+ // case HTTPHeaderName::TE:
+ // case HTTPHeaderName::Trailer:
+ // case HTTPHeaderName::TransferEncoding:
+ // case HTTPHeaderName::Upgrade:
+ // case HTTPHeaderName::Via:
+ // return true;
+ // default:
+ // break;
+ // }
+ // }
+ // return startsWithLettersIgnoringASCIICase(name, "sec-"_s) || startsWithLettersIgnoringASCIICase(name, "proxy-"_s);
}
// Implements <https://fetch.spec.whatwg.org/#no-cors-safelisted-request-header-name>.
diff --git a/src/bun.js/bindings/webcore/HTTPParsers.h b/src/bun.js/bindings/webcore/HTTPParsers.h
index 917ab2eae..0bc922a04 100644
--- a/src/bun.js/bindings/webcore/HTTPParsers.h
+++ b/src/bun.js/bindings/webcore/HTTPParsers.h
@@ -38,7 +38,7 @@ namespace WebCore {
typedef HashSet<String, ASCIICaseInsensitiveHash> HTTPHeaderSet;
-enum class HTTPHeaderName;
+enum class HTTPHeaderName : uint8_t;
enum class XSSProtectionDisposition {
Invalid,
diff --git a/src/bun.js/builtins/BunBuiltinNames.h b/src/bun.js/builtins/BunBuiltinNames.h
index b646211eb..16f7096a6 100644
--- a/src/bun.js/builtins/BunBuiltinNames.h
+++ b/src/bun.js/builtins/BunBuiltinNames.h
@@ -109,6 +109,7 @@ using namespace JSC;
macro(handleEvent) \
macro(hash) \
macro(header) \
+ macro(headers) \
macro(highWaterMark) \
macro(host) \
macro(hostname) \
@@ -137,6 +138,7 @@ using namespace JSC;
macro(makeGetterTypeError) \
macro(makeThisTypeError) \
macro(map) \
+ macro(method) \
macro(nextTick) \
macro(normalize) \
macro(on) \
@@ -199,6 +201,7 @@ using namespace JSC;
macro(started) \
macro(startedPromise) \
macro(state) \
+ macro(status) \
macro(storedError) \
macro(strategy) \
macro(strategyHWM) \
diff --git a/src/bun.js/generate-classes.js b/src/bun.js/generate-classes.js
new file mode 100644
index 000000000..b033e606d
--- /dev/null
+++ b/src/bun.js/generate-classes.js
@@ -0,0 +1,1360 @@
+function symbolName(typeName, name) {
+ return `${typeName}__${name}`;
+}
+
+function protoSymbolName(typeName, name) {
+ return `${typeName}Prototype__${name}`;
+}
+
+function classSymbolName(typeName, name) {
+ return `${typeName}Class__${name}`;
+}
+
+function subspaceFor(typeName) {
+ return `m_subspaceFor${typeName}`;
+}
+
+function clientSubspaceFor(typeName) {
+ return `m_clientSubspaceFor${typeName}`;
+}
+
+function prototypeName(typeName) {
+ return `JS${typeName}Prototype`;
+}
+
+function className(typeName) {
+ return `JS${typeName}`;
+}
+
+function constructorName(typeName) {
+ return `JS${typeName}Constructor`;
+}
+
+function appendSymbols(to, symbolName, prop) {
+ var { defaultValue, getter, setter, accesosr, fn } = prop;
+
+ if (accesosr) {
+ getter = accesosr.getter;
+ setter = accesosr.setter;
+ }
+
+ if (getter) {
+ to.push([getter, symbolName(getter)]);
+ }
+
+ if (setter) {
+ to.push([setter, symbolName(setter)]);
+ }
+
+ if (fn) {
+ to.push([fn, symbolName(fn)]);
+ }
+}
+function propRow(symbolName, typeName, name, prop, isWrapped = true) {
+ var {
+ defaultValue,
+ getter,
+ setter,
+ fn,
+ accesosr,
+ fn,
+ length = 0,
+ cache,
+ } = prop;
+
+ if (accesosr) {
+ getter = accesosr.getter;
+ setter = accesosr.setter;
+ }
+
+ var symbol = symbolName(typeName, name);
+
+ if (isWrapped) {
+ if (getter) {
+ getter = symbol + "GetterWrap";
+ }
+ if (setter) {
+ setter = symbol + "SetterWrap";
+ }
+ if (fn) {
+ fn = symbol + "Callback";
+ }
+ } else {
+ if (getter) {
+ getter = symbolName(typeName, getter);
+ }
+ if (setter) {
+ setter = symbolName(typeName, setter);
+ }
+ if (fn) {
+ fn = symbolName(typeName, fn);
+ }
+ }
+
+ if (fn !== undefined) {
+ return `
+{ "${name}"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(${fn}), (intptr_t)(${
+ length || 0
+ }) } }
+`.trim();
+ } else if (getter && setter) {
+ return `
+
+{ "${name}"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(${getter}), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(${setter}) } }
+`.trim();
+ } else if (defaultValue) {
+ } else if (getter) {
+ return `{ "${name}"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(${getter}), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } }
+`.trim();
+ } else if (setter) {
+ return `{ "${name}"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(0), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(${setter}) } }
+ `.trim();
+ }
+
+ throw "Unsupported property";
+}
+
+function generateHashTable(
+ nameToUse,
+ symbolName,
+ typeName,
+ obj,
+ props = {},
+ wrapped
+) {
+ const rows = [];
+
+ for (const name in props) {
+ rows.push(propRow(symbolName, typeName, name, props[name], wrapped));
+ }
+
+ // static const HashTableValue JSWebSocketPrototypeTableValues[] = {
+ // { "constructor"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocketConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+ // { "URL"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_URL), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+ // { "url"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_url), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+ // { "readyState"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_readyState), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+ // { "bufferedAmount"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_bufferedAmount), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+ // { "onopen"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_onopen), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWebSocket_onopen) } },
+ // { "onmessage"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_onmessage), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWebSocket_onmessage) } },
+ // { "onerror"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_onerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWebSocket_onerror) } },
+ // { "onclose"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_onclose), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWebSocket_onclose) } },
+ // { "protocol"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_protocol), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+ // { "extensions"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_extensions), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
+ // { "binaryType"_s, static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t) static_cast<PropertySlot::GetValueFunc>(jsWebSocket_binaryType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWebSocket_binaryType) } },
+ // { "send"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsWebSocketPrototypeFunction_send), (intptr_t)(1) } },
+ // { "close"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t) static_cast<RawNativeFunction>(jsWebSocketPrototypeFunction_close), (intptr_t)(0) } },
+ // { "CONNECTING"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(0) } },
+ // { "OPEN"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(1) } },
+ // { "CLOSING"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(2) } },
+ // { "CLOSED"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { (long long)(3) } },
+ // };
+ return `
+ static const HashTableValue ${nameToUse}TableValues[] = {
+${rows.join(" ,\n")}
+ };
+`;
+}
+
+function generatePrototype(typeName, obj) {
+ const proto = prototypeName(typeName);
+ const { proto: protoFields } = obj;
+ return `
+${
+ "construct" in obj
+ ? `extern "C" void* ${classSymbolName(
+ typeName,
+ "construct"
+ )}(JSC::JSGlobalObject*, JSC::CallFrame*);
+JSC_DECLARE_CUSTOM_GETTER(js${typeName}Constructor);`
+ : ""
+}
+${
+ "finalize" in obj
+ ? `extern "C" void ${classSymbolName(typeName, "finalize")}(void*);`
+ : ""
+}
+
+${renderDecls(protoSymbolName, typeName, protoFields)}
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(${proto}, ${proto}::Base);
+
+${generateHashTable(
+ prototypeName(typeName),
+ protoSymbolName,
+ typeName,
+ obj,
+
+ protoFields,
+ true
+)}
+
+const ClassInfo ${proto}::s_info = { "${typeName}"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(${proto}) };
+
+${renderFieldsImpl(protoSymbolName, typeName, obj, protoFields)}
+
+void ${proto}::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ reifyStaticProperties(vm, ${className(
+ typeName
+ )}::info(), ${proto}TableValues, *this);
+ JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
+}
+
+
+
+`;
+}
+
+function generateConstructorHeader(typeName) {
+ const name = constructorName(typeName);
+ const proto = prototypeName(typeName);
+
+ return `
+ class ${proto} final : public JSC::JSNonFinalObject {
+ public:
+ using Base = JSC::JSNonFinalObject;
+
+ static ${proto}* create(JSC::VM& vm, JSGlobalObject* globalObject, JSC::Structure* structure)
+ {
+ ${proto}* ptr = new (NotNull, JSC::allocateCell<${proto}>(vm)) ${proto}(vm, globalObject, structure);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ template<typename CellType, JSC::SubspaceAccess>
+ static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ return &vm.plainObjectSpace();
+ }
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+ private:
+ ${proto}(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)
+ : Base(vm, structure)
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject*);
+ };
+
+ class ${name} final : public JSC::InternalFunction {
+ public:
+ using Base = JSC::InternalFunction;
+ static ${name}* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, ${prototypeName(
+ typeName
+ )}* prototype);
+
+ static constexpr unsigned StructureFlags = Base::StructureFlags;
+ static constexpr bool needsDestruction = false;
+
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
+ }
+
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<${name}, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.${clientSubspaceFor(
+ typeName
+ )}Constructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.${clientSubspaceFor(
+ typeName
+ )}Constructor = WTFMove(space); },
+ [](auto& spaces) { return spaces.${subspaceFor(
+ typeName
+ )}Constructor.get(); },
+ [](auto& spaces, auto&& space) { spaces.${subspaceFor(
+ typeName
+ )}Constructor = WTFMove(space); });
+ }
+
+
+ void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, ${prototypeName(
+ typeName
+ )}* prototype);
+
+ // Must be defined for each specialization class.
+ static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
+ DECLARE_EXPORT_INFO;
+ private:
+ ${name}(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
+ : Base(vm, structure, nativeFunction, nativeFunction)
+
+ {
+ }
+
+ void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, ${prototypeName(
+ typeName
+ )}* prototype);
+ };
+
+ `;
+}
+
+function generateConstructorImpl(typeName, obj) {
+ const name = constructorName(typeName);
+ const { klass: fields } = obj;
+ const hashTable =
+ Object.keys(fields).length > 0
+ ? generateHashTable(name, classSymbolName, typeName, obj, fields, false)
+ : "";
+
+ const hashTableIdentifier = hashTable.length ? `${name}TableValues` : "";
+ return `
+${renderStaticDecls(classSymbolName, typeName, fields)}
+${hashTable}
+
+void ${name}::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, ${prototypeName(
+ typeName
+ )}* prototype)
+{
+ Base::finishCreation(vm, 0, "${typeName}"_s, PropertyAdditionMode::WithoutStructureTransition);
+ ${
+ hashTableIdentifier.length
+ ? `reifyStaticProperties(vm, &${name}::s_info, ${hashTableIdentifier}, *this);`
+ : ""
+ }
+ ASSERT(inherits(info()));
+}
+
+${name}* ${name}::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, ${prototypeName(
+ typeName
+ )}* prototype) {
+ ${name}* ptr = new (NotNull, JSC::allocateCell<${name}>(vm)) ${name}(vm, structure, construct);
+ ptr->finishCreation(vm, globalObject, prototype);
+ return ptr;
+}
+
+JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES ${name}::construct(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame)
+{
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ JSC::VM &vm = globalObject->vm();
+ JSObject* newTarget = asObject(callFrame->newTarget());
+ auto* constructor = globalObject->${className(typeName)}Constructor();
+ Structure* structure = globalObject->${className(typeName)}Structure();
+ if (constructor != newTarget) {
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>(
+ // ShadowRealm functions belong to a different global object.
+ getFunctionRealm(globalObject, newTarget)
+ );
+ RETURN_IF_EXCEPTION(scope, {});
+ structure = InternalFunction::createSubclassStructure(
+ globalObject,
+ newTarget,
+ functionGlobalObject->${className(typeName)}Structure()
+ );
+ }
+
+ void* ptr = ${classSymbolName(
+ typeName,
+ "construct"
+ )}(globalObject, callFrame);
+
+ if (UNLIKELY(!ptr)) {
+ return JSValue::encode(JSC::jsUndefined());
+ }
+
+ ${className(typeName)}* instance = ${className(
+ typeName
+ )}::create(vm, globalObject, structure, ptr);
+
+ return JSValue::encode(instance);
+}
+
+extern "C" EncodedJSValue ${typeName}__create(Zig::GlobalObject* globalObject, void* ptr) {
+ auto &vm = globalObject->vm();
+ JSC::Structure* structure = globalObject->${className(typeName)}Structure();
+ ${className(typeName)}* instance = ${className(
+ typeName
+ )}::create(vm, globalObject, structure, ptr);
+ return JSValue::encode(instance);
+}
+
+void ${name}::initializeProperties(VM& vm, JSC::JSGlobalObject* globalObject, ${prototypeName(
+ typeName
+ )}* prototype)
+{
+
+}
+
+const ClassInfo ${name}::s_info = { "Function"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(${name}) };
+
+
+
+
+
+ `;
+}
+
+function renderCachedFieldsHeader(typeName, klass, proto) {
+ const rows = [];
+ for (const name in klass) {
+ if ("cache" in klass[name]) {
+ rows.push(`mutable JSC::WriteBarrier<JSC::Unknown> m_${name};`);
+ }
+ }
+
+ for (const name in proto) {
+ if ("cache" in proto[name]) {
+ rows.push(`mutable JSC::WriteBarrier<JSC::Unknown> m_${name};`);
+ }
+ }
+
+ return rows.join("\n");
+}
+
+function renderDecls(symbolName, typeName, proto) {
+ const rows = [];
+
+ for (const name in proto) {
+ if (
+ "getter" in proto[name] ||
+ ("accessor" in proto[name] && proto[name].getter)
+ ) {
+ rows.push(
+ `extern "C" JSC::EncodedJSValue ${symbolName(
+ typeName,
+ proto[name].getter || proto[name].accessor.getter
+ )}(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject);`,
+ `
+ JSC_DECLARE_CUSTOM_GETTER(${symbolName(typeName, name)}GetterWrap);
+ `.trim(),
+ "\n"
+ );
+ }
+
+ if (
+ "setter" in proto[name] ||
+ ("accessor" in proto[name] && proto[name].setter)
+ ) {
+ rows
+ .push(
+ `extern "C" bool ${symbolName(
+ typeName,
+ proto[name].setter || proto[name].accessor.setter
+ )}(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, EncoedJSValue value);`,
+ `
+ JSC_DECLARE_CUSTOM_SETTER(${symbolName(typeName, name)}SetterWrap);
+ `,
+ "\n"
+ )
+ .trim();
+ }
+
+ if ("fn" in proto[name]) {
+ rows.push(
+ `extern "C" EncodedJSValue ${symbolName(
+ typeName,
+ proto[name].fn
+ )}(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame);`,
+
+ `
+ JSC_DECLARE_HOST_FUNCTION(${symbolName(typeName, name)}Callback);
+ `.trim(),
+ "\n"
+ );
+ }
+ }
+
+ return rows.join("\n");
+}
+
+function renderStaticDecls(symbolName, typeName, fields) {
+ const rows = [];
+
+ for (const name in fields) {
+ if (
+ "getter" in fields[name] ||
+ ("accessor" in fields[name] && fields[name].getter)
+ ) {
+ rows.push(
+ `extern "C" JSC_DECLARE_CUSTOM_GETTER(${symbolName(
+ typeName,
+ fields[name].getter || fields[name].accessor.getter
+ )});`
+ );
+ }
+
+ if (
+ "setter" in fields[name] ||
+ ("accessor" in fields[name] && fields[name].setter)
+ ) {
+ rows.push(
+ `extern "C" JSC_DECLARE_CUSTOM_SETTER(${symbolName(
+ typeName,
+ fields[name].setter || fields[name].accessor.setter
+ )});`
+ );
+ }
+
+ if ("fn" in fields[name]) {
+ rows.push(
+ `extern "C" JSC_DECLARE_HOST_FUNCTION(${symbolName(
+ typeName,
+ fields[name].fn
+ )});`
+ );
+ }
+ }
+
+ return rows.join("\n");
+}
+
+function renderFieldsImpl(symbolName, typeName, obj, proto) {
+ const rows = [];
+
+ if (obj.construct) {
+ rows.push(`
+
+JSC_DEFINE_CUSTOM_GETTER(js${typeName}Constructor, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName))
+{
+ VM& vm = JSC::getVM(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto* prototype = jsDynamicCast<${prototypeName(
+ typeName
+ )}*>(JSValue::decode(thisValue));
+
+ if (UNLIKELY(!prototype))
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ return JSValue::encode(globalObject->${className(typeName)}Constructor());
+}
+
+`);
+ }
+
+ for (const name in proto) {
+ if ("cache" in proto[name]) {
+ rows.push(`
+JSC_DEFINE_CUSTOM_GETTER(${symbolName(
+ typeName,
+ name
+ )}GetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ ${className(typeName)}* thisObject = jsCast<${className(
+ typeName
+ )}*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ if (JSValue cachedValue = thisObject->m_${name}.get())
+ return JSValue::encode(cachedValue);
+
+ JSC::JSValue result = JSC::JSValue::decode(
+ ${symbolName(
+ typeName,
+ proto[name].getter
+ )}(thisObject->wrapped(), globalObject)
+ );
+ RETURN_IF_EXCEPTION(throwScope, {});
+ thisObject->m_${name}.set(vm, thisObject, result);
+ RELEASE_AND_RETURN(throwScope, JSValue::encode(result));
+}
+`);
+ } else if (
+ "getter" in proto[name] ||
+ ("accessor" in proto[name] && proto[name].getter)
+ ) {
+ rows.push(`
+JSC_DEFINE_CUSTOM_GETTER(${symbolName(
+ typeName,
+ name
+ )}GetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject->vm();
+ Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject);
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ ${className(typeName)}* thisObject = jsCast<${className(
+ typeName
+ )}*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ JSC::EncodedJSValue result = ${symbolName(
+ typeName,
+ proto[name].getter
+ )}(thisObject->wrapped(), globalObject);
+ RETURN_IF_EXCEPTION(throwScope, {});
+ RELEASE_AND_RETURN(throwScope, result);
+}
+ `);
+ }
+
+ if (
+ "setter" in proto[name] ||
+ ("accessor" in proto[name] && proto[name].setter)
+ ) {
+ rows.push(
+ `
+JSC_DEFINE_CUSTOM_SETTER(${symbolName(
+ typeName,
+ name
+ )}SetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, EncodedJSValue encodedValue, PropertyName attributeName))
+{
+ auto& vm = lexicalGlobalObject>
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ ${className(typeName)}* thisObject = jsCast<${className(
+ typeName
+ )}*>(JSValue::decode(thisValue));
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+ auto result = ${symbolName(
+ typeName,
+ roto[name].setter || proto[name].accessor.setter
+ )}(thisObject->wrapped(), lexicalGlobalObject, encodedValue);
+
+ RELEASE_AND_RETURN(throwScope, result);
+}
+`
+ );
+ }
+
+ if ("fn" in proto[name]) {
+ rows.push(`
+JSC_DEFINE_HOST_FUNCTION(${symbolName(
+ typeName,
+ name
+ )}Callback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame))
+{
+ auto& vm = lexicalGlobalObject->vm();
+
+ ${className(typeName)}* thisObject = jsDynamicCast<${className(
+ typeName
+ )}*>(callFrame->thisValue());
+
+ if (UNLIKELY(!thisObject)) {
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return throwVMTypeError(lexicalGlobalObject, throwScope);
+ }
+
+ JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject);
+
+ return ${symbolName(
+ typeName,
+ proto[name].fn
+ )}(thisObject->wrapped(), lexicalGlobalObject, callFrame);
+}
+`);
+ }
+ }
+
+ return rows.join("\n");
+}
+
+function generateClassHeader(typeName, obj) {
+ var { klass, proto, JSType = "Object" } = obj;
+ const name = className(typeName);
+
+ const DECLARE_VISIT_CHILDREN = [
+ ...Object.values(klass),
+ ...Object.values(proto),
+ ].find((a) => !!a.cache)
+ ? "DECLARE_VISIT_CHILDREN;"
+ : "";
+
+ return `
+ class ${name} final : public JSC::JSDestructibleObject {
+ public:
+ using Base = JSC::JSDestructibleObject;
+ static ${name}* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx);
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<${name}, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.${clientSubspaceFor(
+ typeName
+ )}.get(); },
+ [](auto& spaces, auto&& space) { spaces.${clientSubspaceFor(
+ typeName
+ )} = WTFMove(space); },
+ [](auto& spaces) { return spaces.${subspaceFor(
+ typeName
+ )}.get(); },
+ [](auto& spaces, auto&& space) { spaces.${subspaceFor(
+ typeName
+ )} = WTFMove(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(static_cast<JSC::JSType>(${JSType}), StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSDOMGlobalObject* globalObject);
+
+ ~${name}();
+
+ void* wrapped() const { return m_ctx; }
+
+ void detach()
+ {
+ m_ctx = nullptr;
+ }
+
+ static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
+ static ptrdiff_t offsetOfWrapped() { return OBJECT_OFFSETOF(${name}, m_ctx); }
+
+ void* m_ctx { nullptr };
+
+
+ ${name}(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
+ : Base(vm, structure)
+ {
+ m_ctx = sinkPtr;
+ }
+
+ void finishCreation(JSC::VM&);
+
+ ${DECLARE_VISIT_CHILDREN}
+
+ ${renderCachedFieldsHeader(typeName, klass, proto)}
+ };
+ `;
+}
+
+function generateClassImpl(typeName, obj) {
+ const { klass: fields, finalize, proto, construct } = obj;
+ const name = className(typeName);
+ var symbolName = classSymbolName;
+
+ const DEFINE_VISIT_CHILDREN_LIST = [
+ ...Object.entries(fields),
+ ...Object.entries(proto),
+ ]
+ .filter(([name, { cache }]) => !!cache)
+ .map(([name]) => ` visitor.append(thisObject->m_${name});`)
+ .join("\n");
+
+ var DEFINE_VISIT_CHILDREN = "";
+ if (DEFINE_VISIT_CHILDREN_LIST.length) {
+ DEFINE_VISIT_CHILDREN = `
+template<typename Visitor>
+void ${name}::visitChildrenImpl(JSCell* cell, Visitor& visitor)
+{
+ ${name}* thisObject = jsCast<${name}*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+${DEFINE_VISIT_CHILDREN_LIST}
+}
+
+DEFINE_VISIT_CHILDREN(${name});
+ `.trim();
+ }
+
+ var output = ``;
+
+ if (finalize) {
+ output += `
+${name}::~${name}()
+{
+ if (m_ctx) {
+ ${classSymbolName(typeName, "finalize")}(m_ctx);
+ }
+}
+`;
+ } else {
+ output += `
+${name}::~${name}()
+{
+}
+`;
+ }
+
+ output += `
+
+
+
+void ${name}::destroy(JSCell* cell)
+{
+ static_cast<${name}*>(cell)->${name}::~${name}();
+}
+
+const ClassInfo ${name}::s_info = { "${typeName}"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(${name}) };
+
+void ${name}::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+}
+
+${name}* ${name}::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* ctx) {
+ ${name}* ptr = new (NotNull, JSC::allocateCell<${name}>(vm)) ${name}(vm, structure, ctx);
+ ptr->finishCreation(vm);
+ return ptr;
+}
+
+
+extern "C" void* ${typeName}__fromJS(JSC::EncodedJSValue value) {
+ ${className(typeName)}* object = JSC::jsDynamicCast<${className(
+ typeName
+ )}*>(JSValue::decode(value));
+ if (!object)
+ return nullptr;
+
+ return object->wrapped();
+}
+
+extern "C" bool ${typeName}__dangerouslySetPtr(JSC::EncodedJSValue value, void* ptr) {
+ ${className(typeName)}* object = JSC::jsDynamicCast<${className(
+ typeName
+ )}*>(JSValue::decode(value));
+ if (!object)
+ return false;
+
+ object->m_ctx = ptr;
+ return true;
+}
+
+
+extern "C" const size_t ${typeName}__ptrOffset = ${className(
+ typeName
+ )}::offsetOfWrapped();
+
+void ${name}::analyzeHeap(JSCell* cell, HeapAnalyzer& analyzer)
+{
+ auto* thisObject = jsCast<${name}*>(cell);
+ if (void* wrapped = thisObject->wrapped()) {
+ // if (thisObject->scriptExecutionContext())
+ // analyzer.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
+ }
+ Base::analyzeHeap(cell, analyzer);
+}
+
+JSObject* ${name}::createPrototype(VM& vm, JSDOMGlobalObject* globalObject)
+{
+ return ${prototypeName(typeName)}::create(vm, globalObject, ${prototypeName(
+ typeName
+ )}::createStructure(vm, globalObject, globalObject->objectPrototype()));
+}
+
+${DEFINE_VISIT_CHILDREN}
+
+ `.trim();
+
+ return output;
+}
+
+function generateHeader(typeName, obj) {
+ return (
+ generateClassHeader(typeName, obj).trim() +
+ "\n" +
+ generateConstructorHeader(typeName).trim() +
+ "\n"
+ );
+}
+
+function generateImpl(typeName, obj) {
+ const proto = obj.proto;
+ return [
+ Object.keys(proto).length > 0 && generatePrototype(typeName, obj).trim(),
+ generateConstructorImpl(typeName, obj).trim(),
+ Object.keys(proto).length > 0 && generateClassImpl(typeName, obj).trim(),
+ ]
+ .filter(Boolean)
+ .join("\n\n");
+}
+
+function generateZig(
+ typeName,
+ { klass = {}, proto = {}, construct, finalize }
+) {
+ const exports = [];
+
+ if (construct) {
+ exports.push([`constructor`, classSymbolName(typeName, "construct")]);
+ }
+
+ if (finalize) {
+ exports.push([`finalize`, classSymbolName(typeName, "finalize")]);
+ }
+
+ Object.values(klass).map((a) =>
+ appendSymbols(exports, (name) => classSymbolName(typeName, name), a)
+ );
+ Object.values(proto).map((a) =>
+ appendSymbols(exports, (name) => protoSymbolName(typeName, name), a)
+ );
+
+ function typeCheck() {
+ var output = "";
+
+ if (construct) {
+ output += `
+ if (@TypeOf(${typeName}.constructor) != (fn(*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) ?*${typeName})) {
+ @compileLog("${typeName}.constructor is not a constructor");
+ }
+ `;
+ }
+
+ if (finalize) {
+ output += `
+ if (@TypeOf(${typeName}.finalize) != (fn(*${typeName}) callconv(.C) void)) {
+ @compileLog("${typeName}.finalize is not a finalizer");
+ }
+ `;
+ }
+
+ [...Object.values(proto)].forEach(({ getter, setter, accessor, fn }) => {
+ if (accessor) {
+ getter = accessor.getter;
+ setter = accessor.setter;
+ }
+
+ if (getter) {
+ output += `
+ if (@TypeOf(${typeName}.${getter}) != GetterType)
+ @compileLog(
+ "Expected ${typeName}.${getter} to be a getter"
+ );
+`;
+ }
+
+ if (setter) {
+ output += `
+ if (@TypeOf(${typeName}.${setter}) != SetterType)
+ @compileLog(
+ "Expected ${typeName}.${setter} to be a setter"
+ );`;
+ }
+
+ if (fn) {
+ output += `
+ if (@TypeOf(${typeName}.${fn}) != CallbackType)
+ @compileLog(
+ "Expected ${typeName}.${fn} to be a callback"
+ );`;
+ }
+ });
+
+ [...Object.values(klass)].forEach(({ getter, setter, accessor, fn }) => {
+ if (accessor) {
+ getter = accessor.getter;
+ setter = accessor.setter;
+ }
+
+ if (getter) {
+ output += `
+ if (@TypeOf(${typeName}.${getter}) != StaticGetterType)
+ @compileLog(
+ "Expected ${typeName}.${getter} to be a static getter"
+ );
+`;
+ }
+
+ if (setter) {
+ output += `
+ if (@TypeOf(${typeName}.${setter}) != StaticSetterType)
+ @compileLog(
+ "Expected ${typeName}.${setter} to be a static setter"
+ );`;
+ }
+
+ if (fn) {
+ output += `
+ if (@TypeOf(${typeName}.${fn}) != StaticCallbackType)
+ @compileLog(
+ "Expected ${typeName}.${fn} to be a static callback"
+ );`;
+ }
+ });
+
+ return output;
+ }
+
+ return `
+
+pub const ${className(typeName)} = struct {
+ const ${typeName} = Classes.${typeName};
+ const GetterType = fn(*${typeName}, *JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+ const SetterType = fn(*${typeName}, *JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+ const CallbackType = fn(*${typeName}, *JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+
+ /// Return the pointer to the wrapped object.
+ /// If the object does not match the type, return null.
+ pub fn fromJS(value: JSC.JSValue) ?*${typeName} {
+ JSC.markBinding();
+ return ${symbolName(typeName, "fromJS")}(value);
+ }
+
+ /// Create a new instance of ${typeName}
+ pub fn toJS(this: *${typeName}, globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ JSC.markBinding();
+ if (comptime Environment.allow_assert) {
+ const value__ = ${symbolName(
+ typeName,
+ "create"
+ )}(globalObject, this);
+ std.debug.assert(value__.as(${typeName}).? == this); // If this fails, likely a C ABI issue.
+ return value__;
+ } else {
+ return ${symbolName(typeName, "create")}(globalObject, this);
+ }
+ }
+
+ /// Modify the internal ptr to point to a new instance of ${typeName}.
+ pub fn dangerouslySetPtr(value: JSC.JSValue, ptr: ?*${typeName}) bool {
+ JSC.markBinding();
+ return ${symbolName(typeName, "dangerouslySetPtr")}(value, ptr);
+ }
+
+ extern fn ${symbolName(typeName, "fromJS")}(JSC.JSValue) ?*${typeName};
+
+ extern fn ${symbolName(
+ typeName,
+ "create"
+ )}(globalObject: *JSC.JSGlobalObject, ptr: ?*${typeName}) JSC.JSValue;
+
+ extern fn ${typeName}__dangerouslySetPtr(JSC.JSValue, ?*${typeName}) bool;
+
+ comptime {
+ ${typeCheck()}
+ if (!JSC.is_bindgen) {
+${exports
+ .sort(([a], [b]) => a.localeCompare(b))
+ .map(
+ ([internalName, externalName]) =>
+ `@export(${typeName}.${internalName}, .{.name = "${externalName}"});`
+ )
+ .join("\n ")}
+ }
+ }
+};
+
+
+`;
+}
+
+function generateLazyClassStructureHeader(
+ typeName,
+ { klass = {}, proto = {} }
+) {
+ return `
+ JSC::Structure* ${className(
+ typeName
+ )}Structure() { return m_${className(
+ typeName
+ )}.getInitializedOnMainThread(this); }
+ JSC::JSObject* ${className(
+ typeName
+ )}Constructor() { return m_${className(
+ typeName
+ )}.constructorInitializedOnMainThread(this); }
+ JSC::JSValue ${className(typeName)}Prototype() { return m_${className(
+ typeName
+ )}.prototypeInitializedOnMainThread(this); }
+ JSC::LazyClassStructure m_${className(typeName)};
+ `.trim();
+}
+
+function generateLazyClassStructureImpl(typeName, { klass = {}, proto = {} }) {
+ return `
+ m_${className(typeName)}.initLater(
+ [](LazyClassStructure::Initializer& init) {
+ init.setPrototype(WebCore::${className(
+ typeName
+ )}::createPrototype(init.vm, reinterpret_cast<Zig::GlobalObject*>(init.global)));
+ init.setStructure(WebCore::${className(
+ typeName
+ )}::createStructure(init.vm, init.global, init.prototype));
+ init.setConstructor(WebCore::${constructorName(
+ typeName
+ )}::create(init.vm, init.global, WebCore::${constructorName(
+ typeName
+ )}::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<WebCore::${prototypeName(
+ typeName
+ )}*>(init.prototype)));
+ });
+
+
+ `.trim();
+}
+
+function define({ klass = {}, proto = {}, ...rest } = {}) {
+ return {
+ ...rest,
+ klass: Object.fromEntries(
+ Object.entries(klass).sort(([a], [b]) => a.localeCompare(b))
+ ),
+ proto: Object.fromEntries(
+ Object.entries(proto).sort(([a], [b]) => a.localeCompare(b))
+ ),
+ };
+}
+
+const classes = [
+ define({
+ name: "Request",
+ construct: true,
+ finalize: true,
+ klass: {},
+ JSType: "0b11101110",
+ proto: {
+ url: {
+ getter: "getURL",
+ cache: true,
+ },
+
+ // body: {
+ // getter: "getBody",
+ // },
+
+ text: { fn: "getText" },
+ json: { fn: "getJSON" },
+ arrayBuffer: { fn: "getArrayBuffer" },
+ blob: { fn: "getBlob" },
+ clone: { fn: "doClone", length: 1 },
+ cache: {
+ getter: "getCache",
+ },
+ credentials: {
+ getter: "getCredentials",
+ },
+ destination: {
+ getter: "getDestination",
+ },
+ headers: {
+ getter: "getHeaders",
+ cache: true,
+ },
+ integrity: {
+ getter: "getIntegrity",
+ },
+ method: {
+ getter: "getMethod",
+ },
+ mode: {
+ getter: "getMode",
+ },
+ redirect: {
+ getter: "getRedirect",
+ },
+ referrer: {
+ getter: "getReferrer",
+ },
+ referrerPolicy: {
+ getter: "getReferrerPolicy",
+ },
+ url: {
+ getter: "getUrl",
+ cache: true,
+ },
+ bodyUsed: {
+ getter: "getBodyUsed",
+ },
+ },
+ }),
+
+ define({
+ name: "Response",
+ construct: true,
+ finalize: true,
+ JSType: "0b11101110",
+ klass: {
+ json: {
+ fn: "constructJSON",
+ },
+ redirect: {
+ fn: "constructRedirect",
+ },
+ error: {
+ fn: "constructError",
+ },
+ },
+ proto: {
+ url: {
+ getter: "getURL",
+ cache: true,
+ },
+
+ // body: {
+ // getter: "getBody",
+ // },
+
+ text: { fn: "getText" },
+ json: { fn: "getJSON" },
+ arrayBuffer: { fn: "getArrayBuffer" },
+ blob: { fn: "getBlob" },
+ clone: { fn: "doClone", length: 1 },
+
+ type: {
+ getter: "getResponseType",
+ },
+ headers: {
+ getter: "getHeaders",
+ cache: true,
+ },
+
+ statusText: {
+ getter: "getStatusText",
+ cache: true,
+ },
+ status: {
+ getter: "getStatus",
+ },
+ ok: {
+ getter: "getOK",
+ },
+ bodyUsed: {
+ getter: "getBodyUsed",
+ },
+ },
+ }),
+];
+
+const GENERATED_CLASSES_HEADER = `
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// Generated by src/bun.js/generate-classes.js
+#pragma once
+
+#include "root.h"
+
+namespace Zig {
+}
+
+#include "JSDOMWrapper.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+using namespace Zig;
+using namespace JSC;
+
+`;
+
+const GENERATED_CLASSES_FOOTER = `
+}
+
+`;
+
+const GENERATED_CLASSES_IMPL_HEADER = `
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// Generated by src/bun.js/generate-classes.js
+#include "root.h"
+
+#include "ZigGlobalObject.h"
+
+#include <JavaScriptCore/DOMJITAbstractHeap.h>
+#include "DOMJITIDLConvert.h"
+#include "DOMJITIDLType.h"
+#include "DOMJITIDLTypeFilter.h"
+#include "DOMJITHelpers.h"
+#include <JavaScriptCore/DFGAbstractHeap.h>
+
+#include "JSDOMConvertBufferSource.h"
+#include "ZigGeneratedClasses.h"
+
+
+
+
+namespace WebCore {
+
+using namespace JSC;
+using namespace Zig;
+
+`;
+
+const GENERATED_CLASSES_IMPL_FOOTER = `
+
+} // namespace WebCore
+
+`;
+
+function initLazyClasses(initLaterFunctions) {
+ return `
+
+void GlobalObject::initGeneratedLazyClasses() {
+ ${initLaterFunctions.map((a) => a.trim()).join("\n ")}
+}
+
+`.trim();
+}
+
+function visitLazyClasses(classes) {
+ return `
+
+template<typename Visitor>
+void GlobalObject::visitGeneratedLazyClasses(GlobalObject *thisObject, Visitor& visitor)
+{
+ ${classes
+ .map((a) => `thisObject->m_${className(a.name)}.visit(visitor);`)
+ .join("\n ")}
+}
+
+ `.trim();
+}
+
+const ZIG_GENERATED_CLASSES_HEADER = `
+const JSC = @import("javascript_core");
+const Classes = @import("./generated_classes_list.zig").Classes;
+const Environment = @import("../../env.zig");
+const std = @import("std");
+
+const StaticGetterType = fn(*JSC.JSGlobalObject) callconv(.C) JSC.JSValue;
+const StaticSetterType = fn(*JSC.JSGlobalObject, JSC.JSValue) callconv(.C) bool;
+const StaticCallbackType = fn(*JSC.JSGlobalObject, *JSC.CallFrame) callconv(.C) JSC.JSValue;
+
+
+
+`;
+await Bun.write(`${import.meta.dir}/bindings/generated_classes.zig`, [
+ ZIG_GENERATED_CLASSES_HEADER,
+ ...classes.map((a) => generateZig(a.name, a).trim()).join("\n"),
+]);
+await Bun.write(`${import.meta.dir}/bindings/ZigGeneratedClasses.h`, [
+ GENERATED_CLASSES_HEADER,
+ ...classes.map((a) => generateHeader(a.name, a)),
+ GENERATED_CLASSES_FOOTER,
+]);
+await Bun.write(`${import.meta.dir}/bindings/ZigGeneratedClasses.cpp`, [
+ GENERATED_CLASSES_IMPL_HEADER,
+ ...classes.map((a) => generateImpl(a.name, a)),
+ GENERATED_CLASSES_IMPL_FOOTER,
+]);
+await Bun.write(
+ `${import.meta.dir}/bindings/ZigGeneratedClasses+lazyStructureHeader.h`,
+ classes.map((a) => generateLazyClassStructureHeader(a.name, a)).join("\n")
+);
+
+await Bun.write(
+ `${import.meta.dir}/bindings/ZigGeneratedClasses+DOMClientIsoSubspaces.h`,
+ classes.map((a) =>
+ [
+ `std::unique_ptr<GCClient::IsoSubspace> ${clientSubspaceFor(a.name)};`,
+ `std::unique_ptr<GCClient::IsoSubspace> ${clientSubspaceFor(
+ a.name
+ )}Constructor;`,
+ ].join("\n")
+ )
+);
+
+await Bun.write(
+ `${import.meta.dir}/bindings/ZigGeneratedClasses+DOMIsoSubspaces.h`,
+ classes.map((a) =>
+ [
+ `std::unique_ptr<IsoSubspace> ${subspaceFor(a.name)};`,
+ `std::unique_ptr<IsoSubspace> ${subspaceFor(a.name)}Constructor;`,
+ ].join("\n")
+ )
+);
+
+await Bun.write(
+ `${import.meta.dir}/bindings/ZigGeneratedClasses+lazyStructureImpl.h`,
+ initLazyClasses(
+ classes.map((a) => generateLazyClassStructureImpl(a.name, a))
+ ) +
+ "\n" +
+ visitLazyClasses(classes)
+);
diff --git a/src/bun.js/headergen/sizegen.cpp b/src/bun.js/headergen/sizegen.cpp
index f12cea820..49b64e0e9 100644
--- a/src/bun.js/headergen/sizegen.cpp
+++ b/src/bun.js/headergen/sizegen.cpp
@@ -50,7 +50,7 @@ int main() {
"in the output. That's how all the bJSC__.* types are created - from "
"these values. \n";
int i = 0;
- int len = 31;
+ int len = 31 - 3;
for (i = 0; i < len; i++) {
cout << "pub const " << names[i] << " = " << sizes[i] << ";\n";
cout << "pub const " << names[i] << "_align = " << aligns[i] << ";\n";
@@ -61,5 +61,29 @@ int main() {
<< JSC::JSArrayBufferView::offsetOfVector() << ";\n";
cout << "pub const Bun_FFI_PointerOffsetToTypedArrayLength = "
<< JSC::JSArrayBufferView::offsetOfLength() << ";\n";
+ cout << "pub const Bun_CallFrame__codeBlock = ";
+
+ cout << static_cast<int>(JSC::CallFrameSlot::codeBlock) << ";\n";
+ cout << "pub const Bun_CallFrame__callee = ";
+
+ cout << static_cast<int>(JSC::CallFrameSlot::callee) << ";\n";
+ cout << "pub const Bun_CallFrame__argumentCountIncludingThis = ";
+
+ cout << static_cast<int>(JSC::CallFrameSlot::argumentCountIncludingThis)
+ << ";\n";
+ cout << "pub const Bun_CallFrame__thisArgument = ";
+
+ cout << static_cast<int>(JSC::CallFrameSlot::thisArgument) << ";\n";
+ cout << "pub const Bun_CallFrame__firstArgument = ";
+
+ cout << static_cast<int>(JSC::CallFrameSlot::firstArgument) << ";\n";
+
+ cout << "pub const Bun_CallFrame__size = ";
+
+ cout << sizeof(JSC::CallFrame) << ";\n";
+
+ cout << "pub const Bun_CallFrame__align = ";
+
+ cout << alignof(JSC::CallFrame) << ";\n";
return 0;
} \ No newline at end of file
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 3290e2ada..75220d58a 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -89,9 +89,6 @@ const ThreadSafeFunction = JSC.napi.ThreadSafeFunction;
pub const GlobalConstructors = [_]type{
WebCore.Blob.Constructor,
WebCore.TextDecoder.Constructor,
- // WebCore.TextEncoder.Constructor,
- Request.Constructor,
- Response.Constructor,
JSC.Cloudflare.HTMLRewriter.Constructor,
};
@@ -1732,7 +1729,7 @@ pub const VirtualMachine = struct {
return;
}
- if (js.JSValueIsObject(this.global.ref(), value.asRef())) {
+ if (value.isObject()) {
if (js.JSObjectGetPrivate(value.asRef())) |priv| {
was_internal = this.printErrorFromMaybePrivateData(
priv,
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 6cbfe3226..bee8467e6 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -659,8 +659,8 @@ pub const TestScope = struct {
args = args[1..];
}
- var function = args[0];
- if (!js.JSValueIsObject(ctx, function) or !js.JSObjectIsFunction(ctx, function)) {
+ var function = args[0].?.value();
+ if (!function.isCell() or !function.isCallable(ctx.vm())) {
JSError(getAllocator(ctx), "test() expects a function", .{}, ctx, exception);
return this;
}
@@ -672,11 +672,11 @@ pub const TestScope = struct {
if (!is_only and Jest.runner.?.only)
return this;
- js.JSValueProtect(ctx, function);
+ js.JSValueProtect(ctx, function.asObjectRef());
DescribeScope.active.tests.append(getAllocator(ctx), TestScope{
.label = label,
- .callback = function,
+ .callback = function.asObjectRef(),
.parent = DescribeScope.active,
}) catch unreachable;
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index 0f6a16bc1..a1057971e 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -45,20 +45,21 @@ const StringJoiner = @import("../../string_joiner.zig");
const uws = @import("uws");
pub const Response = struct {
+ pub usingnamespace JSC.Codegen.JSResponse;
pub const Pool = struct {
- response_objects_pool: [127]JSC.C.JSObjectRef = undefined,
+ response_objects_pool: [127]JSC.JSValue = undefined,
response_objects_used: u8 = 0,
- pub fn get(this: *Pool, ptr: *Response) ?JSC.C.JSObjectRef {
+ pub fn get(this: *Pool, ptr: *Response) ?JSValue {
if (comptime JSC.is_bindgen)
unreachable;
if (this.response_objects_used > 0) {
var result = this.response_objects_pool[this.response_objects_used - 1];
this.response_objects_used -= 1;
- if (JSC.C.JSObjectSetPrivate(result, JSPrivateDataPtr.init(ptr).ptr())) {
+ if (Response.dangerouslySetPtr(result, ptr)) {
return result;
} else {
- JSC.C.JSValueUnprotect(VirtualMachine.vm.global.ref(), result);
+ JSC.C.JSValueUnprotect(VirtualMachine.vm.global.ref(), result.asObjectRef());
}
}
@@ -73,87 +74,16 @@ pub const Response = struct {
}
if (object.as(Response)) |resp| {
- _ = JSC.C.JSObjectSetPrivate(object.asObjectRef(), null);
+ _ = Response.dangerouslySetPtr(object, null);
_ = resp.body.use();
resp.finalize();
- remaining[0] = object.asObjectRef();
+ remaining[0] = object;
this.response_objects_used += 1;
}
}
};
- pub const Constructor = JSC.NewConstructor(
- Response,
- .{
- .@"constructor" = constructor,
- .@"json" = .{ .rfn = constructJSON },
- .@"redirect" = .{ .rfn = constructRedirect },
- .@"error" = .{ .rfn = constructError },
- },
- .{},
- );
-
- pub const Class = NewClass(
- Response,
- .{ .name = "Response" },
- .{
- .@"finalize" = finalize,
- .@"text" = .{
- .rfn = Response.getText,
- .ts = d.ts{},
- },
- .@"json" = .{
- .rfn = Response.getJSON,
- .ts = d.ts{},
- },
- .@"arrayBuffer" = .{
- .rfn = Response.getArrayBuffer,
- .ts = d.ts{},
- },
- .@"blob" = .{
- .rfn = Response.getBlob,
- .ts = d.ts{},
- },
-
- .@"clone" = .{
- .rfn = doClone,
- .ts = d.ts{},
- },
- },
- .{
- .@"url" = .{
- .@"get" = getURL,
- .ro = true,
- },
-
- .@"ok" = .{
- .@"get" = getOK,
- .ro = true,
- },
- .@"status" = .{
- .@"get" = getStatus,
- .ro = true,
- },
- .@"statusText" = .{
- .@"get" = getStatusText,
- .ro = true,
- },
- .@"headers" = .{
- .@"get" = getHeaders,
- .ro = true,
- },
- .@"bodyUsed" = .{
- .@"get" = getBodyUsed,
- .ro = true,
- },
- .@"type" = .{
- .@"get" = getResponseType,
- .ro = true,
- },
- },
- );
-
allocator: std.mem.Allocator,
body: Body,
url: string = "",
@@ -225,59 +155,44 @@ pub const Response = struct {
pub fn getURL(
this: *Response,
- ctx: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/url
- return ZigString.init(this.url).toValueGC(ctx.ptr()).asObjectRef();
+ return ZigString.init(this.url).toValueGC(globalThis);
}
pub fn getResponseType(
this: *Response,
- ctx: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
if (this.body.init.status_code < 200) {
- return ZigString.init("error").toValue(ctx.ptr()).asObjectRef();
+ return ZigString.init("error").toValue(globalThis);
}
- return ZigString.init("basic").toValue(ctx.ptr()).asObjectRef();
+ return ZigString.init("basic").toValue(globalThis);
}
pub fn getBodyUsed(
this: *Response,
- _: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return JSC.JSValue.jsBoolean(this.body.value == .Used).asRef();
+ _: *JSC.JSGlobalObject,
+ ) callconv(.C) JSValue {
+ return JSValue.jsBoolean(this.body.value == .Used);
}
pub fn getStatusText(
this: *Response,
- ctx: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/url
- return ZigString.init(this.status_text).withEncoding().toValueGC(ctx.ptr()).asObjectRef();
+ return ZigString.init(this.status_text).withEncoding().toValueGC(globalThis);
}
pub fn getOK(
this: *Response,
- ctx: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ _: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
- return js.JSValueMakeBoolean(ctx, this.isOK());
+ return JSValue.jsBoolean(this.isOK());
}
fn getOrCreateHeaders(this: *Response) *FetchHeaders {
@@ -289,24 +204,18 @@ pub const Response = struct {
pub fn getHeaders(
this: *Response,
- ctx: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return this.getOrCreateHeaders().toJS(ctx.ptr()).asObjectRef();
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return this.getOrCreateHeaders().toJS(globalThis);
}
pub fn doClone(
this: *Response,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSObjectRef,
- _: []const js.JSValueRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- var cloned = this.clone(getAllocator(ctx), ctx.ptr());
- var val = Response.makeMaybePooled(ctx, cloned);
+ globalThis: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ var cloned = this.clone(getAllocator(globalThis), globalThis);
+ const val = Response.makeMaybePooled(globalThis, cloned);
if (this.body.init.headers) |headers| {
cloned.body.init.headers = headers.cloneThis();
}
@@ -314,18 +223,8 @@ pub const Response = struct {
return val;
}
- pub fn makeMaybePooled(ctx: js.JSContextRef, ptr: *Response) JSC.C.JSObjectRef {
- if (comptime JSC.is_bindgen)
- unreachable;
- var vm = ctx.bunVM();
- if (vm.response_objects_pool) |pool| {
- if (pool.get(ptr)) |object| {
- JSC.C.JSValueUnprotect(ctx, object);
- return object;
- }
- }
-
- return Response.Class.make(ctx, ptr);
+ pub fn makeMaybePooled(globalObject: *JSC.JSGlobalObject, ptr: *Response) JSValue {
+ return ptr.toJS(globalObject);
}
pub fn cloneInto(
@@ -349,22 +248,19 @@ pub const Response = struct {
return new_response;
}
- pub usingnamespace BlobInterface(@This());
+ pub usingnamespace NewBlobInterface(@This());
pub fn getStatus(
this: *Response,
- ctx: js.JSContextRef,
- _: js.JSValueRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ _: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/status
- return js.JSValueMakeNumber(ctx, @intToFloat(f64, this.body.init.status_code));
+ return JSValue.jsNumber(this.body.init.status_code);
}
pub fn finalize(
this: *Response,
- ) void {
+ ) callconv(.C) void {
this.body.deinit(this.allocator);
var allocator = this.allocator;
@@ -410,16 +306,13 @@ pub const Response = struct {
}
pub fn constructJSON(
- _: void,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSObjectRef,
- arguments: []const js.JSValueRef,
- _: js.ExceptionRef,
- ) js.JSObjectRef {
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ const args_list = callframe.arguments(2);
// https://github.com/remix-run/remix/blob/db2c31f64affb2095e4286b91306b96435967969/packages/remix-server-runtime/responses.ts#L4
- var args = JSC.Node.ArgumentsSlice.from(ctx.bunVM(), arguments);
- // var response = getAllocator(ctx).create(Response) catch unreachable;
+ var args = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), args_list.ptr[0..args_list.len]);
+ // var response = getAllocator(globalThis).create(Response) catch unreachable;
var response = Response{
.body = Body{
@@ -428,7 +321,7 @@ pub const Response = struct {
},
.value = Body.Value.empty,
},
- .allocator = getAllocator(ctx),
+ .allocator = getAllocator(globalThis),
.url = "",
};
@@ -438,18 +331,18 @@ pub const Response = struct {
var zig_str = JSC.ZigString.init("");
// calling JSON.stringify on an empty string adds extra quotes
// so this is correct
- json_value.jsonStringify(ctx.ptr(), 0, &zig_str);
+ json_value.jsonStringify(globalThis.ptr(), 0, &zig_str);
if (zig_str.len > 0) {
- var zig_str_slice = zig_str.toSlice(getAllocator(ctx));
+ var zig_str_slice = zig_str.toSlice(getAllocator(globalThis));
if (zig_str_slice.allocated) {
response.body.value = .{
- .Blob = Blob.initWithAllASCII(zig_str_slice.mut(), zig_str_slice.allocator, ctx.ptr(), false),
+ .Blob = Blob.initWithAllASCII(zig_str_slice.mut(), zig_str_slice.allocator, globalThis.ptr(), false),
};
} else {
response.body.value = .{
- .Blob = Blob.initWithAllASCII(getAllocator(ctx).dupe(u8, zig_str_slice.slice()) catch unreachable, zig_str_slice.allocator, ctx.ptr(), true),
+ .Blob = Blob.initWithAllASCII(getAllocator(globalThis).dupe(u8, zig_str_slice.slice()) catch unreachable, zig_str_slice.allocator, globalThis.ptr(), true),
};
}
}
@@ -459,7 +352,7 @@ pub const Response = struct {
if (init.isUndefinedOrNull()) {} else if (init.isNumber()) {
response.body.init.status_code = @intCast(u16, @minimum(@maximum(0, init.toInt32()), std.math.maxInt(u16)));
} else {
- if (Body.Init.init(getAllocator(ctx), ctx, init) catch null) |_init| {
+ if (Body.Init.init(getAllocator(globalThis), globalThis, init) catch null) |_init| {
response.body.init = _init;
}
}
@@ -470,19 +363,16 @@ pub const Response = struct {
var ptr = response.allocator.create(Response) catch unreachable;
ptr.* = response;
- return Response.makeMaybePooled(ctx, ptr);
+ return ptr.toJS(globalThis);
}
pub fn constructRedirect(
- _: void,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSObjectRef,
- arguments: []const js.JSValueRef,
- _: js.ExceptionRef,
- ) js.JSObjectRef {
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ var args_list = callframe.arguments(4);
// https://github.com/remix-run/remix/blob/db2c31f64affb2095e4286b91306b96435967969/packages/remix-server-runtime/responses.ts#L4
- var args = JSC.Node.ArgumentsSlice.from(ctx.bunVM(), arguments);
- // var response = getAllocator(ctx).create(Response) catch unreachable;
+ var args = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), args_list.ptr[0..args_list.len]);
+ // var response = getAllocator(globalThis).create(Response) catch unreachable;
var response = Response{
.body = Body{
@@ -491,7 +381,7 @@ pub const Response = struct {
},
.value = Body.Value.empty,
},
- .allocator = getAllocator(ctx),
+ .allocator = getAllocator(globalThis),
.url = "",
};
@@ -499,16 +389,16 @@ pub const Response = struct {
var url_string = ZigString.init("");
if (@enumToInt(url_string_value) != 0) {
- url_string = url_string_value.getZigString(ctx.ptr());
+ url_string = url_string_value.getZigString(globalThis.ptr());
}
- var url_string_slice = url_string.toSlice(getAllocator(ctx));
+ var url_string_slice = url_string.toSlice(getAllocator(globalThis));
defer url_string_slice.deinit();
if (args.nextEat()) |init| {
if (init.isUndefinedOrNull()) {} else if (init.isNumber()) {
response.body.init.status_code = @intCast(u16, @minimum(@maximum(0, init.toInt32()), std.math.maxInt(u16)));
} else {
- if (Body.Init.init(getAllocator(ctx), ctx, init) catch null) |_init| {
+ if (Body.Init.init(getAllocator(globalThis), globalThis, init) catch null) |_init| {
response.body.init = _init;
response.body.init.status_code = 302;
}
@@ -521,17 +411,13 @@ pub const Response = struct {
var ptr = response.allocator.create(Response) catch unreachable;
ptr.* = response;
- return Response.makeMaybePooled(ctx, ptr);
+ return ptr.toJS(globalThis);
}
pub fn constructError(
- _: void,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSObjectRef,
- _: []const js.JSValueRef,
- _: js.ExceptionRef,
- ) js.JSObjectRef {
- var response = getAllocator(ctx).create(Response) catch unreachable;
+ globalThis: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ var response = getAllocator(globalThis).create(Response) catch unreachable;
response.* = Response{
.body = Body{
.init = Body.Init{
@@ -539,51 +425,45 @@ pub const Response = struct {
},
.value = Body.Value.empty,
},
- .allocator = getAllocator(ctx),
+ .allocator = getAllocator(globalThis),
.url = "",
};
- return Response.makeMaybePooled(
- ctx,
- response,
- );
+ return response.toJS(globalThis);
}
pub fn constructor(
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- arguments: []const js.JSValueRef,
- exception: js.ExceptionRef,
- ) js.JSObjectRef {
- const body: Body = brk: {
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) ?*Response {
+ const args_list = callframe.arguments(4);
+ const arguments = args_list.ptr[0..args_list.len];
+ const body: Body = @as(?Body, brk: {
switch (arguments.len) {
0 => {
- break :brk Body.@"200"(ctx);
+ break :brk Body.@"200"(globalThis);
},
1 => {
- break :brk Body.extract(ctx, arguments[0], exception);
+ break :brk Body.extract(globalThis, arguments[0]);
},
else => {
- if (js.JSValueGetType(ctx, arguments[1]) == js.JSType.kJSTypeObject) {
- break :brk Body.extractWithInit(ctx, arguments[0], arguments[1], exception);
+ if (arguments[1].jsType().isObject()) {
+ break :brk Body.extractWithInit(globalThis, arguments[0], arguments[1]);
} else {
- break :brk Body.extract(ctx, arguments[0], exception);
+ break :brk Body.extract(globalThis, arguments[0]);
}
},
}
unreachable;
- };
+ }) orelse return null;
- var response = getAllocator(ctx).create(Response) catch unreachable;
+ var response = getAllocator(globalThis).create(Response) catch unreachable;
response.* = Response{
.body = body,
- .allocator = getAllocator(ctx),
+ .allocator = getAllocator(globalThis),
.url = "",
};
- return Response.makeMaybePooled(
- ctx,
- response,
- );
+ return response;
}
};
@@ -780,7 +660,7 @@ pub const Fetch = struct {
},
},
};
- return JSValue.fromRef(Response.makeMaybePooled(@ptrCast(js.JSContextRef, this.global_this), response));
+ return Response.makeMaybePooled(@ptrCast(js.JSContextRef, this.global_this), response);
}
pub fn get(
@@ -886,15 +766,15 @@ pub const Fetch = struct {
NetworkThread.init() catch @panic("Failed to start network thread");
url = ZigURL.parse(url_str);
- if (arguments.len >= 2 and js.JSValueIsObject(ctx, arguments[1])) {
+ if (arguments.len >= 2 and arguments[1].?.value().isObject()) {
var options = JSValue.fromRef(arguments[1]);
- if (options.get(ctx.ptr(), "method")) |method_| {
+ if (options.fastGet(ctx.ptr(), .method)) |method_| {
var slice_ = method_.toSlice(ctx.ptr(), getAllocator(ctx));
defer slice_.deinit();
method = Method.which(slice_.slice()) orelse .GET;
}
- if (options.get(ctx.ptr(), "headers")) |headers_| {
+ if (options.fastGet(ctx.ptr(), .headers)) |headers_| {
if (headers_.as(FetchHeaders)) |headers__| {
headers = Headers.from(headers__, bun.default_allocator) catch unreachable;
// TODO: make this one pass
@@ -904,7 +784,7 @@ pub const Fetch = struct {
}
}
- if (options.get(ctx.ptr(), "body")) |body__| {
+ if (options.fastGet(ctx.ptr(), .body)) |body__| {
if (Blob.fromJS(ctx.ptr(), body__, true, false)) |new_blob| {
if (new_blob.size > 0) {
body = MutableString{
@@ -923,7 +803,7 @@ pub const Fetch = struct {
}
}
}
- } else if (first_arg.asCheckLoaded(Request)) |request| {
+ } else if (first_arg.as(Request)) |request| {
url = ZigURL.parse(request.url.dupe(getAllocator(ctx)) catch unreachable);
method = request.method;
if (request.headers) |head| {
@@ -2759,11 +2639,11 @@ pub const Blob = struct {
Blob,
.{ .name = "Blob" },
.{ .finalize = finalize, .text = .{
- .rfn = getText,
+ .rfn = getText_c,
}, .json = .{
- .rfn = getJSON,
+ .rfn = getJSON_c,
}, .arrayBuffer = .{
- .rfn = getArrayBuffer,
+ .rfn = getArrayBuffer_c,
}, .slice = .{
.rfn = getSlice,
}, .stream = .{
@@ -2816,11 +2696,21 @@ pub const Blob = struct {
if (value.jsType() == .JSPromise)
return value;
- return JSC.JSPromise.resolvedPromiseValue(global, value);
+ return JSPromise.resolvedPromiseValue(
+ global,
+ value,
+ );
}
pub fn getText(
this: *Blob,
+ globalThis: *JSC.JSGlobalObject,
+ ) JSC.JSValue {
+ return promisified(this.toString(globalThis, .clone), globalThis);
+ }
+
+ pub fn getText_c(
+ this: *Blob,
ctx: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
@@ -2832,13 +2722,28 @@ pub const Blob = struct {
pub fn getTextTransfer(
this: *Blob,
+ globalObject: *JSC.JSGlobalObject,
+ ) JSC.JSValue {
+ return promisified(this.toString(globalObject, .transfer), globalObject);
+ }
+
+ pub fn getTextTransfer_c(
+ this: *Blob,
ctx: js.JSContextRef,
) JSC.C.JSObjectRef {
- return promisified(this.toString(ctx.ptr(), .transfer), ctx.ptr()).asObjectRef();
+ return this.getTextTransfer(ctx).asObjectRef();
}
pub fn getJSON(
this: *Blob,
+ globalThis: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ return promisified(this.toJSON(globalThis, .share), globalThis);
+ }
+
+ pub fn getJSON_c(
+ this: *Blob,
ctx: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
@@ -2850,6 +2755,13 @@ pub const Blob = struct {
pub fn getArrayBufferTransfer(
this: *Blob,
+ globalThis: *JSC.JSGlobalObject,
+ ) JSC.JSValue {
+ return promisified(this.toArrayBuffer(globalThis, .transfer), globalThis);
+ }
+
+ pub fn getArrayBufferTransfer_c(
+ this: *Blob,
ctx: js.JSContextRef,
) JSC.C.JSObjectRef {
return promisified(this.toArrayBuffer(ctx.ptr(), .transfer), ctx.ptr()).asObjectRef();
@@ -2857,6 +2769,14 @@ pub const Blob = struct {
pub fn getArrayBuffer(
this: *Blob,
+ globalThis: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSValue {
+ return promisified(this.toArrayBuffer(globalThis, .clone), globalThis);
+ }
+
+ pub fn getArrayBuffer_c(
+ this: *Blob,
ctx: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
@@ -3042,7 +2962,7 @@ pub const Blob = struct {
// representing the media type of the Blob.
// Normative conditions for this member are provided
// in the § 3.1 Constructors.
- if (options.get(ctx.ptr(), "type")) |content_type| {
+ if (options.get(ctx.ptr(), "type")) |content_type| {
if (content_type.isString()) {
var content_type_str = content_type.getZigString(ctx.ptr());
if (!content_type_str.is16Bit()) {
@@ -3471,24 +3391,8 @@ pub const Blob = struct {
fromJSCloneOptionalArray
else
fromJSClone;
- const DeferCtx = struct {
- args: std.meta.ArgsTuple(@TypeOf(FromJSFunction)),
- ret: anyerror!Blob = undefined,
- pub fn run(ctx: ?*anyopaque) callconv(.C) void {
- var that = bun.cast(*@This(), ctx.?);
- that.ret = @call(.{}, FromJSFunction, that.args);
- }
- };
- var ctx = DeferCtx{
- .args = .{
- global,
- arg,
- },
- .ret = undefined,
- };
- global.vm().deferGC(&ctx, DeferCtx.run);
- return ctx.ret;
+ return FromJSFunction(global, arg);
}
fn fromJSWithoutDeferGC(
@@ -3504,6 +3408,8 @@ pub const Blob = struct {
var top_value = current;
var might_only_be_one_thing = false;
+ arg.ensureStillAlive();
+ defer arg.ensureStillAlive();
switch (current.jsTypeLoose()) {
.Array, .DerivedArray => {
var top_iter = JSC.JSArrayIterator.init(current, global);
@@ -3562,23 +3468,25 @@ pub const Blob = struct {
return Blob.init(buf, bun.default_allocator, global);
},
- else => {
- if (JSC.C.JSObjectGetPrivate(top_value.asObjectRef())) |priv| {
- var data = JSC.JSPrivateDataPtr.from(priv);
- switch (data.tag()) {
- .Blob => {
- var blob: *Blob = data.as(Blob);
- if (comptime move) {
- var _blob = blob.*;
- _blob.allocator = null;
- blob.transfer();
- return _blob;
- } else {
- return blob.dupe();
- }
- },
+ else => |tag| {
+ if (tag != .DOMWrapper) {
+ if (JSC.C.JSObjectGetPrivate(top_value.asObjectRef())) |priv| {
+ var data = JSC.JSPrivateDataPtr.from(priv);
+ switch (data.tag()) {
+ .Blob => {
+ var blob: *Blob = data.as(Blob);
+ if (comptime move) {
+ var _blob = blob.*;
+ _blob.allocator = null;
+ blob.transfer();
+ return _blob;
+ } else {
+ return blob.dupe();
+ }
+ },
- else => return Blob.initEmpty(global),
+ else => return Blob.initEmpty(global),
+ }
}
}
},
@@ -3683,6 +3591,8 @@ pub const Blob = struct {
}
},
+ .DOMWrapper => {},
+
JSC.JSValue.JSType.ArrayBuffer,
JSC.JSValue.JSType.Int8Array,
JSC.JSValue.JSType.Uint8Array,
@@ -3812,13 +3722,13 @@ pub const Body = struct {
return that;
}
- pub fn init(allocator: std.mem.Allocator, ctx: js.JSContextRef, response_init: JSC.JSValue) !?Init {
+ pub fn init(allocator: std.mem.Allocator, ctx: *JSGlobalObject, response_init: JSC.JSValue) !?Init {
var result = Init{ .status_code = 200 };
if (!response_init.isCell())
return null;
- if (response_init.get(ctx, "headers")) |headers| {
+ if (response_init.fastGet(ctx, .headers)) |headers| {
if (headers.as(FetchHeaders)) |orig| {
result.headers = orig.cloneThis();
} else {
@@ -3826,13 +3736,13 @@ pub const Body = struct {
}
}
- if (response_init.get(ctx, "status")) |status_value| {
+ if (response_init.fastGet(ctx, .status)) |status_value| {
const number = status_value.to(i32);
if (number > 0)
result.status_code = @truncate(u16, @intCast(u32, number));
}
- if (response_init.get(ctx, "method")) |method_value| {
+ if (response_init.fastGet(ctx, .method)) |method_value| {
var method_str = method_value.toSlice(ctx, allocator);
defer method_str.deinit();
if (method_str.len > 0) {
@@ -3964,14 +3874,14 @@ pub const Body = struct {
switch (locked.action) {
.getText => {
- promise.asPromise().?.resolve(global, JSValue.fromRef(blob.getTextTransfer(global.ref())));
+ promise.asPromise().?.resolve(global, blob.getTextTransfer(global.ref()));
},
.getJSON => {
promise.asPromise().?.resolve(global, blob.toJSON(global, .share));
blob.detach();
},
.getArrayBuffer => {
- promise.asPromise().?.resolve(global, JSValue.fromRef(blob.getArrayBufferTransfer(global.ref())));
+ promise.asPromise().?.resolve(global, blob.getArrayBufferTransfer(global));
},
.getBlob => {
var ptr = bun.default_allocator.create(Blob) catch unreachable;
@@ -4107,53 +4017,56 @@ pub const Body = struct {
};
}
- pub fn extract(ctx: js.JSContextRef, body_ref: js.JSObjectRef, exception: js.ExceptionRef) Body {
+ pub fn extract(
+ globalThis: *JSGlobalObject,
+ value: JSValue,
+ ) ?Body {
return extractBody(
- ctx,
- body_ref,
+ globalThis,
+ value,
false,
- null,
- exception,
+ JSValue.zero,
);
}
- pub fn extractWithInit(ctx: js.JSContextRef, body_ref: js.JSObjectRef, init_ref: js.JSValueRef, exception: js.ExceptionRef) Body {
+ pub fn extractWithInit(
+ globalThis: *JSGlobalObject,
+ value: JSValue,
+ init: JSValue,
+ ) ?Body {
return extractBody(
- ctx,
- body_ref,
+ globalThis,
+ value,
true,
- init_ref,
- exception,
+ init,
);
}
// https://github.com/WebKit/webkit/blob/main/Source/WebCore/Modules/fetch/FetchBody.cpp#L45
inline fn extractBody(
- ctx: js.JSContextRef,
- body_ref: js.JSObjectRef,
+ globalThis: *JSGlobalObject,
+ value: JSValue,
comptime has_init: bool,
- init_ref: js.JSValueRef,
- exception: js.ExceptionRef,
- ) Body {
+ init: JSValue,
+ ) ?Body {
var body = Body{
.init = Init{ .headers = null, .status_code = 200 },
};
- const value = JSC.JSValue.fromRef(body_ref);
- var allocator = getAllocator(ctx);
+ var allocator = getAllocator(globalThis);
if (comptime has_init) {
- if (Init.init(allocator, ctx, JSValue.c(init_ref))) |maybeInit| {
+ if (Init.init(allocator, globalThis, init)) |maybeInit| {
if (maybeInit) |init_| {
body.init = init_;
}
} else |_| {}
}
- if (JSC.WebCore.ReadableStream.fromJS(value, ctx)) |readable| {
+ if (JSC.WebCore.ReadableStream.fromJS(value, globalThis)) |readable| {
switch (readable.ptr) {
.Blob => |blob| {
body.value = .{
- .Blob = Blob.initWithStore(blob.store, ctx),
+ .Blob = Blob.initWithStore(blob.store, globalThis),
};
blob.store.ref();
@@ -4168,19 +4081,19 @@ pub const Body = struct {
else => {},
}
- body.value = Body.Value.fromReadableStream(readable, ctx);
+ body.value = Body.Value.fromReadableStream(readable, globalThis);
return body;
}
body.value = .{
- .Blob = Blob.fromJS(ctx.ptr(), value, true, false) catch |err| {
+ .Blob = Blob.fromJS(globalThis, value, true, false) catch |err| {
if (err == error.InvalidArguments) {
- JSC.JSError(allocator, "Expected an Array", .{}, ctx, exception);
- return body;
+ globalThis.throwInvalidArguments("Expected an Array", .{});
+ return null;
}
- JSC.JSError(allocator, "Out of memory", .{}, ctx, exception);
- return body;
+ globalThis.throwInvalidArguments("Invalid Body object", .{});
+ return null;
},
};
@@ -4198,6 +4111,8 @@ pub const Request = struct {
method: Method = Method.GET,
uws_request: ?*uws.Request = null,
+ pub usingnamespace JSC.Codegen.JSRequest;
+
pub fn writeFormat(this: *const Request, formatter: *JSC.Formatter, writer: anytype, comptime enable_ansi_colors: bool) !void {
const Writer = @TypeOf(writer);
try formatter.writeIndent(Writer, writer);
@@ -4242,7 +4157,7 @@ pub const Request = struct {
if (this.headers) |headers| {
// Remember, we always lowercase it
// hopefully doesn't matter here tho
- if (headers.get("content-type")) |content_type| {
+ if (headers.fastGet(.ContentType)) |content_type| {
return content_type;
}
}
@@ -4259,134 +4174,36 @@ pub const Request = struct {
}
}
- pub const Constructor = JSC.NewConstructor(
- Request,
- .{
- .constructor = .{ .rfn = constructor },
- },
- .{},
- );
-
- pub const Class = NewClass(
- Request,
- .{
- .name = "Request",
- .read_only = true,
- },
- .{
- .finalize = finalize,
- .text = .{
- .rfn = Request.getText,
- },
- .json = .{
- .rfn = Request.getJSON,
- },
- .arrayBuffer = .{
- .rfn = Request.getArrayBuffer,
- },
- .blob = .{
- .rfn = Request.getBlob,
- },
- .clone = .{
- .rfn = Request.doClone,
- },
- },
- .{
- .@"cache" = .{
- .@"get" = getCache,
- .@"ro" = true,
- },
- .@"credentials" = .{
- .@"get" = getCredentials,
- .@"ro" = true,
- },
- .@"destination" = .{
- .@"get" = getDestination,
- .@"ro" = true,
- },
- .@"headers" = .{
- .@"get" = getHeaders,
- .@"ro" = true,
- },
- .@"integrity" = .{
- .@"get" = getIntegrity,
- .@"ro" = true,
- },
- .@"method" = .{
- .@"get" = getMethod,
- .@"ro" = true,
- },
- .@"mode" = .{
- .@"get" = getMode,
- .@"ro" = true,
- },
- .@"redirect" = .{
- .@"get" = getRedirect,
- .@"ro" = true,
- },
- .@"referrer" = .{
- .@"get" = getReferrer,
- .@"ro" = true,
- },
- .@"referrerPolicy" = .{
- .@"get" = getReferrerPolicy,
- .@"ro" = true,
- },
- .@"url" = .{
- .@"get" = getUrl,
- .@"ro" = true,
- },
- .@"bodyUsed" = .{
- .@"get" = getBodyUsed,
- .@"ro" = true,
- },
- },
- );
-
pub fn getCache(
_: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return js.JSValueMakeString(ctx, ZigString.init(Properties.UTF8.default).toValueGC(ctx.ptr()).asRef());
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.init(Properties.UTF8.default).toValueGC(globalThis);
}
pub fn getCredentials(
_: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return js.JSValueMakeString(ctx, ZigString.init(Properties.UTF8.include).toValueGC(ctx.ptr()).asRef());
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.init(Properties.UTF8.include).toValueGC(globalThis);
}
pub fn getDestination(
_: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return js.JSValueMakeString(ctx, ZigString.init("").toValueGC(ctx.ptr()).asRef());
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.init("").toValueGC(globalThis);
}
pub fn getIntegrity(
_: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return ZigString.Empty.toValueGC(ctx.ptr()).asRef();
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.Empty.toValueGC(globalThis);
}
+
pub fn getMethod(
this: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
const string_contents: string = switch (this.method) {
.GET => Properties.UTF8.GET,
.HEAD => Properties.UTF8.HEAD,
@@ -4397,20 +4214,17 @@ pub const Request = struct {
else => "",
};
- return ZigString.init(string_contents).toValue(ctx.ptr()).asRef();
+ return ZigString.init(string_contents).toValueGC(globalThis);
}
pub fn getMode(
_: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return ZigString.init(Properties.UTF8.navigate).toValue(ctx.ptr()).asRef();
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.init(Properties.UTF8.navigate).toValue(globalThis);
}
- pub fn finalize(this: *Request) void {
+ pub fn finalize(this: *Request) callconv(.C) void {
if (this.headers) |headers| {
headers.deref();
this.headers = null;
@@ -4420,127 +4234,114 @@ pub const Request = struct {
bun.default_allocator.free(bun.constStrToU8(this.url.slice()));
}
+ this.body.deinit();
+
bun.default_allocator.destroy(this);
}
pub fn getRedirect(
_: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return ZigString.init(Properties.UTF8.follow).toValueGC(ctx.ptr()).asRef();
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.init(Properties.UTF8.follow).toValueGC(globalThis);
}
pub fn getReferrer(
this: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ globalObject: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
if (this.headers) |headers_ref| {
if (headers_ref.get("referrer")) |referrer| {
- return ZigString.init(referrer).toValueGC(ctx.ptr()).asRef();
+ return ZigString.init(referrer).toValueGC(globalObject);
}
}
- return ZigString.init("").toValueGC(ctx.ptr()).asRef();
+ return ZigString.init("").toValueGC(globalObject);
}
pub fn getReferrerPolicy(
_: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return ZigString.init("").toValueGC(ctx.ptr()).asRef();
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return ZigString.init("").toValueGC(globalThis);
}
pub fn getUrl(
this: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return this.url.toValueGC(ctx.ptr()).asObjectRef();
+ globalObject: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return this.url.toValueGC(globalObject);
}
pub fn constructor(
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- arguments: []const js.JSValueRef,
- exception: js.ExceptionRef,
- ) js.JSObjectRef {
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) ?*Request {
var request = Request{};
+ const arguments_ = callframe.arguments(2);
+ const arguments = arguments_.ptr[0..arguments_.len];
switch (arguments.len) {
0 => {},
1 => {
- const urlOrObject = JSC.JSValue.c(arguments[0]);
+ const urlOrObject = arguments[0];
if (urlOrObject.isString()) {
- request.url = urlOrObject.getZigString(ctx.ptr());
+ request.url = urlOrObject.getZigString(globalThis);
} else {
- if (Body.Init.init(getAllocator(ctx), ctx, JSC.JSValue.c(arguments[0])) catch null) |req_init| {
+ if (Body.Init.init(getAllocator(globalThis), globalThis, arguments[0]) catch null) |req_init| {
request.headers = req_init.headers;
request.method = req_init.method;
}
- if (urlOrObject.get(ctx.ptr(), "url")) |url| {
- request.url = url.getZigString(ctx.ptr()).clone(bun.default_allocator) catch {
- return js.JSValueMakeUndefined(ctx.ptr());
+ if (urlOrObject.fastGet(globalThis, .url)) |url| {
+ request.url = url.getZigString(globalThis).clone(bun.default_allocator) catch {
+ return null;
};
}
- if (urlOrObject.get(ctx.ptr(), "body")) |body_| {
- if (Blob.fromJS(ctx.ptr(), body_, true, false)) |blob| {
+ if (urlOrObject.fastGet(globalThis, .body)) |body_| {
+ if (Blob.fromJS(globalThis, body_, true, false)) |blob| {
if (blob.size > 0) {
request.body = Body.Value{ .Blob = blob };
}
} else |err| {
if (err == error.InvalidArguments) {
- JSC.JSError(getAllocator(ctx), "Expected an Array", .{}, ctx, exception);
+ globalThis.throwInvalidArguments("Expected an Array", .{});
return null;
}
- JSC.JSError(getAllocator(ctx), "Invalid Body", .{}, ctx, exception);
+ globalThis.throwInvalidArguments("Invalid Body object", .{});
return null;
}
}
}
},
else => {
- request.url = JSC.JSValue.fromRef(arguments[0]).getZigString(ctx.ptr());
+ request.url = arguments[0].getZigString(globalThis);
- if (Body.Init.init(getAllocator(ctx), ctx, JSValue.c(arguments[1])) catch null) |req_init| {
+ if (Body.Init.init(getAllocator(globalThis), globalThis, arguments[1]) catch null) |req_init| {
request.headers = req_init.headers;
request.method = req_init.method;
}
- if (JSC.JSValue.fromRef(arguments[1]).get(ctx.ptr(), "body")) |body_| {
- if (Blob.fromJS(ctx.ptr(), body_, true, false)) |blob| {
+ if (arguments[1].fastGet(globalThis, .body)) |body_| {
+ if (Blob.fromJS(globalThis, body_, true, false)) |blob| {
if (blob.size > 0) {
request.body = Body.Value{ .Blob = blob };
}
} else |err| {
if (err == error.InvalidArguments) {
- JSC.JSError(getAllocator(ctx), "Expected an Array", .{}, ctx, exception);
+ globalThis.throwInvalidArguments("Expected an Array", .{});
return null;
}
- JSC.JSError(getAllocator(ctx), "Invalid Body", .{}, ctx, exception);
+ globalThis.throwInvalidArguments("Invalid Body object", .{});
return null;
}
}
},
}
- var request_ = getAllocator(ctx).create(Request) catch unreachable;
+ var request_ = getAllocator(globalThis).create(Request) catch unreachable;
request_.* = request;
- return Request.Class.make(
- ctx,
- request_,
- );
+ return request_;
}
pub fn getBodyValue(
@@ -4551,44 +4352,35 @@ pub const Request = struct {
pub fn getBodyUsed(
this: *Request,
- _: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- return JSC.JSValue.jsBoolean(this.body == .Used).asRef();
+ _: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
+ return JSC.JSValue.jsBoolean(this.body == .Used);
}
- pub usingnamespace BlobInterface(@This());
+ pub usingnamespace NewBlobInterface(@This());
pub fn doClone(
this: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSObjectRef,
- _: []const js.JSValueRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
- var cloned = this.clone(getAllocator(ctx), ctx.ptr());
- return Request.Class.make(ctx, cloned);
+ globalThis: *JSC.JSGlobalObject,
+ _: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ var cloned = this.clone(getAllocator(globalThis), globalThis);
+ return cloned.toJS(globalThis);
}
pub fn getHeaders(
this: *Request,
- ctx: js.JSContextRef,
- _: js.JSObjectRef,
- _: js.JSStringRef,
- _: js.ExceptionRef,
- ) js.JSValueRef {
+ globalThis: *JSC.JSGlobalObject,
+ ) callconv(.C) JSC.JSValue {
if (this.headers == null) {
if (this.uws_request) |req| {
- this.headers = FetchHeaders.createFromUWS(ctx.ptr(), req);
+ this.headers = FetchHeaders.createFromUWS(globalThis, req);
} else {
this.headers = FetchHeaders.createEmpty();
}
}
- return this.headers.?.toJS(ctx.ptr()).asObjectRef();
+ return this.headers.?.toJS(globalThis);
}
pub fn cloneInto(
@@ -4632,7 +4424,7 @@ fn BlobInterface(comptime Type: type) type {
}
var blob = this.body.use();
- return blob.getTextTransfer(ctx);
+ return blob.getTextTransfer_c(ctx);
}
pub fn getJSON(
@@ -4649,7 +4441,7 @@ fn BlobInterface(comptime Type: type) type {
}
var blob = this.body.use();
- return blob.getJSON(ctx, null, null, &.{}, exception);
+ return blob.getJSON_c(ctx, null, null, &.{}, exception);
}
pub fn getArrayBuffer(
this: *Type,
@@ -4666,7 +4458,7 @@ fn BlobInterface(comptime Type: type) type {
}
var blob = this.body.use();
- return blob.getArrayBufferTransfer(ctx);
+ return blob.getArrayBufferTransfer_c(ctx);
}
pub fn getBlob(
@@ -4707,6 +4499,88 @@ fn BlobInterface(comptime Type: type) type {
};
}
+fn NewBlobInterface(comptime Type: type) type {
+ return struct {
+ pub fn getText(
+ this: *Type,
+ globalObject: *JSC.JSGlobalObject,
+ cf: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ std.mem.doNotOptimizeAway(cf);
+ var value: *Body.Value = this.getBodyValue();
+ if (value.* == .Locked) {
+ return value.Locked.setPromise(globalObject, .getText);
+ }
+
+ var blob = value.use();
+ return blob.getTextTransfer(globalObject);
+ }
+
+ pub fn getJSON(
+ this: *Type,
+ globalThis: *JSC.JSGlobalObject,
+ callframe: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ var value: *Body.Value = this.getBodyValue();
+ if (value.* == .Locked) {
+ return value.Locked.setPromise(globalThis, .getJSON);
+ }
+
+ var blob: Blob = value.use();
+ return blob.getJSON(globalThis, callframe);
+ }
+ pub fn getArrayBuffer(
+ this: *Type,
+ globalObject: *JSC.JSGlobalObject,
+ cf: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ std.mem.doNotOptimizeAway(cf);
+ var value: *Body.Value = this.getBodyValue();
+
+ if (value.* == .Locked) {
+ return value.Locked.setPromise(globalObject, .getArrayBuffer);
+ }
+
+ var blob: Blob = value.use();
+ return blob.getArrayBufferTransfer(globalObject);
+ }
+
+ pub fn getBlob(
+ this: *Type,
+ globalObject: *JSC.JSGlobalObject,
+ cf: *JSC.CallFrame,
+ ) callconv(.C) JSC.JSValue {
+ std.mem.doNotOptimizeAway(cf);
+ var value: *Body.Value = this.getBodyValue();
+
+ if (value.* == .Locked) {
+ return value.Locked.setPromise(globalObject, .getBlob);
+ }
+
+ var blob = value.use();
+ var ptr = getAllocator(globalObject).create(Blob) catch unreachable;
+ ptr.* = blob;
+ blob.allocator = getAllocator(globalObject);
+ return JSC.JSPromise.resolvedPromiseValue(globalObject, JSValue.fromRef(Blob.Class.make(globalObject, ptr)));
+ }
+
+ // pub fn getBody(
+ // this: *Type,
+ // ctx: js.JSContextRef,
+ // _: js.JSObjectRef,
+ // _: js.JSObjectRef,
+ // _: []const js.JSValueRef,
+ // _: js.ExceptionRef,
+ // ) js.JSValueRef {
+ // var value: *Body.Value = this.getBodyValue();
+
+ // switch (value.*) {
+ // .Empty => {},
+ // }
+ // }
+ };
+}
+
// https://github.com/WebKit/WebKit/blob/main/Source/WebCore/workers/service/FetchEvent.h
pub const FetchEvent = struct {
started_waiting_at: u64 = 0,
@@ -4787,10 +4661,9 @@ pub const FetchEvent = struct {
var req = bun.default_allocator.create(Request) catch unreachable;
req.* = this.request;
- return Request.Class.make(
+ return req.toJS(
ctx,
- req,
- );
+ ).asObjectRef();
}
// https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith
@@ -4805,9 +4678,12 @@ pub const FetchEvent = struct {
var request_context = this.request_context orelse return js.JSValueMakeUndefined(ctx);
if (request_context.has_called_done) return js.JSValueMakeUndefined(ctx);
var globalThis = ctx.ptr();
-
+ var existing_response: ?*Response = if (arguments.len > 0)
+ arguments[0].?.value().as(Response)
+ else
+ null;
// A Response or a Promise that resolves to a Response. Otherwise, a network error is returned to Fetch.
- if (arguments.len == 0 or !Response.Class.isLoaded() or !js.JSValueIsObject(ctx, arguments[0])) {
+ if (arguments.len == 0 or existing_response != null or !js.JSValueIsObject(ctx, arguments[0])) {
JSError(getAllocator(ctx), "event.respondWith() must be a Response or a Promise<Response>.", .{}, ctx, exception);
request_context.sendInternalError(error.respondWithWasEmpty) catch {};
return js.JSValueMakeUndefined(ctx);
@@ -4815,7 +4691,7 @@ pub const FetchEvent = struct {
var arg = arguments[0];
- if (JSValue.fromRef(arg).as(Response) == null) {
+ if (existing_response == null) {
this.pending_promise = this.pending_promise orelse JSInternalPromise.resolvedPromise(globalThis, JSValue.fromRef(arguments[0]));
}
@@ -4840,7 +4716,7 @@ pub const FetchEvent = struct {
arg = promise.result(ctx.ptr().vm()).asRef();
}
- var response: *Response = GetJSPrivateData(Response, arg) orelse {
+ var response: *Response = JSValue.c(arg.?).as(Response) orelse {
this.rejected = true;
this.pending_promise = null;
JSError(getAllocator(ctx), "event.respondWith() expects Response or Promise<Response>", .{}, ctx, exception);
diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig
index 82f27bdb5..47972baec 100644
--- a/src/bun.js/webcore/streams.zig
+++ b/src/bun.js/webcore/streams.zig
@@ -1159,7 +1159,8 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
}
}
- const args = callframe.arguments();
+ const args_list = callframe.arguments(4);
+ const args = args_list.ptr[0..args_list.len];
if (args.len == 0 or args[0].isEmptyOrUndefinedOrNull() or args[0].isNumber()) {
const err = JSC.toTypeError(
@@ -1206,7 +1207,8 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
}
}
- const args = callframe.arguments();
+ const args_list = callframe.arguments(4);
+ const args = args_list.ptr[0..args_list.len];
if (args.len == 0 or args[0].isEmptyOrUndefinedOrNull() or args[0].isNumber()) {
const err = JSC.toTypeError(
if (args.len == 0) JSC.Node.ErrorCode.ERR_MISSING_ARGS else JSC.Node.ErrorCode.ERR_INVALID_ARG_TYPE,
diff --git a/src/bundler.zig b/src/bundler.zig
index 4ad75ecfa..0a5f892ad 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -57,12 +57,14 @@ const JSC = @import("javascript_core");
pub fn MacroJSValueType_() type {
if (comptime JSC.is_bindgen) {
- return void;
+ return struct {
+ pub const zero = @This(){};
+ };
}
return JSC.JSValue;
}
-const MacroJSValueType = MacroJSValueType_();
-const default_macro_js_value = if (JSC.is_bindgen) void{} else JSC.JSValue.zero;
+pub const MacroJSValueType = MacroJSValueType_();
+const default_macro_js_value = if (JSC.is_bindgen) MacroJSValueType{} else JSC.JSValue.zero;
const EntryPoints = @import("./bundler/entry_points.zig");
const SystemTimer = @import("./system_timer.zig").Timer;
diff --git a/src/darwin_c.zig b/src/darwin_c.zig
index e92312d74..d5a002467 100644
--- a/src/darwin_c.zig
+++ b/src/darwin_c.zig
@@ -28,19 +28,19 @@ pub const COPYFILE_DATA = @as(c_int, 1) << @as(c_int, 3);
pub const COPYFILE_SECURITY = COPYFILE_STAT | COPYFILE_ACL;
pub const COPYFILE_METADATA = COPYFILE_SECURITY | COPYFILE_XATTR;
pub const COPYFILE_ALL = COPYFILE_METADATA | COPYFILE_DATA;
-/// Descend into hierarchies
+/// Descend into hierarchies
pub const COPYFILE_RECURSIVE = @as(c_int, 1) << @as(c_int, 15);
-/// return flags for xattr or acls if set
+/// return flags for xattr or acls if set
pub const COPYFILE_CHECK = @as(c_int, 1) << @as(c_int, 16);
-/// fail if destination exists
+/// fail if destination exists
pub const COPYFILE_EXCL = @as(c_int, 1) << @as(c_int, 17);
-/// don't follow if source is a symlink
+/// don't follow if source is a symlink
pub const COPYFILE_NOFOLLOW_SRC = @as(c_int, 1) << @as(c_int, 18);
-/// don't follow if dst is a symlink
+/// don't follow if dst is a symlink
pub const COPYFILE_NOFOLLOW_DST = @as(c_int, 1) << @as(c_int, 19);
-/// unlink src after copy
+/// unlink src after copy
pub const COPYFILE_MOVE = @as(c_int, 1) << @as(c_int, 20);
-/// unlink dst before copy
+/// unlink dst before copy
pub const COPYFILE_UNLINK = @as(c_int, 1) << @as(c_int, 21);
pub const COPYFILE_NOFOLLOW = COPYFILE_NOFOLLOW_SRC | COPYFILE_NOFOLLOW_DST;
pub const COPYFILE_PACK = @as(c_int, 1) << @as(c_int, 22);
diff --git a/src/deps/libarchive b/src/deps/libarchive
-Subproject 66d6e8a9166d3a340a16e1bd861fea9e1c186af
+Subproject dc321febde83dd0f31158e1be61a7aedda65e7a
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index b3a06a721..22ecaf95d 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -53,22 +53,26 @@ pub fn onThreadStartNew(event_fd: os.fd_t) void {
Output.prettyErrorln(
\\<red>error<r>: Linux kernel version doesn't support io_uring, which Bun depends on.
\\
- \\To fix this error: <b>please upgrade to a newer Linux kernel<r>.
- \\
- \\If you're using Windows Subsystem for Linux, here's how:
+ \\ To fix this error: please upgrade to a newer Linux kernel.
+ \\
+ \\ If you're using Windows Subsystem for Linux, here's how:
\\ 1. Open PowerShell as an administrator
\\ 2. Run this:
- \\ <cyan>wsl --update<r>
- \\ <cyan>wsl --shutdown<r>
- \\
- \\ Please make sure you're using WSL version 2 (not WSL 1).
- \\
- \\If that doesn't work (and you're on a Windows machine), try this:
+ \\ wsl --update
+ \\ wsl --shutdown
+ \\
+ \\ Please make sure you're using WSL version 2 (not WSL 1). To check: wsl -l -v
+ \\ If you are on WSL 1, update to WSL 2 with the following commands:
+ \\ 1. wsl --set-default-version 2
+ \\ 2. wsl --set-version <distro_name> 2
+ \\ 3. Now follow the WSL 2 instructions above.
+ \\ Where [distro_name] is one of the names from the list given by: wsl -l -v
+ \\
+ \\ If that doesn't work (and you're on a Windows machine), try this:
\\ 1. Open Windows Update
\\ 2. Download any updates to Windows Subsystem for Linux
- \\
- \\If you're still having trouble, ask for help in bun's discord https://bun.sh/discord
- \\
+ \\
+ \\ If you're still having trouble, ask for help in bun's discord https://bun.sh/discord
, .{});
break :log;
} else if (err == error.SystemResources) {
diff --git a/src/js_ast.zig b/src/js_ast.zig
index aa53efadd..c04819398 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -7836,17 +7836,6 @@ pub const Macro = struct {
this.macro.vm.runErrorHandler(value, null);
return error.MacroFailed;
},
- .Request => {
- var req: *JSC.WebCore.Request = private_data.as(JSC.WebCore.Request);
- blob_ = req.body.use();
- mime_type = HTTP.MimeType.init(req.mimeType());
- },
- .Response => {
- var res: *JSC.WebCore.Response = private_data.as(JSC.WebCore.Response);
- blob_ = res.body.use();
- mime_type =
- HTTP.MimeType.init(res.mimeType(null));
- },
.Blob => {
var blob = private_data.as(JSC.WebCore.Blob);
blob_ = blob.*;
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index 3d382d8ed..ac10439b0 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -37,7 +37,6 @@ fn notimpl() noreturn {
pub var emptyJavaScriptString = ([_]u16{0});
pub const JSONOptions = struct {
-
/// Enable JSON-specific warnings/errors
is_json: bool = false,
@@ -46,7 +45,7 @@ pub const JSONOptions = struct {
allow_trailing_commas: bool = false,
/// Loading JSON-in-JSON may start like \\""\\"
- /// This is technically invalid, since we parse from the first value of the string
+ /// This is technically invalid, since we parse from the first value of the string
ignore_leading_escape_sequences: bool = false,
ignore_trailing_escape_sequences: bool = false,
diff --git a/src/jsc.zig b/src/jsc.zig
index c06ec4022..b562637c9 100644
--- a/src/jsc.zig
+++ b/src/jsc.zig
@@ -47,3 +47,5 @@ pub const jsBoolean = @This().JSValue.jsBoolean;
pub inline fn markBinding() void {
if (comptime is_bindgen) unreachable;
}
+
+pub const Codegen = @import("./bun.js/bindings/generated_classes.zig");
diff --git a/src/mimalloc_arena.zig b/src/mimalloc_arena.zig
index 8b131c84a..c8117b6f5 100644
--- a/src/mimalloc_arena.zig
+++ b/src/mimalloc_arena.zig
@@ -11,9 +11,9 @@ const assert = std.debug.assert;
pub const Arena = struct {
heap: ?*mimalloc.mi_heap_t = null,
- /// Internally, mimalloc calls mi_heap_get_default()
+ /// Internally, mimalloc calls mi_heap_get_default()
/// to get the default heap.
- /// It uses pthread_getspecific to do that.
+ /// It uses pthread_getspecific to do that.
/// We can save those extra calls if we just do it once in here
pub fn getThreadlocalDefault() Allocator {
return Allocator{ .ptr = mimalloc.mi_heap_get_default(), .vtable = &c_allocator_vtable };
diff --git a/src/router.zig b/src/router.zig
index b482cf18c..2fbb53373 100644
--- a/src/router.zig
+++ b/src/router.zig
@@ -513,7 +513,7 @@ pub const Route = struct {
/// case-sensitive, has leading slash
name: string,
- /// Name used for matching.
+ /// Name used for matching.
/// - Omits leading slash
/// - Lowercased
/// This is [inconsistent with Next.js](https://github.com/vercel/next.js/issues/21498)
@@ -1132,7 +1132,7 @@ const Pattern = struct {
kind: Tag = Tag.static,
};
/// Validate a Route pattern, returning the number of route parameters.
- /// `null` means invalid. Error messages are logged.
+ /// `null` means invalid. Error messages are logged.
/// That way, we can provide a list of all invalid routes rather than failing the first time.
pub fn validate(input: string, allocator: std.mem.Allocator, log: *Logger.Log) ?ValidationResult {
if (CodepointIterator.needsUTF8Decoding(input)) {
diff --git a/src/zlib.zig b/src/zlib.zig
index 958454b6c..2ff037c52 100644
--- a/src/zlib.zig
+++ b/src/zlib.zig
@@ -89,30 +89,30 @@ pub const struct_internal_state = extern struct {
// } z_stream;
pub const zStream_struct = extern struct {
- /// next input byte
+ /// next input byte
next_in: [*c]const u8,
- /// number of bytes available at next_in
+ /// number of bytes available at next_in
avail_in: uInt,
- /// total number of input bytes read so far
+ /// total number of input bytes read so far
total_in: uLong,
- /// next output byte will go here
+ /// next output byte will go here
next_out: [*c]u8,
- /// remaining free space at next_out
+ /// remaining free space at next_out
avail_out: uInt,
- /// total number of bytes output so far
+ /// total number of bytes output so far
total_out: uLong,
- /// last error message, NULL if no error
+ /// last error message, NULL if no error
err_msg: [*c]const u8,
- /// not visible by applications
+ /// not visible by applications
internal_state: ?*struct_internal_state,
- /// used to allocate the internal state
+ /// used to allocate the internal state
alloc_func: z_alloc_fn,
- /// used to free the internal state
+ /// used to free the internal state
free_func: z_free_fn,
- /// private data object passed to zalloc and zfree
+ /// private data object passed to zalloc and zfree
user_data: *anyopaque,
/// best guess about the data type: binary or text for deflate, or the decoding state for inflate