diff options
author | Elias Sjögreen <eliassjogreen1@gmail.com> | 2021-08-06 23:28:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-06 23:28:10 +0200 |
commit | 33c8d790c3d358a475c9ba828043e2c19e8d4b37 (patch) | |
tree | 4ab33b3e5b352d49667d55631c76ee76af2ec5e2 /extensions/ffi/00_ffi.js | |
parent | 0d1a522a03c22749e96dab06ca7b3e8b428df701 (diff) |
feat: ffi to replace plugins (#11152)
This commit removes implementation of "native plugins" and replaces
it with FFI API.
Effectively "Deno.openPlugin" API was replaced with "Deno.dlopen" API.
Diffstat (limited to 'extensions/ffi/00_ffi.js')
-rw-r--r-- | extensions/ffi/00_ffi.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/extensions/ffi/00_ffi.js b/extensions/ffi/00_ffi.js new file mode 100644 index 000000000..3c4112a47 --- /dev/null +++ b/extensions/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); |