js-runtime: Add Function.paramCount to get the number of parameters

This commit is contained in:
iddev5 2022-07-08 18:03:55 +05:30 committed by Stephen Gutekanst
parent e8f5ca9117
commit 852278ebe7
2 changed files with 10 additions and 0 deletions

View file

@ -327,6 +327,10 @@ const zig = {
zig.functionCall(values[id], undefined, args, args_len, ret_ptr);
},
zigGetParamCount(id) {
return values[id].length;
},
zigConstructType(id, args, args_len, ret_ptr) {
let memory = new MemoryBlock(zig.wasm.exports.memory.buffer);
let argv = [];

View file

@ -20,6 +20,7 @@ const js = struct {
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;
extern fn zigGetParamCount(id: u64) u32;
extern fn zigConstructType(id: u64, args: ?*const anyopaque, args_len: u32, ret_ptr: *anyopaque) void;
extern fn zigCleanupObject(id: u64) void;
};
@ -142,6 +143,11 @@ pub const Function = struct {
return .{ .tag = .func, .val = .{ .ref = func.ref } };
}
pub fn paramCount(func: *const Function) usize {
// FIXME: native functions would always return 0
return js.zigGetParamCount(func.ref);
}
pub fn construct(func: *const Function, args: []const Value) Value {
var ret: Value = undefined;
js.zigConstructType(func.ref, args.ptr, args.len, &ret);