mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
query_string_map -> url
This commit is contained in:
@@ -3,8 +3,8 @@ const Api = @import("../../../api/schema.zig").Api;
|
||||
const FilesystemRouter = @import("../../../router.zig");
|
||||
const http = @import("../../../http.zig");
|
||||
const JavaScript = @import("../javascript.zig");
|
||||
const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap;
|
||||
const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner;
|
||||
const QueryStringMap = @import("../../../url.zig").QueryStringMap;
|
||||
const CombinedScanner = @import("../../../url.zig").CombinedScanner;
|
||||
const bun = @import("../../../global.zig");
|
||||
const string = bun.string;
|
||||
const JSC = @import("../../../jsc.zig");
|
||||
@@ -29,7 +29,7 @@ const Request = WebCore.Request;
|
||||
const d = Base.d;
|
||||
const FetchEvent = WebCore.FetchEvent;
|
||||
const URLPath = @import("../../../http/url_path.zig");
|
||||
const URL = @import("../../../query_string_map.zig").URL;
|
||||
const URL = @import("../../../url.zig").URL;
|
||||
route: *const FilesystemRouter.Match,
|
||||
route_holder: FilesystemRouter.Match = undefined,
|
||||
needs_deinit: bool = false,
|
||||
|
||||
@@ -3,8 +3,8 @@ const Api = @import("../../../api/schema.zig").Api;
|
||||
const FilesystemRouter = @import("../../../router.zig");
|
||||
const http = @import("../../../http.zig");
|
||||
const JavaScript = @import("../javascript.zig");
|
||||
const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap;
|
||||
const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner;
|
||||
const QueryStringMap = @import("../../../url.zig").QueryStringMap;
|
||||
const CombinedScanner = @import("../../../url.zig").CombinedScanner;
|
||||
const bun = @import("../../../global.zig");
|
||||
const string = bun.string;
|
||||
const JSC = @import("../../../jsc.zig");
|
||||
|
||||
@@ -2032,3 +2032,216 @@ pub const JSPropertyNameIterator = struct {
|
||||
return js.JSPropertyNameArrayGetNameAtIndex(this.array, i);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn getterWrap(comptime Container: type, comptime name: string) GetterType(Container) {
|
||||
return struct {
|
||||
const FunctionType = @TypeOf(@field(Container, name));
|
||||
const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn;
|
||||
|
||||
pub fn callback(
|
||||
this: *Container,
|
||||
ctx: js.JSContextRef,
|
||||
_: js.JSObjectRef,
|
||||
_: js.JSStringRef,
|
||||
exception: js.ExceptionRef,
|
||||
) js.JSObjectRef {
|
||||
const result: JSValue = @call(.{}, @field(Container, name), .{ this, ctx.ptr() });
|
||||
if (!result.isUndefinedOrNull() and result.isError()) {
|
||||
exception.* = result.asObjectRef();
|
||||
return null;
|
||||
}
|
||||
|
||||
return result.asObjectRef();
|
||||
}
|
||||
}.callback;
|
||||
}
|
||||
|
||||
pub fn setterWrap(comptime Container: type, comptime name: string) SetterType(Container) {
|
||||
return struct {
|
||||
const FunctionType = @TypeOf(@field(Container, name));
|
||||
const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn;
|
||||
|
||||
pub fn callback(
|
||||
this: *Container,
|
||||
ctx: js.JSContextRef,
|
||||
_: js.JSObjectRef,
|
||||
_: js.JSStringRef,
|
||||
value: js.JSValueRef,
|
||||
exception: js.ExceptionRef,
|
||||
) bool {
|
||||
@call(.{}, @field(Container, name), .{ this, JSC.JSValue.fromRef(value), exception, ctx.ptr() });
|
||||
return exception.* == null;
|
||||
}
|
||||
}.callback;
|
||||
}
|
||||
|
||||
fn GetterType(comptime Container: type) type {
|
||||
return fn (
|
||||
this: *Container,
|
||||
ctx: js.JSContextRef,
|
||||
_: js.JSObjectRef,
|
||||
_: js.JSStringRef,
|
||||
exception: js.ExceptionRef,
|
||||
) js.JSObjectRef;
|
||||
}
|
||||
|
||||
fn SetterType(comptime Container: type) type {
|
||||
return fn (
|
||||
this: *Container,
|
||||
ctx: js.JSContextRef,
|
||||
obj: js.JSObjectRef,
|
||||
prop: js.JSStringRef,
|
||||
value: js.JSValueRef,
|
||||
exception: js.ExceptionRef,
|
||||
) bool;
|
||||
}
|
||||
|
||||
fn MethodType(comptime Container: type) type {
|
||||
return fn (
|
||||
this: *Container,
|
||||
ctx: js.JSContextRef,
|
||||
thisObject: js.JSObjectRef,
|
||||
target: js.JSObjectRef,
|
||||
args: []const js.JSValueRef,
|
||||
exception: js.ExceptionRef,
|
||||
) js.JSObjectRef;
|
||||
}
|
||||
|
||||
pub fn wrapSync(
|
||||
comptime Container: type,
|
||||
comptime name: string,
|
||||
) MethodType(Container) {
|
||||
return wrap(Container, name, false);
|
||||
}
|
||||
|
||||
pub fn wrapAsync(
|
||||
comptime Container: type,
|
||||
comptime name: string,
|
||||
) MethodType(Container) {
|
||||
return wrap(Container, name, true);
|
||||
}
|
||||
|
||||
pub fn wrap(
|
||||
comptime Container: type,
|
||||
comptime name: string,
|
||||
comptime maybe_async: bool,
|
||||
) MethodType(Container) {
|
||||
return struct {
|
||||
const FunctionType = @TypeOf(@field(Container, name));
|
||||
const FunctionTypeInfo: std.builtin.TypeInfo.Fn = @typeInfo(FunctionType).Fn;
|
||||
|
||||
pub fn callback(
|
||||
this: *Container,
|
||||
ctx: js.JSContextRef,
|
||||
_: js.JSObjectRef,
|
||||
thisObject: js.JSObjectRef,
|
||||
arguments: []const js.JSValueRef,
|
||||
exception: js.ExceptionRef,
|
||||
) js.JSObjectRef {
|
||||
var iter = JSC.Node.ArgumentsSlice.from(arguments);
|
||||
var args: std.meta.ArgsTuple(FunctionType) = undefined;
|
||||
|
||||
comptime var i: usize = 0;
|
||||
inline while (i < FunctionTypeInfo.args.len) : (i += 1) {
|
||||
const ArgType = comptime FunctionTypeInfo.args[i].arg_type.?;
|
||||
|
||||
switch (comptime ArgType) {
|
||||
*Container => {
|
||||
args[i] = this;
|
||||
},
|
||||
*JSC.JSGlobalObject => {
|
||||
args[i] = ctx.ptr();
|
||||
},
|
||||
ZigString => {
|
||||
var string_value = iter.nextEat() orelse {
|
||||
JSC.throwInvalidArguments("Missing argument", .{}, ctx, exception);
|
||||
return null;
|
||||
};
|
||||
|
||||
if (string_value.isUndefinedOrNull()) {
|
||||
JSC.throwInvalidArguments("Expected string", .{}, ctx, exception);
|
||||
return null;
|
||||
}
|
||||
|
||||
args[i] = string_value.getZigString(ctx.ptr());
|
||||
},
|
||||
?JSC.Cloudflare.ContentOptions => {
|
||||
if (iter.nextEat()) |content_arg| {
|
||||
if (content_arg.get(ctx.ptr(), "html")) |html_val| {
|
||||
args[i] = .{ .html = html_val.toBoolean() };
|
||||
}
|
||||
} else {
|
||||
args[i] = null;
|
||||
}
|
||||
},
|
||||
*Response => {
|
||||
args[i] = (iter.nextEat() orelse {
|
||||
JSC.throwInvalidArguments("Missing Response object", .{}, ctx, exception);
|
||||
return null;
|
||||
}).as(Response) orelse {
|
||||
JSC.throwInvalidArguments("Expected Response object", .{}, ctx, exception);
|
||||
return null;
|
||||
};
|
||||
},
|
||||
*Request => {
|
||||
args[i] = (iter.nextEat() orelse {
|
||||
JSC.throwInvalidArguments("Missing Request object", .{}, ctx, exception);
|
||||
return null;
|
||||
}).as(Request) orelse {
|
||||
JSC.throwInvalidArguments("Expected Request object", .{}, ctx, exception);
|
||||
return null;
|
||||
};
|
||||
},
|
||||
js.JSObjectRef => {
|
||||
args[i] = thisObject;
|
||||
if (!JSValue.fromRef(thisObject).isCell() or !JSValue.fromRef(thisObject).isObject()) {
|
||||
JSC.throwInvalidArguments("Expected object", .{}, ctx, exception);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
js.ExceptionRef => {
|
||||
args[i] = exception;
|
||||
},
|
||||
JSValue => {
|
||||
const val = iter.nextEat() orelse {
|
||||
JSC.throwInvalidArguments("Missing argument", .{}, ctx, exception);
|
||||
return null;
|
||||
};
|
||||
args[i] = val;
|
||||
},
|
||||
else => @compileError("Unexpected Type " ++ @typeName(ArgType)),
|
||||
}
|
||||
}
|
||||
|
||||
var result: JSValue = @call(.{}, @field(Container, name), args);
|
||||
if (result.isError()) {
|
||||
exception.* = result.asObjectRef();
|
||||
return null;
|
||||
}
|
||||
|
||||
JavaScript.VirtualMachine.vm.tick();
|
||||
|
||||
if (maybe_async) {
|
||||
var promise = JSC.JSInternalPromise.resolvedPromise(ctx.ptr(), result);
|
||||
|
||||
switch (promise.status(ctx.ptr().vm())) {
|
||||
JSC.JSPromise.Status.Pending => {
|
||||
while (promise.status(ctx.ptr().vm()) == .Pending) {
|
||||
JavaScript.VirtualMachine.vm.tick();
|
||||
}
|
||||
result = promise.result(ctx.ptr().vm());
|
||||
},
|
||||
JSC.JSPromise.Status.Rejected => {
|
||||
result = promise.result(ctx.ptr().vm());
|
||||
exception.* = result.asObjectRef();
|
||||
},
|
||||
JSC.JSPromise.Status.Fulfilled => {
|
||||
result = promise.result(ctx.ptr().vm());
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return result.asObjectRef();
|
||||
}
|
||||
}.callback;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ const Fs = @import("../../../fs.zig");
|
||||
const CAPI = JSC.C;
|
||||
const JS = @import("../javascript.zig");
|
||||
const JSBase = @import("../base.zig");
|
||||
const ZigURL = @import("../../../query_string_map.zig").URL;
|
||||
const ZigURL = @import("../../../url.zig").URL;
|
||||
const Api = @import("../../../api/schema.zig").Api;
|
||||
const bun = @import("../../../global.zig");
|
||||
const std = @import("std");
|
||||
|
||||
@@ -81,7 +81,7 @@ const ZigGlobalObject = @import("../../jsc.zig").ZigGlobalObject;
|
||||
const VM = @import("../../jsc.zig").VM;
|
||||
const JSFunction = @import("../../jsc.zig").JSFunction;
|
||||
const Config = @import("./config.zig");
|
||||
const URL = @import("../../query_string_map.zig").URL;
|
||||
const URL = @import("../../url.zig").URL;
|
||||
const Transpiler = @import("./api/transpiler.zig");
|
||||
pub const GlobalClasses = [_]type{
|
||||
Request.Class,
|
||||
|
||||
13
src/javascript/jsc/process.exports.js
Normal file
13
src/javascript/jsc/process.exports.js
Normal file
@@ -0,0 +1,13 @@
|
||||
export const chdir = process.chdir.bind(process);
|
||||
export const cwd = process.cwd.bind(process);
|
||||
export const nextTick = process.nextTick.bind(process);
|
||||
export const browser = false;
|
||||
export var exitCode = process.exitCode;
|
||||
export const exit = process.exit.bind(process);
|
||||
export const pid = process.pid;
|
||||
export const ppid = process.ppid;
|
||||
export const release = process.release;
|
||||
export const version = process.version;
|
||||
export const versions = process.versions;
|
||||
export const arch = process.arch;
|
||||
export const platform = process.platform;
|
||||
@@ -2,7 +2,7 @@ const std = @import("std");
|
||||
const Api = @import("../../../api/schema.zig").Api;
|
||||
const RequestContext = @import("../../../http.zig").RequestContext;
|
||||
const MimeType = @import("../../../http.zig").MimeType;
|
||||
const ZigURL = @import("../../../query_string_map.zig").URL;
|
||||
const ZigURL = @import("../../../url.zig").URL;
|
||||
const HTTPClient = @import("http");
|
||||
const NetworkThread = HTTPClient.NetworkThread;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ const std = @import("std");
|
||||
const Api = @import("../../../api/schema.zig").Api;
|
||||
const RequestContext = @import("../../../http.zig").RequestContext;
|
||||
const MimeType = @import("../../../http.zig").MimeType;
|
||||
const ZigURL = @import("../../../query_string_map.zig").URL;
|
||||
const ZigURL = @import("../../../url.zig").URL;
|
||||
const HTTPClient = @import("http");
|
||||
const NetworkThread = HTTPClient.NetworkThread;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ const Api = @import("../../../api/schema.zig").Api;
|
||||
const bun = @import("../../../global.zig");
|
||||
const RequestContext = @import("../../../http.zig").RequestContext;
|
||||
const MimeType = @import("../../../http.zig").MimeType;
|
||||
const ZigURL = @import("../../../query_string_map.zig").URL;
|
||||
const ZigURL = @import("../../../url.zig").URL;
|
||||
const HTTPClient = @import("http");
|
||||
const NetworkThread = HTTPClient.NetworkThread;
|
||||
|
||||
|
||||
150
src/javascript/jsc/webcore/url.zig
Normal file
150
src/javascript/jsc/webcore/url.zig
Normal file
@@ -0,0 +1,150 @@
|
||||
const URL = @import("../../../url.zig").URL;
|
||||
const std = @import("std");
|
||||
const Api = @import("../../../api/schema.zig").Api;
|
||||
const RequestContext = @import("../../../http.zig").RequestContext;
|
||||
const MimeType = @import("../../../http.zig").MimeType;
|
||||
const ZigURL = @import("../../../url.zig").URL;
|
||||
const HTTPClient = @import("http");
|
||||
const NetworkThread = HTTPClient.NetworkThread;
|
||||
|
||||
const JSC = @import("../../../jsc.zig");
|
||||
const js = JSC.C;
|
||||
|
||||
const Method = @import("../../../http/method.zig").Method;
|
||||
|
||||
const ObjectPool = @import("../../../pool.zig").ObjectPool;
|
||||
|
||||
const Output = @import("../../../global.zig").Output;
|
||||
const MutableString = @import("../../../global.zig").MutableString;
|
||||
const strings = @import("../../../global.zig").strings;
|
||||
const string = @import("../../../global.zig").string;
|
||||
const default_allocator = @import("../../../global.zig").default_allocator;
|
||||
const FeatureFlags = @import("../../../global.zig").FeatureFlags;
|
||||
const ArrayBuffer = @import("../base.zig").ArrayBuffer;
|
||||
const Properties = @import("../base.zig").Properties;
|
||||
const NewClass = @import("../base.zig").NewClass;
|
||||
const d = @import("../base.zig").d;
|
||||
const castObj = @import("../base.zig").castObj;
|
||||
const getAllocator = @import("../base.zig").getAllocator;
|
||||
const JSPrivateDataPtr = @import("../base.zig").JSPrivateDataPtr;
|
||||
const GetJSPrivateData = @import("../base.zig").GetJSPrivateData;
|
||||
const Environment = @import("../../../env.zig");
|
||||
const ZigString = JSC.ZigString;
|
||||
const JSInternalPromise = JSC.JSInternalPromise;
|
||||
const JSPromise = JSC.JSPromise;
|
||||
const JSValue = JSC.JSValue;
|
||||
const JSError = JSC.JSError;
|
||||
const JSGlobalObject = JSC.JSGlobalObject;
|
||||
|
||||
const VirtualMachine = @import("../javascript.zig").VirtualMachine;
|
||||
const Task = @import("../javascript.zig").Task;
|
||||
|
||||
const picohttp = @import("picohttp");
|
||||
|
||||
pub const DOMURL = struct {
|
||||
url: URL = URL{},
|
||||
m_string: *JSC.RefString,
|
||||
|
||||
pub const Class = JSC.NewClass(
|
||||
DOMURL,
|
||||
.{
|
||||
.name = "URL",
|
||||
},
|
||||
.{},
|
||||
.{
|
||||
.base = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getBase"),
|
||||
},
|
||||
.href = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getHref"),
|
||||
.set = JSC.setterWrap(DOMURL, "setHref"),
|
||||
},
|
||||
.protocol = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getProtocol"),
|
||||
.set = JSC.setterWrap(DOMURL, "setProtocol"),
|
||||
},
|
||||
.username = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getUsername"),
|
||||
.set = JSC.setterWrap(DOMURL, "setUsername"),
|
||||
},
|
||||
.password = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getPassword"),
|
||||
.set = JSC.setterWrap(DOMURL, "setPassword"),
|
||||
},
|
||||
.host = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getHost"),
|
||||
.set = JSC.setterWrap(DOMURL, "setHost"),
|
||||
},
|
||||
.hostname = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getHostname"),
|
||||
.set = JSC.setterWrap(DOMURL, "setHostname"),
|
||||
},
|
||||
.port = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getPort"),
|
||||
.set = JSC.setterWrap(DOMURL, "setPort"),
|
||||
},
|
||||
.pathname = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getPathname"),
|
||||
.set = JSC.setterWrap(DOMURL, "setPathname"),
|
||||
},
|
||||
.search = .{
|
||||
.get = JSC.getterWrap(DOMURL, "getSearch"),
|
||||
.set = JSC.setterWrap(DOMURL, "setSearch"),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
pub fn getBase(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.origin).toValue(globalThis);
|
||||
}
|
||||
|
||||
pub fn getHost(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.host).toValue(globalThis);
|
||||
}
|
||||
pub fn getHostname(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.hostname).toValue(globalThis);
|
||||
}
|
||||
pub fn getHref(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.href).toValue(globalThis);
|
||||
}
|
||||
pub fn getPassword(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.password).toValue(globalThis);
|
||||
}
|
||||
pub fn getPathname(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.pathname).toValue(globalThis);
|
||||
}
|
||||
pub fn getPort(this: *DOMURL) JSC.JSValue {
|
||||
return JSC.JSValue.jsNumber(this.url.getPortAuto());
|
||||
}
|
||||
pub fn getProtocol(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.displayProtocol()).toValue(globalThis);
|
||||
}
|
||||
pub fn getSearch(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.search).toValue(globalThis);
|
||||
}
|
||||
pub fn getUsername(this: *DOMURL, globalThis: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
return JSC.ZigString.init(this.url.username).toValue(globalThis);
|
||||
}
|
||||
|
||||
pub fn setHost(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {
|
||||
var copy = this.url;
|
||||
var input = value.toSlice(globalThis, bun.default_allocator);
|
||||
defer input.deinit();
|
||||
const buf = input.slice();
|
||||
const host_len = copy.parseHost(buf) orelse return false;
|
||||
var temp_clone = std.fmt.allocPrint("{}://{s}/{s}", .{ this.url.displayProtocol(), copy.displayHost(), strings.trimLeadingChar(this.url.pathname, '/') }) catch return false;
|
||||
this.m_string = JSC.VirtualMachine.vm.refCountedString(temp_clone, null, false);
|
||||
if (this.m_string.ptr != temp_clone.ptr) {
|
||||
bun.default_allocator.free(temp_clone);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
pub fn setHostname(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
pub fn setHref(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
pub fn setPassword(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
pub fn setPathname(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
pub fn setPort(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
pub fn setProtocol(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
pub fn setSearch(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
pub fn setUsername(this: *DOMURL, globalThis: *JSC.JSGlobalObject, value: JSC.JSValue) bool {}
|
||||
};
|
||||
Reference in New Issue
Block a user