blob: f0c3a229b32f35976c6bcb72e096efbbe649db57 [file] [log] [blame]
oliver@apple.comf0c01b82012-11-07 00:13:54 +00001/*
mark.lam@apple.com43137872016-03-17 14:58:57 +00002 * Copyright (C) 2012-2013, 2015-2016 Apple Inc. All rights reserved.
oliver@apple.comf0c01b82012-11-07 00:13:54 +00003 *
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
ggaren@apple.com7d92d072014-02-03 20:39:38 +000030#include "Identifier.h"
31
oliver@apple.comf0c01b82012-11-07 00:13:54 +000032namespace JSC {
33
ggaren@apple.com8b873e52015-03-17 21:15:03 +000034enum class JSParserStrictMode { NotStrict, Strict };
35enum class JSParserBuiltinMode { NotBuiltin, Builtin };
utatane.tea@gmail.com9f9c9752015-08-04 21:26:49 +000036enum class JSParserCodeType { Program, Function, Module };
commit-queue@webkit.org5fb80322014-04-15 17:46:42 +000037
rniwa@webkit.orge6f83492015-03-13 23:01:51 +000038enum class ConstructorKind { None, Base, Derived };
rniwa@webkit.org059ef9b2015-03-09 23:47:06 +000039enum class SuperBinding { Needed, NotNeeded };
rniwa@webkit.orge8caec42015-03-31 19:42:56 +000040enum class ThisTDZMode { AlwaysCheck, CheckIfNeeded };
rniwa@webkit.org059ef9b2015-03-09 23:47:06 +000041
oliver@apple.comf0c01b82012-11-07 00:13:54 +000042enum ProfilerMode { ProfilerOff, ProfilerOn };
43enum DebuggerMode { DebuggerOff, DebuggerOn };
44
mark.lam@apple.com89ae9982016-03-17 20:38:56 +000045enum class FunctionMode { FunctionExpression, FunctionDeclaration, MethodDefinition };
ggaren@apple.com7d92d072014-02-03 20:39:38 +000046
sbarati@apple.com5c5f6922016-01-30 02:05:17 +000047enum class SourceParseMode : uint8_t {
saambarati1@gmail.comc497d152015-07-17 18:48:30 +000048 NormalFunctionMode,
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000049 GeneratorBodyMode,
50 GeneratorWrapperFunctionMode,
saambarati1@gmail.comc497d152015-07-17 18:48:30 +000051 GetterMode,
52 SetterMode,
53 MethodMode,
utatane.tea@gmail.com505049b2015-08-13 23:55:35 +000054 ArrowFunctionMode,
55 ProgramMode,
56 ModuleAnalyzeMode,
57 ModuleEvaluateMode
saambarati1@gmail.comc497d152015-07-17 18:48:30 +000058};
59
utatane.tea@gmail.com505049b2015-08-13 23:55:35 +000060inline bool isFunctionParseMode(SourceParseMode parseMode)
61{
62 switch (parseMode) {
63 case SourceParseMode::NormalFunctionMode:
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000064 case SourceParseMode::GeneratorBodyMode:
65 case SourceParseMode::GeneratorWrapperFunctionMode:
utatane.tea@gmail.com505049b2015-08-13 23:55:35 +000066 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
81inline bool isModuleParseMode(SourceParseMode parseMode)
82{
83 switch (parseMode) {
84 case SourceParseMode::ModuleAnalyzeMode:
85 case SourceParseMode::ModuleEvaluateMode:
86 return true;
87
88 case SourceParseMode::NormalFunctionMode:
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000089 case SourceParseMode::GeneratorBodyMode:
90 case SourceParseMode::GeneratorWrapperFunctionMode:
utatane.tea@gmail.com505049b2015-08-13 23:55:35 +000091 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
102inline bool isProgramParseMode(SourceParseMode parseMode)
103{
104 switch (parseMode) {
105 case SourceParseMode::ProgramMode:
106 return true;
107
108 case SourceParseMode::NormalFunctionMode:
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +0000109 case SourceParseMode::GeneratorBodyMode:
110 case SourceParseMode::GeneratorWrapperFunctionMode:
utatane.tea@gmail.com505049b2015-08-13 23:55:35 +0000111 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
ggaren@apple.com7d92d072014-02-03 20:39:38 +0000123inline bool functionNameIsInScope(const Identifier& name, FunctionMode functionMode)
124{
125 if (name.isNull())
126 return false;
127
mark.lam@apple.com89ae9982016-03-17 20:38:56 +0000128 if (functionMode != FunctionMode::FunctionExpression)
ggaren@apple.com7d92d072014-02-03 20:39:38 +0000129 return false;
130
131 return true;
132}
133
134inline 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}
oliver@apple.comf0c01b82012-11-07 00:13:54 +0000147
sbarati@apple.com5c5f6922016-01-30 02:05:17 +0000148typedef uint16_t CodeFeatures;
fpizlo@apple.combb8aa752013-02-18 06:28:54 +0000149
commit-queue@webkit.orgb2610c02015-12-08 20:24:04 +0000150const CodeFeatures NoFeatures = 0;
151const CodeFeatures EvalFeature = 1 << 0;
152const CodeFeatures ArgumentsFeature = 1 << 1;
153const CodeFeatures WithFeature = 1 << 2;
154const CodeFeatures ThisFeature = 1 << 3;
155const CodeFeatures StrictModeFeature = 1 << 4;
156const CodeFeatures ShadowsArgumentsFeature = 1 << 5;
sbarati@apple.comb7c87ec2016-04-20 08:44:43 +0000157const CodeFeatures ArrowFunctionFeature = 1 << 6;
158const CodeFeatures ArrowFunctionContextFeature = 1 << 7;
159const CodeFeatures SuperCallFeature = 1 << 8;
160const CodeFeatures SuperPropertyFeature = 1 << 9;
161const CodeFeatures NewTargetFeature = 1 << 10;
fpizlo@apple.combb8aa752013-02-18 06:28:54 +0000162
sbarati@apple.comb7c87ec2016-04-20 08:44:43 +0000163const CodeFeatures AllFeatures = EvalFeature | ArgumentsFeature | WithFeature | ThisFeature | StrictModeFeature | ShadowsArgumentsFeature | ArrowFunctionFeature | ArrowFunctionContextFeature |
gskachkov@gmail.comf7ba3e42016-03-10 08:19:42 +0000164 SuperCallFeature | SuperPropertyFeature | NewTargetFeature;
fpizlo@apple.combb8aa752013-02-18 06:28:54 +0000165
gskachkov@gmail.coma198dd12016-02-28 19:14:26 +0000166typedef uint8_t InnerArrowFunctionCodeFeatures;
167
168const InnerArrowFunctionCodeFeatures NoInnerArrowFunctionFeatures = 0;
169const InnerArrowFunctionCodeFeatures EvalInnerArrowFunctionFeature = 1 << 0;
170const InnerArrowFunctionCodeFeatures ArgumentsInnerArrowFunctionFeature = 1 << 1;
171const InnerArrowFunctionCodeFeatures ThisInnerArrowFunctionFeature = 1 << 2;
172const InnerArrowFunctionCodeFeatures SuperCallInnerArrowFunctionFeature = 1 << 3;
173const InnerArrowFunctionCodeFeatures SuperPropertyInnerArrowFunctionFeature = 1 << 4;
174const InnerArrowFunctionCodeFeatures NewTargetInnerArrowFunctionFeature = 1 << 5;
175
176const InnerArrowFunctionCodeFeatures AllInnerArrowFunctionCodeFeatures = EvalInnerArrowFunctionFeature | ArgumentsInnerArrowFunctionFeature | ThisInnerArrowFunctionFeature | SuperCallInnerArrowFunctionFeature | SuperPropertyInnerArrowFunctionFeature | NewTargetInnerArrowFunctionFeature;
fpizlo@apple.combb8aa752013-02-18 06:28:54 +0000177} // namespace JSC
178
179#endif // ParserModes_h