mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-21 05:02:11 -05:00
fix: make Eternal::get return an Option instead (#1671)
This commit is contained in:
parent
f830de59a7
commit
36015e7e25
2 changed files with 13 additions and 10 deletions
|
@ -1147,16 +1147,17 @@ 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| {
|
||||
v8__Eternal__Get(
|
||||
self as *const Self as *const Eternal<Data>,
|
||||
sd.get_isolate_ptr(),
|
||||
) as *const T
|
||||
})
|
||||
.unwrap()
|
||||
scope.cast_local(|sd| {
|
||||
v8__Eternal__Get(
|
||||
self as *const Self as *const Eternal<Data>,
|
||||
sd.get_isolate_ptr(),
|
||||
) as *const T
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue