js-runtime: Add Object.attributeCount to get the number of user added
attributes to that object
This commit is contained in:
parent
1919595adc
commit
e8f5ca9117
2 changed files with 10 additions and 0 deletions
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue