js: Implement Value.instanceOf method which performs Js' `instanceof`

check
This commit is contained in:
iddev5 2022-07-07 23:55:32 +05:30 committed by Stephen Gutekanst
parent c587350c71
commit 3b00b478ce
2 changed files with 12 additions and 0 deletions

View file

@ -276,6 +276,13 @@ const zig = {
return val_js === other_js;
},
zigValueInstanceOf(val, other) {
let memory = new MemoryBlock(zig.wasm.exports.memory.buffer);
const val_js = zig.readObject(memory.slice(val), memory);
const other_js = zig.readObject(memory.slice(other), memory);
return val_js instanceof other_js;
},
functionCall(func, this_param, args, args_len, ret_ptr) {
let memory = new MemoryBlock(zig.wasm.exports.memory.buffer);
let argv = [];

View file

@ -15,6 +15,7 @@ const js = struct {
extern fn zigGetString(val_id: u64, ptr: [*]const u8) void;
extern fn zigGetStringLength(val_id: u64) u32;
extern fn zigValueEqual(val: *const anyopaque, other: *const anyopaque) bool;
extern fn zigValueInstanceOf(val: *const anyopaque, other: *const anyopaque) bool;
extern fn zigDeleteIndex(id: u64, index: u32) void;
extern fn zigFunctionCall(id: u64, name: [*]const u8, len: u32, args: ?*const anyopaque, args_len: u32, ret_ptr: *anyopaque) void;
extern fn zigFunctionInvoke(id: u64, args: ?*const anyopaque, args_len: u32, ret_ptr: *anyopaque) void;
@ -92,6 +93,10 @@ pub const Value = extern struct {
else => js.zigValueEqual(val, &other),
};
}
pub fn instanceOf(val: *const Value, other: Value) bool {
return js.zigValueInstanceOf(val, &other);
}
};
pub const Object = struct {