File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -127,12 +127,27 @@ impl<'cx> AutoRealm<'cx> {
127127}
128128
129129impl < ' cx > Drop for AutoRealm < ' cx > {
130- // this is not trivially dropped type
131- // not sure why we need to do this manually
130+ // if we do not implement this rust can shorten lifetime of cx,
131+ // without effecting JSAutoRealm (realm drops after we lose lifetime of cx)
132132 fn drop ( & mut self ) { }
133133}
134134
135135/// Represents the current realm of [JSContext] (top realm on realm stack).
136+ ///
137+ /// Similarly to [AutoRealm], while you can access this type via `&mut`/`&mut`
138+ /// we know that this realm is current (on top of realm stack).
139+ ///
140+ /// ```compile_fail
141+ /// use mozjs::context::JSContext;
142+ /// use mozjs::jsapi::JSObject;
143+ /// use mozjs::realm::{AutoRealm, CurrentRealm};
144+ /// use std::ptr::NonNull;
145+ ///
146+ /// fn f(current_realm: CurrentRealm, target: NonNull<JSObject>) {
147+ /// let mut realm = AutoRealm::new(current_realm.cx(), target);
148+ /// let cx = current_realm.cx(); // we cannot use current realm while it's not current
149+ /// }
150+ /// ```
136151pub struct CurrentRealm < ' cx > {
137152 cx : & ' cx mut JSContext ,
138153 realm : NonNull < Realm > ,
You can’t perform that action at this time.
0 commit comments