-
Notifications
You must be signed in to change notification settings - Fork 6
/
TinyJS.h
2660 lines (2247 loc) · 118 KB
/
TinyJS.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
/*
* TinyJS
*
* A single-file Javascript-alike engine
*
* Authored By Gordon Williams <[email protected]>
*
* Copyright (C) 2009 Pur3 Ltd
*
* 42TinyJS
*
* A fork of TinyJS with the goal to makes a more JavaScript/ECMA compliant engine
*
* Authored / Changed By Armin Diedering <[email protected]>
*
* Copyright (C) 2010-2015 ardisoft
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TINYJS_H
#define TINYJS_H
#define TINY_JS_VERSION 0.9.8
#include <string>
#include <vector>
#include <map>
#include <set>
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || _MSC_VER >= 1700 // Visual Studio 2012
# include <cstdint>
#else
# define __STDC_LIMIT_MACROS
# include <stdint.h> // <cstdint> is C++11
#endif
#include <climits>
#include <cstring>
#include <cassert>
#include <ctime>
#include <limits>
#include <iostream>
#include "config.h"
#ifdef NO_POOL_ALLOCATOR
template<typename T, int num_objects=64>
class fixed_size_object {};
#else
# include "pool_allocator.h"
#endif
#include "TinyJS_Threading.h"
#ifdef _MSC_VER
# if defined(_DEBUG) && defined(_DEBUG_NEW)
# define _AFXDLL
# include <afx.h> // MFC-Kern- und -Standardkomponenten
# define new DEBUG_NEW
# endif
# define DEPRECATED(_Text) __declspec(deprecated(_Text))
# define ATTRIBUTE_USED
#elif defined(__GNUC__)
# define DEPRECATED(_Text) __attribute__ ((deprecated))
# define ATTRIBUTE_USED __attribute__((used))
#else
# define DEPRECATED(_Text)
# define ATTRIBUTE_USED
#endif
#ifdef NO_WARN_DEPRECATED
# undef DEPRECATED
# define DEPRECATED(_Text)
#endif
#ifndef ASSERT
# define ASSERT(X) assert(X)
#endif
#undef TRACE
#ifndef TRACE
#define TRACE printf
#endif // TRACE
enum LEX_TYPES {
LEX_EOF = 0,
#define LEX_RELATIONS_1_BEGIN LEX_EQUAL
LEX_EQUAL = 256,
LEX_TYPEEQUAL,
LEX_NEQUAL,
LEX_NTYPEEQUAL,
#define LEX_RELATIONS_1_END LEX_NTYPEEQUAL
LEX_ARROW,
LEX_LEQUAL,
LEX_GEQUAL,
#define LEX_SHIFTS_BEGIN LEX_LSHIFT
LEX_LSHIFT,
LEX_RSHIFT,
LEX_RSHIFTU, // unsigned
#define LEX_SHIFTS_END LEX_RSHIFTU
LEX_PLUSPLUS,
LEX_MINUSMINUS,
LEX_ANDAND,
LEX_OROR,
LEX_INT,
#define LEX_ASSIGNMENTS_BEGIN LEX_PLUSEQUAL
LEX_PLUSEQUAL,
LEX_MINUSEQUAL,
LEX_ASTERISKEQUAL,
LEX_SLASHEQUAL,
LEX_PERCENTEQUAL,
LEX_LSHIFTEQUAL,
LEX_RSHIFTEQUAL,
LEX_RSHIFTUEQUAL, // unsigned
LEX_ANDEQUAL,
LEX_OREQUAL,
LEX_XOREQUAL,
#define LEX_ASSIGNMENTS_END LEX_XOREQUAL
#define LEX_TOKEN_NONSIMPLE_1_BEGIN LEX_TOKEN_STRING_BEGIN
#define LEX_TOKEN_STRING_BEGIN LEX_ID
LEX_ID,
LEX_STR,
LEX_REGEXP,
LEX_T_LABEL,
LEX_T_DUMMY_LABEL,
#define LEX_TOKEN_STRING_END LEX_T_DUMMY_LABEL
LEX_FLOAT,
#define LEX_TOKEN_NONSIMPLE_1_END LEX_FLOAT
// reserved words
LEX_R_IF,
LEX_R_ELSE,
LEX_R_DO,
LEX_R_WHILE,
LEX_R_FOR,
LEX_R_IN,
LEX_T_OF,
LEX_R_BREAK,
LEX_R_CONTINUE,
LEX_R_RETURN,
LEX_R_VAR,
LEX_R_LET,
LEX_R_CONST,
LEX_R_WITH,
LEX_R_TRUE,
LEX_R_FALSE,
LEX_R_NULL,
LEX_R_NEW,
LEX_R_TRY,
LEX_R_CATCH,
LEX_R_FINALLY,
LEX_R_THROW,
LEX_R_TYPEOF,
LEX_R_VOID,
LEX_R_DELETE,
LEX_R_INSTANCEOF,
LEX_R_SWITCH,
LEX_R_CASE,
LEX_R_DEFAULT,
// special token
// LEX_T_FILE,
#define LEX_TOKEN_NONSIMPLE_2_BEGIN LEX_TOKEN_FOR_BEGIN
#define LEX_TOKEN_FOR_BEGIN LEX_T_LOOP
LEX_T_LOOP,
LEX_T_FOR_IN,
#define LEX_TOKEN_FOR_END LEX_T_FOR_IN
#define LEX_TOKEN_FUNCTION_BEGIN LEX_R_FUNCTION
LEX_R_FUNCTION,
LEX_T_FUNCTION_PLACEHOLDER,
LEX_T_FUNCTION_OPERATOR,
LEX_T_GET,
LEX_T_SET,
#define LEX_TOKEN_FUNCTION_END LEX_T_SET
LEX_T_IF,
LEX_T_TRY,
LEX_T_OBJECT_LITERAL,
LEX_T_DESTRUCTURING_VAR,
LEX_T_ARRAY_COMPREHENSIONS_BODY,
LEX_T_FORWARD,
#define LEX_TOKEN_NONSIMPLE_2_END LEX_T_FORWARD
LEX_T_EXCEPTION_VAR,
LEX_T_SKIP,
LEX_T_END_EXPRESSION,
LEX_R_YIELD,
LEX_ASTERISKASTERISK, // **
LEX_ASTERISKASTERISKEQUAL, // **=
LEX_ASKASK, // ??
LEX_ASKASKEQUAL, // ??=
LEX_OPTIONAL_CHAINING_MEMBER, // .?
LEX_OPTIONAL_CHAINING_ARRAY, // .?[ ... ]
LEX_OPTIONAL_CHANING_FNC, // .?( ... )
};
#define LEX_TOKEN_DATA_STRING(tk) ((LEX_TOKEN_STRING_BEGIN<= tk && tk <= LEX_TOKEN_STRING_END))
#define LEX_TOKEN_DATA_FLOAT(tk) (tk==LEX_FLOAT)
#define LEX_TOKEN_DATA_LOOP(tk) (LEX_TOKEN_FOR_BEGIN <= tk && tk <= LEX_TOKEN_FOR_END)
#define LEX_TOKEN_DATA_FUNCTION(tk) (LEX_TOKEN_FUNCTION_BEGIN <= tk && tk <= LEX_TOKEN_FUNCTION_END)
#define LEX_TOKEN_DATA_IF(tk) (tk==LEX_T_IF)
#define LEX_TOKEN_DATA_TRY(tk) (tk==LEX_T_TRY)
#define LEX_TOKEN_DATA_OBJECT_LITERAL(tk) (tk==LEX_T_OBJECT_LITERAL)
#define LEX_TOKEN_DATA_DESTRUCTURING_VAR(tk) (tk==LEX_T_DESTRUCTURING_VAR)
#define LEX_TOKEN_DATA_ARRAY_COMPREHENSIONS_BODY(tk) (tk==LEX_T_ARRAY_COMPREHENSIONS_BODY)
#define LEX_TOKEN_DATA_FORWARDER(tk) (tk==LEX_T_FORWARD)
#define LEX_TOKEN_DATA_SIMPLE(tk) (!((LEX_TOKEN_NONSIMPLE_1_BEGIN <= tk && tk <= LEX_TOKEN_NONSIMPLE_1_END) || (LEX_TOKEN_NONSIMPLE_2_BEGIN <= tk && tk <= LEX_TOKEN_NONSIMPLE_2_END)))
enum SCRIPTVARLINK_FLAGS {
SCRIPTVARLINK_WRITABLE = 1<<0,
SCRIPTVARLINK_CONFIGURABLE = 1<<1,
SCRIPTVARLINK_ENUMERABLE = 1<<2,
SCRIPTVARLINK_DEFAULT = SCRIPTVARLINK_WRITABLE | SCRIPTVARLINK_CONFIGURABLE | SCRIPTVARLINK_ENUMERABLE,
SCRIPTVARLINK_VARDEFAULT = SCRIPTVARLINK_WRITABLE | SCRIPTVARLINK_ENUMERABLE,
SCRIPTVARLINK_CONSTDEFAULT = SCRIPTVARLINK_ENUMERABLE,
SCRIPTVARLINK_BUILDINDEFAULT = SCRIPTVARLINK_WRITABLE | SCRIPTVARLINK_CONFIGURABLE,
SCRIPTVARLINK_READONLY = SCRIPTVARLINK_CONFIGURABLE,
SCRIPTVARLINK_READONLY_ENUM = SCRIPTVARLINK_CONFIGURABLE | SCRIPTVARLINK_ENUMERABLE,
SCRIPTVARLINK_CONSTANT = 0,
};
enum ERROR_TYPES {
Error = 0,
EvalError,
RangeError,
ReferenceError,
SyntaxError,
TypeError
};
#define ERROR_MAX TypeError
#define ERROR_COUNT (ERROR_MAX+1)
extern const char *ERROR_NAME[];
#define TEMPORARY_MARK_SLOTS 5
#define TINYJS_RETURN_VAR "return"
#define TINYJS_LOKALE_VAR "__locale__"
#define TINYJS_ANONYMOUS_VAR "__anonymous__"
#define TINYJS_ARGUMENTS_VAR "arguments"
#define TINYJS_PROTOTYPE_CLASS "prototype"
#define TINYJS_FUNCTION_CLOSURE_VAR "__function_closure__"
#define TINYJS_SCOPE_PARENT_VAR "__scope_parent__"
#define TINYJS_SCOPE_WITH_VAR "__scope_with__"
#define TINYJS_ACCESSOR_GET_VAR "__accessor_get__"
#define TINYJS_ACCESSOR_SET_VAR "__accessor_set__"
#define TINYJS_CONSTRUCTOR_VAR "constructor"
#define TINYJS_TEMP_NAME ""
#define TINYJS_BLANK_DATA ""
typedef std::vector<std::string> STRING_VECTOR_t;
typedef STRING_VECTOR_t::iterator STRING_VECTOR_it;
typedef STRING_VECTOR_t::const_iterator STRING_VECTOR_cit;
typedef std::set<std::string> STRING_SET_t;
typedef STRING_SET_t::iterator STRING_SET_it;
/// convert the given string into a quoted string suitable for javascript
std::string getJSString(const std::string &str);
/// convert the given int into a string
// GCC 4.8 and above because issue with MingW
#if (__cplusplus >= 201103L || isCXX0x(4,8) || _MSC_VER >= 1600) // Visual Studio 2010 and above
# define HAVE_STD_TO_STRING 1
inline std::string int2string(long long intData) { return std::to_string(intData); }
inline std::string int2string(unsigned long long intData) { return std::to_string(intData); }
# if !defined(_MSC_VER) || _MSC_VER >= 19800// Visual Studio 2013 and above
template<typename intType>
typename std::enable_if<std::is_integral<intType>::value, std::string>::type int2string(intType intData) { return std::to_string(intData); }
# else
template<typename intType>
typename std::enable_if<std::is_integral<intType>::value && std::is_signed<intType>::value, std::string>::type int2string(intType intData) { return std::to_string((long long)intData); }
template<typename intType>
typename std::enable_if<std::is_integral<intType>::value && std::is_unsigned<intType>::value, std::string>::type int2string(intType intData) { return std::to_string((unsigned long long)intData); }
# endif
#else
// std::string int2string(int intData);
// std::string int2string(unsigned intData);
// std::string int2string(long intData);
// std::string int2string(unsigned long intData);
// std::string int2string(long long intData);
// std::string int2string(unsigned long long intData);
template<typename intType>
std::string int2string(intType intData);
#endif
/// convert the given double into a string
std::string float2string(const double &floatData);
//////////////////////////////////////////////////////////////////////////
/// CScriptException
//////////////////////////////////////////////////////////////////////////
class CScriptException {
public:
ERROR_TYPES errorType;
std::string message;
std::string fileName;
int32_t lineNumber;
int32_t column;
CScriptException(const std::string &Message, const std::string &File, int32_t Line=-1, int32_t Column=-1) :
errorType(Error), message(Message), fileName(File), lineNumber(Line), column(Column){}
CScriptException(ERROR_TYPES ErrorType, const std::string &Message, const std::string &File, int32_t Line=-1, int32_t Column=-1) :
errorType(ErrorType), message(Message), fileName(File), lineNumber(Line), column(Column){}
CScriptException(const std::string &Message, const char *File="", int32_t Line=-1, int32_t Column=-1) :
errorType(Error), message(Message), fileName(File), lineNumber(Line), column(Column){}
CScriptException(ERROR_TYPES ErrorType, const std::string &Message, const char *File="", int32_t Line=-1, int32_t Column=-1) :
errorType(ErrorType), message(Message), fileName(File), lineNumber(Line), column(Column){}
std::string toString();
};
//////////////////////////////////////////////////////////////////////////
/// CScriptLex
//////////////////////////////////////////////////////////////////////////
class CScriptLex
{
public:
CScriptLex(const char* Code, const std::string& File = "", int Line = 0, int Column = 0);
struct POS;
int tk; ///< The type of the token that we have
int last_tk; ///< The type of the last token that we have
std::string tkStr; ///< Data contained in the token we have here
void check(int expected_tk, int alternate_tk=-1); ///< Lexical check wotsit
void match(int expected_tk, int alternate_tk=-1); ///< Lexical match wotsit
void reset(const POS &toPos); ///< Reset this lex so we can start again
const char* rest() const { return pos.tokenStart; }
std::string currentFile;
struct POS {
const char *tokenStart;
int32_t currentLine;
const char *currentLineStart;
int16_t currentColumn() const { return (int16_t)(tokenStart - currentLineStart) /* silently casted to int16_t because always checked in match(...) */; }
} pos;
int32_t currentLine() const { return pos.currentLine; }
int16_t currentColumn() const { return pos.currentColumn(); }
bool lineBreakBeforeToken;
private:
const char *data;
const char *dataPos;
char currCh, nextCh;
void getNextCh();
void getNextToken(); ///< Get the text token from our text string
};
//////////////////////////////////////////////////////////////////////////
/// CScriptTokenData
//////////////////////////////////////////////////////////////////////////
class CScriptToken;
typedef std::vector<CScriptToken> TOKEN_VECT;
typedef std::vector<CScriptToken>::iterator TOKEN_VECT_it;
typedef std::vector<CScriptToken>::const_iterator TOKEN_VECT_cit;
class CScriptTokenData
{
protected:
CScriptTokenData() : refs(0){}
virtual ~CScriptTokenData() {}
private:
// CScriptTokenData(const CScriptTokenData &noCopy);
// CScriptTokenData &operator=(const CScriptTokenData &noCopy);
public:
void ref() { refs++; }
void unref() { if(--refs == 0) delete this; }
virtual void serialize(std::ostream &) const=0;
private:
int refs;
};
template<typename C>
class CScriptTokenDataPtr {
public:
CScriptTokenDataPtr() : ptr(0) {}
CScriptTokenDataPtr(const CScriptTokenDataPtr &Copy) : ptr(0) { *this=Copy; }
CScriptTokenDataPtr &operator=(const CScriptTokenDataPtr &Copy) {
if(ptr != Copy.ptr) {
if(ptr) ptr->unref();
if((ptr = Copy.ptr)) ptr->ref();
}
return *this;
}
CScriptTokenDataPtr(C &Init) { (ptr=&Init)->ref(); }
~CScriptTokenDataPtr() { if(ptr) ptr->unref(); }
C *operator->() { return ptr; }
const C *operator->() const { return ptr; }
C &operator*() { return *ptr; }
operator bool() const { return ptr!=0; }
bool operator==(const CScriptTokenDataPtr& rhs) const { return ptr==rhs.ptr; }
private:
C *ptr;
};
class CScriptTokenDataString : public fixed_size_object<CScriptTokenDataString>, public CScriptTokenData {
public:
CScriptTokenDataString() {}
CScriptTokenDataString(const std::string &String) : tokenStr(String) {}
CScriptTokenDataString(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
std::string tokenStr;
private:
};
class CScriptTokenDataFnc : public fixed_size_object<CScriptTokenDataFnc>, public CScriptTokenData {
public:
CScriptTokenDataFnc() : line(0),isGenerator(false), isArrowFunction(false) {}
CScriptTokenDataFnc(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
std::string getArgumentsString(bool forArrowFunction=false);
std::string file;
int32_t line;
std::string name;
TOKEN_VECT arguments;
TOKEN_VECT body;
bool isGenerator;
bool isArrowFunction;
};
typedef CScriptTokenDataPtr<CScriptTokenDataFnc> CScriptTokenDataFncPtr;
class CScriptTokenDataForwards : public fixed_size_object<CScriptTokenDataForwards>, public CScriptTokenData {
public:
CScriptTokenDataForwards() {}
CScriptTokenDataForwards(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
bool checkRedefinition(const std::string &Str, bool checkVars);
void addVars( STRING_VECTOR_t &Vars );
void addConsts( STRING_VECTOR_t &Vars );
std::string addVarsInLetscope(STRING_VECTOR_t &Vars);
std::string addLets(STRING_VECTOR_t &Lets);
bool empty() const { return varNames[LETS].empty() && varNames[VARS].empty() && varNames[CONSTS].empty() && functions.empty(); }
enum {
LETS = 0,
VARS,
CONSTS,
END
};
STRING_SET_t varNames[END];
STRING_SET_t vars_in_letscope;
class compare_fnc_token_by_name {
public:
bool operator()(const CScriptToken& lhs, const CScriptToken& rhs) const;
};
typedef std::set<CScriptToken, compare_fnc_token_by_name> FNC_SET_t;
typedef FNC_SET_t::iterator FNC_SET_it;
FNC_SET_t functions;
private:
};
#ifdef old
class CScriptTokenDataForwardsPtr {
public:
CScriptTokenDataForwardsPtr() : ptr(0) {}
CScriptTokenDataForwardsPtr(const CScriptTokenDataForwardsPtr &Copy) : ptr(0) { *this=Copy; }
CScriptTokenDataForwardsPtr &operator=(const CScriptTokenDataForwardsPtr &Copy) {
if(ptr != Copy.ptr) {
if(ptr) ptr->unref();
if((ptr = Copy.ptr)) ptr->ref();
}
return *this;
}
CScriptTokenDataForwardsPtr(CScriptTokenDataForwards &Init) { (ptr=&Init)->ref(); }
~CScriptTokenDataForwardsPtr() { if(ptr) ptr->unref(); }
CScriptTokenDataForwards *operator->() { return ptr; }
operator bool() { return ptr!=0; }
bool operator==(const CScriptTokenDataForwardsPtr& rhs) { return ptr==rhs.ptr; }
private:
CScriptTokenDataForwards *ptr;
};
#else
typedef CScriptTokenDataPtr<CScriptTokenDataForwards> CScriptTokenDataForwardsPtr;
#endif
typedef std::vector<CScriptTokenDataForwardsPtr> FORWARDER_VECTOR_t;
class CScriptTokenDataLoop : public fixed_size_object<CScriptTokenDataLoop>, public CScriptTokenData {
public:
CScriptTokenDataLoop() { type=FOR; }
CScriptTokenDataLoop(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
std::string getParsableString(const std::string &IndentString="", const std::string &Indent="");
enum {FOR_EACH=0, FOR_IN, FOR_OF, FOR, WHILE, DO} type; // do not change the order
STRING_VECTOR_t labels;
TOKEN_VECT init;
TOKEN_VECT condition;
TOKEN_VECT iter;
TOKEN_VECT body;
};
class CScriptTokenDataIf : public fixed_size_object<CScriptTokenDataIf>, public CScriptTokenData {
public:
CScriptTokenDataIf() {}
CScriptTokenDataIf(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
std::string getParsableString(const std::string &IndentString="", const std::string &Indent="");
TOKEN_VECT condition;
TOKEN_VECT if_body;
TOKEN_VECT else_body;
};
typedef std::pair<std::string, std::string> DESTRUCTURING_VAR_t;
typedef std::vector<DESTRUCTURING_VAR_t> DESTRUCTURING_VARS_t;
typedef DESTRUCTURING_VARS_t::iterator DESTRUCTURING_VARS_it;
typedef DESTRUCTURING_VARS_t::const_iterator DESTRUCTURING_VARS_cit;
class CScriptTokenDataDestructuringVar : public fixed_size_object<CScriptTokenDataDestructuringVar>, public CScriptTokenData {
public:
CScriptTokenDataDestructuringVar() {}
CScriptTokenDataDestructuringVar(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
std::string getParsableString();
void getVarNames(STRING_VECTOR_t &Names);
DESTRUCTURING_VARS_t vars;
TOKEN_VECT assignment;
private:
};
class CScriptTokenDataObjectLiteral : public fixed_size_object<CScriptTokenDataObjectLiteral>, public CScriptTokenData {
public:
CScriptTokenDataObjectLiteral() : type(CScriptTokenDataObjectLiteral::OBJECT), destructuring(false), structuring(false) {}
CScriptTokenDataObjectLiteral(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
std::string getParsableString();
void setMode(bool Destructuring);
bool toDestructuringVar(CScriptTokenDataDestructuringVar &DestructuringVar);
enum {OBJECT, ARRAY, ARRAY_COMPREHENSIONS, ARRAY_COMPREHENSIONS_OLD} type;
struct ELEMENT {
std::string id;
TOKEN_VECT value;
};
bool destructuring;
bool structuring;
typedef std::vector<ELEMENT> ELEMENTS_t;
typedef ELEMENTS_t::iterator ELEMENTS_it;
typedef ELEMENTS_t::const_iterator ELEMENTS_cit;
ELEMENTS_t elements;
private:
};
class CScriptTokenDataArrayComprehensionsBody : public fixed_size_object<CScriptTokenDataArrayComprehensionsBody>, public CScriptTokenData {
public:
CScriptTokenDataArrayComprehensionsBody() {}
CScriptTokenDataArrayComprehensionsBody(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
TOKEN_VECT body;
};
class CScriptTokenDataTry : public fixed_size_object<CScriptTokenDataTry>, public CScriptTokenData {
public:
CScriptTokenDataTry() {}
CScriptTokenDataTry(std::istream &in);
virtual void serialize(std::ostream &out) const OVERRIDE;
std::string getParsableString(const std::string &IndentString="", const std::string &Indent="");
TOKEN_VECT tryBlock;
struct CatchBlock {
CScriptTokenDataPtr<CScriptTokenDataDestructuringVar> indentifiers;
TOKEN_VECT condition;
TOKEN_VECT block;
};
typedef std::vector<CatchBlock> CATCHBLOCKS_t;
typedef CATCHBLOCKS_t::iterator CATCHBLOCKS_it;
typedef CATCHBLOCKS_t::const_iterator CATCHBLOCKS_cit;
CATCHBLOCKS_t catchBlocks;
TOKEN_VECT finallyBlock;
};
//////////////////////////////////////////////////////////////////////////
/// CScriptToken
//////////////////////////////////////////////////////////////////////////
class CScriptTokenizer;
/*
a Token needs 8 Byte
2 Bytes for the Row-Position of the Token
2 Bytes for the Token self
and
4 Bytes for special Datas in an union
e.g. an int for interger-literals
or pointer for double-literals,
for string-literals or for functions
*/
class CScriptToken : public fixed_size_object<CScriptToken>
{
public:
CScriptToken() : line(0), column(0), token(0), intData(0) {}
CScriptToken(CScriptLex *l, int Match=-1, int Alternate=-1);
CScriptToken(uint16_t Tk, int32_t IntData=0);
CScriptToken(uint16_t Tk, double FloatData);
CScriptToken(uint16_t Tk, const std::string &TkStr);
CScriptToken(const CScriptToken &Copy) : token(0) { *this = Copy; }
CScriptToken &operator =(const CScriptToken &Copy);
CScriptToken(std::istream &in);
~CScriptToken() { clear(); }
void serialize(std::ostream &out) const;
int32_t &Int() { ASSERT(LEX_TOKEN_DATA_SIMPLE(token)); return intData; }
std::string &String() { ASSERT(LEX_TOKEN_DATA_STRING(token)); return dynamic_cast<CScriptTokenDataString*>(tokenData)->tokenStr; }
double &Float() { ASSERT(LEX_TOKEN_DATA_FLOAT(token)); return *floatData; }
CScriptTokenDataFnc &Fnc() { ASSERT(LEX_TOKEN_DATA_FUNCTION(token)); return *dynamic_cast<CScriptTokenDataFnc*>(tokenData); }
const CScriptTokenDataFnc &Fnc() const { ASSERT(LEX_TOKEN_DATA_FUNCTION(token)); return *dynamic_cast<CScriptTokenDataFnc*>(tokenData); }
CScriptTokenDataObjectLiteral &Object() { ASSERT(LEX_TOKEN_DATA_OBJECT_LITERAL(token)); return *dynamic_cast<CScriptTokenDataObjectLiteral*>(tokenData); }
CScriptTokenDataDestructuringVar &DestructuringVar() { ASSERT(LEX_TOKEN_DATA_DESTRUCTURING_VAR(token)); return *dynamic_cast<CScriptTokenDataDestructuringVar*>(tokenData); }
CScriptTokenDataArrayComprehensionsBody &ArrayComprehensionsBody() { ASSERT(LEX_TOKEN_DATA_ARRAY_COMPREHENSIONS_BODY(token)); return *dynamic_cast<CScriptTokenDataArrayComprehensionsBody*>(tokenData); }
CScriptTokenDataLoop &Loop() { ASSERT(LEX_TOKEN_DATA_LOOP(token)); return *dynamic_cast<CScriptTokenDataLoop*>(tokenData); }
CScriptTokenDataIf &If() { ASSERT(LEX_TOKEN_DATA_IF(token)); return *dynamic_cast<CScriptTokenDataIf*>(tokenData); }
CScriptTokenDataTry &Try() { ASSERT(LEX_TOKEN_DATA_TRY(token)); return *dynamic_cast<CScriptTokenDataTry*>(tokenData); }
CScriptTokenDataForwards &Forwarder() { ASSERT(LEX_TOKEN_DATA_FORWARDER(token)); return *dynamic_cast<CScriptTokenDataForwards*>(tokenData); }
CScriptTokenData &TokenData() { CScriptTokenData *data = dynamic_cast<CScriptTokenData*>(tokenData); ASSERT(data); return *data; }
const CScriptTokenData &TokenData() const { CScriptTokenData *data = dynamic_cast<CScriptTokenData*>(tokenData); ASSERT(data); return *data; }
#ifdef _DEBUG
std::string token_str;
#endif
uint16_t line;
uint16_t column;
uint16_t token;
static std::string getParsableString(TOKEN_VECT &Tokens, const std::string &IndentString="", const std::string &Indent="");
static std::string getParsableString(TOKEN_VECT_it Begin, TOKEN_VECT_it End, const std::string &IndentString="", const std::string &Indent="");
static std::string getTokenStr( int token, const char *tokenStr=0, bool *need_space=0 );
static const char *isReservedWord(int Token);
static int isReservedWord(const std::string &Str);
template<typename T> static void serialize(const T &value, std::ostream &out) {
out.write(reinterpret_cast<const char*>(&value), sizeof(value));
}
template<typename T> static T &unserialize(T &value, std::istream &in) {
in.read(reinterpret_cast<char*>(&value), sizeof(value));
return value;
}
static void serialize(const std::string &value, std::ostream &out);
static std::string &unserialize(std::string &value, std::istream &in);
static void serialize(const STRING_VECTOR_t &value, std::ostream &out);
static STRING_VECTOR_t &unserialize(STRING_VECTOR_t &value, std::istream &in);
static void serialize(const TOKEN_VECT &Tokens, std::ostream &out);
static void unserialize(TOKEN_VECT &Tokens, std::istream &in);
private:
void clear();
union {
int32_t intData;
double *floatData;
CScriptTokenData *tokenData;
};
};
//////////////////////////////////////////////////////////////////////////
/// CScriptTokenizer - converts the code in a vector with tokens
//////////////////////////////////////////////////////////////////////////
typedef std::vector<size_t> MARKS_t;
class CScriptTokenizer
{
public:
struct ScriptTokenPosition {
ScriptTokenPosition(TOKEN_VECT *Tokens) : tokens(Tokens), pos(tokens->begin())/*, currentLine(0)*//*, currentColumn(0)*/ {}
bool operator ==(const ScriptTokenPosition &eq) { return pos == eq.pos; }
ScriptTokenPosition &operator =(const ScriptTokenPosition ©) {
tokens=copy.tokens; pos=copy.pos;
return *this;
}
TOKEN_VECT *tokens;
TOKEN_VECT_it pos;
int currentLine() const { return pos->line; }
int currentColumn() const { return pos->column; }
};
struct ScriptTokenState {
ScriptTokenState() : LeftHand(false), FunctionIsGenerator(false), HaveReturnValue(false) {}
TOKEN_VECT Tokens;
FORWARDER_VECTOR_t Forwarders;
MARKS_t Marks;
STRING_VECTOR_t Labels;
STRING_VECTOR_t LoopLabels;
bool LeftHand;
void pushLeftHandState() { States.push_back(LeftHand); }
void popLeftHandeState() { LeftHand = States.back(); States.pop_back(); }
std::vector<bool> States;
bool FunctionIsGenerator;
bool HaveReturnValue;
};
CScriptTokenizer();
CScriptTokenizer(CScriptLex &Lexer);
CScriptTokenizer(const char *Code, const std::string &File="", int Line=0, int Column=0);
static bool writeCompiledTokens;
private:
void unserialize(const std::string &File, const std::string &FileC="");
void serialize(std::ostream &out) const;
void serialize(const std::string &File);
void serialize(const std::string &File, const std::nothrow_t &);
public:
void tokenizeCode(CScriptLex &Lexer);
CScriptToken &getToken() { return *(tokenScopeStack.back().pos); }
void getNextToken();
bool check(int ExpectedToken, int AlternateToken=-1);
void match(int ExpectedToken, int AlternateToken=-1);
void pushTokenScope(TOKEN_VECT &Tokens);
ScriptTokenPosition &getPos() { return tokenScopeStack.back(); }
void setPos(ScriptTokenPosition &TokenPos);
ScriptTokenPosition &getPrevPos() { return prevPos; }
void skip(int Tokens);
int tk; // current Token
std::string currentFile;
int currentLine() { return getPos().currentLine();}
int currentColumn() { return getPos().currentColumn();}
const std::string &tkStr() { static std::string empty; return LEX_TOKEN_DATA_STRING(getToken().token)?getToken().String():empty; }
private:
void tokenizeTry(ScriptTokenState &State, int Flags);
void tokenizeSwitch(ScriptTokenState &State, int Flags);
void tokenizeWith(ScriptTokenState &State, int Flags);
void tokenizeWhileAndDo(ScriptTokenState &State, int Flags);
void tokenizeIf_inArrayComprehensions(ScriptTokenState &State, int Flags, TOKEN_VECT &Assign);
void tokenizeIf(ScriptTokenState &State, int Flags);
void tokenizeFor_inArrayComprehensions(ScriptTokenState &State, int Flags, TOKEN_VECT &Assign);
void tokenizeFor(ScriptTokenState &State, int Flags);
CScriptToken tokenizeVarIdentifier(STRING_VECTOR_t *VarNames=0, bool *NeedAssignment=0);
CScriptToken tokenizeFunctionArgument();
void tokenizeArrowFunction(const TOKEN_VECT &Arguments, ScriptTokenState &State, int Flags, bool noLetDef=false);
void tokenizeFunction(ScriptTokenState &State, int Flags, bool noLetDef=false);
void tokenizeLet(ScriptTokenState &State, int Flags, bool noLetDef=false);
void tokenizeVarNoConst(ScriptTokenState &State, int Flags);
void tokenizeVarAndConst(ScriptTokenState &State, int Flags);
void _tokenizeLiteralObject(ScriptTokenState &State, int Flags);
void _tokenizeLiteralArray(ScriptTokenState &State, int Flags);
bool _tokenizeArrayComprehensions(ScriptTokenState &State, int Flags);
void tokenizeLiteral(ScriptTokenState &State, int Flags);
void tokenizeMember(ScriptTokenState &State, int Flags);
void tokenizeFunctionCall(ScriptTokenState &State, int Flags);
void tokenizeSubExpression(ScriptTokenState &State, int Flags);
void tokenizeLogic(ScriptTokenState &State, int Flags, int op= LEX_OROR, int op_n=LEX_ANDAND);
void tokenizeCondition(ScriptTokenState &State, int Flags);
void tokenizeAssignment(ScriptTokenState& State, int Flags); // = += -= *= /= %= <<= >>= >>>= &= |= ^= AND ??=
void tokenizeExpression(ScriptTokenState& State, int Flags); // ..., ...
void tokenizeBlock(ScriptTokenState& State, int Flags); // { ... }
void tokenizeStatementNoLet(ScriptTokenState &State, int Flags);
void tokenizeStatement(ScriptTokenState &State, int Flags);
size_t pushToken(TOKEN_VECT &Tokens, int Match=-1, int Alternate=-1);
size_t pushToken(TOKEN_VECT &Tokens, const CScriptToken &Token);
void pushForwarder(ScriptTokenState &State, bool noMarks=false);
void removeEmptyForwarder(ScriptTokenState &State);
void pushForwarder(TOKEN_VECT &Tokens, FORWARDER_VECTOR_t &Forwarders, MARKS_t &Marks);
void removeEmptyForwarder(TOKEN_VECT &Tokens, FORWARDER_VECTOR_t &Forwarders, MARKS_t &Marks);
void throwTokenNotExpected();
CScriptLex *l;
TOKEN_VECT tokens;
ScriptTokenPosition prevPos;
std::vector<ScriptTokenPosition> tokenScopeStack;
};
//////////////////////////////////////////////////////////////////////////
/// forward-declaration
//////////////////////////////////////////////////////////////////////////
class CNumber;
class CScriptVar;
class CScriptVarPtr;
template<typename C> class CScriptVarPointer;
class CScriptVarLink;
class CScriptVarLinkPtr;
class CScriptVarLinkWorkPtr;
class CScriptVarPrimitive;
typedef CScriptVarPointer<CScriptVarPrimitive> CScriptVarPrimitivePtr;
class CScriptVarScopeFnc;
typedef CScriptVarPointer<CScriptVarScopeFnc> CFunctionsScopePtr;
typedef void (*JSCallback)(const CFunctionsScopePtr &var, void *userdata);
class CTinyJS;
class CScriptResult;
enum IteratorMode {
RETURN_KEY = 1,
RETURN_VALUE = 2,
RETURN_ARRAY = 3
};
//////////////////////////////////////////////////////////////////////////
/// CScriptPropertyName
//////////////////////////////////////////////////////////////////////////
/// CScriptPropertyName holds the name of any property
class CScriptPropertyName {
public:
CScriptPropertyName() : idx(-1) {}
// property name
CScriptPropertyName(const std::string &Name) : name(Name), idx(name2arrayIdx(Name)) {}
// array index
CScriptPropertyName(uint32_t Idx) : name(int2string(Idx)), idx(Idx) { if (idx == 0xffffffffUL) idx = -1; }
// symbol
CScriptPropertyName(uint32_t Id, const std::string &Desc) : name(Desc), idx(-1-(int64_t)Id) {}
bool operator<(const CScriptPropertyName& rhs) {
int64_t lhs_idx = idx + 1;
int64_t rhs_idx = rhs.idx + 1;
if (lhs_idx < rhs_idx) return true;
if (lhs_idx == 0 && rhs_idx == 0) return name < rhs.name;
return false;
}
bool isArrayIdx() const { return 0 <= idx && idx < 0xFFFFFFFFLL; }
bool isPropertyName() const { return idx == -1; }
bool isSymbol() const { return idx < -1; }
private:
static int64_t name2arrayIdx(const std::string &Name);
std::string name;
int64_t idx; /* -1 ==> normal Name; >=0 ==> arrayIdx; <-1 ==> Symbol*/
};
//////////////////////////////////////////////////////////////////////////
/// CScriptVar
//////////////////////////////////////////////////////////////////////////
typedef std::vector<class CScriptVarLinkPtr> SCRIPTVAR_CHILDS_t;
typedef SCRIPTVAR_CHILDS_t::iterator SCRIPTVAR_CHILDS_it;
typedef SCRIPTVAR_CHILDS_t::reverse_iterator SCRIPTVAR_CHILDS_rit;
typedef SCRIPTVAR_CHILDS_t::const_iterator SCRIPTVAR_CHILDS_cit;
// CScriptVar is the base class of all variable values.
// Instances of CScriptVar can only exists as pointer. CScriptVarPtr holds this pointer
// CScriptVar is the base class of all variable values.
//
class CScriptVar : public fixed_size_object<CScriptVar> {
protected:
CScriptVar(CTinyJS* Context, const CScriptVarPtr& Prototype); ///< Create
CScriptVar(const CScriptVar &Copy); ///< Copy protected -> use clone for public
private:
CScriptVar & operator=(const CScriptVar &Copy) MEMBER_DELETE; ///< private -> no assignment-Copy
public:
virtual ~CScriptVar();
virtual CScriptVarPtr clone()=0;
//************************************
// Method: getPrototype
// FullName: CScriptVar::getPrototype
// Access: public
// Returns: CScriptVarPtr
// Qualifier:
//************************************
CScriptVarPtr getPrototype();
void setPrototype(const CScriptVarPtr& Prototype);
/// Type
virtual bool isObject(); ///< is an Object
virtual bool isArray(); ///< is an Array
virtual bool isDate(); ///< is a Date-Object
virtual bool isError(); ///< is an ErrorObject
virtual bool isRegExp(); ///< is a RegExpObject
virtual bool isAccessor(); ///< is an Accessor
virtual bool isNull(); ///< is Null
virtual bool isUndefined(); ///< is Undefined
bool isNullOrUndefined(); ///< is Null or Undefined
virtual bool isNaN(); ///< is NaN
virtual bool isString(); ///< is String
virtual bool isInt(); ///< is Integer
virtual bool isBool(); ///< is Bool
virtual int isInfinity(); ///< is Infinity ///< +1==POSITIVE_INFINITY, -1==NEGATIVE_INFINITY, 0==is not an InfinityVar
virtual bool isDouble(); ///< is Double
virtual bool isRealNumber();///< is isInt | isDouble
virtual bool isNumber(); ///< is isNaN | isInt | isDouble | isInfinity
virtual bool isPrimitive(); ///< isNull | isUndefined | isNaN | isString | isInt | isDouble | isInfinity
virtual bool isFunction(); ///< is CScriptVarFunction / CScriptVarFunctionNativeCallback / CScriptVarFunctionNativeClass
virtual bool isNative(); ///< is CScriptVarFunctionNativeCallback / CScriptVarFunctionNativeClass
virtual bool isBounded(); ///< is CScriptVarFunctionBounded
virtual bool isIterator();
virtual bool isGenerator();
//bool isBasic() const { return Childs.empty(); } ///< Is this *not* an array/object/etc
//////////////////////////////////////////////////////////////////////////
/// Value
//////////////////////////////////////////////////////////////////////////
virtual CScriptVarPrimitivePtr getRawPrimitive()=0; ///< is Var==Primitive -> return this isObject return Value
CScriptVarPrimitivePtr toPrimitive(); ///< by default call getDefaultValue_hintNumber by a Date-object calls getDefaultValue_hintString
virtual CScriptVarPrimitivePtr toPrimitive(CScriptResult &execute); ///< if the var an ObjectType gets the valueOf; if valueOf of an ObjectType gets toString / otherwise gets the Var itself
CScriptVarPrimitivePtr toPrimitive_hintString(int32_t radix=0); ///< if the var an ObjectType gets the valueOf; if valueOf of an ObjectType gets toString / otherwise gets the Var itself
CScriptVarPrimitivePtr toPrimitive_hintString(CScriptResult &execute, int32_t radix=0); ///< if the var an ObjectType gets the valueOf; if valueOf of an ObjectType gets toString / otherwise gets the Var itself
CScriptVarPrimitivePtr toPrimitive_hintNumber(); ///< if the var an ObjectType gets the valueOf; if valueOf of an ObjectType gets toString / otherwise gets the Var itself
CScriptVarPrimitivePtr toPrimitive_hintNumber(CScriptResult &execute); ///< if the var an ObjectType gets the valueOf; if valueOf of an ObjectType gets toString / otherwise gets the Var itself
CScriptVarPtr callJS_toString(CScriptResult &execute, int radix=0);
virtual CScriptVarPtr toString_CallBack(CScriptResult &execute, int radix=0);
CScriptVarPtr callJS_valueOf(CScriptResult &execute);
virtual CScriptVarPtr valueOf_CallBack();
CNumber toNumber();
CNumber toNumber(CScriptResult &execute);
virtual bool toBoolean();
std::string toString(int32_t radix=0); ///< shortcut for this->toPrimitive_hintString()->toCString();
std::string toString(CScriptResult &execute, int32_t radix=0); ///< shortcut for this->toPrimitive_hintString(execute)->toCString();
int DEPRECATED("getInt() is deprecated use toNumber().toInt32 instead") getInt();
bool DEPRECATED("getBool() is deprecated use toBoolean() instead") getBool();
double DEPRECATED("getDouble() is deprecated use toNumber().toDouble() instead") getDouble();
std::string DEPRECATED("getString() is deprecated use toString() instead") getString();
virtual void setter(CScriptResult &execute, const CScriptVarLinkPtr &link, const CScriptVarPtr &value);
virtual CScriptVarLinkPtr &getter(CScriptResult &execute, CScriptVarLinkPtr &link);
virtual CScriptTokenDataFnc *getFunctionData(); ///< { return 0; }
virtual CScriptVarPtr toObject()=0;
CScriptVarPtr toIterator(IteratorMode Mode=RETURN_ARRAY);
CScriptVarPtr toIterator(CScriptResult &execute, IteratorMode Mode=RETURN_ARRAY);
// virtual std::string getParsableString(const std::string &indentString, const std::string &indent, bool &hasRecursion); ///< get Data as a parsable javascript string
#define getParsableStringRecursionsCheckBegin() do{ \
if(uniqueID) { \
if(uniqueID==getTemporaryMark()) { hasRecursion=true; return "recursion"; } \
setTemporaryMark(uniqueID); \
} \
} while(0)
#define getParsableStringRecursionsCheckEnd() setTemporaryMark(0)
std::string getParsableString(); ///< get Data as a parsable javascript string
virtual std::string getParsableString(const std::string &indentString, const std::string &indent, uint32_t uniqueID, bool &hasRecursion); ///< get Data as a parsable javascript string
virtual std::string getVarType()=0;
CScriptVarPtr DEPRECATED("getNumericVar() is deprecated use toNumber() instead") getNumericVar(); ///< returns an Integer, a Double, an Infinity or a NaN
//////////////////////////////////////////////////////////////////////////
/// Childs
//////////////////////////////////////////////////////////////////////////
CScriptVarPtr getOwnPropertyDescriptor(const std::string &Name);
const char *defineProperty(const std::string &Name, CScriptVarPtr Attributes);
/// flags
void setExtensible(bool On=true) { extensible=On; }
void preventExtensions() { extensible=false; }
bool isExtensible() const { return extensible; }
void seal();
bool isSealed() const;
void freeze();
bool isFrozen() const;
/// find
CScriptVarLinkPtr findChild(const std::string &childName); ///< Tries to find a child with the given name, may return 0