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 ///
43 /// # Safety
44 ///
45 /// `value` might not allow `None`.
46 #[unsafe(method(managedValueWithValue:))]
47 #[unsafe(method_family = none)]
48 pub unsafe fn managedValueWithValue(
49 value: Option<&JSValue>,
50 ) -> Option<Retained<JSManagedValue>>;
51
52 #[cfg(feature = "JSValue")]
53 /// # Safety
54 ///
55 /// - `value` might not allow `None`.
56 /// - `owner` should be of the correct type.
57 /// - `owner` might not allow `None`.
58 #[unsafe(method(managedValueWithValue:andOwner:))]
59 #[unsafe(method_family = none)]
60 pub unsafe fn managedValueWithValue_andOwner(
61 value: Option<&JSValue>,
62 owner: Option<&AnyObject>,
63 ) -> Option<Retained<JSManagedValue>>;
64
65 #[cfg(feature = "JSValue")]
66 /// Create a JSManagedValue.
67 ///
68 /// Returns: The new JSManagedValue.
69 ///
70 /// # Safety
71 ///
72 /// `value` might not allow `None`.
73 #[unsafe(method(initWithValue:))]
74 #[unsafe(method_family = init)]
75 pub unsafe fn initWithValue(
76 this: Allocated<Self>,
77 value: Option<&JSValue>,
78 ) -> Option<Retained<Self>>;
79
80 #[cfg(feature = "JSValue")]
81 /// Get the JSValue from the JSManagedValue.
82 ///
83 /// Returns: The corresponding JSValue for this JSManagedValue or
84 /// nil if the JSValue has been collected.
85 #[unsafe(method(value))]
86 #[unsafe(method_family = none)]
87 pub unsafe fn value(&self) -> Option<Retained<JSValue>>;
88 );
89}
90
91/// Methods declared on superclass `NSObject`.
92#[cfg(feature = "objc2")]
93impl JSManagedValue {
94 extern_methods!(
95 #[unsafe(method(init))]
96 #[unsafe(method_family = init)]
97 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
98
99 #[unsafe(method(new))]
100 #[unsafe(method_family = new)]
101 pub unsafe fn new() -> Retained<Self>;
102 );
103}