Remove unused m_writtenVariables from the parser and related bits
[WebKit-https.git] / Source / JavaScriptCore / parser / ParserModes.h
1 /*
2  * Copyright (C) 2012-2013, 2015-2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26
27 #ifndef ParserModes_h
28 #define ParserModes_h
29
30 #include "Identifier.h"
31
32 namespace JSC {
33
34 enum class JSParserStrictMode { NotStrict, Strict };
35 enum class JSParserBuiltinMode { NotBuiltin, Builtin };
36 enum class JSParserCodeType { Program, Function, Module };
37
38 enum class ConstructorKind { None, Base, Derived };
39 enum class SuperBinding { Needed, NotNeeded };
40 enum class ThisTDZMode { AlwaysCheck, CheckIfNeeded };
41
42 enum ProfilerMode { ProfilerOff, ProfilerOn };
43 enum DebuggerMode { DebuggerOff, DebuggerOn };
44
45 enum class FunctionMode { FunctionExpression, FunctionDeclaration, MethodDefinition };
46
47 enum class SourceParseMode : uint8_t {
48     NormalFunctionMode,
49     GeneratorBodyMode,
50     GeneratorWrapperFunctionMode,
51     GetterMode,
52     SetterMode,
53     MethodMode,
54     ArrowFunctionMode,
55     ProgramMode,
56     ModuleAnalyzeMode,
57     ModuleEvaluateMode
58 };
59
60 inline bool isFunctionParseMode(SourceParseMode parseMode)
61 {
62     switch (parseMode) {
63     case SourceParseMode::NormalFunctionMode:
64     case SourceParseMode::GeneratorBodyMode:
65     case SourceParseMode::GeneratorWrapperFunctionMode:
66     case SourceParseMode::GetterMode:
67     case SourceParseMode::SetterMode:
68     case SourceParseMode::MethodMode:
69     case SourceParseMode::ArrowFunctionMode:
70         return true;
71
72     case SourceParseMode::ProgramMode:
73     case SourceParseMode::ModuleAnalyzeMode:
74     case SourceParseMode::ModuleEvaluateMode:
75         return false;
76     }
77     RELEASE_ASSERT_NOT_REACHED();
78     return false;
79 }
80
81 inline bool isModuleParseMode(SourceParseMode parseMode)
82 {
83     switch (parseMode) {
84     case SourceParseMode::ModuleAnalyzeMode:
85     case SourceParseMode::ModuleEvaluateMode:
86         return true;
87
88     case SourceParseMode::NormalFunctionMode:
89     case SourceParseMode::GeneratorBodyMode:
90     case SourceParseMode::GeneratorWrapperFunctionMode:
91     case SourceParseMode::GetterMode:
92     case SourceParseMode::SetterMode:
93     case SourceParseMode::MethodMode:
94     case SourceParseMode::ArrowFunctionMode:
95     case SourceParseMode::ProgramMode:
96         return false;
97     }
98     RELEASE_ASSERT_NOT_REACHED();
99     return false;
100 }
101
102 inline bool isProgramParseMode(SourceParseMode parseMode)
103 {
104     switch (parseMode) {
105     case SourceParseMode::ProgramMode:
106         return true;
107
108     case SourceParseMode::NormalFunctionMode:
109     case SourceParseMode::GeneratorBodyMode:
110     case SourceParseMode::GeneratorWrapperFunctionMode:
111     case SourceParseMode::GetterMode:
112     case SourceParseMode::SetterMode:
113     case SourceParseMode::MethodMode:
114     case SourceParseMode::ArrowFunctionMode:
115     case SourceParseMode::ModuleAnalyzeMode:
116     case SourceParseMode::ModuleEvaluateMode:
117         return false;
118     }
119     RELEASE_ASSERT_NOT_REACHED();
120     return false;
121 }
122
123 inline bool functionNameIsInScope(const Identifier& name, FunctionMode functionMode)
124 {
125     if (name.isNull())
126         return false;
127
128     if (functionMode != FunctionMode::FunctionExpression)
129         return false;
130
131     return true;
132 }
133
134 inline bool functionNameScopeIsDynamic(bool usesEval, bool isStrictMode)
135 {
136     // If non-strict eval is in play, a function gets a separate object in the scope chain for its name.
137     // This enables eval to declare and then delete a name that shadows the function's name.
138
139     if (!usesEval)
140         return false;
141
142     if (isStrictMode)
143         return false;
144
145     return true;
146 }
147
148 typedef uint16_t CodeFeatures;
149
150 const CodeFeatures NoFeatures =                       0;
151 const CodeFeatures EvalFeature =                 1 << 0;
152 const CodeFeatures ArgumentsFeature =            1 << 1;
153 const CodeFeatures WithFeature =                 1 << 2;
154 const CodeFeatures ThisFeature =                 1 << 3;
155 const CodeFeatures StrictModeFeature =           1 << 4;
156 const CodeFeatures ShadowsArgumentsFeature =     1 << 5;
157 const CodeFeatures ArrowFunctionFeature =        1 << 6;
158 const CodeFeatures ArrowFunctionContextFeature = 1 << 7;
159 const CodeFeatures SuperCallFeature =            1 << 8;
160 const CodeFeatures SuperPropertyFeature =        1 << 9;
161 const CodeFeatures NewTargetFeature =            1 << 10;
162
163 const CodeFeatures AllFeatures = EvalFeature | ArgumentsFeature | WithFeature | ThisFeature | StrictModeFeature | ShadowsArgumentsFeature | ArrowFunctionFeature | ArrowFunctionContextFeature |
164     SuperCallFeature | SuperPropertyFeature | NewTargetFeature;
165
166 typedef uint8_t InnerArrowFunctionCodeFeatures;
167     
168 const InnerArrowFunctionCodeFeatures NoInnerArrowFunctionFeatures =                0;
169 const InnerArrowFunctionCodeFeatures EvalInnerArrowFunctionFeature =          1 << 0;
170 const InnerArrowFunctionCodeFeatures ArgumentsInnerArrowFunctionFeature =     1 << 1;
171 const InnerArrowFunctionCodeFeatures ThisInnerArrowFunctionFeature =          1 << 2;
172 const InnerArrowFunctionCodeFeatures SuperCallInnerArrowFunctionFeature =     1 << 3;
173 const InnerArrowFunctionCodeFeatures SuperPropertyInnerArrowFunctionFeature = 1 << 4;
174 const InnerArrowFunctionCodeFeatures NewTargetInnerArrowFunctionFeature =     1 << 5;
175     
176 const InnerArrowFunctionCodeFeatures AllInnerArrowFunctionCodeFeatures = EvalInnerArrowFunctionFeature | ArgumentsInnerArrowFunctionFeature | ThisInnerArrowFunctionFeature | SuperCallInnerArrowFunctionFeature | SuperPropertyInnerArrowFunctionFeature | NewTargetInnerArrowFunctionFeature;
177 } // namespace JSC
178
179 #endif // ParserModes_h