Skip to content

Commit cddd892

Browse files
committed
Fix rquickjs 0.12 loader API compatibility
1 parent dd0aebc commit cddd892

4 files changed

Lines changed: 84 additions & 12 deletions

File tree

src/hyperlight-js-runtime/src/host_fn.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use core::ptr::NonNull;
2222

2323
use anyhow::{bail, ensure, Context as _};
2424
use hashbrown::HashMap;
25-
use rquickjs::loader::{Loader, Resolver};
25+
use rquickjs::loader::{ImportAttributes, Loader, Resolver};
2626
use rquickjs::module::{Declarations, Exports, ModuleDef};
2727
use rquickjs::prelude::Rest;
2828
use rquickjs::{Ctx, Exception, Function, JsLifetime, Module, Value};
@@ -262,7 +262,13 @@ pub struct HostModuleLoader {
262262
}
263263

264264
impl Resolver for HostModuleLoader {
265-
fn resolve(&mut self, _ctx: &Ctx<'_>, base: &str, name: &str) -> rquickjs::Result<String> {
265+
fn resolve(
266+
&mut self,
267+
_ctx: &Ctx<'_>,
268+
base: &str,
269+
name: &str,
270+
_attributes: Option<ImportAttributes<'_>>,
271+
) -> rquickjs::Result<String> {
266272
if !self.borrow().contains_key(name) {
267273
return Err(rquickjs::Error::new_resolving(base, name));
268274
}
@@ -271,7 +277,12 @@ impl Resolver for HostModuleLoader {
271277
}
272278

273279
impl Loader for HostModuleLoader {
274-
fn load<'js>(&mut self, ctx: &Ctx<'js>, name: &str) -> rquickjs::Result<Module<'js>> {
280+
fn load<'js>(
281+
&mut self,
282+
ctx: &Ctx<'js>,
283+
name: &str,
284+
_attributes: Option<ImportAttributes<'js>>,
285+
) -> rquickjs::Result<Module<'js>> {
275286
if !self.borrow().contains_key(name) {
276287
return Err(rquickjs::Error::new_loading(name));
277288
}

src/hyperlight-js-runtime/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use alloc::string::{String, ToString};
2929

3030
use anyhow::{anyhow, Context as _};
3131
use hashbrown::HashMap;
32-
use rquickjs::loader::{Loader, Resolver};
32+
use rquickjs::loader::{ImportAttributes, Loader, Resolver};
3333
use rquickjs::promise::MaybePromise;
3434
use rquickjs::{Context, Ctx, Function, Module, Persistent, Result, Runtime, Value};
3535
use serde::de::DeserializeOwned;
@@ -265,7 +265,13 @@ impl ModuleLoader {
265265
}
266266

267267
impl Resolver for ModuleLoader {
268-
fn resolve(&mut self, _ctx: &Ctx<'_>, base: &str, name: &str) -> Result<String> {
268+
fn resolve(
269+
&mut self,
270+
_ctx: &Ctx<'_>,
271+
base: &str,
272+
name: &str,
273+
_attributes: Option<ImportAttributes<'_>>,
274+
) -> Result<String> {
269275
// quickjs uses the module path as the base for relative imports
270276
// but oxc_resolver expects the directory as the base
271277
let (dir, _) = base.rsplit_once('/').unwrap_or((".", ""));
@@ -282,7 +288,12 @@ impl Resolver for ModuleLoader {
282288
}
283289

284290
impl Loader for ModuleLoader {
285-
fn load<'js>(&mut self, ctx: &Ctx<'js>, name: &str) -> Result<Module<'js>> {
291+
fn load<'js>(
292+
&mut self,
293+
ctx: &Ctx<'js>,
294+
name: &str,
295+
_attributes: Option<ImportAttributes<'js>>,
296+
) -> Result<Module<'js>> {
286297
let source = self
287298
.host
288299
.load_module(name.to_string())

src/hyperlight-js-runtime/src/modules/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
use alloc::string::{String, ToString as _};
1717

1818
use hashbrown::HashMap;
19-
use rquickjs::loader::{Loader, Resolver};
19+
use rquickjs::loader::{ImportAttributes, Loader, Resolver};
2020
use rquickjs::module::ModuleDef;
2121
use rquickjs::{Ctx, Module, Result};
2222
use spin::LazyLock;
@@ -57,7 +57,13 @@ static NATIVE_MODULES: LazyLock<HashMap<&str, ModuleDeclarationFn>> = LazyLock::
5757
});
5858

5959
impl Resolver for NativeModuleLoader {
60-
fn resolve(&mut self, _ctx: &Ctx<'_>, base: &str, name: &str) -> Result<String> {
60+
fn resolve(
61+
&mut self,
62+
_ctx: &Ctx<'_>,
63+
base: &str,
64+
name: &str,
65+
_attributes: Option<ImportAttributes<'_>>,
66+
) -> Result<String> {
6167
if NATIVE_MODULES.contains_key(name) {
6268
Ok(name.to_string())
6369
} else {
@@ -67,7 +73,12 @@ impl Resolver for NativeModuleLoader {
6773
}
6874

6975
impl Loader for NativeModuleLoader {
70-
fn load<'js>(&mut self, ctx: &Ctx<'js>, name: &str) -> Result<Module<'js>> {
76+
fn load<'js>(
77+
&mut self,
78+
ctx: &Ctx<'js>,
79+
name: &str,
80+
_attributes: Option<ImportAttributes<'js>>,
81+
) -> Result<Module<'js>> {
7182
if let Some(declaration) = NATIVE_MODULES.get(name) {
7283
declaration(ctx.clone(), name)
7384
} else {

src/js-host-api/package-lock.json

Lines changed: 42 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)