oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 4313787 | 2016-03-17 14:58:57 +0000 | [diff] [blame] | 2 | * Copyright (C) 2012-2013, 2015-2016 Apple Inc. All rights reserved. |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 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 | |
ggaren@apple.com | 7d92d07 | 2014-02-03 20:39:38 +0000 | [diff] [blame] | 30 | #include "Identifier.h" |
| 31 | |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 32 | namespace JSC { |
| 33 | |
ggaren@apple.com | 8b873e5 | 2015-03-17 21:15:03 +0000 | [diff] [blame] | 34 | enum class JSParserStrictMode { NotStrict, Strict }; |
| 35 | enum class JSParserBuiltinMode { NotBuiltin, Builtin }; |
utatane.tea@gmail.com | 9f9c975 | 2015-08-04 21:26:49 +0000 | [diff] [blame] | 36 | enum class JSParserCodeType { Program, Function, Module }; |
commit-queue@webkit.org | 5fb8032 | 2014-04-15 17:46:42 +0000 | [diff] [blame] | 37 | |
rniwa@webkit.org | e6f8349 | 2015-03-13 23:01:51 +0000 | [diff] [blame] | 38 | enum class ConstructorKind { None, Base, Derived }; |
rniwa@webkit.org | 059ef9b | 2015-03-09 23:47:06 +0000 | [diff] [blame] | 39 | enum class SuperBinding { Needed, NotNeeded }; |
rniwa@webkit.org | e8caec4 | 2015-03-31 19:42:56 +0000 | [diff] [blame] | 40 | enum class ThisTDZMode { AlwaysCheck, CheckIfNeeded }; |
rniwa@webkit.org | 059ef9b | 2015-03-09 23:47:06 +0000 | [diff] [blame] | 41 | |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 42 | enum ProfilerMode { ProfilerOff, ProfilerOn }; |
| 43 | enum DebuggerMode { DebuggerOff, DebuggerOn }; |
| 44 | |
mark.lam@apple.com | 89ae998 | 2016-03-17 20:38:56 +0000 | [diff] [blame] | 45 | enum class FunctionMode { FunctionExpression, FunctionDeclaration, MethodDefinition }; |
ggaren@apple.com | 7d92d07 | 2014-02-03 20:39:38 +0000 | [diff] [blame] | 46 | |
sbarati@apple.com | 5c5f692 | 2016-01-30 02:05:17 +0000 | [diff] [blame] | 47 | enum class SourceParseMode : uint8_t { |
saambarati1@gmail.com | c497d15 | 2015-07-17 18:48:30 +0000 | [diff] [blame] | 48 | NormalFunctionMode, |
utatane.tea@gmail.com | fdd9bf4 | 2015-12-02 03:16:28 +0000 | [diff] [blame] | 49 | GeneratorBodyMode, |
| 50 | GeneratorWrapperFunctionMode, |
saambarati1@gmail.com | c497d15 | 2015-07-17 18:48:30 +0000 | [diff] [blame] | 51 | GetterMode, |
| 52 | SetterMode, |
| 53 | MethodMode, |
utatane.tea@gmail.com | 505049b | 2015-08-13 23:55:35 +0000 | [diff] [blame] | 54 | ArrowFunctionMode, |
| 55 | ProgramMode, |
| 56 | ModuleAnalyzeMode, |
| 57 | ModuleEvaluateMode |
saambarati1@gmail.com | c497d15 | 2015-07-17 18:48:30 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
utatane.tea@gmail.com | 505049b | 2015-08-13 23:55:35 +0000 | [diff] [blame] | 60 | inline bool isFunctionParseMode(SourceParseMode parseMode) |
| 61 | { |
| 62 | switch (parseMode) { |
| 63 | case SourceParseMode::NormalFunctionMode: |
utatane.tea@gmail.com | fdd9bf4 | 2015-12-02 03:16:28 +0000 | [diff] [blame] | 64 | case SourceParseMode::GeneratorBodyMode: |
| 65 | case SourceParseMode::GeneratorWrapperFunctionMode: |
utatane.tea@gmail.com | 505049b | 2015-08-13 23:55:35 +0000 | [diff] [blame] | 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: |
utatane.tea@gmail.com | fdd9bf4 | 2015-12-02 03:16:28 +0000 | [diff] [blame] | 89 | case SourceParseMode::GeneratorBodyMode: |
| 90 | case SourceParseMode::GeneratorWrapperFunctionMode: |
utatane.tea@gmail.com | 505049b | 2015-08-13 23:55:35 +0000 | [diff] [blame] | 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: |
utatane.tea@gmail.com | fdd9bf4 | 2015-12-02 03:16:28 +0000 | [diff] [blame] | 109 | case SourceParseMode::GeneratorBodyMode: |
| 110 | case SourceParseMode::GeneratorWrapperFunctionMode: |
utatane.tea@gmail.com | 505049b | 2015-08-13 23:55:35 +0000 | [diff] [blame] | 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 | |
ggaren@apple.com | 7d92d07 | 2014-02-03 20:39:38 +0000 | [diff] [blame] | 123 | inline bool functionNameIsInScope(const Identifier& name, FunctionMode functionMode) |
| 124 | { |
| 125 | if (name.isNull()) |
| 126 | return false; |
| 127 | |
mark.lam@apple.com | 89ae998 | 2016-03-17 20:38:56 +0000 | [diff] [blame] | 128 | if (functionMode != FunctionMode::FunctionExpression) |
ggaren@apple.com | 7d92d07 | 2014-02-03 20:39:38 +0000 | [diff] [blame] | 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 | } |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 147 | |
sbarati@apple.com | 5c5f692 | 2016-01-30 02:05:17 +0000 | [diff] [blame] | 148 | typedef uint16_t CodeFeatures; |
fpizlo@apple.com | bb8aa75 | 2013-02-18 06:28:54 +0000 | [diff] [blame] | 149 | |
commit-queue@webkit.org | b2610c0 | 2015-12-08 20:24:04 +0000 | [diff] [blame] | 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; |
sbarati@apple.com | b7c87ec | 2016-04-20 08:44:43 +0000 | [diff] [blame] | 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; |
fpizlo@apple.com | bb8aa75 | 2013-02-18 06:28:54 +0000 | [diff] [blame] | 162 | |
sbarati@apple.com | b7c87ec | 2016-04-20 08:44:43 +0000 | [diff] [blame] | 163 | const CodeFeatures AllFeatures = EvalFeature | ArgumentsFeature | WithFeature | ThisFeature | StrictModeFeature | ShadowsArgumentsFeature | ArrowFunctionFeature | ArrowFunctionContextFeature | |
gskachkov@gmail.com | f7ba3e4 | 2016-03-10 08:19:42 +0000 | [diff] [blame] | 164 | SuperCallFeature | SuperPropertyFeature | NewTargetFeature; |
fpizlo@apple.com | bb8aa75 | 2013-02-18 06:28:54 +0000 | [diff] [blame] | 165 | |
gskachkov@gmail.com | a198dd1 | 2016-02-28 19:14:26 +0000 | [diff] [blame] | 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; |
fpizlo@apple.com | bb8aa75 | 2013-02-18 06:28:54 +0000 | [diff] [blame] | 177 | } // namespace JSC |
| 178 | |
| 179 | #endif // ParserModes_h |