Skip to content

Commit

Permalink
fix(bridge): custom inspect not working
Browse files Browse the repository at this point in the history
Signed-off-by: Markus <28785953+MarkusJx@users.noreply.github.com>
  • Loading branch information
MarkusJx committed Mar 3, 2024
1 parent a505077 commit 49d43ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
24 changes: 8 additions & 16 deletions crates/java-bridge/src/node/java_class_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl JavaClassInstance {
this.set_named_property(OBJECT_PROPERTY, instance_obj)?;

if proxy.config.custom_inspect {
Self::add_custom_inspect(env, this);
Self::add_custom_inspect(env, this)?;
}

for method in &proxy.methods {
Expand Down Expand Up @@ -409,19 +409,13 @@ impl JavaClassInstance {
)
}

fn add_custom_inspect(env: &Env, this: &mut JsObject) -> Option<()> {
fn add_custom_inspect(env: &Env, this: &mut JsObject) -> napi::Result<()> {
let custom = env
.get_global()
.ok()?
.get_named_property::<JsObject>("Symbol")
.ok()?
.get_named_property::<JsFunction>("for")
.ok()?
.call(
None,
&[env.create_string("nodejs.util.inspect.custom").ok()?],
)
.ok()?;
.get_global()?
.get_named_property::<JsUnknown>("Symbol")?
.coerce_to_object()?
.get_named_property::<JsFunction>("for")?
.call(None, &[env.create_string("nodejs.util.inspect.custom")?])?;

this.set_property(
custom,
Expand All @@ -443,10 +437,8 @@ impl JavaClassInstance {
let res = method.call(&obj, &[]).map_napi_err()?;
res.to_napi_value(&env, &ctx.env).map_napi_err()
},
)
.ok()?,
)?,
)
.ok()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/java-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
.header(java_home.join("jni.h").as_path().to_str().unwrap())
.clang_arg(format!("-I{}", java_home.to_str().unwrap()).as_str())
.clang_arg(format!("-I{}", java_home.join(os_dir).as_path().to_str().unwrap()).as_str())
.parse_callbacks(Box::new(bindgen::CargoCallbacks));
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));

if build_target::target_os().unwrap() == Os::Linux
&& build_target::target_arch().unwrap() == Arch::AARCH64
Expand Down

0 comments on commit 49d43ca

Please sign in to comment.