lightpanda-io / zig-js-runtime

Add a JS runtime in your Zig project
https://lightpanda.io
Apache License 2.0
16 stars 0 forks source link

Variadic: impossible to define user defined variadic argument #165

Closed krichprollsch closed 8 months ago

krichprollsch commented 9 months ago

given this change:

diff --git a/src/tests/types_complex_test.zig b/src/tests/types_complex_test.zig
index cd62db2..9769828 100644
--- a/src/tests/types_complex_test.zig
+++ b/src/tests/types_complex_test.zig
@@ -50,6 +50,10 @@ const MyVariadic = struct {
         return variadic.?.slice[variadic.?.slice.len - 1];
     }

+    pub fn _userDefined(_: MyVariadic, _: ?Variadic(MyList)) bool {
+        return true;
+    }
+
     pub fn _empty(_: MyVariadic, _: ?VariadicBool) bool {
         return true;
     }
@@ -193,6 +197,7 @@ pub fn exec(
         .{ .src = "myVariadic.first('a_str', true, false, true, false)", .ex = "true" },
         .{ .src = "myVariadic.last(true, false)", .ex = "false" },
         .{ .src = "myVariadic.empty()", .ex = "true" },
+        .{ .src = "myVariadic.userDefined(new MyList(1, 2, 3))", .ex = "true" },
     };
     try tests.checkCases(js_env, &variadic);

The tests are crashing:

panic: attempt to unwrap error: JSTypeUnhandled            
/home/pierre/wrk/jsruntime-lib/src/engines/v8/types_primitives.zig:156:17: 0xac52a1 in jsToNative__anon_23181 (test)
        else => return error.JSTypeUnhandled,
                ^                                                   
/home/pierre/wrk/jsruntime-lib/src/engines/v8/generate.zig:202:21: 0xaa1816 in getArg__anon_21672 (test)
            ) catch unreachable,
                    ^
/home/pierre/wrk/jsruntime-lib/src/engines/v8/generate.zig:342:43: 0xa77dd4 in getArgs__anon_20944 (test)
                const slice_value = getArg(
                                          ^
/home/pierre/wrk/jsruntime-lib/src/engines/v8/generate.zig:657:23: 0xa2eb91 in callFunc__anon_19997 (test)
    var args = getArgs(                                                                                                                      
                      ^                                            
/home/pierre/wrk/jsruntime-lib/src/engines/v8/generate.zig:843:21: 0xa0930d in method (test)
            callFunc(                                                                                                                        
                    ^
../../../../v8/src/api/api-arguments-inl.h:146:3: 0x251e039 in Call (../../../../v8/src/builtins/builtins-api.cc)
../../../../v8/src/builtins/builtins-api.cc:113:36: 0x251c9ef in HandleApiCallHelper<false> (../../../../v8/src/builtins/builtins-api.cc)
../../../../v8/src/builtins/builtins-api.cc:148:5: 0x251b150 in Builtin_Impl_HandleApiCall (../../../../v8/src/builtins/builtins-api.cc)
../../../../v8/src/builtins/builtins-api.cc:135:1: 0x251ac16 in Builtin_HandleApiCall (../../../../v8/src/builtins/builtins-api.cc)
???:?:?: 0xfee4be in ??? (???)
Unwind error at address `:0xfee4be` (error.AddressOutOfRange), trace may be incomplete

???:?:?: 0xc57e8d in ??? (???)
???:?:?: 0xc5069b in ??? (???)
???:?:?: 0xc503c6 in ??? (???)
../../../../v8/src/execution/simulator.h:155:12: 0x1a5ecfa in Invoke (../../../../v8/src/execution/execution.cc)
../../../../v8/src/execution/execution.cc:538:10: 0x1a5fd7c in CallScript (../../../../v8/src/execution/execution.cc)
../../../../v8/src/api/api.cc:2272:7: 0xb9d58d in Run (../../../../v8/src/api/api.cc)
/home/pierre/prs/brwsrcr/jsruntime-lib/vendor/zig-v8/src/binding.cpp:414:54: 0xad9dc3 in v8__Script__Run (/home/pierre/prs/brwsrcr/jsruntime-lib/vendor/zig-v8/src/binding.cpp)
/home/pierre/wrk/jsruntime-lib/vendor/zig-v8/src/v8.zig:1679:30: 0x998d6b in run (test)
        if (c.v8__Script__Run(self.handle, ctx.handle)) |value| {
                             ^
/home/pierre/wrk/jsruntime-lib/src/engines/v8/v8.zig:464:28: 0x999aa5 in exec (test)
        const res = scr.run(context) catch {
                           ^
/home/pierre/wrk/jsruntime-lib/src/engines/v8/v8.zig:329:21: 0x97c3c7 in run (test)
        try res.exec(alloc, script, name, self.isolate, self.context.?, try_catch);
                    ^
/home/pierre/wrk/jsruntime-lib/src/tests/test_utils.zig:85:23: 0x97bd57 in checkCases (test)
        try js_env.run(fba_alloc, case.src, name, &res, &cbk_res);
                      ^
/home/pierre/wrk/jsruntime-lib/src/tests/types_complex_test.zig:202:25: 0x981d29 in exec__anon_12495 (test)
    try tests.checkCases(js_env, &variadic);
                        ^
/home/pierre/wrk/jsruntime-lib/src/engine.zig:47:18: 0x9826f9 in loadEnv__anon_12493 (test)
    try ctxExecFn(alloc, &js_env, apis);
                 ^
/home/pierre/wrk/jsruntime-lib/src/run_tests.zig:87:28: 0x98aea0 in test_0 (test)
        _ = try eng.loadEnv(&complex_arena, complex_types.exec, complex_apis);
                           ^
/usr/local/zig-0.12.0-dev.1773+8a8fd47d2/lib/test_runner.zig:101:29: 0x9ac994 in mainServer (test)
                test_fn.func() catch |err| switch (err) {
                            ^
/usr/local/zig-0.12.0-dev.1773+8a8fd47d2/lib/test_runner.zig:34:26: 0x98e71e in main (test)
        return mainServer() catch @panic("internal test runner failure");
                         ^
/usr/local/zig-0.12.0-dev.1773+8a8fd47d2/lib/std/start.zig:575:22: 0x98e224 in main (test)
            root.main();
                     ^
run test: error: while executing test 'test_0', the following command terminated with signal 6 (expected exited with code 0):
/home/pierre/wrk/jsruntime-lib/zig-cache/o/d0128d436b76ae0b5508dcbd198ad290/test --listen=- 
Build Summary: 2/4 steps succeeded; 1 failed; 3/3 tests passed (disable with --summary none)
test transitive failure
└─ run test failure
error: the following build command failed with exit code 1:
/home/pierre/wrk/jsruntime-lib/zig-cache/o/8602ed2d9edb40a537144721326b371e/build /usr/local/zig-0.12.0-dev.1773+8a8fd47d2/zig /home/pierre/wrk/jsruntime-lib /home/pierre/wrk/jsruntime-lib/zig-cache /home/pierre/.cache/zig --seed 0xfed29ea test -Dengine=v8
Test ERROR
make: *** [Makefile:155: test] Error 1