diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/javascript/jsc/bindings/DefaultGlobal.cpp | 50 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/DefaultGlobal.zig | 1582 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/bindings-generator.zig | 1 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/header-gen.zig | 244 | ||||
-rw-r--r-- | src/javascript/jsc/bindings/headers.h | 429 |
5 files changed, 1984 insertions, 322 deletions
diff --git a/src/javascript/jsc/bindings/DefaultGlobal.cpp b/src/javascript/jsc/bindings/DefaultGlobal.cpp index 2c83c0e3c..42e5c962c 100644 --- a/src/javascript/jsc/bindings/DefaultGlobal.cpp +++ b/src/javascript/jsc/bindings/DefaultGlobal.cpp @@ -86,77 +86,75 @@ JSValue DefaultGlobal::moduleLoaderEvaluate(JSGlobalObject* globalObject, JSModu using namespace JSC; -JSC::ObjectPrototype* DefaultGlobal__objectPrototype(Wundle::DefaultGlobal* arg0) { +JSC::ObjectPrototype* JSC__JSGlobalObject__objectPrototype(JSC::JSGlobalObject* arg0) { return arg0->objectPrototype(); } -JSC::FunctionPrototype* DefaultGlobal__functionPrototype(Wundle::DefaultGlobal* arg0) { +JSC::FunctionPrototype* JSC__JSGlobalObject__functionPrototype(JSC::JSGlobalObject* arg0) { return arg0->functionPrototype(); } -JSC::ArrayPrototype* DefaultGlobal__arrayPrototype(Wundle::DefaultGlobal* arg0) { +JSC::ArrayPrototype* JSC__JSGlobalObject__arrayPrototype(JSC::JSGlobalObject* arg0) { return arg0->arrayPrototype(); } -JSC::JSObject* DefaultGlobal__booleanPrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSObject* JSC__JSGlobalObject__booleanPrototype(JSC::JSGlobalObject* arg0) { return arg0->booleanPrototype(); } -JSC::StringPrototype* DefaultGlobal__stringPrototype(Wundle::DefaultGlobal* arg0) { +JSC::StringPrototype* JSC__JSGlobalObject__stringPrototype(JSC::JSGlobalObject* arg0) { return arg0->stringPrototype(); } -JSC::JSObject* DefaultGlobal__numberPrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSObject* JSC__JSGlobalObject__numberPrototype(JSC::JSGlobalObject* arg0) { return arg0->numberPrototype(); } -JSC::BigIntPrototype* DefaultGlobal__bigIntPrototype(Wundle::DefaultGlobal* arg0) { +JSC::BigIntPrototype* JSC__JSGlobalObject__bigIntPrototype(JSC::JSGlobalObject* arg0) { return arg0->bigIntPrototype(); } -JSC::JSObject* DefaultGlobal__datePrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSObject* JSC__JSGlobalObject__datePrototype(JSC::JSGlobalObject* arg0) { return arg0->datePrototype(); } -JSC::JSObject* DefaultGlobal__symbolPrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSObject* JSC__JSGlobalObject__symbolPrototype(JSC::JSGlobalObject* arg0) { return arg0->symbolPrototype(); } -JSC::RegExpPrototype* DefaultGlobal__regExpPrototype(Wundle::DefaultGlobal* arg0) { +JSC::RegExpPrototype* JSC__JSGlobalObject__regExpPrototype(JSC::JSGlobalObject* arg0) { return arg0->regExpPrototype(); } -JSC::JSObject* DefaultGlobal__errorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSObject* JSC__JSGlobalObject__errorPrototype(JSC::JSGlobalObject* arg0) { return arg0->errorPrototype(); } -JSC::IteratorPrototype* DefaultGlobal__iteratorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::IteratorPrototype* JSC__JSGlobalObject__iteratorPrototype(JSC::JSGlobalObject* arg0) { return arg0->iteratorPrototype(); } -JSC::AsyncIteratorPrototype* DefaultGlobal__asyncIteratorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::AsyncIteratorPrototype* JSC__JSGlobalObject__asyncIteratorPrototype(JSC::JSGlobalObject* arg0) { return arg0->asyncIteratorPrototype(); } -JSC::GeneratorFunctionPrototype* DefaultGlobal__generatorFunctionPrototype(Wundle::DefaultGlobal* arg0) { +JSC::GeneratorFunctionPrototype* JSC__JSGlobalObject__generatorFunctionPrototype(JSC::JSGlobalObject* arg0) { return arg0->generatorFunctionPrototype(); } -JSC::GeneratorPrototype* DefaultGlobal__generatorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::GeneratorPrototype* JSC__JSGlobalObject__generatorPrototype(JSC::JSGlobalObject* arg0) { return arg0->generatorPrototype(); } -JSC::AsyncFunctionPrototype* DefaultGlobal__asyncFunctionPrototype(Wundle::DefaultGlobal* arg0) { +JSC::AsyncFunctionPrototype* JSC__JSGlobalObject__asyncFunctionPrototype(JSC::JSGlobalObject* arg0) { return arg0->asyncFunctionPrototype(); } -JSC::ArrayIteratorPrototype* DefaultGlobal__arrayIteratorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::ArrayIteratorPrototype* JSC__JSGlobalObject__arrayIteratorPrototype(JSC::JSGlobalObject* arg0) { return arg0->arrayIteratorPrototype(); } -JSC::MapIteratorPrototype* DefaultGlobal__mapIteratorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::MapIteratorPrototype* JSC__JSGlobalObject__mapIteratorPrototype(JSC::JSGlobalObject* arg0) { return arg0->mapIteratorPrototype(); } -JSC::SetIteratorPrototype* DefaultGlobal__setIteratorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::SetIteratorPrototype* JSC__JSGlobalObject__setIteratorPrototype(JSC::JSGlobalObject* arg0) { return arg0->setIteratorPrototype(); } -JSC::JSObject* DefaultGlobal__mapPrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSObject* JSC__JSGlobalObject__mapPrototype(JSC::JSGlobalObject* arg0) { return arg0->mapPrototype(); } -JSC::JSObject* DefaultGlobal__jsSetPrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSObject* JSC__JSGlobalObject__jsSetPrototype(JSC::JSGlobalObject* arg0) { return arg0->jsSetPrototype(); } -JSC::JSPromisePrototype* DefaultGlobal__promisePrototype(Wundle::DefaultGlobal* arg0) { +JSC::JSPromisePrototype* JSC__JSGlobalObject__promisePrototype(JSC::JSGlobalObject* arg0) { return arg0->promisePrototype(); } -JSC::AsyncGeneratorPrototype* DefaultGlobal__asyncGeneratorPrototype(Wundle::DefaultGlobal* arg0) { +JSC::AsyncGeneratorPrototype* JSC__JSGlobalObject__asyncGeneratorPrototype(JSC::JSGlobalObject* arg0) { return arg0->asyncGeneratorPrototype(); } -JSC::AsyncGeneratorFunctionPrototype* DefaultGlobal__asyncGeneratorFunctionPrototype(Wundle::DefaultGlobal* arg0) { +JSC::AsyncGeneratorFunctionPrototype* JSC__JSGlobalObject__asyncGeneratorFunctionPrototype(JSC::JSGlobalObject* arg0) { return arg0->asyncGeneratorFunctionPrototype(); } - -} diff --git a/src/javascript/jsc/bindings/DefaultGlobal.zig b/src/javascript/jsc/bindings/DefaultGlobal.zig index dfc931efb..fc548e1be 100644 --- a/src/javascript/jsc/bindings/DefaultGlobal.zig +++ b/src/javascript/jsc/bindings/DefaultGlobal.zig @@ -3,258 +3,1513 @@ usingnamespace @import("./imports.zig"); const std = @import("std"); const main = @import("root"); const is_bindgen = std.meta.trait.hasDecls(main, .{"bindgen"}); +const hasRef = std.meta.trait.hasField("ref"); -fn Shimmer(comptime name: []const u8, comptime Parent: type) type { +fn Shimmer(comptime _namespace: []const u8, comptime _name: []const u8, comptime Parent: type) type { return struct { - pub inline fn cppFn(comptime typeName: []const u8, args: anytype) (@typeInfo(@TypeOf(@field(Parent.C, typeName))).Fn.return_type orelse void) { - if (comptime is_bindgen) { - return .{}; - } else { - const func = @field(Parent, typeName); - const Func = @TypeOf(func); - // const Func: std.builtin.TypeInfo = brk: { - // var FuncType: std.builtin.TypeInfo = @typeInfo(@TypeOf(func)); - // var decl = std.meta.declarationInfo(Parent, name); - // var argument_field_list: [function_info.args.len]std.builtin.TypeInfo.StructField = undefined; - // inline for (function_info.args) |arg, i| { - // const T = arg.arg_type.?; - // @setEvalBranchQuota(10_000); - // var num_buf: [128]u8 = undefined; - // argument_field_list[i] = std.builtin.TypeInfo.StructField{ - // .name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable, - // .field_type = T, - // .default_value = @as(?T, null), - // .is_comptime = false, - // .alignment = if (@sizeOf(T) > 0) @alignOf(T) else 0, - // }; - // } - - // std.builtin.TypeInfo{ - // .Struct = std.builtin.TypeInfo.Struct{ - // .is_tuple = true, - // .layout = .Auto, - // .decls = &[_]std.builtin.TypeInfo.Declaration{}, - // .fields = &argument_field_list, - // }, - // }); - // }; - - const identifier = comptime std.fmt.comptimePrint("{s}__{s}", .{ name, typeName }); - const Outgoing = comptime @extern(Func, std.builtin.ExternOptions{ .name = identifier }); - const Decl: std.builtin.TypeInfo.Fn = @typeInfo(Func).Fn; - if (comptime Decl.return_type) |ReturnType| { - if (comptime @typeInfo(ReturnType) == .Pointer) { - const Ptr: std.builtin.TypeInfo.Pointer = comptime @typeInfo(ReturnType).Pointer; - const ChildType: type = brk: { - if (@typeInfo(ChildType) == .Struct) { - const Struct: std.builtin.TypeInfo.Struct = ChildType.Struct; - for (Struct.fields) |field| { - if (std.mem.eql(u8, field.name, "ref")) { - break :brk field.field_type; - } - } - } - break :brk Ptr.child; - }; + pub const namespace = _namespace; + pub const name = _name; + + fn toCppType(comptime FromType: ?type) ?type { + return comptime brk: { + var NewReturnType = FromType orelse c_void; + + if (NewReturnType == c_void) { + break :brk FromType; + } - if (comptime Ptr.is_const) { - const return_type = @call(.{}, comptime Outgoing, args); - return @ptrCast(*const ChildType, @alignCast(alignment, return_type)); - } else { - var return_type = @call(.{}, comptime Outgoing, args); - return @ptrCast(*ChildType, @alignCast(alignment, return_type)); + var ReturnTypeInfo: std.builtin.TypeInfo = @typeInfo(FromType orelse c_void); + + if (ReturnTypeInfo == .Pointer and NewReturnType != *c_void) { + NewReturnType = ReturnTypeInfo.Pointer.child; + ReturnTypeInfo = @typeInfo(NewReturnType); + } + + switch (ReturnTypeInfo) { + .Union, + .Struct, + .Enum, + => { + if (@hasDecl(ReturnTypeInfo, "Type")) { + break :brk NewReturnType; } + }, + else => {}, + } + + break :brk FromType; + }; + } + + pub inline fn getConvertibleType(comptime ZigType: type) type { + if (@typeInfo(ZigType) == .Struct) { + const Struct: std.builtin.TypeInfo.Struct = ChildType.Struct; + for (Struct.fields) |field| { + if (std.mem.eql(u8, field.name, "ref")) { + return field.field_type; } + } + } + + return ZigType; + } + + fn pointerChild(comptime Type: type) type { + if (@typeInfo(Type) == .Pointer) { + return @typeInfo(Type).Pointer.child_type; + } + + return Type; + } + + pub inline fn toZigType(comptime ZigType: type, comptime CppType: type, value: CppType) *ZigType { + if (comptime hasRef(ZigType)) { + // *WTF::String => Wtf.String{ = value}, via casting instead of copying + if (comptime @typeInfo(CppType) == .Pointer and @typeInfo(ZigType) != .Pointer) { + return @bitCast(ZigType, @ptrToInt(value)); + } + } + + return @as(ZigType, value); + } - return @as(ReturnType, @call(.{}, comptime Outgoing, args)); - } else { - @call(.{}, comptime Outgoing, args); + pub inline fn zigFn(comptime typeName: []const u8, args: anytype) (@typeInfo(@TypeOf(@field(Parent, typeName))).Fn.return_type orelse void) { + const identifier = comptime std.fmt.comptimePrint("{s}__{s}__{s}", .{ namespace, name, typeName }); + const func = comptime @typeInfo(Parent).Struct.fields[std.meta.fieldIndex(Parent, typeName)].field_type; + const ReturnType = comptime @typeInfo(func).Fn.return_type orelse c_void; + + const Func: type = comptime brk: { + var FuncType: std.builtin.TypeInfo = @typeInfo(@TypeOf(func)); + var Fn: std.builtin.TypeInfo.Fn = FuncType.Fn; + + Fn.calling_convention = std.builtin.CallingConvention.C; + Fn.return_type = toCppType(Fn.return_type); + + const ArgsType = @TypeOf(args); + for (std.meta.fieldNames(args)) |field, i| { + Fn.args[i] = std.builtin.TypeInfo.FnArg{ + .is_generic = false, + .is_noalias = false, + .arg_type = @typeInfo(ArgsType).fields[i].field_type, + }; } + FuncType.Fn = Fn; + break :brk @Type(FuncType); + }; + + comptime @export(Func, .{ .name = identifier }); + unreachable; + } + + pub inline fn cppFn(comptime typeName: []const u8, args: anytype) (ret: { + if (!@hasDecl(Parent, typeName)) { + @compileError(@typeName(Parent) ++ " is missing cppFn: " ++ typeName); + } + break :ret std.meta.declarationInfo(Parent, typeName).data.Fn.return_type; + }) { + if (comptime is_bindgen) { + unreachable; + } else { + const identifier = comptime std.fmt.comptimePrint("{s}__{s}__{s}", .{ namespace, name, typeName }); + const func = comptime @typeInfo(Parent).Struct.fields[std.meta.fieldIndex(Parent, typeName)].field_type; + const ReturnType = comptime @typeInfo(func).Fn.return_type orelse c_void; + + const Func: type = comptime brk: { + var FuncType: std.builtin.TypeInfo = @typeInfo(@TypeOf(func)); + var Fn: std.builtin.TypeInfo.Fn = FuncType.Fn; + + Fn.calling_convention = std.builtin.CallingConvention.C; + Fn.return_type = toCppType(Fn.return_type); + + const ArgsType = @TypeOf(args); + for (std.meta.fieldNames(args)) |field, i| { + Fn.args[i] = std.builtin.TypeInfo.FnArg{ + .is_generic = false, + .is_noalias = false, + .arg_type = @typeInfo(ArgsType).fields[i].field_type, + }; + } + FuncType.Fn = Fn; + break :brk @Type(FuncType); + }; + const Outgoing = comptime @extern(Func, std.builtin.ExternOptions{ .name = identifier }); + + return toZigType( + ReturnType, + @typeInfo(Func).Fn.return_type orelse void, + @call(.{}, Outgoing, args), + ); } } }; } -pub const JSCell = packed struct { - ref: Type, - pub const shim = Shimmer("JSCell", @This()); +pub const JSObject = opaque { + pub const shim = Shimmer("JSC", "JSObject", @This()); const cppFn = shim.cppFn; - pub const include = "\"GenericBindings.h\""; + pub const include = "<JavaScriptCore/JSObject.h>"; + pub const name = "JSC::JSObject"; + pub const namespace = "JSC"; + + pub fn hasProperty(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName) bool { + return cppFn("hasProperty", .{ this, globalThis, property_name }); + } + + pub fn getPropertyNames(this: *JSObject, globalThis: *JSGlobalObject) *PropertyNameArray { + return cppFn("getPropertyNames", .{ this, globalThis }); + } + + pub fn getArrayLength(this: *JSObject) usize { + return cppFn("getArrayLength", .{ + this, + }); + } + + // This get function only looks at the property map. + pub fn getDirect(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName) *JSValue { + return cppFn("getDirect", .{ + this, + property_name, + }); + } + pub fn putDirect(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName, value: *JSValue) bool { + return cppFn("putDirect", .{ + this, + property_name, + value, + }); + } + pub fn get(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName) *JSValue { + return cppFn("get", .{ + this, + property_name, + }); + } + pub fn getAtIndex(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName, i: u32) *JSValue { + return cppFn("getAtIndex", .{ + this, + property_name, + i, + }); + } + pub fn putAtIndex(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName, i: u32) bool { + return cppFn("putAtIndex", .{ + this, + property_name, + i, + }); + } + pub fn getIfExists(this: *JSObject, globalThis: *JSGlobalObject, property_name: *PropertyName) ?*JSValue { + return cppFn("getIfExists", .{ + this, + property_name, + }); + } + + pub const Extern = [_][]const u8{ "hasProperty", "getPropertyNames", "getArrayLength", "getDirect", "putDirect", "get", "getAtIndex", "putAtIndex", "getIfExists" }; +}; + +pub const PropertyNameArray = opaque { + pub const shim = Shimmer("JSC", "PropertyNameArray", @This()); + const cppFn = shim.cppFn; + pub const include = "<JavaScriptCore/PropertyNameArray.h>"; + pub const name = "JSC::PropertyNameArray"; + pub const namespace = "JSC"; + + pub fn length(this: *PropertyNameArray) usize { + return cppFn("length", .{this}); + } + + pub fn next(this: *PropertyNameArray, i: usize) ?*const PropertyName { + return cppFn("next", .{ this, i }); + } + + pub fn release(this: *PropertyNameArray) void { + return cppFn("release", .{this}); + } + + pub const Extern = [_][]const u8{ "length", "release", "next" }; +}; + +pub const JSCell = opaque { + pub const shim = Shimmer("JSC", "JSCell", @This()); + const cppFn = shim.cppFn; + pub const include = "<JavaScriptCore/JSCell.h>"; pub const name = "JSC::JSCell"; + pub const namespace = "JSC"; - pub const Type = *c_void; + const CellType = enum(u8) { _ }; - pub fn getObject(this: *const JSCell) ?JSObject { - return shim.cppFn("getObject", .{this.ref}); + pub fn getObject(this: *JSCell) *JSObject { + return shim.cppFn("getObject", .{this}); } - pub fn getString(this: *const JSCell, globalObject: *DefaultGlobal) ?String { - return shim.cppFn("getString", .{ this.ref, globalObject.ref }); + pub fn getString(this: *JSCell, globalObject: *JSGlobalObject) *String { + return shim.cppFn("getString", .{ this, globalObject }); } - pub fn getType(this: *const JSCell) u8 { - return @intCast(CellType, shim.cppFn("getType", .{ - this.ref, - })); + pub fn getType(this: *JSCell) u8 { + return shim.cppFn("getType", .{ + this, + }); } + + pub const Extern = [_][]const u8{ "getObject", "getString", "getType" }; }; -pub const JSString = packed struct { - ref: Type, - pub const shim = Shimmer("JSString", @This()); +pub const JSString = opaque { + pub const shim = Shimmer("JSC", "JSString", @This()); const cppFn = shim.cppFn; - pub const include = "\"GenericBindings.h\""; + pub const include = "<JavaScriptCore/JSString.h>"; pub const name = "JSC::JSString"; + pub const namespace = "JSC"; + + pub fn getObject(this: *JSString) *JSObject { + return shim.cppFn("getObject", .{this}); + } + + pub fn eql(this: *const JSString, other: *const JSString) bool { + return shim.cppFn("eql", .{ this, other }); + } - pub const Type = *c_void; + pub fn value(this: *JSString, globalObject: *JSGlobalObject) *String { + return shim.cppFn("value", .{ this, globalObject }); + } + + pub fn length(this: *const JSString) usize { + return shim.cppFn("length", .{ + this, + }); + } - pub fn getObject(this: *const JSCell) ?JSObject { - - return shim.cppFn("getObject", .{this.ref}); + pub fn is8Bit(this: *const JSString) bool { + return shim.cppFn("is8Bit", .{ + this, + }); } - pub fn getString(this: *const JSCell, globalObject: *DefaultGlobal) ?String { - return shim.cppFn("getString", .{ this.ref, globalObject.ref }); + pub fn createFromOwnedString(vm: *VM, str: *StringImpl) bool { + return shim.cppFn("createFromOwnedString", .{ + vm, str, + }); } + pub fn createFromString(vm: *VM, str: *StringImpl) bool { + return shim.cppFn("createFromString", .{ + vm, str, + }); + } + pub const Extern = [_][]const u8{ "getObject", "eql", "value", "length", "is8Bit", "createFromOwnedString", "createFromString" }; }; -pub const DefaultGlobal = struct { - pub const shim = Shimmer("DefaultGlobal", @This()); +pub const DefaultGlobalObject = opaque { + pub const shim = Shimmer("JSC", "JSGlobalObject", @This()); +}; - ref: Type, - pub const Type = *c_void; +pub const JSPromise = opaque { + pub const shim = Shimmer("JSC", "JSPromise", @This()); + const cppFn = shim.cppFn; + pub const include = "<JavaScriptCore/JSPromise.h>"; + pub const name = "JSC::JSPromise"; + pub const namespace = "JSC"; - pub const include = "\"DefaultGlobal.h\""; - pub const name = "Wundle::DefaultGlobal"; + pub const Status = enum(u32) { + Pending = 0, // Making this as 0, so that, we can change the status from Pending to others without masking. + Fulfilled = 1, + Rejected = 2, + }; + pub fn status(this: *JSPromise, vm: *VM) Status { + return shim.cppFn("status", .{ this, vm }); + } + pub fn result(this: *JSPromise, vm: *VM) *JSValue { + return cppFn("result", .{ this, vm }); + } + pub fn isHandled(this: *JSPromise, vm: *VM) bool { + return cppFn("isHandled", .{ this, vm }); + } + + pub fn resolvedPromise(globalThis: *JSGlobalObject, value: *JSValue) *JSPromise { + return cppFn("resolvedPromise", .{ .globalThis = globalThis, .value = value }); + } + pub fn rejectedPromise(globalThis: *JSGlobalObject, value: *JSValue) *JSPromise { + return cppFn("rejectedPromise", .{ .globalThis = globalThis, .value = value }); + } + + pub fn resolve(globalThis: *JSGlobalObject, value: *JSValue) void { + cppFn("resolve", .{ .globalThis = globalThis, .value = value }); + } + pub fn reject(this: *JSPromise, globalThis: *JSGlobalObject, value: *JSValue) void { + cppFn("reject", .{ .this = this, .globalThis = globalThis, .value = value }); + } + pub fn rejectAsHandled(this: *JSPromise, globalThis: *JSGlobalObject, value: *JSValue) void { + cppFn("rejectAsHandled", .{ .this = this, .globalThis = globalThis, .value = value }); + } + pub fn rejectException(this: *JSPromise, globalThis: *JSGlobalObject, value: *Exception) void { + cppFn("rejectException", .{ .this = this, .globalThis = globalThis, .value = value }); + } + pub fn rejectAsHandledException(this: *JSPromise, globalThis: *JSGlobalObject, value: *Exception) void { + cppFn("rejectAsHandledException", .{ .this = this, .globalThis = globalThis, .value = value }); + } + + pub fn isInternal(this: *JSPromise, vm: *VM) bool { + return cppFn("isInternal", .{ this, vm }); + } + + pub fn createDeferred(globalThis: *JSGlobalObject, resolved: *JSFunction, rejected: *JSFunction, exception: *Exception) *JSPromise { + return cppFn("createDeferred", .{ + .globalThis = globalThis, + .resolve = resolved, + .reject = rejected, + .exception = exception, + }); + } + + pub const Extern = [_][]const u8{ "status", "result", "isHandled", "resolvedPromise", "rejectedPromise", "resolve", "reject", "rejectAsHandled", "rejectException", "rejectAsHandledException", "isInternal", "createDeferred" }; +}; + +// SourceProvider.h +pub const SourceType = enum(u8) { + Program = 0, + Module = 1, + WebAssembly = 2, +}; + +pub const SourceOrigin = opaque { + pub const shim = Shimmer("JSC", "SourceOrigin", @This()); const cppFn = shim.cppFn; + pub const include = "<JavaScriptCore/SourceOrigin.h>"; + pub const name = "JSC::SourceOrigin"; + pub const namespace = "JSC"; - pub fn objectPrototype(instance: *DefaultGlobal) ObjectPrototype { - return cppFn("objectPrototype", .{instance.ref}); + pub fn fromURL(url: *const URL) *const SourceOrigin { + return cppFn("fromURL", .{url}); } - pub fn functionPrototype(instance: *DefaultGlobal) FunctionPrototype { - return cppFn("functionPrototype", .{instance.ref}); + + pub const Extern = [_][]const u8{ + "fromURL", + }; +}; + +pub const SourceCode = opaque { + pub const shim = Shimmer("JSC", "SourceCode", @This()); + const cppFn = shim.cppFn; + pub const include = "<JavaScriptCore/SourceProvider.h>"; + pub const name = "JSC::SourceCode"; + pub const namespace = "JSC"; + + pub fn fromString(source: *const String, origin: *const SourceOrigin, filename: *String, source_type: SourceType) *const SourceCode { + return cppFn("fromString", .{ source, origin, filename, source_type }); } - pub fn arrayPrototype(instance: *DefaultGlobal) ArrayPrototype { - return cppFn("arrayPrototype", .{instance.ref}); + + pub const Extern = [_][]const u8{ + "fromString", + }; +}; + +pub const JSFunction = opaque { + pub const shim = Shimmer("JSC", "JSFunction", @This()); + const cppFn = shim.cppFn; + pub const include = "<JavaScriptCore/JSFunction.h>"; + pub const name = "JSC::JSFunction"; + pub const namespace = "JSC"; + + pub fn createFromSourceCode(source: *SourceCode, origin: *SourceOrigin, exception: ?*Exception) *JSFunction { + return cppFn("createFromSourceCode", .{ source, origin, exception }); + } + pub fn createFromNative( + vm: *VM, + globalthis: *JSGlobalObject, + argument_count: u32, + name_: *String, + func: *c_void, + ) *JSFunction { + return cppFn("createFromNative", .{ vm, globalthis, argument_count, name_, func }); } - pub fn booleanPrototype(instance: *DefaultGlobal) JSObject { - return cppFn("booleanPrototype", .{instance.ref}); + pub fn getName(this: *JSFunction, vm: *VM) *String { + return cppFn("getName", .{ this, vm }); + } + pub fn displayName(this: *JSFunction, vm: *VM) *String { + return cppFn("displayName", .{ this, vm }); + } + pub fn calculatedDisplayName(this: *JSFunction, vm: *VM) *String { + return cppFn("calculatedDisplayName", .{ this, vm }); + } + pub fn toString(this: *JSFunction, globalThis: *JSGlobalObject) *JSString { + return cppFn("toString", .{ this, globalThis }); + } + + pub fn callWithArgumentsAndThis( + function: *JSFunction, + thisValue: *JSValue, + globalThis: *JSGlobalObject, + arguments_ptr: **JSValue, + arguments_len: usize, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("callWithArgumentsAndThis", .{ + function, + globalThis, + thisValue, + arguments_ptr, + arguments_len, + exception, + error_message, + }); + } + + pub fn callWithArguments( + function: *JSFunction, + globalThis: *JSGlobalObject, + arguments_ptr: **JSValue, + arguments_len: usize, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("callWithArguments", .{ function, globalThis, arguments_ptr, arguments_len, exception, exception, error_message }); } - pub fn stringPrototype(instance: *DefaultGlobal) StringPrototype { - return cppFn("stringPrototype", .{instance.ref}); + + pub fn callWithThis( + function: *JSFunction, + globalThis: *JSGlobalObject, + thisValue: *JSValue, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("callWithArguments", .{ + function, + globalThis, + thisValue, + exception, + error_message, + }); } - pub fn numberPrototype(instance: *DefaultGlobal) JSObject { - return cppFn("numberPrototype", .{instance.ref}); + + pub fn callWithoutAnyArgumentsOrThis( + function: *JSFunction, + globalThis: *JSGlobalObject, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("callWithoutAnyArgumentsOrThis", .{ function, globalThis, exception, exception, error_message }); } - pub fn bigIntPrototype(instance: *DefaultGlobal) BigIntPrototype { - return cppFn("bigIntPrototype", .{instance.ref}); + + pub fn constructWithArgumentsAndNewTarget( + function: *JSFunction, + newTarget: *JSValue, + globalThis: *JSGlobalObject, + arguments_ptr: **JSValue, + arguments_len: usize, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("constructWithArgumentsAndNewTarget", .{ + function, + globalThis, + newTarget, + arguments_ptr, + arguments_len, + exception, + error_message, + }); } - pub fn datePrototype(instance: *DefaultGlobal) JSObject { - return cppFn("datePrototype", .{instance.ref}); + + pub fn constructWithArguments( + function: *JSFunction, + globalThis: *JSGlobalObject, + arguments_ptr: **JSValue, + arguments_len: usize, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("constructWithArguments", .{ function, globalThis, arguments_ptr, arguments_len, exception, exception, error_message }); } - pub fn symbolPrototype(instance: *DefaultGlobal) JSObject { - return cppFn("symbolPrototype", .{instance.ref}); + + pub fn constructWithNewTarget( + function: *JSFunction, + globalThis: *JSGlobalObject, + newTarget: *JSValue, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("constructWithArguments", .{ + function, + globalThis, + newTarget, + exception, + error_message, + }); } - pub fn regExpPrototype(instance: *DefaultGlobal) RegExpPrototype { - return cppFn("regExpPrototype", .{instance.ref}); + + pub fn constructWithoutAnyArgumentsOrNewTarget( + function: *JSFunction, + globalThis: *JSGlobalObject, + exception: *?*Exception, + error_message: ?*const u8, + ) *JSValue { + return cppFn("constructWithoutAnyArgumentsOrNewTarget", .{ function, globalThis, exception, exception, error_message }); } - pub fn errorPrototype(instance: *DefaultGlobal) JSObject { - return cppFn("errorPrototype", .{instance.ref}); + + pub const Extern = [_][]const u8{ + "fromString", + "createFromSourceCode", + "createFromNative", + "getName", + "displayName", + "calculatedDisplayName", + "callWithArgumentsAndThis", + "callWithArguments", + "callWithThis", + "callWithoutAnyArgumentsOrThis", + "constructWithArgumentsAndNewTarget", + "constructWithArguments", + "constructWithNewTarget", + "constructWithoutAnyArgumentsOrNewTarget", + }; +}; + +pub const JSGlobalObject = opaque { + pub const shim = Shimmer("JSC", "JSGlobalObject", @This()); + + pub const include = "<JavaScriptCore/JSGlobalObject.h>"; + pub const name = "JSC::JSGlobalObject"; + pub const namespace = "JSC"; + + const cppFn = shim.cppFn; + + pub fn objectPrototype(this: *JSGlobalObject) *ObjectPrototype { + return cppFn("objectPrototype", .{this}); } - pub fn iteratorPrototype(instance: *DefaultGlobal) IteratorPrototype { - return cppFn("iteratorPrototype", .{instance.ref}); + pub fn functionPrototype(this: *JSGlobalObject) *FunctionPrototype { + return cppFn("functionPrototype", .{this}); } - pub fn asyncIteratorPrototype(instance: *DefaultGlobal) AsyncIteratorPrototype { - return cppFn("asyncIteratorPrototype", .{instance.ref}); + pub fn arrayPrototype(this: *JSGlobalObject) *ArrayPrototype { + return cppFn("arrayPrototype", .{this}); } - pub fn generatorFunctionPrototype(instance: *DefaultGlobal) GeneratorFunctionPrototype { - return cppFn("generatorFunctionPrototype", .{instance.ref}); + pub fn booleanPrototype(this: *JSGlobalObject) *JSObject { + return cppFn("booleanPrototype", .{this}); } - pub fn generatorPrototype(instance: *DefaultGlobal) GeneratorPrototype { - return cppFn("generatorPrototype", .{instance.ref}); + pub fn stringPrototype(this: *JSGlobalObject) *StringPrototype { + return cppFn("stringPrototype", .{this}); } - pub fn asyncFunctionPrototype(instance: *DefaultGlobal) AsyncFunctionPrototype { - return cppFn("asyncFunctionPrototype", .{instance.ref}); + pub fn numberPrototype(this: *JSGlobalObject) *JSObject { + return cppFn("numberPrototype", .{this}); } - pub fn arrayIteratorPrototype(instance: *DefaultGlobal) ArrayIteratorPrototype { - return cppFn("arrayIteratorPrototype", .{instance.ref}); + pub fn bigIntPrototype(this: *JSGlobalObject) *BigIntPrototype { + return cppFn("bigIntPrototype", .{this}); } - pub fn mapIteratorPrototype(instance: *DefaultGlobal) MapIteratorPrototype { - return cppFn("mapIteratorPrototype", .{instance.ref}); + pub fn datePrototype(this: *JSGlobalObject) *JSObject { + return cppFn("datePrototype", .{this}); } - pub fn setIteratorPrototype(instance: *DefaultGlobal) SetIteratorPrototype { - return cppFn("setIteratorPrototype", .{instance.ref}); + pub fn symbolPrototype(this: *JSGlobalObject) *JSObject { + return cppFn("symbolPrototype", .{this}); } - pub fn mapPrototype(instance: *DefaultGlobal) JSObject { - return cppFn("mapPrototype", .{instance.ref}); + pub fn regExpPrototype(this: *JSGlobalObject) *RegExpPrototype { + return cppFn("regExpPrototype", .{this}); } - pub fn jsSetPrototype(instance: *DefaultGlobal) JSObject { - return cppFn("jsSetPrototype", .{instance.ref}); + pub fn errorPrototype(this: *JSGlobalObject) *JSObject { + return cppFn("errorPrototype", .{this}); } - pub fn promisePrototype(instance: *DefaultGlobal) JSPromisePrototype { - return cppFn("promisePrototype", .{instance.ref}); + pub fn iteratorPrototype(this: *JSGlobalObject) *IteratorPrototype { + return cppFn("iteratorPrototype", .{this}); } - pub fn asyncGeneratorPrototype(instance: *DefaultGlobal) AsyncGeneratorPrototype { - return cppFn("asyncGeneratorPrototype", .{instance.ref}); + pub fn asyncIteratorPrototype(this: *JSGlobalObject) *AsyncIteratorPrototype { + return cppFn("asyncIteratorPrototype", .{this}); } - pub fn asyncGeneratorFunctionPrototype(instance: *DefaultGlobal) AsyncGeneratorFunctionPrototype { - return cppFn("asyncGeneratorFunctionPrototype", .{instance.ref}); + pub fn generatorFunctionPrototype(this: *JSGlobalObject) *GeneratorFunctionPrototype { + return cppFn("generatorFunctionPrototype", .{this}); } + pub fn generatorPrototype(this: *JSGlobalObject) *GeneratorPrototype { + return cppFn("generatorPrototype", .{this}); + } + pub fn asyncFunctionPrototype(this: *JSGlobalObject) *AsyncFunctionPrototype { + return cppFn("asyncFunctionPrototype", .{this}); + } + pub fn arrayIteratorPrototype(this: *JSGlobalObject) *ArrayIteratorPrototype { + return cppFn("arrayIteratorPrototype", .{this}); + } + pub fn mapIteratorPrototype(this: *JSGlobalObject) *MapIteratorPrototype { + return cppFn("mapIteratorPrototype", .{this}); + } + pub fn setIteratorPrototype(this: *JSGlobalObject) *SetIteratorPrototype { + return cppFn("setIteratorPrototype", .{this}); + } + pub fn mapPrototype(this: *JSGlobalObject) *JSObject { + return cppFn("mapPrototype", .{this}); + } + pub fn jsSetPrototype(this: *JSGlobalObject) *JSObject { + return cppFn("jsSetPrototype", .{this}); + } + pub fn promisePrototype(this: *JSGlobalObject) *JSPromisePrototype { + return cppFn("promisePrototype", .{this}); + } + pub fn asyncGeneratorPrototype(this: *JSGlobalObject) *AsyncGeneratorPrototype { + return cppFn("asyncGeneratorPrototype", .{this}); + } + pub fn asyncGeneratorFunctionPrototype(this: *JSGlobalObject) *AsyncGeneratorFunctionPrototype { + return cppFn("asyncGeneratorFunctionPrototype", .{this}); + } + + pub const Extern = [_][]const u8{ + "objectPrototype", + "functionPrototype", + "arrayPrototype", + "booleanPrototype", + "stringPrototype", + "numberPrototype", + "bigIntPrototype", + "datePrototype", + "symbolPrototype", + "regExpPrototype", + "errorPrototype", + "iteratorPrototype", + "asyncIteratorPrototype", + "generatorFunctionPrototype", + "generatorPrototype", + "asyncFunctionPrototype", + "arrayIteratorPrototype", + "mapIteratorPrototype", + "setIteratorPrototype", + "mapPrototype", + "jsSetPrototype", + "promisePrototype", + "asyncGeneratorPrototype", + "asyncGeneratorFunctionPrototype", + }; }; fn _JSCellStub(comptime str: []const u8) type { if (is_bindgen) { - return struct { - pub const C = struct { - pub const name = "JSC::" ++ str ++ "*"; - ref: ?*c_void = null, - }; + return opaque { + pub const name = "JSC::" ++ str ++ ""; }; } else { - return struct { - pub const C = *c_void; - }; + return struct {}; } } fn _Wundle(comptime str: []const u8) type { if (is_bindgen) { - return struct { - pub const C = struct { - pub const name = "Wundle::" ++ str ++ "*"; - ref: ?*c_void = null, - }; + return opaque { + pub const name = "Wundle::" ++ str ++ ""; }; } else { - return struct { - pub const C = *c_void; - }; + return struct {}; } } fn _WTF(comptime str: []const u8) type { if (is_bindgen) { - return struct { - pub const C = struct { - pub const name = "WTF::" ++ str ++ "*"; - ref: ?*c_void = null, - }; + return opaque { + pub const name = "WTF::" ++ str ++ ""; }; } else { - return struct { - pub const C = *c_void; - }; + return struct {}; } } -const _DefaultGlobal = _Wundle("DefaultGlobal"); +pub const URL = opaque { + pub const shim = Shimmer("WTF", "URL", @This()); + const cppFn = shim.cppFn; + pub const include = "<wtf/URL.h>"; + pub const name = "WTF::URL"; + pub const namespace = "WTF"; + + pub fn fromString(base: *const String, relative: *const String) *URL { + return cppFn("fromString", .{ base, relative }); + } + + pub fn fromFileSystemPath(file_system_path: *const StringView) *URL { + return cppFn("fromFileSystemPath", .{file_system_path}); + } + + pub fn isEmpty(this: *const URL) bool { + return cppFn("isEmpty", .{this}); + } + pub fn isValid(this: *const URL) bool { + return cppFn("isValid", .{this}); + } + + pub fn protocol(this: *URL) ?*const StringView { + return cppFn("protocol", .{this}); + } + pub fn encodedUser(this: *URL) ?*const StringView { + return cppFn("encodedUser", .{this}); + } + pub fn encodedPassword(this: *URL) ?*const StringView { + return cppFn("encodedPassword", .{this}); + } + pub fn host(this: *URL) ?*const StringView { + return cppFn("host", .{this}); + } + pub fn path(this: *URL) ?*const StringView { + return cppFn("path", .{this}); + } + pub fn lastPathComponent(this: *URL) ?*const StringView { + return cppFn("lastPathComponent", .{this}); + } + pub fn query(this: *URL) ?*const StringView { + return cppFn("query", .{this}); + } + pub fn fragmentIdentifier(this: *URL) ?*const StringView { + return cppFn("fragmentIdentifier", .{this}); + } + pub fn queryWithLeadingQuestionMark(this: *URL) ?*const StringView { + return cppFn("queryWithLeadingQuestionMark", .{this}); + } + pub fn fragmentIdentifierWithLeadingNumberSign(this: *URL) ?*const StringView { + return cppFn("fragmentIdentifierWithLeadingNumberSign", .{this}); + } + pub fn stringWithoutQueryOrFragmentIdentifier(this: *URL) ?*const StringView { + return cppFn("stringWithoutQueryOrFragmentIdentifier", .{this}); + } + pub fn stringWithoutFragmentIdentifier(this: *URL) ?*const StringView { + return cppFn("stringWithoutFragmentIdentifier", .{this}); + } + pub fn protocolHostAndPort(this: *URL) ?*const String { + return cppFn("protocolHostAndPort", .{this}); + } + pub fn hostAndPort(this: *URL) ?*const String { + return cppFn("hostAndPort", .{this}); + } + pub fn user(this: *URL) ?*const String { + return cppFn("user", .{this}); + } + pub fn password(this: *URL) ?*const String { + return cppFn("password", .{this}); + } + pub fn fileSystemPath(this: *URL) ?*const String { + return cppFn("fileSystemPath", .{this}); + } + + pub fn setProtocol(this: *URL, protocol_value: *const StringView) void { + return cppFn("setProtocol", .{ this, protocol_value }); + } + pub fn setHost(this: *URL, host_value: *const StringView) void { + return cppFn("setHost", .{ this, host_value }); + } + pub fn setHostAndPort(this: *URL, host_and_port_value: *const StringView) void { + return cppFn("setHostAndPort", .{ this, host_and_port_value }); + } + pub fn setUser(this: *URL, user_value: *const StringView) void { + return cppFn("setUser", .{ this, user_value }); + } + pub fn setPassword(this: *URL, password_value: *const StringView) void { + return cppFn("setPassword", .{ this, password_value }); + } + pub fn setPath(this: *URL, path_value: *const StringView) void { + return cppFn("setPath", .{ this, path_value }); + } + pub fn setQuery(this: *URL, query_value: *const StringView) void { + return cppFn("setQuery", .{ this, query_value }); + } + + pub fn truncatedForUseAsBase( + this: *URL, + ) *URL { + return cppFn("truncatedForUseAsBase", .{ + this, + }); + } + pub const Extern = [_][]const u8{ "fromFileSystemPath", "fromString", "isEmpty", "isValid", "protocol", "encodedUser", "encodedPassword", "host", "path", "lastPathComponent", "query", "fragmentIdentifier", "queryWithLeadingQuestionMark", "fragmentIdentifierWithLeadingNumberSign", "stringWithoutQueryOrFragmentIdentifier", "stringWithoutFragmentIdentifier", "protocolHostAndPort", "hostAndPort", "user", "password", "fileSystemPath", "setProtocol", "setHost", "setHostAndPort", "setUser", "setPassword", "setPath", "setQuery", "truncatedForUseAsBase" }; +}; + +pub const String = opaque { + pub const shim = Shimmer("WTF", "WTFString", @This()); + const cppFn = shim.cppFn; + pub const include = "<wtf/text/WTFString.h>"; + pub const name = "WTF::WTFString"; + pub const namespace = "WTF"; + + pub fn createWithoutCopyingFromPtr(str: [*]const u8, len: usize) *String { + return cppFn("createWithoutCopyingFromPtr", .{ str, len }); + } + + pub fn createFromExternalString(str: *StringImpl) *String { + return cppFn("createFromExternalString", .{str}); + } + + pub fn createWithoutCopying(str: []const u8) *String { + return @call(.{ .modifier = .always_inline }, createWithoutCopyingFromPtr, .{ str.ptr, str.len }); + } + + pub fn is8Bit(this: *String) bool { + return cppFn("is8Bit", .{this}); + } + pub fn is16Bit(this: *String) bool { + return cppFn("is16Bit", .{this}); + } + pub fn isExternal(this: *String) bool { + return cppFn("isExternal", .{this}); + } + pub fn isStatic(this: *String) bool { + return cppFn("isStatic", .{this}); + } + pub fn isEmpty(this: *String) bool { + return cppFn("isEmpty", .{this}); + } + pub fn length(this: *String) usize { + return cppFn("length", .{this}); + } + pub fn characters8(this: *String) ?[*]u8 { + return cppFn("characters8", .{this}); + } + pub fn characters16(this: *String) ?[*]u8 { + return cppFn("characters16", .{this}); + } + + pub fn eqlString(this: *String, other: *String) bool { + return cppFn("eqlString", .{ this, other }); + } + + pub fn eqlSlice(this: *String, other: [*]u8, other_len: usize) bool { + return cppFn("eqlSlice", .{ this, other, other_len }); + } + + pub fn impl( + this: *String, + ) *StringImpl { + return cppFn("impl", .{ + this, + }); + } + + pub fn slice(this: *String) []const u8 { + if (this.isEmpty()) return ""; + + if (this.is8Bit()) { + return if (this.characters8()) |ptr| ptr[0..this.length()] else ""; + } else { + return if (this.characters8()) |ptr| ptr[0..this.length()] else ""; + } + } + + pub const Extern = [_][]const u8{ + "is8Bit", + "is16Bit", + "isExternal", + "isStatic", + "isEmpty", + "length", + "characters8", + "characters16", + "createWithoutCopyingFromPtr", + "eqlString", + "eqlSlice", + "impl", + "createFromExternalString", + }; +}; + +pub const JSValue = opaque { + pub const shim = Shimmer("JSC", "JSValue", @This()); + pub const is_pointer = false; + pub const Type = u64; + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/JSValue.h>"; + pub const name = "JSC::JSValue"; + pub const namespace = "JSC"; + + pub fn jsNumber(number: anytype) *JSValue { + return switch (@TypeOf(number)) { + f64 => @call(.{ .modifier = .always_inline }, jsNumberFromDouble, .{number}), + u8 => @call(.{ .modifier = .always_inline }, jsNumberFromChar, .{number}), + u16 => @call(.{ .modifier = .always_inline }, jsNumberFromU16, .{number}), + i32 => @call(.{ .modifier = .always_inline }, jsNumberFromInt32, .{number}), + i64 => @call(.{ .modifier = .always_inline }, jsNumberFromInt64, .{number}), + u64 => @call(.{ .modifier = .always_inline }, jsNumberFromUint64, .{number}), + else => @compileError("Type transformation missing for number of type: " ++ @typeName(@TypeOf(number))), + }; + } + + pub fn jsNull() *JSValue { + return cppFn("jsNull", .{}); + } + pub fn jsUndefined() *JSValue { + return cppFn("jsUndefined", .{}); + } + pub fn jsTDZValue() *JSValue { + return cppFn("jsTDZValue", .{}); + } + pub fn jsBoolean(i: bool) *JSValue { + return cppFn("jsBoolean", .{i}); + } + pub fn jsDoubleNumber(i: f64) *JSValue { + return cppFn("jsDoubleNumber", .{i}); + } + + pub fn jsNumberFromDouble(i: f64) *JSValue { + return cppFn("jsNumberFromDouble", .{i}); + } + pub fn jsNumberFromChar(i: u8) *JSValue { + return cppFn("jsNumberFromChar", .{i}); + } + pub fn jsNumberFromU16(i: u16) *JSValue { + return cppFn("jsNumberFromU16", .{i}); + } + pub fn jsNumberFromInt32(i: i32) *JSValue { + return cppFn("jsNumberFromInt32", .{i}); + } + pub fn jsNumberFromInt64(i: i64) *JSValue { + return cppFn("jsNumberFromInt64", .{i}); + } + pub fn jsNumberFromUint64(i: u64) *JSValue { + return cppFn("jsNumberFromUint64", .{i}); + } + + pub fn isUndefined(this: *JSValue) bool { + return cppFn("isUndefined", .{this}); + } + pub fn isNull(this: *JSValue) bool { + return cppFn("isNull", .{this}); + } + pub fn isUndefinedOrNull(this: *JSValue) bool { + return cppFn("isUndefinedOrNull", .{this}); + } + pub fn isBoolean(this: *JSValue) bool { + return cppFn("isBoolean", .{this}); + } + pub fn isAnyInt(this: *JSValue) bool { + return cppFn("isAnyInt", .{this}); + } + pub fn isUInt32AsAnyInt(this: *JSValue) bool { + return cppFn("isUInt32AsAnyInt", .{this}); + } + pub fn isInt32AsAnyInt(this: *JSValue) bool { + return cppFn("isInt32AsAnyInt", .{this}); + } + pub fn isNumber(this: *JSValue) bool { + return cppFn("isNumber", .{this}); + } + pub fn isString(this: *JSValue) bool { + return cppFn("isString", .{this}); + } + pub fn isBigInt(this: *JSValue) bool { + return cppFn("isBigInt", .{this}); + } + pub fn isHeapBigInt(this: *JSValue) bool { + return cppFn("isHeapBigInt", .{this}); + } + pub fn isBigInt32(this: *JSValue) bool { + return cppFn("isBigInt32", .{this}); + } + pub fn isSymbol(this: *JSValue) bool { + return cppFn("isSymbol", .{this}); + } + pub fn isPrimitive(this: *JSValue) bool { + return cppFn("isPrimitive", .{this}); + } + pub fn isGetterSetter(this: *JSValue) bool { + return cppFn("isGetterSetter", .{this}); + } + pub fn isCustomGetterSetter(this: *JSValue) bool { + return cppFn("isCustomGetterSetter", .{this}); + } + pub fn isObject(this: *JSValue) bool { + return cppFn("isObject", .{this}); + } + + pub fn isCell(this: *JSValue) bool { + return cppFn("isCell", .{this}); + } + + pub fn asCell(this: *JSValue) *JSCell { + return cppFn("asCell", .{this}); + } + + // On exception, this returns the empty string. + pub fn toString(this: *JSValue, globalThis: *JSGlobalObject) *JSString { + return cppFn("toString", .{ this, globalThis }); + } + + // On exception, this returns null, to make exception checks faster. + pub fn toStringOrNull(this: *JSValue, globalThis: *JSGlobalObject) *JSString { + return cppFn("toStringOrNull", .{ this, globalThis }); + } + pub fn toPropertyKey(this: *JSValue, globalThis: *JSGlobalObject) *Identifier { + return cppFn("toPropertyKey", .{ this, globalThis }); + } + pub fn toPropertyKeyValue(this: *JSValue, globalThis: *JSGlobalObject) *JSValue { + return cppFn("toPropertyKeyValue", .{ this, globalThis }); + } + pub fn toObject(this: *JSValue, globalThis: *JSGlobalObject) *JSObject { + return cppFn("toObject", .{ this, globalThis }); + } + + pub fn toWTFString(this: *JSValue) *String { + return cppFn("toWTFString", .{this}); + } + + pub fn getPrototype(this: *JSValue, globalObject: *JSGlobalObject) *JSValue { + return cppFn("getPrototype", .{ this, globalObject }); + } + + pub fn getPropertyByPropertyName(this: *JSValue, property_name: *PropertyName, globalObject: *JSGlobalObject) *JSValue { + return cppFn("getPropertyByPropertyName", .{ this, property_name, globalObject }); + } + + pub fn eqlValue(this: *JSValue, other: *JSValue) bool { + return cppFn("eqlValue", .{ this, other }); + } + + pub fn eqlCell(this: *JSValue, other: *JSCell) bool { + return cppFn("eqlCell", .{ this, other }); + } + + pub const Extern = [_][]const u8{ "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isUndefined", "isNull", "isUndefinedOrNull", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toWTFString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell" }; +}; + +pub const PropertyName = opaque { + pub const shim = Shimmer("JSC", "PropertyName", @This()); + + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/PropertyName.h>"; + pub const name = "JSC::PropertyName"; + pub const namespace = "JSC"; + + pub fn eqlToPropertyName(property_name: *PropertyName, other: *PropertyName) bool { + return cppFn("eqlToPropertyName", .{ property_name, other }); + } + + pub fn eqlToIdentifier(property_name: *PropertyName, other: *Identifier) bool { + return cppFn("eqlToIdentifier", .{ property_name, other }); + } +}; + +pub const Error = opaque { + pub const shim = Shimmer("JSC", "JSGlobalObject", @This()); + + pub const Type = JSObject; + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/Error.h>"; + pub const name = "JSC::JSGlobalObject"; + pub const namespace = "JSC"; + + pub const ErrorType = enum(u8) { + Error = 0, + EvalError = 1, + RangeError = 2, + ReferenceError = 3, + SyntaxError = 4, + TypeError = 5, + URIError = 6, + AggregateError = 7, + OutOfMemoryError = 8, + }; + + pub fn createError(globalObject: *JSGlobalObject, error_type: ErrorType, message: *String) *JSObject { + return cppFn("createError", .{ globalObject, @enumToInt(error_type), message }); + } + + pub fn throwError( + globalObject: *JSGlobalObject, + err: *JSObject, + ) *JSObject { + return cppFn("throwError", .{ + globalObject, + err, + }); + } + + pub const Extern = [_][]const u8{ + "throwError", "createError", + }; +}; + +pub const Exception = opaque { + pub const shim = Shimmer("JSC", "Exception", @This()); + + pub const Type = JSObject; + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/Exception.h>"; + pub const name = "JSC::Exception"; + pub const namespace = "JSC"; + + pub const StackCaptureAction = enum(u8) { + CaptureStack = 0, + DoNotCaptureStack = 1, + }; + + pub fn create(globalObject: *JSGlobalObject, object: *JSObject, stack_capture: StackCaptureAction) *Exception { + return cppFn( + "create", + .{ globalObject, object, @enumToInt(stack_capture) }, + ); + } + + pub const Extern = [_][]const u8{ + "create", + }; +}; + +pub const VM = opaque { + pub const shim = Shimmer("JSC", "VM", @This()); + + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/VM.h>"; + pub const name = "JSC::VM"; + pub const namespace = "JSC"; + + pub const HeapType = enum(u8) { + SmallHeap = 0, + LargeHeap = 1, + }; + pub fn create(heap_type: *HeapType) *VM { + return cppFn("create", .{@enumToInt(heap_type)}); + } + + pub fn deinit(vm: *VM) void { + return cppFn("deinit", .{vm}); + } + + pub fn setExecutionForbidden(vm: *VM, forbidden: bool) void { + cppFn("setExecutionForbidden", .{ vm, forbidden }); + } + + pub fn executionForbidden(vm: *VM) bool { + return cppFn("executionForbidden", .{ + vm, + }); + } + + pub fn isEntered(vm: *VM) bool { + return cppFn("isEntered", .{ + vm, + }); + } +}; + +pub const CallFrame = opaque { + pub const shim = Shimmer("JSC", "CallFrame", @This()); + + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/CallFrame.h>"; + pub const name = "JSC::CallFrame"; + pub const namespace = "JSC"; + + pub fn argumentsCount(call_frame: *const CallFrame) usize { + return cppFn("argumentsCount", .{ + call_frame, + }); + } + pub fn uncheckedArgument(call_frame: *const CallFrame, i: u16) *JSValue { + return cppFn("uncheckedArgument", .{ call_frame, i }); + } + pub fn argument(call_frame: *const CallFrame, i: u16) *JSValue { + return cppFn("argument", .{ + call_frame, + }); + } + pub fn thisValue(call_frame: *const CallFrame) ?*JSValue { + return cppFn("thisValue", .{ + call_frame, + }); + } + pub fn newTarget(call_frame: *const CallFrame) ?*JSValue { + return cppFn("newTarget", .{ + call_frame, + }); + } + pub fn jsCallee(call_frame: *const CallFrame) *JSObject { + return cppFn("jsCallee", .{ + call_frame, + }); + } + pub const Extern = [_][]const u8{ "argumentsCount", "uncheckedArgument", "argument", "thisValue", "newTarget", "jsCallee" }; +}; + +// pub const WellKnownSymbols = opaque { +// pub const shim = Shimmer("JSC", "CommonIdentifiers", @This()); + +// +// + +// pub const include = "<JavaScriptCore/CommonIdentifiers.h>"; +// pub const name = "JSC::CommonIdentifiers"; +// pub const namespace = "JSC"; + +// pub var hasthis: *Identifier = shim.cppConst(Identifier, "hasInstance"); +// pub var isConcatSpreadable: Identifier = shim.cppConst(Identifier, "isConcatSpreadable"); +// pub var asyncIterator: Identifier = shim.cppConst(Identifier, "asyncIterator"); +// pub var iterator: Identifier = shim.cppConst(Identifier, "iterator"); +// pub var match: Identifier = shim.cppConst(Identifier, "match"); +// pub var matchAll: Identifier = shim.cppConst(Identifier, "matchAll"); +// pub var replace: Identifier = shim.cppConst(Identifier, "replace"); +// pub var search: Identifier = shim.cppConst(Identifier, "search"); +// pub var species: Identifier = shim.cppConst(Identifier, "species"); +// pub var split: Identifier = shim.cppConst(Identifier, "split"); +// pub var toPrimitive: Identifier = shim.cppConst(Identifier, "toPrimitive"); +// pub var toStringTag: Identifier = shim.cppConst(Identifier, "toStringTag"); +// pub var unscopable: Identifier = shim.cppConst(Identifier, "unscopabl"); + +// }; + +pub const EncodedJSValue = opaque { + pub const shim = Shimmer("JSC", "EncodedJSValue", @This()); + + pub const Type = u64; + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/VM.h>"; + pub const name = "JSC::VM"; + pub const namespace = "JSC"; + + // pub const Extern = [_][]const u8{}; +}; + +pub const Identifier = opaque { + pub const shim = Shimmer("JSC", "Identifier", @This()); + + const cppFn = shim.cppFn; + + pub const include = "<JavaScriptCore/Identifier.h>"; + pub const name = "JSC::Identifier"; + pub const namespace = "JSC"; + + pub fn fromString(vm: *VM, other: *String) *Identifier { + return cppFn("fromString", .{ vm, other }); + } + + pub fn fromSlice(vm: *VM, ptr: [*]u8, len: usize) *Identifier { + return cppFn("fromSlice", .{ vm, ptr, len }); + } + + pub fn fromUid(vm: *VM, other: *StringImpl) *Identifier { + return cppFn("fromString", .{ vm, other }); + } + + pub fn deinit(vm: *VM) void { + return cppFn("deinit", .{vm}); + } + + pub fn toString(identifier: *Identifier) *String { + return cppFn("toString", .{identifier}); + } + + pub fn length(identifier: *Identifier) usize { + return cppFn("length", .{identifier}); + } + + pub fn isNull(this: *Identifier) bool { + return cppFn("isNull", .{this}); + } + pub fn isEmpty(this: *Identifier) bool { + return cppFn("isEmpty", .{this}); + } + pub fn isSymbol(this: *Identifier) bool { + return cppFn("isSymbol", .{this}); + } + pub fn isPrivateName(this: *Identifier) bool { + return cppFn("isPrivateName", .{this}); + } + + pub fn eqlIdent(this: *Identifier, other: *Identifier) bool { + return cppFn("eqlIdent", .{ this, other }); + } + + pub fn neqlIdent(this: *Identifier, other: *Identifier) bool { + return cppFn("neqlIdent", .{ this, other }); + } + + pub fn eqlStringImpl(this: *Identifier, other: *StringImpl) bool { + return cppFn("eqlStringImpl", .{ this, other }); + } + + pub fn neqlStringImpl(this: *Identifier, other: *StringImpl) bool { + return cppFn("neqlStringImpl", .{ this, other }); + } + + pub fn eqlUTF8(this: *Identifier, other: [*]u8, other_len: usize) bool { + return cppFn("eqlUTF8", .{ this, other, other_len }); + } + + pub const Extern = [_][]const u8{ + "fromString", + "fromSlice", + "fromUid", + "deinit", + "toString", + "length", + "isNull", + "isEmpty", + "isSymbol", + "isPrivateName", + "eqlIdent", + "neqlIdent", + "eqlStringImpl", + "neqlStringImpl", + "eqlUTF8", + }; +}; + +pub const StringImpl = opaque { + pub const shim = Shimmer("WTF", "StringImpl", @This()); + + const cppFn = shim.cppFn; + + pub const include = "<WTF/text/StringImpl.h>"; + pub const name = "WTF::StringImpl"; + pub const namespace = "WTF"; + + pub fn is8Bit(this: *StringImpl) bool { + return cppFn("is8Bit", .{this}); + } + pub fn is16Bit(this: *StringImpl) bool { + return cppFn("is16Bit", .{this}); + } + pub fn isExternal(this: *StringImpl) bool { + return cppFn("isExternal", .{this}); + } + pub fn isStatic(this: *StringImpl) bool { + return cppFn("isStatic", .{this}); + } + pub fn isEmpty(this: *StringImpl) bool { + return cppFn("isEmpty", .{this}); + } + pub fn length(this: *StringImpl) usize { + return cppFn("length", .{this}); + } + pub fn characters8(this: *StringImpl) [*]u8 { + return cppFn("characters8", .{this}); + } + pub fn characters16(this: *StringImpl) [*]u16 { + return cppFn("characters16", .{this}); + } + + pub fn slice(this: *String) []const u8 { + if (this.isEmpty()) return ""; + + if (this.is8Bit()) { + return if (this.characters8()) |ptr| ptr[0..this.length()] else ""; + } else { + return if (this.characters8()) |ptr| ptr[0..this.length()] else ""; + } + } + + pub const Extern = [_][]const u8{ + "is8Bit", + "is16Bit", + "isExternal", + "isStatic", + "isEmpty", + "length", + "characters8", + "characters16", + }; +}; + +pub const StringView = opaque { + pub const shim = Shimmer("WTF", "StringView", @This()); + + const cppFn = shim.cppFn; + + pub const include = "<WTF/text/StringView.h>"; + pub const name = "WTF::StringView"; + pub const namespace = "WTF"; + + pub fn from8Bit(ptr: [*]const u8, len: usize) *StringView { + return cppFn("from8Bit", .{ ptr, len }); + } + + pub fn fromSlice(value: []const u8) *StringView { + return from8Bit(value.ptr, value.len); + } + + pub fn is8Bit(this: *StringView) bool { + return cppFn("is8Bit", .{this}); + } + pub fn is16Bit(this: *StringView) bool { + return cppFn("is16Bit", .{this}); + } + pub fn isEmpty(this: *StringView) bool { + return cppFn("isEmpty", .{this}); + } + pub fn length(this: *StringView) usize { + return cppFn("length", .{this}); + } + pub fn characters8(this: *StringView) ?[*]u8 { + return cppFn("characters8", .{this}); + } + pub fn characters16(this: *StringView) ?[*]u16 { + return cppFn("characters16", .{this}); + } + + pub fn slice(this: *StringView) []const u8 { + if (this.isEmpty()) return ""; + + if (this.is8Bit()) { + return if (this.characters8()) |ptr| ptr[0..this.length()] else ""; + } else { + return if (this.characters8()) |ptr| ptr[0..this.length()] else ""; + } + } + + pub const Extern = [_][]const u8{ + "from8Bit", + "is8Bit", + "is16Bit", + "isEmpty", + "length", + "characters8", + "characters16", + }; +}; + +pub const Cpp = opaque { + pub const Function = fn ( + globalObject: *JSGlobalObject, + callframe: CallFrame, + ) *EncodedJSValue; + pub const Getter = fn ( + globalObject: *JSGlobalObject, + this: *EncodedJSValue, + propertyName: *PropertyName, + ) *EncodedJSValue; + pub const Setter = fn ( + globalObject: *JSGlobalObject, + this: *EncodedJSValue, + value: EncodedJSValue, + propertyName: *PropertyName, + ) bool; + + pub const Tag = enum { + Callback, + Constructor, + Getter, + Setter, + }; + + pub const LUTAttribute = enum { + Function, + Accessor, + CellProperty, + ClassStructure, + PropertyCallback, + }; + + pub const ZigValue = union(Tag) { + Callback: Function, + Constructor: Function, + Getter: Getter, + Setter: Setter, + }; +}; +pub const Callback = opaque { + // zig: Value, +}; + +const _JSGlobalObject = _Wundle("JSGlobalObject"); const ObjectPrototype = _JSCellStub("ObjectPrototype"); const FunctionPrototype = _JSCellStub("FunctionPrototype"); const ArrayPrototype = _JSCellStub("ArrayPrototype"); -const JSObject = _JSCellStub("JSObject"); const StringPrototype = _JSCellStub("StringPrototype"); const BigIntPrototype = _JSCellStub("BigIntPrototype"); const RegExpPrototype = _JSCellStub("RegExpPrototype"); @@ -269,4 +1524,3 @@ const SetIteratorPrototype = _JSCellStub("SetIteratorPrototype"); const JSPromisePrototype = _JSCellStub("JSPromisePrototype"); const AsyncGeneratorPrototype = _JSCellStub("AsyncGeneratorPrototype"); const AsyncGeneratorFunctionPrototype = _JSCellStub("AsyncGeneratorFunctionPrototype"); -const String = _WTF("String"); diff --git a/src/javascript/jsc/bindings/bindings-generator.zig b/src/javascript/jsc/bindings/bindings-generator.zig index ac6fbe738..96a36cd59 100644 --- a/src/javascript/jsc/bindings/bindings-generator.zig +++ b/src/javascript/jsc/bindings/bindings-generator.zig @@ -27,6 +27,5 @@ pub fn main() anyerror!void { Bindings, "src/javascript/jsc/bindings/bindings.zig", ); - HeaderGenerator.exec(HeaderGenerator{}, file); } diff --git a/src/javascript/jsc/bindings/header-gen.zig b/src/javascript/jsc/bindings/header-gen.zig index e0ea96a21..3a8d11040 100644 --- a/src/javascript/jsc/bindings/header-gen.zig +++ b/src/javascript/jsc/bindings/header-gen.zig @@ -7,22 +7,35 @@ const EnumMeta = std.builtin.TypeInfo.Enum; const UnionMeta = std.builtin.TypeInfo.Union; const warn = std.debug.warn; +fn isCppObject(comptime Type: type) bool { + return switch (@typeInfo(Type)) { + .Struct, .Union, .Opaque => true, + else => false, + }; +} + pub const C_Generator = struct { file: std.fs.File, filebase: []const u8, + + direction: Direction = .export_cpp, const Self = @This(); + pub const Direction = enum { + export_cpp, + export_zig, + }; + pub fn init(comptime src_file: []const u8, file: std.fs.File) Self { var res = Self{ .file = file, .filebase = src_file }; - file.writeAll("\n/**** " ++ src_file ++ " /*****/\n\n") catch unreachable; return res; } - pub fn deinit(self: *Self) void { - self.file.writeAll("\n/***** ") catch unreachable; - self.file.writeAll(self.filebase) catch unreachable; - self.file.writeAll(" *****/") catch unreachable; + pub fn deinit(self: *const Self) void { + // self.file.writeAll("\n/**** </") catch unreachable; + // self.file.writeAll(self.filebase) catch unreachable; + // self.file.writeAll("> ****/\n\n") catch unreachable; } pub fn gen_func(self: *Self, comptime name: []const u8, comptime func: FnDecl, comptime meta: FnMeta, comptime arg_names: []const []const u8) void { @@ -34,7 +47,11 @@ pub const C_Generator = struct { else => {}, } - self.write("extern \"C\" "); + switch (self.direction) { + .export_cpp => self.write("CPP_DECL \"C\" "), + .export_zig => self.write("ZIG_DECL \"C\" "), + } + self.writeType(func.return_type); self.write(" " ++ name ++ "("); @@ -43,7 +60,12 @@ pub const C_Generator = struct { if (func.arg_names.len > i) { self.write(comptime arg_names[i]); } else { - self.write(comptime std.fmt.comptimePrint(" arg{d}", .{i})); + const ArgType = arg.arg_type.?; + if (@typeInfo(ArgType) == .Enum) { + self.write(comptime std.fmt.comptimePrint(" {s}{d}", .{ @typeName(ArgType), i })); + } else { + self.write(comptime std.fmt.comptimePrint(" arg{d}", .{i})); + } } //TODO: Figure out how to get arg names; for now just do arg0..argN @@ -51,7 +73,16 @@ pub const C_Generator = struct { self.write(", "); } - self.write(");\n"); + self.write(")"); + defer self.write(";\n"); + // const ReturnTypeInfo: std.builtin.TypeInfo = comptime @typeInfo(func.return_type); + // switch (comptime ReturnTypeInfo) { + // .Pointer => |Pointer| { + // self.write(" __attribute__((returns_nonnull))"); + // }, + // .Optional => |Optional| {}, + // else => {}, + // } } pub fn gen_struct(self: *Self, comptime name: []const u8, comptime meta: StructMeta) void { @@ -118,20 +149,20 @@ pub const C_Generator = struct { } fn writeType(self: *Self, comptime T: type) void { - const TT = if (@typeInfo(T) == .Pointer) @typeInfo(T).Pointer.child else T; + const TT = comptime if (@typeInfo(T) == .Pointer) @typeInfo(T).Pointer.child else T; - if (comptime std.meta.trait.hasDecls(TT, .{"C"}) and std.meta.trait.hasDecls(TT.C, .{"name"})) { - writeType(self, TT.C); - if (std.meta.trait.isSingleItemPtr(T)) { - write(self, "*"); + if (comptime (isCppObject(TT)) and @hasDecl(TT, "name")) { + if (@typeInfo(T) == .Pointer or @hasDecl(TT, "Type") and @typeInfo(TT.Type) == .Pointer) { + if (@hasDecl(TT, "is_pointer") and !TT.is_pointer) {} else if (@typeInfo(T).Pointer.is_const) { + write(self, "const "); + } } - return; - } - if (comptime std.meta.trait.hasDecls(TT, .{"name"})) { - self.write(comptime T.name); - if (std.meta.trait.isSingleItemPtr(T)) { - write(self, "*"); + self.write(comptime TT.name); + if (@typeInfo(T) == .Pointer or @hasDecl(TT, "Type") and @typeInfo(TT.Type) == .Pointer) { + if (@hasDecl(TT, "is_pointer") and !TT.is_pointer) {} else { + write(self, "*"); + } } return; } @@ -141,7 +172,7 @@ pub const C_Generator = struct { bool => self.write("bool"), usize => self.write("size_t"), isize => self.write("int"), - u8 => self.write("uint8_t"), + u8 => self.write("char"), u16 => self.write("uint16_t"), u32 => self.write("uint32_t"), u64 => self.write("uint64_t"), @@ -150,10 +181,13 @@ pub const C_Generator = struct { i24 => self.write("int24_t"), i32 => self.write("int32_t"), i64 => self.write("int64_t"), + f64 => self.write("double"), + f32 => self.write("float"), + *c_void => self.write("void*"), [*]bool => self.write("bool*"), [*]usize => self.write("size_t*"), [*]isize => self.write("int*"), - [*]u8 => self.write("uint8_t*"), + [*]u8 => self.write("char*"), [*]u16 => self.write("uint16_t*"), [*]u32 => self.write("uint32_t*"), [*]u64 => self.write("uint64_t*"), @@ -161,11 +195,22 @@ pub const C_Generator = struct { [*]i16 => self.write("int16_t*"), [*]i32 => self.write("int32_t*"), [*]i64 => self.write("int64_t*"), + [*]const bool => self.write("const bool*"), + [*]const usize => self.write("const size_t*"), + [*]const isize => self.write("const int*"), + [*]const u8 => self.write("const char*"), + [*]const u16 => self.write("const uint16_t*"), + [*]const u32 => self.write("const uint32_t*"), + [*]const u64 => self.write("const uint64_t*"), + [*]const i8 => self.write("const int8_t*"), + [*]const i16 => self.write("const int16_t*"), + [*]const i32 => self.write("const int32_t*"), + [*]const i64 => self.write("const int64_t*"), else => { const meta = @typeInfo(T); switch (meta) { - .Pointer => { - const child = meta.Pointer.child; + .Pointer => |Pointer| { + const child = Pointer.child; const childmeta = @typeInfo(child); // if (childmeta == .Struct and childmeta.Struct.layout != .Extern) { // self.write("void"); @@ -176,7 +221,12 @@ pub const C_Generator = struct { }, .Optional => self.writeType(meta.Optional.child), .Array => @compileError("Handle goofy looking C Arrays in the calling function"), - else => self.write(@typeName(T) ++ "_t"), + .Enum => |Enum| { + self.writeType(Enum.tag_type); + }, + else => { + return self.write(@typeName(T)); + }, } }, } @@ -226,10 +276,10 @@ pub fn getCStruct(comptime T: type) ?NamedStruct { } inline for (std.meta.declarations(T)) |decl| { - if (std.mem.eql(u8, decl.name, "C")) { + if (std.mem.eql(u8, decl.name, "Type")) { switch (decl.data) { - .Type => |TT| { - return NamedStruct{ .Type = TT, .name = @typeName(T) }; + .Type => { + return NamedStruct{ .Type = T, .name = @typeName(T) }; }, else => {}, } @@ -244,24 +294,14 @@ pub fn HeaderGen(comptime import: type, comptime fname: []const u8) type { return struct { source_file: []const u8 = fname, - + gen: C_Generator = undefined, const Self = @This(); pub fn init() Self { return Self{}; } - pub fn processDecls( - comptime self: Self, - file: std.fs.File, - comptime Parent: type, - comptime Type: type, - comptime prefix: []const u8, - ) void { - const decls = std.meta.declarations(Type); - var gen = C_Generator.init(prefix, file); - defer gen.deinit(); - + pub fn startFile(comptime self: Self, comptime Type: type, comptime prefix: []const u8, file: std.fs.File) void { if (comptime std.meta.trait.hasDecls(Type, .{"include"})) { comptime var new_name = std.mem.zeroes([Type.include.len]u8); @@ -270,65 +310,63 @@ pub fn HeaderGen(comptime import: type, comptime fname: []const u8) type { _ = std.mem.replace(u8, &new_name, ".", "_", std.mem.span(&new_name)); } const inner_name = comptime std.mem.trim(u8, &new_name, "<>\""); - file.writeAll("#ifndef BINDINGS__decls__" ++ inner_name ++ "\n") catch {}; + file.writeAll("\n#pragma mark - " ++ Type.name ++ "\n") catch unreachable; + file.writeAll("\n#ifndef BINDINGS__decls__" ++ inner_name ++ "\n") catch {}; file.writeAll("#define BINDINGS__decls__" ++ inner_name ++ "\n") catch {}; file.writeAll("#include " ++ Type.include ++ "\n") catch {}; - file.writeAll("namespace Wundle {\n class " ++ prefix ++ ";\n}\n") catch {}; + file.writeAll("namespace " ++ Type.namespace ++ " {\n class " ++ prefix ++ ";\n}\n") catch {}; file.writeAll("#endif\n\n") catch {}; } - - // iterate exported enums - // do this first in case target lang needs enums defined before use - inline for (decls) |decl| { - if (decl.is_pub and decl.data == .Type and comptime std.ascii.isUpper(decl.name[0])) { - const T = decl.data.Type; - const info = @typeInfo(T); - if (info == .Enum and decl.is_pub) { - const layout = info.Enum.layout; - gen.gen_enum(prefix ++ "__" ++ decl.name, info.Enum); - } - } - } - - // iterate exported structs - inline for (decls) |decl| { - if (decl.is_pub and decl.data == .Type and decl.is_pub and comptime std.ascii.isUpper(decl.name[0])) { - const T = decl.data.Type; - const info = @typeInfo(T); - if (info == .Struct and decl.is_pub) { - gen.gen_struct(decl.name, @typeInfo(T).Struct); - } - } - } - - inline for (decls) |decl| { - if (decl.is_pub and decl.data == .Type and decl.is_pub) { - const T = decl.data.Type; - const info = @typeInfo(T); - if (info == .Union and comptime std.ascii.isUpper(decl.name[0])) { - const layout = info.Union.layout; - gen.gen_union(prefix ++ "__" ++ decl.name, info.Union); + } + pub fn processDecl( + comptime self: Self, + file: std.fs.File, + gen: *C_Generator, + comptime Container: type, + comptime Decl: std.builtin.TypeInfo.Declaration, + comptime name: []const u8, + comptime prefix: []const u8, + ) void { + switch (comptime Decl.data) { + .Type => |Type| { + switch (@typeInfo(Type)) { + .Enum => |Enum| { + const layout = Enum.layout; + gen.gen_enum(prefix ++ "__" ++ name, Enum); + }, + .Struct => |Struct| { + gen.gen_struct(decl.name, Struct); + }, + .Union => |Union| { + const layout = Union.layout; + gen.gen_union(prefix ++ "__" ++ name, Union); + }, + .Fn => |func| { + // if (func.) { + const fn_meta = @typeInfo(func.name).Fn; + // blocked by https://github.com/ziglang/zig/issues/8259 + gen.gen_func( + prefix ++ "__" ++ name, + func, + fn_meta, + &.{}, + ); + }, + else => {}, } - } - } - - // iterate exported fns - inline for (decls) |decl, decl_i| { - if (decl.is_pub and decl.data == .Fn and decl.is_pub) { - const func = decl.data.Fn; + }, + .Fn => |func| { // if (func.) { const fn_meta = @typeInfo(func.fn_type).Fn; - const info = @typeInfo(Type); - const struct_decl = info.Struct.decls[decl_i]; // blocked by https://github.com/ziglang/zig/issues/8259 gen.gen_func( - prefix ++ "__" ++ decl.name, + prefix ++ "__" ++ name, func, fn_meta, - struct_decl.data.Fn.arg_names, + &.{}, ); - // } - } + }, + else => {}, } } @@ -336,20 +374,36 @@ pub fn HeaderGen(comptime import: type, comptime fname: []const u8) type { const Generator = C_Generator; validateGenerator(Generator); - file.writeAll("#pragma once\n#include <stddef.h>\n#include <stdint.h>\n#include <stdbool.h>\n\n") catch {}; + file.writeAll("#pragma once\n#include <stddef.h>\n#include <stdint.h>\n#include <stdbool.h>\n#define ZIG_DECL extern\n#define CPP_DECL extern \n\n") catch {}; inline for (all_decls) |_decls| { if (comptime _decls.is_pub) { switch (_decls.data) { .Type => |Type| { - if (getCStruct(Type)) |CStruct| { - processDecls( - self, - file, - Type, - CStruct.Type, - CStruct.name, - ); + @setEvalBranchQuota(99999); + if (@hasDecl(Type, "Extern")) { + self.startFile(Type, Type.shim.name, file); + var gen = C_Generator.init(Type.name, file); + defer gen.deinit(); + inline for (Type.Extern) |extern_decl| { + if (@hasDecl(Type, extern_decl)) { + const normalized_name = comptime brk: { + var _normalized_name: [Type.name.len]u8 = undefined; + _ = std.mem.replace(u8, Type.name, ":", "_", std.mem.span(&_normalized_name)); + break :brk _normalized_name; + }; + + processDecl( + self, + file, + &gen, + Type, + comptime std.meta.declarationInfo(Type, extern_decl), + comptime extern_decl, + comptime std.mem.span(&normalized_name), + ); + } + } } }, else => {}, diff --git a/src/javascript/jsc/bindings/headers.h b/src/javascript/jsc/bindings/headers.h index 231c6697e..422c687a0 100644 --- a/src/javascript/jsc/bindings/headers.h +++ b/src/javascript/jsc/bindings/headers.h @@ -2,41 +2,398 @@ #include <stddef.h> #include <stdint.h> #include <stdbool.h> +#define ZIG_DECL extern +#define CPP_DECL extern -/**** DefaultGlobal /*****/ - -#ifndef BINDINGS__decls__DefaultGlobal_h -#define BINDINGS__decls__DefaultGlobal_h -#include "DefaultGlobal.h" -namespace Wundle { - class DefaultGlobal; -} -#endif - -extern "C" JSC::ObjectPrototype* DefaultGlobal__objectPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::FunctionPrototype* DefaultGlobal__functionPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::ArrayPrototype* DefaultGlobal__arrayPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSObject* DefaultGlobal__booleanPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::StringPrototype* DefaultGlobal__stringPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSObject* DefaultGlobal__numberPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::BigIntPrototype* DefaultGlobal__bigIntPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSObject* DefaultGlobal__datePrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSObject* DefaultGlobal__symbolPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::RegExpPrototype* DefaultGlobal__regExpPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSObject* DefaultGlobal__errorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::IteratorPrototype* DefaultGlobal__iteratorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::AsyncIteratorPrototype* DefaultGlobal__asyncIteratorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::GeneratorFunctionPrototype* DefaultGlobal__generatorFunctionPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::GeneratorPrototype* DefaultGlobal__generatorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::AsyncFunctionPrototype* DefaultGlobal__asyncFunctionPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::ArrayIteratorPrototype* DefaultGlobal__arrayIteratorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::MapIteratorPrototype* DefaultGlobal__mapIteratorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::SetIteratorPrototype* DefaultGlobal__setIteratorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSObject* DefaultGlobal__mapPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSObject* DefaultGlobal__jsSetPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::JSPromisePrototype* DefaultGlobal__promisePrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::AsyncGeneratorPrototype* DefaultGlobal__asyncGeneratorPrototype(Wundle::DefaultGlobal* arg0); -extern "C" JSC::AsyncGeneratorFunctionPrototype* DefaultGlobal__asyncGeneratorFunctionPrototype(Wundle::DefaultGlobal* arg0); - -/***** DefaultGlobal *****/
\ No newline at end of file +#pragma mark - JSC::JSObject + +#ifndef BINDINGS__decls__JavaScriptCore_JSObject_h +#define BINDINGS__decls__JavaScriptCore_JSObject_h +#include <JavaScriptCore/JSObject.h> +namespace JSC { + class JSObject; +} +#endif + +CPP_DECL "C" bool JSC__JSObject__hasProperty(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1, JSC::PropertyName* arg2); +CPP_DECL "C" JSC::PropertyNameArray* JSC__JSObject__getPropertyNames(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" size_t JSC__JSObject__getArrayLength(JSC::JSObject* arg0); +CPP_DECL "C" JSC::JSValue JSC__JSObject__getDirect(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1, JSC::PropertyName* arg2); +CPP_DECL "C" bool JSC__JSObject__putDirect(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1, JSC::PropertyName* arg2, JSC::JSValue arg3); +CPP_DECL "C" JSC::JSValue JSC__JSObject__get(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1, JSC::PropertyName* arg2); +CPP_DECL "C" JSC::JSValue JSC__JSObject__getAtIndex(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1, JSC::PropertyName* arg2, uint32_t arg3); +CPP_DECL "C" bool JSC__JSObject__putAtIndex(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1, JSC::PropertyName* arg2, uint32_t arg3); +CPP_DECL "C" JSC::JSValue JSC__JSObject__getIfExists(JSC::JSObject* arg0, JSC::JSGlobalObject* arg1, JSC::PropertyName* arg2); + +#pragma mark - JSC::PropertyNameArray + +#ifndef BINDINGS__decls__JavaScriptCore_PropertyNameArray_h +#define BINDINGS__decls__JavaScriptCore_PropertyNameArray_h +#include <JavaScriptCore/PropertyNameArray.h> +namespace JSC { + class PropertyNameArray; +} +#endif + +CPP_DECL "C" size_t JSC__PropertyNameArray__length(JSC::PropertyNameArray* arg0); +CPP_DECL "C" void JSC__PropertyNameArray__release(JSC::PropertyNameArray* arg0); +CPP_DECL "C" const JSC::PropertyName* JSC__PropertyNameArray__next(JSC::PropertyNameArray* arg0, size_t arg1); + +#pragma mark - JSC::JSCell + +#ifndef BINDINGS__decls__JavaScriptCore_JSCell_h +#define BINDINGS__decls__JavaScriptCore_JSCell_h +#include <JavaScriptCore/JSCell.h> +namespace JSC { + class JSCell; +} +#endif + +CPP_DECL "C" JSC::JSObject* JSC__JSCell__getObject(JSC::JSCell* arg0); +CPP_DECL "C" WTF::WTFString* JSC__JSCell__getString(JSC::JSCell* arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" char JSC__JSCell__getType(JSC::JSCell* arg0); + +#pragma mark - JSC::JSString + +#ifndef BINDINGS__decls__JavaScriptCore_JSString_h +#define BINDINGS__decls__JavaScriptCore_JSString_h +#include <JavaScriptCore/JSString.h> +namespace JSC { + class JSString; +} +#endif + +CPP_DECL "C" JSC::JSObject* JSC__JSString__getObject(JSC::JSString* arg0); +CPP_DECL "C" bool JSC__JSString__eql(const JSC::JSString* arg0, const JSC::JSString* arg1); +CPP_DECL "C" WTF::WTFString* JSC__JSString__value(JSC::JSString* arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" size_t JSC__JSString__length(const JSC::JSString* arg0); +CPP_DECL "C" bool JSC__JSString__is8Bit(const JSC::JSString* arg0); +CPP_DECL "C" bool JSC__JSString__createFromOwnedString(JSC::VM* arg0, WTF::StringImpl* arg1); +CPP_DECL "C" bool JSC__JSString__createFromString(JSC::VM* arg0, WTF::StringImpl* arg1); + +#pragma mark - JSC::JSPromise + +#ifndef BINDINGS__decls__JavaScriptCore_JSPromise_h +#define BINDINGS__decls__JavaScriptCore_JSPromise_h +#include <JavaScriptCore/JSPromise.h> +namespace JSC { + class JSPromise; +} +#endif + +CPP_DECL "C" uint32_t JSC__JSPromise__status(JSC::JSPromise* arg0, JSC::VM* arg1); +CPP_DECL "C" JSC::JSValue JSC__JSPromise__result(JSC::JSPromise* arg0, JSC::VM* arg1); +CPP_DECL "C" bool JSC__JSPromise__isHandled(JSC::JSPromise* arg0, JSC::VM* arg1); +CPP_DECL "C" JSC::JSPromise* JSC__JSPromise__resolvedPromise(JSC::JSGlobalObject* arg0, JSC::JSValue arg1); +CPP_DECL "C" JSC::JSPromise* JSC__JSPromise__rejectedPromise(JSC::JSGlobalObject* arg0, JSC::JSValue arg1); +CPP_DECL "C" void JSC__JSPromise__resolve(JSC::JSGlobalObject* arg0, JSC::JSValue arg1); +CPP_DECL "C" void JSC__JSPromise__reject(JSC::JSPromise* arg0, JSC::JSGlobalObject* arg1, JSC::JSValue arg2); +CPP_DECL "C" void JSC__JSPromise__rejectAsHandled(JSC::JSPromise* arg0, JSC::JSGlobalObject* arg1, JSC::JSValue arg2); +CPP_DECL "C" void JSC__JSPromise__rejectException(JSC::JSPromise* arg0, JSC::JSGlobalObject* arg1, JSC::Exception* arg2); +CPP_DECL "C" void JSC__JSPromise__rejectAsHandledException(JSC::JSPromise* arg0, JSC::JSGlobalObject* arg1, JSC::Exception* arg2); +CPP_DECL "C" bool JSC__JSPromise__isInternal(JSC::JSPromise* arg0, JSC::VM* arg1); +CPP_DECL "C" JSC::JSPromise* JSC__JSPromise__createDeferred(JSC::JSGlobalObject* arg0, JSC::JSFunction* arg1, JSC::JSFunction* arg2, JSC::Exception* arg3); + +#pragma mark - JSC::SourceOrigin + +#ifndef BINDINGS__decls__JavaScriptCore_SourceOrigin_h +#define BINDINGS__decls__JavaScriptCore_SourceOrigin_h +#include <JavaScriptCore/SourceOrigin.h> +namespace JSC { + class SourceOrigin; +} +#endif + +CPP_DECL "C" const JSC::SourceOrigin* JSC__SourceOrigin__fromURL(const WTF::URL* arg0); + +#pragma mark - JSC::SourceCode + +#ifndef BINDINGS__decls__JavaScriptCore_SourceProvider_h +#define BINDINGS__decls__JavaScriptCore_SourceProvider_h +#include <JavaScriptCore/SourceProvider.h> +namespace JSC { + class SourceCode; +} +#endif + +CPP_DECL "C" const JSC::SourceCode* JSC__SourceCode__fromString(const WTF::WTFString* arg0, const JSC::SourceOrigin* arg1, WTF::WTFString* arg2, char SourceType3); + +#pragma mark - JSC::JSFunction + +#ifndef BINDINGS__decls__JavaScriptCore_JSFunction_h +#define BINDINGS__decls__JavaScriptCore_JSFunction_h +#include <JavaScriptCore/JSFunction.h> +namespace JSC { + class JSFunction; +} +#endif + +CPP_DECL "C" JSC::JSFunction* JSC__JSFunction__createFromSourceCode(JSC::SourceCode* arg0, JSC::SourceOrigin* arg1, JSC::Exception* arg2); +CPP_DECL "C" JSC::JSFunction* JSC__JSFunction__createFromNative(JSC::VM* arg0, JSC::JSGlobalObject* arg1, uint32_t arg2, WTF::WTFString* arg3, void* arg4); +CPP_DECL "C" WTF::WTFString* JSC__JSFunction__getName(JSC::JSFunction* arg0, JSC::VM* arg1); +CPP_DECL "C" WTF::WTFString* JSC__JSFunction__displayName(JSC::JSFunction* arg0, JSC::VM* arg1); +CPP_DECL "C" WTF::WTFString* JSC__JSFunction__calculatedDisplayName(JSC::JSFunction* arg0, JSC::VM* arg1); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__callWithArgumentsAndThis(JSC::JSFunction* arg0, JSC::JSValue arg1, JSC::JSGlobalObject* arg2, JSC::JSValue* arg3, size_t arg4, JSC::Exception** arg5, char* arg6); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__callWithArguments(JSC::JSFunction* arg0, JSC::JSGlobalObject* arg1, JSC::JSValue* arg2, size_t arg3, JSC::Exception** arg4, char* arg5); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__callWithThis(JSC::JSFunction* arg0, JSC::JSGlobalObject* arg1, JSC::JSValue arg2, JSC::Exception** arg3, char* arg4); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__callWithoutAnyArgumentsOrThis(JSC::JSFunction* arg0, JSC::JSGlobalObject* arg1, JSC::Exception** arg2, char* arg3); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__constructWithArgumentsAndNewTarget(JSC::JSFunction* arg0, JSC::JSValue arg1, JSC::JSGlobalObject* arg2, JSC::JSValue* arg3, size_t arg4, JSC::Exception** arg5, char* arg6); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__constructWithArguments(JSC::JSFunction* arg0, JSC::JSGlobalObject* arg1, JSC::JSValue* arg2, size_t arg3, JSC::Exception** arg4, char* arg5); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__constructWithNewTarget(JSC::JSFunction* arg0, JSC::JSGlobalObject* arg1, JSC::JSValue arg2, JSC::Exception** arg3, char* arg4); +CPP_DECL "C" JSC::JSValue JSC__JSFunction__constructWithoutAnyArgumentsOrNewTarget(JSC::JSFunction* arg0, JSC::JSGlobalObject* arg1, JSC::Exception** arg2, char* arg3); + +#pragma mark - JSC::JSGlobalObject + +#ifndef BINDINGS__decls__JavaScriptCore_JSGlobalObject_h +#define BINDINGS__decls__JavaScriptCore_JSGlobalObject_h +#include <JavaScriptCore/JSGlobalObject.h> +namespace JSC { + class JSGlobalObject; +} +#endif + +CPP_DECL "C" JSC::ObjectPrototype* JSC__JSGlobalObject__objectPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::FunctionPrototype* JSC__JSGlobalObject__functionPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::ArrayPrototype* JSC__JSGlobalObject__arrayPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__booleanPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::StringPrototype* JSC__JSGlobalObject__stringPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__numberPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::BigIntPrototype* JSC__JSGlobalObject__bigIntPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__datePrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__symbolPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::RegExpPrototype* JSC__JSGlobalObject__regExpPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__errorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::IteratorPrototype* JSC__JSGlobalObject__iteratorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::AsyncIteratorPrototype* JSC__JSGlobalObject__asyncIteratorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::GeneratorFunctionPrototype* JSC__JSGlobalObject__generatorFunctionPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::GeneratorPrototype* JSC__JSGlobalObject__generatorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::AsyncFunctionPrototype* JSC__JSGlobalObject__asyncFunctionPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::ArrayIteratorPrototype* JSC__JSGlobalObject__arrayIteratorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::MapIteratorPrototype* JSC__JSGlobalObject__mapIteratorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::SetIteratorPrototype* JSC__JSGlobalObject__setIteratorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__mapPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__jsSetPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::JSPromisePrototype* JSC__JSGlobalObject__promisePrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::AsyncGeneratorPrototype* JSC__JSGlobalObject__asyncGeneratorPrototype(JSC::JSGlobalObject* arg0); +CPP_DECL "C" JSC::AsyncGeneratorFunctionPrototype* JSC__JSGlobalObject__asyncGeneratorFunctionPrototype(JSC::JSGlobalObject* arg0); + +#pragma mark - WTF::URL + +#ifndef BINDINGS__decls__wtf_URL_h +#define BINDINGS__decls__wtf_URL_h +#include <wtf/URL.h> +namespace WTF { + class URL; +} +#endif + +CPP_DECL "C" WTF::URL* WTF__URL__fromFileSystemPath(const WTF::StringView* arg0); +CPP_DECL "C" WTF::URL* WTF__URL__fromString(const WTF::WTFString* arg0, const WTF::WTFString* arg1); +CPP_DECL "C" bool WTF__URL__isEmpty(const WTF::URL* arg0); +CPP_DECL "C" bool WTF__URL__isValid(const WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__protocol(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__encodedUser(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__encodedPassword(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__host(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__path(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__lastPathComponent(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__query(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__fragmentIdentifier(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__queryWithLeadingQuestionMark(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__fragmentIdentifierWithLeadingNumberSign(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__stringWithoutQueryOrFragmentIdentifier(WTF::URL* arg0); +CPP_DECL "C" const WTF::StringView* WTF__URL__stringWithoutFragmentIdentifier(WTF::URL* arg0); +CPP_DECL "C" const WTF::WTFString* WTF__URL__protocolHostAndPort(WTF::URL* arg0); +CPP_DECL "C" const WTF::WTFString* WTF__URL__hostAndPort(WTF::URL* arg0); +CPP_DECL "C" const WTF::WTFString* WTF__URL__user(WTF::URL* arg0); +CPP_DECL "C" const WTF::WTFString* WTF__URL__password(WTF::URL* arg0); +CPP_DECL "C" const WTF::WTFString* WTF__URL__fileSystemPath(WTF::URL* arg0); +CPP_DECL "C" void WTF__URL__setProtocol(WTF::URL* arg0, const WTF::StringView* arg1); +CPP_DECL "C" void WTF__URL__setHost(WTF::URL* arg0, const WTF::StringView* arg1); +CPP_DECL "C" void WTF__URL__setHostAndPort(WTF::URL* arg0, const WTF::StringView* arg1); +CPP_DECL "C" void WTF__URL__setUser(WTF::URL* arg0, const WTF::StringView* arg1); +CPP_DECL "C" void WTF__URL__setPassword(WTF::URL* arg0, const WTF::StringView* arg1); +CPP_DECL "C" void WTF__URL__setPath(WTF::URL* arg0, const WTF::StringView* arg1); +CPP_DECL "C" void WTF__URL__setQuery(WTF::URL* arg0, const WTF::StringView* arg1); +CPP_DECL "C" WTF::URL* WTF__URL__truncatedForUseAsBase(WTF::URL* arg0); + +#pragma mark - WTF::WTFString + +#ifndef BINDINGS__decls__wtf_text_WTFString_h +#define BINDINGS__decls__wtf_text_WTFString_h +#include <wtf/text/WTFString.h> +namespace WTF { + class WTFString; +} +#endif + +CPP_DECL "C" bool WTF__WTFString__is8Bit(WTF::WTFString* arg0); +CPP_DECL "C" bool WTF__WTFString__is16Bit(WTF::WTFString* arg0); +CPP_DECL "C" bool WTF__WTFString__isExternal(WTF::WTFString* arg0); +CPP_DECL "C" bool WTF__WTFString__isStatic(WTF::WTFString* arg0); +CPP_DECL "C" bool WTF__WTFString__isEmpty(WTF::WTFString* arg0); +CPP_DECL "C" size_t WTF__WTFString__length(WTF::WTFString* arg0); +CPP_DECL "C" char* WTF__WTFString__characters8(WTF::WTFString* arg0); +CPP_DECL "C" char* WTF__WTFString__characters16(WTF::WTFString* arg0); +CPP_DECL "C" WTF::WTFString* WTF__WTFString__createWithoutCopyingFromPtr(const char* arg0, size_t arg1); +CPP_DECL "C" bool WTF__WTFString__eqlString(WTF::WTFString* arg0, WTF::WTFString* arg1); +CPP_DECL "C" bool WTF__WTFString__eqlSlice(WTF::WTFString* arg0, char* arg1, size_t arg2); +CPP_DECL "C" WTF::StringImpl* WTF__WTFString__impl(WTF::WTFString* arg0); +CPP_DECL "C" WTF::WTFString* WTF__WTFString__createFromExternalString(WTF::StringImpl* arg0); + +#pragma mark - JSC::JSValue + +#ifndef BINDINGS__decls__JavaScriptCore_JSValue_h +#define BINDINGS__decls__JavaScriptCore_JSValue_h +#include <JavaScriptCore/JSValue.h> +namespace JSC { + class JSValue; +} +#endif + +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsNull(); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsUndefined(); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsTDZValue(); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsBoolean(bool arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsDoubleNumber(double arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsNumberFromDouble(double arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsNumberFromChar(char arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsNumberFromU16(uint16_t arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsNumberFromInt32(int32_t arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsNumberFromInt64(int64_t arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__jsNumberFromUint64(uint64_t arg0); +CPP_DECL "C" bool JSC__JSValue__isUndefined(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isNull(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isUndefinedOrNull(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isBoolean(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isAnyInt(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isUInt32AsAnyInt(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isInt32AsAnyInt(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isNumber(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isString(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isBigInt(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isHeapBigInt(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isBigInt32(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isSymbol(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isPrimitive(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isGetterSetter(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isCustomGetterSetter(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isObject(JSC::JSValue arg0); +CPP_DECL "C" bool JSC__JSValue__isCell(JSC::JSValue arg0); +CPP_DECL "C" JSC::JSCell* JSC__JSValue__asCell(JSC::JSValue arg0); +CPP_DECL "C" JSC::JSString* JSC__JSValue__toString(JSC::JSValue arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" JSC::JSString* JSC__JSValue__toStringOrNull(JSC::JSValue arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" JSC::Identifier* JSC__JSValue__toPropertyKey(JSC::JSValue arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" JSC::JSValue JSC__JSValue__toPropertyKeyValue(JSC::JSValue arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" JSC::JSObject* JSC__JSValue__toObject(JSC::JSValue arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" WTF::WTFString* JSC__JSValue__toWTFString(JSC::JSValue arg0); +CPP_DECL "C" JSC::JSValue JSC__JSValue__getPrototype(JSC::JSValue arg0, JSC::JSGlobalObject* arg1); +CPP_DECL "C" JSC::JSValue JSC__JSValue__getPropertyByPropertyName(JSC::JSValue arg0, JSC::PropertyName* arg1, JSC::JSGlobalObject* arg2); +CPP_DECL "C" bool JSC__JSValue__eqlValue(JSC::JSValue arg0, JSC::JSValue arg1); +CPP_DECL "C" bool JSC__JSValue__eqlCell(JSC::JSValue arg0, JSC::JSCell* arg1); + +#pragma mark - JSC::JSGlobalObject + +#ifndef BINDINGS__decls__JavaScriptCore_Error_h +#define BINDINGS__decls__JavaScriptCore_Error_h +#include <JavaScriptCore/Error.h> +namespace JSC { + class JSGlobalObject; +} +#endif + +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__throwError(JSC::JSGlobalObject* arg0, JSC::JSObject* arg1); +CPP_DECL "C" JSC::JSObject* JSC__JSGlobalObject__createError(JSC::JSGlobalObject* arg0, char ErrorType1, WTF::WTFString* arg2); + +#pragma mark - JSC::Exception + +#ifndef BINDINGS__decls__JavaScriptCore_Exception_h +#define BINDINGS__decls__JavaScriptCore_Exception_h +#include <JavaScriptCore/Exception.h> +namespace JSC { + class Exception; +} +#endif + +CPP_DECL "C" JSC::Exception* JSC__Exception__create(JSC::JSGlobalObject* arg0, JSC::JSObject* arg1, char StackCaptureAction2); + +#pragma mark - JSC::CallFrame + +#ifndef BINDINGS__decls__JavaScriptCore_CallFrame_h +#define BINDINGS__decls__JavaScriptCore_CallFrame_h +#include <JavaScriptCore/CallFrame.h> +namespace JSC { + class CallFrame; +} +#endif + +CPP_DECL "C" size_t JSC__CallFrame__argumentsCount(const JSC::CallFrame* arg0); +CPP_DECL "C" JSC::JSValue JSC__CallFrame__uncheckedArgument(const JSC::CallFrame* arg0, uint16_t arg1); +CPP_DECL "C" JSC::JSValue JSC__CallFrame__argument(const JSC::CallFrame* arg0, uint16_t arg1); +CPP_DECL "C" JSC::JSValue JSC__CallFrame__thisValue(const JSC::CallFrame* arg0); +CPP_DECL "C" JSC::JSValue JSC__CallFrame__newTarget(const JSC::CallFrame* arg0); +CPP_DECL "C" JSC::JSObject* JSC__CallFrame__jsCallee(const JSC::CallFrame* arg0); + +#pragma mark - JSC::Identifier + +#ifndef BINDINGS__decls__JavaScriptCore_Identifier_h +#define BINDINGS__decls__JavaScriptCore_Identifier_h +#include <JavaScriptCore/Identifier.h> +namespace JSC { + class Identifier; +} +#endif + +CPP_DECL "C" JSC::Identifier* JSC__Identifier__fromString(JSC::VM* arg0, WTF::WTFString* arg1); +CPP_DECL "C" JSC::Identifier* JSC__Identifier__fromSlice(JSC::VM* arg0, char* arg1, size_t arg2); +CPP_DECL "C" JSC::Identifier* JSC__Identifier__fromUid(JSC::VM* arg0, WTF::StringImpl* arg1); +CPP_DECL "C" void JSC__Identifier__deinit(JSC::VM* arg0); +CPP_DECL "C" WTF::WTFString* JSC__Identifier__toString(JSC::Identifier* arg0); +CPP_DECL "C" size_t JSC__Identifier__length(JSC::Identifier* arg0); +CPP_DECL "C" bool JSC__Identifier__isNull(JSC::Identifier* arg0); +CPP_DECL "C" bool JSC__Identifier__isEmpty(JSC::Identifier* arg0); +CPP_DECL "C" bool JSC__Identifier__isSymbol(JSC::Identifier* arg0); +CPP_DECL "C" bool JSC__Identifier__isPrivateName(JSC::Identifier* arg0); +CPP_DECL "C" bool JSC__Identifier__eqlIdent(JSC::Identifier* arg0, JSC::Identifier* arg1); +CPP_DECL "C" bool JSC__Identifier__neqlIdent(JSC::Identifier* arg0, JSC::Identifier* arg1); +CPP_DECL "C" bool JSC__Identifier__eqlStringImpl(JSC::Identifier* arg0, WTF::StringImpl* arg1); +CPP_DECL "C" bool JSC__Identifier__neqlStringImpl(JSC::Identifier* arg0, WTF::StringImpl* arg1); +CPP_DECL "C" bool JSC__Identifier__eqlUTF8(JSC::Identifier* arg0, char* arg1, size_t arg2); + +#pragma mark - WTF::StringImpl + +#ifndef BINDINGS__decls__WTF_text_StringImpl_h +#define BINDINGS__decls__WTF_text_StringImpl_h +#include <WTF/text/StringImpl.h> +namespace WTF { + class StringImpl; +} +#endif + +CPP_DECL "C" bool WTF__StringImpl__is8Bit(WTF::StringImpl* arg0); +CPP_DECL "C" bool WTF__StringImpl__is16Bit(WTF::StringImpl* arg0); +CPP_DECL "C" bool WTF__StringImpl__isExternal(WTF::StringImpl* arg0); +CPP_DECL "C" bool WTF__StringImpl__isStatic(WTF::StringImpl* arg0); +CPP_DECL "C" bool WTF__StringImpl__isEmpty(WTF::StringImpl* arg0); +CPP_DECL "C" size_t WTF__StringImpl__length(WTF::StringImpl* arg0); +CPP_DECL "C" char* WTF__StringImpl__characters8(WTF::StringImpl* arg0); +CPP_DECL "C" uint16_t* WTF__StringImpl__characters16(WTF::StringImpl* arg0); + +#pragma mark - WTF::StringView + +#ifndef BINDINGS__decls__WTF_text_StringView_h +#define BINDINGS__decls__WTF_text_StringView_h +#include <WTF/text/StringView.h> +namespace WTF { + class StringView; +} +#endif + +CPP_DECL "C" WTF::StringView* WTF__StringView__from8Bit(const char* arg0, size_t arg1); +CPP_DECL "C" bool WTF__StringView__is8Bit(WTF::StringView* arg0); +CPP_DECL "C" bool WTF__StringView__is16Bit(WTF::StringView* arg0); +CPP_DECL "C" bool WTF__StringView__isEmpty(WTF::StringView* arg0); +CPP_DECL "C" size_t WTF__StringView__length(WTF::StringView* arg0); +CPP_DECL "C" char* WTF__StringView__characters8(WTF::StringView* arg0); +CPP_DECL "C" uint16_t* WTF__StringView__characters16(WTF::StringView* arg0); |