Skip to content

Commit 0b79db1

Browse files
simongdaviesCopilot
andcommitted
style: fix formatting and add ImportAttributes to test calls
- Fix import ordering in guest/mod.rs (cargo fmt) - Fix line length in clock.rs (cargo fmt) - Add missing ImportAttributes (None) arg to resolve/load calls in tests to match the updated rquickjs trait signatures from the rebase Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 95d7ead commit 0b79db1

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ use anyhow::{anyhow, Context as _};
3434
use hashbrown::HashMap;
3535
use hyperlight_guest_bin::error::{ErrorCode, HyperlightGuestError, Result};
3636
use hyperlight_guest_bin::{guest_function, host_function, main};
37-
use crate::JsRuntime;
3837
use spin::Mutex;
3938
use tracing::instrument;
4039

40+
use crate::JsRuntime;
41+
4142
mod stubs;
4243

4344
struct Host;
@@ -74,8 +75,8 @@ impl crate::host::Host for Host {
7475
}
7576
}
7677

77-
static RUNTIME: spin::LazyLock<Mutex<crate::JsRuntime>> = spin::LazyLock::new(|| {
78-
Mutex::new(crate::JsRuntime::new(Host).unwrap_or_else(|e| {
78+
static RUNTIME: spin::LazyLock<Mutex<JsRuntime>> = spin::LazyLock::new(|| {
79+
Mutex::new(JsRuntime::new(Host).unwrap_or_else(|e| {
7980
panic!("Failed to initialize JS runtime: {e:#?}");
8081
}))
8182
});

src/hyperlight-js-runtime/src/guest/stubs/clock.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616
use hyperlight_guest_bin::error::Result;
17-
use hyperlight_guest_bin::host_function;
18-
use hyperlight_guest_bin::libc;
17+
use hyperlight_guest_bin::{host_function, libc};
1918

2019
fn micros_since_epoch() -> u64 {
2120
#[host_function("CurrentTimeMicros")]
@@ -33,7 +32,10 @@ fn micros_since_epoch() -> u64 {
3332
// hyperlight runtime's libc is a stub that returns an epuch and increments time by 1s
3433
// on every call.
3534
#[unsafe(no_mangle)]
36-
extern "C" fn __wrap_clock_gettime(clk_id: libc::clockid_t, ts: *mut libc::timespec) -> libc::c_int {
35+
extern "C" fn __wrap_clock_gettime(
36+
clk_id: libc::clockid_t,
37+
ts: *mut libc::timespec,
38+
) -> libc::c_int {
3739
const CLOCK_REALTIME: libc::clockid_t = libc::CLOCK_REALTIME as libc::clockid_t;
3840
const CLOCK_MONOTONIC: libc::clockid_t = libc::CLOCK_MONOTONIC as libc::clockid_t;
3941

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use hashbrown::HashMap;
1919
use rquickjs::loader::{ImportAttributes, Loader, Resolver};
2020
use rquickjs::module::ModuleDef;
2121
use rquickjs::{Ctx, Module, Result};
22-
use spin::LazyLock;
23-
use spin::Mutex;
22+
use spin::{LazyLock, Mutex};
2423

2524
#[doc(hidden)]
2625
pub mod console;

src/hyperlight-js-runtime/tests/native_modules.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn loader_resolves_all_builtin_modules() {
6161

6262
with_qjs_context(|ctx| {
6363
for name in &builtins {
64-
let result = loader.resolve(&ctx, ".", name);
64+
let result = loader.resolve(&ctx, ".", name, None);
6565
assert!(result.is_ok(), "Should resolve built-in module '{name}'");
6666
assert_eq!(result.unwrap(), *name);
6767
}
@@ -73,7 +73,7 @@ fn loader_rejects_unknown_modules() {
7373
let mut loader = hyperlight_js_runtime::modules::NativeModuleLoader;
7474

7575
with_qjs_context(|ctx| {
76-
let result = loader.resolve(&ctx, ".", "nonexistent");
76+
let result = loader.resolve(&ctx, ".", "nonexistent", None);
7777
assert!(result.is_err(), "Should reject unknown modules");
7878
});
7979
}
@@ -85,7 +85,7 @@ fn loader_loads_all_builtin_modules() {
8585

8686
with_qjs_context(|ctx| {
8787
for name in &builtins {
88-
let result = loader.load(&ctx, name);
88+
let result = loader.load(&ctx, name, None);
8989
assert!(
9090
result.is_ok(),
9191
"Should load built-in module '{name}', got: {:?}",
@@ -116,13 +116,13 @@ fn registered_custom_module_resolves_and_loads() {
116116
let mut loader = hyperlight_js_runtime::modules::NativeModuleLoader;
117117

118118
with_qjs_context(|ctx| {
119-
let result = loader.resolve(&ctx, ".", "greeting");
119+
let result = loader.resolve(&ctx, ".", "greeting", None);
120120
assert!(
121121
result.is_ok(),
122122
"Should resolve registered 'greeting' module"
123123
);
124124

125-
let result = loader.load(&ctx, "greeting");
125+
let result = loader.load(&ctx, "greeting", None);
126126
assert!(
127127
result.is_ok(),
128128
"Should load registered 'greeting' module, got: {:?}",
@@ -144,7 +144,7 @@ fn builtins_still_work_after_custom_registration() {
144144

145145
with_qjs_context(|ctx| {
146146
for name in &builtins {
147-
let result = loader.resolve(&ctx, ".", name);
147+
let result = loader.resolve(&ctx, ".", name, None);
148148
assert!(
149149
result.is_ok(),
150150
"Built-in '{name}' should still resolve after custom registration"
@@ -221,7 +221,7 @@ fn macro_generated_init_registers_modules() {
221221
let mut loader = hyperlight_js_runtime::modules::NativeModuleLoader;
222222

223223
with_qjs_context(|ctx| {
224-
let result = loader.resolve(&ctx, ".", "test_math_macro");
224+
let result = loader.resolve(&ctx, ".", "test_math_macro", None);
225225
assert!(
226226
result.is_ok(),
227227
"Module registered via native_modules! macro should resolve"

0 commit comments

Comments
 (0)