objc2-javascript-core 0.3.2

Bindings to the JavaScriptCore framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributenone?language=objc)
pub const kJSPropertyAttributeNone: c_uint = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributereadonly?language=objc)
pub const kJSPropertyAttributeReadOnly: c_uint = 1 << 1;
/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributedontenum?language=objc)
pub const kJSPropertyAttributeDontEnum: c_uint = 1 << 2;
/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjspropertyattributedontdelete?language=objc)
pub const kJSPropertyAttributeDontDelete: c_uint = 1 << 3;

/// A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jspropertyattributes?language=objc)
pub type JSPropertyAttributes = c_uint;

/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjsclassattributenone?language=objc)
pub const kJSClassAttributeNone: c_uint = 0;
/// [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjsclassattributenoautomaticprototype?language=objc)
pub const kJSClassAttributeNoAutomaticPrototype: c_uint = 1 << 1;

/// A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsclassattributes?language=objc)
pub type JSClassAttributes = c_uint;

/// The callback invoked when an object is first created.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `object`: The JSObject being created.
///
/// If you named your function Initialize, you would declare it like this:
///
/// void Initialize(JSContextRef ctx, JSObjectRef object);
///
/// Unlike the other object callbacks, the initialize callback is called on the least
/// derived class (the parent class) first, and the most derived class last.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectinitializecallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectInitializeCallback =
    Option<unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef)>;

/// The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
///
/// Parameter `object`: The JSObject being finalized.
///
/// If you named your function Finalize, you would declare it like this:
///
/// void Finalize(JSObjectRef object);
///
/// The finalize callback is called on the most derived class first, and the least
/// derived class (the parent class) last.
///
/// You must not call any function that may cause a garbage collection or an allocation
/// of a garbage collected object from within a JSObjectFinalizeCallback. This includes
/// all functions that have a JSContextRef parameter.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectfinalizecallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectFinalizeCallback = Option<unsafe extern "C-unwind" fn(JSObjectRef)>;

/// The callback invoked when determining whether an object has a property.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `object`: The JSObject to search for the property.
///
/// Parameter `propertyName`: A JSString containing the name of the property look up.
///
/// Returns: true if object has the property, otherwise false.
///
/// If you named your function HasProperty, you would declare it like this:
///
/// bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
///
/// If this function returns false, the hasProperty request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
///
/// This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive.
///
/// If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjecthaspropertycallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectHasPropertyCallback =
    Option<unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSStringRef) -> bool>;

/// The callback invoked when getting a property's value.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `object`: The JSObject to search for the property.
///
/// Parameter `propertyName`: A JSString containing the name of the property to get.
///
/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
///
/// Returns: The property's value if object has the property, otherwise NULL.
///
/// If you named your function GetProperty, you would declare it like this:
///
/// JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
///
/// If this function returns NULL, the get request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectgetpropertycallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectGetPropertyCallback = Option<
    unsafe extern "C-unwind" fn(
        JSContextRef,
        JSObjectRef,
        JSStringRef,
        *mut JSValueRef,
    ) -> JSValueRef,
>;

/// The callback invoked when setting a property's value.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `object`: The JSObject on which to set the property's value.
///
/// Parameter `propertyName`: A JSString containing the name of the property to set.
///
/// Parameter `value`: A JSValue to use as the property's value.
///
/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
///
/// Returns: true if the property was set, otherwise false.
///
/// If you named your function SetProperty, you would declare it like this:
///
/// bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
///
/// If this function returns false, the set request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectsetpropertycallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectSetPropertyCallback = Option<
    unsafe extern "C-unwind" fn(
        JSContextRef,
        JSObjectRef,
        JSStringRef,
        JSValueRef,
        *mut JSValueRef,
    ) -> bool,
>;

/// The callback invoked when deleting a property.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `object`: The JSObject in which to delete the property.
///
/// Parameter `propertyName`: A JSString containing the name of the property to delete.
///
/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
///
/// Returns: true if propertyName was successfully deleted, otherwise false.
///
/// If you named your function DeleteProperty, you would declare it like this:
///
/// bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
///
/// If this function returns false, the delete request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectdeletepropertycallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectDeletePropertyCallback = Option<
    unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSStringRef, *mut JSValueRef) -> bool,
>;

