objc2_javascript_core/generated/
JSContextRef.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4
5use crate::*;
6
7#[cfg(all(feature = "JSContext", feature = "objc2"))]
8impl JSContext {
9    /// Creates a JavaScript context group.
10    ///
11    /// A JSContextGroup associates JavaScript contexts with one another.
12    /// Contexts in the same group may share and exchange JavaScript objects. Sharing and/or exchanging
13    /// JavaScript objects between contexts in different groups will produce undefined behavior.
14    /// When objects from the same context group are used in multiple threads, explicit
15    /// synchronization is required.
16    ///
17    /// A JSContextGroup may need to run deferred tasks on a run loop, such as garbage collection
18    /// or resolving WebAssembly compilations. By default, calling JSContextGroupCreate will use
19    /// the run loop of the thread it was called on. Currently, there is no API to change a
20    /// JSContextGroup's run loop once it has been created.
21    ///
22    /// Returns: The created JSContextGroup.
23    #[doc(alias = "JSContextGroupCreate")]
24    #[cfg(feature = "JSBase")]
25    #[inline]
26    pub unsafe fn group_create() -> JSContextGroupRef {
27        extern "C-unwind" {
28            fn JSContextGroupCreate() -> JSContextGroupRef;
29        }
30        unsafe { JSContextGroupCreate() }
31    }
32
33    /// Retains a JavaScript context group.
34    ///
35    /// Parameter `group`: The JSContextGroup to retain.
36    ///
37    /// Returns: A JSContextGroup that is the same as group.
38    ///
39    /// # Safety
40    ///
41    /// `group` must be a valid pointer.
42    #[doc(alias = "JSContextGroupRetain")]
43    #[cfg(feature = "JSBase")]
44    #[inline]
45    pub unsafe fn group_retain(group: JSContextGroupRef) -> JSContextGroupRef {
46        extern "C-unwind" {
47            fn JSContextGroupRetain(group: JSContextGroupRef) -> JSContextGroupRef;
48        }
49        unsafe { JSContextGroupRetain(group) }
50    }
51
52    /// Releases a JavaScript context group.
53    ///
54    /// Parameter `group`: The JSContextGroup to release.
55    ///
56    /// # Safety
57    ///
58    /// `group` must be a valid pointer.
59    #[doc(alias = "JSContextGroupRelease")]
60    #[cfg(feature = "JSBase")]
61    #[inline]
62    pub unsafe fn group_release(group: JSContextGroupRef) {
63        extern "C-unwind" {
64            fn JSContextGroupRelease(group: JSContextGroupRef);
65        }
66        unsafe { JSContextGroupRelease(group) }
67    }
68}
69
70extern "C-unwind" {
71    /// Creates a global JavaScript execution context.
72    ///
73    /// JSGlobalContextCreate allocates a global object and populates it with all the
74    /// built-in JavaScript objects, such as Object, Function, String, and Array.
75    ///
76    /// In WebKit version 4.0 and later, the context is created in a unique context group.
77    /// Therefore, scripts may execute in it concurrently with scripts executing in other contexts.
78    /// However, you may not use values created in the context in other contexts.
79    ///
80    /// Parameter `globalObjectClass`: The class to use when creating the global object. Pass
81    /// NULL to use the default object class.
82    ///
83    /// Returns: A JSGlobalContext with a global object of class globalObjectClass.
84    ///
85    /// # Safety
86    ///
87    /// `global_object_class` must be a valid pointer.
88    #[cfg(feature = "JSBase")]
89    pub fn JSGlobalContextCreate(global_object_class: JSClassRef) -> JSGlobalContextRef;
90}
91
92extern "C-unwind" {
93    /// Creates a global JavaScript execution context in the context group provided.
94    ///
95    /// JSGlobalContextCreateInGroup allocates a global object and populates it with
96    /// all the built-in JavaScript objects, such as Object, Function, String, and Array.
97    ///
98    /// Parameter `globalObjectClass`: The class to use when creating the global object. Pass
99    /// NULL to use the default object class.
100    ///
101    /// Parameter `group`: The context group to use. The created global context retains the group.
102    /// Pass NULL to create a unique group for the context.
103    ///
104    /// Returns: A JSGlobalContext with a global object of class globalObjectClass and a context
105    /// group equal to group.
106    ///
107    /// # Safety
108    ///
109    /// - `group` must be a valid pointer.
110    /// - `global_object_class` must be a valid pointer.
111    #[cfg(feature = "JSBase")]
112    pub fn JSGlobalContextCreateInGroup(
113        group: JSContextGroupRef,
114        global_object_class: JSClassRef,
115    ) -> JSGlobalContextRef;
116}
117
118extern "C-unwind" {
119    /// Retains a global JavaScript execution context.
120    ///
121    /// Parameter `ctx`: The JSGlobalContext to retain.
122    ///
123    /// Returns: A JSGlobalContext that is the same as ctx.
124    ///
125    /// # Safety
126    ///
127    /// `ctx` must be a valid pointer.
128    #[cfg(feature = "JSBase")]
129    pub fn JSGlobalContextRetain(ctx: JSGlobalContextRef) -> JSGlobalContextRef;
130}
131
132extern "C-unwind" {
133    /// Releases a global JavaScript execution context.
134    ///
135    /// Parameter `ctx`: The JSGlobalContext to release.
136    ///
137    /// # Safety
138    ///
139    /// `ctx` must be a valid pointer.
140    #[cfg(feature = "JSBase")]
141    pub fn JSGlobalContextRelease(ctx: JSGlobalContextRef);
142}
143
144#[cfg(all(feature = "JSContext", feature = "objc2"))]
145impl JSContext {
146    /// Gets the global object of a JavaScript execution context.
147    ///
148    /// Parameter `ctx`: The JSContext whose global object you want to get.
149    ///
150    /// Returns: ctx's global object.
151    ///
152    /// # Safety
153    ///
154    /// `ctx` must be a valid pointer.
155    #[doc(alias = "JSContextGetGlobalObject")]
156    #[cfg(feature = "JSBase")]
157    #[inline]
158    pub unsafe fn global_object(ctx: JSContextRef) -> JSObjectRef {
159        extern "C-unwind" {
160            fn JSContextGetGlobalObject(ctx: JSContextRef) -> JSObjectRef;
161        }
162        unsafe { JSContextGetGlobalObject(ctx) }
163    }
164
165    /// Gets the context group to which a JavaScript execution context belongs.
166    ///
167    /// Parameter `ctx`: The JSContext whose group you want to get.
168    ///
169    /// Returns: ctx's group.
170    ///
171    /// # Safety
172    ///
173    /// `ctx` must be a valid pointer.
174    #[doc(alias = "JSContextGetGroup")]
175    #[cfg(feature = "JSBase")]
176    #[inline]
177    pub unsafe fn group(ctx: JSContextRef) -> JSContextGroupRef {
178        extern "C-unwind" {
179            fn JSContextGetGroup(ctx: JSContextRef) -> JSContextGroupRef;
180        }
181        unsafe { JSContextGetGroup(ctx) }
182    }
183
184    /// Gets the global context of a JavaScript execution context.
185    ///
186    /// Parameter `ctx`: The JSContext whose global context you want to get.
187    ///
188    /// Returns: ctx's global context.
189    ///
190    /// # Safety
191    ///
192    /// `ctx` must be a valid pointer.
193    #[doc(alias = "JSContextGetGlobalContext")]
194    #[cfg(feature = "JSBase")]
195    #[inline]
196    pub unsafe fn global_context(ctx: JSContextRef) -> JSGlobalContextRef {
197        extern "C-unwind" {
198            fn JSContextGetGlobalContext(ctx: JSContextRef) -> JSGlobalContextRef;
199        }
200        unsafe { JSContextGetGlobalContext(ctx) }
201    }
202}
203
204extern "C-unwind" {
205    /// Gets a copy of the name of a context.
206    ///
207    /// Parameter `ctx`: The JSGlobalContext whose name you want to get.
208    ///
209    /// Returns: The name for ctx.
210    ///
211    /// A JSGlobalContext's name is exposed when inspecting the context to make it easier to identify the context you would like to inspect.
212    ///
213    /// # Safety
214    ///
215    /// `ctx` must be a valid pointer.
216    #[cfg(feature = "JSBase")]
217    pub fn JSGlobalContextCopyName(ctx: JSGlobalContextRef) -> JSStringRef;
218}
219
220extern "C-unwind" {
221    /// Sets the name exposed when inspecting a context.
222    ///
223    /// Parameter `ctx`: The JSGlobalContext that you want to name.
224    ///
225    /// Parameter `name`: The name to set on the context.
226    ///
227    /// # Safety
228    ///
229    /// - `ctx` must be a valid pointer.
230    /// - `name` must be a valid pointer.
231    #[cfg(feature = "JSBase")]
232    pub fn JSGlobalContextSetName(ctx: JSGlobalContextRef, name: JSStringRef);
233}
234
235extern "C-unwind" {
236    /// Gets whether the context is inspectable in Web Inspector.
237    ///
238    /// Parameter `ctx`: The JSGlobalContext that you want to change the inspectability of.
239    ///
240    /// Returns: Whether the context is inspectable in Web Inspector.
241    ///
242    /// # Safety
243    ///
244    /// `ctx` must be a valid pointer.
245    #[cfg(feature = "JSBase")]
246    pub fn JSGlobalContextIsInspectable(ctx: JSGlobalContextRef) -> bool;
247}
248
249extern "C-unwind" {
250    /// Sets whether the context is inspectable in Web Inspector. Default value is NO.
251    ///
252    /// Parameter `ctx`: The JSGlobalContext that you want to change the inspectability of.
253    ///
254    /// Parameter `inspectable`: YES to allow Web Inspector to connect to the context, otherwise NO.
255    ///
256    /// # Safety
257    ///
258    /// `ctx` must be a valid pointer.
259    #[cfg(feature = "JSBase")]
260    pub fn JSGlobalContextSetInspectable(ctx: JSGlobalContextRef, inspectable: bool);
261}
262
263extern "C-unwind" {
264    #[cfg(feature = "JSBase")]
265    #[deprecated = "renamed to `JSContext::group_create`"]
266    pub fn JSContextGroupCreate() -> JSContextGroupRef;
267}
268
269extern "C-unwind" {
270    #[cfg(feature = "JSBase")]
271    #[deprecated = "renamed to `JSContext::group_retain`"]
272    pub fn JSContextGroupRetain(group: JSContextGroupRef) -> JSContextGroupRef;
273}
274
275extern "C-unwind" {
276    #[cfg(feature = "JSBase")]
277    #[deprecated = "renamed to `JSContext::group_release`"]
278    pub fn JSContextGroupRelease(group: JSContextGroupRef);
279}
280
281extern "C-unwind" {
282    #[cfg(feature = "JSBase")]
283    #[deprecated = "renamed to `JSContext::global_object`"]
284    pub fn JSContextGetGlobalObject(ctx: JSContextRef) -> JSObjectRef;
285}
286
287extern "C-unwind" {
288    #[cfg(feature = "JSBase")]
289    #[deprecated = "renamed to `JSContext::group`"]
290    pub fn JSContextGetGroup(ctx: JSContextRef) -> JSContextGroupRef;
291}
292
293extern "C-unwind" {
294    #[cfg(feature = "JSBase")]
295    #[deprecated = "renamed to `JSContext::global_context`"]
296    pub fn JSContextGetGlobalContext(ctx: JSContextRef) -> JSGlobalContextRef;
297}