fetc h!!!

This commit is contained in:
Jarred Sumner
2021-09-09 05:40:07 -07:00
parent c30ec608b1
commit 8a02ad48a5
34 changed files with 6782 additions and 161 deletions

View File

@@ -726,11 +726,15 @@ pub fn NewClass(
var static_functions = brk: {
var funcs: [function_name_refs.len + 1]js.JSStaticFunction = undefined;
std.mem.set(js.JSStaticFunction, &funcs, js.JSStaticFunction{
.name = @intToPtr([*c]const u8, 0),
.callAsFunction = null,
.attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone,
},);
std.mem.set(
js.JSStaticFunction,
&funcs,
js.JSStaticFunction{
.name = @intToPtr([*c]const u8, 0),
.callAsFunction = null,
.attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone,
},
);
break :brk funcs;
};
var instance_functions = std.mem.zeroes([function_names.len]js.JSObjectRef);
@@ -738,36 +742,40 @@ pub fn NewClass(
var property_name_refs = std.mem.zeroes([property_names.len]js.JSStringRef);
const property_name_literals = property_names;
var static_properties = brk: {
var props: [property_names.len]js.JSStaticValue = undefined;
std.mem.set(js.JSStaticValue, &props, js.JSStaticValue{
.name = @intToPtr([*c]const u8, 0),
.getProperty = null,
.setProperty = null,
.attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone,
},);
var props: [property_names.len]js.JSStaticValue = undefined;
std.mem.set(
js.JSStaticValue,
&props,
js.JSStaticValue{
.name = @intToPtr([*c]const u8, 0),
.getProperty = null,
.setProperty = null,
.attributes = js.JSPropertyAttributes.kJSPropertyAttributeNone,
},
);
break :brk props;
};
pub var ref: js.JSClassRef = null;
pub var loaded = false;
pub var definition: js.JSClassDefinition =.{
.version = 0,
.attributes = js.JSClassAttributes.kJSClassAttributeNone,
.className = name[0..:0].ptr,
.parentClass = null,
.staticValues = null,
.staticFunctions = null,
.initialize = null,
.finalize = null,
.hasProperty = null,
.getProperty = null,
.setProperty = null,
.deleteProperty = null,
.getPropertyNames = null,
.callAsFunction = null,
.callAsConstructor = null,
.hasInstance = null,
.convertToType = null,
pub var definition: js.JSClassDefinition = .{
.version = 0,
.attributes = js.JSClassAttributes.kJSClassAttributeNone,
.className = name[0.. :0].ptr,
.parentClass = null,
.staticValues = null,
.staticFunctions = null,
.initialize = null,
.finalize = null,
.hasProperty = null,
.getProperty = null,
.setProperty = null,
.deleteProperty = null,
.getPropertyNames = null,
.callAsFunction = null,
.callAsConstructor = null,
.hasInstance = null,
.convertToType = null,
};
const ConstructorWrapper = struct {
pub fn rfn(
@@ -1326,7 +1334,7 @@ pub fn NewClass(
.callAsConstructor = null,
.hasInstance = null,
.convertToType = null,
};
};
if (static_functions.len > 0) {
std.mem.set(js.JSStaticFunction, &static_functions, std.mem.zeroes(js.JSStaticFunction));
@@ -1338,6 +1346,8 @@ pub fn NewClass(
def.callAsConstructor = To.JS.Constructor(staticFunctions.constructor.rfn).rfn;
} else if (comptime strings.eqlComptime(function_names[i], "finalize")) {
def.finalize = To.JS.Finalize(ZigType, staticFunctions.finalize.rfn).rfn;
} else if (comptime strings.eqlComptime(function_names[i], "call")) {
def.callAsFunction = To.JS.Callback(ZigType, staticFunctions.call.rfn).rfn;
} else if (comptime strings.eqlComptime(function_names[i], "callAsFunction")) {
const ctxfn = @field(staticFunctions, function_names[i]).rfn;
const Func: std.builtin.TypeInfo.Fn = @typeInfo(@TypeOf(ctxfn)).Fn;
@@ -1379,6 +1389,8 @@ pub fn NewClass(
def.callAsConstructor = To.JS.Constructor(staticFunctions.constructor).rfn;
} else if (comptime strings.eqlComptime(function_names[i], "finalize")) {
def.finalize = To.JS.Finalize(ZigType, staticFunctions.finalize).rfn;
} else if (comptime strings.eqlComptime(function_names[i], "call")) {
def.callAsFunction = To.JS.Callback(ZigType, staticFunctions.call).rfn;
} else {
var callback = To.JS.Callback(
ZigType,