/// The callback invoked when collecting the names of an object's properties.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `object`: The JSObject whose property names are being collected.
///
/// Parameter `propertyNames`: A JavaScript property name accumulator in which to accumulate the names of object's properties.
///
/// If you named your function GetPropertyNames, you would declare it like this:
///
/// void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
///
/// Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.
///
/// Use JSPropertyNameAccumulatorAddName to add property names to accumulator. A class's getPropertyNames callback only needs to provide the names of properties that the class vends through a custom getProperty or setProperty callback. Other properties, including statically declared properties, properties vended by other classes, and properties belonging to object's prototype, are added independently.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectgetpropertynamescallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectGetPropertyNamesCallback =
    Option<unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSPropertyNameAccumulatorRef)>;

/// The callback invoked when an object is called as a function.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `function`: A JSObject that is the function being called.
///
/// Parameter `thisObject`: A JSObject that is the 'this' variable in the function's scope.
///
/// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
///
/// Parameter `arguments`: A JSValue array of the  arguments passed to the function.
///
/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
///
/// Returns: A JSValue that is the function's return value.
///
/// If you named your function CallAsFunction, you would declare it like this:
///
/// JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
///
/// If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.
///
/// If this callback is NULL, calling your object as a function will throw an exception.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectcallasfunctioncallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectCallAsFunctionCallback = Option<
    unsafe extern "C-unwind" fn(
        JSContextRef,
        JSObjectRef,
        JSObjectRef,
        usize,
        *mut JSValueRef,
        *mut JSValueRef,
    ) -> JSValueRef,
>;

/// The callback invoked when an object is used as a constructor in a 'new' expression.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `constructor`: A JSObject that is the constructor being called.
///
/// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
///
/// Parameter `arguments`: A JSValue array of the  arguments passed to the function.
///
/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
///
/// Returns: A JSObject that is the constructor's return value.
///
/// If you named your function CallAsConstructor, you would declare it like this:
///
/// JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
///
/// If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.
///
/// If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectcallasconstructorcallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectCallAsConstructorCallback = Option<
    unsafe extern "C-unwind" fn(
        JSContextRef,
        JSObjectRef,
        usize,
        *mut JSValueRef,
        *mut JSValueRef,
    ) -> JSObjectRef,
>;

/// hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `constructor`: The JSObject that is the target of the 'instanceof' expression.
///
/// Parameter `possibleInstance`: The JSValue being tested to determine if it is an instance of constructor.
///
/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
///
/// Returns: true if possibleInstance is an instance of constructor, otherwise false.
///
/// If you named your function HasInstance, you would declare it like this:
///
/// bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
///
/// If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.
///
/// If this callback is NULL, 'instanceof' expressions that target your object will return false.
///
/// Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjecthasinstancecallback?language=objc)
#[cfg(feature = "JSBase")]
pub type JSObjectHasInstanceCallback = Option<
    unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSValueRef, *mut JSValueRef) -> bool,
>;

/// The callback invoked when converting an object to a particular JavaScript type.
///
/// Parameter `ctx`: The execution context to use.
///
/// Parameter `object`: The JSObject to convert.
///
/// Parameter `type`: A JSType specifying the JavaScript type to convert to.
///
/// Parameter `exception`: A pointer to a JSValueRef in which to return an exception, if any.
///
/// Returns: The objects's converted value, or NULL if the object was not converted.
///
/// If you named your function ConvertToType, you would declare it like this:
///
/// JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
///
/// If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
///
/// This function is only invoked when converting an object to number or string. An object converted to boolean is 'true.' An object converted to object is itself.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsobjectconverttotypecallback?language=objc)
#[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
pub type JSObjectConvertToTypeCallback = Option<
    unsafe extern "C-unwind" fn(JSContextRef, JSObjectRef, JSType, *mut JSValueRef) -> JSValueRef,
>;

/// This structure describes a statically declared value property.
/// Field: name A null-terminated UTF8 string containing the property's name.
/// Field: getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
/// Field: setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.
/// Field: attributes A logically ORed set of JSPropertyAttributes to give to the property.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsstaticvalue?language=objc)
#[cfg(feature = "JSBase")]
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct JSStaticValue {
    pub name: *const c_char,
    pub getProperty: JSObjectGetPropertyCallback,
    pub setProperty: JSObjectSetPropertyCallback,
    pub attributes: JSPropertyAttributes,
}

