File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -182,10 +182,12 @@ impl FunctionTemplateData {
182
182
}
183
183
}
184
184
185
+ #[ derive( Debug ) ]
185
186
pub struct SameObject < T : GarbageCollected + ' static > {
186
187
cell : std:: cell:: OnceCell < v8:: Global < v8:: Object > > ,
187
188
_phantom_data : std:: marker:: PhantomData < T > ,
188
189
}
190
+
189
191
impl < T : GarbageCollected + ' static > SameObject < T > {
190
192
#[ allow( clippy:: new_without_default) ]
191
193
pub fn new ( ) -> Self {
@@ -212,4 +214,19 @@ impl<T: GarbageCollected + 'static> SameObject<T> {
212
214
} )
213
215
. clone ( )
214
216
}
217
+
218
+ pub fn set (
219
+ & self ,
220
+ scope : & mut v8:: HandleScope ,
221
+ value : T ,
222
+ ) -> Result < ( ) , v8:: Global < v8:: Object > > {
223
+ let obj = make_cppgc_object ( scope, value) ;
224
+ self . cell . set ( v8:: Global :: new ( scope, obj) )
225
+ }
226
+
227
+ pub fn try_unwrap ( & self , scope : & mut v8:: HandleScope ) -> Option < Ptr < T > > {
228
+ let obj = self . cell . get ( ) ?;
229
+ let val = v8:: Local :: new ( scope, obj) ;
230
+ try_unwrap_cppgc_object ( scope, val. cast ( ) )
231
+ }
215
232
}
You can’t perform that action at this time.
0 commit comments