Skip to content

Commit 501d0f5

Browse files
simongdaviesCopilot
andcommitted
fix: address PR review comments
- Fix napi_create_string_utf8 length parameter cast (isize usize) - Fix formatted error string using concat!() to avoid embedded whitespace Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent f733126 commit 501d0f5

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub(crate) mod utils;
2626
use alloc::format;
2727
use alloc::rc::Rc;
2828
use alloc::string::{String, ToString};
29-
use core::cell::RefCell;
3029
use alloc::vec::Vec;
30+
use core::cell::RefCell;
3131

3232
use anyhow::{anyhow, Context as _};
3333
use hashbrown::HashMap;

src/hyperlight-js/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ mod script;
2727
pub mod sandbox;
2828

2929
use hyperlight_host::func::HostFunction;
30+
// Re-export FnReturn for the NAPI bridge (used in register_js signature).
31+
#[doc(hidden)]
32+
pub use sandbox::host_fn::FnReturn;
3033
/// Validate a module identifier (name or namespace).
3134
pub use sandbox::js_sandbox::validate_module_identifier;
3235
/// Validate that a namespace is not reserved.
3336
pub use sandbox::js_sandbox::validate_namespace_not_reserved;
34-
// Re-export FnReturn for the NAPI bridge (used in register_js signature).
35-
#[doc(hidden)]
36-
pub use sandbox::host_fn::FnReturn;
3737
/// A Hyperlight Sandbox with a JavaScript run time loaded but no guest code.
3838
pub use sandbox::js_sandbox::JSSandbox;
3939
/// Default namespace for user modules added via [`JSSandbox::add_module`].

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,11 @@ impl HostModule {
202202
// data is not supported — reject if blobs are present.
203203
if !blobs.is_empty() {
204204
return Err(crate::HyperlightError::Error(format!(
205-
"Function '{}' received {} binary argument(s) but was registered \
206-
with `register` (typed JSON-only). Use `register_js` for functions \
207-
that accept Uint8Array/Buffer arguments.",
205+
concat!(
206+
"Function '{}' received {} binary argument(s) but was registered ",
207+
"with `register` (typed JSON-only). Use `register_js` for functions ",
208+
"that accept Uint8Array/Buffer arguments.",
209+
),
208210
name,
209211
blobs.len()
210212
)));

src/hyperlight-js/tests/user_modules.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fn user_module_can_import_builtin_module() {
507507
fn user_module_can_import_host_function() {
508508
let enricher_module = Script::from_content(
509509
r#"
510-
import * as db from 'host:db';
510+
import * as db from 'db';
511511
export function enrich(event) {
512512
const user = db.lookup(event.userId);
513513
event.userName = user.name;
@@ -526,15 +526,13 @@ fn user_module_can_import_host_function() {
526526
);
527527

528528
let mut proto = SandboxBuilder::new().build().unwrap();
529-
proto.host_module("host:db").register_raw(
530-
"lookup",
531-
|args: String| -> hyperlight_js::Result<String> {
532-
let parsed: serde_json::Value = serde_json::from_str(&args).unwrap();
533-
let id = parsed[0].as_i64().unwrap();
534-
let result = serde_json::json!({ "id": id, "name": format!("User {}", id) });
535-
Ok(serde_json::to_string(&result).unwrap())
536-
},
537-
);
529+
proto
530+
.register(
531+
"db",
532+
"lookup",
533+
|id: i32| serde_json::json!({ "id": id, "name": format!("User {}", id) }),
534+
)
535+
.unwrap();
538536

539537
let mut sandbox = proto.load_runtime().unwrap();
540538

0 commit comments

Comments
 (0)