#[cfg(all(feature = "JSBase", feature = "objc2"))]
unsafe impl Encode for JSStaticValue {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <*const c_char>::ENCODING,
            <JSObjectGetPropertyCallback>::ENCODING,
            Encoding::Pointer(&Encoding::Unknown),
            <JSPropertyAttributes>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "JSBase", feature = "objc2"))]
unsafe impl RefEncode for JSStaticValue {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// This structure describes a statically declared function property.
/// Field: name A null-terminated UTF8 string containing the property's name.
/// Field: callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
/// Field: attributes A logically ORed set of JSPropertyAttributes to give to the property.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsstaticfunction?language=objc)
#[cfg(feature = "JSBase")]
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct JSStaticFunction {
    pub name: *const c_char,
    pub callAsFunction: JSObjectCallAsFunctionCallback,
    pub attributes: JSPropertyAttributes,
}

#[cfg(all(feature = "JSBase", feature = "objc2"))]
unsafe impl Encode for JSStaticFunction {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <*const c_char>::ENCODING,
            <JSObjectCallAsFunctionCallback>::ENCODING,
            <JSPropertyAttributes>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "JSBase", feature = "objc2"))]
unsafe impl RefEncode for JSStaticFunction {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
/// Field: version The version number of this structure. The current version is 0.
/// Field: attributes A logically ORed set of JSClassAttributes to give to the class.
/// Field: className A null-terminated UTF8 string containing the class's name.
/// Field: parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
/// Field: staticValues A JSStaticValue array containing the class's statically declared value properties. Pass NULL to specify no statically declared value properties. The array must be terminated by a JSStaticValue whose name field is NULL.
/// Field: staticFunctions A JSStaticFunction array containing the class's statically declared function properties. Pass NULL to specify no statically declared function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.
/// Field: initialize The callback invoked when an object is first created. Use this callback to initialize the object.
/// Field: finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for the object, and perform other cleanup.
/// Field: hasProperty The callback invoked when determining whether an object has a property. If this field is NULL, getProperty is called instead. The hasProperty callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value is expensive.
/// Field: getProperty The callback invoked when getting a property's value.
/// Field: setProperty The callback invoked when setting a property's value.
/// Field: deleteProperty The callback invoked when deleting a property.
/// Field: getPropertyNames The callback invoked when collecting the names of an object's properties.
/// Field: callAsFunction The callback invoked when an object is called as a function.
/// Field: hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
/// Field: callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
/// Field: convertToType The callback invoked when converting an object to a particular JavaScript type.
///
/// The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties autmatically service requests like getProperty, setProperty, and getPropertyNames. Property access callbacks are required only to implement unusual properties, like array indexes, whose names are not known at compile-time.
///
/// If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
///
/// JSStaticValue StaticValueArray[] = {
/// { "X", GetX, SetX, kJSPropertyAttributeNone },
/// { 0, 0, 0, 0 }
/// };
///
/// Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects.
///
/// A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
///
/// It is not possible to use JS subclassing with objects created from a class definition that sets callAsConstructor by default. Subclassing is supported via the JSObjectMakeConstructor function, however.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/jsclassdefinition?language=objc)
#[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct JSClassDefinition {
    pub version: c_int,
    pub attributes: JSClassAttributes,
    pub className: *const c_char,
    pub parentClass: JSClassRef,
    pub staticValues: *const JSStaticValue,
    pub staticFunctions: *const JSStaticFunction,
    pub initialize: JSObjectInitializeCallback,
    pub finalize: JSObjectFinalizeCallback,
    pub hasProperty: JSObjectHasPropertyCallback,
    pub getProperty: JSObjectGetPropertyCallback,
    pub setProperty: JSObjectSetPropertyCallback,
    pub deleteProperty: JSObjectDeletePropertyCallback,
    pub getPropertyNames: JSObjectGetPropertyNamesCallback,
    pub callAsFunction: JSObjectCallAsFunctionCallback,
    pub callAsConstructor: JSObjectCallAsConstructorCallback,
    pub hasInstance: JSObjectHasInstanceCallback,
    pub convertToType: JSObjectConvertToTypeCallback,
}

