forked from cesanta/v7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v7.h
2086 lines (1738 loc) · 54.9 KB
/
v7.h
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
#ifdef V7_MODULE_LINES
#line 1 "v7/src/license.h"
#endif
/*
* Copyright (c) 2013-2014 Cesanta Software Limited
* All rights reserved
*
* This software is dual-licensed: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. For the terms of this
* license, see <http://www.gnu.org/licenses/>.
*
* You are free to use this software under the terms of the GNU General
* Public License, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* Alternatively, you can license this software under a commercial
* license, as set out in <https://www.cesanta.com/license>.
*/
#ifdef V7_EXPOSE_PRIVATE
#define V7_PRIVATE
#define V7_EXTERN extern
#else
#define V7_PRIVATE static
#define V7_EXTERN static
#endif /* CS_V7_SRC_LICENSE_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_profiles.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_FEATURES_PROFILES_H_
#define CS_V7_SRC_FEATURES_PROFILES_H_
#define V7_BUILD_PROFILE_MINIMAL 1
#define V7_BUILD_PROFILE_MEDIUM 2
#define V7_BUILD_PROFILE_FULL 3
#ifndef V7_BUILD_PROFILE
#define V7_BUILD_PROFILE V7_BUILD_PROFILE_FULL
#endif
#endif /* CS_V7_SRC_FEATURES_PROFILES_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_minimal.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/* Amalgamated: #include "v7/src/features_profiles.h" */
#if V7_BUILD_PROFILE == V7_BUILD_PROFILE_MINIMAL
/* This space is intentionally left blank. */
#endif /* CS_V7_SRC_FEATURES_MINIMAL_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_medium.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/* Amalgamated: #include "v7/src/features_profiles.h" */
#if V7_BUILD_PROFILE == V7_BUILD_PROFILE_MEDIUM
#define V7_ENABLE__Date 1
#define V7_ENABLE__Date__now 1
#define V7_ENABLE__Date__UTC 1
#define V7_ENABLE__Math 1
#define V7_ENABLE__Math__atan2 1
#define V7_ENABLE__RegExp 1
#endif /* CS_V7_SRC_FEATURES_MEDIUM_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_full.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_FEATURES_FULL_H_
#define CS_V7_SRC_FEATURES_FULL_H_
/* Amalgamated: #include "v7/src/features_profiles.h" */
#if V7_BUILD_PROFILE == V7_BUILD_PROFILE_FULL
/*
* DO NOT EDIT.
* This file is generated by scripts/gen-features-full.pl.
*/
#ifndef CS_ENABLE_UTF8 /* ifdef-ok */
#define CS_ENABLE_UTF8 1
#endif
#define V7_ENABLE__Array__reduce 1
#define V7_ENABLE__Blob 1
#define V7_ENABLE__Date 1
#define V7_ENABLE__Date__UTC 1
#define V7_ENABLE__Date__getters 1
#define V7_ENABLE__Date__now 1
#define V7_ENABLE__Date__parse 1
#define V7_ENABLE__Date__setters 1
#define V7_ENABLE__Date__toJSON 1
#define V7_ENABLE__Date__toLocaleString 1
#define V7_ENABLE__Date__toString 1
#define V7_ENABLE__File__list 1
#define V7_ENABLE__File__require 1
#define V7_ENABLE__Function__bind 1
#define V7_ENABLE__Function__call 1
#define V7_ENABLE__Math 1
#define V7_ENABLE__Math__abs 1
#define V7_ENABLE__Math__acos 1
#define V7_ENABLE__Math__asin 1
#define V7_ENABLE__Math__atan 1
#define V7_ENABLE__Math__atan2 1
#define V7_ENABLE__Math__ceil 1
#define V7_ENABLE__Math__constants 1
#define V7_ENABLE__Math__cos 1
#define V7_ENABLE__Math__exp 1
#define V7_ENABLE__Math__floor 1
#define V7_ENABLE__Math__log 1
#define V7_ENABLE__Math__max 1
#define V7_ENABLE__Math__min 1
#define V7_ENABLE__Math__pow 1
#define V7_ENABLE__Math__random 1
#define V7_ENABLE__Math__round 1
#define V7_ENABLE__Math__sin 1
#define V7_ENABLE__Math__sqrt 1
#define V7_ENABLE__Math__tan 1
#define V7_ENABLE__Memory__stats 1
#define V7_ENABLE__NUMBER__NEGATIVE_INFINITY 1
#define V7_ENABLE__NUMBER__POSITIVE_INFINITY 1
#define V7_ENABLE__Object__create 1
#define V7_ENABLE__Object__defineProperties 1
#define V7_ENABLE__Object__getOwnPropertyDescriptor 1
#define V7_ENABLE__Object__getOwnPropertyNames 1
#define V7_ENABLE__Object__getPrototypeOf 1
#define V7_ENABLE__Object__hasOwnProperty 1
#define V7_ENABLE__Object__isExtensible 1
#define V7_ENABLE__Object__isFrozen 1
#define V7_ENABLE__Object__isPrototypeOf 1
#define V7_ENABLE__Object__isSealed 1
#define V7_ENABLE__Object__keys 1
#define V7_ENABLE__Object__preventExtensions 1
#define V7_ENABLE__Object__propertyIsEnumerable 1
#define V7_ENABLE__Proxy 1
#define V7_ENABLE__RegExp 1
#define V7_ENABLE__StackTrace 1
#define V7_ENABLE__String__localeCompare 1
#define V7_ENABLE__String__localeLowerCase 1
#define V7_ENABLE__String__localeUpperCase 1
#endif /* V7_BUILD_PROFILE == V7_BUILD_PROFILE_FULL */
#endif /* CS_V7_SRC_FEATURES_FULL_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/features_all.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_FEATURES_ALL_H_
#define CS_V7_SRC_FEATURES_ALL_H_
/*
* DO NOT EDIT.
* This file is generated by scripts/gen-features-all.pl.
*/
#ifndef V7_ENABLE__Array__reduce
#define V7_ENABLE__Array__reduce 0
#endif
#ifndef V7_ENABLE__Blob
#define V7_ENABLE__Blob 0
#endif
#ifndef V7_ENABLE__Date
#define V7_ENABLE__Date 0
#endif
#ifndef V7_ENABLE__Date__UTC
#define V7_ENABLE__Date__UTC 0
#endif
#ifndef V7_ENABLE__Date__getters
#define V7_ENABLE__Date__getters 0
#endif
#ifndef V7_ENABLE__Date__now
#define V7_ENABLE__Date__now 0
#endif
#ifndef V7_ENABLE__Date__parse
#define V7_ENABLE__Date__parse 0
#endif
#ifndef V7_ENABLE__Date__setters
#define V7_ENABLE__Date__setters 0
#endif
#ifndef V7_ENABLE__Date__toJSON
#define V7_ENABLE__Date__toJSON 0
#endif
#ifndef V7_ENABLE__Date__toLocaleString
#define V7_ENABLE__Date__toLocaleString 0
#endif
#ifndef V7_ENABLE__Date__toString
#define V7_ENABLE__Date__toString 0
#endif
#ifndef V7_ENABLE__File__list
#define V7_ENABLE__File__list 0
#endif
#ifndef V7_ENABLE__File__require
#define V7_ENABLE__File__require 0
#endif
#ifndef V7_ENABLE__Function__bind
#define V7_ENABLE__Function__bind 0
#endif
#ifndef V7_ENABLE__Function__call
#define V7_ENABLE__Function__call 0
#endif
#ifndef V7_ENABLE__Math
#define V7_ENABLE__Math 0
#endif
#ifndef V7_ENABLE__Math__abs
#define V7_ENABLE__Math__abs 0
#endif
#ifndef V7_ENABLE__Math__acos
#define V7_ENABLE__Math__acos 0
#endif
#ifndef V7_ENABLE__Math__asin
#define V7_ENABLE__Math__asin 0
#endif
#ifndef V7_ENABLE__Math__atan
#define V7_ENABLE__Math__atan 0
#endif
#ifndef V7_ENABLE__Math__atan2
#define V7_ENABLE__Math__atan2 0
#endif
#ifndef V7_ENABLE__Math__ceil
#define V7_ENABLE__Math__ceil 0
#endif
#ifndef V7_ENABLE__Math__constants
#define V7_ENABLE__Math__constants 0
#endif
#ifndef V7_ENABLE__Math__cos
#define V7_ENABLE__Math__cos 0
#endif
#ifndef V7_ENABLE__Math__exp
#define V7_ENABLE__Math__exp 0
#endif
#ifndef V7_ENABLE__Math__floor
#define V7_ENABLE__Math__floor 0
#endif
#ifndef V7_ENABLE__Math__log
#define V7_ENABLE__Math__log 0
#endif
#ifndef V7_ENABLE__Math__max
#define V7_ENABLE__Math__max 0
#endif
#ifndef V7_ENABLE__Math__min
#define V7_ENABLE__Math__min 0
#endif
#ifndef V7_ENABLE__Math__pow
#define V7_ENABLE__Math__pow 0
#endif
#ifndef V7_ENABLE__Math__random
#define V7_ENABLE__Math__random 0
#endif
#ifndef V7_ENABLE__Math__round
#define V7_ENABLE__Math__round 0
#endif
#ifndef V7_ENABLE__Math__sin
#define V7_ENABLE__Math__sin 0
#endif
#ifndef V7_ENABLE__Math__sqrt
#define V7_ENABLE__Math__sqrt 0
#endif
#ifndef V7_ENABLE__Math__tan
#define V7_ENABLE__Math__tan 0
#endif
#ifndef V7_ENABLE__Memory__stats
#define V7_ENABLE__Memory__stats 0
#endif
#ifndef V7_ENABLE__NUMBER__NEGATIVE_INFINITY
#define V7_ENABLE__NUMBER__NEGATIVE_INFINITY 0
#endif
#ifndef V7_ENABLE__NUMBER__POSITIVE_INFINITY
#define V7_ENABLE__NUMBER__POSITIVE_INFINITY 0
#endif
#ifndef V7_ENABLE__Object__create
#define V7_ENABLE__Object__create 0
#endif
#ifndef V7_ENABLE__Object__defineProperties
#define V7_ENABLE__Object__defineProperties 0
#endif
#ifndef V7_ENABLE__Object__getOwnPropertyDescriptor
#define V7_ENABLE__Object__getOwnPropertyDescriptor 0
#endif
#ifndef V7_ENABLE__Object__getOwnPropertyNames
#define V7_ENABLE__Object__getOwnPropertyNames 0
#endif
#ifndef V7_ENABLE__Object__getPrototypeOf
#define V7_ENABLE__Object__getPrototypeOf 0
#endif
#ifndef V7_ENABLE__Object__hasOwnProperty
#define V7_ENABLE__Object__hasOwnProperty 0
#endif
#ifndef V7_ENABLE__Object__isExtensible
#define V7_ENABLE__Object__isExtensible 0
#endif
#ifndef V7_ENABLE__Object__isFrozen
#define V7_ENABLE__Object__isFrozen 0
#endif
#ifndef V7_ENABLE__Object__isPrototypeOf
#define V7_ENABLE__Object__isPrototypeOf 0
#endif
#ifndef V7_ENABLE__Object__isSealed
#define V7_ENABLE__Object__isSealed 0
#endif
#ifndef V7_ENABLE__Object__keys
#define V7_ENABLE__Object__keys 0
#endif
#ifndef V7_ENABLE__Object__preventExtensions
#define V7_ENABLE__Object__preventExtensions 0
#endif
#ifndef V7_ENABLE__Object__propertyIsEnumerable
#define V7_ENABLE__Object__propertyIsEnumerable 0
#endif
#ifndef V7_ENABLE__Proxy
#define V7_ENABLE__Proxy 0
#endif
#ifndef V7_ENABLE__RegExp
#define V7_ENABLE__RegExp 0
#endif
#ifndef V7_ENABLE__StackTrace
#define V7_ENABLE__StackTrace 0
#endif
#ifndef V7_ENABLE__String__localeCompare
#define V7_ENABLE__String__localeCompare 0
#endif
#ifndef V7_ENABLE__String__localeLowerCase
#define V7_ENABLE__String__localeLowerCase 0
#endif
#ifndef V7_ENABLE__String__localeUpperCase
#define V7_ENABLE__String__localeUpperCase 0
#endif
#endif /* CS_V7_SRC_FEATURES_ALL_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/v7_features.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_V7_FEATURES_H_
#define CS_V7_SRC_V7_FEATURES_H_
/* Only one will actually be used based on V7_BUILD_PROFILE. */
/* Amalgamated: #include "v7/src/features_minimal.h" */
/* Amalgamated: #include "v7/src/features_medium.h" */
/* Amalgamated: #include "v7/src/features_full.h" */
/* All the features will be default-defined to 0. */
/* Amalgamated: #include "v7/src/features_all.h" */
#ifndef V7_DISABLE_AST_TAG_NAMES
#define V7_DISABLE_AST_TAG_NAMES 0
#endif
#ifndef V7_DISABLE_GC
#define V7_DISABLE_GC 0
#endif
#ifndef V7_DISABLE_CALL_ERROR_CONTEXT
#define V7_DISABLE_CALL_ERROR_CONTEXT 0
#endif
#ifndef V7_DISABLE_FILENAMES
#define V7_DISABLE_FILENAMES 0
#endif
#ifndef V7_DISABLE_LINE_NUMBERS
#define V7_DISABLE_LINE_NUMBERS 0
#endif
#ifndef V7_DISABLE_STR_ALLOC_SEQ
#define V7_DISABLE_STR_ALLOC_SEQ 0
#endif
#ifndef V7_ENABLE_CALL_TRACE
#define V7_ENABLE_CALL_TRACE 0
#endif
#ifndef V7_ENABLE_CRYPTO
#define V7_ENABLE_CRYPTO 0
#endif
#ifndef V7_ENABLE_DENSE_ARRAYS
#define V7_ENABLE_DENSE_ARRAYS 0
#endif
#ifndef V7_ENABLE_ENTITY_IDS
#define V7_ENABLE_ENTITY_IDS 0
#endif
#ifndef V7_ENABLE_FILE
#define V7_ENABLE_FILE 0
#endif
#ifndef V7_ENABLE_FOOTPRINT_REPORT
#define V7_ENABLE_FOOTPRINT_REPORT 0
#endif
#ifndef V7_ENABLE_GC_CHECK
#define V7_ENABLE_GC_CHECK 0
#endif
#ifndef V7_ENABLE_JS_GETTERS
#define V7_ENABLE_JS_GETTERS 0
#endif
#ifndef V7_ENABLE_JS_SETTERS
#define V7_ENABLE_JS_SETTERS 0
#endif
#ifndef V7_ENABLE_STACK_TRACKING
#define V7_ENABLE_STACK_TRACKING 0
#endif
#ifndef V7_ENABLE_SOCKET
#define V7_ENABLE_SOCKET 0
#endif
#ifndef V7_AST_FORCE_LINE_NUMBERS
#define V7_AST_FORCE_LINE_NUMBERS 0
#endif
#ifndef V7_HEAPUSAGE_ENABLE
#define V7_HEAPUSAGE_ENABLE 0
#endif
#endif /* CS_V7_SRC_V7_FEATURES_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/platform.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_V7_SRC_PLATFORM_H_
#define CS_V7_SRC_PLATFORM_H_
#ifdef __arm
#undef V7_ENABLE__Date
#define V7_ENABLE__Date 0
#endif
#endif /* CS_V7_SRC_PLATFORM_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/core_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Core
*/
#ifndef CS_V7_SRC_CORE_PUBLIC_H_
#define CS_V7_SRC_CORE_PUBLIC_H_
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
/* Amalgamated: #include "v7/src/license.h" */
/* Amalgamated: #include "v7/src/v7_features.h" */
/* Amalgamated: #include "v7/src/platform.h" */
#include <stddef.h> /* For size_t */
#include <stdio.h> /* For FILE */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* TODO(dfrank) : improve amalgamation, so that we'll be able to include
* files here, and include common/platform.h
*
* For now, copy-pasting `WARN_UNUSED_RESULT` here
*/
#ifdef __GNUC__
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define NOINSTR __attribute__((no_instrument_function))
#else
#define WARN_UNUSED_RESULT
#define NOINSTR
#endif
#define V7_VERSION "1.0"
#if (defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)) || \
(defined(_MSC_VER) && _MSC_VER <= 1200)
#define V7_WINDOWS
#endif
#ifdef V7_WINDOWS
typedef unsigned __int64 uint64_t;
#else
#include <inttypes.h>
#endif
/* 64-bit value, used to store JS values */
typedef uint64_t v7_val_t;
/* JavaScript `null` value */
#define V7_NULL ((uint64_t) 0xfffe << 48)
/* JavaScript `undefined` value */
#define V7_UNDEFINED ((uint64_t) 0xfffd << 48)
/* This if-0 is a dirty workaround to force etags to pick `struct v7` */
#if 0
/* Opaque structure. V7 engine context. */
struct v7 {
/* ... */
};
#endif
struct v7;
/*
* Code which is returned by some of the v7 functions. If something other than
* `V7_OK` is returned from some function, the caller function typically should
* either immediately cleanup and return the code further, or handle the error.
*/
enum v7_err {
V7_OK,
V7_SYNTAX_ERROR,
V7_EXEC_EXCEPTION,
V7_AST_TOO_LARGE,
V7_INTERNAL_ERROR,
};
/* JavaScript -> C call interface */
WARN_UNUSED_RESULT
typedef enum v7_err(v7_cfunction_t)(struct v7 *v7, v7_val_t *res);
/* Create V7 instance */
struct v7 *v7_create(void);
/*
* Customizations of initial V7 state; used by `v7_create_opt()`.
*/
struct v7_create_opts {
size_t object_arena_size;
size_t function_arena_size;
size_t property_arena_size;
#ifdef V7_STACK_SIZE
void *c_stack_base;
#endif
#ifdef V7_FREEZE
/* if not NULL, dump JS heap after init */
char *freeze_file;
#endif
};
/*
* Like `v7_create()`, but allows to customize initial v7 state, see `struct
* v7_create_opts`.
*/
struct v7 *v7_create_opt(struct v7_create_opts opts);
/* Destroy V7 instance */
void v7_destroy(struct v7 *v7);
/* Return root level (`global`) object of the given V7 instance. */
v7_val_t v7_get_global(struct v7 *v);
/* Return current `this` object. */
v7_val_t v7_get_this(struct v7 *v);
/* Return current `arguments` array */
v7_val_t v7_get_arguments(struct v7 *v);
/* Return i-th argument */
v7_val_t v7_arg(struct v7 *v, unsigned long i);
/* Return the length of `arguments` */
unsigned long v7_argc(struct v7 *v7);
/*
* Tells the GC about a JS value variable/field owned
* by C code.
*
* User C code should own v7_val_t variables
* if the value's lifetime crosses any invocation
* to the v7 runtime that creates new objects or new
* properties and thus can potentially trigger GC.
*
* The registration of the variable prevents the GC from mistakenly treat
* the object as garbage. The GC might be triggered potentially
* allows the GC to update pointers
*
* User code should also explicitly disown the variables with v7_disown once
* it goes out of scope or the structure containing the v7_val_t field is freed.
*
* Example:
*
* ```
* struct v7_val cb;
* v7_own(v7, &cb);
* cb = v7_array_get(v7, args, 0);
* // do something with cb
* v7_disown(v7, &cb);
* ```
*/
void v7_own(struct v7 *v7, v7_val_t *v);
/*
* Returns 1 if value is found, 0 otherwise
*/
int v7_disown(struct v7 *v7, v7_val_t *v);
/*
* Enable or disable GC.
*
* Must be called before invoking v7_exec or v7_apply
* from within a cfunction unless you know what you're doing.
*
* GC is disabled during execution of cfunctions in order to simplify
* memory management of simple cfunctions.
* However executing even small snippets of JS code causes a lot of memory
* pressure. Enabling GC solves that but forces you to take care of the
* reachability of your temporary V7 v7_val_t variables, as the GC needs
* to know where they are since objects and strings can be either reclaimed
* or relocated during a GC pass.
*/
void v7_set_gc_enabled(struct v7 *v7, int enabled);
/*
* Set an optional C stack limit.
*
* It sets a flag that will cause the interpreter
* to throw an InterruptedError.
* It's safe to call it from signal handlers and ISRs
* on single threaded environments.
*/
void v7_interrupt(struct v7 *v7);
/* Returns last parser error message. TODO: rename it to `v7_get_error()` */
const char *v7_get_parser_error(struct v7 *v7);
#if V7_ENABLE_STACK_TRACKING
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Stack metric id. See `v7_stack_stat()`
*/
enum v7_stack_stat_what {
/* max stack size consumed by `i_exec()` */
V7_STACK_STAT_EXEC,
/* max stack size consumed by `parse()` (which is called from `i_exec()`) */
V7_STACK_STAT_PARSER,
V7_STACK_STATS_CNT
};
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Returns stack metric specified by the metric id `what`. See
* `v7_stack_stat_clean()`
*/
int v7_stack_stat(struct v7 *v7, enum v7_stack_stat_what what);
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Clean all stack statistics gathered so far. See `v7_stack_stat()`
*/
void v7_stack_stat_clean(struct v7 *v7);
#endif
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_CORE_PUBLIC_H_ */
#ifndef V7_EXPORT_INTERNAL_HEADERS
#ifdef V7_MODULE_LINES
#line 1 "v7/src/core_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Core
*/
#ifndef CS_V7_SRC_CORE_PUBLIC_H_
#define CS_V7_SRC_CORE_PUBLIC_H_
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
/* Amalgamated: #include "v7/src/license.h" */
/* Amalgamated: #include "v7/src/v7_features.h" */
/* Amalgamated: #include "v7/src/platform.h" */
#include <stddef.h> /* For size_t */
#include <stdio.h> /* For FILE */
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
/*
* TODO(dfrank) : improve amalgamation, so that we'll be able to include
* files here, and include common/platform.h
*
* For now, copy-pasting `WARN_UNUSED_RESULT` here
*/
#ifdef __GNUC__
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define NOINSTR __attribute__((no_instrument_function))
#else
#define WARN_UNUSED_RESULT
#define NOINSTR
#endif
#define V7_VERSION "1.0"
#if (defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)) || \
(defined(_MSC_VER) && _MSC_VER <= 1200)
#define V7_WINDOWS
#endif
#ifdef V7_WINDOWS
typedef unsigned __int64 uint64_t;
#else
#include <inttypes.h>
#endif
/* 64-bit value, used to store JS values */
typedef uint64_t v7_val_t;
/* JavaScript `null` value */
#define V7_NULL ((uint64_t) 0xfffe << 48)
/* JavaScript `undefined` value */
#define V7_UNDEFINED ((uint64_t) 0xfffd << 48)
/* This if-0 is a dirty workaround to force etags to pick `struct v7` */
#if 0
/* Opaque structure. V7 engine context. */
struct v7 {
/* ... */
};
#endif
struct v7;
/*
* Code which is returned by some of the v7 functions. If something other than
* `V7_OK` is returned from some function, the caller function typically should
* either immediately cleanup and return the code further, or handle the error.
*/
enum v7_err {
V7_OK,
V7_SYNTAX_ERROR,
V7_EXEC_EXCEPTION,
V7_AST_TOO_LARGE,
V7_INTERNAL_ERROR,
};
/* JavaScript -> C call interface */
WARN_UNUSED_RESULT
typedef enum v7_err(v7_cfunction_t)(struct v7 *v7, v7_val_t *res);
/* Create V7 instance */
struct v7 *v7_create(void);
/*
* Customizations of initial V7 state; used by `v7_create_opt()`.
*/
struct v7_create_opts {
size_t object_arena_size;
size_t function_arena_size;
size_t property_arena_size;
#ifdef V7_STACK_SIZE
void *c_stack_base;
#endif
#ifdef V7_FREEZE
/* if not NULL, dump JS heap after init */
char *freeze_file;
#endif
};
/*
* Like `v7_create()`, but allows to customize initial v7 state, see `struct
* v7_create_opts`.
*/
struct v7 *v7_create_opt(struct v7_create_opts opts);
/* Destroy V7 instance */
void v7_destroy(struct v7 *v7);
/* Return root level (`global`) object of the given V7 instance. */
v7_val_t v7_get_global(struct v7 *v);
/* Return current `this` object. */
v7_val_t v7_get_this(struct v7 *v);
/* Return current `arguments` array */
v7_val_t v7_get_arguments(struct v7 *v);
/* Return i-th argument */
v7_val_t v7_arg(struct v7 *v, unsigned long i);
/* Return the length of `arguments` */
unsigned long v7_argc(struct v7 *v7);
/*
* Tells the GC about a JS value variable/field owned
* by C code.
*
* User C code should own v7_val_t variables
* if the value's lifetime crosses any invocation
* to the v7 runtime that creates new objects or new
* properties and thus can potentially trigger GC.
*
* The registration of the variable prevents the GC from mistakenly treat
* the object as garbage. The GC might be triggered potentially
* allows the GC to update pointers
*
* User code should also explicitly disown the variables with v7_disown once
* it goes out of scope or the structure containing the v7_val_t field is freed.
*
* Example:
*
* ```
* struct v7_val cb;
* v7_own(v7, &cb);
* cb = v7_array_get(v7, args, 0);
* // do something with cb
* v7_disown(v7, &cb);
* ```
*/
void v7_own(struct v7 *v7, v7_val_t *v);
/*
* Returns 1 if value is found, 0 otherwise
*/
int v7_disown(struct v7 *v7, v7_val_t *v);
/*
* Enable or disable GC.
*
* Must be called before invoking v7_exec or v7_apply
* from within a cfunction unless you know what you're doing.
*
* GC is disabled during execution of cfunctions in order to simplify
* memory management of simple cfunctions.
* However executing even small snippets of JS code causes a lot of memory
* pressure. Enabling GC solves that but forces you to take care of the
* reachability of your temporary V7 v7_val_t variables, as the GC needs
* to know where they are since objects and strings can be either reclaimed
* or relocated during a GC pass.
*/
void v7_set_gc_enabled(struct v7 *v7, int enabled);
/*
* Set an optional C stack limit.
*
* It sets a flag that will cause the interpreter
* to throw an InterruptedError.
* It's safe to call it from signal handlers and ISRs
* on single threaded environments.
*/
void v7_interrupt(struct v7 *v7);
/* Returns last parser error message. TODO: rename it to `v7_get_error()` */
const char *v7_get_parser_error(struct v7 *v7);
#if V7_ENABLE_STACK_TRACKING
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Stack metric id. See `v7_stack_stat()`
*/
enum v7_stack_stat_what {
/* max stack size consumed by `i_exec()` */
V7_STACK_STAT_EXEC,
/* max stack size consumed by `parse()` (which is called from `i_exec()`) */
V7_STACK_STAT_PARSER,
V7_STACK_STATS_CNT
};
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Returns stack metric specified by the metric id `what`. See
* `v7_stack_stat_clean()`
*/
int v7_stack_stat(struct v7 *v7, enum v7_stack_stat_what what);
/*
* Available if only `V7_ENABLE_STACK_TRACKING` is defined.
*
* Clean all stack statistics gathered so far. See `v7_stack_stat()`
*/
void v7_stack_stat_clean(struct v7 *v7);
#endif
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* CS_V7_SRC_CORE_PUBLIC_H_ */
#ifdef V7_MODULE_LINES
#line 1 "v7/src/primitive_public.h"
#endif
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
/*
* === Primitives