Skip to content

Commit

Permalink
fix: make Eternal::get return an Option instead
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Dec 31, 2024
1 parent f830de5 commit f181726
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ impl<T> Eternal<T> {
}
}

pub fn get<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, T> {
pub fn get<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Option<Local<'s, T>> {
unsafe {
scope
.cast_local(|sd| {
Expand All @@ -1156,7 +1156,6 @@ impl<T> Eternal<T> {
sd.get_isolate_ptr(),
) as *const T
})
.unwrap()
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11990,14 +11990,16 @@ fn test_eternals() {
let str1 = v8::String::new(&mut scope, "hello").unwrap();

assert!(eternal1.is_empty());
assert!(eternal1.get(&mut scope).is_none());
eternal1.set(&mut scope, str1);
assert!(!eternal1.is_empty());

let str1_get = eternal1.get(&mut scope);
let str1_get = eternal1.get(&mut scope).unwrap();
assert_eq!(str1, str1_get);

eternal1.clear();
assert!(eternal1.is_empty());
assert!(eternal1.get(&mut scope).is_none());
}

// Try all 'standalone' methods after isolate has dropped.
Expand Down

0 comments on commit f181726

Please sign in to comment.