objc2_javascript_core/generated/
JSManagedValue.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4#[cfg(feature = "objc2")]
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9#[cfg(feature = "objc2")]
10extern_class!(
11    /// JSManagedValue represents a "conditionally retained" JSValue.
12    /// "Conditionally retained" means that as long as the JSManagedValue's
13    /// JSValue is reachable through the JavaScript object graph,
14    /// or through the Objective-C object graph reported to the JSVirtualMachine using
15    /// addManagedReference:withOwner:, the corresponding JSValue will
16    /// be retained. However, if neither graph reaches the JSManagedValue, the
17    /// corresponding JSValue will be released and set to nil.
18    ///
19    /// The primary use for a JSManagedValue is to store a JSValue in an Objective-C
20    /// or Swift object that is exported to JavaScript. It is incorrect to store a JSValue
21    /// in an object that is exported to JavaScript, since doing so creates a retain cycle.
22    ///
23    /// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsmanagedvalue?language=objc)
24    #[unsafe(super(NSObject))]
25    #[derive(Debug, PartialEq, Eq, Hash)]
26    #[cfg(feature = "objc2")]
27    pub struct JSManagedValue;
28);
29
30#[cfg(feature = "objc2")]
31extern_conformance!(
32    unsafe impl NSObjectProtocol for JSManagedValue {}
33);
34
35#[cfg(feature = "objc2")]
36impl JSManagedValue {
37    extern_methods!(
38        #[cfg(feature = "JSValue")]
39        /// Create a JSManagedValue from a JSValue.
40        ///
41        /// Returns: The new JSManagedValue.
42        #[unsafe(method(managedValueWithValue:))]
43        #[unsafe(method_family = none)]
44        pub unsafe fn managedValueWithValue(
45            value: Option<&JSValue>,
46        ) -> Option<Retained<JSManagedValue>>;
47
48        #[cfg(feature = "JSValue")]
49        #[unsafe(method(managedValueWithValue:andOwner:))]
50        #[unsafe(method_family = none)]
51        pub unsafe fn managedValueWithValue_andOwner(
52            value: Option<&JSValue>,
53            owner: Option<&AnyObject>,
54        ) -> Option<Retained<JSManagedValue>>;
55
56        #[cfg(feature = "JSValue")]
57        /// Create a JSManagedValue.
58        ///
59        /// Returns: The new JSManagedValue.
60        #[unsafe(method(initWithValue:))]
61        #[unsafe(method_family = init)]
62        pub unsafe fn initWithValue(
63            this: Allocated<Self>,
64            value: Option<&JSValue>,
65        ) -> Option<Retained<Self>>;
66
67        #[cfg(feature = "JSValue")]
68        /// Get the JSValue from the JSManagedValue.
69        ///
70        /// Returns: The corresponding JSValue for this JSManagedValue or
71        /// nil if the JSValue has been collected.
72        #[unsafe(method(value))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn value(&self) -> Option<Retained<JSValue>>;
75    );
76}
77
78/// Methods declared on superclass `NSObject`.
79#[cfg(feature = "objc2")]
80impl JSManagedValue {
81    extern_methods!(
82        #[unsafe(method(init))]
83        #[unsafe(method_family = init)]
84        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
85
86        #[unsafe(method(new))]
87        #[unsafe(method_family = new)]
88        pub unsafe fn new() -> Retained<Self>;
89    );
90}