-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascriptcore-4.1.d.ts
More file actions
1675 lines (1554 loc) · 72.7 KB
/
javascriptcore-4.1.d.ts
File metadata and controls
1675 lines (1554 loc) · 72.7 KB
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
/// <reference path="./gobject-2.0.d.ts" />
/// <reference path="./glib-2.0.d.ts" />
/**
* Type Definitions for Gjs (https://gjs.guide/)
*
* These type definitions are automatically generated, do not edit them by hand.
* If you found a bug fix it in `ts-for-gir` or create a bug report on https://github.com/gjsify/ts-for-gir
*
* The based EJS template file is used for the generated .d.ts file of each GIR module like Gtk-4.0, GObject-2.0, ...
*/
declare module 'gi://JavaScriptCore?version=4.1' {
// Module dependencies
import type GObject from 'gi://GObject?version=2.0';
import type GLib from 'gi://GLib?version=2.0';
export namespace JavaScriptCore {
/**
* JavaScriptCore-4.1
*/
/**
* Enum values to specify a mode to check for syntax errors in `jsc_context_check_syntax()`.
* @gir-type Enum
*/
enum CheckSyntaxMode {
/**
* mode to check syntax of a script
*/
SCRIPT,
/**
* mode to check syntax of a module
*/
MODULE,
}
/**
* Enum values to specify the result of `jsc_context_check_syntax()`.
* @gir-type Enum
*/
enum CheckSyntaxResult {
/**
* no errors
*/
SUCCESS,
/**
* recoverable syntax error
*/
RECOVERABLE_ERROR,
/**
* irrecoverable syntax error
*/
IRRECOVERABLE_ERROR,
/**
* unterminated literal error
*/
UNTERMINATED_LITERAL_ERROR,
/**
* out of memory error
*/
OUT_OF_MEMORY_ERROR,
/**
* stack overflow error
*/
STACK_OVERFLOW_ERROR,
}
/**
* Enum values for options types.
* @gir-type Enum
* @since 2.24
*/
enum OptionType {
/**
* A `gboolean` option type.
*/
BOOLEAN,
/**
* A `gint` option type.
*/
INT,
/**
* A `guint` option type.
*/
UINT,
/**
* A `gsize` options type.
*/
SIZE,
/**
* A `gdouble` options type.
*/
DOUBLE,
/**
* A string option type.
*/
STRING,
/**
* A range string option type.
*/
RANGE_STRING,
}
/**
* Possible types of the elements contained in a typed array.
* @gir-type Enum
* @since 2.38
*/
enum TypedArrayType {
/**
* Not a typed array, or type unsupported.
*/
NONE,
/**
* Array elements are 8-bit signed integers (int8_t).
*/
INT8,
/**
* Array elements are 16-bit signed integers (int16_t).
*/
INT16,
/**
* Array elements are 32-bit signed integers (int32_t).
*/
INT32,
/**
* Array elements are 64-bit signed integers (int64_t).
*/
INT64,
/**
* Array elements are 8-bit unsigned integers (uint8_t).
*/
UINT8,
/**
* Array elements are 8-bit unsigned integers (uint8_t).
*/
UINT8_CLAMPED,
/**
* Array elements are 16-bit unsigned integers (uint16_t).
*/
UINT16,
/**
* Array elements are 32-bit unsigned integers (uint32_t).
*/
UINT32,
/**
* Array elements are 64-bit unsigned integers (uint64_t).
*/
UINT64,
/**
* Array elements are 32-bit floating point numbers (float).
*/
FLOAT32,
/**
* Array elements are 64-bit floating point numbers (double).
*/
FLOAT64,
}
/**
* Like `jsc_get_major_version()`, but from the headers used at
* application compile time, rather than from the library linked
* against at application run time.
*/
const MAJOR_VERSION: number;
/**
* Like `jsc_get_micro_version()`, but from the headers used at
* application compile time, rather than from the library linked
* against at application run time.
*/
const MICRO_VERSION: number;
/**
* Like `jsc_get_minor_version()`, but from the headers used at
* application compile time, rather than from the library linked
* against at application run time.
*/
const MINOR_VERSION: number;
/**
* Allows the DFG JIT to be used if `true`.
* Option type: {@link JavaScriptCore.OptionType.BOOLEAN}
* Default value: `true`.
* @since 2.24
*/
const OPTIONS_USE_DFG: string;
/**
* Allows the FTL JIT to be used if `true`.
* Option type: {@link JavaScriptCore.OptionType.BOOLEAN}
* Default value: `true`.
* @since 2.24
*/
const OPTIONS_USE_FTL: string;
/**
* Allows the executable pages to be allocated for JIT and thunks if `true`.
* Option type: {@link JavaScriptCore.OptionType.BOOLEAN}
* Default value: `true`.
* @since 2.24
*/
const OPTIONS_USE_JIT: string;
/**
* Allows the LLINT to be used if `true`.
* Option type: {@link JavaScriptCore.OptionType.BOOLEAN}
* Default value: `true`.
* @since 2.24
*/
const OPTIONS_USE_LLINT: string;
/**
* Returns the major version number of the JavaScriptCore library.
* (e.g. in JavaScriptCore version 1.8.3 this is 1.)
*
* This function is in the library, so it represents the JavaScriptCore library
* your code is running against. Contrast with the #JSC_MAJOR_VERSION
* macro, which represents the major version of the JavaScriptCore headers you
* have included when compiling your code.
* @returns the major version number of the JavaScriptCore library
*/
function get_major_version(): number;
/**
* Returns the micro version number of the JavaScriptCore library.
* (e.g. in JavaScriptCore version 1.8.3 this is 3.)
*
* This function is in the library, so it represents the JavaScriptCore library
* your code is running against. Contrast with the #JSC_MICRO_VERSION
* macro, which represents the micro version of the JavaScriptCore headers you
* have included when compiling your code.
* @returns the micro version number of the JavaScriptCore library
*/
function get_micro_version(): number;
/**
* Returns the minor version number of the JavaScriptCore library.
* (e.g. in JavaScriptCore version 1.8.3 this is 8.)
*
* This function is in the library, so it represents the JavaScriptCore library
* your code is running against. Contrast with the #JSC_MINOR_VERSION
* macro, which represents the minor version of the JavaScriptCore headers you
* have included when compiling your code.
* @returns the minor version number of the JavaScriptCore library
*/
function get_minor_version(): number;
/**
* Iterates all available options calling `function` for each one. Iteration can
* stop early if `function` returns `false`.
* @param _function a {@link JavaScriptCore.OptionsFunc} callback
* @since 2.24
*/
function options_foreach(_function: OptionsFunc): void;
/**
* Get `option` as a `gboolean` value.
* @param option the option identifier
* @returns `true` if `value` has been set or `false` if the option doesn't exist
* @since 2.24
*/
function options_get_boolean(option: string): [boolean, boolean];
/**
* Get `option` as a `gdouble` value.
* @param option the option identifier
* @returns `true` if `value` has been set or `false` if the option doesn't exist
* @since 2.24
*/
function options_get_double(option: string): [boolean, number];
/**
* Get `option` as a `gint` value.
* @param option the option identifier
* @returns `true` if `value` has been set or `false` if the option doesn't exist
* @since 2.24
*/
function options_get_int(option: string): [boolean, number];
/**
* Create a {@link GLib.OptionGroup} to handle JSCOptions as command line arguments.
* The options will be exposed as command line arguments with the form
* <emphasis>--jsc-<option>=<value></emphasis>.
* Each entry in the returned {@link GLib.OptionGroup} is configured to apply the
* corresponding option during command line parsing. Applications only need to
* pass the returned group to `g_option_context_add_group()`, and the rest will
* be taken care for automatically.
* @returns a {@link GLib.OptionGroup} for the JSCOptions
* @since 2.24
*/
function options_get_option_group(): GLib.OptionGroup;
/**
* Get `option` as a range string. The string must be in the
* format <emphasis>[!]<low>[:<high>]</emphasis> where low and high are `guint` values.
* Values between low and high (both included) will be considered in
* the range, unless <emphasis>!</emphasis> is used to invert the range.
* @param option the option identifier
* @returns `true` if `value` has been set or `false` if the option doesn't exist
* @since 2.24
*/
function options_get_range_string(option: string): [boolean, string];
/**
* Get `option` as a `gsize` value.
* @param option the option identifier
* @returns `true` if `value` has been set or `false` if the option doesn't exist
* @since 2.24
*/
function options_get_size(option: string): [boolean, number];
/**
* Get `option` as a string.
* @param option the option identifier
* @returns `true` if `value` has been set or `false` if the option doesn't exist
* @since 2.24
*/
function options_get_string(option: string): [boolean, string];
/**
* Get `option` as a `guint` value.
* @param option the option identifier
* @returns `true` if `value` has been set or `false` if the option doesn't exist
* @since 2.24
*/
function options_get_uint(option: string): [boolean, number];
/**
* Set `option` as a `gboolean` value.
* @param option the option identifier
* @param value the value to set
* @returns `true` if option was correctly set or `false` otherwise.
* @since 2.24
*/
function options_set_boolean(option: string, value: boolean): boolean;
/**
* Set `option` as a `gdouble` value.
* @param option the option identifier
* @param value the value to set
* @returns `true` if option was correctly set or `false` otherwise.
* @since 2.24
*/
function options_set_double(option: string, value: number): boolean;
/**
* Set `option` as a `gint` value.
* @param option the option identifier
* @param value the value to set
* @returns `true` if option was correctly set or `false` otherwise.
* @since 2.24
*/
function options_set_int(option: string, value: number): boolean;
/**
* Set `option` as a range string. The string must be in the
* format <emphasis>[!]<low>[:<high>]</emphasis> where low and high are `guint` values.
* Values between low and high (both included) will be considered in
* the range, unless <emphasis>!</emphasis> is used to invert the range.
* @param option the option identifier
* @param value the value to set
* @returns `true` if option was correctly set or `false` otherwise.
* @since 2.24
*/
function options_set_range_string(option: string, value: string): boolean;
/**
* Set `option` as a `gsize` value.
* @param option the option identifier
* @param value the value to set
* @returns `true` if option was correctly set or `false` otherwise.
* @since 2.24
*/
function options_set_size(option: string, value: bigint | number): boolean;
/**
* Set `option` as a string.
* @param option the option identifier
* @param value the value to set
* @returns `true` if option was correctly set or `false` otherwise.
* @since 2.24
*/
function options_set_string(option: string, value: string): boolean;
/**
* Set `option` as a `guint` value.
* @param option the option identifier
* @param value the value to set
* @returns `true` if option was correctly set or `false` otherwise.
* @since 2.24
*/
function options_set_uint(option: string, value: number): boolean;
/**
* @gir-type Callback
*/
interface ClassDeletePropertyFunction {
(jsc_class: Class, context: Context, instance: any | null, name: string): boolean;
}
/**
* @gir-type Callback
*/
interface ClassEnumeratePropertiesFunction {
(jsc_class: Class, context: Context, instance?: any | null): string[] | null;
}
/**
* @gir-type Callback
*/
interface ClassGetPropertyFunction {
(jsc_class: Class, context: Context, instance: any | null, name: string): Value | null;
}
/**
* @gir-type Callback
*/
interface ClassHasPropertyFunction {
(jsc_class: Class, context: Context, instance: any | null, name: string): boolean;
}
/**
* @gir-type Callback
*/
interface ClassSetPropertyFunction {
(jsc_class: Class, context: Context, instance: any | null, name: string, value: Value): boolean;
}
/**
* @gir-type Callback
*/
interface ExceptionHandler {
(context: Context, exception: Exception): void;
}
/**
* @gir-type Callback
*/
interface Executor {
(resolve: Value, reject: Value): void;
}
/**
* @gir-type Callback
*/
interface OptionsFunc {
(option: string, type: OptionType, description?: string | null): boolean;
}
/**
* Flags used when defining properties with `jsc_value_object_define_property_data()` and
* `jsc_value_object_define_property_accessor()`.
* @gir-type Flags
*/
enum ValuePropertyFlags {
/**
* the type of the property descriptor may be changed and the
* property may be deleted from the corresponding object.
*/
CONFIGURABLE,
/**
* the property shows up during enumeration of the properties on
* the corresponding object.
*/
ENUMERABLE,
/**
* the value associated with the property may be changed with an
* assignment operator. This doesn't have any effect when passed to `jsc_value_object_define_property_accessor()`.
*/
WRITABLE,
}
namespace Class {
// Signal signatures
interface SignalSignatures extends GObject.Object.SignalSignatures {
'notify::context': (pspec: GObject.ParamSpec) => void;
'notify::name': (pspec: GObject.ParamSpec) => void;
'notify::parent': (pspec: GObject.ParamSpec) => void;
}
// Constructor properties interface
interface ConstructorProps extends GObject.Object.ConstructorProps {
context: Context;
name: string;
parent: Class;
}
}
/**
* A JSSClass represents a custom JavaScript class registered by the user in a {@link JavaScriptCore.Context}.
* It allows to create new JavaScripts objects whose instances are created by the user using
* this API.
* It's possible to add constructors, properties and methods for a JSSClass by providing
* {@link GObject.Callback}<!-- -->s to implement them.
* @gir-type Class
*/
class Class extends GObject.Object {
static $gtype: GObject.GType<Class>;
// Properties
/**
* The {@link JavaScriptCore.Context} in which the class was registered.
* @construct-only
*/
set context(val: Context);
/**
* The name of the class.
* @construct-only
*/
get name(): string;
/**
* The parent class or `null` in case of final classes.
* @construct-only
*/
get parent(): Class;
/**
* Compile-time signal type information.
*
* This instance property is generated only for TypeScript type checking.
* It is not defined at runtime and should not be accessed in JS code.
* @internal
*/
$signals: Class.SignalSignatures;
// Constructors
constructor(properties?: Partial<Class.ConstructorProps>, ...args: any[]);
_init(...args: any[]): void;
// Signals
/** @signal */
connect<K extends keyof Class.SignalSignatures>(
signal: K,
callback: GObject.SignalCallback<this, Class.SignalSignatures[K]>,
): number;
connect(signal: string, callback: (...args: any[]) => any): number;
/** @signal */
connect_after<K extends keyof Class.SignalSignatures>(
signal: K,
callback: GObject.SignalCallback<this, Class.SignalSignatures[K]>,
): number;
connect_after(signal: string, callback: (...args: any[]) => any): number;
/** @signal */
emit<K extends keyof Class.SignalSignatures>(
signal: K,
...args: GObject.GjsParameters<Class.SignalSignatures[K]> extends [any, ...infer Q] ? Q : never
): void;
emit(signal: string, ...args: any[]): void;
// Methods
/**
* Add a constructor to `jsc_class`. If `name` is `null`, the class name will be used. When <function>new</function>
* is used with the constructor or `jsc_value_constructor_call()` is called, `callback` is invoked receiving
* a {@link GLib.PtrArray} of {@link JavaScriptCore.Value}<!-- -->s as arguments and `user_data` as the last parameter. When the constructor object
* is cleared in the {@link JavaScriptCore.Class} context, `destroy_notify` is called with `user_data` as parameter.
*
* This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use
* `jsc_context_set_value()` to make the constructor available in the global object.
*
* Note that the value returned by `callback` is adopted by `jsc_class`, and the {@link GLib.DestroyNotify} passed to
* `jsc_context_register_class()` is responsible for disposing of it.
* @param name the constructor name or `null`
* @param callback a {@link GObject.Callback} to be called to create an instance of `jsc_class`
* @param destroy_notify destroy notifier for `user_data`
* @param return_type the {@link GObject.GType} of the constructor return value
* @returns a {@link JavaScriptCore.Value} representing the class constructor.
*/
add_constructor_variadic(
name: string | null,
callback: GObject.Callback,
destroy_notify: GLib.DestroyNotify | null,
return_type: GObject.GType,
): Value;
/**
* Add a constructor to `jsc_class`. If `name` is `null`, the class name will be used. When <function>new</function>
* is used with the constructor or `jsc_value_constructor_call()` is called, `callback` is invoked receiving the
* parameters and `user_data` as the last parameter. When the constructor object is cleared in the {@link JavaScriptCore.Class} context,
* `destroy_notify` is called with `user_data` as parameter.
*
* This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use
* `jsc_context_set_value()` to make the constructor available in the global object.
*
* Note that the value returned by `callback` is adopted by `jsc_class`, and the {@link GLib.DestroyNotify} passed to
* `jsc_context_register_class()` is responsible for disposing of it.
* @param name the constructor name or `null`
* @param callback a {@link GObject.Callback} to be called to create an instance of `jsc_class`
* @param destroy_notify destroy notifier for `user_data`
* @param return_type the {@link GObject.GType} of the constructor return value
* @param parameter_types a list of {@link GObject.GType}<!-- -->s, one for each parameter, or `null`
* @returns a {@link JavaScriptCore.Value} representing the class constructor.
*/
add_constructor(
name: string | null,
callback: GObject.Callback,
destroy_notify: GLib.DestroyNotify | null,
return_type: GObject.GType,
parameter_types?: GObject.GType[] | null,
): Value;
/**
* Add method with `name` to `jsc_class`. When the method is called by JavaScript or `jsc_value_object_invoke_method()`,
* `callback` is called receiving the class instance as first parameter, followed by a {@link GLib.PtrArray} of {@link JavaScriptCore.Value}<!-- -->s
* with the method arguments and then `user_data` as last parameter. When the method is cleared in the {@link JavaScriptCore.Class} context,
* `destroy_notify` is called with `user_data` as parameter.
*
* Note that the value returned by `callback` must be transfer full. In case of non-refcounted boxed types, you should use
* `G_TYPE_POINTER` instead of the actual boxed {@link GObject.GType} to ensure that the instance owned by {@link JavaScriptCore.Class} is used.
* If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return a {@link JavaScriptCore.Value} created
* with `jsc_value_new_object()` that receives the copy as the instance parameter.
* @param name the method name
* @param callback a {@link GObject.Callback} to be called to invoke method `name` of `jsc_class`
* @param destroy_notify destroy notifier for `user_data`
* @param return_type the {@link GObject.GType} of the method return value, or `G_TYPE_NONE` if the method is void.
*/
add_method_variadic(
name: string,
callback: GObject.Callback,
destroy_notify: GLib.DestroyNotify | null,
return_type: GObject.GType,
): void;
/**
* Add method with `name` to `jsc_class`. When the method is called by JavaScript or `jsc_value_object_invoke_method()`,
* `callback` is called receiving the class instance as first parameter, followed by the method parameters and then
* `user_data` as last parameter. When the method is cleared in the {@link JavaScriptCore.Class} context, `destroy_notify` is called with
* `user_data` as parameter.
*
* Note that the value returned by `callback` must be transfer full. In case of non-refcounted boxed types, you should use
* `G_TYPE_POINTER` instead of the actual boxed {@link GObject.GType} to ensure that the instance owned by {@link JavaScriptCore.Class} is used.
* If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return a {@link JavaScriptCore.Value} created
* with `jsc_value_new_object()` that receives the copy as the instance parameter.
* @param name the method name
* @param callback a {@link GObject.Callback} to be called to invoke method `name` of `jsc_class`
* @param destroy_notify destroy notifier for `user_data`
* @param return_type the {@link GObject.GType} of the method return value, or `G_TYPE_NONE` if the method is void.
* @param parameter_types a list of {@link GObject.GType}<!-- -->s, one for each parameter, or `null`
*/
add_method(
name: string,
callback: GObject.Callback,
destroy_notify: GLib.DestroyNotify | null,
return_type: GObject.GType,
parameter_types?: GObject.GType[] | null,
): void;
/**
* Add a property with `name` to `jsc_class`. When the property value is read, `getter` is called
* receiving the the class instance as first parameter and `user_data` as last parameter. When the property
* value needs to be set, `setter` is called receiving the the class instance as first parameter, followed
* by the value to be set and then `user_data` as the last parameter. When the property is cleared in the
* {@link JavaScriptCore.Class} context, `destroy_notify` is called with `user_data` as parameter.
*
* Note that the value returned by `getter` must be transfer full. In case of non-refcounted boxed types, you should use
* `G_TYPE_POINTER` instead of the actual boxed {@link GObject.GType} to ensure that the instance owned by {@link JavaScriptCore.Class} is used.
* If you really want to return a new copy of the boxed type, use #JSC_TYPE_VALUE and return a {@link JavaScriptCore.Value} created
* with `jsc_value_new_object()` that receives the copy as the instance parameter.
* @param name the property name
* @param property_type the {@link GObject.GType} of the property value
* @param getter a {@link GObject.Callback} to be called to get the property value
* @param setter a {@link GObject.Callback} to be called to set the property value
* @param destroy_notify destroy notifier for `user_data`
*/
add_property(
name: string,
property_type: GObject.GType,
getter?: GObject.Callback | null,
setter?: GObject.Callback | null,
destroy_notify?: GLib.DestroyNotify | null,
): void;
/**
* Get the class name of `jsc_class`
* @returns the name of `jsc_class`
*/
get_name(): string;
/**
* Get the parent class of `jsc_class`
* @returns the parent class of `jsc_class`
*/
get_parent(): Class;
}
namespace Context {
// Signal signatures
interface SignalSignatures extends GObject.Object.SignalSignatures {
'notify::virtual-machine': (pspec: GObject.ParamSpec) => void;
}
// Constructor properties interface
interface ConstructorProps extends GObject.Object.ConstructorProps {
virtual_machine: VirtualMachine;
virtualMachine: VirtualMachine;
}
}
/**
* JSCContext represents a JavaScript execution context, where all operations
* take place and where the values will be associated.
*
* When a new context is created, a global object is allocated and the built-in JavaScript
* objects (Object, Function, String, Array) are populated. You can execute JavaScript in
* the context by using `jsc_context_evaluate()` or `jsc_context_evaluate_with_source_uri()`.
* It's also possible to register custom objects in the context with `jsc_context_register_class()`.
* @gir-type Class
*/
class Context extends GObject.Object {
static $gtype: GObject.GType<Context>;
// Properties
/**
* The {@link JavaScriptCore.VirtualMachine} in which the context was created.
* @construct-only
*/
get virtual_machine(): VirtualMachine;
/**
* The {@link JavaScriptCore.VirtualMachine} in which the context was created.
* @construct-only
*/
get virtualMachine(): VirtualMachine;
/**
* Compile-time signal type information.
*
* This instance property is generated only for TypeScript type checking.
* It is not defined at runtime and should not be accessed in JS code.
* @internal
*/
$signals: Context.SignalSignatures;
// Constructors
constructor(properties?: Partial<Context.ConstructorProps>, ...args: any[]);
_init(...args: any[]): void;
static ['new'](): Context;
static new_with_virtual_machine(vm: VirtualMachine): Context;
// Signals
/** @signal */
connect<K extends keyof Context.SignalSignatures>(
signal: K,
callback: GObject.SignalCallback<this, Context.SignalSignatures[K]>,
): number;
connect(signal: string, callback: (...args: any[]) => any): number;
/** @signal */
connect_after<K extends keyof Context.SignalSignatures>(
signal: K,
callback: GObject.SignalCallback<this, Context.SignalSignatures[K]>,
): number;
connect_after(signal: string, callback: (...args: any[]) => any): number;
/** @signal */
emit<K extends keyof Context.SignalSignatures>(
signal: K,
...args: GObject.GjsParameters<Context.SignalSignatures[K]> extends [any, ...infer Q] ? Q : never
): void;
emit(signal: string, ...args: any[]): void;
// Static methods
/**
* Get the {@link JavaScriptCore.Context} that is currently executing a function. This should only be
* called within a function or method callback, otherwise `null` will be returned.
*/
static get_current(): Context | null;
// Methods
/**
* Check the given `code` in `context` for syntax errors. The `line_number` is the starting line number in `uri`;
* the value is one-based so the first line is 1. `uri` and `line_number` are only used to fill the `exception`.
* In case of errors `exception` will be set to a new {@link JavaScriptCore.Exception} with the details. You can pass `null` to
* `exception` to ignore the error details.
* @param code a JavaScript script to check
* @param length length of `code`, or -1 if `code` is a nul-terminated string
* @param mode a {@link JavaScriptCore.CheckSyntaxMode}
* @param uri the source URI
* @param line_number the starting line number
* @returns a {@link JavaScriptCore.CheckSyntaxResult}
*/
check_syntax(
code: string,
length: bigint | number,
mode: CheckSyntaxMode | null,
uri: string,
line_number: number,
): [CheckSyntaxResult, Exception | null];
/**
* Clear the uncaught exception in `context` if any.
*/
clear_exception(): void;
/**
* Evaluate `code` in `context`.
* @param code a JavaScript script to evaluate
* @param length length of `code`, or -1 if `code` is a nul-terminated string
* @returns a {@link JavaScriptCore.Value} representing the last value generated by the script.
*/
evaluate(code: string, length: bigint | number): Value;
/**
* Evaluate `code` and create an new object where symbols defined in `code` will be added as properties,
* instead of being added to `context` global object. The new object is returned as `object` parameter.
* Similar to how `jsc_value_new_object()` works, if `object_instance` is not `null` `object_class` must be provided too.
* The `line_number` is the starting line number in `uri`; the value is one-based so the first line is 1.
* `uri` and `line_number` will be shown in exceptions and they don't affect the behavior of the script.
* @param code a JavaScript script to evaluate
* @param length length of `code`, or -1 if `code` is a nul-terminated string
* @param object_instance an object instance
* @param object_class a {@link JavaScriptCore.Class} or `null` to use the default
* @param uri the source URI
* @param line_number the starting line number
* @returns a {@link JavaScriptCore.Value} representing the last value generated by the script.
*/
evaluate_in_object(
code: string,
length: bigint | number,
object_instance: any | null,
object_class: Class | null,
uri: string,
line_number: number,
): [Value, Value];
/**
* Evaluate `code` in `context` using `uri` as the source URI. The `line_number` is the starting line number
* in `uri`; the value is one-based so the first line is 1. `uri` and `line_number` will be shown in exceptions and
* they don't affect the behavior of the script.
* @param code a JavaScript script to evaluate
* @param length length of `code`, or -1 if `code` is a nul-terminated string
* @param uri the source URI
* @param line_number the starting line number
* @returns a {@link JavaScriptCore.Value} representing the last value generated by the script.
*/
evaluate_with_source_uri(code: string, length: bigint | number, uri: string, line_number: number): Value;
/**
* Get the last unhandled exception thrown in `context` by API functions calls.
* @returns a {@link JavaScriptCore.Exception} or `null` if there isn't any unhandled exception in the {@link JavaScriptCore.Context}.
*/
get_exception(): Exception | null;
/**
* Get a {@link JavaScriptCore.Value} referencing the `context` global object
* @returns a {@link JavaScriptCore.Value}
*/
get_global_object(): Value;
/**
* Get a property of `context` global object with `name`.
* @param name the value name
* @returns a {@link JavaScriptCore.Value}
*/
get_value(name: string): Value;
/**
* Get the {@link JavaScriptCore.VirtualMachine} where `context` was created.
* @returns the {@link JavaScriptCore.VirtualMachine} where the {@link JavaScriptCore.Context} was created.
*/
get_virtual_machine(): VirtualMachine;
/**
* Remove the last {@link JavaScriptCore.ExceptionHandler} previously pushed to `context` with
* `jsc_context_push_exception_handler()`.
*/
pop_exception_handler(): void;
/**
* Push an exception handler in `context`. Whenever a JavaScript exception happens in
* the {@link JavaScriptCore.Context}, the given `handler` will be called. The default {@link JavaScriptCore.ExceptionHandler}
* simply calls `jsc_context_throw_exception()` to throw the exception to the {@link JavaScriptCore.Context}.
* If you don't want to catch the exception, but only get notified about it, call
* `jsc_context_throw_exception()` in `handler` like the default one does.
* The last exception handler pushed is the only one used by the {@link JavaScriptCore.Context}, use
* `jsc_context_pop_exception_handler()` to remove it and set the previous one. When `handler`
* is removed from the context, `destroy_notify` is called with `user_data` as parameter.
* @param handler a {@link JavaScriptCore.ExceptionHandler}
* @param destroy_notify destroy notifier for `user_data`
*/
push_exception_handler(handler: ExceptionHandler, destroy_notify?: GLib.DestroyNotify | null): void;
/**
* Register a custom class in `context` using the given `name`. If the new class inherits from
* another {@link JavaScriptCore.Class}, the parent should be passed as `parent_class`, otherwise `null` should be
* used. The optional `vtable` parameter allows to provide a custom implementation for handling
* the class, for example, to handle external properties not added to the prototype.
* When an instance of the {@link JavaScriptCore.Class} is cleared in the context, `destroy_notify` is called with
* the instance as parameter.
* @param name the class name
* @param parent_class a {@link JavaScriptCore.Class} or `null`
* @param vtable an optional {@link JavaScriptCore.ClassVTable} or `null`
* @param destroy_notify a destroy notifier for class instances
* @returns a {@link JavaScriptCore.Class}
*/
register_class(
name: string,
parent_class?: Class | null,
vtable?: ClassVTable | null,
destroy_notify?: GLib.DestroyNotify | null,
): Class;
/**
* Set a property of `context` global object with `name` and `value`.
* @param name the value name
* @param value a {@link JavaScriptCore.Value}
*/
set_value(name: string, value: Value): void;
/**
* Throw an exception to `context` using the given error message. The created {@link JavaScriptCore.Exception}
* can be retrieved with `jsc_context_get_exception()`.
* @param error_message an error message
*/
['throw'](error_message: string): void;
/**
* Throw `exception` to `context`.
* @param exception a {@link JavaScriptCore.Exception}
*/
throw_exception(exception: Exception): void;
/**
* Throw an exception to `context` using the given error name and message. The created {@link JavaScriptCore.Exception}
* can be retrieved with `jsc_context_get_exception()`.
* @param error_name the error name
* @param error_message an error message
*/
throw_with_name(error_name: string, error_message: string): void;
}
namespace Exception {
// Signal signatures
interface SignalSignatures extends GObject.Object.SignalSignatures {}
// Constructor properties interface
interface ConstructorProps extends GObject.Object.ConstructorProps {}
}
/**
* JSCException represents a JavaScript exception.
* @gir-type Class
*/
class Exception extends GObject.Object {
static $gtype: GObject.GType<Exception>;
/**
* Compile-time signal type information.
*
* This instance property is generated only for TypeScript type checking.
* It is not defined at runtime and should not be accessed in JS code.
* @internal
*/
$signals: Exception.SignalSignatures;
// Constructors
constructor(properties?: Partial<Exception.ConstructorProps>, ...args: any[]);
_init(...args: any[]): void;
static ['new'](context: Context, message: string): Exception;
static new_with_name(context: Context, name: string, message: string): Exception;
// Signals
/** @signal */
connect<K extends keyof Exception.SignalSignatures>(
signal: K,
callback: GObject.SignalCallback<this, Exception.SignalSignatures[K]>,
): number;
connect(signal: string, callback: (...args: any[]) => any): number;
/** @signal */
connect_after<K extends keyof Exception.SignalSignatures>(
signal: K,
callback: GObject.SignalCallback<this, Exception.SignalSignatures[K]>,
): number;
connect_after(signal: string, callback: (...args: any[]) => any): number;
/** @signal */
emit<K extends keyof Exception.SignalSignatures>(
signal: K,
...args: GObject.GjsParameters<Exception.SignalSignatures[K]> extends [any, ...infer Q] ? Q : never
): void;
emit(signal: string, ...args: any[]): void;
// Methods
/**
* Get a string with the exception backtrace.
* @returns the exception backtrace string or `null`.
*/
get_backtrace_string(): string | null;
/**
* Get the column number at which `exception` happened.
* @returns the column number of `exception`.
*/
get_column_number(): number;
/**
* Get the line number at which `exception` happened.
* @returns the line number of `exception`.
*/
get_line_number(): number;
/**
* Get the error message of `exception`.
* @returns the `exception` error message.
*/
get_message(): string;
/**
* Get the error name of `exception`
* @returns the `exception` error name.
*/
get_name(): string;
/**
* Get the source URI of `exception`.
* @returns the the source URI of `exception`, or `null`.
*/
get_source_uri(): string | null;
/**
* Return a report message of `exception`, containing all the possible details such us
* source URI, line, column and backtrace, and formatted to be printed.
* @returns a new string with the exception report
*/
report(): string;
/**
* Get the string representation of `exception` error.
* @returns the string representation of `exception`.
*/
to_string(): string;
}
namespace Value {
// Signal signatures
interface SignalSignatures extends GObject.Object.SignalSignatures {
'notify::context': (pspec: GObject.ParamSpec) => void;
}
// Constructor properties interface
interface ConstructorProps extends GObject.Object.ConstructorProps {
context: Context;