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 #[doc(alias = "JSContextGroupRetain")]
39 #[cfg(feature = "JSBase")]
40 #[inline]
41 pub unsafe fn group_retain(group: JSContextGroupRef) -> JSContextGroupRef {
42 extern "C-unwind" {
43 fn JSContextGroupRetain(group: JSContextGroupRef) -> JSContextGroupRef;
44 }
45 unsafe { JSContextGroupRetain(group) }
46 }
47
48 /// Releases a JavaScript context group.
49 ///
50 /// Parameter `group`: The JSContextGroup to release.
51 #[doc(alias = "JSContextGroupRelease")]
52 #[cfg(feature = "JSBase")]
53 #[inline]
54 pub unsafe fn group_release(group: JSContextGroupRef) {
55 extern "C-unwind" {
56 fn JSContextGroupRelease(group: JSContextGroupRef);
57 }
58 unsafe { JSContextGroupRelease(group) }
59 }
60}
61
62extern "C-unwind" {
63 /// Creates a global JavaScript execution context.
64 ///
65 /// JSGlobalContextCreate allocates a global object and populates it with all the
66 /// built-in JavaScript objects, such as Object, Function, String, and Array.
67 ///
68 /// In WebKit version 4.0 and later, the context is created in a unique context group.
69 /// Therefore, scripts may execute in it concurrently with scripts executing in other contexts.
70 /// However, you may not use values created in the context in other contexts.
71 ///
72 /// Parameter `globalObjectClass`: The class to use when creating the global object. Pass
73 /// NULL to use the default object class.
74 ///
75 /// Returns: A JSGlobalContext with a global object of class globalObjectClass.
76 #[cfg(feature = "JSBase")]
77 pub fn JSGlobalContextCreate(global_object_class: JSClassRef) -> JSGlobalContextRef;
78}
79
80extern "C-unwind" {
81 /// Creates a global JavaScript execution context in the context group provided.
82 ///
83 /// JSGlobalContextCreateInGroup allocates a global object and populates it with
84 /// all the built-in JavaScript objects, such as Object, Function, String, and Array.
85 ///
86 /// Parameter `globalObjectClass`: The class to use when creating the global object. Pass
87 /// NULL to use the default object class.
88 ///
89 /// Parameter `group`: The context group to use. The created global context retains the group.
90 /// Pass NULL to create a unique group for the context.
91 ///
92 /// Returns: A JSGlobalContext with a global object of class globalObjectClass and a context
93 /// group equal to group.
94 #[cfg(feature = "JSBase")]
95 pub fn JSGlobalContextCreateInGroup(
96 group: JSContextGroupRef,
97 global_object_class: JSClassRef,
98 ) -> JSGlobalContextRef;
99}
100
101extern "C-unwind" {
102 /// Retains a global JavaScript execution context.
103 ///
104 /// Parameter `ctx`: The JSGlobalContext to retain.
105 ///
106 /// Returns: A JSGlobalContext that is the same as ctx.
107 #[cfg(feature = "JSBase")]
108 pub fn JSGlobalContextRetain(ctx: JSGlobalContextRef) -> JSGlobalContextRef;
109}
110
111extern "C-unwind" {
112 /// Releases a global JavaScript execution context.
113 ///
114 /// Parameter `ctx`: The JSGlobalContext to release.
115 #[cfg(feature = "JSBase")]
116 pub fn JSGlobalContextRelease(ctx: JSGlobalContextRef);
117}
118
119#[cfg(all(feature = "JSContext", feature = "objc2"))]
120impl JSContext {
121 /// Gets the global object of a JavaScript execution context.
122 ///
123 /// Parameter `ctx`: The JSContext whose global object you want to get.
124 ///
125 /// Returns: ctx's global object.
126 #[doc(alias = "JSContextGetGlobalObject")]
127 #[cfg(feature = "JSBase")]
128 #[inline]
129 pub unsafe fn global_object(ctx: JSContextRef) -> JSObjectRef {
130 extern "C-unwind" {
131 fn JSContextGetGlobalObject(ctx: JSContextRef) -> JSObjectRef;
132 }
133 unsafe { JSContextGetGlobalObject(ctx) }
134 }
135
136 /// Gets the context group to which a JavaScript execution context belongs.
137 ///
138 /// Parameter `ctx`: The JSContext whose group you want to get.
139 ///
140 /// Returns: ctx's group.
141 #[doc(alias = "JSContextGetGroup")]
142 #[cfg(feature = "JSBase")]
143 #[inline]
144 pub unsafe fn group(ctx: JSContextRef) -> JSContextGroupRef {
145 extern "C-unwind" {
146 fn JSContextGetGroup(ctx: JSContextRef) -> JSContextGroupRef;
147 }
148 unsafe { JSContextGetGroup(ctx) }
149 }
150
151 /// Gets the global context of a JavaScript execution context.
152 ///
153 /// Parameter `ctx`: The JSContext whose global context you want to get.
154 ///
155 /// Returns: ctx's global context.
156 #[doc(alias = "JSContextGetGlobalContext")]
157 #[cfg(feature = "JSBase")]
158 #[inline]
159 pub unsafe fn global_context(ctx: JSContextRef) -> JSGlobalContextRef {
160 extern "C-unwind" {
161 fn JSContextGetGlobalContext(ctx: JSContextRef) -> JSGlobalContextRef;
162 }
163 unsafe { JSContextGetGlobalContext(ctx) }
164 }
165}
166
167extern "C-unwind" {
168 /// Gets a copy of the name of a context.
169 ///
170 /// Parameter `ctx`: The JSGlobalContext whose name you want to get.
171 ///
172 /// Returns: The name for ctx.
173 ///
174 /// A JSGlobalContext's name is exposed when inspecting the context to make it easier to identify the context you would like to inspect.
175 #[cfg(feature = "JSBase")]
176 pub fn JSGlobalContextCopyName(ctx: JSGlobalContextRef) -> JSStringRef;
177}
178
179extern "C-unwind" {
180 /// Sets the name exposed when inspecting a context.
181 ///
182 /// Parameter `ctx`: The JSGlobalContext that you want to name.
183 ///
184 /// Parameter `name`: The name to set on the context.
185 #[cfg(feature = "JSBase")]
186 pub fn JSGlobalContextSetName(ctx: JSGlobalContextRef, name: JSStringRef);
187}
188
189extern "C-unwind" {
190 /// Gets whether the context is inspectable in Web Inspector.
191 ///
192 /// Parameter `ctx`: The JSGlobalContext that you want to change the inspectability of.
193 ///
194 /// Returns: Whether the context is inspectable in Web Inspector.
195 #[cfg(feature = "JSBase")]
196 pub fn JSGlobalContextIsInspectable(ctx: JSGlobalContextRef) -> bool;
197}
198
199extern "C-unwind" {
200 /// Sets whether the context is inspectable in Web Inspector. Default value is NO.
201 ///
202 /// Parameter `ctx`: The JSGlobalContext that you want to change the inspectability of.
203 ///
204 /// Parameter `inspectable`: YES to allow Web Inspector to connect to the context, otherwise NO.
205 #[cfg(feature = "JSBase")]
206 pub fn JSGlobalContextSetInspectable(ctx: JSGlobalContextRef, inspectable: bool);
207}
208
209extern "C-unwind" {
210 #[cfg(feature = "JSBase")]
211 #[deprecated = "renamed to `JSContext::group_create`"]
212 pub fn JSContextGroupCreate() -> JSContextGroupRef;
213}
214
215extern "C-unwind" {
216 #[cfg(feature = "JSBase")]
217 #[deprecated = "renamed to `JSContext::group_retain`"]
218 pub fn JSContextGroupRetain(group: JSContextGroupRef) -> JSContextGroupRef;
219}
220
221extern "C-unwind" {
222 #[cfg(feature = "JSBase")]
223 #[deprecated = "renamed to `JSContext::group_release`"]
224 pub fn JSContextGroupRelease(group: JSContextGroupRef);
225}
226
227extern "C-unwind" {
228 #[cfg(feature = "JSBase")]
229 #[deprecated = "renamed to `JSContext::global_object`"]
230 pub fn JSContextGetGlobalObject(ctx: JSContextRef) -> JSObjectRef;
231}
232
233extern "C-unwind" {
234 #[cfg(feature = "JSBase")]
235 #[deprecated = "renamed to `JSContext::group`"]
236 pub fn JSContextGetGroup(ctx: JSContextRef) -> JSContextGroupRef;
237}
238
239extern "C-unwind" {
240 #[cfg(feature = "JSBase")]
241 #[deprecated = "renamed to `JSContext::global_context`"]
242 pub fn JSContextGetGlobalContext(ctx: JSContextRef) -> JSGlobalContextRef;
243}