-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathNodes.h
More file actions
2795 lines (2172 loc) · 109 KB
/
Nodes.h
File metadata and controls
2795 lines (2172 loc) · 109 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
/*
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003-2025 Apple Inc. All rights reserved.
* Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
* Copyright (C) 2007 Maks Orlovich
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#pragma once
#include "BytecodeIntrinsicRegistry.h"
#include "ImplementationVisibility.h"
#include "JITCode.h"
#include "Label.h"
#include "ModuleScopeData.h"
#include "ParserArena.h"
#include "ParserModes.h"
#include "ParserTokens.h"
#include "ResultType.h"
#include "SourceCode.h"
#include "SymbolTable.h"
#include "UnlinkedFunctionExecutable.h"
#include "VariableEnvironment.h"
#include <wtf/MathExtras.h>
#include <wtf/SmallSet.h>
namespace JSC {
enum OpcodeID : unsigned;
class ArgumentListNode;
class BytecodeGenerator;
class FunctionMetadataNode;
class FunctionParameters;
class ModuleAnalyzer;
class PropertyListNode;
class ReadModifyResolveNode;
class RegisterID;
class ScopeNode;
typedef SmallSet<UniquedStringImpl*> UniquedStringImplPtrSet;
enum class Operator : uint8_t {
Equal,
PlusEq,
MinusEq,
MultEq,
DivEq,
PlusPlus,
MinusMinus,
BitAndEq,
BitXOrEq,
BitOrEq,
ModEq,
PowEq,
CoalesceEq,
OrEq,
AndEq,
LShift,
RShift,
URShift
};
enum class LogicalOperator : uint8_t {
And,
Or
};
enum FallThroughMode : uint8_t {
FallThroughMeansTrue = 0,
FallThroughMeansFalse = 1
};
inline FallThroughMode invert(FallThroughMode fallThroughMode) { return static_cast<FallThroughMode>(!fallThroughMode); }
namespace DeclarationStacks {
typedef Vector<FunctionMetadataNode*> FunctionStack;
}
struct SwitchInfo {
enum class SwitchType : uint8_t { None, Immediate, Character, ImmediateList, CharacterList, String };
uint32_t bytecodeOffset;
SwitchType switchType;
};
enum class AssignmentContext : uint8_t {
DeclarationStatement,
ConstDeclarationStatement,
UsingDeclarationStatement,
AwaitUsingDeclarationStatement,
AssignmentExpression
};
class ParserArenaFreeable {
public:
// ParserArenaFreeable objects are freed when the arena is deleted.
// Destructors are not called. Clients must not call delete on such objects.
void* operator new(size_t, ParserArena&);
};
class ParserArenaDeletable {
public:
virtual ~ParserArenaDeletable() { }
// ParserArenaDeletable objects are deleted when the arena is deleted.
// Clients must not call delete directly on such objects.
template<typename T> void* operator new(size_t, ParserArena&);
};
#define JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED_IMPL(__classToNew) \
void* operator new(size_t size, ParserArena& parserArena) \
{ \
return ParserArenaDeletable::operator new<__classToNew>(size, parserArena); \
}
#define JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(__classToNew) \
public: \
JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED_IMPL(__classToNew) \
private: \
typedef int __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ParserArenaRoot);
class ParserArenaRoot {
WTF_DEPRECATED_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ParserArenaRoot, ParserArenaRoot);
protected:
ParserArenaRoot(ParserArena&);
public:
ParserArena& parserArena() LIFETIME_BOUND { return m_arena; }
virtual ~ParserArenaRoot() { }
protected:
ParserArena m_arena;
};
class Node : public ParserArenaFreeable {
protected:
Node(const JSTokenLocation&);
public:
virtual ~Node() { }
int firstLine() const { return m_position.line; }
int startOffset() const { return m_position.offset; }
int endOffset() const { return m_endOffset; }
int lineStartOffset() const { return m_position.lineStartOffset; }
const JSTextPosition& position() const LIFETIME_BOUND { return m_position; }
void setEndOffset(int offset) { m_endOffset = offset; }
void setStartOffset(int offset) { m_position.offset = offset; }
bool needsDebugHook() const { return m_needsDebugHook; }
void setNeedsDebugHook() { m_needsDebugHook = true; }
protected:
JSTextPosition m_position;
int m_endOffset { -1 };
bool m_needsDebugHook { false };
};
class ExpressionNode : public Node {
protected:
ExpressionNode(const JSTokenLocation&, ResultType = ResultType::unknownType());
public:
virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* destination = nullptr) = 0;
virtual bool isNumber() const { return false; }
virtual bool isString() const { return false; }
virtual bool isBigInt() const { return false; }
virtual bool isObjectLiteral() const { return false; }
virtual bool isArrayLiteral() const { return false; }
virtual bool isNull() const { return false; }
virtual bool isPure(BytecodeGenerator&) const { return false; }
virtual bool isConstant() const { return false; }
virtual bool isLocation() const { return false; }
virtual bool isPrivateLocation() const { return false; }
virtual bool isAssignmentLocation() const { return isLocation(); }
virtual bool isResolveNode() const { return false; }
virtual bool isAssignResolveNode() const { return false; }
virtual bool isBracketAccessorNode() const { return false; }
virtual bool isDotAccessorNode() const { return false; }
virtual bool isDestructuringNode() const { return false; }
virtual bool isBaseFuncExprNode() const { return false; }
virtual bool isFuncExprNode() const { return false; }
virtual bool isArrowFuncExprNode() const { return false; }
virtual bool isClassExprNode() const { return false; }
virtual bool isCommaNode() const { return false; }
virtual bool isSimpleArray() const { return false; }
virtual bool isAdd() const { return false; }
virtual bool isSubtract() const { return false; }
virtual bool isBoolean() const { return false; }
virtual bool isThisNode() const { return false; }
virtual bool isSpreadExpression() const { return false; }
virtual bool isSuperNode() const { return false; }
virtual bool isImportNode() const { return false; }
virtual bool isMetaProperty() const { return false; }
virtual bool isNewTarget() const { return false; }
virtual bool isImportMeta() const { return false; }
virtual bool isBytecodeIntrinsicNode() const { return false; }
virtual bool isBinaryOpNode() const { return false; }
virtual bool isFunctionCall() const { return false; }
virtual bool isDeleteNode() const { return false; }
virtual bool isOptionalChain() const { return false; }
virtual bool isOptionalCall() const { return false; }
virtual bool isPrivateIdentifier() const { return false; }
virtual bool isArgumentsLengthAccess(VM&) const { return false; }
virtual bool isArguments(VM&) const { return false; }
virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label&, Label&, FallThroughMode);
virtual ExpressionNode* stripUnaryPlus() { return this; }
ResultType resultDescriptor() const { return m_resultType; }
bool isOptionalChainBase() const { return m_isOptionalChainBase; }
void setIsOptionalChainBase() { m_isOptionalChainBase = true; }
private:
ResultType m_resultType;
bool m_isOptionalChainBase { false };
};
class StatementNode : public Node {
protected:
StatementNode(const JSTokenLocation&);
public:
virtual void emitBytecode(BytecodeGenerator&, RegisterID* destination = nullptr) = 0;
void setLoc(unsigned firstLine, unsigned lastLine, int startOffset, int lineStartOffset);
unsigned lastLine() const { return m_lastLine; }
StatementNode* next() const { return m_next; }
void setNext(StatementNode* next) { m_next = next; }
virtual bool hasCompletionValue() const { return true; }
virtual bool hasEarlyBreakOrContinue() const { return false; }
virtual bool isEmptyStatement() const { return false; }
virtual bool isDebuggerStatement() const { return false; }
virtual bool isFunctionNode() const { return false; }
virtual bool isReturnNode() const { return false; }
virtual bool isExprStatement() const { return false; }
virtual bool isBreak() const { return false; }
virtual bool isContinue() const { return false; }
virtual bool isLabel() const { return false; }
virtual bool isBlock() const { return false; }
virtual bool isFuncDeclNode() const { return false; }
virtual bool isModuleDeclarationNode() const { return false; }
virtual bool isForOfNode() const { return false; }
virtual bool isDefineFieldNode() const { return false; }
protected:
int m_lastLine { -1 };
StatementNode* m_next { nullptr };
};
class VariableEnvironmentNode : public ParserArenaDeletable {
JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED(VariableEnvironmentNode);
public:
typedef DeclarationStacks::FunctionStack FunctionStack;
VariableEnvironmentNode() = default;
VariableEnvironmentNode(VariableEnvironment&& lexicalDeclaredVariables);
VariableEnvironmentNode(VariableEnvironment&& lexicalDeclaredVariables, FunctionStack&&);
VariableEnvironment& lexicalVariables() LIFETIME_BOUND { return m_lexicalVariables; }
FunctionStack& functionStack() LIFETIME_BOUND { return m_functionStack; }
bool hasUsingDeclaration() const { return m_lexicalVariables.hasUsingDeclaration(); }
bool hasAwaitUsingDeclaration() const { return m_lexicalVariables.hasAwaitUsingDeclaration(); }
unsigned usingDeclarationCount() const { return m_lexicalVariables.usingDeclarationCount(); }
protected:
VariableEnvironment m_lexicalVariables;
FunctionStack m_functionStack;
};
class ConstantNode : public ExpressionNode {
public:
ConstantNode(const JSTokenLocation&, ResultType);
bool isPure(BytecodeGenerator&) const override { return true; }
bool isConstant() const override { return true; }
virtual JSValue jsValue(BytecodeGenerator&) const = 0;
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) override;
void emitBytecodeInConditionContext(BytecodeGenerator&, Label& trueTarget, Label& falseTarget, FallThroughMode) override;
};
class NullNode final : public ConstantNode {
public:
NullNode(const JSTokenLocation&);
private:
bool isNull() const final { return true; }
JSValue jsValue(BytecodeGenerator&) const final { return jsNull(); }
};
class BooleanNode final : public ConstantNode {
public:
BooleanNode(const JSTokenLocation&, bool value);
bool value() { return m_value; }
private:
bool isBoolean() const final { return true; }
JSValue jsValue(BytecodeGenerator&) const final { return jsBoolean(m_value); }
bool m_value;
};
class NumberNode : public ConstantNode {
public:
NumberNode(const JSTokenLocation&, double value);
double value() const { return m_value; }
virtual bool isIntegerNode() const = 0;
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
private:
bool isNumber() const final { return true; }
JSValue jsValue(BytecodeGenerator&) const override { return jsNumber(m_value); }
double m_value;
};
class DoubleNode : public NumberNode {
public:
DoubleNode(const JSTokenLocation&, double value);
private:
bool isIntegerNode() const override { return false; }
};
// An integer node represent a number represented as an integer (e.g. 42 instead of 42., 42.0, 42e0)
class IntegerNode final : public DoubleNode {
public:
IntegerNode(const JSTokenLocation&, double value);
bool isIntegerNode() const final { return true; }
};
class StringNode final : public ConstantNode {
public:
StringNode(const JSTokenLocation&, const Identifier&);
const Identifier& value() { return m_value; }
private:
bool isString() const final { return true; }
JSValue jsValue(BytecodeGenerator&) const final;
const Identifier& m_value;
};
class BigIntNode final : public ConstantNode {
public:
BigIntNode(const JSTokenLocation&, const Identifier&, uint8_t radix);
BigIntNode(const JSTokenLocation&, const Identifier&, uint8_t radix, bool sign);
const Identifier& value() { return m_value; }
const Identifier& identifier() const { return m_value; }
uint8_t radix() const { return m_radix; }
bool sign() const { return m_sign; }
private:
bool isBigInt() const final { return true; }
JSValue jsValue(BytecodeGenerator&) const final;
const Identifier& m_value;
const uint8_t m_radix;
const bool m_sign;
};
class ThrowableExpressionData {
public:
ThrowableExpressionData() = default;
ThrowableExpressionData(const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end)
: m_divot(divot)
, m_divotStart(start)
, m_divotEnd(end)
{
checkConsistency();
}
void setExceptionSourceCode(const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd)
{
m_divot = divot;
m_divotStart = divotStart;
m_divotEnd = divotEnd;
checkConsistency();
}
const JSTextPosition& divot() const LIFETIME_BOUND { return m_divot; }
const JSTextPosition& divotStart() const LIFETIME_BOUND { return m_divotStart; }
const JSTextPosition& divotEnd() const LIFETIME_BOUND { return m_divotEnd; }
void checkConsistency() const
{
ASSERT(m_divot.offset >= m_divot.lineStartOffset);
ASSERT(m_divotStart.offset >= m_divotStart.lineStartOffset);
ASSERT(m_divotEnd.offset >= m_divotEnd.lineStartOffset);
ASSERT(m_divot.offset >= m_divotStart.offset);
ASSERT(m_divotEnd.offset >= m_divot.offset);
}
protected:
RegisterID* emitThrowReferenceError(BytecodeGenerator&, ASCIILiteral message, RegisterID* dst = nullptr);
private:
JSTextPosition m_divot;
JSTextPosition m_divotStart;
JSTextPosition m_divotEnd;
};
class ThrowableSubExpressionData : public ThrowableExpressionData {
public:
ThrowableSubExpressionData()
: m_subexpressionDivotOffset(0)
, m_subexpressionEndOffset(0)
, m_subexpressionLineOffset(0)
, m_subexpressionLineStartOffset(0)
{
}
ThrowableSubExpressionData(const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd)
: ThrowableExpressionData(divot, divotStart, divotEnd)
, m_subexpressionDivotOffset(0)
, m_subexpressionEndOffset(0)
, m_subexpressionLineOffset(0)
, m_subexpressionLineStartOffset(0)
{
}
void setSubexpressionInfo(const JSTextPosition& subexpressionDivot, int subexpressionOffset)
{
ASSERT(subexpressionDivot.offset <= divot().offset);
// Overflow means we can't do this safely, so just point at the primary divot,
// divotLine, or divotLineStart.
if ((divot() - subexpressionDivot.offset) & ~0xFFFF)
return;
if ((divot().line - subexpressionDivot.line) & ~0xFFFF)
return;
if ((divot().lineStartOffset - subexpressionDivot.lineStartOffset) & ~0xFFFF)
return;
if ((divotEnd() - subexpressionOffset) & ~0xFFFF)
return;
m_subexpressionDivotOffset = divot() - subexpressionDivot.offset;
m_subexpressionEndOffset = divotEnd() - subexpressionOffset;
m_subexpressionLineOffset = divot().line - subexpressionDivot.line;
m_subexpressionLineStartOffset = divot().lineStartOffset - subexpressionDivot.lineStartOffset;
}
JSTextPosition subexpressionDivot()
{
int newLine = divot().line - m_subexpressionLineOffset;
int newOffset = divot().offset - m_subexpressionDivotOffset;
int newLineStartOffset = divot().lineStartOffset - m_subexpressionLineStartOffset;
return JSTextPosition(newLine, newOffset, newLineStartOffset);
}
JSTextPosition subexpressionStart() { return divotStart(); }
JSTextPosition subexpressionEnd() { return divotEnd() - static_cast<int>(m_subexpressionEndOffset); }
protected:
uint16_t m_subexpressionDivotOffset;
uint16_t m_subexpressionEndOffset;
uint16_t m_subexpressionLineOffset;
uint16_t m_subexpressionLineStartOffset;
};
class ThrowablePrefixedSubExpressionData : public ThrowableExpressionData {
public:
ThrowablePrefixedSubExpressionData()
: m_subexpressionDivotOffset(0)
, m_subexpressionStartOffset(0)
, m_subexpressionLineOffset(0)
, m_subexpressionLineStartOffset(0)
{
}
ThrowablePrefixedSubExpressionData(const JSTextPosition& divot, const JSTextPosition& start, const JSTextPosition& end)
: ThrowableExpressionData(divot, start, end)
, m_subexpressionDivotOffset(0)
, m_subexpressionStartOffset(0)
, m_subexpressionLineOffset(0)
, m_subexpressionLineStartOffset(0)
{
}
void setSubexpressionInfo(const JSTextPosition& subexpressionDivot, int subexpressionOffset)
{
ASSERT(subexpressionDivot.offset >= divot().offset);
// Overflow means we can't do this safely, so just point at the primary divot,
// divotLine, or divotLineStart.
if ((subexpressionDivot.offset - divot()) & ~0xFFFF)
return;
if ((subexpressionDivot.line - divot().line) & ~0xFFFF)
return;
if ((subexpressionDivot.lineStartOffset - divot().lineStartOffset) & ~0xFFFF)
return;
if ((subexpressionOffset - divotStart()) & ~0xFFFF)
return;
m_subexpressionDivotOffset = subexpressionDivot.offset - divot();
m_subexpressionStartOffset = subexpressionOffset - divotStart();
m_subexpressionLineOffset = subexpressionDivot.line - divot().line;
m_subexpressionLineStartOffset = subexpressionDivot.lineStartOffset - divot().lineStartOffset;
}
JSTextPosition subexpressionDivot()
{
int newLine = divot().line + m_subexpressionLineOffset;
int newOffset = divot().offset + m_subexpressionDivotOffset;
int newLineStartOffset = divot().lineStartOffset + m_subexpressionLineStartOffset;
return JSTextPosition(newLine, newOffset, newLineStartOffset);
}
JSTextPosition subexpressionStart() { return divotStart() + static_cast<int>(m_subexpressionStartOffset); }
JSTextPosition subexpressionEnd() { return divotEnd(); }
protected:
uint16_t m_subexpressionDivotOffset;
uint16_t m_subexpressionStartOffset;
uint16_t m_subexpressionLineOffset;
uint16_t m_subexpressionLineStartOffset;
};
class TemplateExpressionListNode final : public ParserArenaFreeable {
public:
TemplateExpressionListNode(ExpressionNode*);
TemplateExpressionListNode(TemplateExpressionListNode*, ExpressionNode*);
ExpressionNode* value() { return m_node; }
TemplateExpressionListNode* next() { return m_next; }
private:
TemplateExpressionListNode* m_next { nullptr };
ExpressionNode* m_node { nullptr };
};
class TemplateStringNode final : public ExpressionNode {
public:
TemplateStringNode(const JSTokenLocation&, const Identifier* cooked, const Identifier* raw);
const Identifier* cooked() { return m_cooked; }
const Identifier* raw() { return m_raw; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
const Identifier* m_cooked;
const Identifier* m_raw;
};
class TemplateStringListNode final : public ParserArenaFreeable {
public:
TemplateStringListNode(TemplateStringNode*);
TemplateStringListNode(TemplateStringListNode*, TemplateStringNode*);
TemplateStringNode* value() { return m_node; }
TemplateStringListNode* next() { return m_next; }
private:
TemplateStringListNode* m_next { nullptr };
TemplateStringNode* m_node { nullptr };
};
class TemplateLiteralNode final : public ExpressionNode {
public:
TemplateLiteralNode(const JSTokenLocation&, TemplateStringListNode*);
TemplateLiteralNode(const JSTokenLocation&, TemplateStringListNode*, TemplateExpressionListNode*);
TemplateStringListNode* templateStrings() const { return m_templateStrings; }
TemplateExpressionListNode* templateExpressions() const { return m_templateExpressions; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
TemplateStringListNode* m_templateStrings;
TemplateExpressionListNode* m_templateExpressions;
};
class TaggedTemplateNode final : public ExpressionNode, public ThrowableExpressionData {
public:
TaggedTemplateNode(const JSTokenLocation&, ExpressionNode*, TemplateLiteralNode*);
TemplateLiteralNode* templateLiteral() const { return m_templateLiteral; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
ExpressionNode* m_tag;
TemplateLiteralNode* m_templateLiteral;
};
class RegExpNode final : public ExpressionNode, public ThrowableExpressionData {
public:
RegExpNode(const JSTokenLocation&, const Identifier& pattern, const Identifier& flags);
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
const Identifier& m_pattern;
const Identifier& m_flags;
};
class ThisNode final : public ExpressionNode {
public:
ThisNode(const JSTokenLocation&);
private:
bool isThisNode() const final { return true; }
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
};
class SuperNode final : public ExpressionNode {
public:
SuperNode(const JSTokenLocation&);
private:
bool isSuperNode() const final { return true; }
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
};
class ImportNode final : public ExpressionNode, public ThrowableExpressionData {
public:
ImportNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*);
private:
bool isImportNode() const final { return true; }
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
ExpressionNode* m_expr;
ExpressionNode* m_option;
};
class MetaPropertyNode : public ExpressionNode {
public:
MetaPropertyNode(const JSTokenLocation&);
private:
bool isMetaProperty() const final { return true; }
};
class NewTargetNode final : public MetaPropertyNode {
public:
NewTargetNode(const JSTokenLocation&);
private:
bool isNewTarget() const final { return true; }
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
};
class ImportMetaNode final : public MetaPropertyNode {
public:
ImportMetaNode(const JSTokenLocation&, ExpressionNode*);
private:
bool isImportMeta() const final { return true; }
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
ExpressionNode* m_expr;
};
class ResolveNode final : public ExpressionNode {
public:
ResolveNode(const JSTokenLocation&, const Identifier&, const JSTextPosition& start);
const Identifier& identifier() const { return m_ident; }
bool isArguments(VM& vm) const final { return m_ident == vm.propertyNames->arguments; }
bool getFromScopeCanThrow(BytecodeGenerator&) const;
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
bool isPure(BytecodeGenerator&) const final;
bool isLocation() const final { return true; }
bool isResolveNode() const final { return true; }
const Identifier& m_ident;
JSTextPosition m_start;
};
// Dummy expression to hold the LHS of `#x in obj`.
class PrivateIdentifierNode final : public ExpressionNode {
public:
PrivateIdentifierNode(const JSTokenLocation&, const Identifier&);
const Identifier& value() const { return m_ident; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final { RELEASE_ASSERT_NOT_REACHED(); }
bool isPrivateIdentifier() const final { return true; }
const Identifier& m_ident;
};
class ElementNode final : public ParserArenaFreeable {
public:
ElementNode(int elision, ExpressionNode*);
ElementNode(ElementNode*, int elision, ExpressionNode*);
int elision() const { return m_elision; }
ExpressionNode* value() { return m_node; }
ElementNode* next() { return m_next; }
private:
ElementNode* m_next { nullptr };
ExpressionNode* m_node;
int m_elision;
};
class ArrayNode final : public ExpressionNode {
public:
ArrayNode(const JSTokenLocation&, int elision);
ArrayNode(const JSTokenLocation&, ElementNode*);
ArrayNode(const JSTokenLocation&, int elision, ElementNode*);
bool isArrayLiteral() const final { return true; }
ArgumentListNode* toArgumentList(ParserArena&, int, int) const;
ElementNode* elements() const { return m_element; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
bool isSimpleArray() const final;
ElementNode* m_element;
int m_elision;
};
enum class ClassElementTag : uint8_t { No, Instance, Static, LastTag };
class PropertyNode final : public ParserArenaFreeable {
public:
friend class ObjectLiteralNode;
enum Type : uint16_t { Constant = 1, Getter = 2, Setter = 4, Computed = 8, Shorthand = 16, Spread = 32, PrivateField = 64, PrivateMethod = 128, PrivateSetter = 256, PrivateGetter = 512, Block = 1024 };
PropertyNode(const Identifier&, Type, SuperBinding, ClassElementTag);
PropertyNode(const Identifier&, ExpressionNode*, Type, SuperBinding, ClassElementTag);
PropertyNode(ExpressionNode*, Type, SuperBinding, ClassElementTag);
PropertyNode(ExpressionNode* propertyName, ExpressionNode*, Type, SuperBinding, ClassElementTag);
PropertyNode(const Identifier&, ExpressionNode* propertyName, ExpressionNode*, Type, SuperBinding, ClassElementTag);
ExpressionNode* expressionName() const { return m_expression; }
const Identifier* name() const { return m_name; }
Type type() const { return static_cast<Type>(m_type); }
bool needsSuperBinding() const { return m_needsSuperBinding; }
bool isClassProperty() const { return static_cast<ClassElementTag>(m_classElementTag) != ClassElementTag::No; }
bool isStaticClassProperty() const { return static_cast<ClassElementTag>(m_classElementTag) == ClassElementTag::Static; }
bool isInstanceClassProperty() const { return static_cast<ClassElementTag>(m_classElementTag) == ClassElementTag::Instance; }
bool isClassField() const { return isClassProperty() && !needsSuperBinding(); }
bool isInstanceClassField() const { return isInstanceClassProperty() && !needsSuperBinding(); }
bool isStaticClassField() const { return isStaticClassProperty() && !needsSuperBinding(); }
bool isStaticClassBlock() const { return m_type & Block; }
bool isStaticClassElement() const { return isStaticClassBlock() || isStaticClassField(); }
bool isOverriddenByDuplicate() const { return m_isOverriddenByDuplicate; }
bool isPrivate() const { return m_type & (PrivateField | PrivateMethod | PrivateGetter | PrivateSetter); }
bool hasComputedName() const { return m_expression; }
bool isComputedClassField() const { return isClassField() && hasComputedName(); }
void setIsOverriddenByDuplicate() { m_isOverriddenByDuplicate = true; }
ALWAYS_INLINE static bool isUnderscoreProtoSetter(VM& vm, const PropertyNode& node)
{
return isUnderscoreProtoSetter(vm, node.name(), node.type(), node.needsSuperBinding(), node.isClassProperty());
}
ALWAYS_INLINE static bool isUnderscoreProtoSetter(VM& vm, const Identifier* name, Type type, bool needsSuperBinding, bool isClassProperty)
{
return name && *name == vm.propertyNames->underscoreProto && type == Type::Constant && !needsSuperBinding && !isClassProperty;
}
private:
friend class PropertyListNode;
const Identifier* m_name { nullptr };
ExpressionNode* m_expression { nullptr };
ExpressionNode* m_assign { nullptr };
unsigned m_type : 11;
unsigned m_needsSuperBinding : 1;
static_assert(1 << 2 > static_cast<unsigned>(ClassElementTag::LastTag), "ClassElementTag shouldn't use more than two bits");
unsigned m_classElementTag : 2;
unsigned m_isOverriddenByDuplicate : 1 { false };
};
class PropertyListNode final : public ExpressionNode {
public:
friend class ObjectLiteralNode;
PropertyListNode(const JSTokenLocation&, PropertyNode*);
PropertyListNode(const JSTokenLocation&, PropertyNode*, PropertyListNode*);
bool hasStaticallyNamedProperty(const Identifier& propName);
bool isComputedClassField() const
{
return m_node->isComputedClassField();
}
bool isInstanceClassField() const
{
return m_node->isInstanceClassField();
}
bool hasInstanceFields() const;
bool isStaticClassField() const
{
return m_node->isStaticClassField();
}
bool isStaticClassBlock() const
{
return m_node->isStaticClassBlock();
}
bool isStaticClassElement() const
{
return m_node->isStaticClassElement();
}
void setHasPrivateAccessors(bool hasPrivateAccessors)
{
m_hasPrivateAccessors = hasPrivateAccessors;
}
bool hasPrivateAccessors() const
{
return m_hasPrivateAccessors;
}
static bool shouldCreateLexicalScopeForClass(PropertyListNode*);
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID*, RegisterID*, Vector<UnlinkedFunctionExecutable::ClassElementDefinition>*, Vector<UnlinkedFunctionExecutable::ClassElementDefinition>*);
void emitDeclarePrivateFieldNames(BytecodeGenerator&, RegisterID* scope);
private:
RegisterID* emitBytecode(BytecodeGenerator& generator, RegisterID* dst = nullptr) final
{
return emitBytecode(generator, dst, nullptr, nullptr, nullptr);
}
void emitPutConstantProperty(BytecodeGenerator&, RegisterID*, PropertyNode&);
void emitSaveComputedFieldName(BytecodeGenerator&, PropertyNode&);
PropertyNode* m_node;
PropertyListNode* m_next { nullptr };
bool m_hasPrivateAccessors { false };
};
class ObjectLiteralNode final : public ExpressionNode {
public:
ObjectLiteralNode(const JSTokenLocation&);
ObjectLiteralNode(const JSTokenLocation&, PropertyListNode*);
bool isObjectLiteral() const final { return true; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
PropertyListNode* m_list;
};
class BracketAccessorNode final : public ExpressionNode, public ThrowableExpressionData {
public:
BracketAccessorNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments);
ExpressionNode* base() const { return m_base; }
ExpressionNode* subscript() const { return m_subscript; }
bool subscriptHasAssignments() const { return m_subscriptHasAssignments; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
bool isLocation() const final { return true; }
bool isBracketAccessorNode() const final { return true; }
ExpressionNode* m_base;
ExpressionNode* m_subscript;
bool m_subscriptHasAssignments;
};
enum class DotType { Name, PrivateMember };
class BaseDotNode : public ExpressionNode {
public:
BaseDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, DotType);
ExpressionNode* base() const { return m_base; }
const Identifier& identifier() const { return m_ident; }
DotType type() const { return m_type; }
bool isPrivateMember() const { return m_type == DotType::PrivateMember; }
bool isArgumentsLengthAccess(VM& vm) const final { return m_base->isArguments(vm) && identifier() == vm.propertyNames->length; }
RegisterID* emitGetPropertyValue(BytecodeGenerator&, RegisterID* dst, RegisterID* base, RefPtr<RegisterID>& thisValue);
RegisterID* emitGetPropertyValue(BytecodeGenerator&, RegisterID* dst, RegisterID* base);
RegisterID* emitPutProperty(BytecodeGenerator&, RegisterID* base, RegisterID* value, RefPtr<RegisterID>& thisValue);
RegisterID* emitPutProperty(BytecodeGenerator&, RegisterID* base, RegisterID* value);
protected:
ExpressionNode* m_base;
const Identifier& m_ident;
DotType m_type;
};
class DotAccessorNode final : public BaseDotNode, public ThrowableExpressionData {
public:
DotAccessorNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, DotType);
ExpressionNode* base() const { return m_base; }
const Identifier& identifier() const { return m_ident; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
bool isLocation() const final { return true; }
bool isPrivateLocation() const override { return m_type == DotType::PrivateMember; }
bool isDotAccessorNode() const final { return true; }
};
class SpreadExpressionNode final : public ExpressionNode, public ThrowableExpressionData {
public:
SpreadExpressionNode(const JSTokenLocation&, ExpressionNode*);
ExpressionNode* expression() const { return m_expression; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
bool isSpreadExpression() const final { return true; }
ExpressionNode* m_expression;
};
class ObjectSpreadExpressionNode final : public ExpressionNode, public ThrowableExpressionData {
public:
ObjectSpreadExpressionNode(const JSTokenLocation&, ExpressionNode*);
ExpressionNode* expression() const { return m_expression; }
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
ExpressionNode* m_expression;
};
class ArgumentListNode final : public ExpressionNode {
public:
ArgumentListNode(const JSTokenLocation&, ExpressionNode*);
ArgumentListNode(const JSTokenLocation&, ArgumentListNode*, ExpressionNode*);
ArgumentListNode* m_next { nullptr };
ExpressionNode* m_expr;
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
};
class ArgumentsNode final : public ParserArenaFreeable {
public:
ArgumentsNode();
ArgumentsNode(ArgumentListNode*, bool hasAssignments);
bool hasAssignments() const { return m_hasAssignments; }
ArgumentListNode* m_listNode;
private:
bool m_hasAssignments { false };
};
class NewExprNode final : public ExpressionNode, public ThrowableExpressionData {
public:
NewExprNode(const JSTokenLocation&, ExpressionNode*);
NewExprNode(const JSTokenLocation&, ExpressionNode*, ArgumentsNode*);
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
ExpressionNode* m_expr;
ArgumentsNode* m_args;
};
class EvalFunctionCallNode final : public ExpressionNode, public ThrowableExpressionData {
public:
EvalFunctionCallNode(const JSTokenLocation&, ArgumentsNode*, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd);
private:
RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = nullptr) final;
bool isFunctionCall() const final { return true; }
ArgumentsNode* m_args;
};