From 1b7848c4a9f6ba848452c9b3a9e88e95c17ab295 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 24 Aug 2021 14:09:00 +0100 Subject: feat(unstable): Support file URLs in Deno.dlopen() (#11658) --- cli/dts/lib.deno.unstable.d.ts | 2 +- ext/ffi/00_ffi.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index b83309bc9..fb5ed461c 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -142,7 +142,7 @@ declare namespace Deno { * Opens a dynamic library and registers symbols */ export function dlopen>( - filename: string, + filename: string | URL, symbols: S, ): DynamicLibrary; diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index 3c4112a47..553ea1dd3 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -3,6 +3,7 @@ ((window) => { const core = window.Deno.core; + const __bootstrap = window.__bootstrap; class DynamicLibrary { #rid; @@ -23,7 +24,9 @@ } function dlopen(path, symbols) { - return new DynamicLibrary(path, symbols); + // URL support is progressively enhanced by util in `runtime/js`. + const pathFromURL = __bootstrap.util.pathFromURL ?? ((p) => p); + return new DynamicLibrary(pathFromURL(path), symbols); } window.__bootstrap.ffi = { dlopen }; -- cgit v1.2.3