javascriptcore_sys/
lib.rs

1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7//! This crate provides raw bindings for the JavaScriptCore public
8//! API. It is a pretty direct mapping of the underlying C API
9//! provided by JavaScriptCore.
10
11#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
12#![warn(clippy::doc_markdown, missing_docs)]
13
14use std::ptr;
15
16/// A group that associates JavaScript contexts with one another.
17/// Contexts in the same group may share and exchange JavaScript objects.
18#[doc(hidden)]
19#[repr(C)]
20#[derive(Debug, Copy, Clone)]
21pub struct OpaqueJSContextGroup([u8; 0]);
22
23/// A group that associates JavaScript contexts with one another.
24/// Contexts in the same group may share and exchange JavaScript objects.
25pub type JSContextGroupRef = *const OpaqueJSContextGroup;
26
27/// A JavaScript execution context. Holds the global object and
28/// other execution state.
29#[doc(hidden)]
30#[repr(C)]
31#[derive(Debug, Copy, Clone)]
32pub struct OpaqueJSContext([u8; 0]);
33
34/// A JavaScript execution context. Holds the global object and
35/// other execution state.
36pub type JSContextRef = *const OpaqueJSContext;
37
38/// A global JavaScript execution context.
39/// A [`JSGlobalContextRef`] is a [`JSContextRef`].
40pub type JSGlobalContextRef = *mut OpaqueJSContext;
41
42/// A UTF16 character buffer. The fundamental string representation
43/// in JavaScript.
44#[doc(hidden)]
45#[repr(C)]
46#[derive(Debug, Copy, Clone)]
47pub struct OpaqueJSString([u8; 0]);
48
49/// A UTF16 character buffer. The fundamental string representation
50/// in JavaScript.
51pub type JSStringRef = *mut OpaqueJSString;
52
53/// A JavaScript class.
54/// Used with [`JSObjectMake`] to construct objects with custom behavior.
55#[doc(hidden)]
56#[repr(C)]
57#[derive(Debug, Copy, Clone)]
58pub struct OpaqueJSClass([u8; 0]);
59
60/// A JavaScript class.
61/// Used with [`JSObjectMake`] to construct objects with custom behavior.
62pub type JSClassRef = *mut OpaqueJSClass;
63
64/// An array of JavaScript property names.
65#[doc(hidden)]
66#[repr(C)]
67#[derive(Debug, Copy, Clone)]
68pub struct OpaqueJSPropertyNameArray([u8; 0]);
69
70/// An array of JavaScript property names.
71///
72/// Values of this type are obtained via [`JSObjectCopyPropertyNames`].
73///
74/// Operations:
75///
76/// * [`JSPropertyNameArrayGetCount`]
77/// * [`JSPropertyNameArrayGetNameAtIndex`]
78/// * [`JSPropertyNameArrayRelease`]
79/// * [`JSPropertyNameArrayRetain`]
80pub type JSPropertyNameArrayRef = *mut OpaqueJSPropertyNameArray;
81
82/// An ordered set used to collect the names of
83/// a JavaScript object's properties.
84#[doc(hidden)]
85#[repr(C)]
86#[derive(Debug, Copy, Clone)]
87pub struct OpaqueJSPropertyNameAccumulator([u8; 0]);
88
89/// An ordered set used to collect the names of
90/// a JavaScript object's properties.
91///
92/// Values of this type are passed to the [`getPropertyNames` callback].
93/// Names are added to the accumulator using [`JSPropertyNameAccumulatorAddName`].
94///
95/// [`getPropertyNames` callback]: crate::JSObjectGetPropertyNamesCallback
96pub type JSPropertyNameAccumulatorRef = *mut OpaqueJSPropertyNameAccumulator;
97
98/// A function used to deallocate bytes passed to a Typed Array constructor.
99/// The function should take two arguments. The first is a pointer to
100/// the bytes that were originally passed to the Typed Array constructor.
101/// The second is a pointer to additional information desired at the time
102/// the bytes are to be freed.
103pub type JSTypedArrayBytesDeallocator = ::std::option::Option<
104    unsafe extern "C" fn(
105        bytes: *mut ::std::os::raw::c_void,
106        deallocatorContext: *mut ::std::os::raw::c_void,
107    ),
108>;
109
110/// A JavaScript value.
111/// The base type for all JavaScript values, and polymorphic functions on them.
112#[doc(hidden)]
113#[repr(C)]
114#[derive(Debug, Copy, Clone)]
115pub struct OpaqueJSValue([u8; 0]);
116
117/// A JavaScript value.
118/// The base type for all JavaScript values, and polymorphic functions on them.
119pub type JSValueRef = *const OpaqueJSValue;
120
121/// A JavaScript object. A [`JSObjectRef`] is a [`JSValueRef`].
122pub type JSObjectRef = *mut OpaqueJSValue;
123
124extern "C" {
125    /// Evaluates a string of JavaScript.
126    ///
127    /// * `ctx`: The execution context to use.
128    /// * `script`: A [`JSStringRef`] containing the script to evaluate.
129    /// * `thisObject`: The object to use as `this`, or `NULL` to
130    ///   use the global object as `this`.
131    /// * `sourceURL`: A [`JSStringRef`] containing a URL for the script's
132    ///   source file. This is used by debuggers and when reporting
133    ///   exceptions. Pass `NULL` if you do not care to include source
134    ///   file information.
135    /// * `startingLineNumber`: An integer value specifying the script's
136    ///   starting line number in the file located at `sourceURL`. This
137    ///   is only used when reporting exceptions. The value is one-based,
138    ///   so the first line is line `1` and invalid values are clamped
139    ///   to `1`.
140    /// * `exception`: A pointer to a [`JSValueRef`] in which to store an
141    ///   exception, if any. Pass `NULL` if you do not care to store an
142    ///   exception.
143    ///
144    /// The [`JSValueRef`] that results from evaluating script, or `NULL` if an exception is thrown.
145    ///
146    /// # See also
147    ///
148    /// * [`JSCheckScriptSyntax()`]
149    pub fn JSEvaluateScript(
150        ctx: JSContextRef,
151        script: JSStringRef,
152        thisObject: JSObjectRef,
153        sourceURL: JSStringRef,
154        startingLineNumber: ::std::os::raw::c_int,
155        exception: *mut JSValueRef,
156    ) -> JSValueRef;
157
158    /// Checks for syntax errors in a string of JavaScript.
159    ///
160    /// * `ctx`: The execution context to use.
161    /// * `script`: A [`JSStringRef`] containing the script to check for
162    ///   syntax errors.
163    /// * `sourceURL`: A [`JSStringRef`] containing a URL for the script's
164    ///   source file. This is only used when reporting exceptions.
165    ///   Pass `NULL` if you do not care to include source file
166    ///   information in exceptions.
167    /// * `startingLineNumber`: An integer value specifying the script's
168    ///   starting line number in the file located at `sourceURL`. This
169    ///   is only used when reporting exceptions. The value is one-based,
170    ///   so the first line is line `1` and invalid values are clamped
171    ///   to `1`.
172    /// * `exception`: A pointer to a [`JSValueRef`] in which to store a
173    ///   syntax error exception, if any. Pass `NULL` if you do not care
174    ///   to store a syntax error exception.
175    ///
176    /// Returns `true` if the script is syntactically correct, otherwise `false`.
177    ///
178    /// # See also
179    ///
180    /// * [`JSEvaluateScript()`]
181    pub fn JSCheckScriptSyntax(
182        ctx: JSContextRef,
183        script: JSStringRef,
184        sourceURL: JSStringRef,
185        startingLineNumber: ::std::os::raw::c_int,
186        exception: *mut JSValueRef,
187    ) -> bool;
188
189    /// Performs a JavaScript garbage collection.
190    ///
191    /// JavaScript values that are on the machine stack, in a register,
192    /// protected by [`JSValueProtect`], set as the global object of an
193    /// execution context, or reachable from any such value will not
194    /// be collected.
195    ///
196    /// During JavaScript execution, you are not required to call this
197    /// function; the JavaScript engine will garbage collect as needed.
198    /// JavaScript values created within a context group are automatically
199    /// destroyed when the last reference to the context group is released.
200    ///
201    /// * `ctx`: The execution context to use.
202    ///
203    /// # See also
204    ///
205    /// * [`JSValueProtect()`]
206    /// * [`JSValueUnprotect()`]
207    pub fn JSGarbageCollect(ctx: JSContextRef);
208}
209
210/// A constant identifying the type of a [`JSValueRef`].
211#[repr(u32)]
212#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
213pub enum JSType {
214    /// The unique `undefined` value.
215    Undefined = 0,
216    /// The unique `null` value.
217    Null = 1,
218    /// A primitive boolean value, one of `true` or `false`.
219    Boolean = 2,
220    /// A primitive number value.
221    Number = 3,
222    /// A primitive string value.
223    String = 4,
224    /// An object value (meaning that this [`JSValueRef`] is a [`JSObjectRef`]).
225    Object = 5,
226    /// A primitive symbol value.
227    Symbol = 6,
228}
229
230/// A constant identifying the Typed Array type of a [`JSObjectRef`].
231#[repr(u32)]
232#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
233pub enum JSTypedArrayType {
234    /// `Int8Array`
235    Int8Array = 0,
236    /// `Int16Array`
237    Int16Array = 1,
238    /// `Int32Array`
239    Int32Array = 2,
240    /// `Uint8Array`
241    Uint8Array = 3,
242    /// `Uint8ClampedArray`
243    Uint8ClampedArray = 4,
244    /// `Uint16Array`
245    Uint16Array = 5,
246    /// `Uint32Array`
247    Uint32Array = 6,
248    /// `Float32Array`
249    Float32Array = 7,
250    /// `Float64Array`
251    Float64Array = 8,
252    /// `ArrayBuffer`
253    ArrayBuffer = 9,
254    /// Not a Typed Array
255    None = 10,
256    /// `BigInt64Array`
257    BigInt64Array = 11,
258    /// `BigUint64Array`
259    BigUint64Array = 12,
260}
261
262extern "C" {
263    /// Returns a JavaScript value's type.
264    ///
265    /// * `ctx`: The execution context to use.
266    /// * `value`: The [`JSValueRef`] whose type you want to obtain.
267    ///
268    /// Returns a value of type [`JSType`] that identifies `value`'s type.
269    pub fn JSValueGetType(ctx: JSContextRef, arg1: JSValueRef) -> JSType;
270
271    /// Tests whether a JavaScript value's type is the `undefined` type.
272    ///
273    /// * `ctx`: The execution context to use.
274    /// * `value`: The [`JSValueRef`] to test.
275    ///
276    /// Returns `true` if `value`'s type is the `undefined` type, otherwise `false`.
277    pub fn JSValueIsUndefined(ctx: JSContextRef, value: JSValueRef) -> bool;
278
279    /// Tests whether a JavaScript value's type is the `null` type.
280    ///
281    /// * `ctx`: The execution context to use.
282    /// * `value`: The [`JSValueRef`] to test.
283    ///
284    /// Returns `true` if `value`'s type is the `null` type, otherwise `false`.
285    pub fn JSValueIsNull(ctx: JSContextRef, value: JSValueRef) -> bool;
286
287    /// Tests whether a JavaScript value's type is the `boolean` type.
288    ///
289    /// * `ctx`: The execution context to use.
290    /// * `value`: The [`JSValueRef`] to test.
291    ///
292    /// Returns `true` if `value`'s type is the `boolean` type, otherwise `false`.
293    pub fn JSValueIsBoolean(ctx: JSContextRef, value: JSValueRef) -> bool;
294
295    /// Tests whether a JavaScript value's type is the `number` type.
296    ///
297    /// * `ctx`: The execution context to use.
298    /// * `value`: The [`JSValueRef`] to test.
299    ///
300    /// Returns `true` if `value`'s type is the `number` type, otherwise `false`.
301    pub fn JSValueIsNumber(ctx: JSContextRef, value: JSValueRef) -> bool;
302
303    /// Tests whether a JavaScript value's type is the `string` type.
304    ///
305    /// * `ctx`: The execution context to use.
306    /// * `value`: The [`JSValueRef`] to test.
307    ///
308    /// Returns `true` if `value`'s type is the `string` type, otherwise `false`.
309    pub fn JSValueIsString(ctx: JSContextRef, value: JSValueRef) -> bool;
310
311    /// Tests whether a JavaScript value's type is the `symbol` type.
312    ///
313    /// * `ctx`: The execution context to use.
314    /// * `value`: The [`JSValueRef`] to test.
315    ///
316    /// Returns `true` if `value`'s type is the `symbol` type, otherwise `false`.
317    pub fn JSValueIsSymbol(ctx: JSContextRef, value: JSValueRef) -> bool;
318
319    /// Tests whether a JavaScript value's type is the `object` type.
320    ///
321    /// * `ctx`: The execution context to use.
322    /// * `value`: The [`JSValueRef`] to test.
323    ///
324    /// Returns `true` if `value`'s type is the `object` type, otherwise `false`.
325    pub fn JSValueIsObject(ctx: JSContextRef, value: JSValueRef) -> bool;
326
327    /// Tests whether a JavaScript value is an `object` with a given class in its class chain.
328    ///
329    /// * `ctx`: The execution context to use.
330    /// * `value`: The [`JSValueRef`] to test.
331    /// * `jsClass`: The [`JSClassRef`] to test against.
332    ///
333    /// Returns `true` if `value` is an `object` and has `jsClass` in its
334    /// class chain, otherwise `false`.
335    pub fn JSValueIsObjectOfClass(
336        ctx: JSContextRef,
337        value: JSValueRef,
338        jsClass: JSClassRef,
339    ) -> bool;
340
341    /// Tests whether a JavaScript value is an `array`.
342    ///
343    /// * `ctx`: The execution context to use.
344    /// * `value`: The [`JSValueRef`] to test.
345    ///
346    /// Returns `true` if `value` is an `array`, otherwise `false`.
347    pub fn JSValueIsArray(ctx: JSContextRef, value: JSValueRef) -> bool;
348
349    /// Tests whether a JavaScript value is a `date`.
350    ///
351    /// * `ctx`: The execution context to use.
352    /// * `value`: The [`JSValueRef`] to test.
353    ///
354    /// Returns `true` if `value` is a `date`, otherwise `false`.
355    pub fn JSValueIsDate(ctx: JSContextRef, value: JSValueRef) -> bool;
356
357    /// Returns a JavaScript value's Typed Array type.
358    ///
359    /// * `ctx`: The execution context to use.
360    /// * `value`: The [`JSValueRef`] whose Typed Array type to return.
361    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
362    ///   an exception, if any. Pass `NULL` if you do not care to
363    ///   store an exception.
364    ///
365    /// Returns a value of type [`JSTypedArrayType`] that identifies
366    /// value's Typed Array type, or `JSTypedArrayType::None` if the
367    /// value is not a Typed Array object.
368    pub fn JSValueGetTypedArrayType(
369        ctx: JSContextRef,
370        value: JSValueRef,
371        exception: *mut JSValueRef,
372    ) -> JSTypedArrayType;
373
374    /// Tests whether two JavaScript values are equal, as compared by the JS `==` operator.
375    ///
376    /// * `ctx`: The execution context to use.
377    /// * `a`: The first value to test.
378    /// * `b`: The second value to test.
379    /// * `exception`: A pointer to a [`JSValueRef`] in which to
380    ///   store an exception, if any. Pass `NULL` if you do
381    ///   not care to store an exception.
382    ///
383    /// Returns `true` if the two values are equal, `false` if
384    /// they are not equal or an exception is thrown.
385    pub fn JSValueIsEqual(
386        ctx: JSContextRef,
387        a: JSValueRef,
388        b: JSValueRef,
389        exception: *mut JSValueRef,
390    ) -> bool;
391
392    /// Tests whether two JavaScript values are strict equal, as compared
393    /// by the JS `===` operator.
394    ///
395    /// * `ctx`: The execution context to use.
396    /// * `a`: The first value to test.
397    /// * `b`: The second value to test.
398    ///
399    /// Returns `true` if the two values are strict equal, otherwise `false`.
400    pub fn JSValueIsStrictEqual(ctx: JSContextRef, a: JSValueRef, b: JSValueRef) -> bool;
401
402    /// Tests whether a JavaScript value is an object constructed by a
403    /// given constructor, as compared by the JS `instanceof` operator.
404    ///
405    /// * `ctx`: The execution context to use.
406    /// * `value`: The [`JSValueRef`] to test.
407    /// * `constructor`: The constructor to test against.
408    /// * `exception`: A pointer to a [`JSValueRef`] in which to
409    ///   store an exception, if any. Pass `NULL` if you do
410    ///   not care to store an exception.
411    ///
412    /// Returns `true` if value is an object constructed by constructor,
413    /// as compared by the JS `instanceof` operator, otherwise `false`.
414    pub fn JSValueIsInstanceOfConstructor(
415        ctx: JSContextRef,
416        value: JSValueRef,
417        constructor: JSObjectRef,
418        exception: *mut JSValueRef,
419    ) -> bool;
420
421    /// Creates a JavaScript value of the `undefined` type.
422    ///
423    /// * `ctx`: The execution context to use.
424    ///
425    /// Returns the unique `undefined` value.
426    pub fn JSValueMakeUndefined(ctx: JSContextRef) -> JSValueRef;
427
428    /// Creates a JavaScript value of the `null` type.
429    ///
430    /// * `ctx`: The execution context to use.
431    ///
432    /// Returns the unique `null` value.
433    pub fn JSValueMakeNull(ctx: JSContextRef) -> JSValueRef;
434
435    /// Creates a JavaScript value of the `boolean` type.
436    ///
437    /// * `ctx`: The execution context to use.
438    /// * `boolean`: The `bool` to assign to the newly created [`JSValueRef`].
439    ///
440    /// Returns a [`JSValueRef`] of the `boolean` type, representing the value of `boolean`.
441    pub fn JSValueMakeBoolean(ctx: JSContextRef, boolean: bool) -> JSValueRef;
442
443    /// Creates a JavaScript value of the `number` type.
444    ///
445    /// * `ctx`: The execution context to use.
446    /// * `number`: The `f64` to assign to the newly created [`JSValueRef`].
447    ///
448    /// Returns a [`JSValueRef`] of the `number` type, representing the value of `number`.
449    pub fn JSValueMakeNumber(ctx: JSContextRef, number: f64) -> JSValueRef;
450
451    /// Creates a JavaScript value of the string type.
452    ///
453    /// * `ctx`: The execution context to use.
454    /// * `string`: The [`JSStringRef`] to assign to the newly created
455    ///   [`JSValueRef`]. The newly created [`JSValueRef`] retains `string`, and
456    ///   releases it upon garbage collection.
457    ///
458    /// Returns a [`JSValueRef`] of the `string` type, representing the value of `string`.
459    pub fn JSValueMakeString(ctx: JSContextRef, string: JSStringRef) -> JSValueRef;
460
461    /// Creates a JavaScript value of the symbol type.
462    ///
463    /// * `ctx`: The execution context to use.
464    /// * `description`: The [`JSStringRef`] to assign to the newly created
465    ///   [`JSValueRef`].
466    ///
467    /// Returns a [`JSValueRef`] of the `symbol` type, whose description matches the one provided.
468    pub fn JSValueMakeSymbol(ctx: JSContextRef, description: JSStringRef) -> JSValueRef;
469
470    /// Creates a JavaScript value from a JSON formatted string.
471    ///
472    /// * `ctx`: The execution context to use.
473    /// * `string`: The [`JSStringRef`] containing the JSON string to be parsed.
474    ///
475    /// Returns a [`JSValueRef`] containing the parsed value, or `NULL` if the input is invalid.
476    pub fn JSValueMakeFromJSONString(ctx: JSContextRef, string: JSStringRef) -> JSValueRef;
477
478    /// Creates a JavaScript string containing the JSON serialized representation of a JS value.
479    ///
480    /// * `ctx`: The execution context to use.
481    /// * `value`: The value to serialize.
482    /// * `indent`: The number of spaces to indent when nesting.
483    ///   If `0`, the resulting JSON will not contains newlines.
484    ///   The size of the indent is clamped to `10` spaces.
485    /// * `exception`: A pointer to a [`JSValueRef`] in which to
486    ///   store an exception, if any. Pass `NULL` if you do not
487    ///   care to store an exception.
488    ///
489    /// Returns a [`JSStringRef`] with the result of serialization, or `NULL` if an exception is thrown.
490    pub fn JSValueCreateJSONString(
491        ctx: JSContextRef,
492        value: JSValueRef,
493        indent: ::std::os::raw::c_uint,
494        exception: *mut JSValueRef,
495    ) -> JSStringRef;
496
497    /// Converts a JavaScript value to boolean and returns the resulting boolean.
498    ///
499    /// * `ctx`: The execution context to use.
500    /// * `value`: The [`JSValueRef`] to convert.
501    ///
502    /// Returns the boolean result of conversion.
503    pub fn JSValueToBoolean(ctx: JSContextRef, value: JSValueRef) -> bool;
504
505    /// Converts a JavaScript value to number and returns the resulting number.
506    ///
507    /// * `ctx`: The execution context to use.
508    /// * `value`: The [`JSValueRef`] to convert.
509    /// * `exception`: A pointer to a [`JSValueRef`] in which to store an
510    ///   exception, if any. Pass `NULL` if you do not care to store an
511    ///   exception.
512    ///
513    /// Returns the numeric result of conversion, or `NaN` if an exception is thrown.
514    pub fn JSValueToNumber(ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef)
515        -> f64;
516
517    /// Converts a JavaScript value to string and copies the result into a JavaScript string.
518    ///
519    /// * `ctx`: The execution context to use.
520    /// * `value`: The [`JSValueRef`] to convert.
521    /// * `exception`:  A pointer to a [`JSValueRef`] in which to store an
522    ///   exception, if any. Pass `NULL` if you do not care to store an
523    ///   exception.
524    ///
525    /// Returns a [`JSStringRef`] with the result of conversion, or `NULL`
526    /// if an exception is thrown. Ownership follows the Create Rule.
527    pub fn JSValueToStringCopy(
528        ctx: JSContextRef,
529        value: JSValueRef,
530        exception: *mut JSValueRef,
531    ) -> JSStringRef;
532
533    /// Converts a JavaScript value to object and returns the resulting object.
534    ///
535    /// * `ctx`: The execution context to use.
536    /// * `value`: The [`JSValueRef`] to convert.
537    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
538    ///   an exception, if any. Pass `NULL` if you do not care to store
539    ///   an exception.
540    ///
541    /// Returns the [`JSObjectRef`] result of conversion, or `NULL` if
542    /// an exception is thrown.
543    pub fn JSValueToObject(
544        ctx: JSContextRef,
545        value: JSValueRef,
546        exception: *mut JSValueRef,
547    ) -> JSObjectRef;
548
549    /// Protects a JavaScript value from garbage collection.
550    ///
551    /// Use this method when you want to store a [`JSValueRef`] in a
552    /// global or on the heap, where the garbage collector will
553    /// not be able to discover your reference to it.
554    ///
555    /// A value may be protected multiple times and must be
556    /// [unprotected] an equal number of times before becoming
557    /// eligible for garbage collection.
558    ///
559    /// * `ctx`: The execution context to use.
560    /// * `value`: The [`JSValueRef`] to protect.
561    ///
562    /// # See also
563    ///
564    /// * [`JSGarbageCollect()`]
565    /// * [`JSValueUnprotect()`]
566    ///
567    /// [unprotected]: crate::JSValueUnprotect
568    pub fn JSValueProtect(ctx: JSContextRef, value: JSValueRef);
569
570    /// Unprotects a JavaScript value from garbage collection.
571    ///
572    /// A value may be [protected] multiple times and must be unprotected
573    /// an equal number of times before becoming eligible for garbage
574    /// collection.
575    ///
576    /// * `ctx`: The execution context to use.
577    /// * `value`: The [`JSValueRef`] to unprotect.
578    ///
579    /// # See also
580    ///
581    /// * [`JSGarbageCollect()`]
582    /// * [`JSValueProtect()`]
583    ///
584    /// [protected]: crate::JSValueProtect
585    pub fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef);
586}
587
588/// Specifies that a property has no special attributes.
589pub const kJSPropertyAttributeNone: ::std::os::raw::c_uint = 0;
590/// Specifies that a property is read-only.
591pub const kJSPropertyAttributeReadOnly: ::std::os::raw::c_uint = 2;
592/// Specifies that a property should not be enumerated by `JSPropertyEnumerators` and JavaScript `for...in` loops.
593pub const kJSPropertyAttributeDontEnum: ::std::os::raw::c_uint = 4;
594/// Specifies that the delete operation should fail on a property.
595pub const kJSPropertyAttributeDontDelete: ::std::os::raw::c_uint = 8;
596
597/// A set of `JSPropertyAttribute`s.
598///
599/// Combine multiple attributes by logically ORing them together.
600pub type JSPropertyAttributes = ::std::os::raw::c_uint;
601
602/// Specifies that a class has no special attributes.
603pub const kJSClassAttributeNone: ::std::os::raw::c_uint = 0;
604/// Specifies that a class should not automatically generate a shared
605/// prototype for its instance objects. Use
606/// `kJSClassAttributeNoAutomaticPrototype` in combination with
607/// [`JSObjectSetPrototype`] to manage prototypes manually.
608pub const kJSClassAttributeNoAutomaticPrototype: ::std::os::raw::c_uint = 2;
609
610/// A set of `JSClassAttribute`s.
611///
612/// Combine multiple attributes by logically ORing them together.
613pub type JSClassAttributes = ::std::os::raw::c_uint;
614
615/// The callback invoked when an object is first created.
616///
617/// * `ctx`: The execution context to use.
618/// * `object`: The [`JSObjectRef`] being created.
619///
620/// If you named your function `Initialize`, you would declare it like this:
621///
622/// ```ignore
623/// void
624/// Initialize(JSContextRef ctx, JSObjectRef object);
625/// ```
626///
627/// Unlike the other object callbacks, the initialize callback is
628/// called on the least derived class (the parent class) first,
629/// and the most derived class last.
630pub type JSObjectInitializeCallback =
631    ::std::option::Option<unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef)>;
632
633/// The callback invoked when an object is finalized (prepared
634/// for garbage collection). An object may be finalized on any thread.
635///
636/// * `object`: The [`JSObjectRef`] being finalized.
637///
638/// If you named your function `Finalize`, you would declare it like this:
639///
640/// ```ignore
641/// void
642/// Finalize(JSObjectRef object);
643/// ```
644///
645/// The finalize callback is called on the most derived class
646/// first, and the least derived class (the parent class) last.
647///
648/// You must not call any function that may cause a garbage
649/// collection or an allocation of a garbage collected object
650/// from within a `JSObjectFinalizeCallback`. This includes
651/// all functions that have a [`JSContextRef`] parameter.
652pub type JSObjectFinalizeCallback =
653    ::std::option::Option<unsafe extern "C" fn(object: JSObjectRef)>;
654
655/// The callback invoked when determining whether an object has a property.
656///
657/// * `ctx`: The execution context to use.
658/// * `object`: The [`JSObjectRef`] to search for the property.
659/// * `propertyName`: A [`JSStringRef`] containing the name of the property look up.
660///
661/// Returns `true` if object has the property, otherwise `false`.
662///
663/// If you named your function `HasProperty`, you would declare it like this:
664///
665/// ```ignore
666/// bool
667/// HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
668/// ```
669///
670/// If this function returns `false`, the `hasProperty` request
671/// forwards to object's statically declared properties, then
672/// its parent class chain (which includes the default object
673/// class), then its prototype chain.
674///
675/// This callback enables optimization in cases where only a
676/// property's existence needs to be known, not its value,
677/// and computing its value would be expensive.
678///
679/// If this callback is `NULL`, the `getProperty` callback will be used
680/// to service `hasProperty` requests.
681///
682/// # See also
683///
684/// * [`JSClassDefinition::getProperty`]
685/// * [`JSClassDefinition::hasProperty`]
686/// * [`JSObjectDeletePropertyCallback`]
687/// * [`JSObjectGetPropertyCallback`]
688/// * [`JSObjectSetPropertyCallback`]
689/// * [`JSObjectHasProperty()`]
690pub type JSObjectHasPropertyCallback = ::std::option::Option<
691    unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef) -> bool,
692>;
693
694/// The callback invoked when getting a property's value.
695///
696/// * `ctx`: The execution context to use.
697/// * `object`: The [`JSObjectRef`] to search for the property.
698/// * `propertyName`: A [`JSStringRef`] containing the name of the property to get.
699/// * `exception`: A pointer to a [`JSValueRef`] in which to return an exception, if any.
700///
701/// Returns the property's value if object has the property, otherwise `NULL`.
702///
703/// If you named your function `GetProperty`, you would declare it like this:
704///
705/// ```ignore
706/// JSValueRef
707/// GetProperty(JSContextRef ctx, JSObjectRef object,
708///             JSStringRef propertyName, JSValueRef* exception);
709/// ```
710///
711/// If this function returns `NULL`, the get request forwards to `object`'s
712/// statically declared properties, then its parent class chain (which
713/// includes the default object class), then its prototype chain.
714///
715/// # See also
716///
717/// * [`JSClassDefinition::getProperty`]
718/// * [`JSObjectDeletePropertyCallback`]
719/// * [`JSObjectHasPropertyCallback`]
720/// * [`JSObjectSetPropertyCallback`]
721/// * [`JSObjectGetProperty()`]
722pub type JSObjectGetPropertyCallback = ::std::option::Option<
723    unsafe extern "C" fn(
724        ctx: JSContextRef,
725        object: JSObjectRef,
726        propertyName: JSStringRef,
727        exception: *mut JSValueRef,
728    ) -> *const OpaqueJSValue,
729>;
730
731/// The callback invoked when setting a property's value.
732///
733/// * `ctx`: The execution context to use.
734/// * `object`: The [`JSObjectRef`] on which to set the property's value.
735/// * `propertyName`: A [`JSStringRef`] containing the name of the property to set.
736/// * `value`: A [`JSValueRef`] to use as the property's value.
737/// * `exception`: A pointer to a [`JSValueRef`] in which to return an exception, if any.
738///
739/// Returns `true` if the property was set, otherwise `false`.
740///
741/// If you named your function `SetProperty`, you would declare it like this:
742///
743/// ```ignore
744/// bool
745/// SetProperty(JSContextRef ctx, JSObjectRef object,
746///             JSStringRef propertyName, JSValueRef value,
747///             JSValueRef* exception);
748/// ```
749///
750/// If this function returns `false`, the set request forwards to
751/// `object`'s statically declared properties, then its parent class
752/// chain (which includes the default object class).
753///
754/// # See also
755///
756/// * [`JSClassDefinition::setProperty`]
757/// * [`JSObjectDeletePropertyCallback`]
758/// * [`JSObjectGetPropertyCallback`]
759/// * [`JSObjectHasPropertyCallback`]
760/// * [`JSObjectSetProperty()`]
761pub type JSObjectSetPropertyCallback = ::std::option::Option<
762    unsafe extern "C" fn(
763        ctx: JSContextRef,
764        object: JSObjectRef,
765        propertyName: JSStringRef,
766        value: JSValueRef,
767        exception: *mut JSValueRef,
768    ) -> bool,
769>;
770
771/// The callback invoked when deleting a property.
772///
773/// * `ctx`: The execution context to use.
774/// * `object`: The [`JSObjectRef`] in which to delete the property.
775/// * `propertyName`: A [`JSStringRef`] containing the name of the property to delete.
776/// * `exception`: A pointer to a [`JSValueRef`] in which to return an exception, if any.
777///
778/// Returns `true` if `propertyName` was successfully deleted, otherwise `false`.
779///
780/// If you named your function `DeleteProperty`, you would declare it like this:
781///
782/// ```ignore
783/// bool
784/// DeleteProperty(JSContextRef ctx, JSObjectRef object,
785///                JSStringRef propertyName, JSValueRef* exception);
786/// ```
787///
788/// If this function returns `false`, the delete request forwards to
789/// `object`'s statically declared properties, then its parent class
790/// chain (which includes the default object class).
791///
792/// # See also
793///
794/// * [`JSClassDefinition::deleteProperty`]
795/// * [`JSObjectGetPropertyCallback`]
796/// * [`JSObjectHasPropertyCallback`]
797/// * [`JSObjectSetPropertyCallback`]
798/// * [`JSObjectDeleteProperty()`]
799pub type JSObjectDeletePropertyCallback = ::std::option::Option<
800    unsafe extern "C" fn(
801        ctx: JSContextRef,
802        object: JSObjectRef,
803        propertyName: JSStringRef,
804        exception: *mut JSValueRef,
805    ) -> bool,
806>;
807
808/// The callback invoked when collecting the names of an object's properties.
809///
810/// * `ctx`: The execution context to use.
811/// * `object`: The [`JSObjectRef`] whose property names are being collected.
812/// * `propertyNames`: A JavaScript property name accumulator in which to
813///   accumulate the names of object's properties.
814///
815/// If you named your function `GetPropertyNames`, you would declare it like this:
816///
817/// ```ignore
818/// void
819/// GetPropertyNames(JSContextRef ctx, JSObjectRef object,
820///                  JSPropertyNameAccumulatorRef propertyNames);
821/// ```
822///
823/// Property name accumulators are used by [`JSObjectCopyPropertyNames`]
824/// and JavaScript `for...in` loops.
825///
826/// Use [`JSPropertyNameAccumulatorAddName`] to add property names to
827/// accumulator. A class's `getPropertyNames` callback only needs to
828/// provide the names of properties that the class vends through a
829/// custom `getProperty` or `setProperty` callback. Other properties,
830/// including statically declared properties, properties vended by
831/// other classes, and properties belonging to object's prototype,
832/// are added independently.
833pub type JSObjectGetPropertyNamesCallback = ::std::option::Option<
834    unsafe extern "C" fn(
835        ctx: JSContextRef,
836        object: JSObjectRef,
837        propertyNames: JSPropertyNameAccumulatorRef,
838    ),
839>;
840
841/// The callback invoked when an object is called as a function.
842///
843/// * `ctx`: The execution context to use.
844/// * `function`: A [`JSObjectRef`] that is the function being called.
845/// * `thisObject`: A [`JSObjectRef`] that is the `this` variable in the function's scope.
846/// * `argumentCount`: An integer count of the number of arguments in `arguments`.
847/// * `arguments`: A [`JSValueRef`] array of the arguments passed to the function.
848/// * `exception`: A pointer to a [`JSValueRef`] in which to return an exception, if any.
849///
850/// Returns a [`JSValueRef`] that is the function's return value.
851///
852/// If you named your function `CallAsFunction`, you would declare it like this:
853///
854/// ```ignore
855/// JSValueRef
856/// CallAsFunction(JSContextRef ctx, JSObjectRef function,
857///                JSObjectRef thisObject,
858///                size_t argumentCount, const JSValueRef arguments[],
859///                JSValueRef* exception);
860/// ```
861///
862/// If your callback were invoked by the JavaScript expression
863/// `myObject.myFunction()`, function would be set to `myFunction`,
864/// and `thisObject` would be set to `myObject`.
865///
866/// If this callback is `NULL`, calling your object as a function
867/// will throw an exception.
868pub type JSObjectCallAsFunctionCallback = ::std::option::Option<
869    unsafe extern "C" fn(
870        ctx: JSContextRef,
871        function: JSObjectRef,
872        thisObject: JSObjectRef,
873        argumentCount: usize,
874        arguments: *const JSValueRef,
875        exception: *mut JSValueRef,
876    ) -> *const OpaqueJSValue,
877>;
878
879/// The callback invoked when an object is used as a constructor in a `new` expression.
880///
881/// * `ctx`: The execution context to use.
882/// * `constructor`: A [`JSObjectRef`] that is the constructor being called.
883/// * `argumentCount`: An integer count of the number of arguments in `arguments`.
884/// * `arguments`: A [`JSValueRef`] array of the arguments passed to the function.
885/// * `exception`: A pointer to a [`JSValueRef`] in which to return an exception, if any.
886///
887/// Returns a [`JSObjectRef`] that is the constructor's return value.
888///
889/// If you named your function `CallAsConstructor`, you would declare it like this:
890///
891/// ```ignore
892/// JSObjectRef
893/// CallAsConstructor(JSContextRef ctx, JSObjectRef constructor,
894///                   size_t argumentCount, const JSValueRef arguments[],
895///                   JSValueRef* exception);
896/// ```
897///
898/// If your callback were invoked by the JavaScript expression
899/// `new myConstructor()`, constructor would be set to `myConstructor`.
900///
901/// If this callback is `NULL`, using your object as a constructor in a
902/// `new` expression will throw an exception.
903pub type JSObjectCallAsConstructorCallback = ::std::option::Option<
904    unsafe extern "C" fn(
905        ctx: JSContextRef,
906        constructor: JSObjectRef,
907        argumentCount: usize,
908        arguments: *const JSValueRef,
909        exception: *mut JSValueRef,
910    ) -> *mut OpaqueJSValue,
911>;
912
913/// The callback invoked when an object is used as the target
914/// of an `instanceof` expression.
915///
916/// * `ctx`: The execution context to use.
917/// * `constructor`: The [`JSObjectRef`] that is the target of the
918///   `instanceof` expression.
919/// * `possibleInstance`: The [`JSValueRef`] being tested to determine if it
920///   is an instance of `constructor`.
921/// * `exception`: A pointer to a [`JSValueRef`] in which to return an exception, if any.
922///
923/// Returns `true` if `possibleInstance` is an instance of `constructor`,
924/// otherwise `false`.
925///
926/// If you named your function `HasInstance`, you would declare it like this:
927///
928/// ```ignore
929/// bool
930/// HasInstance(JSContextRef ctx, JSObjectRef constructor,
931///             JSValueRef possibleInstance, JSValueRef* exception);
932/// ```
933///
934/// If your callback were invoked by the JavaScript expression
935/// `someValue instanceof myObject`, constructor would be set
936/// to `myObject` and `possibleInstance` would be set to `someValue`.
937///
938/// If this callback is `NULL`, `instanceof` expressions that target
939/// your object will return `false`.
940///
941/// Standard JavaScript practice calls for objects that implement
942/// the `callAsConstructor` callback to implement the `hasInstance`
943/// callback as well.
944pub type JSObjectHasInstanceCallback = ::std::option::Option<
945    unsafe extern "C" fn(
946        ctx: JSContextRef,
947        constructor: JSObjectRef,
948        possibleInstance: JSValueRef,
949        exception: *mut JSValueRef,
950    ) -> bool,
951>;
952
953/// The callback invoked when converting an object to a particular
954/// JavaScript type.
955///
956/// * `ctx`: The execution context to use.
957/// * `object`: The [`JSObjectRef`] to convert.
958/// * `type`: A [`JSType`] specifying the JavaScript type to convert to.
959/// * `exception`: A pointer to a [`JSValueRef`] in which to return an exception, if any.
960///
961///Returns the objects' converted value, or `NULL` if the object was not converted.
962///
963/// If you named your function `ConvertToType`, you would declare it like this:
964///
965/// ```ignore
966/// JSValueRef
967/// ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type,
968///               JSValueRef* exception);
969/// ```
970///
971/// If this function returns `false`, the conversion request forwards
972/// to object's parent class chain (which includes the default object
973/// class).
974///
975/// This function is only invoked when converting an object to number
976/// or string. An object converted to boolean is `true`. An object
977/// converted to object is itself.
978pub type JSObjectConvertToTypeCallback = ::std::option::Option<
979    unsafe extern "C" fn(
980        ctx: JSContextRef,
981        object: JSObjectRef,
982        type_: JSType,
983        exception: *mut JSValueRef,
984    ) -> *const OpaqueJSValue,
985>;
986
987/// A statically declared value property.
988#[repr(C)]
989#[derive(Debug, Copy, Clone)]
990pub struct JSStaticValue {
991    /// A null-terminated UTF8 string containing the property's name.
992    pub name: *const ::std::os::raw::c_char,
993    /// A [`JSObjectGetPropertyCallback`] to invoke when getting the property's value.
994    pub getProperty: JSObjectGetPropertyCallback,
995    /// A [`JSObjectSetPropertyCallback`] to invoke when setting the property's value.
996    /// May be `NULL` if the `ReadOnly` attribute is set.
997    pub setProperty: JSObjectSetPropertyCallback,
998    /// A logically ORed set of [`JSPropertyAttributes`] to give to the property.
999    pub attributes: JSPropertyAttributes,
1000}
1001
1002/// A statically declared function property.
1003#[repr(C)]
1004#[derive(Debug, Copy, Clone)]
1005pub struct JSStaticFunction {
1006    /// A null-terminated UTF8 string containing the property's name.
1007    pub name: *const ::std::os::raw::c_char,
1008    /// A [`JSObjectCallAsFunctionCallback`] to invoke when the property
1009    /// is called as a function.
1010    pub callAsFunction: JSObjectCallAsFunctionCallback,
1011    /// A logically ORed set of [`JSPropertyAttributes`] to give to the property.
1012    pub attributes: JSPropertyAttributes,
1013}
1014
1015/// Contains properties and callbacks that define a type of object.
1016///
1017/// All fields other than the version field are optional. Any pointer may be `NULL`.
1018///
1019/// The `staticValues` and `staticFunctions` arrays are the simplest and most
1020/// efficient means for vending custom properties. Statically declared
1021/// properties automatically service requests like `getProperty`,
1022/// `setProperty`, and `getPropertyNames`. Property access callbacks
1023/// are required only to implement unusual properties, like array
1024/// indexes, whose names are not known at compile-time.
1025///
1026/// If you named your getter function `GetX` and your setter function
1027/// `SetX`, you would declare a [`JSStaticValue`] array containing `"X"` like this:
1028///
1029/// ```ignore
1030/// JSStaticValue StaticValueArray[] = {
1031///     { "X", GetX, SetX, kJSPropertyAttributeNone },
1032///     { 0, 0, 0, 0 }
1033/// };
1034/// ```
1035///
1036/// Standard JavaScript practice calls for storing function objects in
1037/// prototypes, so they can be shared. The default [`JSClassRef`] created by
1038/// [`JSClassCreate`] follows this idiom, instantiating objects with a
1039/// shared, automatically generating prototype containing the class's
1040/// function objects. The [`kJSClassAttributeNoAutomaticPrototype`]
1041/// attribute specifies that a [`JSClassRef`] should not automatically
1042/// generate such a prototype. The resulting [`JSClassRef`] instantiates
1043/// objects with the default object prototype, and gives each instance
1044/// object its own copy of the class's function objects.
1045///
1046/// A `NULL` callback specifies that the default object callback
1047/// should substitute, except in the case of `hasProperty`, where it
1048/// specifies that `getProperty` should substitute.
1049#[repr(C)]
1050#[derive(Debug, Copy, Clone)]
1051pub struct JSClassDefinition {
1052    /// The version number of this structure. The current version is 0.
1053    pub version: ::std::os::raw::c_int,
1054    /// A logically ORed set of [`JSClassAttributes`] to give to the class.
1055    pub attributes: JSClassAttributes,
1056    /// A null-terminated UTF8 string containing the class's name.
1057    pub className: *const ::std::os::raw::c_char,
1058    /// A [`JSClassRef`] to set as the class's parent class. Pass `NULL` use the default object class.
1059    pub parentClass: JSClassRef,
1060    /// A [`JSStaticValue`] array containing the class's statically declared
1061    /// value properties. Pass `NULL` to specify no statically declared
1062    /// value properties. The array must be terminated by a [`JSStaticValue`]
1063    /// whose name field is `NULL`.
1064    pub staticValues: *const JSStaticValue,
1065    /// A [`JSStaticFunction`] array containing the class's statically
1066    /// declared function properties. Pass `NULL` to specify no
1067    /// statically declared function properties. The array must be
1068    /// terminated by a [`JSStaticFunction`] whose name field is `NULL`.
1069    pub staticFunctions: *const JSStaticFunction,
1070    /// The callback invoked when an object is first created. Use this callback
1071    /// to initialize the object.
1072    pub initialize: JSObjectInitializeCallback,
1073    /// The callback invoked when an object is finalized (prepared for garbage
1074    /// collection). Use this callback to release resources allocated for the
1075    /// object, and perform other cleanup.
1076    pub finalize: JSObjectFinalizeCallback,
1077    /// The callback invoked when determining whether an object has a property.
1078    ///
1079    /// If this field is `NULL`, `getProperty` is called instead. The
1080    /// `hasProperty` callback enables optimization in cases where
1081    /// only a property's existence needs to be known, not its value,
1082    /// and computing its value is expensive.
1083    pub hasProperty: JSObjectHasPropertyCallback,
1084    /// The callback invoked when getting a property's value.
1085    pub getProperty: JSObjectGetPropertyCallback,
1086    /// The callback invoked when setting a property's value.
1087    pub setProperty: JSObjectSetPropertyCallback,
1088    /// The callback invoked when deleting a property.
1089    pub deleteProperty: JSObjectDeletePropertyCallback,
1090    /// The callback invoked when collecting the names of an object's properties.
1091    pub getPropertyNames: JSObjectGetPropertyNamesCallback,
1092    /// The callback invoked when an object is called as a function.
1093    pub callAsFunction: JSObjectCallAsFunctionCallback,
1094    /// The callback invoked when an object is used as a constructor in a `new` expression.
1095    pub callAsConstructor: JSObjectCallAsConstructorCallback,
1096    /// The callback invoked when an object is used as the target of an `instanceof` expression.
1097    pub hasInstance: JSObjectHasInstanceCallback,
1098    /// The callback invoked when converting an object to a particular JavaScript type.
1099    pub convertToType: JSObjectConvertToTypeCallback,
1100}
1101
1102impl Default for JSClassDefinition {
1103    fn default() -> Self {
1104        JSClassDefinition {
1105            version: 0,
1106            attributes: 0,
1107            className: ptr::null(),
1108            parentClass: ptr::null_mut(),
1109            staticValues: ptr::null(),
1110            staticFunctions: ptr::null(),
1111            initialize: None,
1112            finalize: None,
1113            hasProperty: None,
1114            getProperty: None,
1115            setProperty: None,
1116            deleteProperty: None,
1117            getPropertyNames: None,
1118            callAsFunction: None,
1119            callAsConstructor: None,
1120            hasInstance: None,
1121            convertToType: None,
1122        }
1123    }
1124}
1125
1126extern "C" {
1127    /// Creates a JavaScript class suitable for use with [`JSObjectMake`].
1128    ///
1129    /// * `definition`: A [`JSClassDefinition`] that defines the class.
1130    ///
1131    /// Returns a [`JSClassRef`] with the given definition. Ownership follows
1132    /// the Create Rule.
1133    pub fn JSClassCreate(definition: *const JSClassDefinition) -> JSClassRef;
1134
1135    /// Retains a JavaScript class.
1136    ///
1137    /// `jsClass`: The [`JSClassRef`] to retain.
1138    ///
1139    /// Returns a [`JSClassRef`] that is the same as `jsClass`.
1140    pub fn JSClassRetain(jsClass: JSClassRef) -> JSClassRef;
1141
1142    /// Releases a JavaScript class.
1143    ///
1144    /// `jsClass`: The [`JSClassRef`] to release.
1145    pub fn JSClassRelease(jsClass: JSClassRef);
1146
1147    /// Creates a JavaScript object.
1148    ///
1149    /// The default object class does not allocate storage for private data,
1150    /// so you must provide a non-`NULL` `jsClass` to `JSObjectMake` if you
1151    /// want your object to be able to store private data.
1152    ///
1153    /// `data` is set on the created object before the initialize methods in
1154    /// its class chain are called. This enables the initialize methods to
1155    /// retrieve and manipulate data through [`JSObjectGetPrivate`].
1156    ///
1157    /// * `ctx`: The execution context to use.
1158    /// * `jsClass`: The [`JSClassRef`] to assign to the object. Pass `NULL` to use
1159    ///   the default object class.
1160    /// * `data`: A `void*` to set as the object's private data.
1161    ///    Pass `NULL` to specify no private data.
1162    ///
1163    /// Returns a [`JSObjectRef`] with the given class and private data.
1164    pub fn JSObjectMake(
1165        ctx: JSContextRef,
1166        jsClass: JSClassRef,
1167        data: *mut ::std::os::raw::c_void,
1168    ) -> JSObjectRef;
1169
1170    /// Convenience method for creating a JavaScript function with a given
1171    /// callback as its implementation.
1172    ///
1173    /// * `ctx`: The execution context to use.
1174    /// * `name`: A [`JSStringRef`] containing the function's name. This will be
1175    ///   used when converting the function to string. Pass `NULL` to create
1176    ///   an anonymous function.
1177    /// * `callAsFunction`: The [`JSObjectCallAsFunctionCallback`] to invoke
1178    ///   when the function is called.
1179    ///
1180    /// Returns a [`JSObjectRef`] that is a function. The object's prototype will be
1181    /// the default function prototype.
1182    pub fn JSObjectMakeFunctionWithCallback(
1183        ctx: JSContextRef,
1184        name: JSStringRef,
1185        callAsFunction: JSObjectCallAsFunctionCallback,
1186    ) -> JSObjectRef;
1187
1188    /// Convenience method for creating a JavaScript constructor.
1189    ///
1190    /// * `ctx`: The execution context to use.
1191    /// * `jsClass`: A [`JSClassRef`] that is the class your constructor
1192    ///   will assign to the objects its constructs. `jsClass` will
1193    ///   be used to set the constructor's `.prototype` property, and
1194    ///   to evaluate `instanceof` expressions. Pass `NULL` to use
1195    ///   the default object class.
1196    /// * `callAsConstructor` A [`JSObjectCallAsConstructorCallback`] to
1197    ///   invoke when your constructor is used in a `new` expression.
1198    ///   Pass `NULL` to use the default object constructor.
1199    ///
1200    /// Returns a [`JSObjectRef`] that is a constructor. The object's
1201    /// prototype will be the default object prototype.
1202    ///
1203    /// The default object constructor takes no arguments and constructs
1204    /// an object of class `jsClass` with no private data.
1205    pub fn JSObjectMakeConstructor(
1206        ctx: JSContextRef,
1207        jsClass: JSClassRef,
1208        callAsConstructor: JSObjectCallAsConstructorCallback,
1209    ) -> JSObjectRef;
1210
1211    /// Creates a JavaScript Array object.
1212    ///
1213    /// * `ctx`: The execution context to use.
1214    /// * `argumentCount`: An integer count of the number of
1215    ///   arguments in `arguments`.
1216    /// * `arguments`: A [`JSValueRef`] array of data to populate the
1217    ///   `Array` with. Pass `NULL` if `argumentCount` is `0`.
1218    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1219    ///   an exception, if any. Pass `NULL` if you do not care to
1220    ///   store an exception.
1221    ///
1222    /// Returns a [`JSObjectRef`] that is an `Array`.
1223    ///
1224    /// The behavior of this function does not exactly match the behavior
1225    /// of the built-in `Array` constructor. Specifically, if one argument
1226    ///  is supplied, this function returns an array with one element.
1227    pub fn JSObjectMakeArray(
1228        ctx: JSContextRef,
1229        argumentCount: usize,
1230        arguments: *const JSValueRef,
1231        exception: *mut JSValueRef,
1232    ) -> JSObjectRef;
1233
1234    /// Creates a JavaScript `Date` object, as if by invoking the
1235    /// built-in `Date` constructor.
1236    ///
1237    /// * `ctx`: The execution context to use.
1238    /// * `argumentCount`: An integer count of the number of
1239    ///   arguments in `arguments`.
1240    /// * `arguments`: A [`JSValueRef`] array of arguments to pass to
1241    ///   the `Date` constructor. Pass `NULL` if `argumentCount` is `0`.
1242    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1243    ///   an exception, if any. Pass `NULL` if you do not care to
1244    ///   store an exception.
1245    ///
1246    /// Returns a [`JSObjectRef`] that is a `Date`.
1247    pub fn JSObjectMakeDate(
1248        ctx: JSContextRef,
1249        argumentCount: usize,
1250        arguments: *const JSValueRef,
1251        exception: *mut JSValueRef,
1252    ) -> JSObjectRef;
1253
1254    /// Creates a JavaScript `Error` object, as if by invoking the
1255    /// built-in `Error` constructor.
1256    ///
1257    /// * `ctx`: The execution context to use.
1258    /// * `argumentCount`: An integer count of the number of
1259    ///   arguments in `arguments`.
1260    /// * `arguments`: A [`JSValueRef`] array of arguments to pass to
1261    ///   the `Error` constructor. Pass `NULL` if `argumentCount` is `0`.
1262    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1263    ///   an exception, if any. Pass `NULL` if you do not care to
1264    ///   store an exception.
1265    ///
1266    /// Returns a [`JSObjectRef`] that is a `Error`.
1267    pub fn JSObjectMakeError(
1268        ctx: JSContextRef,
1269        argumentCount: usize,
1270        arguments: *const JSValueRef,
1271        exception: *mut JSValueRef,
1272    ) -> JSObjectRef;
1273
1274    /// Creates a JavaScript `RegExp` object, as if by invoking the
1275    /// built-in `RegExp` constructor.
1276    ///
1277    /// * `ctx`: The execution context to use.
1278    /// * `argumentCount`: An integer count of the number of
1279    ///   arguments in `arguments`.
1280    /// * `arguments`: A [`JSValueRef`] array of arguments to pass to
1281    ///   the `RegExp` constructor. Pass `NULL` if `argumentCount` is `0`.
1282    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1283    ///   an exception, if any. Pass `NULL` if you do not care to
1284    ///   store an exception.
1285    ///
1286    /// Returns a [`JSObjectRef`] that is a `RegExp`.
1287    pub fn JSObjectMakeRegExp(
1288        ctx: JSContextRef,
1289        argumentCount: usize,
1290        arguments: *const JSValueRef,
1291        exception: *mut JSValueRef,
1292    ) -> JSObjectRef;
1293
1294    /// Creates a JavaScript promise object by invoking the provided executor.
1295    ///
1296    /// * `ctx`: The execution context to use.
1297    /// * `resolve`: A pointer to a [`JSObjectRef`] in which to store the
1298    ///   resolve function for the new promise. Pass `NULL` if you do not
1299    ///   care to store the resolve callback.
1300    /// * `reject`: A pointer to a [`JSObjectRef`] in which to store the
1301    ///   reject function for the new promise. Pass `NULL` if you do not
1302    ///   care to store the reject callback.
1303    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1304    ///   an exception, if any. Pass `NULL` if you do not care to
1305    ///   store an exception.
1306    ///
1307    /// A [`JSObjectRef`] that is a promise or `NULL` if an exception occurred.
1308    pub fn JSObjectMakeDeferredPromise(
1309        ctx: JSContextRef,
1310        resolve: *mut JSObjectRef,
1311        reject: *mut JSObjectRef,
1312        exception: *mut JSValueRef,
1313    ) -> JSObjectRef;
1314
1315    /// Creates a function with a given script as its body.
1316    ///
1317    /// * `ctx`: The execution context to use.
1318    /// * `name`: A [`JSStringRef`] containing the function's name. This
1319    ///   will be used when converting the function to string. Pass
1320    ///   `NULL` to create an anonymous function.
1321    /// * `parameterCount`: An integer count of the number of parameter
1322    ///   names in `parameterNames`.
1323    /// * `parameterNames`: A [`JSStringRef`] array containing the names of
1324    ///   the function's parameters. Pass `NULL` if `parameterCount` is `0`.
1325    /// * `body`: A [`JSStringRef`] containing the script to use as the
1326    ///   function's body.
1327    /// * `sourceURL` A [`JSStringRef`] containing a URL for the script's
1328    ///   source file. This is only used when reporting exceptions.
1329    ///   Pass `NULL` if you do not care to include source file
1330    ///   information in exceptions.
1331    /// * `startingLineNumber`: An integer value specifying the
1332    ///   script's starting line number in the file located at
1333    ///   `sourceURL`. This is only used when reporting exceptions.
1334    ///   The value is one-based, so the first line is line `1`
1335    ///   and invalid values are clamped to `1`.
1336    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1337    ///   an exception, if any. Pass `NULL` if you do not care to
1338    ///   store an exception.
1339    ///
1340    /// Returns a [`JSObjectRef`] that is a function, or `NULL` if either
1341    /// body or `parameterNames` contains a syntax error. The
1342    /// object's prototype will be the default function prototype.
1343    ///
1344    /// Use this method when you want to execute a script repeatedly, to
1345    /// avoid the cost of re-parsing the script before each execution.
1346    pub fn JSObjectMakeFunction(
1347        ctx: JSContextRef,
1348        name: JSStringRef,
1349        parameterCount: ::std::os::raw::c_uint,
1350        parameterNames: *const JSStringRef,
1351        body: JSStringRef,
1352        sourceURL: JSStringRef,
1353        startingLineNumber: ::std::os::raw::c_int,
1354        exception: *mut JSValueRef,
1355    ) -> JSObjectRef;
1356
1357    /// Gets an object's prototype.
1358    ///
1359    /// * `ctx`: The execution context to use.
1360    /// * `object`: A [`JSObjectRef`] whose prototype you want to get.
1361    ///
1362    /// Returns a [`JSValueRef`] that is the object's prototype.
1363    ///
1364    /// # See also
1365    ///
1366    /// * [`JSObjectSetPrototype()`]
1367    pub fn JSObjectGetPrototype(ctx: JSContextRef, object: JSObjectRef) -> JSValueRef;
1368
1369    ///Sets an object's prototype.
1370    ///
1371    /// * `ctx`: The execution context to use.
1372    /// * `object`: The [`JSObjectRef`] whose prototype you want to set.
1373    /// * `value`: A [`JSValueRef`] to set as the object's prototype.
1374    ///
1375    /// # See also
1376    ///
1377    /// * [`JSObjectGetPrototype()`]
1378    pub fn JSObjectSetPrototype(ctx: JSContextRef, object: JSObjectRef, value: JSValueRef);
1379
1380    /// Tests whether an object has a given property.
1381    ///
1382    /// * `object`: The [`JSObjectRef`] to test.
1383    /// * `propertyName`: A [`JSStringRef`] containing the property's name.
1384    ///
1385    /// Returns `true` if the object has a property whose name matches
1386    /// `propertyName`, otherwise `false`.
1387    ///
1388    /// # See also
1389    ///
1390    /// * [`JSClassDefinition::hasProperty`]
1391    /// * [`JSObjectDeleteProperty()`]
1392    /// * [`JSObjectGetProperty()`]
1393    /// * [`JSObjectHasPropertyCallback`]
1394    /// * [`JSObjectHasPropertyForKey()`]
1395    /// * [`JSObjectSetProperty()`]
1396    pub fn JSObjectHasProperty(
1397        ctx: JSContextRef,
1398        object: JSObjectRef,
1399        propertyName: JSStringRef,
1400    ) -> bool;
1401
1402    /// Gets a property from an object.
1403    ///
1404    /// * `ctx`: The execution context to use.
1405    /// * `object`: The [`JSObjectRef`] whose property you want to get.
1406    /// * `propertyName`: A [`JSStringRef`] containing the property's name.
1407    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1408    ///   an exception, if any. Pass `NULL` if you do not care to
1409    ///   store an exception.
1410    ///
1411    /// Returns the property's value if object has the property, otherwise
1412    /// the undefined value.
1413    ///
1414    /// # See also
1415    ///
1416    /// * [`JSClassDefinition::getProperty`]
1417    /// * [`JSObjectDeleteProperty()`]
1418    /// * [`JSObjectGetPropertyAtIndex()`]
1419    /// * [`JSObjectGetPropertyCallback`]
1420    /// * [`JSObjectGetPropertyForKey()`]
1421    /// * [`JSObjectHasProperty()`]
1422    /// * [`JSObjectSetProperty()`]
1423    pub fn JSObjectGetProperty(
1424        ctx: JSContextRef,
1425        object: JSObjectRef,
1426        propertyName: JSStringRef,
1427        exception: *mut JSValueRef,
1428    ) -> JSValueRef;
1429
1430    /// Sets a property on an object.
1431    ///
1432    /// * `ctx`: The execution context to use.
1433    /// * `object`: The [`JSObjectRef`] whose property you want to set.
1434    /// * `propertyName`: A [`JSStringRef`] containing the property's name.
1435    /// * `value`: A [`JSValueRef`] to use as the property's value.
1436    /// * `attributes`: A logically ORed set of [`JSPropertyAttributes`] to give to the property.
1437    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1438    ///   an exception, if any. Pass `NULL` if you do not care to
1439    ///   store an exception.
1440    ///
1441    /// # See also
1442    ///
1443    /// * [`JSClassDefinition::setProperty`]
1444    /// * [`JSObjectDeleteProperty()`]
1445    /// * [`JSObjectGetProperty()`]
1446    /// * [`JSObjectHasProperty()`]
1447    /// * [`JSObjectSetPropertyAtIndex()`]
1448    /// * [`JSObjectSetPropertyCallback`]
1449    /// * [`JSObjectGetPropertyForKey()`]
1450    pub fn JSObjectSetProperty(
1451        ctx: JSContextRef,
1452        object: JSObjectRef,
1453        propertyName: JSStringRef,
1454        value: JSValueRef,
1455        attributes: JSPropertyAttributes,
1456        exception: *mut JSValueRef,
1457    );
1458
1459    /// Deletes a property from an object.
1460    ///
1461    /// * `ctx`: The execution context to use.
1462    /// * `object`: The [`JSObjectRef`] whose property you want to delete.
1463    /// * `propertyName`: A [`JSStringRef`] containing the property's name.
1464    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1465    ///   an exception, if any. Pass `NULL` if you do not care to
1466    ///   store an exception.
1467    ///
1468    /// Returns `true` if the delete operation succeeds, otherwise `false`
1469    /// (for example, if the property has the [`kJSPropertyAttributeDontDelete`]
1470    /// attribute set).
1471    ///
1472    /// # See also
1473    ///
1474    /// * [`JSClassDefinition::deleteProperty`]
1475    /// * [`JSObjectDeletePropertyCallback`]
1476    /// * [`JSObjectDeletePropertyForKey()`]
1477    /// * [`JSObjectGetProperty()`]
1478    /// * [`JSObjectHasProperty()`]
1479    /// * [`JSObjectSetProperty()`]
1480    pub fn JSObjectDeleteProperty(
1481        ctx: JSContextRef,
1482        object: JSObjectRef,
1483        propertyName: JSStringRef,
1484        exception: *mut JSValueRef,
1485    ) -> bool;
1486
1487    /// Tests whether an object has a given property using a [`JSValueRef`] as the property key.
1488    ///
1489    /// * `ctx`: The execution context to use.
1490    /// * `object`: The [`JSObjectRef`] to test.
1491    /// * `propertyKey`: A [`JSValueRef`] containing the property key
1492    ///   to use when looking up the property.
1493    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1494    ///   an exception, if any. Pass `NULL` if you do not care to
1495    ///   store an exception.
1496    ///
1497    /// Returns `true` if the object has a property whose name matches
1498    /// `propertyKey`, otherwise `false`.
1499    ///
1500    /// This function is the same as performing `propertyKey in object` from JavaScript.
1501    ///
1502    /// # See also
1503    ///
1504    /// * [`JSObjectDeletePropertyForKey()`]
1505    /// * [`JSObjectGetPropertyForKey()`]
1506    /// * [`JSObjectHasProperty()`]
1507    /// * [`JSObjectSetPropertyForKey()`]
1508    pub fn JSObjectHasPropertyForKey(
1509        ctx: JSContextRef,
1510        object: JSObjectRef,
1511        propertyKey: JSValueRef,
1512        exception: *mut JSValueRef,
1513    ) -> bool;
1514
1515    /// Gets a property from an object using a [`JSValueRef`] as the property key.
1516    ///
1517    /// * `ctx`: The execution context to use.
1518    /// * `object`: The [`JSObjectRef`] whose property you want to get.
1519    /// * `propertyKey`: A [`JSValueRef`] containing the property key
1520    ///   to use when looking up the property.
1521    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1522    ///   an exception, if any. Pass `NULL` if you do not care to
1523    ///   store an exception.
1524    ///
1525    /// The property's value if object has the property key, otherwise the undefined value.
1526    ///
1527    /// This function is the same as performing `object[propertyKey]` from JavaScript.
1528    ///
1529    /// # See also
1530    ///
1531    /// * [`JSObjectDeletePropertyForKey()`]
1532    /// * [`JSObjectGetProperty()`]
1533    /// * [`JSObjectGetPropertyAtIndex()`]
1534    /// * [`JSObjectHasPropertyForKey()`]
1535    /// * [`JSObjectSetPropertyForKey()`]
1536    pub fn JSObjectGetPropertyForKey(
1537        ctx: JSContextRef,
1538        object: JSObjectRef,
1539        propertyKey: JSValueRef,
1540        exception: *mut JSValueRef,
1541    ) -> JSValueRef;
1542
1543    /// Sets a property on an object using a [`JSValueRef`] as the property key.
1544    ///
1545    /// * `ctx`: The execution context to use.
1546    /// * `object `:The [`JSObjectRef`] whose property you want to set.
1547    /// * `propertyKey`: A [`JSValueRef`] containing the property key
1548    ///   to use when looking up the property.
1549    /// * `value`: A [`JSValueRef`] to use as the property's value.
1550    /// * `attributes`: A logically ORed set of [`JSPropertyAttributes`]
1551    ///   to give to the property.
1552    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1553    ///   an exception, if any. Pass `NULL` if you do not care to
1554    ///   store an exception.
1555    ///
1556    /// This function is the same as performing `object[propertyKey] = value` from JavaScript.
1557    ///
1558    /// # See also
1559    ///
1560    /// * [`JSObjectDeletePropertyForKey()`]
1561    /// * [`JSObjectGetPropertyForKey()`]
1562    /// * [`JSObjectHasPropertyForKey()`]
1563    /// * [`JSObjectSetProperty()`]
1564    /// * [`JSObjectSetPropertyAtIndex()`]
1565    pub fn JSObjectSetPropertyForKey(
1566        ctx: JSContextRef,
1567        object: JSObjectRef,
1568        propertyKey: JSValueRef,
1569        value: JSValueRef,
1570        attributes: JSPropertyAttributes,
1571        exception: *mut JSValueRef,
1572    );
1573
1574    /// Deletes a property from an object using a [`JSValueRef`] as the property key.
1575    ///
1576    /// * `ctx`: The execution context to use.
1577    /// * `object`: The [`JSObjectRef`] whose property you want to delete.
1578    /// * `propertyKey`: A [`JSValueRef`] containing the property key
1579    ///   to use when looking up the property.
1580    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1581    ///   an exception, if any. Pass `NULL` if you do not care to
1582    ///   store an exception.
1583    ///
1584    /// Returns `true` if the delete operation succeeds, otherwise `false`
1585    /// (for example, if the property has the `kJSPropertyAttributeDontDelete`
1586    /// attribute set).
1587    ///
1588    /// This function is the same as performing `delete object[propertyKey]` from JavaScript.
1589    ///
1590    /// # See also
1591    ///
1592    /// * [`JSObjectDeleteProperty()`]
1593    /// * [`JSObjectGetPropertyForKey()`]
1594    /// * [`JSObjectHasPropertyForKey()`]
1595    /// * [`JSObjectSetPropertyForKey()`]
1596    pub fn JSObjectDeletePropertyForKey(
1597        ctx: JSContextRef,
1598        object: JSObjectRef,
1599        propertyKey: JSValueRef,
1600        exception: *mut JSValueRef,
1601    ) -> bool;
1602
1603    /// Gets a property from an object by numeric index.
1604    ///
1605    /// * `ctx`: The execution context to use.
1606    /// * `object`: The [`JSObjectRef`] whose property you want to get.
1607    /// * `propertyIndex`: An integer value that is the property's name.
1608    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1609    ///   an exception, if any. Pass `NULL` if you do not care to
1610    ///   store an exception.
1611    ///
1612    /// Returns the property's value if object has the property,
1613    /// otherwise the undefined value.
1614    ///
1615    /// Calling [`JSObjectGetPropertyAtIndex`] is equivalent to calling
1616    /// [`JSObjectGetProperty`] with a string containing `propertyIndex`,
1617    /// but `JSObjectGetPropertyAtIndex` provides optimized access to
1618    /// numeric properties.
1619    ///
1620    /// # See also
1621    ///
1622    /// * [`JSObjectGetProperty()`]
1623    /// * [`JSObjectGetPropertyForKey()`]
1624    /// * [`JSObjectSetPropertyAtIndex()`]
1625    pub fn JSObjectGetPropertyAtIndex(
1626        ctx: JSContextRef,
1627        object: JSObjectRef,
1628        propertyIndex: ::std::os::raw::c_uint,
1629        exception: *mut JSValueRef,
1630    ) -> JSValueRef;
1631
1632    /// Sets a property on an object by numeric index.
1633    ///
1634    /// * `ctx`: The execution context to use.
1635    /// * `object`: The [`JSObjectRef`] whose property you want to set.
1636    /// * `propertyIndex`: The property's name as a number.
1637    /// * `value`: A [`JSValueRef`] to use as the property's value.
1638    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1639    ///   an exception, if any. Pass `NULL` if you do not care to
1640    ///   store an exception.
1641    ///
1642    /// Calling `JSObjectSetPropertyAtIndex` is equivalent to calling
1643    /// [`JSObjectSetProperty`] with a string containing `propertyIndex`,
1644    /// but `JSObjectSetPropertyAtIndex` provides optimized access to
1645    /// numeric properties.
1646    ///
1647    /// # See also
1648    ///
1649    /// * [`JSObjectGetPropertyAtIndex()`]
1650    /// * [`JSObjectSetProperty()`]
1651    /// * [`JSObjectSetPropertyForKey()`]
1652    pub fn JSObjectSetPropertyAtIndex(
1653        ctx: JSContextRef,
1654        object: JSObjectRef,
1655        propertyIndex: ::std::os::raw::c_uint,
1656        value: JSValueRef,
1657        exception: *mut JSValueRef,
1658    );
1659
1660    /// Gets an object's private data.
1661    ///
1662    /// * `object`: A [`JSObjectRef`] whose private data you want to get.
1663    ///
1664    /// Returns a `void*` that is the object's private data, if the
1665    /// object has private data, otherwise `NULL`.
1666    ///
1667    /// # See also
1668    ///
1669    /// * [`JSObjectMake()`]
1670    /// * [`JSObjectSetPrivate()`]
1671    pub fn JSObjectGetPrivate(object: JSObjectRef) -> *mut ::std::os::raw::c_void;
1672
1673    /// Sets a pointer to private data on an object.
1674    ///
1675    /// * `object`: The [`JSObjectRef`] whose private data you want to set.
1676    /// * `data`: A `void*` to set as the object's private data.
1677    ///
1678    /// Returns `true` if object can store private data, otherwise `false`.
1679    ///
1680    /// The default object class does not allocate storage for private data.
1681    /// Only objects created with a non-`NULL` [`JSClassRef`] can store private data.
1682    ///
1683    /// # See also
1684    ///
1685    /// * [`JSObjectGetPrivate()`]
1686    /// * [`JSObjectMake()`]
1687    pub fn JSObjectSetPrivate(object: JSObjectRef, data: *mut ::std::os::raw::c_void) -> bool;
1688
1689    /// Tests whether an object can be called as a function.
1690    ///
1691    /// * `ctx`: The execution context to use.
1692    /// * `object`: The [`JSObjectRef`] to test.
1693    ///
1694    /// Returns `true` if the object can be called as a function, otherwise `false`.
1695    ///
1696    /// # See also
1697    ///
1698    /// * [`JSObjectCallAsFunction()`]
1699    pub fn JSObjectIsFunction(ctx: JSContextRef, object: JSObjectRef) -> bool;
1700
1701    /// Calls an object as a function.
1702    ///
1703    /// * `ctx`: The execution context to use.
1704    /// * `object`: The [`JSObjectRef`] to call as a function.
1705    /// * `thisObject`: The object to use as `this`, or `NULL` to use the global object as `this`.
1706    /// * `argumentCount`: An integer count of the number of arguments in `arguments`.
1707    /// * `arguments`: A [`JSValueRef`] array of arguments to pass to the function.
1708    ///   Pass `NULL` if `argumentCount` is `0`.
1709    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1710    ///   an exception, if any. Pass `NULL` if you do not care to
1711    ///   store an exception.
1712    ///
1713    /// Returns the [`JSValueRef`] that results from calling `object` as a function,
1714    /// or `NULL` if an exception is thrown or `object` is not a function.
1715    ///
1716    /// # See also
1717    ///
1718    /// * [`JSObjectCallAsFunction()`]
1719    pub fn JSObjectCallAsFunction(
1720        ctx: JSContextRef,
1721        object: JSObjectRef,
1722        thisObject: JSObjectRef,
1723        argumentCount: usize,
1724        arguments: *const JSValueRef,
1725        exception: *mut JSValueRef,
1726    ) -> JSValueRef;
1727
1728    /// Tests whether an object can be called as a constructor.
1729    ///
1730    /// * `ctx`: The execution context to use.
1731    /// * `object`: The [`JSObjectRef`] to test.
1732    ///
1733    /// Returns `true` if the object can be called as a constructor, otherwise `false`.
1734    pub fn JSObjectIsConstructor(ctx: JSContextRef, object: JSObjectRef) -> bool;
1735
1736    /// Calls an object as a constructor.
1737    ///
1738    /// * `ctx`: The execution context to use.
1739    /// * `object`: The [`JSObjectRef`] to call as a constructor.
1740    /// * `argumentCount`: An integer count of the number of arguments in `arguments`.
1741    /// * `arguments`: A [`JSValueRef`] array of arguments to pass to the constructor.
1742    ///   Pass `NULL` if `argumentCount` is `0`.
1743    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
1744    ///   an exception, if any. Pass `NULL` if you do not care to
1745    ///   store an exception.
1746    ///
1747    /// Returns the [`JSObjectRef`] that results from calling `object` as a constructor,
1748    /// or `NULL` if an exception is thrown or `object` is not a constructor.
1749    pub fn JSObjectCallAsConstructor(
1750        ctx: JSContextRef,
1751        object: JSObjectRef,
1752        argumentCount: usize,
1753        arguments: *const JSValueRef,
1754        exception: *mut JSValueRef,
1755    ) -> JSObjectRef;
1756
1757    /// Gets the names of an object's enumerable properties.
1758    ///
1759    /// * `ctx`: The execution context to use.
1760    /// * `object`: The object whose property names you want to get.
1761    ///
1762    /// Returns a [`JSPropertyNameArrayRef`] containing the names of
1763    /// `object`'s enumerable properties. Ownership follows the Create
1764    /// Rule.
1765    ///
1766    /// # See also
1767    ///
1768    /// * [`JSPropertyNameArrayGetCount`]
1769    /// * [`JSPropertyNameArrayGetNameAtIndex`]
1770    /// * [`JSPropertyNameArrayRelease`]
1771    /// * [`JSPropertyNameArrayRetain`]
1772    pub fn JSObjectCopyPropertyNames(
1773        ctx: JSContextRef,
1774        object: JSObjectRef,
1775    ) -> JSPropertyNameArrayRef;
1776
1777    /// Retains a JavaScript property name array.
1778    ///
1779    /// * `array`: The [`JSPropertyNameArrayRef`] to retain.
1780    ///
1781    /// Returns a [`JSPropertyNameArrayRef`] that is the same as array.
1782    ///
1783    /// # See also
1784    ///
1785    /// * [`JSPropertyNameArrayRelease()`]
1786    pub fn JSPropertyNameArrayRetain(array: JSPropertyNameArrayRef) -> JSPropertyNameArrayRef;
1787
1788    /// Releases a JavaScript property name array.
1789    ///
1790    /// * `array` The [`JSPropertyNameArrayRef`] to release.
1791    ///
1792    /// # See also
1793    ///
1794    /// * [`JSPropertyNameArrayRetain()`]
1795    pub fn JSPropertyNameArrayRelease(array: JSPropertyNameArrayRef);
1796
1797    /// Gets a count of the number of items in a JavaScript property name array.
1798    ///
1799    /// * `array`: The array from which to retrieve the count.
1800    ///
1801    /// Return an integer count of the number of names in `array`.
1802    ///
1803    /// # See also
1804    ///
1805    /// * [`JSObjectCopyPropertyNames()`]
1806    /// * [`JSPropertyNameArrayGetNameAtIndex`]
1807    pub fn JSPropertyNameArrayGetCount(array: JSPropertyNameArrayRef) -> usize;
1808
1809    /// Gets a property name at a given index in a JavaScript property name array.
1810    ///
1811    /// * `array`: The array from which to retrieve the property name.
1812    /// * `index`: The index of the property name to retrieve.
1813    ///
1814    /// Returns a [`JSStringRef`] containing the property name.
1815    ///
1816    /// # See also
1817    ///
1818    /// * [`JSObjectCopyPropertyNames()`]
1819    /// * [`JSPropertyNameArrayGetCount`]
1820    pub fn JSPropertyNameArrayGetNameAtIndex(
1821        array: JSPropertyNameArrayRef,
1822        index: usize,
1823    ) -> JSStringRef;
1824
1825    /// Adds a property name to a JavaScript property name accumulator.
1826    ///
1827    /// * `accumulator`: The accumulator object to which to add the property name.
1828    /// * `propertyName`: The property name to add.
1829    pub fn JSPropertyNameAccumulatorAddName(
1830        accumulator: JSPropertyNameAccumulatorRef,
1831        propertyName: JSStringRef,
1832    );
1833
1834    /// Creates a JavaScript context group.
1835    ///
1836    /// [`JSContextGroupRef`] associates JavaScript contexts with one another.
1837    /// Contexts in the same group may share and exchange JavaScript
1838    /// objects. Sharing and/or exchanging JavaScript objects between
1839    /// contexts in different groups will produce undefined behavior.
1840    /// When objects from the same context group are used in multiple threads,
1841    /// explicit synchronization is required.
1842    ///
1843    /// Returns the created [`JSContextGroupRef`].
1844    pub fn JSContextGroupCreate() -> JSContextGroupRef;
1845
1846    /// Retains a JavaScript context group.
1847    ///
1848    /// * `group`: The [`JSContextGroupRef`] to retain.
1849    ///
1850    /// Returns a [`JSContextGroupRef`] that is the same as group.
1851    pub fn JSContextGroupRetain(group: JSContextGroupRef) -> JSContextGroupRef;
1852
1853    /// Releases a JavaScript context group.
1854    ///
1855    /// * `group`: The [`JSContextGroupRef`] to release.
1856    pub fn JSContextGroupRelease(group: JSContextGroupRef);
1857
1858    /// Creates a global JavaScript execution context.
1859    ///
1860    /// `JSGlobalContextCreate` allocates a global object and populates
1861    /// it with all the built-in JavaScript objects, such as `Object`,
1862    /// `Function`, `String`, and `Array`.
1863    ///
1864    /// In WebKit version 4.0 and later, the context is created in a
1865    /// unique context group. Therefore, scripts may execute in it
1866    /// concurrently with scripts executing in other contexts. However,
1867    /// you may not use values created in the context in other contexts.
1868    ///
1869    /// * `globalObjectClass`: The class to use when creating the global
1870    ///   object. Pass `NULL` to use the default object class.
1871    ///
1872    /// Returns a [`JSGlobalContextRef`] with a global object of
1873    /// class `globalObjectClass`.
1874    pub fn JSGlobalContextCreate(globalObjectClass: JSClassRef) -> JSGlobalContextRef;
1875
1876    /// Creates a global JavaScript execution context in the context
1877    /// group provided.
1878    ///
1879    /// `JSGlobalContextCreateInGroup` allocates a global object and
1880    /// populates it with all the built-in JavaScript objects, such as
1881    /// `Object`, `Function`, `String`, and `Array`.
1882    ///
1883    /// * `group`: The context group to use. The created global context
1884    ///   retains the group.  Pass `NULL` to create a unique group for
1885    ///   the context.
1886    /// * `globalObjectClass`: The class to use when creating the global
1887    ///   object. Pass NULL to use the default object class.
1888    ///
1889    /// Returns a [`JSGlobalContextRef`] with a global object of class
1890    /// `globalObjectClass` and a context group equal to `group`.
1891    pub fn JSGlobalContextCreateInGroup(
1892        group: JSContextGroupRef,
1893        globalObjectClass: JSClassRef,
1894    ) -> JSGlobalContextRef;
1895
1896    /// Retains a global JavaScript execution context.
1897    ///
1898    /// * `ctx`: The [`JSGlobalContextRef`] to retain.
1899    ///
1900    /// Returns a [`JSGlobalContextRef`] that is the same as `ctx`.
1901    pub fn JSGlobalContextRetain(ctx: JSGlobalContextRef) -> JSGlobalContextRef;
1902
1903    /// Releases a global JavaScript execution context.
1904    ///
1905    /// * `ctx` The [`JSGlobalContextRef`] to release.
1906    pub fn JSGlobalContextRelease(ctx: JSGlobalContextRef);
1907
1908    /// Gets the global object of a JavaScript execution context.
1909    ///
1910    /// * `ctx` The [`JSContextRef`] whose global object you want to get.
1911    ///
1912    /// Returns `ctx`'s global object.
1913    pub fn JSContextGetGlobalObject(ctx: JSContextRef) -> JSObjectRef;
1914
1915    /// Gets the context group to which a JavaScript execution context belongs.
1916    ///
1917    /// * `ctx`: The [`JSContextRef`] whose group you want to get.
1918    ///
1919    /// Returns `ctx`'s group.
1920    pub fn JSContextGetGroup(ctx: JSContextRef) -> JSContextGroupRef;
1921
1922    /// Gets the global context of a JavaScript execution context.
1923    ///
1924    /// * `ctx`: The [`JSContextRef`] whose global context you want to get.
1925    ///
1926    /// Returns `ctx`'s global context.
1927    pub fn JSContextGetGlobalContext(ctx: JSContextRef) -> JSGlobalContextRef;
1928
1929    /// Gets a copy of the name of a context.
1930    ///
1931    /// A [`JSGlobalContextRef`]'s name is exposed for remote debugging
1932    /// to make it easier to identify the context you would like to
1933    /// attach to.
1934    ///
1935    /// * `ctx`: The [`JSGlobalContextRef`] whose name you want to get.
1936    ///
1937    /// Returns the name for `ctx`.
1938    pub fn JSGlobalContextCopyName(ctx: JSGlobalContextRef) -> JSStringRef;
1939
1940    /// Sets the remote debugging name for a context.
1941    ///
1942    /// * `ctx`: The [`JSGlobalContextRef`] that you want to name.
1943    /// * `name`: The remote debugging name to set on `ctx`.
1944    pub fn JSGlobalContextSetName(ctx: JSGlobalContextRef, name: JSStringRef);
1945}
1946/// A UTF-16 code unit.
1947///
1948/// One, or a sequence of two, can encode any Unicode character. As
1949/// with all scalar types, endianness depends on the underlying
1950/// architecture.
1951pub type JSChar = ::std::os::raw::c_ushort;
1952extern "C" {
1953    /// Creates a JavaScript string from a buffer of Unicode characters.
1954    ///
1955    /// * `chars`: The buffer of Unicode characters to copy into the
1956    ///   new [`JSStringRef`].
1957    /// * `numChars`: The number of characters to copy from the buffer
1958    ///   pointed to by `chars`.
1959    ///
1960    /// Returns a [`JSStringRef`] containing `chars`. Ownership follows the
1961    /// Create Rule.
1962    pub fn JSStringCreateWithCharacters(chars: *const JSChar, numChars: usize) -> JSStringRef;
1963
1964    /// Creates a JavaScript string from a null-terminated UTF8 string.
1965    ///
1966    /// * `string`: The null-terminated UTF8 string to copy into the
1967    ///   new [`JSStringRef`].
1968    ///
1969    /// Returns a [`JSStringRef`] containing `string`. Ownership follows the
1970    /// Create Rule.
1971    pub fn JSStringCreateWithUTF8CString(string: *const ::std::os::raw::c_char) -> JSStringRef;
1972
1973    /// Retains a JavaScript string.
1974    ///
1975    /// * `string`: The [`JSStringRef`] to retain.
1976    ///
1977    /// Returns a [`JSStringRef`] that is the same as `string`.
1978    pub fn JSStringRetain(string: JSStringRef) -> JSStringRef;
1979
1980    /// Releases a JavaScript string.
1981    ///
1982    /// * `string`: The [`JSStringRef`] to release.
1983    pub fn JSStringRelease(string: JSStringRef);
1984
1985    /// Returns the number of Unicode characters in a JavaScript string.
1986    ///
1987    /// * `string`: The [`JSStringRef`] whose length (in Unicode characters)
1988    ///   you want to know.
1989    ///
1990    /// Returns the number of Unicode characters stored in `string`.
1991    pub fn JSStringGetLength(string: JSStringRef) -> usize;
1992
1993    /// Returns a pointer to the Unicode character buffer that
1994    /// serves as the backing store for a JavaScript string.
1995    ///
1996    /// * `string`: The [`JSStringRef`] whose backing store you want to access.
1997    ///
1998    /// Returns a pointer to the Unicode character buffer that serves
1999    /// as `string`'s backing store, which will be deallocated when
2000    /// `string` is deallocated.
2001    pub fn JSStringGetCharactersPtr(string: JSStringRef) -> *const JSChar;
2002
2003    /// Returns the maximum number of bytes a JavaScript string will
2004    /// take up if converted into a null-terminated UTF8 string.
2005    ///
2006    /// * `string`: The [`JSStringRef`] whose maximum converted size (in bytes)
2007    ///   you want to know.
2008    ///
2009    /// Returns the maximum number of bytes that could be required to
2010    /// convert `string` into a null-terminated UTF8 string. The number
2011    /// of bytes that the conversion actually ends up requiring could
2012    /// be less than this, but never more.
2013    pub fn JSStringGetMaximumUTF8CStringSize(string: JSStringRef) -> usize;
2014
2015    /// Converts a JavaScript string into a null-terminated UTF8 string,
2016    /// and copies the result into an external byte buffer.
2017    ///
2018    /// * `string`: The source [`JSStringRef`].
2019    /// * `buffer`: The destination byte buffer into which to copy a
2020    ///   null-terminated UTF8 representation of `string`. On return,
2021    ///   `buffer` contains a UTF8 string representation of `string`. If
2022    ///   `bufferSize` is too small, `buffer` will contain only
2023    ///   partial results. If `buffer` is not at least `bufferSize`
2024    ///   bytes in size, behavior is undefined.
2025    /// * `bufferSize`: The size of the external buffer in bytes.
2026    ///
2027    /// Returns the number of bytes written into buffer (including the null-terminator byte).
2028    pub fn JSStringGetUTF8CString(
2029        string: JSStringRef,
2030        buffer: *mut ::std::os::raw::c_char,
2031        bufferSize: usize,
2032    ) -> usize;
2033
2034    /// Tests whether two JavaScript strings match.
2035    ///
2036    /// * `a`: The first [`JSStringRef`] to test.
2037    /// * `b`: The second [`JSStringRef`] to test.
2038    ///
2039    /// Returns `true` if the two strings match, otherwise `false`.
2040    pub fn JSStringIsEqual(a: JSStringRef, b: JSStringRef) -> bool;
2041
2042    /// Tests whether a JavaScript string matches a null-terminated
2043    /// UTF8 string.
2044    ///
2045    /// * `a`: The [`JSStringRef`] to test.
2046    /// * `b`: The null-terminated UTF8 string to test.
2047    ///
2048    /// Returns `true` if the two strings match, otherwise `false`.
2049    pub fn JSStringIsEqualToUTF8CString(a: JSStringRef, b: *const ::std::os::raw::c_char) -> bool;
2050
2051    /// Creates a JavaScript Typed Array object with the given number of elements.
2052    ///
2053    /// * `ctx`: The execution context to use.
2054    /// * `arrayType`: A value identifying the type of array to
2055    ///   create. If `arrayType` is `JSTypedArrayType::None` or
2056    ///   `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned.
2057    /// * `length`: The number of elements to be in the new Typed Array.
2058    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2059    ///   an exception, if any. Pass `NULL` if you do not care to
2060    ///   store an exception.
2061    ///
2062    /// Returns a [`JSObjectRef`] that is a Typed Array with all elements set to
2063    /// zero or `NULL` if there was an error.
2064    pub fn JSObjectMakeTypedArray(
2065        ctx: JSContextRef,
2066        arrayType: JSTypedArrayType,
2067        length: usize,
2068        exception: *mut JSValueRef,
2069    ) -> JSObjectRef;
2070
2071    /// Creates a JavaScript Typed Array object from an existing pointer.
2072    ///
2073    /// * `ctx`: The execution context to use.
2074    /// * `arrayType`: A value identifying the type of array to
2075    ///   create. If `arrayType` is `JSTypedArrayType::None` or
2076    ///   `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned.
2077    /// * `bytes`: A pointer to the byte buffer to be used as the backing store
2078    ///   of the Typed Array object.
2079    /// * `byteLength`: The number of bytes pointed to by the parameter bytes.
2080    /// * `bytesDeallocator`: The allocator to use to deallocate the external
2081    ///    buffer when the `JSTypedArrayData` object is deallocated.
2082    /// * `deallocatorContext`: A pointer to pass back to the deallocator.
2083    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2084    ///   an exception, if any. Pass `NULL` if you do not care to
2085    ///   store an exception.
2086    ///
2087    /// Returns a [`JSObjectRef`] Typed Array whose backing store is the same as
2088    /// the one pointed to by `bytes` or `NULL` if there was an error.
2089    ///
2090    /// If an exception is thrown during this function the `bytesDeallocator`
2091    /// will always be called.
2092    pub fn JSObjectMakeTypedArrayWithBytesNoCopy(
2093        ctx: JSContextRef,
2094        arrayType: JSTypedArrayType,
2095        bytes: *mut ::std::os::raw::c_void,
2096        byteLength: usize,
2097        bytesDeallocator: JSTypedArrayBytesDeallocator,
2098        deallocatorContext: *mut ::std::os::raw::c_void,
2099        exception: *mut JSValueRef,
2100    ) -> JSObjectRef;
2101
2102    /// Creates a JavaScript Typed Array object from an existing
2103    /// JavaScript Array Buffer object.
2104    ///
2105    /// * `ctx`: The execution context to use.
2106    /// * `arrayType`: A value identifying the type of array to
2107    ///   create. If `arrayType` is `JSTypedArrayType::None` or
2108    ///   `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned.
2109    /// * `buffer`: An Array Buffer object that should be used as the
2110    ///   backing store for the created JavaScript Typed Array object.
2111    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2112    ///   an exception, if any. Pass `NULL` if you do not care to
2113    ///   store an exception.
2114    ///
2115    /// Returns a [`JSObjectRef`] that is a Typed Array or `NULL` if there
2116    /// was an error. The backing store of the Typed Array will be `buffer`.
2117    pub fn JSObjectMakeTypedArrayWithArrayBuffer(
2118        ctx: JSContextRef,
2119        arrayType: JSTypedArrayType,
2120        buffer: JSObjectRef,
2121        exception: *mut JSValueRef,
2122    ) -> JSObjectRef;
2123
2124    /// Creates a JavaScript Typed Array object from an existing
2125    /// JavaScript Array Buffer object with the given offset and
2126    /// length.
2127    ///
2128    /// * `ctx`: The execution context to use.
2129    /// * `arrayType`: A value identifying the type of array to
2130    ///   create. If `arrayType` is `JSTypedArrayType::None` or
2131    ///   `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned.
2132    /// * `buffer`: An Array Buffer object that should be used as the
2133    ///   backing store for the created JavaScript Typed Array object.
2134    /// * `byteOffset`: The byte offset for the created Typed Array.
2135    ///   `byteOffset` should aligned with the element size of `arrayType`.
2136    /// * `length`: The number of elements to include in the Typed Array.
2137    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2138    ///   an exception, if any. Pass `NULL` if you do not care to
2139    ///   store an exception.
2140    ///
2141    /// Returns a [`JSObjectRef`] that is a Typed Array or `NULL` if there
2142    /// was an error. The backing store of the Typed Array will be `buffer`.
2143    pub fn JSObjectMakeTypedArrayWithArrayBufferAndOffset(
2144        ctx: JSContextRef,
2145        arrayType: JSTypedArrayType,
2146        buffer: JSObjectRef,
2147        byteOffset: usize,
2148        length: usize,
2149        exception: *mut JSValueRef,
2150    ) -> JSObjectRef;
2151
2152    /// Returns a temporary pointer to the backing store of a
2153    /// JavaScript Typed Array object.
2154    ///
2155    /// * `ctx`: The execution context to use.
2156    /// * `object`: The Typed Array object whose backing store pointer
2157    ///   to return.
2158    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2159    ///   an exception, if any. Pass `NULL` if you do not care to
2160    ///   store an exception.
2161    ///
2162    /// Returns a pointer to the raw data buffer that serves as `object`'s
2163    /// backing store or `NULL` if object is not a Typed Array object.
2164    ///
2165    /// The pointer returned by this function is temporary and is not
2166    /// guaranteed to remain valid across JavaScriptCore API calls.
2167    pub fn JSObjectGetTypedArrayBytesPtr(
2168        ctx: JSContextRef,
2169        object: JSObjectRef,
2170        exception: *mut JSValueRef,
2171    ) -> *mut ::std::os::raw::c_void;
2172
2173    /// Returns the length of a JavaScript Typed Array object.
2174    ///
2175    /// * `ctx`: The execution context to use.
2176    /// * `object`: The Typed Array object whose length to return.
2177    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2178    ///   an exception, if any. Pass `NULL` if you do not care to
2179    ///   store an exception.
2180    ///
2181    /// Returns the length of the Typed Array object or `0` if the object
2182    /// is not a Typed Array object.
2183    pub fn JSObjectGetTypedArrayLength(
2184        ctx: JSContextRef,
2185        object: JSObjectRef,
2186        exception: *mut JSValueRef,
2187    ) -> usize;
2188
2189    /// Returns the byte length of a JavaScript Typed Array object.
2190    ///
2191    /// * `ctx`: The execution context to use.
2192    /// * `object`: The Typed Array object whose byte length to return.
2193    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2194    ///   an exception, if any. Pass `NULL` if you do not care to
2195    ///   store an exception.
2196    ///
2197    /// Returns the byte length of the Typed Array object or `0` if the
2198    /// object is not a Typed Array object.
2199    pub fn JSObjectGetTypedArrayByteLength(
2200        ctx: JSContextRef,
2201        object: JSObjectRef,
2202        exception: *mut JSValueRef,
2203    ) -> usize;
2204
2205    /// Returns the byte offset of a JavaScript Typed Array object.
2206    ///
2207    /// * `ctx`: The execution context to use.
2208    /// * `object`: The Typed Array object whose byte offset to return.
2209    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2210    ///   an exception, if any. Pass `NULL` if you do not care to
2211    ///   store an exception.
2212    ///
2213    /// Returns the byte offset of the Typed Array object or `0` if the
2214    /// object is not a Typed Array object.
2215    pub fn JSObjectGetTypedArrayByteOffset(
2216        ctx: JSContextRef,
2217        object: JSObjectRef,
2218        exception: *mut JSValueRef,
2219    ) -> usize;
2220
2221    /// Returns the JavaScript Array Buffer object that is used as the
2222    /// backing of a JavaScript Typed Array object.
2223    ///
2224    /// * `ctx`: The execution context to use.
2225    /// * `object`: The [`JSObjectRef`] whose Typed Array type data pointer
2226    ///   to obtain.
2227    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2228    ///   an exception, if any. Pass `NULL` if you do not care to
2229    ///   store an exception.
2230    ///
2231    /// Returns a [`JSObjectRef`] with a [`JSTypedArrayType`] of
2232    /// `JSTypedArrayType::ArrayBuffer` or `NULL` if object is not
2233    /// a Typed Array.
2234    pub fn JSObjectGetTypedArrayBuffer(
2235        ctx: JSContextRef,
2236        object: JSObjectRef,
2237        exception: *mut JSValueRef,
2238    ) -> JSObjectRef;
2239
2240    /// Creates a JavaScript Array Buffer object from an existing pointer.
2241    ///
2242    /// * `ctx`: The execution context to use.
2243    /// * `bytes`: A pointer to the byte buffer to be used as the backing
2244    ///   store of the Typed Array object.
2245    /// * `byteLength`: The number of bytes pointed to by the parameter `bytes`.
2246    /// * `bytesDeallocator`: The allocator to use to deallocate the
2247    ///   external buffer when the Typed Array data object is deallocated.
2248    /// * `deallocatorContext`: A pointer to pass back to the deallocator.
2249    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2250    ///   an exception, if any. Pass `NULL` if you do not care to
2251    ///   store an exception.
2252    ///
2253    /// Returns a [`JSObjectRef`] Array Buffer whose backing store is
2254    /// the same as the one pointed to by `bytes` or `NULL` if there
2255    /// was an error.
2256    ///
2257    /// If an exception is thrown during this function the `bytesDeallocator`
2258    /// will always be called.
2259    pub fn JSObjectMakeArrayBufferWithBytesNoCopy(
2260        ctx: JSContextRef,
2261        bytes: *mut ::std::os::raw::c_void,
2262        byteLength: usize,
2263        bytesDeallocator: JSTypedArrayBytesDeallocator,
2264        deallocatorContext: *mut ::std::os::raw::c_void,
2265        exception: *mut JSValueRef,
2266    ) -> JSObjectRef;
2267
2268    /// Returns a pointer to the data buffer that serves as the backing
2269    /// store for a JavaScript Typed Array object.
2270    ///
2271    /// * `ctx`: The execution context to use.
2272    /// * `object`: The Array Buffer object whose internal backing
2273    ///   store pointer to return.
2274    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2275    ///   an exception, if any. Pass `NULL` if you do not care to
2276    ///   store an exception.
2277    ///
2278    /// Returns a pointer to the raw data buffer that serves as
2279    /// `object`'s backing store or `NULL` if `object` is not an
2280    /// Array Buffer object.
2281    ///
2282    /// The pointer returned by this function is temporary and is not
2283    /// guaranteed to remain valid across JavaScriptCore API calls.
2284    pub fn JSObjectGetArrayBufferBytesPtr(
2285        ctx: JSContextRef,
2286        object: JSObjectRef,
2287        exception: *mut JSValueRef,
2288    ) -> *mut ::std::os::raw::c_void;
2289
2290    /// Returns the number of bytes in a JavaScript data object.
2291    ///
2292    /// * `ctx`: The execution context to use.
2293    /// * `object`: The JS Array Buffer object whose length in bytes to return.
2294    /// * `exception`: A pointer to a [`JSValueRef`] in which to store
2295    ///   an exception, if any. Pass `NULL` if you do not care to
2296    ///   store an exception.
2297    ///
2298    /// Returns the number of bytes stored in the data `object`.
2299    pub fn JSObjectGetArrayBufferByteLength(
2300        ctx: JSContextRef,
2301        object: JSObjectRef,
2302        exception: *mut JSValueRef,
2303    ) -> usize;
2304}