objc2_javascript_core/generated/JSObjectRef.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4#[cfg(feature = "objc2")]
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributenone?language=objc)
10pub const kJSPropertyAttributeNone: c_uint = 0;
11/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributereadonly?language=objc)
12pub const kJSPropertyAttributeReadOnly: c_uint = 1 << 1;
13/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributedontenum?language=objc)
14pub const kJSPropertyAttributeDontEnum: c_uint = 1 << 2;
15/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributedontdelete?language=objc)
16pub const kJSPropertyAttributeDontDelete: c_uint = 1 << 3;
17
18/// A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
19///
20/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jspropertyattributes?language=objc)
21pub type JSPropertyAttributes = c_uint;
22
23/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjsclassattributenone?language=objc)
24pub const kJSClassAttributeNone: c_uint = 0;
25/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjsclassattributenoautomaticprototype?language=objc)
26pub const kJSClassAttributeNoAutomaticPrototype: c_uint = 1 << 1;
27
28/// A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
29///
30/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsclassattributes?language=objc)
31pub type JSClassAttributes = c_uint;
32
33/// The callback invoked when an object is first created.
34///
35/// Parameter `ctx`: The execution context to use.
36///
37/// Parameter `object`: The JSObject being created.
38///
39/// If you named your function Initialize, you would declare it like this:
40///
41/// void Initialize(JSContextRef ctx, JSObjectRef object);
42///
43/// Unlike the other object callbacks, the initialize callback is called on the least
44/// derived class (the parent class) first, and the most derived class last.
45///
46/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectinitializecallback?language=objc)
47#[cfg(feature = "JSBase")]
48pub type JSObjectInitializeCallback =
49 Option<unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef)>;
50
51/// The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
52///
53/// Parameter `object`: The JSObject being finalized.
54///
55/// If you named your function Finalize, you would declare it like this:
56///
57/// void Finalize(JSObjectRef object);
58///
59/// The finalize callback is called on the most derived class first, and the least
60/// derived class (the parent class) last.
61///
62/// You must not call any function that may cause a garbage collection or an allocation
63/// of a garbage collected object from within a JSObjectFinalizeCallback. This includes
64/// all functions that have a JSContextRef parameter.
65///
66/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectfinalizecallback?language=objc)
67#[cfg(feature = "JSBase")]
68pub type JSObjectFinalizeCallback = Option<unsafe extern "C-unwind" fn(JSObjectRef)>;
69
70/// The callback invoked when determining whether an object has a property.
71///
72/// Parameter `ctx`: The execution context to use.
73///
74/// Parameter `object`: The JSObject to search for the property.
75///
76/// Parameter `propertyName`: A JSString containing the name of the property look up.
77///
78/// Returns: true if object has the property, otherwise false.
79///
80/// If you named your function HasProperty, you would declare it like this:
81///
82/// bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
83///
84/// If this function returns false, the hasProperty request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
85///
86/// This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive.
87///
88/// If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
89///
90/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjecthaspropertycallback?language=objc)
91#[cfg(feature = "JSBase")]
92pub type JSObjectHasPropertyCallback =
93 Option<unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSStringRef) -> bool>;
94
95/// The callback invoked when getting a property's value.
96///
97/// Parameter `ctx`: The execution context to use.
98///
99/// Parameter `object`: The JSObject to search for the property.
100///
101/// Parameter `propertyName`: A JSString containing the name of the property to get.
102///
103/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
104///
105/// Returns: The property's value if object has the property, otherwise NULL.
106///
107/// If you named your function GetProperty, you would declare it like this:
108///
109/// JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
110///
111/// If this function returns NULL, the get request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
112///
113/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectgetpropertycallback?language=objc)
114#[cfg(feature = "JSBase")]
115pub type JSObjectGetPropertyCallback = Option<
116 unsafe extern "C-unwind" fn(
117 JSContextRef,
118 JSObjectRef,
119 JSStringRef,
120 *mut JSValueRef,
121 ) -> JSValueRef,
122>;
123
124/// The callback invoked when setting a property's value.
125///
126/// Parameter `ctx`: The execution context to use.
127///
128/// Parameter `object`: The JSObject on which to set the property's value.
129///
130/// Parameter `propertyName`: A JSString containing the name of the property to set.
131///
132/// Parameter `value`: A JSValue to use as the property's value.
133///
134/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
135///
136/// Returns: true if the property was set, otherwise false.
137///
138/// If you named your function SetProperty, you would declare it like this:
139///
140/// bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
141///
142/// If this function returns false, the set request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
143///
144/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectsetpropertycallback?language=objc)
145#[cfg(feature = "JSBase")]
146pub type JSObjectSetPropertyCallback = Option<
147 unsafe extern "C-unwind" fn(
148 JSContextRef,
149 JSObjectRef,
150 JSStringRef,
151 JSValueRef,
152 *mut JSValueRef,
153 ) -> bool,
154>;
155
156/// The callback invoked when deleting a property.
157///
158/// Parameter `ctx`: The execution context to use.
159///
160/// Parameter `object`: The JSObject in which to delete the property.
161///
162/// Parameter `propertyName`: A JSString containing the name of the property to delete.
163///
164/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
165///
166/// Returns: true if propertyName was successfully deleted, otherwise false.
167///
168/// If you named your function DeleteProperty, you would declare it like this:
169///
170/// bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
171///
172/// If this function returns false, the delete request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
173///
174/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectdeletepropertycallback?language=objc)
175#[cfg(feature = "JSBase")]
176pub type JSObjectDeletePropertyCallback = Option<
177 unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSStringRef, *mut JSValueRef) -> bool,
178>;
179
180/// The callback invoked when collecting the names of an object's properties.
181///
182/// Parameter `ctx`: The execution context to use.
183///
184/// Parameter `object`: The JSObject whose property names are being collected.
185///
186/// Parameter `propertyNames`: A JavaScript property name accumulator in which to accumulate the names of object's properties.
187///
188/// If you named your function GetPropertyNames, you would declare it like this:
189///
190/// void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
191///
192/// Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.
193///
194/// Use JSPropertyNameAccumulatorAddName to add property names to accumulator. A class's getPropertyNames callback only needs to provide the names of properties that the class vends through a custom getProperty or setProperty callback. Other properties, including statically declared properties, properties vended by other classes, and properties belonging to object's prototype, are added independently.
195///
196/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectgetpropertynamescallback?language=objc)
197#[cfg(feature = "JSBase")]
198pub type JSObjectGetPropertyNamesCallback =
199 Option<unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSPropertyNameAccumulatorRef)>;
200
201/// The callback invoked when an object is called as a function.
202///
203/// Parameter `ctx`: The execution context to use.
204///
205/// Parameter `function`: A JSObject that is the function being called.
206///
207/// Parameter `thisObject`: A JSObject that is the 'this' variable in the function's scope.
208///
209/// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
210///
211/// Parameter `arguments`: A JSValue array of the arguments passed to the function.
212///
213/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
214///
215/// Returns: A JSValue that is the function's return value.
216///
217/// If you named your function CallAsFunction, you would declare it like this:
218///
219/// JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
220///
221/// If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.
222///
223/// If this callback is NULL, calling your object as a function will throw an exception.
224///
225/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectcallasfunctioncallback?language=objc)
226#[cfg(feature = "JSBase")]
227pub type JSObjectCallAsFunctionCallback = Option<
228 unsafe extern "C-unwind" fn(
229 JSContextRef,
230 JSObjectRef,
231 JSObjectRef,
232 usize,
233 *mut JSValueRef,
234 *mut JSValueRef,
235 ) -> JSValueRef,
236>;
237
238/// The callback invoked when an object is used as a constructor in a 'new' expression.
239///
240/// Parameter `ctx`: The execution context to use.
241///
242/// Parameter `constructor`: A JSObject that is the constructor being called.
243///
244/// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
245///
246/// Parameter `arguments`: A JSValue array of the arguments passed to the function.
247///
248/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
249///
250/// Returns: A JSObject that is the constructor's return value.
251///
252/// If you named your function CallAsConstructor, you would declare it like this:
253///
254/// JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
255///
256/// If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.
257///
258/// If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
259///
260/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectcallasconstructorcallback?language=objc)
261#[cfg(feature = "JSBase")]
262pub type JSObjectCallAsConstructorCallback = Option<
263 unsafe extern "C-unwind" fn(
264 JSContextRef,
265 JSObjectRef,
266 usize,
267 *mut JSValueRef,
268 *mut JSValueRef,
269 ) -> JSObjectRef,
270>;
271
272/// hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
273///
274/// Parameter `ctx`: The execution context to use.
275///
276/// Parameter `constructor`: The JSObject that is the target of the 'instanceof' expression.
277///
278/// Parameter `possibleInstance`: The JSValue being tested to determine if it is an instance of constructor.
279///
280/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
281///
282/// Returns: true if possibleInstance is an instance of constructor, otherwise false.
283///
284/// If you named your function HasInstance, you would declare it like this:
285///
286/// bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
287///
288/// If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.
289///
290/// If this callback is NULL, 'instanceof' expressions that target your object will return false.
291///
292/// Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
293///
294/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjecthasinstancecallback?language=objc)
295#[cfg(feature = "JSBase")]
296pub type JSObjectHasInstanceCallback = Option<
297 unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSValueRef, *mut JSValueRef) -> bool,
298>;
299
300/// The callback invoked when converting an object to a particular JavaScript type.
301///
302/// Parameter `ctx`: The execution context to use.
303///
304/// Parameter `object`: The JSObject to convert.
305///
306/// Parameter `type`: A JSType specifying the JavaScript type to convert to.
307///
308/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
309///
310/// Returns: The objects's converted value, or NULL if the object was not converted.
311///
312/// If you named your function ConvertToType, you would declare it like this:
313///
314/// JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
315///
316/// If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
317///
318/// This function is only invoked when converting an object to number or string. An object converted to boolean is 'true.' An object converted to object is itself.
319///
320/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectconverttotypecallback?language=objc)
321#[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
322pub type JSObjectConvertToTypeCallback = Option<
323 unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSType, *mut JSValueRef) -> JSValueRef,
324>;
325
326/// This structure describes a statically declared value property.
327/// Field: name A null-terminated UTF8 string containing the property's name.
328/// Field: getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
329/// Field: setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.
330/// Field: attributes A logically ORed set of JSPropertyAttributes to give to the property.
331///
332/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsstaticvalue?language=objc)
333#[cfg(feature = "JSBase")]
334#[repr(C)]
335#[allow(unpredictable_function_pointer_comparisons)]
336#[derive(Clone, Copy, Debug, PartialEq)]
337pub struct JSStaticValue {
338 pub name: *const c_char,
339 pub getProperty: JSObjectGetPropertyCallback,
340 pub setProperty: JSObjectSetPropertyCallback,
341 pub attributes: JSPropertyAttributes,
342}
343
344#[cfg(all(feature = "JSBase", feature = "objc2"))]
345unsafe impl Encode for JSStaticValue {
346 const ENCODING: Encoding = Encoding::Struct(
347 "?",
348 &[
349 <*const c_char>::ENCODING,
350 <JSObjectGetPropertyCallback>::ENCODING,
351 Encoding::Pointer(&Encoding::Unknown),
352 <JSPropertyAttributes>::ENCODING,
353 ],
354 );
355}
356
357#[cfg(all(feature = "JSBase", feature = "objc2"))]
358unsafe impl RefEncode for JSStaticValue {
359 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
360}
361
362/// This structure describes a statically declared function property.
363/// Field: name A null-terminated UTF8 string containing the property's name.
364/// Field: callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
365/// Field: attributes A logically ORed set of JSPropertyAttributes to give to the property.
366///
367/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsstaticfunction?language=objc)
368#[cfg(feature = "JSBase")]
369#[repr(C)]
370#[allow(unpredictable_function_pointer_comparisons)]
371#[derive(Clone, Copy, Debug, PartialEq)]
372pub struct JSStaticFunction {
373 pub name: *const c_char,
374 pub callAsFunction: JSObjectCallAsFunctionCallback,
375 pub attributes: JSPropertyAttributes,
376}
377
378#[cfg(all(feature = "JSBase", feature = "objc2"))]
379unsafe impl Encode for JSStaticFunction {
380 const ENCODING: Encoding = Encoding::Struct(
381 "?",
382 &[
383 <*const c_char>::ENCODING,
384 <JSObjectCallAsFunctionCallback>::ENCODING,
385 <JSPropertyAttributes>::ENCODING,
386 ],
387 );
388}
389
390#[cfg(all(feature = "JSBase", feature = "objc2"))]
391unsafe impl RefEncode for JSStaticFunction {
392 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
393}
394
395/// This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
396/// Field: version The version number of this structure. The current version is 0.
397/// Field: attributes A logically ORed set of JSClassAttributes to give to the class.
398/// Field: className A null-terminated UTF8 string containing the class's name.
399/// Field: parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
400/// Field: staticValues A JSStaticValue array containing the class's statically declared value properties. Pass NULL to specify no statically declared value properties. The array must be terminated by a JSStaticValue whose name field is NULL.
401/// Field: staticFunctions A JSStaticFunction array containing the class's statically declared function properties. Pass NULL to specify no statically declared function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.
402/// Field: initialize The callback invoked when an object is first created. Use this callback to initialize the object.
403/// Field: finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for the object, and perform other cleanup.
404/// Field: hasProperty The callback invoked when determining whether an object has a property. If this field is NULL, getProperty is called instead. The hasProperty callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value is expensive.
405/// Field: getProperty The callback invoked when getting a property's value.
406/// Field: setProperty The callback invoked when setting a property's value.
407/// Field: deleteProperty The callback invoked when deleting a property.
408/// Field: getPropertyNames The callback invoked when collecting the names of an object's properties.
409/// Field: callAsFunction The callback invoked when an object is called as a function.
410/// Field: hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
411/// Field: callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
412/// Field: convertToType The callback invoked when converting an object to a particular JavaScript type.
413///
414/// The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties autmatically service requests like getProperty, setProperty, and getPropertyNames. Property access callbacks are required only to implement unusual properties, like array indexes, whose names are not known at compile-time.
415///
416/// If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
417///
418/// JSStaticValue StaticValueArray[] = {
419/// { "X", GetX, SetX, kJSPropertyAttributeNone },
420/// { 0, 0, 0, 0 }
421/// };
422///
423/// Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects.
424///
425/// A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
426///
427/// It is not possible to use JS subclassing with objects created from a class definition that sets callAsConstructor by default. Subclassing is supported via the JSObjectMakeConstructor function, however.
428///
429/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsclassdefinition?language=objc)
430#[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
431#[repr(C)]
432#[allow(unpredictable_function_pointer_comparisons)]
433#[derive(Clone, Copy, Debug, PartialEq)]
434pub struct JSClassDefinition {
435 pub version: c_int,
436 pub attributes: JSClassAttributes,
437 pub className: *const c_char,
438 pub parentClass: JSClassRef,
439 pub staticValues: *const JSStaticValue,
440 pub staticFunctions: *const JSStaticFunction,
441 pub initialize: JSObjectInitializeCallback,
442 pub finalize: JSObjectFinalizeCallback,
443 pub hasProperty: JSObjectHasPropertyCallback,
444 pub getProperty: JSObjectGetPropertyCallback,
445 pub setProperty: JSObjectSetPropertyCallback,
446 pub deleteProperty: JSObjectDeletePropertyCallback,
447 pub getPropertyNames: JSObjectGetPropertyNamesCallback,
448 pub callAsFunction: JSObjectCallAsFunctionCallback,
449 pub callAsConstructor: JSObjectCallAsConstructorCallback,
450 pub hasInstance: JSObjectHasInstanceCallback,
451 pub convertToType: JSObjectConvertToTypeCallback,
452}
453
454#[cfg(all(feature = "JSBase", feature = "JSValueRef", feature = "objc2"))]
455unsafe impl Encode for JSClassDefinition {
456 const ENCODING: Encoding = Encoding::Struct(
457 "?",
458 &[
459 <c_int>::ENCODING,
460 <JSClassAttributes>::ENCODING,
461 <*const c_char>::ENCODING,
462 <JSClassRef>::ENCODING,
463 <*const JSStaticValue>::ENCODING,
464 <*const JSStaticFunction>::ENCODING,
465 <JSObjectInitializeCallback>::ENCODING,
466 <JSObjectFinalizeCallback>::ENCODING,
467 Encoding::Pointer(&Encoding::Unknown),
468 <JSObjectGetPropertyCallback>::ENCODING,
469 Encoding::Pointer(&Encoding::Unknown),
470 Encoding::Pointer(&Encoding::Unknown),
471 <JSObjectGetPropertyNamesCallback>::ENCODING,
472 <JSObjectCallAsFunctionCallback>::ENCODING,
473 <JSObjectCallAsConstructorCallback>::ENCODING,
474 Encoding::Pointer(&Encoding::Unknown),
475 <JSObjectConvertToTypeCallback>::ENCODING,
476 ],
477 );
478}
479
480#[cfg(all(feature = "JSBase", feature = "JSValueRef", feature = "objc2"))]
481unsafe impl RefEncode for JSClassDefinition {
482 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
483}
484
485extern "C" {
486 /// A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
487 ///
488 /// Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
489 ///
490 /// JSClassDefinition definition = kJSClassDefinitionEmpty;
491 /// definition.finalize = Finalize;
492 ///
493 /// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjsclassdefinitionempty?language=objc)
494 #[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
495 pub static kJSClassDefinitionEmpty: JSClassDefinition;
496}
497
498extern "C-unwind" {
499 /// Creates a JavaScript class suitable for use with JSObjectMake.
500 ///
501 /// Parameter `definition`: A JSClassDefinition that defines the class.
502 ///
503 /// Returns: A JSClass with the given definition. Ownership follows the Create Rule.
504 ///
505 /// # Safety
506 ///
507 /// `definition` must be a valid pointer.
508 #[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
509 pub fn JSClassCreate(definition: *const JSClassDefinition) -> JSClassRef;
510}
511
512extern "C-unwind" {
513 /// Retains a JavaScript class.
514 ///
515 /// Parameter `jsClass`: The JSClass to retain.
516 ///
517 /// Returns: A JSClass that is the same as jsClass.
518 ///
519 /// # Safety
520 ///
521 /// `js_class` must be a valid pointer.
522 #[cfg(feature = "JSBase")]
523 pub fn JSClassRetain(js_class: JSClassRef) -> JSClassRef;
524}
525
526extern "C-unwind" {
527 /// Releases a JavaScript class.
528 ///
529 /// Parameter `jsClass`: The JSClass to release.
530 ///
531 /// # Safety
532 ///
533 /// `js_class` must be a valid pointer.
534 #[cfg(feature = "JSBase")]
535 pub fn JSClassRelease(js_class: JSClassRef);
536}
537
538extern "C-unwind" {
539 /// Creates a JavaScript object.
540 ///
541 /// Parameter `ctx`: The execution context to use.
542 ///
543 /// Parameter `jsClass`: The JSClass to assign to the object. Pass NULL to use the default object class.
544 ///
545 /// Parameter `data`: A void* to set as the object's private data. Pass NULL to specify no private data.
546 ///
547 /// Returns: A JSObject with the given class and private data.
548 ///
549 /// The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data.
550 ///
551 /// data is set on the created object before the intialize methods in its class chain are called. This enables the initialize methods to retrieve and manipulate data through JSObjectGetPrivate.
552 ///
553 /// # Safety
554 ///
555 /// - `ctx` must be a valid pointer.
556 /// - `js_class` must be a valid pointer.
557 /// - `data` must be a valid pointer.
558 #[cfg(feature = "JSBase")]
559 pub fn JSObjectMake(ctx: JSContextRef, js_class: JSClassRef, data: *mut c_void) -> JSObjectRef;
560}
561
562extern "C-unwind" {
563 /// Convenience method for creating a JavaScript function with a given callback as its implementation.
564 ///
565 /// Parameter `ctx`: The execution context to use.
566 ///
567 /// Parameter `name`: A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
568 ///
569 /// Parameter `callAsFunction`: The JSObjectCallAsFunctionCallback to invoke when the function is called.
570 ///
571 /// Returns: A JSObject that is a function. The object's prototype will be the default function prototype.
572 ///
573 /// # Safety
574 ///
575 /// - `ctx` must be a valid pointer.
576 /// - `name` must be a valid pointer.
577 /// - `call_as_function` must be implemented correctly.
578 #[cfg(feature = "JSBase")]
579 pub fn JSObjectMakeFunctionWithCallback(
580 ctx: JSContextRef,
581 name: JSStringRef,
582 call_as_function: JSObjectCallAsFunctionCallback,
583 ) -> JSObjectRef;
584}
585
586extern "C-unwind" {
587 /// Convenience method for creating a JavaScript constructor.
588 ///
589 /// Parameter `ctx`: The execution context to use.
590 ///
591 /// Parameter `jsClass`: A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class.
592 ///
593 /// Parameter `callAsConstructor`: A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
594 ///
595 /// Returns: A JSObject that is a constructor. The object's prototype will be the default object prototype.
596 ///
597 /// The default object constructor takes no arguments and constructs an object of class jsClass with no private data. If the constructor is inherited via JS subclassing and the value returned from callAsConstructor was created with jsClass, then the returned object will have it's prototype overridden to the derived class's prototype.
598 ///
599 /// # Safety
600 ///
601 /// - `ctx` must be a valid pointer.
602 /// - `js_class` must be a valid pointer.
603 /// - `call_as_constructor` must be implemented correctly.
604 #[cfg(feature = "JSBase")]
605 pub fn JSObjectMakeConstructor(
606 ctx: JSContextRef,
607 js_class: JSClassRef,
608 call_as_constructor: JSObjectCallAsConstructorCallback,
609 ) -> JSObjectRef;
610}
611
612extern "C-unwind" {
613 /// Creates a JavaScript Array object.
614 ///
615 /// Parameter `ctx`: The execution context to use.
616 ///
617 /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
618 ///
619 /// Parameter `arguments`: A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0.
620 ///
621 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
622 ///
623 /// Returns: A JSObject that is an Array.
624 ///
625 /// The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument
626 /// is supplied, this function returns an array with one element.
627 ///
628 /// # Safety
629 ///
630 /// - `ctx` must be a valid pointer.
631 /// - `arguments` must be a valid pointer.
632 /// - `exception` must be a valid pointer.
633 #[cfg(feature = "JSBase")]
634 pub fn JSObjectMakeArray(
635 ctx: JSContextRef,
636 argument_count: usize,
637 arguments: *mut JSValueRef,
638 exception: *mut JSValueRef,
639 ) -> JSObjectRef;
640}
641
642extern "C-unwind" {
643 /// Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
644 ///
645 /// Parameter `ctx`: The execution context to use.
646 ///
647 /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
648 ///
649 /// Parameter `arguments`: A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0.
650 ///
651 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
652 ///
653 /// Returns: A JSObject that is a Date.
654 ///
655 /// # Safety
656 ///
657 /// - `ctx` must be a valid pointer.
658 /// - `arguments` must be a valid pointer.
659 /// - `exception` must be a valid pointer.
660 #[cfg(feature = "JSBase")]
661 pub fn JSObjectMakeDate(
662 ctx: JSContextRef,
663 argument_count: usize,
664 arguments: *mut JSValueRef,
665 exception: *mut JSValueRef,
666 ) -> JSObjectRef;
667}
668
669extern "C-unwind" {
670 /// Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
671 ///
672 /// Parameter `ctx`: The execution context to use.
673 ///
674 /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
675 ///
676 /// Parameter `arguments`: A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0.
677 ///
678 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
679 ///
680 /// Returns: A JSObject that is an Error.
681 ///
682 /// # Safety
683 ///
684 /// - `ctx` must be a valid pointer.
685 /// - `arguments` must be a valid pointer.
686 /// - `exception` must be a valid pointer.
687 #[cfg(feature = "JSBase")]
688 pub fn JSObjectMakeError(
689 ctx: JSContextRef,
690 argument_count: usize,
691 arguments: *mut JSValueRef,
692 exception: *mut JSValueRef,
693 ) -> JSObjectRef;
694}
695
696extern "C-unwind" {
697 /// Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
698 ///
699 /// Parameter `ctx`: The execution context to use.
700 ///
701 /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
702 ///
703 /// Parameter `arguments`: A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0.
704 ///
705 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
706 ///
707 /// Returns: A JSObject that is a RegExp.
708 ///
709 /// # Safety
710 ///
711 /// - `ctx` must be a valid pointer.
712 /// - `arguments` must be a valid pointer.
713 /// - `exception` must be a valid pointer.
714 #[cfg(feature = "JSBase")]
715 pub fn JSObjectMakeRegExp(
716 ctx: JSContextRef,
717 argument_count: usize,
718 arguments: *mut JSValueRef,
719 exception: *mut JSValueRef,
720 ) -> JSObjectRef;
721}
722
723extern "C-unwind" {
724 /// Creates a JavaScript promise object by invoking the provided executor.
725 ///
726 /// Parameter `ctx`: The execution context to use.
727 ///
728 /// Parameter `resolve`: A pointer to a JSObjectRef in which to store the resolve function for the new promise. Pass NULL if you do not care to store the resolve callback.
729 ///
730 /// Parameter `reject`: A pointer to a JSObjectRef in which to store the reject function for the new promise. Pass NULL if you do not care to store the reject callback.
731 ///
732 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
733 ///
734 /// Returns: A JSObject that is a promise or NULL if an exception occurred.
735 ///
736 /// # Safety
737 ///
738 /// - `ctx` must be a valid pointer.
739 /// - `resolve` must be a valid pointer.
740 /// - `reject` must be a valid pointer.
741 /// - `exception` must be a valid pointer.
742 #[cfg(feature = "JSBase")]
743 pub fn JSObjectMakeDeferredPromise(
744 ctx: JSContextRef,
745 resolve: *mut JSObjectRef,
746 reject: *mut JSObjectRef,
747 exception: *mut JSValueRef,
748 ) -> JSObjectRef;
749}
750
751extern "C-unwind" {
752 /// Creates a function with a given script as its body.
753 ///
754 /// Parameter `ctx`: The execution context to use.
755 ///
756 /// Parameter `name`: A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
757 ///
758 /// Parameter `parameterCount`: An integer count of the number of parameter names in parameterNames.
759 ///
760 /// Parameter `parameterNames`: A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
761 ///
762 /// Parameter `body`: A JSString containing the script to use as the function's body.
763 ///
764 /// Parameter `sourceURL`: A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
765 ///
766 /// Parameter `startingLineNumber`: An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
767 ///
768 /// Parameter `exception`: A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
769 ///
770 /// Returns: A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype.
771 ///
772 /// Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
773 ///
774 /// # Safety
775 ///
776 /// - `ctx` must be a valid pointer.
777 /// - `name` must be a valid pointer.
778 /// - `parameter_names` must be a valid pointer.
779 /// - `body` must be a valid pointer.
780 /// - `source_url` must be a valid pointer.
781 /// - `exception` must be a valid pointer.
782 #[cfg(feature = "JSBase")]
783 pub fn JSObjectMakeFunction(
784 ctx: JSContextRef,
785 name: JSStringRef,
786 parameter_count: c_uint,
787 parameter_names: *mut JSStringRef,
788 body: JSStringRef,
789 source_url: JSStringRef,
790 starting_line_number: c_int,
791 exception: *mut JSValueRef,
792 ) -> JSObjectRef;
793}
794
795extern "C-unwind" {
796 /// Gets an object's prototype.
797 ///
798 /// Parameter `ctx`: The execution context to use.
799 ///
800 /// Parameter `object`: A JSObject whose prototype you want to get.
801 ///
802 /// Returns: A JSValue that is the object's prototype.
803 ///
804 /// # Safety
805 ///
806 /// - `ctx` must be a valid pointer.
807 /// - `object` must be a valid pointer.
808 #[cfg(feature = "JSBase")]
809 pub fn JSObjectGetPrototype(ctx: JSContextRef, object: JSObjectRef) -> JSValueRef;
810}
811
812extern "C-unwind" {
813 /// Sets an object's prototype.
814 ///
815 /// Parameter `ctx`: The execution context to use.
816 ///
817 /// Parameter `object`: The JSObject whose prototype you want to set.
818 ///
819 /// Parameter `value`: A JSValue to set as the object's prototype.
820 ///
821 /// # Safety
822 ///
823 /// - `ctx` must be a valid pointer.
824 /// - `object` must be a valid pointer.
825 /// - `value` must be a valid pointer.
826 #[cfg(feature = "JSBase")]
827 pub fn JSObjectSetPrototype(ctx: JSContextRef, object: JSObjectRef, value: JSValueRef);
828}
829
830extern "C-unwind" {
831 /// Tests whether an object has a given property.
832 ///
833 /// Parameter `object`: The JSObject to test.
834 ///
835 /// Parameter `propertyName`: A JSString containing the property's name.
836 ///
837 /// Returns: true if the object has a property whose name matches propertyName, otherwise false.
838 ///
839 /// # Safety
840 ///
841 /// - `ctx` must be a valid pointer.
842 /// - `object` must be a valid pointer.
843 /// - `property_name` must be a valid pointer.
844 #[cfg(feature = "JSBase")]
845 pub fn JSObjectHasProperty(
846 ctx: JSContextRef,
847 object: JSObjectRef,
848 property_name: JSStringRef,
849 ) -> bool;
850}
851
852extern "C-unwind" {
853 /// Gets a property from an object.
854 ///
855 /// Parameter `ctx`: The execution context to use.
856 ///
857 /// Parameter `object`: The JSObject whose property you want to get.
858 ///
859 /// Parameter `propertyName`: A JSString containing the property's name.
860 ///
861 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
862 ///
863 /// Returns: The property's value if object has the property, otherwise the undefined value.
864 ///
865 /// # Safety
866 ///
867 /// - `ctx` must be a valid pointer.
868 /// - `object` must be a valid pointer.
869 /// - `property_name` must be a valid pointer.
870 /// - `exception` must be a valid pointer.
871 #[cfg(feature = "JSBase")]
872 pub fn JSObjectGetProperty(
873 ctx: JSContextRef,
874 object: JSObjectRef,
875 property_name: JSStringRef,
876 exception: *mut JSValueRef,
877 ) -> JSValueRef;
878}
879
880extern "C-unwind" {
881 /// Sets a property on an object.
882 ///
883 /// Parameter `ctx`: The execution context to use.
884 ///
885 /// Parameter `object`: The JSObject whose property you want to set.
886 ///
887 /// Parameter `propertyName`: A JSString containing the property's name.
888 ///
889 /// Parameter `value`: A JSValueRef to use as the property's value.
890 ///
891 /// Parameter `attributes`: A logically ORed set of JSPropertyAttributes to give to the property.
892 ///
893 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
894 ///
895 /// # Safety
896 ///
897 /// - `ctx` must be a valid pointer.
898 /// - `object` must be a valid pointer.
899 /// - `property_name` must be a valid pointer.
900 /// - `value` must be a valid pointer.
901 /// - `exception` must be a valid pointer.
902 #[cfg(feature = "JSBase")]
903 pub fn JSObjectSetProperty(
904 ctx: JSContextRef,
905 object: JSObjectRef,
906 property_name: JSStringRef,
907 value: JSValueRef,
908 attributes: JSPropertyAttributes,
909 exception: *mut JSValueRef,
910 );
911}
912
913extern "C-unwind" {
914 /// Deletes a property from an object.
915 ///
916 /// Parameter `ctx`: The execution context to use.
917 ///
918 /// Parameter `object`: The JSObject whose property you want to delete.
919 ///
920 /// Parameter `propertyName`: A JSString containing the property's name.
921 ///
922 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
923 ///
924 /// Returns: true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
925 ///
926 /// # Safety
927 ///
928 /// - `ctx` must be a valid pointer.
929 /// - `object` must be a valid pointer.
930 /// - `property_name` must be a valid pointer.
931 /// - `exception` must be a valid pointer.
932 #[cfg(feature = "JSBase")]
933 pub fn JSObjectDeleteProperty(
934 ctx: JSContextRef,
935 object: JSObjectRef,
936 property_name: JSStringRef,
937 exception: *mut JSValueRef,
938 ) -> bool;
939}
940
941extern "C-unwind" {
942 /// Tests whether an object has a given property using a JSValueRef as the property key.
943 ///
944 /// Parameter `object`: The JSObject to test.
945 ///
946 /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
947 ///
948 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
949 ///
950 /// Returns: true if the object has a property whose name matches propertyKey, otherwise false.
951 ///
952 /// This function is the same as performing "propertyKey in object" from JavaScript.
953 ///
954 /// # Safety
955 ///
956 /// - `ctx` must be a valid pointer.
957 /// - `object` must be a valid pointer.
958 /// - `property_key` must be a valid pointer.
959 /// - `exception` must be a valid pointer.
960 #[cfg(feature = "JSBase")]
961 pub fn JSObjectHasPropertyForKey(
962 ctx: JSContextRef,
963 object: JSObjectRef,
964 property_key: JSValueRef,
965 exception: *mut JSValueRef,
966 ) -> bool;
967}
968
969extern "C-unwind" {
970 /// Gets a property from an object using a JSValueRef as the property key.
971 ///
972 /// Parameter `ctx`: The execution context to use.
973 ///
974 /// Parameter `object`: The JSObject whose property you want to get.
975 ///
976 /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
977 ///
978 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
979 ///
980 /// Returns: The property's value if object has the property key, otherwise the undefined value.
981 ///
982 /// This function is the same as performing "object[propertyKey]" from JavaScript.
983 ///
984 /// # Safety
985 ///
986 /// - `ctx` must be a valid pointer.
987 /// - `object` must be a valid pointer.
988 /// - `property_key` must be a valid pointer.
989 /// - `exception` must be a valid pointer.
990 #[cfg(feature = "JSBase")]
991 pub fn JSObjectGetPropertyForKey(
992 ctx: JSContextRef,
993 object: JSObjectRef,
994 property_key: JSValueRef,
995 exception: *mut JSValueRef,
996 ) -> JSValueRef;
997}
998
999extern "C-unwind" {
1000 /// Sets a property on an object using a JSValueRef as the property key.
1001 ///
1002 /// Parameter `ctx`: The execution context to use.
1003 ///
1004 /// Parameter `object`: The JSObject whose property you want to set.
1005 ///
1006 /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
1007 ///
1008 /// Parameter `value`: A JSValueRef to use as the property's value.
1009 ///
1010 /// Parameter `attributes`: A logically ORed set of JSPropertyAttributes to give to the property.
1011 ///
1012 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
1013 ///
1014 /// This function is the same as performing "object[propertyKey] = value" from JavaScript.
1015 ///
1016 /// # Safety
1017 ///
1018 /// - `ctx` must be a valid pointer.
1019 /// - `object` must be a valid pointer.
1020 /// - `property_key` must be a valid pointer.
1021 /// - `value` must be a valid pointer.
1022 /// - `exception` must be a valid pointer.
1023 #[cfg(feature = "JSBase")]
1024 pub fn JSObjectSetPropertyForKey(
1025 ctx: JSContextRef,
1026 object: JSObjectRef,
1027 property_key: JSValueRef,
1028 value: JSValueRef,
1029 attributes: JSPropertyAttributes,
1030 exception: *mut JSValueRef,
1031 );
1032}
1033
1034extern "C-unwind" {
1035 /// Deletes a property from an object using a JSValueRef as the property key.
1036 ///
1037 /// Parameter `ctx`: The execution context to use.
1038 ///
1039 /// Parameter `object`: The JSObject whose property you want to delete.
1040 ///
1041 /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
1042 ///
1043 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
1044 ///
1045 /// Returns: true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
1046 ///
1047 /// This function is the same as performing "delete object[propertyKey]" from JavaScript.
1048 ///
1049 /// # Safety
1050 ///
1051 /// - `ctx` must be a valid pointer.
1052 /// - `object` must be a valid pointer.
1053 /// - `property_key` must be a valid pointer.
1054 /// - `exception` must be a valid pointer.
1055 #[cfg(feature = "JSBase")]
1056 pub fn JSObjectDeletePropertyForKey(
1057 ctx: JSContextRef,
1058 object: JSObjectRef,
1059 property_key: JSValueRef,
1060 exception: *mut JSValueRef,
1061 ) -> bool;
1062}
1063
1064extern "C-unwind" {
1065 /// Gets a property from an object by numeric index.
1066 ///
1067 /// Parameter `ctx`: The execution context to use.
1068 ///
1069 /// Parameter `object`: The JSObject whose property you want to get.
1070 ///
1071 /// Parameter `propertyIndex`: An integer value that is the property's name.
1072 ///
1073 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
1074 ///
1075 /// Returns: The property's value if object has the property, otherwise the undefined value.
1076 ///
1077 /// Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
1078 ///
1079 /// # Safety
1080 ///
1081 /// - `ctx` must be a valid pointer.
1082 /// - `object` must be a valid pointer.
1083 /// - `exception` must be a valid pointer.
1084 #[cfg(feature = "JSBase")]
1085 pub fn JSObjectGetPropertyAtIndex(
1086 ctx: JSContextRef,
1087 object: JSObjectRef,
1088 property_index: c_uint,
1089 exception: *mut JSValueRef,
1090 ) -> JSValueRef;
1091}
1092
1093extern "C-unwind" {
1094 /// Sets a property on an object by numeric index.
1095 ///
1096 /// Parameter `ctx`: The execution context to use.
1097 ///
1098 /// Parameter `object`: The JSObject whose property you want to set.
1099 ///
1100 /// Parameter `propertyIndex`: The property's name as a number.
1101 ///
1102 /// Parameter `value`: A JSValue to use as the property's value.
1103 ///
1104 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
1105 ///
1106 /// Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
1107 ///
1108 /// # Safety
1109 ///
1110 /// - `ctx` must be a valid pointer.
1111 /// - `object` must be a valid pointer.
1112 /// - `value` must be a valid pointer.
1113 /// - `exception` must be a valid pointer.
1114 #[cfg(feature = "JSBase")]
1115 pub fn JSObjectSetPropertyAtIndex(
1116 ctx: JSContextRef,
1117 object: JSObjectRef,
1118 property_index: c_uint,
1119 value: JSValueRef,
1120 exception: *mut JSValueRef,
1121 );
1122}
1123
1124extern "C-unwind" {
1125 /// Gets an object's private data.
1126 ///
1127 /// Parameter `object`: A JSObject whose private data you want to get.
1128 ///
1129 /// Returns: A void* that is the object's private data, if the object has private data, otherwise NULL.
1130 ///
1131 /// # Safety
1132 ///
1133 /// `object` must be a valid pointer.
1134 #[cfg(feature = "JSBase")]
1135 pub fn JSObjectGetPrivate(object: JSObjectRef) -> *mut c_void;
1136}
1137
1138extern "C-unwind" {
1139 /// Sets a pointer to private data on an object.
1140 ///
1141 /// Parameter `object`: The JSObject whose private data you want to set.
1142 ///
1143 /// Parameter `data`: A void* to set as the object's private data.
1144 ///
1145 /// Returns: true if object can store private data, otherwise false.
1146 ///
1147 /// The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
1148 ///
1149 /// # Safety
1150 ///
1151 /// - `object` must be a valid pointer.
1152 /// - `data` must be a valid pointer.
1153 #[cfg(feature = "JSBase")]
1154 pub fn JSObjectSetPrivate(object: JSObjectRef, data: *mut c_void) -> bool;
1155}
1156
1157extern "C-unwind" {
1158 /// Tests whether an object can be called as a function.
1159 ///
1160 /// Parameter `ctx`: The execution context to use.
1161 ///
1162 /// Parameter `object`: The JSObject to test.
1163 ///
1164 /// Returns: true if the object can be called as a function, otherwise false.
1165 ///
1166 /// # Safety
1167 ///
1168 /// - `ctx` must be a valid pointer.
1169 /// - `object` must be a valid pointer.
1170 #[cfg(feature = "JSBase")]
1171 pub fn JSObjectIsFunction(ctx: JSContextRef, object: JSObjectRef) -> bool;
1172}
1173
1174extern "C-unwind" {
1175 /// Calls an object as a function.
1176 ///
1177 /// Parameter `ctx`: The execution context to use.
1178 ///
1179 /// Parameter `object`: The JSObject to call as a function.
1180 ///
1181 /// Parameter `thisObject`: The object to use as "this," or NULL to use the global object as "this."
1182 ///
1183 /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
1184 ///
1185 /// Parameter `arguments`: A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0.
1186 ///
1187 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
1188 ///
1189 /// Returns: The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
1190 ///
1191 /// # Safety
1192 ///
1193 /// - `ctx` must be a valid pointer.
1194 /// - `object` must be a valid pointer.
1195 /// - `this_object` must be a valid pointer.
1196 /// - `arguments` must be a valid pointer.
1197 /// - `exception` must be a valid pointer.
1198 #[cfg(feature = "JSBase")]
1199 pub fn JSObjectCallAsFunction(
1200 ctx: JSContextRef,
1201 object: JSObjectRef,
1202 this_object: JSObjectRef,
1203 argument_count: usize,
1204 arguments: *mut JSValueRef,
1205 exception: *mut JSValueRef,
1206 ) -> JSValueRef;
1207}
1208
1209extern "C-unwind" {
1210 /// Tests whether an object can be called as a constructor.
1211 ///
1212 /// Parameter `ctx`: The execution context to use.
1213 ///
1214 /// Parameter `object`: The JSObject to test.
1215 ///
1216 /// Returns: true if the object can be called as a constructor, otherwise false.
1217 ///
1218 /// # Safety
1219 ///
1220 /// - `ctx` must be a valid pointer.
1221 /// - `object` must be a valid pointer.
1222 #[cfg(feature = "JSBase")]
1223 pub fn JSObjectIsConstructor(ctx: JSContextRef, object: JSObjectRef) -> bool;
1224}
1225
1226extern "C-unwind" {
1227 /// Calls an object as a constructor.
1228 ///
1229 /// Parameter `ctx`: The execution context to use.
1230 ///
1231 /// Parameter `object`: The JSObject to call as a constructor.
1232 ///
1233 /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
1234 ///
1235 /// Parameter `arguments`: A JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0.
1236 ///
1237 /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
1238 ///
1239 /// Returns: The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
1240 ///
1241 /// # Safety
1242 ///
1243 /// - `ctx` must be a valid pointer.
1244 /// - `object` must be a valid pointer.
1245 /// - `arguments` must be a valid pointer.
1246 /// - `exception` must be a valid pointer.
1247 #[cfg(feature = "JSBase")]
1248 pub fn JSObjectCallAsConstructor(
1249 ctx: JSContextRef,
1250 object: JSObjectRef,
1251 argument_count: usize,
1252 arguments: *mut JSValueRef,
1253 exception: *mut JSValueRef,
1254 ) -> JSObjectRef;
1255}
1256
1257extern "C-unwind" {
1258 /// Gets the names of an object's enumerable properties.
1259 ///
1260 /// Parameter `ctx`: The execution context to use.
1261 ///
1262 /// Parameter `object`: The object whose property names you want to get.
1263 ///
1264 /// Returns: A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
1265 ///
1266 /// # Safety
1267 ///
1268 /// - `ctx` must be a valid pointer.
1269 /// - `object` must be a valid pointer.
1270 #[cfg(feature = "JSBase")]
1271 pub fn JSObjectCopyPropertyNames(
1272 ctx: JSContextRef,
1273 object: JSObjectRef,
1274 ) -> JSPropertyNameArrayRef;
1275}
1276
1277extern "C-unwind" {
1278 /// Retains a JavaScript property name array.
1279 ///
1280 /// Parameter `array`: The JSPropertyNameArray to retain.
1281 ///
1282 /// Returns: A JSPropertyNameArray that is the same as array.
1283 ///
1284 /// # Safety
1285 ///
1286 /// `array` must be a valid pointer.
1287 #[cfg(feature = "JSBase")]
1288 pub fn JSPropertyNameArrayRetain(array: JSPropertyNameArrayRef) -> JSPropertyNameArrayRef;
1289}
1290
1291extern "C-unwind" {
1292 /// Releases a JavaScript property name array.
1293 ///
1294 /// Parameter `array`: The JSPropetyNameArray to release.
1295 ///
1296 /// # Safety
1297 ///
1298 /// `array` must be a valid pointer.
1299 #[cfg(feature = "JSBase")]
1300 pub fn JSPropertyNameArrayRelease(array: JSPropertyNameArrayRef);
1301}
1302
1303extern "C-unwind" {
1304 /// Gets a count of the number of items in a JavaScript property name array.
1305 ///
1306 /// Parameter `array`: The array from which to retrieve the count.
1307 ///
1308 /// Returns: An integer count of the number of names in array.
1309 ///
1310 /// # Safety
1311 ///
1312 /// `array` must be a valid pointer.
1313 #[cfg(feature = "JSBase")]
1314 pub fn JSPropertyNameArrayGetCount(array: JSPropertyNameArrayRef) -> usize;
1315}
1316
1317extern "C-unwind" {
1318 /// Gets a property name at a given index in a JavaScript property name array.
1319 ///
1320 /// Parameter `array`: The array from which to retrieve the property name.
1321 ///
1322 /// Parameter `index`: The index of the property name to retrieve.
1323 ///
1324 /// Returns: A JSStringRef containing the property name.
1325 ///
1326 /// # Safety
1327 ///
1328 /// `array` must be a valid pointer.
1329 #[cfg(feature = "JSBase")]
1330 pub fn JSPropertyNameArrayGetNameAtIndex(
1331 array: JSPropertyNameArrayRef,
1332 index: usize,
1333 ) -> JSStringRef;
1334}
1335
1336extern "C-unwind" {
1337 /// Adds a property name to a JavaScript property name accumulator.
1338 ///
1339 /// Parameter `accumulator`: The accumulator object to which to add the property name.
1340 ///
1341 /// Parameter `propertyName`: The property name to add.
1342 ///
1343 /// # Safety
1344 ///
1345 /// - `accumulator` must be a valid pointer.
1346 /// - `property_name` must be a valid pointer.
1347 #[cfg(feature = "JSBase")]
1348 pub fn JSPropertyNameAccumulatorAddName(
1349 accumulator: JSPropertyNameAccumulatorRef,
1350 property_name: JSStringRef,
1351 );
1352}