diff options
| author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-01-21 07:51:14 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-21 21:21:14 +0530 |
| commit | 59289255411b902588619fd7d2f6e3e48af11d82 (patch) | |
| tree | a328e565abb1695e57c99538d6482f62e5008cad /test_ffi | |
| parent | 638b6ef554676422c43cc5c0ae2285ba369740bf (diff) | |
fix(ext/ffi): disallow empty ffi structs (#17487)
This patch makes `NativeType` to `libffi::middle::Type` conversion
failliable and w.t disallows struct with empty fields. libffi does not
handle "empty" struct because they don't exist in C (or Rust).
Fixes #17481
Diffstat (limited to 'test_ffi')
| -rw-r--r-- | test_ffi/tests/test.js | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index 0ada7dc0a..e45c5895b 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -37,6 +37,40 @@ assertThrows( "Failed to register symbol non_existent_symbol", ); +assertThrows(() => { + Deno.dlopen(libPath, { + print_something: { + parameters: [], + result: { struct: [] } + }, + }), + TypeError, + "Struct must have at least one field" +}); + +assertThrows(() => { + Deno.dlopen(libPath, { + print_something: { + parameters: [ { struct: [] } ], + result: "void", + }, + }), + TypeError, + "Struct must have at least one field" +}); + +const Empty = { struct: [] } +assertThrows(() => { + Deno.dlopen(libPath, { + print_something: { + parameters: [ { struct: [Empty] } ], + result: "void", + }, + }), + TypeError, + "Struct must have at least one field" +}); + const Point = ["f64", "f64"]; const Size = ["f64", "f64"]; const Rect = ["f64", "f64", "f64", "f64"]; @@ -720,4 +754,4 @@ function testOptimized(fn, callback) { console.log(r2); } assertIsOptimized(fn); -}
\ No newline at end of file +} |
