diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2022-02-18 14:21:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-18 17:51:19 +0530 |
commit | b1a6555c0502196174bed1454e446717daf52f12 (patch) | |
tree | 3e0c74d87a63044090564638dee0af22f4e2ca10 /test_ffi/tests | |
parent | 4a144c7d6e55a5e047080cb1e2377b70657f1809 (diff) |
feat(ext/ffi): Support read only global statics (#13662)
Diffstat (limited to 'test_ffi/tests')
-rw-r--r-- | test_ffi/tests/ffi_types.ts | 57 | ||||
-rw-r--r-- | test_ffi/tests/integration_tests.rs | 3 | ||||
-rw-r--r-- | test_ffi/tests/test.js | 14 |
3 files changed, 74 insertions, 0 deletions
diff --git a/test_ffi/tests/ffi_types.ts b/test_ffi/tests/ffi_types.ts index b1e10868a..0aab6a8fa 100644 --- a/test_ffi/tests/ffi_types.ts +++ b/test_ffi/tests/ffi_types.ts @@ -24,6 +24,20 @@ const remote = Deno.dlopen( method17: { parameters: [], result: "usize", nonblocking: true }, method18: { parameters: [], result: "pointer" }, method19: { parameters: [], result: "pointer", nonblocking: true }, + static1: { type: "usize" }, + static2: { type: "pointer" }, + static3: { type: "usize" }, + static4: { type: "isize" }, + static5: { type: "u8" }, + static6: { type: "u16" }, + static7: { type: "u32" }, + static8: { type: "u64" }, + static9: { type: "i8" }, + static10: { type: "i16" }, + static11: { type: "i32" }, + static12: { type: "i64" }, + static13: { type: "f32" }, + static14: { type: "f64" }, } as const, ); @@ -121,3 +135,46 @@ const fnptr = new Deno.UnsafeFnPointer( // @ts-expect-error: Invalid argument fnptr.call(null, null); fnptr.call(0, null); + +// @ts-expect-error: Invalid member type +const static1_wrong: null = remote.symbols.static1; +const static1_right: number = remote.symbols.static1; +// @ts-expect-error: Invalid member type +const static2_wrong: null = remote.symbols.static2; +const static2_right: Deno.UnsafePointer = remote.symbols.static2; +// @ts-expect-error: Invalid member type +const static3_wrong: null = remote.symbols.static3; +const static3_right: number = remote.symbols.static3; +// @ts-expect-error: Invalid member type +const static4_wrong: null = remote.symbols.static4; +const static4_right: number = remote.symbols.static4; +// @ts-expect-error: Invalid member type +const static5_wrong: null = remote.symbols.static5; +const static5_right: number = remote.symbols.static5; +// @ts-expect-error: Invalid member type +const static6_wrong: null = remote.symbols.static6; +const static6_right: number = remote.symbols.static6; +// @ts-expect-error: Invalid member type +const static7_wrong: null = remote.symbols.static7; +const static7_right: number = remote.symbols.static7; +// @ts-expect-error: Invalid member type +const static8_wrong: null = remote.symbols.static8; +const static8_right: number = remote.symbols.static8; +// @ts-expect-error: Invalid member type +const static9_wrong: null = remote.symbols.static9; +const static9_right: number = remote.symbols.static9; +// @ts-expect-error: Invalid member type +const static10_wrong: null = remote.symbols.static10; +const static10_right: number = remote.symbols.static10; +// @ts-expect-error: Invalid member type +const static11_wrong: null = remote.symbols.static11; +const static11_right: number = remote.symbols.static11; +// @ts-expect-error: Invalid member type +const static12_wrong: null = remote.symbols.static12; +const static12_right: number = remote.symbols.static12; +// @ts-expect-error: Invalid member type +const static13_wrong: null = remote.symbols.static13; +const static13_right: number = remote.symbols.static13; +// @ts-expect-error: Invalid member type +const static14_wrong: null = remote.symbols.static14; +const static14_right: number = remote.symbols.static14; diff --git a/test_ffi/tests/integration_tests.rs b/test_ffi/tests/integration_tests.rs index c818f12d9..fea5b5fbd 100644 --- a/test_ffi/tests/integration_tests.rs +++ b/test_ffi/tests/integration_tests.rs @@ -69,6 +69,9 @@ fn basic() { true\n\ Before\n\ true\n\ + Static u32: 42\n\ + Static ptr: true\n\ + Static ptr value: 42\n\ After\n\ true\n\ Correct number of resources\n"; diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index a9681ab9f..943f86ae8 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -73,6 +73,12 @@ const dylib = Deno.dlopen(libPath, { parameters: [], result: "pointer", }, + "static_u32": { + type: "u32", + }, + "static_ptr": { + type: "pointer", + }, }); dylib.symbols.printSomething(); @@ -201,6 +207,14 @@ dylib.symbols.sleep_nonblocking(100).then(() => { console.log("Before"); console.log(performance.now() - start < 100); +console.log("Static u32:", dylib.symbols.static_u32); +console.log( + "Static ptr:", + dylib.symbols.static_ptr instanceof Deno.UnsafePointer, +); +const view = new Deno.UnsafePointerView(dylib.symbols.static_ptr); +console.log("Static ptr value:", view.getUint32()); + function cleanup() { dylib.close(); |