summaryrefslogtreecommitdiff
path: root/ext/ffi/00_ffi.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r--ext/ffi/00_ffi.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js
new file mode 100644
index 000000000..3c4112a47
--- /dev/null
+++ b/ext/ffi/00_ffi.js
@@ -0,0 +1,30 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+"use strict";
+
+((window) => {
+ const core = window.Deno.core;
+
+ class DynamicLibrary {
+ #rid;
+ symbols = {};
+
+ constructor(path, symbols) {
+ this.#rid = core.opSync("op_ffi_load", { path, symbols });
+
+ for (const symbol in symbols) {
+ this.symbols[symbol] = (...parameters) =>
+ core.opSync("op_ffi_call", { rid: this.#rid, symbol, parameters });
+ }
+ }
+
+ close() {
+ core.close(this.#rid);
+ }
+ }
+
+ function dlopen(path, symbols) {
+ return new DynamicLibrary(path, symbols);
+ }
+
+ window.__bootstrap.ffi = { dlopen };
+})(this);