summaryrefslogtreecommitdiff
path: root/test_ffi/tests/test.js
diff options
context:
space:
mode:
authorDjDeveloper <43033058+DjDeveloperr@users.noreply.github.com>2022-01-05 12:55:31 +0530
committerGitHub <noreply@github.com>2022-01-05 12:55:31 +0530
commit9778545048a9908f62c24b93ae3ec0762e3db2d9 (patch)
tree3d329ea75566cf5e56d863d7ea9806711d61fe65 /test_ffi/tests/test.js
parentc4a0a43ce832c85de6bb97a4afc9ecf915e63e5a (diff)
fix(ext/ffi): throw errors instead of panic (#13283)
Diffstat (limited to 'test_ffi/tests/test.js')
-rw-r--r--test_ffi/tests/test.js35
1 files changed, 31 insertions, 4 deletions
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js
index 16e4d76b6..db7603521 100644
--- a/test_ffi/tests/test.js
+++ b/test_ffi/tests/test.js
@@ -1,6 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file
+import { assertThrows } from "../../test_util/std/testing/asserts.ts";
+
const targetDir = Deno.execPath().replace(/[^\/\\]+$/, "");
const [libPrefix, libSuffix] = {
darwin: ["lib", "dylib"],
@@ -12,11 +14,22 @@ const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;
const resourcesPre = Deno.resources();
// dlopen shouldn't panic
-try {
+assertThrows(() => {
Deno.dlopen("cli/src/main.rs", {});
-} catch (_) {
- console.log("dlopen doesn't panic");
-}
+});
+
+assertThrows(
+ () => {
+ Deno.dlopen(libPath, {
+ non_existent_symbol: {
+ parameters: [],
+ result: "void",
+ },
+ });
+ },
+ Error,
+ "Failed to register symbol non_existent_symbol",
+);
const dylib = Deno.dlopen(libPath, {
"print_something": { parameters: [], result: "void" },
@@ -75,6 +88,20 @@ console.log(Boolean(dylib.symbols.is_null_ptr(ptr)));
console.log(Boolean(dylib.symbols.is_null_ptr(null)));
console.log(Boolean(dylib.symbols.is_null_ptr(Deno.UnsafePointer.of(into))));
console.log(dylib.symbols.add_u32(123, 456));
+assertThrows(
+ () => {
+ dylib.symbols.add_u32(-1, 100);
+ },
+ TypeError,
+ "Expected FFI argument to be an unsigned integer, but got Number(-1)",
+);
+assertThrows(
+ () => {
+ dylib.symbols.add_u32(null, 100);
+ },
+ TypeError,
+ "Expected FFI argument to be an unsigned integer, but got Null",
+);
console.log(dylib.symbols.add_i32(123, 456));
console.log(dylib.symbols.add_u64(123, 456));
console.log(dylib.symbols.add_i64(123, 456));