#[cfg(all(feature = "JSBase", feature = "JSValueRef", feature = "objc2"))]
unsafe impl Encode for JSClassDefinition {
    const ENCODING: Encoding = Encoding::Struct(
        "?",
        &[
            <c_int>::ENCODING,
            <JSClassAttributes>::ENCODING,
            <*const c_char>::ENCODING,
            <JSClassRef>::ENCODING,
            <*const JSStaticValue>::ENCODING,
            <*const JSStaticFunction>::ENCODING,
            <JSObjectInitializeCallback>::ENCODING,
            <JSObjectFinalizeCallback>::ENCODING,
            Encoding::Pointer(&Encoding::Unknown),
            <JSObjectGetPropertyCallback>::ENCODING,
            Encoding::Pointer(&Encoding::Unknown),
            Encoding::Pointer(&Encoding::Unknown),
            <JSObjectGetPropertyNamesCallback>::ENCODING,
            <JSObjectCallAsFunctionCallback>::ENCODING,
            <JSObjectCallAsConstructorCallback>::ENCODING,
            Encoding::Pointer(&Encoding::Unknown),
            <JSObjectConvertToTypeCallback>::ENCODING,
        ],
    );
}

#[cfg(all(feature = "JSBase", feature = "JSValueRef", feature = "objc2"))]
unsafe impl RefEncode for JSClassDefinition {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
    ///
    /// Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
    ///
    /// JSClassDefinition definition = kJSClassDefinitionEmpty;
    /// definition.finalize = Finalize;
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/javascriptcore/kjsclassdefinitionempty?language=objc)
    #[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
    pub static kJSClassDefinitionEmpty: JSClassDefinition;
}

extern "C-unwind" {
    /// Creates a JavaScript class suitable for use with JSObjectMake.
    ///
    /// Parameter `definition`: A JSClassDefinition that defines the class.
    ///
    /// Returns: A JSClass with the given definition. Ownership follows the Create Rule.
    ///
    /// # Safety
    ///
    /// `definition` must be a valid pointer.
    #[cfg(all(feature = "JSBase", feature = "JSValueRef"))]
    pub fn JSClassCreate(definition: *const JSClassDefinition) -> JSClassRef;
}

extern "C-unwind" {
    /// Retains a JavaScript class.
    ///
    /// Parameter `jsClass`: The JSClass to retain.
    ///
    /// Returns: A JSClass that is the same as jsClass.
    ///
    /// # Safety
    ///
    /// `js_class` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSClassRetain(js_class: JSClassRef) -> JSClassRef;
}

extern "C-unwind" {
    /// Releases a JavaScript class.
    ///
    /// Parameter `jsClass`: The JSClass to release.
    ///
    /// # Safety
    ///
    /// `js_class` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSClassRelease(js_class: JSClassRef);
}

extern "C-unwind" {
    /// Creates a JavaScript object.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `jsClass`: The JSClass to assign to the object. Pass NULL to use the default object class.
    ///
    /// Parameter `data`: A void* to set as the object's private data. Pass NULL to specify no private data.
    ///
    /// Returns: A JSObject with the given class and private data.
    ///
    /// The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data.
    ///
    /// data is set on the created object before the intialize methods in its class chain are called. This enables the initialize methods to retrieve and manipulate data through JSObjectGetPrivate.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `js_class` must be a valid pointer.
    /// - `data` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMake(ctx: JSContextRef, js_class: JSClassRef, data: *mut c_void) -> JSObjectRef;
}

