diff --git a/js-runtime/src/js-runtime.js b/js-runtime/src/js-runtime.js index 4572a137..5524b78f 100644 --- a/js-runtime/src/js-runtime.js +++ b/js-runtime/src/js-runtime.js @@ -252,6 +252,11 @@ const zig = { delete values[id][index]; }, + zigGetAttributeCount(id) { + let obj = values[id]; + return Object.keys(obj).length; + }, + zigCleanupObject(id) { const idx = Number(id); delete value_map[values[idx].__uindex]; diff --git a/js-runtime/src/main.zig b/js-runtime/src/main.zig index 07b35922..d4efa6b7 100644 --- a/js-runtime/src/main.zig +++ b/js-runtime/src/main.zig @@ -7,6 +7,7 @@ const js = struct { extern fn zigCreateArray() u32; extern fn zigCreateString(str: [*]const u8, len: u32) u32; extern fn zigCreateFunction(id: *const anyopaque) u32; + extern fn zigGetAttributeCount(id: u64) u32; extern fn zigGetProperty(id: u64, name: [*]const u8, len: u32, ret_ptr: *anyopaque) void; extern fn zigSetProperty(id: u64, name: [*]const u8, len: u32, set_ptr: *const anyopaque) void; extern fn zigDeleteProperty(id: u64, name: [*]const u8, len: u32) void; @@ -91,6 +92,10 @@ pub const Object = struct { return .{ .tag = .object, .val = .{ .ref = obj.ref } }; } + pub fn attributeCount(obj: *const Object) usize { + return js.zigGetAttributeCount(obj.ref); + } + pub fn get(obj: *const Object, prop: []const u8) Value { var ret: Value = undefined; js.zigGetProperty(obj.ref, prop.ptr, @intCast(u32, prop.len), &ret);