objc2_javascript_core/generated/JSExport.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3#[cfg(feature = "objc2")]
4use objc2::__framework_prelude::*;
5
6use crate::*;
7
8#[cfg(feature = "objc2")]
9extern_protocol!(
10 /// JSExport provides a declarative way to export Objective-C objects and
11 /// classes -- including properties, instance methods, class methods, and
12 /// initializers -- to JavaScript.
13 ///
14 /// When an Objective-C object is exported to JavaScript, a JavaScript
15 /// wrapper object is created.
16 ///
17 /// In JavaScript, inheritance works via a chain of prototype objects.
18 /// For each Objective-C class in each JSContext, an object appropriate for use
19 /// as a prototype will be provided. For the class NSObject the prototype
20 /// will be the Object prototype. For all other Objective-C
21 /// classes a prototype will be created. The prototype for a given
22 /// Objective-C class will have its internal [Prototype] property set to point to
23 /// the prototype created for the Objective-C class's superclass. As such the
24 /// prototype chain for a JavaScript wrapper object will reflect the wrapped
25 /// Objective-C type's inheritance hierarchy.
26 ///
27 /// JavaScriptCore also produces a constructor for each Objective-C class. The
28 /// constructor has a property named 'prototype' that references the prototype,
29 /// and the prototype has a property named 'constructor' that references the
30 /// constructor.
31 ///
32 /// By default JavaScriptCore does not export any methods or properties from an
33 /// Objective-C class to JavaScript; however methods and properties may be exported
34 /// explicitly using JSExport. For each protocol that a class conforms to, if the
35 /// protocol incorporates the protocol JSExport, JavaScriptCore exports the methods
36 /// and properties in that protocol to JavaScript
37 ///
38 /// For each exported instance method JavaScriptCore will assign a corresponding
39 /// JavaScript function to the prototype. For each exported Objective-C property
40 /// JavaScriptCore will assign a corresponding JavaScript accessor to the prototype.
41 /// For each exported class method JavaScriptCore will assign a corresponding
42 /// JavaScript function to the constructor. For example:
43 ///
44 /// <pre>
45 ///
46 /// ```text
47 /// @protocol MyClassJavaScriptMethods <JSExport>
48 /// - (void)foo;
49 /// @end
50 ///
51 /// @interface MyClass : NSObject <MyClassJavaScriptMethods>
52 /// - (void)foo;
53 /// - (void)bar;
54 /// @end
55 /// ```
56 ///
57 /// </pre>
58 ///
59 /// Data properties that are created on the prototype or constructor objects have
60 /// the attributes:
61 /// <code>
62 /// writable:true
63 /// </code>
64 /// ,
65 /// <code>
66 /// enumerable:false
67 /// </code>
68 /// ,
69 /// <code>
70 /// configurable:true
71 /// </code>
72 /// .
73 /// Accessor properties have the attributes:
74 /// <code>
75 /// enumerable:false
76 /// </code>
77 /// and
78 /// <code>
79 /// configurable:true
80 /// </code>
81 /// .
82 ///
83 /// If an instance of
84 /// <code>
85 /// MyClass
86 /// </code>
87 /// is converted to a JavaScript value, the resulting
88 /// wrapper object will (via its prototype) export the method
89 /// <code>
90 /// foo
91 /// </code>
92 /// to JavaScript,
93 /// since the class conforms to the
94 /// <code>
95 /// MyClassJavaScriptMethods
96 /// </code>
97 /// protocol, and this
98 /// protocol incorporates
99 /// <code>
100 /// JSExport
101 /// </code>
102 /// .
103 /// <code>
104 /// bar
105 /// </code>
106 /// will not be exported.
107 ///
108 /// JSExport supports properties, arguments, and return values of the following types:
109 ///
110 /// Primitive numbers: signed values up to 32-bits convert using JSValue's
111 /// valueWithInt32/toInt32. Unsigned values up to 32-bits convert using JSValue's
112 /// valueWithUInt32/toUInt32. All other numeric values convert using JSValue's
113 /// valueWithDouble/toDouble.
114 ///
115 /// BOOL: values convert using JSValue's valueWithBool/toBool.
116 ///
117 /// id: values convert using JSValue's valueWithObject/toObject.
118 ///
119 /// Objective-C instance pointers: Pointers convert using JSValue's
120 /// valueWithObjectOfClass/toObject.
121 ///
122 /// C structs: C structs for CGPoint, NSRange, CGRect, and CGSize convert using
123 /// JSValue's appropriate methods. Other C structs are not supported.
124 ///
125 /// Blocks: Blocks convert using JSValue's valueWithObject/toObject.
126 ///
127 /// All objects that conform to JSExport convert to JavaScript wrapper objects,
128 /// even if they subclass classes that would otherwise behave differently. For
129 /// example, if a subclass of NSString conforms to JSExport, it converts to
130 /// JavaScript as a wrapper object rather than a JavaScript string.
131 ///
132 /// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsexport?language=objc)
133 #[cfg(feature = "objc2")]
134 pub unsafe trait JSExport {}
135);