extern "C-unwind" {
    /// Convenience method for creating a JavaScript function with a given callback as its implementation.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `name`: A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
    ///
    /// Parameter `callAsFunction`: The JSObjectCallAsFunctionCallback to invoke when the function is called.
    ///
    /// Returns: A JSObject that is a function. The object's prototype will be the default function prototype.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `name` must be a valid pointer.
    /// - `call_as_function` must be implemented correctly.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeFunctionWithCallback(
        ctx: JSContextRef,
        name: JSStringRef,
        call_as_function: JSObjectCallAsFunctionCallback,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Convenience method for creating a JavaScript constructor.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `jsClass`: A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class.
    ///
    /// Parameter `callAsConstructor`: A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
    ///
    /// Returns: A JSObject that is a constructor. The object's prototype will be the default object prototype.
    ///
    /// The default object constructor takes no arguments and constructs an object of class jsClass with no private data. If the constructor is inherited via JS subclassing and the value returned from callAsConstructor was created with jsClass, then the returned object will have it's prototype overridden to the derived class's prototype.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `js_class` must be a valid pointer.
    /// - `call_as_constructor` must be implemented correctly.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeConstructor(
        ctx: JSContextRef,
        js_class: JSClassRef,
        call_as_constructor: JSObjectCallAsConstructorCallback,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Creates a JavaScript Array object.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
    ///
    /// Parameter `arguments`: A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: A JSObject that is an Array.
    ///
    /// The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument
    /// is supplied, this function returns an array with one element.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `arguments` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeArray(
        ctx: JSContextRef,
        argument_count: usize,
        arguments: *mut JSValueRef,
        exception: *mut JSValueRef,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
    ///
    /// Parameter `arguments`: A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: A JSObject that is a Date.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `arguments` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeDate(
        ctx: JSContextRef,
        argument_count: usize,
        arguments: *mut JSValueRef,
        exception: *mut JSValueRef,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
    ///
    /// Parameter `arguments`: A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: A JSObject that is an Error.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `arguments` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeError(
        ctx: JSContextRef,
        argument_count: usize,
        arguments: *mut JSValueRef,
        exception: *mut JSValueRef,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
    ///
    /// Parameter `arguments`: A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: A JSObject that is a RegExp.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `arguments` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeRegExp(
        ctx: JSContextRef,
        argument_count: usize,
        arguments: *mut JSValueRef,
        exception: *mut JSValueRef,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Creates a JavaScript promise object by invoking the provided executor.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `resolve`: A pointer to a JSObjectRef in which to store the resolve function for the new promise. Pass NULL if you do not care to store the resolve callback.
    ///
    /// Parameter `reject`: A pointer to a JSObjectRef in which to store the reject function for the new promise. Pass NULL if you do not care to store the reject callback.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: A JSObject that is a promise or NULL if an exception occurred.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `resolve` must be a valid pointer.
    /// - `reject` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeDeferredPromise(
        ctx: JSContextRef,
        resolve: *mut JSObjectRef,
        reject: *mut JSObjectRef,
        exception: *mut JSValueRef,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Creates a function with a given script as its body.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `name`: A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
    ///
    /// Parameter `parameterCount`: An integer count of the number of parameter names in parameterNames.
    ///
    /// Parameter `parameterNames`: A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
    ///
    /// Parameter `body`: A JSString containing the script to use as the function's body.
    ///
    /// Parameter `sourceURL`: A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
    ///
    /// Parameter `startingLineNumber`: An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
    ///
    /// Returns: A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype.
    ///
    /// Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `name` must be a valid pointer.
    /// - `parameter_names` must be a valid pointer.
    /// - `body` must be a valid pointer.
    /// - `source_url` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectMakeFunction(
        ctx: JSContextRef,
        name: JSStringRef,
        parameter_count: c_uint,
        parameter_names: *mut JSStringRef,
        body: JSStringRef,
        source_url: JSStringRef,
        starting_line_number: c_int,
        exception: *mut JSValueRef,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Gets an object's prototype.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: A JSObject whose prototype you want to get.
    ///
    /// Returns: A JSValue that is the object's prototype.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectGetPrototype(ctx: JSContextRef, object: JSObjectRef) -> JSValueRef;
}

extern "C-unwind" {
    /// Sets an object's prototype.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose prototype you want to set.
    ///
    /// Parameter `value`: A JSValue to set as the object's prototype.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `value` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectSetPrototype(ctx: JSContextRef, object: JSObjectRef, value: JSValueRef);
}

extern "C-unwind" {
    /// Tests whether an object has a given property.
    ///
    /// Parameter `object`: The JSObject to test.
    ///
    /// Parameter `propertyName`: A JSString containing the property's name.
    ///
    /// Returns: true if the object has a property whose name matches propertyName, otherwise false.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_name` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectHasProperty(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_name: JSStringRef,
    ) -> bool;
}

extern "C-unwind" {
    /// Gets a property from an object.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to get.
    ///
    /// Parameter `propertyName`: A JSString containing the property's name.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: The property's value if object has the property, otherwise the undefined value.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_name` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectGetProperty(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_name: JSStringRef,
        exception: *mut JSValueRef,
    ) -> JSValueRef;
}

extern "C-unwind" {
    /// Sets a property on an object.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to set.
    ///
    /// Parameter `propertyName`: A JSString containing the property's name.
    ///
    /// Parameter `value`: A JSValueRef to use as the property's value.
    ///
    /// Parameter `attributes`: A logically ORed set of JSPropertyAttributes to give to the property.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_name` must be a valid pointer.
    /// - `value` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectSetProperty(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_name: JSStringRef,
        value: JSValueRef,
        attributes: JSPropertyAttributes,
        exception: *mut JSValueRef,
    );
}

extern "C-unwind" {
    /// Deletes a property from an object.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to delete.
    ///
    /// Parameter `propertyName`: A JSString containing the property's name.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_name` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectDeleteProperty(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_name: JSStringRef,
        exception: *mut JSValueRef,
    ) -> bool;
}

extern "C-unwind" {
    /// Tests whether an object has a given property using a JSValueRef as the property key.
    ///
    /// Parameter `object`: The JSObject to test.
    ///
    /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: true if the object has a property whose name matches propertyKey, otherwise false.
    ///
    /// This function is the same as performing "propertyKey in object" from JavaScript.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_key` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectHasPropertyForKey(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_key: JSValueRef,
        exception: *mut JSValueRef,
    ) -> bool;
}

extern "C-unwind" {
    /// Gets a property from an object using a JSValueRef as the property key.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to get.
    ///
    /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: The property's value if object has the property key, otherwise the undefined value.
    ///
    /// This function is the same as performing "object[propertyKey]" from JavaScript.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_key` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectGetPropertyForKey(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_key: JSValueRef,
        exception: *mut JSValueRef,
    ) -> JSValueRef;
}

extern "C-unwind" {
    /// Sets a property on an object using a JSValueRef as the property key.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to set.
    ///
    /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
    ///
    /// Parameter `value`: A JSValueRef to use as the property's value.
    ///
    /// Parameter `attributes`: A logically ORed set of JSPropertyAttributes to give to the property.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// This function is the same as performing "object[propertyKey] = value" from JavaScript.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_key` must be a valid pointer.
    /// - `value` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectSetPropertyForKey(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_key: JSValueRef,
        value: JSValueRef,
        attributes: JSPropertyAttributes,
        exception: *mut JSValueRef,
    );
}

extern "C-unwind" {
    /// Deletes a property from an object using a JSValueRef as the property key.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to delete.
    ///
    /// Parameter `propertyKey`: A JSValueRef containing the property key to use when looking up the property.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
    ///
    /// This function is the same as performing "delete object[propertyKey]" from JavaScript.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `property_key` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectDeletePropertyForKey(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_key: JSValueRef,
        exception: *mut JSValueRef,
    ) -> bool;
}

extern "C-unwind" {
    /// Gets a property from an object by numeric index.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to get.
    ///
    /// Parameter `propertyIndex`: An integer value that is the property's name.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: The property's value if object has the property, otherwise the undefined value.
    ///
    /// Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectGetPropertyAtIndex(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_index: c_uint,
        exception: *mut JSValueRef,
    ) -> JSValueRef;
}

extern "C-unwind" {
    /// Sets a property on an object by numeric index.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject whose property you want to set.
    ///
    /// Parameter `propertyIndex`: The property's name as a number.
    ///
    /// Parameter `value`: A JSValue to use as the property's value.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `value` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectSetPropertyAtIndex(
        ctx: JSContextRef,
        object: JSObjectRef,
        property_index: c_uint,
        value: JSValueRef,
        exception: *mut JSValueRef,
    );
}

extern "C-unwind" {
    /// Gets an object's private data.
    ///
    /// Parameter `object`: A JSObject whose private data you want to get.
    ///
    /// Returns: A void* that is the object's private data, if the object has private data, otherwise NULL.
    ///
    /// # Safety
    ///
    /// `object` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectGetPrivate(object: JSObjectRef) -> *mut c_void;
}

extern "C-unwind" {
    /// Sets a pointer to private data on an object.
    ///
    /// Parameter `object`: The JSObject whose private data you want to set.
    ///
    /// Parameter `data`: A void* to set as the object's private data.
    ///
    /// Returns: true if object can store private data, otherwise false.
    ///
    /// The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
    ///
    /// # Safety
    ///
    /// - `object` must be a valid pointer.
    /// - `data` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectSetPrivate(object: JSObjectRef, data: *mut c_void) -> bool;
}

extern "C-unwind" {
    /// Tests whether an object can be called as a function.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject to test.
    ///
    /// Returns: true if the object can be called as a function, otherwise false.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectIsFunction(ctx: JSContextRef, object: JSObjectRef) -> bool;
}

extern "C-unwind" {
    /// Calls an object as a function.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject to call as a function.
    ///
    /// Parameter `thisObject`: The object to use as "this," or NULL to use the global object as "this."
    ///
    /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
    ///
    /// Parameter `arguments`: A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `this_object` must be a valid pointer.
    /// - `arguments` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectCallAsFunction(
        ctx: JSContextRef,
        object: JSObjectRef,
        this_object: JSObjectRef,
        argument_count: usize,
        arguments: *mut JSValueRef,
        exception: *mut JSValueRef,
    ) -> JSValueRef;
}

extern "C-unwind" {
    /// Tests whether an object can be called as a constructor.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject to test.
    ///
    /// Returns: true if the object can be called as a constructor, otherwise false.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectIsConstructor(ctx: JSContextRef, object: JSObjectRef) -> bool;
}

extern "C-unwind" {
    /// Calls an object as a constructor.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The JSObject to call as a constructor.
    ///
    /// Parameter `argumentCount`: An integer count of the number of arguments in arguments.
    ///
    /// Parameter `arguments`: A JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0.
    ///
    /// Parameter `exception`: A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    ///
    /// Returns: The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    /// - `arguments` must be a valid pointer.
    /// - `exception` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectCallAsConstructor(
        ctx: JSContextRef,
        object: JSObjectRef,
        argument_count: usize,
        arguments: *mut JSValueRef,
        exception: *mut JSValueRef,
    ) -> JSObjectRef;
}

extern "C-unwind" {
    /// Gets the names of an object's enumerable properties.
    ///
    /// Parameter `ctx`: The execution context to use.
    ///
    /// Parameter `object`: The object whose property names you want to get.
    ///
    /// Returns: A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
    ///
    /// # Safety
    ///
    /// - `ctx` must be a valid pointer.
    /// - `object` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSObjectCopyPropertyNames(
        ctx: JSContextRef,
        object: JSObjectRef,
    ) -> JSPropertyNameArrayRef;
}

extern "C-unwind" {
    /// Retains a JavaScript property name array.
    ///
    /// Parameter `array`: The JSPropertyNameArray to retain.
    ///
    /// Returns: A JSPropertyNameArray that is the same as array.
    ///
    /// # Safety
    ///
    /// `array` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSPropertyNameArrayRetain(array: JSPropertyNameArrayRef) -> JSPropertyNameArrayRef;
}

extern "C-unwind" {
    /// Releases a JavaScript property name array.
    ///
    /// Parameter `array`: The JSPropetyNameArray to release.
    ///
    /// # Safety
    ///
    /// `array` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSPropertyNameArrayRelease(array: JSPropertyNameArrayRef);
}

extern "C-unwind" {
    /// Gets a count of the number of items in a JavaScript property name array.
    ///
    /// Parameter `array`: The array from which to retrieve the count.
    ///
    /// Returns: An integer count of the number of names in array.
    ///
    /// # Safety
    ///
    /// `array` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSPropertyNameArrayGetCount(array: JSPropertyNameArrayRef) -> usize;
}

extern "C-unwind" {
    /// Gets a property name at a given index in a JavaScript property name array.
    ///
    /// Parameter `array`: The array from which to retrieve the property name.
    ///
    /// Parameter `index`: The index of the property name to retrieve.
    ///
    /// Returns: A JSStringRef containing the property name.
    ///
    /// # Safety
    ///
    /// `array` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSPropertyNameArrayGetNameAtIndex(
        array: JSPropertyNameArrayRef,
        index: usize,
    ) -> JSStringRef;
}

extern "C-unwind" {
    /// Adds a property name to a JavaScript property name accumulator.
    ///
    /// Parameter `accumulator`: The accumulator object to which to add the property name.
    ///
    /// Parameter `propertyName`: The property name to add.
    ///
    /// # Safety
    ///
    /// - `accumulator` must be a valid pointer.
    /// - `property_name` must be a valid pointer.
    #[cfg(feature = "JSBase")]
    pub fn JSPropertyNameAccumulatorAddName(
        accumulator: JSPropertyNameAccumulatorRef,
        property_name: JSStringRef,
    );
}