| File: | root/firefox-clang/js/src/frontend/Parser.cpp |
| Warning: | line 4221, column 20 The left operand of '==' is a garbage value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public | ||||
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||||
| 4 | |||||
| 5 | /* | ||||
| 6 | * JS parser. | ||||
| 7 | * | ||||
| 8 | * This is a recursive-descent parser for the JavaScript language specified by | ||||
| 9 | * "The ECMAScript Language Specification" (Standard ECMA-262). It uses | ||||
| 10 | * lexical and semantic feedback to disambiguate non-LL(1) structures. It | ||||
| 11 | * generates trees of nodes induced by the recursive parsing (not precise | ||||
| 12 | * syntax trees, see Parser.h). After tree construction, it rewrites trees to | ||||
| 13 | * fold constants and evaluate compile-time expressions. | ||||
| 14 | * | ||||
| 15 | * This parser attempts no error recovery. | ||||
| 16 | */ | ||||
| 17 | |||||
| 18 | #include "frontend/Parser.h" | ||||
| 19 | |||||
| 20 | #include "mozilla/ArrayUtils.h" | ||||
| 21 | #include "mozilla/Assertions.h" | ||||
| 22 | #include "mozilla/Casting.h" | ||||
| 23 | #include "mozilla/Range.h" | ||||
| 24 | #include "mozilla/Sprintf.h" | ||||
| 25 | #include "mozilla/Try.h" // MOZ_TRY* | ||||
| 26 | #include "mozilla/Utf8.h" | ||||
| 27 | #include "mozilla/Variant.h" | ||||
| 28 | |||||
| 29 | #include <memory> | ||||
| 30 | #include <new> | ||||
| 31 | #include <type_traits> | ||||
| 32 | |||||
| 33 | #include "jstypes.h" | ||||
| 34 | |||||
| 35 | #include "builtin/Number.h" | ||||
| 36 | #include "frontend/FoldConstants.h" | ||||
| 37 | #include "frontend/FunctionSyntaxKind.h" // FunctionSyntaxKind | ||||
| 38 | #include "frontend/ModuleSharedContext.h" | ||||
| 39 | #include "frontend/ParseNode.h" | ||||
| 40 | #include "frontend/ParseNodeVerify.h" | ||||
| 41 | #include "frontend/Parser-macros.h" // MOZ_TRY_VAR_OR_RETURN | ||||
| 42 | #include "frontend/ParserAtom.h" // TaggedParserAtomIndex, ParserAtomsTable, ParserAtom | ||||
| 43 | #include "frontend/ScriptIndex.h" // ScriptIndex | ||||
| 44 | #include "frontend/TokenStream.h" // IsKeyword, ReservedWordTokenKind, ReservedWordToCharZ, DeprecatedContent, *TokenStream*, CharBuffer, TokenKindToDesc | ||||
| 45 | #include "irregexp/RegExpAPI.h" | ||||
| 46 | #include "jit/JitOptions.h" // fuzzingSafe | ||||
| 47 | #include "js/ColumnNumber.h" // JS::LimitedColumnNumberOneOrigin, JS::ColumnNumberOneOrigin | ||||
| 48 | #include "js/ErrorReport.h" // JSErrorBase | ||||
| 49 | #include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_* | ||||
| 50 | #include "js/HashTable.h" | ||||
| 51 | #include "js/RegExpFlags.h" // JS::RegExpFlags | ||||
| 52 | #include "js/Stack.h" // JS::NativeStackLimit | ||||
| 53 | #include "util/DifferentialTesting.h" | ||||
| 54 | #include "util/StringBuilder.h" // StringBuilder | ||||
| 55 | #include "vm/BytecodeUtil.h" | ||||
| 56 | #include "vm/FunctionFlags.h" // js::FunctionFlags | ||||
| 57 | #include "vm/GeneratorAndAsyncKind.h" // js::GeneratorKind, js::FunctionAsyncKind | ||||
| 58 | #include "vm/JSContext.h" | ||||
| 59 | #include "vm/JSScript.h" | ||||
| 60 | #include "vm/ModuleBuilder.h" // js::ModuleBuilder | ||||
| 61 | #include "vm/Scope.h" // GetScopeDataTrailingNames | ||||
| 62 | |||||
| 63 | #include "frontend/ParseContext-inl.h" | ||||
| 64 | #include "frontend/SharedContext-inl.h" | ||||
| 65 | |||||
| 66 | using namespace js; | ||||
| 67 | |||||
| 68 | using mozilla::AssertedCast; | ||||
| 69 | using mozilla::AsVariant; | ||||
| 70 | using mozilla::Maybe; | ||||
| 71 | using mozilla::Nothing; | ||||
| 72 | using mozilla::PointerRangeSize; | ||||
| 73 | using mozilla::Some; | ||||
| 74 | using mozilla::Utf8Unit; | ||||
| 75 | |||||
| 76 | using JS::ReadOnlyCompileOptions; | ||||
| 77 | using JS::RegExpFlags; | ||||
| 78 | |||||
| 79 | namespace js::frontend { | ||||
| 80 | |||||
| 81 | using DeclaredNamePtr = ParseContext::Scope::DeclaredNamePtr; | ||||
| 82 | using AddDeclaredNamePtr = ParseContext::Scope::AddDeclaredNamePtr; | ||||
| 83 | using BindingIter = ParseContext::Scope::BindingIter; | ||||
| 84 | using UsedNamePtr = UsedNameTracker::UsedNameMap::Ptr; | ||||
| 85 | |||||
| 86 | using ParserBindingNameVector = Vector<ParserBindingName, 6>; | ||||
| 87 | |||||
| 88 | static inline void PropagateTransitiveParseFlags(const FunctionBox* inner, | ||||
| 89 | SharedContext* outer) { | ||||
| 90 | if (inner->bindingsAccessedDynamically()) { | ||||
| 91 | outer->setBindingsAccessedDynamically(); | ||||
| 92 | } | ||||
| 93 | if (inner->hasDirectEval()) { | ||||
| 94 | outer->setHasDirectEval(); | ||||
| 95 | } | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | static bool StatementKindIsBraced(StatementKind kind) { | ||||
| 99 | return kind == StatementKind::Block || kind == StatementKind::Switch || | ||||
| 100 | kind == StatementKind::Try || kind == StatementKind::Catch || | ||||
| 101 | kind == StatementKind::Finally; | ||||
| 102 | } | ||||
| 103 | |||||
| 104 | template <class ParseHandler, typename Unit> | ||||
| 105 | inline typename GeneralParser<ParseHandler, Unit>::FinalParser* | ||||
| 106 | GeneralParser<ParseHandler, Unit>::asFinalParser() { | ||||
| 107 | static_assert( | ||||
| 108 | std::is_base_of_v<GeneralParser<ParseHandler, Unit>, FinalParser>, | ||||
| 109 | "inheritance relationship required by the static_cast<> below"); | ||||
| 110 | |||||
| 111 | return static_cast<FinalParser*>(this); | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | template <class ParseHandler, typename Unit> | ||||
| 115 | inline const typename GeneralParser<ParseHandler, Unit>::FinalParser* | ||||
| 116 | GeneralParser<ParseHandler, Unit>::asFinalParser() const { | ||||
| 117 | static_assert( | ||||
| 118 | std::is_base_of_v<GeneralParser<ParseHandler, Unit>, FinalParser>, | ||||
| 119 | "inheritance relationship required by the static_cast<> below"); | ||||
| 120 | |||||
| 121 | return static_cast<const FinalParser*>(this); | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | template <class ParseHandler, typename Unit> | ||||
| 125 | template <typename ConditionT, typename ErrorReportT> | ||||
| 126 | bool GeneralParser<ParseHandler, Unit>::mustMatchTokenInternal( | ||||
| 127 | ConditionT condition, ErrorReportT errorReport) { | ||||
| 128 | MOZ_ASSERT(condition(TokenKind::Div) == false)do { static_assert( mozilla::detail::AssertionConditionType< decltype(condition(TokenKind::Div) == false)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(condition(TokenKind::Div) == false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("condition(TokenKind::Div) == false", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 128); AnnotateMozCrashReason("MOZ_ASSERT" "(" "condition(TokenKind::Div) == false" ")"); do { MOZ_CrashSequence(__null, 128); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 129 | MOZ_ASSERT(condition(TokenKind::DivAssign) == false)do { static_assert( mozilla::detail::AssertionConditionType< decltype(condition(TokenKind::DivAssign) == false)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(condition(TokenKind::DivAssign) == false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("condition(TokenKind::DivAssign) == false" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 129); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "condition(TokenKind::DivAssign) == false" ")" ); do { MOZ_CrashSequence(__null, 129); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 130 | MOZ_ASSERT(condition(TokenKind::RegExp) == false)do { static_assert( mozilla::detail::AssertionConditionType< decltype(condition(TokenKind::RegExp) == false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(condition(TokenKind::RegExp) == false))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("condition(TokenKind::RegExp) == false" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 130); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "condition(TokenKind::RegExp) == false" ")" ); do { MOZ_CrashSequence(__null, 130); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 131 | |||||
| 132 | TokenKind actual; | ||||
| 133 | if (!tokenStream.getToken(&actual, TokenStream::SlashIsInvalid)) { | ||||
| 134 | return false; | ||||
| 135 | } | ||||
| 136 | if (!condition(actual)) { | ||||
| 137 | errorReport(actual); | ||||
| 138 | return false; | ||||
| 139 | } | ||||
| 140 | return true; | ||||
| 141 | } | ||||
| 142 | |||||
| 143 | ParserSharedBase::ParserSharedBase(FrontendContext* fc, | ||||
| 144 | CompilationState& compilationState, | ||||
| 145 | Kind kind) | ||||
| 146 | : fc_(fc), | ||||
| 147 | alloc_(compilationState.parserAllocScope.alloc()), | ||||
| 148 | compilationState_(compilationState), | ||||
| 149 | pc_(nullptr), | ||||
| 150 | usedNames_(compilationState.usedNames) { | ||||
| 151 | fc_->nameCollectionPool().addActiveCompilation(); | ||||
| 152 | } | ||||
| 153 | |||||
| 154 | ParserSharedBase::~ParserSharedBase() { | ||||
| 155 | fc_->nameCollectionPool().removeActiveCompilation(); | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | #if defined(DEBUG1) || defined(JS_JITSPEW1) | ||||
| 159 | void ParserSharedBase::dumpAtom(TaggedParserAtomIndex index) const { | ||||
| 160 | parserAtoms().dump(index); | ||||
| 161 | } | ||||
| 162 | #endif | ||||
| 163 | |||||
| 164 | ParserBase::ParserBase(FrontendContext* fc, | ||||
| 165 | const ReadOnlyCompileOptions& options, | ||||
| 166 | CompilationState& compilationState) | ||||
| 167 | : ParserSharedBase(fc, compilationState, ParserSharedBase::Kind::Parser), | ||||
| 168 | anyChars(fc, options, this), | ||||
| 169 | ss(nullptr), | ||||
| 170 | #ifdef DEBUG1 | ||||
| 171 | checkOptionsCalled_(false), | ||||
| 172 | #endif | ||||
| 173 | isUnexpectedEOF_(false), | ||||
| 174 | awaitHandling_(AwaitIsName), | ||||
| 175 | inParametersOfAsyncFunction_(false) { | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | bool ParserBase::checkOptions() { | ||||
| 179 | #ifdef DEBUG1 | ||||
| 180 | checkOptionsCalled_ = true; | ||||
| 181 | #endif | ||||
| 182 | |||||
| 183 | return anyChars.checkOptions(); | ||||
| 184 | } | ||||
| 185 | |||||
| 186 | ParserBase::~ParserBase() { MOZ_ASSERT(checkOptionsCalled_)do { static_assert( mozilla::detail::AssertionConditionType< decltype(checkOptionsCalled_)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(checkOptionsCalled_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("checkOptionsCalled_" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 186); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence (__null, 186); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); } | ||||
| 187 | |||||
| 188 | JSAtom* ParserBase::liftParserAtomToJSAtom(TaggedParserAtomIndex index) { | ||||
| 189 | JSContext* cx = fc_->maybeCurrentJSContext(); | ||||
| 190 | MOZ_ASSERT(cx)do { static_assert( mozilla::detail::AssertionConditionType< decltype(cx)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(cx))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("cx", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 190); AnnotateMozCrashReason("MOZ_ASSERT" "(" "cx" ")"); do { MOZ_CrashSequence(__null, 190); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); | ||||
| 191 | return parserAtoms().toJSAtom(cx, fc_, index, | ||||
| 192 | compilationState_.input.atomCache); | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | template <class ParseHandler> | ||||
| 196 | PerHandlerParser<ParseHandler>::PerHandlerParser( | ||||
| 197 | FrontendContext* fc, const ReadOnlyCompileOptions& options, | ||||
| 198 | CompilationState& compilationState, void* internalSyntaxParser) | ||||
| 199 | : ParserBase(fc, options, compilationState), | ||||
| 200 | handler_(fc, compilationState), | ||||
| 201 | internalSyntaxParser_(internalSyntaxParser) { | ||||
| 202 | MOZ_ASSERT(compilationState.isInitialStencil() ==do { static_assert( mozilla::detail::AssertionConditionType< decltype(compilationState.isInitialStencil() == compilationState .input.isInitialStencil())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(compilationState.isInitialStencil () == compilationState.input.isInitialStencil()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("compilationState.isInitialStencil() == compilationState.input.isInitialStencil()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 203); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "compilationState.isInitialStencil() == compilationState.input.isInitialStencil()" ")"); do { MOZ_CrashSequence(__null, 203); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 203 | compilationState.input.isInitialStencil())do { static_assert( mozilla::detail::AssertionConditionType< decltype(compilationState.isInitialStencil() == compilationState .input.isInitialStencil())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(compilationState.isInitialStencil () == compilationState.input.isInitialStencil()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("compilationState.isInitialStencil() == compilationState.input.isInitialStencil()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 203); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "compilationState.isInitialStencil() == compilationState.input.isInitialStencil()" ")"); do { MOZ_CrashSequence(__null, 203); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 204 | } | ||||
| 205 | |||||
| 206 | template <class ParseHandler, typename Unit> | ||||
| 207 | GeneralParser<ParseHandler, Unit>::GeneralParser( | ||||
| 208 | FrontendContext* fc, const ReadOnlyCompileOptions& options, | ||||
| 209 | const Unit* units, size_t length, CompilationState& compilationState, | ||||
| 210 | SyntaxParser* syntaxParser) | ||||
| 211 | : Base(fc, options, compilationState, syntaxParser), | ||||
| 212 | tokenStream(fc, &compilationState.parserAtoms, options, units, length) {} | ||||
| 213 | |||||
| 214 | template <typename Unit> | ||||
| 215 | void Parser<SyntaxParseHandler, Unit>::setAwaitHandling( | ||||
| 216 | AwaitHandling awaitHandling) { | ||||
| 217 | this->awaitHandling_ = awaitHandling; | ||||
| 218 | } | ||||
| 219 | |||||
| 220 | template <typename Unit> | ||||
| 221 | void Parser<FullParseHandler, Unit>::setAwaitHandling( | ||||
| 222 | AwaitHandling awaitHandling) { | ||||
| 223 | this->awaitHandling_ = awaitHandling; | ||||
| 224 | if (SyntaxParser* syntaxParser = getSyntaxParser()) { | ||||
| 225 | syntaxParser->setAwaitHandling(awaitHandling); | ||||
| 226 | } | ||||
| 227 | } | ||||
| 228 | |||||
| 229 | template <class ParseHandler, typename Unit> | ||||
| 230 | inline void GeneralParser<ParseHandler, Unit>::setAwaitHandling( | ||||
| 231 | AwaitHandling awaitHandling) { | ||||
| 232 | asFinalParser()->setAwaitHandling(awaitHandling); | ||||
| 233 | } | ||||
| 234 | |||||
| 235 | template <typename Unit> | ||||
| 236 | void Parser<SyntaxParseHandler, Unit>::setInParametersOfAsyncFunction( | ||||
| 237 | bool inParameters) { | ||||
| 238 | this->inParametersOfAsyncFunction_ = inParameters; | ||||
| 239 | } | ||||
| 240 | |||||
| 241 | template <typename Unit> | ||||
| 242 | void Parser<FullParseHandler, Unit>::setInParametersOfAsyncFunction( | ||||
| 243 | bool inParameters) { | ||||
| 244 | this->inParametersOfAsyncFunction_ = inParameters; | ||||
| 245 | if (SyntaxParser* syntaxParser = getSyntaxParser()) { | ||||
| 246 | syntaxParser->setInParametersOfAsyncFunction(inParameters); | ||||
| 247 | } | ||||
| 248 | } | ||||
| 249 | |||||
| 250 | template <class ParseHandler, typename Unit> | ||||
| 251 | inline void GeneralParser<ParseHandler, Unit>::setInParametersOfAsyncFunction( | ||||
| 252 | bool inParameters) { | ||||
| 253 | asFinalParser()->setInParametersOfAsyncFunction(inParameters); | ||||
| 254 | } | ||||
| 255 | |||||
| 256 | template <class ParseHandler> | ||||
| 257 | FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox( | ||||
| 258 | FunctionNodeType funNode, TaggedParserAtomIndex explicitName, | ||||
| 259 | FunctionFlags flags, uint32_t toStringStart, Directives inheritedDirectives, | ||||
| 260 | GeneratorKind generatorKind, FunctionAsyncKind asyncKind) { | ||||
| 261 | MOZ_ASSERT(funNode)do { static_assert( mozilla::detail::AssertionConditionType< decltype(funNode)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(funNode))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("funNode", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 261); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funNode" ")" ); do { MOZ_CrashSequence(__null, 261); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 262 | |||||
| 263 | ScriptIndex index = ScriptIndex(compilationState_.scriptData.length()); | ||||
| 264 | if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) { | ||||
| 265 | ReportAllocationOverflow(fc_); | ||||
| 266 | return nullptr; | ||||
| 267 | } | ||||
| 268 | if (!compilationState_.appendScriptStencilAndData(fc_)) { | ||||
| 269 | return nullptr; | ||||
| 270 | } | ||||
| 271 | |||||
| 272 | bool isInitialStencil = compilationState_.isInitialStencil(); | ||||
| 273 | |||||
| 274 | // This source extent will be further filled in during the remainder of parse. | ||||
| 275 | SourceExtent extent; | ||||
| 276 | extent.toStringStart = toStringStart; | ||||
| 277 | |||||
| 278 | FunctionBox* funbox = alloc_.new_<FunctionBox>( | ||||
| 279 | fc_, extent, compilationState_, inheritedDirectives, generatorKind, | ||||
| 280 | asyncKind, isInitialStencil, explicitName, flags, index); | ||||
| 281 | if (!funbox) { | ||||
| 282 | ReportOutOfMemory(fc_); | ||||
| 283 | return nullptr; | ||||
| 284 | } | ||||
| 285 | |||||
| 286 | handler_.setFunctionBox(funNode, funbox); | ||||
| 287 | |||||
| 288 | return funbox; | ||||
| 289 | } | ||||
| 290 | |||||
| 291 | template <class ParseHandler> | ||||
| 292 | FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox( | ||||
| 293 | FunctionNodeType funNode, const ScriptStencil& cachedScriptData, | ||||
| 294 | const ScriptStencilExtra& cachedScriptExtra) { | ||||
| 295 | MOZ_ASSERT(funNode)do { static_assert( mozilla::detail::AssertionConditionType< decltype(funNode)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(funNode))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("funNode", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 295); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funNode" ")" ); do { MOZ_CrashSequence(__null, 295); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 296 | |||||
| 297 | ScriptIndex index = ScriptIndex(compilationState_.scriptData.length()); | ||||
| 298 | if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) { | ||||
| 299 | ReportAllocationOverflow(fc_); | ||||
| 300 | return nullptr; | ||||
| 301 | } | ||||
| 302 | if (!compilationState_.appendScriptStencilAndData(fc_)) { | ||||
| 303 | return nullptr; | ||||
| 304 | } | ||||
| 305 | |||||
| 306 | FunctionBox* funbox = alloc_.new_<FunctionBox>( | ||||
| 307 | fc_, cachedScriptExtra.extent, compilationState_, | ||||
| 308 | Directives(/* strict = */ false), cachedScriptExtra.generatorKind(), | ||||
| 309 | cachedScriptExtra.asyncKind(), compilationState_.isInitialStencil(), | ||||
| 310 | cachedScriptData.functionAtom, cachedScriptData.functionFlags, index); | ||||
| 311 | if (!funbox) { | ||||
| 312 | ReportOutOfMemory(fc_); | ||||
| 313 | return nullptr; | ||||
| 314 | } | ||||
| 315 | |||||
| 316 | handler_.setFunctionBox(funNode, funbox); | ||||
| 317 | funbox->initFromScriptStencilExtra(cachedScriptExtra); | ||||
| 318 | |||||
| 319 | return funbox; | ||||
| 320 | } | ||||
| 321 | |||||
| 322 | bool ParserBase::setSourceMapInfo() { | ||||
| 323 | // If support for source pragmas have been fully disabled, we can skip | ||||
| 324 | // processing of all of these values. | ||||
| 325 | if (!options().sourcePragmas()) { | ||||
| 326 | return true; | ||||
| 327 | } | ||||
| 328 | |||||
| 329 | // Not all clients initialize ss. Can't update info to an object that isn't | ||||
| 330 | // there. | ||||
| 331 | if (!ss) { | ||||
| 332 | return true; | ||||
| 333 | } | ||||
| 334 | |||||
| 335 | if (anyChars.hasDisplayURL()) { | ||||
| 336 | if (!ss->setDisplayURL(fc_, anyChars.displayURL())) { | ||||
| 337 | return false; | ||||
| 338 | } | ||||
| 339 | } | ||||
| 340 | |||||
| 341 | if (anyChars.hasSourceMapURL()) { | ||||
| 342 | MOZ_ASSERT(!ss->hasSourceMapURL())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!ss->hasSourceMapURL())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!ss->hasSourceMapURL()))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("!ss->hasSourceMapURL()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 342); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!ss->hasSourceMapURL()" ")"); do { MOZ_CrashSequence (__null, 342); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); | ||||
| 343 | if (!ss->setSourceMapURL(fc_, anyChars.sourceMapURL())) { | ||||
| 344 | return false; | ||||
| 345 | } | ||||
| 346 | } | ||||
| 347 | |||||
| 348 | /* | ||||
| 349 | * Source map URLs passed as a compile option (usually via a HTTP source map | ||||
| 350 | * header) override any source map urls passed as comment pragmas. | ||||
| 351 | */ | ||||
| 352 | if (options().sourceMapURL()) { | ||||
| 353 | // Warn about the replacement, but use the new one. | ||||
| 354 | if (ss->hasSourceMapURL()) { | ||||
| 355 | if (!warningNoOffset(JSMSG_ALREADY_HAS_PRAGMA, ss->filename(), | ||||
| 356 | "//# sourceMappingURL")) { | ||||
| 357 | return false; | ||||
| 358 | } | ||||
| 359 | } | ||||
| 360 | |||||
| 361 | if (!ss->setSourceMapURL(fc_, options().sourceMapURL())) { | ||||
| 362 | return false; | ||||
| 363 | } | ||||
| 364 | } | ||||
| 365 | |||||
| 366 | return true; | ||||
| 367 | } | ||||
| 368 | |||||
| 369 | /* | ||||
| 370 | * Parse a top-level JS script. | ||||
| 371 | */ | ||||
| 372 | template <class ParseHandler, typename Unit> | ||||
| 373 | typename ParseHandler::ListNodeResult | ||||
| 374 | GeneralParser<ParseHandler, Unit>::parse() { | ||||
| 375 | MOZ_ASSERT(checkOptionsCalled_)do { static_assert( mozilla::detail::AssertionConditionType< decltype(checkOptionsCalled_)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(checkOptionsCalled_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("checkOptionsCalled_" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 375); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence (__null, 375); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); | ||||
| 376 | |||||
| 377 | SourceExtent extent = SourceExtent::makeGlobalExtent( | ||||
| 378 | /* len = */ 0, options().lineno, | ||||
| 379 | JS::LimitedColumnNumberOneOrigin::fromUnlimited( | ||||
| 380 | JS::ColumnNumberOneOrigin(options().column))); | ||||
| 381 | Directives directives(options().forceStrictMode()); | ||||
| 382 | GlobalSharedContext globalsc(this->fc_, ScopeKind::Global, options(), | ||||
| 383 | directives, extent); | ||||
| 384 | SourceParseContext globalpc(this, &globalsc, /* newDirectives = */ nullptr); | ||||
| 385 | if (!globalpc.init()) { | ||||
| 386 | return errorResult(); | ||||
| 387 | } | ||||
| 388 | |||||
| 389 | ParseContext::VarScope varScope(this); | ||||
| 390 | if (!varScope.init(pc_)) { | ||||
| 391 | return errorResult(); | ||||
| 392 | } | ||||
| 393 | |||||
| 394 | ListNodeType stmtList = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 395 | |||||
| 396 | TokenKind tt; | ||||
| 397 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 398 | return errorResult(); | ||||
| 399 | } | ||||
| 400 | if (tt != TokenKind::Eof) { | ||||
| 401 | error(JSMSG_GARBAGE_AFTER_INPUT, "script", TokenKindToDesc(tt)); | ||||
| 402 | return errorResult(); | ||||
| 403 | } | ||||
| 404 | |||||
| 405 | if (!CheckParseTree(this->fc_, alloc_, stmtList)) { | ||||
| 406 | return errorResult(); | ||||
| 407 | } | ||||
| 408 | |||||
| 409 | return stmtList; | ||||
| 410 | } | ||||
| 411 | |||||
| 412 | /* | ||||
| 413 | * Strict mode forbids introducing new definitions for 'eval', 'arguments', | ||||
| 414 | * 'let', 'static', 'yield', or for any strict mode reserved word. | ||||
| 415 | */ | ||||
| 416 | bool ParserBase::isValidStrictBinding(TaggedParserAtomIndex name) { | ||||
| 417 | TokenKind tt = ReservedWordTokenKind(name); | ||||
| 418 | if (tt == TokenKind::Limit) { | ||||
| 419 | return name != TaggedParserAtomIndex::WellKnown::eval() && | ||||
| 420 | name != TaggedParserAtomIndex::WellKnown::arguments(); | ||||
| 421 | } | ||||
| 422 | return tt != TokenKind::Let && tt != TokenKind::Static && | ||||
| 423 | tt != TokenKind::Yield && !TokenKindIsStrictReservedWord(tt); | ||||
| 424 | } | ||||
| 425 | |||||
| 426 | /* | ||||
| 427 | * Returns true if all parameter names are valid strict mode binding names and | ||||
| 428 | * no duplicate parameter names are present. | ||||
| 429 | */ | ||||
| 430 | bool ParserBase::hasValidSimpleStrictParameterNames() { | ||||
| 431 | MOZ_ASSERT(pc_->isFunctionBox() &&do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isFunctionBox() && pc_->functionBox ()->hasSimpleParameterList())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 432); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()" ")"); do { MOZ_CrashSequence(__null, 432); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 432 | pc_->functionBox()->hasSimpleParameterList())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isFunctionBox() && pc_->functionBox ()->hasSimpleParameterList())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 432); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()" ")"); do { MOZ_CrashSequence(__null, 432); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 433 | |||||
| 434 | if (pc_->functionBox()->hasDuplicateParameters) { | ||||
| 435 | return false; | ||||
| 436 | } | ||||
| 437 | |||||
| 438 | for (auto name : pc_->positionalFormalParameterNames()) { | ||||
| 439 | MOZ_ASSERT(name)do { static_assert( mozilla::detail::AssertionConditionType< decltype(name)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(name))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("name", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 439); AnnotateMozCrashReason("MOZ_ASSERT" "(" "name" ")"); do { MOZ_CrashSequence(__null, 439); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); | ||||
| 440 | if (!isValidStrictBinding(name)) { | ||||
| 441 | return false; | ||||
| 442 | } | ||||
| 443 | } | ||||
| 444 | return true; | ||||
| 445 | } | ||||
| 446 | |||||
| 447 | template <class ParseHandler, typename Unit> | ||||
| 448 | void GeneralParser<ParseHandler, Unit>::reportMissingClosing( | ||||
| 449 | unsigned errorNumber, unsigned noteNumber, uint32_t openedPos) { | ||||
| 450 | auto notes = MakeUnique<JSErrorNotes>(); | ||||
| 451 | if (!notes) { | ||||
| 452 | ReportOutOfMemory(this->fc_); | ||||
| 453 | return; | ||||
| 454 | } | ||||
| 455 | |||||
| 456 | uint32_t line; | ||||
| 457 | JS::LimitedColumnNumberOneOrigin column; | ||||
| 458 | tokenStream.computeLineAndColumn(openedPos, &line, &column); | ||||
| 459 | |||||
| 460 | const size_t MaxWidth = sizeof("4294967295"); | ||||
| 461 | char columnNumber[MaxWidth]; | ||||
| 462 | SprintfLiteral(columnNumber, "%" PRIu32"u", column.oneOriginValue()); | ||||
| 463 | char lineNumber[MaxWidth]; | ||||
| 464 | SprintfLiteral(lineNumber, "%" PRIu32"u", line); | ||||
| 465 | |||||
| 466 | if (!notes->addNoteASCII(this->fc_, getFilename().c_str(), 0, line, | ||||
| 467 | JS::ColumnNumberOneOrigin(column), GetErrorMessage, | ||||
| 468 | nullptr, noteNumber, lineNumber, columnNumber)) { | ||||
| 469 | return; | ||||
| 470 | } | ||||
| 471 | |||||
| 472 | errorWithNotes(std::move(notes), errorNumber); | ||||
| 473 | } | ||||
| 474 | |||||
| 475 | template <class ParseHandler, typename Unit> | ||||
| 476 | void GeneralParser<ParseHandler, Unit>::reportRedeclarationHelper( | ||||
| 477 | TaggedParserAtomIndex& name, DeclarationKind& prevKind, TokenPos& pos, | ||||
| 478 | uint32_t& prevPos, const unsigned& errorNumber, | ||||
| 479 | const unsigned& noteErrorNumber) { | ||||
| 480 | UniqueChars bytes = this->parserAtoms().toPrintableString(name); | ||||
| 481 | if (!bytes) { | ||||
| 482 | ReportOutOfMemory(this->fc_); | ||||
| 483 | return; | ||||
| 484 | } | ||||
| 485 | |||||
| 486 | if (prevPos == DeclaredNameInfo::npos) { | ||||
| 487 | errorAt(pos.begin, errorNumber, DeclarationKindString(prevKind), | ||||
| 488 | bytes.get()); | ||||
| 489 | return; | ||||
| 490 | } | ||||
| 491 | |||||
| 492 | auto notes = MakeUnique<JSErrorNotes>(); | ||||
| 493 | if (!notes) { | ||||
| 494 | ReportOutOfMemory(this->fc_); | ||||
| 495 | return; | ||||
| 496 | } | ||||
| 497 | |||||
| 498 | uint32_t line; | ||||
| 499 | JS::LimitedColumnNumberOneOrigin column; | ||||
| 500 | tokenStream.computeLineAndColumn(prevPos, &line, &column); | ||||
| 501 | |||||
| 502 | const size_t MaxWidth = sizeof("4294967295"); | ||||
| 503 | char columnNumber[MaxWidth]; | ||||
| 504 | SprintfLiteral(columnNumber, "%" PRIu32"u", column.oneOriginValue()); | ||||
| 505 | char lineNumber[MaxWidth]; | ||||
| 506 | SprintfLiteral(lineNumber, "%" PRIu32"u", line); | ||||
| 507 | |||||
| 508 | if (!notes->addNoteASCII(this->fc_, getFilename().c_str(), 0, line, | ||||
| 509 | JS::ColumnNumberOneOrigin(column), GetErrorMessage, | ||||
| 510 | nullptr, noteErrorNumber, lineNumber, | ||||
| 511 | columnNumber)) { | ||||
| 512 | return; | ||||
| 513 | } | ||||
| 514 | |||||
| 515 | errorWithNotesAt(std::move(notes), pos.begin, errorNumber, | ||||
| 516 | DeclarationKindString(prevKind), bytes.get()); | ||||
| 517 | } | ||||
| 518 | |||||
| 519 | template <class ParseHandler, typename Unit> | ||||
| 520 | void GeneralParser<ParseHandler, Unit>::reportRedeclaration( | ||||
| 521 | TaggedParserAtomIndex name, DeclarationKind prevKind, TokenPos pos, | ||||
| 522 | uint32_t prevPos) { | ||||
| 523 | reportRedeclarationHelper(name, prevKind, pos, prevPos, JSMSG_REDECLARED_VAR, | ||||
| 524 | JSMSG_PREV_DECLARATION); | ||||
| 525 | } | ||||
| 526 | |||||
| 527 | template <class ParseHandler, typename Unit> | ||||
| 528 | void GeneralParser<ParseHandler, Unit>::reportMismatchedPlacement( | ||||
| 529 | TaggedParserAtomIndex name, DeclarationKind prevKind, TokenPos pos, | ||||
| 530 | uint32_t prevPos) { | ||||
| 531 | reportRedeclarationHelper(name, prevKind, pos, prevPos, | ||||
| 532 | JSMSG_MISMATCHED_PLACEMENT, JSMSG_PREV_DECLARATION); | ||||
| 533 | } | ||||
| 534 | |||||
| 535 | // notePositionalFormalParameter is called for both the arguments of a regular | ||||
| 536 | // function definition and the arguments specified by the Function | ||||
| 537 | // constructor. | ||||
| 538 | // | ||||
| 539 | // The 'disallowDuplicateParams' bool indicates whether the use of another | ||||
| 540 | // feature (destructuring or default arguments) disables duplicate arguments. | ||||
| 541 | // (ECMA-262 requires us to support duplicate parameter names, but, for newer | ||||
| 542 | // features, we consider the code to have "opted in" to higher standards and | ||||
| 543 | // forbid duplicates.) | ||||
| 544 | template <class ParseHandler, typename Unit> | ||||
| 545 | bool GeneralParser<ParseHandler, Unit>::notePositionalFormalParameter( | ||||
| 546 | FunctionNodeType funNode, TaggedParserAtomIndex name, uint32_t beginPos, | ||||
| 547 | bool disallowDuplicateParams, bool* duplicatedParam) { | ||||
| 548 | if (AddDeclaredNamePtr p = | ||||
| 549 | pc_->functionScope().lookupDeclaredNameForAdd(name)) { | ||||
| 550 | if (disallowDuplicateParams) { | ||||
| 551 | error(JSMSG_BAD_DUP_ARGS); | ||||
| 552 | return false; | ||||
| 553 | } | ||||
| 554 | |||||
| 555 | // Strict-mode disallows duplicate args. We may not know whether we are | ||||
| 556 | // in strict mode or not (since the function body hasn't been parsed). | ||||
| 557 | // In such cases, report will queue up the potential error and return | ||||
| 558 | // 'true'. | ||||
| 559 | if (pc_->sc()->strict()) { | ||||
| 560 | UniqueChars bytes = this->parserAtoms().toPrintableString(name); | ||||
| 561 | if (!bytes) { | ||||
| 562 | ReportOutOfMemory(this->fc_); | ||||
| 563 | return false; | ||||
| 564 | } | ||||
| 565 | if (!strictModeError(JSMSG_DUPLICATE_FORMAL, bytes.get())) { | ||||
| 566 | return false; | ||||
| 567 | } | ||||
| 568 | } | ||||
| 569 | |||||
| 570 | *duplicatedParam = true; | ||||
| 571 | } else { | ||||
| 572 | DeclarationKind kind = DeclarationKind::PositionalFormalParameter; | ||||
| 573 | if (!pc_->functionScope().addDeclaredName(pc_, p, name, kind, beginPos)) { | ||||
| 574 | return false; | ||||
| 575 | } | ||||
| 576 | } | ||||
| 577 | |||||
| 578 | if (!pc_->positionalFormalParameterNames().append( | ||||
| 579 | TrivialTaggedParserAtomIndex::from(name))) { | ||||
| 580 | ReportOutOfMemory(this->fc_); | ||||
| 581 | return false; | ||||
| 582 | } | ||||
| 583 | |||||
| 584 | NameNodeType paramNode; | ||||
| 585 | MOZ_TRY_VAR_OR_RETURN(paramNode, newName(name), false)do { auto parserTryVarTempResult_ = (newName(name)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (paramNode) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 586 | |||||
| 587 | handler_.addFunctionFormalParameter(funNode, paramNode); | ||||
| 588 | return true; | ||||
| 589 | } | ||||
| 590 | |||||
| 591 | template <class ParseHandler> | ||||
| 592 | bool PerHandlerParser<ParseHandler>::noteDestructuredPositionalFormalParameter( | ||||
| 593 | FunctionNodeType funNode, Node destruct) { | ||||
| 594 | // Append an empty name to the positional formals vector to keep track of | ||||
| 595 | // argument slots when making FunctionScope::ParserData. | ||||
| 596 | if (!pc_->positionalFormalParameterNames().append( | ||||
| 597 | TrivialTaggedParserAtomIndex::null())) { | ||||
| 598 | ReportOutOfMemory(fc_); | ||||
| 599 | return false; | ||||
| 600 | } | ||||
| 601 | |||||
| 602 | handler_.addFunctionFormalParameter(funNode, destruct); | ||||
| 603 | return true; | ||||
| 604 | } | ||||
| 605 | |||||
| 606 | template <class ParseHandler, typename Unit> | ||||
| 607 | bool GeneralParser<ParseHandler, Unit>::noteDeclaredName( | ||||
| 608 | TaggedParserAtomIndex name, DeclarationKind kind, TokenPos pos, | ||||
| 609 | ClosedOver isClosedOver) { | ||||
| 610 | switch (kind) { | ||||
| 611 | case DeclarationKind::Var: | ||||
| 612 | case DeclarationKind::BodyLevelFunction: { | ||||
| 613 | Maybe<DeclarationKind> redeclaredKind; | ||||
| 614 | uint32_t prevPos; | ||||
| 615 | if (!pc_->tryDeclareVar(name, this, kind, pos.begin, &redeclaredKind, | ||||
| 616 | &prevPos)) { | ||||
| 617 | return false; | ||||
| 618 | } | ||||
| 619 | |||||
| 620 | if (redeclaredKind) { | ||||
| 621 | reportRedeclaration(name, *redeclaredKind, pos, prevPos); | ||||
| 622 | return false; | ||||
| 623 | } | ||||
| 624 | |||||
| 625 | break; | ||||
| 626 | } | ||||
| 627 | |||||
| 628 | case DeclarationKind::ModuleBodyLevelFunction: { | ||||
| 629 | MOZ_ASSERT(pc_->atModuleLevel())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->atModuleLevel())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->atModuleLevel()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->atModuleLevel()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 629); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->atModuleLevel()" ")"); do { MOZ_CrashSequence (__null, 629); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); | ||||
| 630 | |||||
| 631 | AddDeclaredNamePtr p = pc_->varScope().lookupDeclaredNameForAdd(name); | ||||
| 632 | if (p) { | ||||
| 633 | reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos()); | ||||
| 634 | return false; | ||||
| 635 | } | ||||
| 636 | |||||
| 637 | if (!pc_->varScope().addDeclaredName(pc_, p, name, kind, pos.begin, | ||||
| 638 | isClosedOver)) { | ||||
| 639 | return false; | ||||
| 640 | } | ||||
| 641 | |||||
| 642 | // Body-level functions in modules are always closed over. | ||||
| 643 | pc_->varScope().lookupDeclaredName(name)->value()->setClosedOver(); | ||||
| 644 | |||||
| 645 | break; | ||||
| 646 | } | ||||
| 647 | |||||
| 648 | case DeclarationKind::FormalParameter: { | ||||
| 649 | // It is an early error if any non-positional formal parameter name | ||||
| 650 | // (e.g., destructuring formal parameter) is duplicated. | ||||
| 651 | |||||
| 652 | AddDeclaredNamePtr p = | ||||
| 653 | pc_->functionScope().lookupDeclaredNameForAdd(name); | ||||
| 654 | if (p) { | ||||
| 655 | error(JSMSG_BAD_DUP_ARGS); | ||||
| 656 | return false; | ||||
| 657 | } | ||||
| 658 | |||||
| 659 | if (!pc_->functionScope().addDeclaredName(pc_, p, name, kind, pos.begin, | ||||
| 660 | isClosedOver)) { | ||||
| 661 | return false; | ||||
| 662 | } | ||||
| 663 | |||||
| 664 | break; | ||||
| 665 | } | ||||
| 666 | |||||
| 667 | case DeclarationKind::LexicalFunction: | ||||
| 668 | case DeclarationKind::PrivateName: | ||||
| 669 | case DeclarationKind::Synthetic: | ||||
| 670 | case DeclarationKind::PrivateMethod: { | ||||
| 671 | ParseContext::Scope* scope = pc_->innermostScope(); | ||||
| 672 | AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name); | ||||
| 673 | if (p) { | ||||
| 674 | reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos()); | ||||
| 675 | return false; | ||||
| 676 | } | ||||
| 677 | |||||
| 678 | if (!scope->addDeclaredName(pc_, p, name, kind, pos.begin, | ||||
| 679 | isClosedOver)) { | ||||
| 680 | return false; | ||||
| 681 | } | ||||
| 682 | |||||
| 683 | break; | ||||
| 684 | } | ||||
| 685 | |||||
| 686 | case DeclarationKind::SloppyLexicalFunction: { | ||||
| 687 | // Functions in block have complex allowances in sloppy mode for being | ||||
| 688 | // labelled that other lexical declarations do not have. Those checks | ||||
| 689 | // are done in functionStmt. | ||||
| 690 | |||||
| 691 | ParseContext::Scope* scope = pc_->innermostScope(); | ||||
| 692 | if (AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name)) { | ||||
| 693 | // It is usually an early error if there is another declaration | ||||
| 694 | // with the same name in the same scope. | ||||
| 695 | // | ||||
| 696 | // Sloppy lexical functions may redeclare other sloppy lexical | ||||
| 697 | // functions for web compatibility reasons. | ||||
| 698 | if (p->value()->kind() != DeclarationKind::SloppyLexicalFunction) { | ||||
| 699 | reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos()); | ||||
| 700 | return false; | ||||
| 701 | } | ||||
| 702 | } else { | ||||
| 703 | if (!scope->addDeclaredName(pc_, p, name, kind, pos.begin, | ||||
| 704 | isClosedOver)) { | ||||
| 705 | return false; | ||||
| 706 | } | ||||
| 707 | } | ||||
| 708 | |||||
| 709 | break; | ||||
| 710 | } | ||||
| 711 | |||||
| 712 | case DeclarationKind::Let: | ||||
| 713 | case DeclarationKind::Const: | ||||
| 714 | case DeclarationKind::Using: | ||||
| 715 | case DeclarationKind::AwaitUsing: | ||||
| 716 | case DeclarationKind::Class: | ||||
| 717 | // The BoundNames of LexicalDeclaration and ForDeclaration must not | ||||
| 718 | // contain 'let'. (CatchParameter is the only lexical binding form | ||||
| 719 | // without this restriction.) | ||||
| 720 | if (name == TaggedParserAtomIndex::WellKnown::let()) { | ||||
| 721 | errorAt(pos.begin, JSMSG_LEXICAL_DECL_DEFINES_LET); | ||||
| 722 | return false; | ||||
| 723 | } | ||||
| 724 | |||||
| 725 | // For body-level lexically declared names in a function, it is an | ||||
| 726 | // early error if there is a formal parameter of the same name. This | ||||
| 727 | // needs a special check if there is an extra var scope due to | ||||
| 728 | // parameter expressions. | ||||
| 729 | if (pc_->isFunctionExtraBodyVarScopeInnermost()) { | ||||
| 730 | DeclaredNamePtr p = pc_->functionScope().lookupDeclaredName(name); | ||||
| 731 | if (p && DeclarationKindIsParameter(p->value()->kind())) { | ||||
| 732 | reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos()); | ||||
| 733 | return false; | ||||
| 734 | } | ||||
| 735 | } | ||||
| 736 | |||||
| 737 | [[fallthrough]]; | ||||
| 738 | |||||
| 739 | case DeclarationKind::Import: | ||||
| 740 | // Module code is always strict, so 'let' is always a keyword and never a | ||||
| 741 | // name. | ||||
| 742 | MOZ_ASSERT(name != TaggedParserAtomIndex::WellKnown::let())do { static_assert( mozilla::detail::AssertionConditionType< decltype(name != TaggedParserAtomIndex::WellKnown::let())> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(name != TaggedParserAtomIndex::WellKnown::let()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("name != TaggedParserAtomIndex::WellKnown::let()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 742); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "name != TaggedParserAtomIndex::WellKnown::let()" ")"); do { MOZ_CrashSequence(__null, 742); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 743 | [[fallthrough]]; | ||||
| 744 | |||||
| 745 | case DeclarationKind::SimpleCatchParameter: | ||||
| 746 | case DeclarationKind::CatchParameter: { | ||||
| 747 | ParseContext::Scope* scope = pc_->innermostScope(); | ||||
| 748 | |||||
| 749 | // It is an early error if there is another declaration with the same | ||||
| 750 | // name in the same scope. | ||||
| 751 | AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name); | ||||
| 752 | if (p) { | ||||
| 753 | reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos()); | ||||
| 754 | return false; | ||||
| 755 | } | ||||
| 756 | |||||
| 757 | if (!scope->addDeclaredName(pc_, p, name, kind, pos.begin, | ||||
| 758 | isClosedOver)) { | ||||
| 759 | return false; | ||||
| 760 | } | ||||
| 761 | |||||
| 762 | break; | ||||
| 763 | } | ||||
| 764 | |||||
| 765 | case DeclarationKind::CoverArrowParameter: | ||||
| 766 | // CoverArrowParameter is only used as a placeholder declaration kind. | ||||
| 767 | break; | ||||
| 768 | |||||
| 769 | case DeclarationKind::PositionalFormalParameter: | ||||
| 770 | MOZ_CRASH(do { do { } while (false); MOZ_ReportCrash("" "Positional formal parameter names should use " "notePositionalFormalParameter", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 772); AnnotateMozCrashReason("MOZ_CRASH(" "Positional formal parameter names should use " "notePositionalFormalParameter" ")"); do { MOZ_CrashSequence (__null, 772); __attribute__((nomerge)) ::abort(); } while (false ); } while (false) | ||||
| 771 | "Positional formal parameter names should use "do { do { } while (false); MOZ_ReportCrash("" "Positional formal parameter names should use " "notePositionalFormalParameter", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 772); AnnotateMozCrashReason("MOZ_CRASH(" "Positional formal parameter names should use " "notePositionalFormalParameter" ")"); do { MOZ_CrashSequence (__null, 772); __attribute__((nomerge)) ::abort(); } while (false ); } while (false) | ||||
| 772 | "notePositionalFormalParameter")do { do { } while (false); MOZ_ReportCrash("" "Positional formal parameter names should use " "notePositionalFormalParameter", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 772); AnnotateMozCrashReason("MOZ_CRASH(" "Positional formal parameter names should use " "notePositionalFormalParameter" ")"); do { MOZ_CrashSequence (__null, 772); __attribute__((nomerge)) ::abort(); } while (false ); } while (false); | ||||
| 773 | break; | ||||
| 774 | |||||
| 775 | case DeclarationKind::VarForAnnexBLexicalFunction: | ||||
| 776 | MOZ_CRASH(do { do { } while (false); MOZ_ReportCrash("" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 779); AnnotateMozCrashReason ("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence (__null, 779); __attribute__((nomerge)) ::abort(); } while (false ); } while (false) | ||||
| 777 | "Synthesized Annex B vars should go through "do { do { } while (false); MOZ_ReportCrash("" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 779); AnnotateMozCrashReason ("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence (__null, 779); __attribute__((nomerge)) ::abort(); } while (false ); } while (false) | ||||
| 778 | "addPossibleAnnexBFunctionBox, and "do { do { } while (false); MOZ_ReportCrash("" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 779); AnnotateMozCrashReason ("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence (__null, 779); __attribute__((nomerge)) ::abort(); } while (false ); } while (false) | ||||
| 779 | "propagateAndMarkAnnexBFunctionBoxes")do { do { } while (false); MOZ_ReportCrash("" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 779); AnnotateMozCrashReason ("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and " "propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence (__null, 779); __attribute__((nomerge)) ::abort(); } while (false ); } while (false); | ||||
| 780 | break; | ||||
| 781 | } | ||||
| 782 | |||||
| 783 | return true; | ||||
| 784 | } | ||||
| 785 | |||||
| 786 | template <class ParseHandler, typename Unit> | ||||
| 787 | bool GeneralParser<ParseHandler, Unit>::noteDeclaredPrivateName( | ||||
| 788 | Node nameNode, TaggedParserAtomIndex name, PropertyType propType, | ||||
| 789 | FieldPlacement placement, TokenPos pos) { | ||||
| 790 | ParseContext::Scope* scope = pc_->innermostScope(); | ||||
| 791 | AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name); | ||||
| 792 | |||||
| 793 | DeclarationKind declKind = DeclarationKind::PrivateName; | ||||
| 794 | |||||
| 795 | // Our strategy for enabling debugger functionality is to mark names as closed | ||||
| 796 | // over, even if they don't necessarily need to be, to ensure that they are | ||||
| 797 | // included in the environment object. This allows us to easily look them up | ||||
| 798 | // by name when needed, even if there is no corresponding property on an | ||||
| 799 | // object, as is the case with getter, setters and private methods. | ||||
| 800 | ClosedOver closedOver = ClosedOver::Yes; | ||||
| 801 | PrivateNameKind kind; | ||||
| 802 | switch (propType) { | ||||
| 803 | case PropertyType::Field: | ||||
| 804 | kind = PrivateNameKind::Field; | ||||
| 805 | closedOver = ClosedOver::No; | ||||
| 806 | break; | ||||
| 807 | case PropertyType::FieldWithAccessor: | ||||
| 808 | // In this case, we create a new private field for the underlying storage, | ||||
| 809 | // and use the current name for the getter and setter. | ||||
| 810 | kind = PrivateNameKind::GetterSetter; | ||||
| 811 | break; | ||||
| 812 | case PropertyType::Method: | ||||
| 813 | case PropertyType::GeneratorMethod: | ||||
| 814 | case PropertyType::AsyncMethod: | ||||
| 815 | case PropertyType::AsyncGeneratorMethod: | ||||
| 816 | if (placement == FieldPlacement::Instance) { | ||||
| 817 | // Optimized private method. Non-optimized paths still get | ||||
| 818 | // DeclarationKind::Synthetic. | ||||
| 819 | declKind = DeclarationKind::PrivateMethod; | ||||
| 820 | } | ||||
| 821 | kind = PrivateNameKind::Method; | ||||
| 822 | break; | ||||
| 823 | case PropertyType::Getter: | ||||
| 824 | kind = PrivateNameKind::Getter; | ||||
| 825 | break; | ||||
| 826 | case PropertyType::Setter: | ||||
| 827 | kind = PrivateNameKind::Setter; | ||||
| 828 | break; | ||||
| 829 | default: | ||||
| 830 | MOZ_CRASH("Invalid Property Type for noteDeclarePrivateName")do { do { } while (false); MOZ_ReportCrash("" "Invalid Property Type for noteDeclarePrivateName" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 830); AnnotateMozCrashReason ("MOZ_CRASH(" "Invalid Property Type for noteDeclarePrivateName" ")"); do { MOZ_CrashSequence(__null, 830); __attribute__((nomerge )) ::abort(); } while (false); } while (false); | ||||
| 831 | } | ||||
| 832 | |||||
| 833 | if (p) { | ||||
| 834 | PrivateNameKind prevKind = p->value()->privateNameKind(); | ||||
| 835 | if ((prevKind == PrivateNameKind::Getter && | ||||
| 836 | kind == PrivateNameKind::Setter) || | ||||
| 837 | (prevKind == PrivateNameKind::Setter && | ||||
| 838 | kind == PrivateNameKind::Getter)) { | ||||
| 839 | // Private methods demands that | ||||
| 840 | // | ||||
| 841 | // class A { | ||||
| 842 | // static set #x(_) {} | ||||
| 843 | // get #x() { } | ||||
| 844 | // } | ||||
| 845 | // | ||||
| 846 | // Report a SyntaxError. | ||||
| 847 | if (placement == p->value()->placement()) { | ||||
| 848 | p->value()->setPrivateNameKind(PrivateNameKind::GetterSetter); | ||||
| 849 | handler_.setPrivateNameKind(nameNode, PrivateNameKind::GetterSetter); | ||||
| 850 | return true; | ||||
| 851 | } | ||||
| 852 | } | ||||
| 853 | |||||
| 854 | reportMismatchedPlacement(name, p->value()->kind(), pos, p->value()->pos()); | ||||
| 855 | return false; | ||||
| 856 | } | ||||
| 857 | |||||
| 858 | if (!scope->addDeclaredName(pc_, p, name, declKind, pos.begin, closedOver)) { | ||||
| 859 | return false; | ||||
| 860 | } | ||||
| 861 | |||||
| 862 | DeclaredNamePtr declared = scope->lookupDeclaredName(name); | ||||
| 863 | declared->value()->setPrivateNameKind(kind); | ||||
| 864 | declared->value()->setFieldPlacement(placement); | ||||
| 865 | handler_.setPrivateNameKind(nameNode, kind); | ||||
| 866 | |||||
| 867 | return true; | ||||
| 868 | } | ||||
| 869 | |||||
| 870 | bool ParserBase::noteUsedNameInternal(TaggedParserAtomIndex name, | ||||
| 871 | NameVisibility visibility, | ||||
| 872 | mozilla::Maybe<TokenPos> tokenPosition) { | ||||
| 873 | // Global bindings are properties and not actual bindings; we don't need | ||||
| 874 | // to know if they are closed over. So no need to track used name at the | ||||
| 875 | // global scope. It is not incorrect to track them, this is an | ||||
| 876 | // optimization. | ||||
| 877 | // | ||||
| 878 | // Exceptions: | ||||
| 879 | // (a) Track private name references, as the used names tracker is used to | ||||
| 880 | // provide early errors for undeclared private name references | ||||
| 881 | // (b) If the script has extra bindings, track all references to detect | ||||
| 882 | // references to extra bindings | ||||
| 883 | ParseContext::Scope* scope = pc_->innermostScope(); | ||||
| 884 | if (pc_->sc()->isGlobalContext() && scope == &pc_->varScope() && | ||||
| 885 | visibility == NameVisibility::Public && | ||||
| 886 | !this->compilationState_.input.hasExtraBindings()) { | ||||
| 887 | return true; | ||||
| 888 | } | ||||
| 889 | |||||
| 890 | return usedNames_.noteUse(fc_, name, visibility, pc_->scriptId(), scope->id(), | ||||
| 891 | tokenPosition); | ||||
| 892 | } | ||||
| 893 | |||||
| 894 | template <class ParseHandler> | ||||
| 895 | bool PerHandlerParser<ParseHandler>:: | ||||
| 896 | propagateFreeNamesAndMarkClosedOverBindings(ParseContext::Scope& scope) { | ||||
| 897 | // Now that we have all the declared names in the scope, check which | ||||
| 898 | // functions should exhibit Annex B semantics. | ||||
| 899 | if (!scope.propagateAndMarkAnnexBFunctionBoxes(pc_, this)) { | ||||
| 900 | return false; | ||||
| 901 | } | ||||
| 902 | |||||
| 903 | if (handler_.reuseClosedOverBindings()) { | ||||
| 904 | MOZ_ASSERT(pc_->isOutermostOfCurrentCompile())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isOutermostOfCurrentCompile())>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(pc_->isOutermostOfCurrentCompile()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isOutermostOfCurrentCompile()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 904); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isOutermostOfCurrentCompile()" ")" ); do { MOZ_CrashSequence(__null, 904); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 905 | |||||
| 906 | // Closed over bindings for all scopes are stored in a contiguous array, in | ||||
| 907 | // the same order as the order in which scopes are visited, and seprated by | ||||
| 908 | // TaggedParserAtomIndex::null(). | ||||
| 909 | uint32_t slotCount = scope.declaredCount(); | ||||
| 910 | while (auto parserAtom = handler_.nextLazyClosedOverBinding()) { | ||||
| 911 | scope.lookupDeclaredName(parserAtom)->value()->setClosedOver(); | ||||
| 912 | MOZ_ASSERT(slotCount > 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(slotCount > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(slotCount > 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("slotCount > 0" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 912); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "slotCount > 0" ")"); do { MOZ_CrashSequence (__null, 912); __attribute__((nomerge)) ::abort(); } while (false ); } } while (false); | ||||
| 913 | slotCount--; | ||||
| 914 | } | ||||
| 915 | |||||
| 916 | if (pc_->isGeneratorOrAsync()) { | ||||
| 917 | scope.setOwnStackSlotCount(slotCount); | ||||
| 918 | } | ||||
| 919 | return true; | ||||
| 920 | } | ||||
| 921 | |||||
| 922 | constexpr bool isSyntaxParser = | ||||
| 923 | std::is_same_v<ParseHandler, SyntaxParseHandler>; | ||||
| 924 | uint32_t scriptId = pc_->scriptId(); | ||||
| 925 | uint32_t scopeId = scope.id(); | ||||
| 926 | |||||
| 927 | uint32_t slotCount = 0; | ||||
| 928 | for (BindingIter bi = scope.bindings(pc_); bi; bi++) { | ||||
| 929 | bool closedOver = false; | ||||
| 930 | if (UsedNamePtr p = usedNames_.lookup(bi.name())) { | ||||
| 931 | p->value().noteBoundInScope(scriptId, scopeId, &closedOver); | ||||
| 932 | if (closedOver) { | ||||
| 933 | bi.setClosedOver(); | ||||
| 934 | |||||
| 935 | if constexpr (isSyntaxParser) { | ||||
| 936 | if (!pc_->closedOverBindingsForLazy().append( | ||||
| 937 | TrivialTaggedParserAtomIndex::from(bi.name()))) { | ||||
| 938 | ReportOutOfMemory(fc_); | ||||
| 939 | return false; | ||||
| 940 | } | ||||
| 941 | } | ||||
| 942 | } | ||||
| 943 | } | ||||
| 944 | |||||
| 945 | if constexpr (!isSyntaxParser) { | ||||
| 946 | if (!closedOver) { | ||||
| 947 | slotCount++; | ||||
| 948 | } | ||||
| 949 | } | ||||
| 950 | } | ||||
| 951 | if constexpr (!isSyntaxParser) { | ||||
| 952 | if (pc_->isGeneratorOrAsync()) { | ||||
| 953 | scope.setOwnStackSlotCount(slotCount); | ||||
| 954 | } | ||||
| 955 | } | ||||
| 956 | |||||
| 957 | // Append a nullptr to denote end-of-scope. | ||||
| 958 | if constexpr (isSyntaxParser) { | ||||
| 959 | if (!pc_->closedOverBindingsForLazy().append( | ||||
| 960 | TrivialTaggedParserAtomIndex::null())) { | ||||
| 961 | ReportOutOfMemory(fc_); | ||||
| 962 | return false; | ||||
| 963 | } | ||||
| 964 | } | ||||
| 965 | |||||
| 966 | return true; | ||||
| 967 | } | ||||
| 968 | |||||
| 969 | template <typename Unit> | ||||
| 970 | bool Parser<FullParseHandler, Unit>::checkStatementsEOF() { | ||||
| 971 | // This is designed to be paired with parsing a statement list at the top | ||||
| 972 | // level. | ||||
| 973 | // | ||||
| 974 | // The statementList() call breaks on TokenKind::RightCurly, so make sure | ||||
| 975 | // we've reached EOF here. | ||||
| 976 | TokenKind tt; | ||||
| 977 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 978 | return false; | ||||
| 979 | } | ||||
| 980 | if (tt != TokenKind::Eof) { | ||||
| 981 | error(JSMSG_UNEXPECTED_TOKEN, "expression", TokenKindToDesc(tt)); | ||||
| 982 | return false; | ||||
| 983 | } | ||||
| 984 | return true; | ||||
| 985 | } | ||||
| 986 | |||||
| 987 | template <typename ScopeT> | ||||
| 988 | typename ScopeT::ParserData* NewEmptyBindingData(FrontendContext* fc, | ||||
| 989 | LifoAlloc& alloc, | ||||
| 990 | uint32_t numBindings) { | ||||
| 991 | using Data = typename ScopeT::ParserData; | ||||
| 992 | size_t allocSize = SizeOfScopeData<Data>(numBindings); | ||||
| 993 | auto* bindings = alloc.newWithSize<Data>(allocSize, numBindings); | ||||
| 994 | if (!bindings) { | ||||
| 995 | ReportOutOfMemory(fc); | ||||
| 996 | } | ||||
| 997 | return bindings; | ||||
| 998 | } | ||||
| 999 | |||||
| 1000 | GlobalScope::ParserData* NewEmptyGlobalScopeData(FrontendContext* fc, | ||||
| 1001 | LifoAlloc& alloc, | ||||
| 1002 | uint32_t numBindings) { | ||||
| 1003 | return NewEmptyBindingData<GlobalScope>(fc, alloc, numBindings); | ||||
| 1004 | } | ||||
| 1005 | |||||
| 1006 | LexicalScope::ParserData* NewEmptyLexicalScopeData(FrontendContext* fc, | ||||
| 1007 | LifoAlloc& alloc, | ||||
| 1008 | uint32_t numBindings) { | ||||
| 1009 | return NewEmptyBindingData<LexicalScope>(fc, alloc, numBindings); | ||||
| 1010 | } | ||||
| 1011 | |||||
| 1012 | FunctionScope::ParserData* NewEmptyFunctionScopeData(FrontendContext* fc, | ||||
| 1013 | LifoAlloc& alloc, | ||||
| 1014 | uint32_t numBindings) { | ||||
| 1015 | return NewEmptyBindingData<FunctionScope>(fc, alloc, numBindings); | ||||
| 1016 | } | ||||
| 1017 | |||||
| 1018 | namespace detail { | ||||
| 1019 | |||||
| 1020 | template <class SlotInfo> | ||||
| 1021 | static MOZ_ALWAYS_INLINEinline ParserBindingName* InitializeIndexedBindings( | ||||
| 1022 | SlotInfo& slotInfo, ParserBindingName* start, ParserBindingName* cursor) { | ||||
| 1023 | return cursor; | ||||
| 1024 | } | ||||
| 1025 | |||||
| 1026 | template <class SlotInfo, typename UnsignedInteger, typename... Step> | ||||
| 1027 | static MOZ_ALWAYS_INLINEinline ParserBindingName* InitializeIndexedBindings( | ||||
| 1028 | SlotInfo& slotInfo, ParserBindingName* start, ParserBindingName* cursor, | ||||
| 1029 | UnsignedInteger SlotInfo::* field, const ParserBindingNameVector& bindings, | ||||
| 1030 | Step&&... step) { | ||||
| 1031 | slotInfo.*field = | ||||
| 1032 | AssertedCast<UnsignedInteger>(PointerRangeSize(start, cursor)); | ||||
| 1033 | |||||
| 1034 | ParserBindingName* newCursor = | ||||
| 1035 | std::uninitialized_copy(bindings.begin(), bindings.end(), cursor); | ||||
| 1036 | |||||
| 1037 | return InitializeIndexedBindings(slotInfo, start, newCursor, | ||||
| 1038 | std::forward<Step>(step)...); | ||||
| 1039 | } | ||||
| 1040 | |||||
| 1041 | } // namespace detail | ||||
| 1042 | |||||
| 1043 | // Initialize the trailing name bindings of |data|, then set |data->length| to | ||||
| 1044 | // the count of bindings added (which must equal |count|). | ||||
| 1045 | // | ||||
| 1046 | // First, |firstBindings| are added to the trailing names. Then any | ||||
| 1047 | // "steps" present are performed first to last. Each step is 1) a pointer to a | ||||
| 1048 | // member of |data| to be set to the current number of bindings added, and 2) a | ||||
| 1049 | // vector of |ParserBindingName|s to then copy into |data->trailingNames|. | ||||
| 1050 | // (Thus each |data| member field indicates where the corresponding vector's | ||||
| 1051 | // names start.) | ||||
| 1052 | template <class Data, typename... Step> | ||||
| 1053 | static MOZ_ALWAYS_INLINEinline void InitializeBindingData( | ||||
| 1054 | Data* data, uint32_t count, const ParserBindingNameVector& firstBindings, | ||||
| 1055 | Step&&... step) { | ||||
| 1056 | MOZ_ASSERT(data->length == 0, "data shouldn't be filled yet")do { static_assert( mozilla::detail::AssertionConditionType< decltype(data->length == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(data->length == 0))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("data->length == 0" " (" "data shouldn't be filled yet" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1056); AnnotateMozCrashReason("MOZ_ASSERT" "(" "data->length == 0" ") (" "data shouldn't be filled yet" ")"); do { MOZ_CrashSequence (__null, 1056); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 1057 | |||||
| 1058 | ParserBindingName* start = GetScopeDataTrailingNamesPointer(data); | ||||
| 1059 | ParserBindingName* cursor = std::uninitialized_copy( | ||||
| 1060 | firstBindings.begin(), firstBindings.end(), start); | ||||
| 1061 | |||||
| 1062 | #ifdef DEBUG1 | ||||
| 1063 | ParserBindingName* end = | ||||
| 1064 | #endif | ||||
| 1065 | detail::InitializeIndexedBindings(data->slotInfo, start, cursor, | ||||
| 1066 | std::forward<Step>(step)...); | ||||
| 1067 | |||||
| 1068 | MOZ_ASSERT(PointerRangeSize(start, end) == count)do { static_assert( mozilla::detail::AssertionConditionType< decltype(PointerRangeSize(start, end) == count)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(PointerRangeSize(start, end) == count))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("PointerRangeSize(start, end) == count" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1068); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "PointerRangeSize(start, end) == count" ")" ); do { MOZ_CrashSequence(__null, 1068); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 1069 | data->length = count; | ||||
| 1070 | } | ||||
| 1071 | |||||
| 1072 | static Maybe<GlobalScope::ParserData*> NewGlobalScopeData( | ||||
| 1073 | FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc, | ||||
| 1074 | ParseContext* pc) { | ||||
| 1075 | ParserBindingNameVector vars(fc); | ||||
| 1076 | ParserBindingNameVector lets(fc); | ||||
| 1077 | ParserBindingNameVector consts(fc); | ||||
| 1078 | |||||
| 1079 | bool allBindingsClosedOver = pc->sc()->allBindingsClosedOver(); | ||||
| 1080 | for (BindingIter bi = scope.bindings(pc); bi; bi++) { | ||||
| 1081 | bool closedOver = allBindingsClosedOver || bi.closedOver(); | ||||
| 1082 | |||||
| 1083 | switch (bi.kind()) { | ||||
| 1084 | case BindingKind::Var: { | ||||
| 1085 | bool isTopLevelFunction = | ||||
| 1086 | bi.declarationKind() == DeclarationKind::BodyLevelFunction; | ||||
| 1087 | |||||
| 1088 | ParserBindingName binding(bi.name(), closedOver, isTopLevelFunction); | ||||
| 1089 | if (!vars.append(binding)) { | ||||
| 1090 | return Nothing(); | ||||
| 1091 | } | ||||
| 1092 | break; | ||||
| 1093 | } | ||||
| 1094 | case BindingKind::Let: { | ||||
| 1095 | ParserBindingName binding(bi.name(), closedOver); | ||||
| 1096 | if (!lets.append(binding)) { | ||||
| 1097 | return Nothing(); | ||||
| 1098 | } | ||||
| 1099 | break; | ||||
| 1100 | } | ||||
| 1101 | case BindingKind::Const: { | ||||
| 1102 | ParserBindingName binding(bi.name(), closedOver); | ||||
| 1103 | if (!consts.append(binding)) { | ||||
| 1104 | return Nothing(); | ||||
| 1105 | } | ||||
| 1106 | break; | ||||
| 1107 | } | ||||
| 1108 | default: | ||||
| 1109 | MOZ_CRASH("Bad global scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "Bad global scope BindingKind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1109); AnnotateMozCrashReason ("MOZ_CRASH(" "Bad global scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1109); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 1110 | } | ||||
| 1111 | } | ||||
| 1112 | |||||
| 1113 | GlobalScope::ParserData* bindings = nullptr; | ||||
| 1114 | uint32_t numBindings = vars.length() + lets.length() + consts.length(); | ||||
| 1115 | |||||
| 1116 | if (numBindings > 0) { | ||||
| 1117 | bindings = NewEmptyBindingData<GlobalScope>(fc, alloc, numBindings); | ||||
| 1118 | if (!bindings) { | ||||
| 1119 | return Nothing(); | ||||
| 1120 | } | ||||
| 1121 | |||||
| 1122 | // The ordering here is important. See comments in GlobalScope. | ||||
| 1123 | InitializeBindingData(bindings, numBindings, vars, | ||||
| 1124 | &ParserGlobalScopeSlotInfo::letStart, lets, | ||||
| 1125 | &ParserGlobalScopeSlotInfo::constStart, consts); | ||||
| 1126 | } | ||||
| 1127 | |||||
| 1128 | return Some(bindings); | ||||
| 1129 | } | ||||
| 1130 | |||||
| 1131 | Maybe<GlobalScope::ParserData*> ParserBase::newGlobalScopeData( | ||||
| 1132 | ParseContext::Scope& scope) { | ||||
| 1133 | return NewGlobalScopeData(fc_, scope, stencilAlloc(), pc_); | ||||
| 1134 | } | ||||
| 1135 | |||||
| 1136 | static Maybe<ModuleScope::ParserData*> NewModuleScopeData( | ||||
| 1137 | FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc, | ||||
| 1138 | ParseContext* pc) { | ||||
| 1139 | ParserBindingNameVector imports(fc); | ||||
| 1140 | ParserBindingNameVector vars(fc); | ||||
| 1141 | ParserBindingNameVector lets(fc); | ||||
| 1142 | ParserBindingNameVector consts(fc); | ||||
| 1143 | ParserBindingNameVector usings(fc); | ||||
| 1144 | |||||
| 1145 | bool allBindingsClosedOver = | ||||
| 1146 | pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize(); | ||||
| 1147 | |||||
| 1148 | for (BindingIter bi = scope.bindings(pc); bi; bi++) { | ||||
| 1149 | // Imports are indirect bindings and must not be given known slots. | ||||
| 1150 | ParserBindingName binding(bi.name(), | ||||
| 1151 | (allBindingsClosedOver || bi.closedOver()) && | ||||
| 1152 | bi.kind() != BindingKind::Import); | ||||
| 1153 | switch (bi.kind()) { | ||||
| 1154 | case BindingKind::Import: | ||||
| 1155 | if (!imports.append(binding)) { | ||||
| 1156 | return Nothing(); | ||||
| 1157 | } | ||||
| 1158 | break; | ||||
| 1159 | case BindingKind::Var: | ||||
| 1160 | if (!vars.append(binding)) { | ||||
| 1161 | return Nothing(); | ||||
| 1162 | } | ||||
| 1163 | break; | ||||
| 1164 | case BindingKind::Let: | ||||
| 1165 | if (!lets.append(binding)) { | ||||
| 1166 | return Nothing(); | ||||
| 1167 | } | ||||
| 1168 | break; | ||||
| 1169 | case BindingKind::Const: | ||||
| 1170 | if (!consts.append(binding)) { | ||||
| 1171 | return Nothing(); | ||||
| 1172 | } | ||||
| 1173 | break; | ||||
| 1174 | case BindingKind::Using: | ||||
| 1175 | if (!usings.append(binding)) { | ||||
| 1176 | return Nothing(); | ||||
| 1177 | } | ||||
| 1178 | break; | ||||
| 1179 | default: | ||||
| 1180 | MOZ_CRASH("Bad module scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "Bad module scope BindingKind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1180); AnnotateMozCrashReason ("MOZ_CRASH(" "Bad module scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1180); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 1181 | } | ||||
| 1182 | } | ||||
| 1183 | |||||
| 1184 | ModuleScope::ParserData* bindings = nullptr; | ||||
| 1185 | uint32_t numBindings = imports.length() + vars.length() + lets.length() + | ||||
| 1186 | consts.length() + usings.length(); | ||||
| 1187 | |||||
| 1188 | if (numBindings > 0) { | ||||
| 1189 | bindings = NewEmptyBindingData<ModuleScope>(fc, alloc, numBindings); | ||||
| 1190 | if (!bindings) { | ||||
| 1191 | return Nothing(); | ||||
| 1192 | } | ||||
| 1193 | |||||
| 1194 | // The ordering here is important. See comments in ModuleScope. | ||||
| 1195 | InitializeBindingData(bindings, numBindings, imports, | ||||
| 1196 | &ParserModuleScopeSlotInfo::varStart, vars, | ||||
| 1197 | &ParserModuleScopeSlotInfo::letStart, lets, | ||||
| 1198 | &ParserModuleScopeSlotInfo::constStart, consts, | ||||
| 1199 | &ParserModuleScopeSlotInfo::usingStart, usings); | ||||
| 1200 | } | ||||
| 1201 | |||||
| 1202 | return Some(bindings); | ||||
| 1203 | } | ||||
| 1204 | |||||
| 1205 | Maybe<ModuleScope::ParserData*> ParserBase::newModuleScopeData( | ||||
| 1206 | ParseContext::Scope& scope) { | ||||
| 1207 | return NewModuleScopeData(fc_, scope, stencilAlloc(), pc_); | ||||
| 1208 | } | ||||
| 1209 | |||||
| 1210 | static Maybe<EvalScope::ParserData*> NewEvalScopeData( | ||||
| 1211 | FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc, | ||||
| 1212 | ParseContext* pc) { | ||||
| 1213 | ParserBindingNameVector vars(fc); | ||||
| 1214 | |||||
| 1215 | // Treat all bindings as closed over in non-strict eval. | ||||
| 1216 | bool allBindingsClosedOver = | ||||
| 1217 | !pc->sc()->strict() || pc->sc()->allBindingsClosedOver(); | ||||
| 1218 | for (BindingIter bi = scope.bindings(pc); bi; bi++) { | ||||
| 1219 | // Eval scopes only contain 'var' bindings. | ||||
| 1220 | MOZ_ASSERT(bi.kind() == BindingKind::Var)do { static_assert( mozilla::detail::AssertionConditionType< decltype(bi.kind() == BindingKind::Var)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(bi.kind() == BindingKind::Var ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "bi.kind() == BindingKind::Var", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1220); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Var" ")"); do { MOZ_CrashSequence(__null, 1220); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 1221 | bool isTopLevelFunction = | ||||
| 1222 | bi.declarationKind() == DeclarationKind::BodyLevelFunction; | ||||
| 1223 | bool closedOver = allBindingsClosedOver || bi.closedOver(); | ||||
| 1224 | |||||
| 1225 | ParserBindingName binding(bi.name(), closedOver, isTopLevelFunction); | ||||
| 1226 | if (!vars.append(binding)) { | ||||
| 1227 | return Nothing(); | ||||
| 1228 | } | ||||
| 1229 | } | ||||
| 1230 | |||||
| 1231 | EvalScope::ParserData* bindings = nullptr; | ||||
| 1232 | uint32_t numBindings = vars.length(); | ||||
| 1233 | |||||
| 1234 | if (numBindings > 0) { | ||||
| 1235 | bindings = NewEmptyBindingData<EvalScope>(fc, alloc, numBindings); | ||||
| 1236 | if (!bindings) { | ||||
| 1237 | return Nothing(); | ||||
| 1238 | } | ||||
| 1239 | |||||
| 1240 | InitializeBindingData(bindings, numBindings, vars); | ||||
| 1241 | } | ||||
| 1242 | |||||
| 1243 | return Some(bindings); | ||||
| 1244 | } | ||||
| 1245 | |||||
| 1246 | Maybe<EvalScope::ParserData*> ParserBase::newEvalScopeData( | ||||
| 1247 | ParseContext::Scope& scope) { | ||||
| 1248 | return NewEvalScopeData(fc_, scope, stencilAlloc(), pc_); | ||||
| 1249 | } | ||||
| 1250 | |||||
| 1251 | Maybe<FunctionScope::ParserData*> ParserBase::newFunctionScopeData( | ||||
| 1252 | ParseContext::Scope& scope, bool hasParameterExprs) { | ||||
| 1253 | ParserBindingNameVector positionalFormals(fc_); | ||||
| 1254 | ParserBindingNameVector formals(fc_); | ||||
| 1255 | ParserBindingNameVector vars(fc_); | ||||
| 1256 | |||||
| 1257 | bool allBindingsClosedOver = | ||||
| 1258 | pc_->sc()->allBindingsClosedOver() || scope.tooBigToOptimize(); | ||||
| 1259 | bool argumentBindingsClosedOver = | ||||
| 1260 | allBindingsClosedOver || pc_->isGeneratorOrAsync(); | ||||
| 1261 | bool hasDuplicateParams = pc_->functionBox()->hasDuplicateParameters; | ||||
| 1262 | |||||
| 1263 | // Positional parameter names must be added in order of appearance as they are | ||||
| 1264 | // referenced using argument slots. | ||||
| 1265 | for (size_t i = 0; i < pc_->positionalFormalParameterNames().length(); i++) { | ||||
| 1266 | TaggedParserAtomIndex name = pc_->positionalFormalParameterNames()[i]; | ||||
| 1267 | |||||
| 1268 | ParserBindingName bindName; | ||||
| 1269 | if (name) { | ||||
| 1270 | DeclaredNamePtr p = scope.lookupDeclaredName(name); | ||||
| 1271 | |||||
| 1272 | // Do not consider any positional formal parameters closed over if | ||||
| 1273 | // there are parameter defaults. It is the binding in the defaults | ||||
| 1274 | // scope that is closed over instead. | ||||
| 1275 | bool closedOver = | ||||
| 1276 | argumentBindingsClosedOver || (p && p->value()->closedOver()); | ||||
| 1277 | |||||
| 1278 | // If the parameter name has duplicates, only the final parameter | ||||
| 1279 | // name should be on the environment, as otherwise the environment | ||||
| 1280 | // object would have multiple, same-named properties. | ||||
| 1281 | if (hasDuplicateParams) { | ||||
| 1282 | for (size_t j = pc_->positionalFormalParameterNames().length() - 1; | ||||
| 1283 | j > i; j--) { | ||||
| 1284 | if (TaggedParserAtomIndex(pc_->positionalFormalParameterNames()[j]) == | ||||
| 1285 | name) { | ||||
| 1286 | closedOver = false; | ||||
| 1287 | break; | ||||
| 1288 | } | ||||
| 1289 | } | ||||
| 1290 | } | ||||
| 1291 | |||||
| 1292 | bindName = ParserBindingName(name, closedOver); | ||||
| 1293 | } | ||||
| 1294 | |||||
| 1295 | if (!positionalFormals.append(bindName)) { | ||||
| 1296 | return Nothing(); | ||||
| 1297 | } | ||||
| 1298 | } | ||||
| 1299 | |||||
| 1300 | for (BindingIter bi = scope.bindings(pc_); bi; bi++) { | ||||
| 1301 | ParserBindingName binding(bi.name(), | ||||
| 1302 | allBindingsClosedOver || bi.closedOver()); | ||||
| 1303 | switch (bi.kind()) { | ||||
| 1304 | case BindingKind::FormalParameter: | ||||
| 1305 | // Positional parameter names are already handled above. | ||||
| 1306 | if (bi.declarationKind() == DeclarationKind::FormalParameter) { | ||||
| 1307 | if (!formals.append(binding)) { | ||||
| 1308 | return Nothing(); | ||||
| 1309 | } | ||||
| 1310 | } | ||||
| 1311 | break; | ||||
| 1312 | case BindingKind::Var: | ||||
| 1313 | // The only vars in the function scope when there are parameter | ||||
| 1314 | // exprs, which induces a separate var environment, should be the | ||||
| 1315 | // special bindings. | ||||
| 1316 | MOZ_ASSERT_IF(hasParameterExprs,do { if (hasParameterExprs) { do { static_assert( mozilla::detail ::AssertionConditionType<decltype(FunctionScope::isSpecialName (bi.name()))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(FunctionScope::isSpecialName(bi.name ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("FunctionScope::isSpecialName(bi.name())", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1317); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FunctionScope::isSpecialName(bi.name())" ")"); do { MOZ_CrashSequence(__null, 1317); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 1317 | FunctionScope::isSpecialName(bi.name()))do { if (hasParameterExprs) { do { static_assert( mozilla::detail ::AssertionConditionType<decltype(FunctionScope::isSpecialName (bi.name()))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(FunctionScope::isSpecialName(bi.name ())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("FunctionScope::isSpecialName(bi.name())", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1317); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FunctionScope::isSpecialName(bi.name())" ")"); do { MOZ_CrashSequence(__null, 1317); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 1318 | if (!vars.append(binding)) { | ||||
| 1319 | return Nothing(); | ||||
| 1320 | } | ||||
| 1321 | break; | ||||
| 1322 | case BindingKind::Let: | ||||
| 1323 | case BindingKind::Const: | ||||
| 1324 | case BindingKind::Using: | ||||
| 1325 | break; | ||||
| 1326 | default: | ||||
| 1327 | MOZ_CRASH("bad function scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "bad function scope BindingKind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1327); AnnotateMozCrashReason ("MOZ_CRASH(" "bad function scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1327); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 1328 | break; | ||||
| 1329 | } | ||||
| 1330 | } | ||||
| 1331 | |||||
| 1332 | // This should already be checked by GeneralParser::functionArguments. | ||||
| 1333 | MOZ_ASSERT(positionalFormals.length() <= UINT16_MAX)do { static_assert( mozilla::detail::AssertionConditionType< decltype(positionalFormals.length() <= (65535))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(positionalFormals.length() <= (65535)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("positionalFormals.length() <= (65535)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1333); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "positionalFormals.length() <= (65535)" ")" ); do { MOZ_CrashSequence(__null, 1333); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 1334 | |||||
| 1335 | if (positionalFormals.length() + formals.length() > UINT16_MAX(65535)) { | ||||
| 1336 | error(JSMSG_TOO_MANY_FUN_ARGS); | ||||
| 1337 | return Nothing(); | ||||
| 1338 | } | ||||
| 1339 | |||||
| 1340 | FunctionScope::ParserData* bindings = nullptr; | ||||
| 1341 | uint32_t numBindings = | ||||
| 1342 | positionalFormals.length() + formals.length() + vars.length(); | ||||
| 1343 | |||||
| 1344 | if (numBindings > 0) { | ||||
| 1345 | bindings = | ||||
| 1346 | NewEmptyBindingData<FunctionScope>(fc_, stencilAlloc(), numBindings); | ||||
| 1347 | if (!bindings) { | ||||
| 1348 | return Nothing(); | ||||
| 1349 | } | ||||
| 1350 | |||||
| 1351 | // The ordering here is important. See comments in FunctionScope. | ||||
| 1352 | InitializeBindingData( | ||||
| 1353 | bindings, numBindings, positionalFormals, | ||||
| 1354 | &ParserFunctionScopeSlotInfo::nonPositionalFormalStart, formals, | ||||
| 1355 | &ParserFunctionScopeSlotInfo::varStart, vars); | ||||
| 1356 | } | ||||
| 1357 | |||||
| 1358 | return Some(bindings); | ||||
| 1359 | } | ||||
| 1360 | |||||
| 1361 | // Compute if `newFunctionScopeData` would return any binding list with any | ||||
| 1362 | // entry marked as closed-over. This is done without the need to allocate the | ||||
| 1363 | // binding list. If true, an EnvironmentObject will be needed at runtime. | ||||
| 1364 | bool FunctionScopeHasClosedOverBindings(ParseContext* pc) { | ||||
| 1365 | bool allBindingsClosedOver = pc->sc()->allBindingsClosedOver() || | ||||
| 1366 | pc->functionScope().tooBigToOptimize(); | ||||
| 1367 | |||||
| 1368 | for (BindingIter bi = pc->functionScope().bindings(pc); bi; bi++) { | ||||
| 1369 | switch (bi.kind()) { | ||||
| 1370 | case BindingKind::FormalParameter: | ||||
| 1371 | case BindingKind::Var: | ||||
| 1372 | if (allBindingsClosedOver || bi.closedOver()) { | ||||
| 1373 | return true; | ||||
| 1374 | } | ||||
| 1375 | break; | ||||
| 1376 | |||||
| 1377 | default: | ||||
| 1378 | break; | ||||
| 1379 | } | ||||
| 1380 | } | ||||
| 1381 | |||||
| 1382 | return false; | ||||
| 1383 | } | ||||
| 1384 | |||||
| 1385 | VarScope::ParserData* NewEmptyVarScopeData(FrontendContext* fc, | ||||
| 1386 | LifoAlloc& alloc, | ||||
| 1387 | uint32_t numBindings) { | ||||
| 1388 | return NewEmptyBindingData<VarScope>(fc, alloc, numBindings); | ||||
| 1389 | } | ||||
| 1390 | |||||
| 1391 | static Maybe<VarScope::ParserData*> NewVarScopeData(FrontendContext* fc, | ||||
| 1392 | ParseContext::Scope& scope, | ||||
| 1393 | LifoAlloc& alloc, | ||||
| 1394 | ParseContext* pc) { | ||||
| 1395 | ParserBindingNameVector vars(fc); | ||||
| 1396 | |||||
| 1397 | bool allBindingsClosedOver = | ||||
| 1398 | pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize(); | ||||
| 1399 | |||||
| 1400 | for (BindingIter bi = scope.bindings(pc); bi; bi++) { | ||||
| 1401 | if (bi.kind() == BindingKind::Var) { | ||||
| 1402 | ParserBindingName binding(bi.name(), | ||||
| 1403 | allBindingsClosedOver || bi.closedOver()); | ||||
| 1404 | if (!vars.append(binding)) { | ||||
| 1405 | return Nothing(); | ||||
| 1406 | } | ||||
| 1407 | } else { | ||||
| 1408 | MOZ_ASSERT(bi.kind() == BindingKind::Let ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(bi.kind() == BindingKind::Let || bi.kind() == BindingKind ::Const || bi.kind() == BindingKind::Using)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind ::Using))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" " (" "bad var scope BindingKind" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" ") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1411); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false) | ||||
| 1409 | bi.kind() == BindingKind::Const ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(bi.kind() == BindingKind::Let || bi.kind() == BindingKind ::Const || bi.kind() == BindingKind::Using)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind ::Using))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" " (" "bad var scope BindingKind" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" ") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1411); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false) | ||||
| 1410 | bi.kind() == BindingKind::Using,do { static_assert( mozilla::detail::AssertionConditionType< decltype(bi.kind() == BindingKind::Let || bi.kind() == BindingKind ::Const || bi.kind() == BindingKind::Using)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind ::Using))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" " (" "bad var scope BindingKind" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" ") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1411); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false) | ||||
| 1411 | "bad var scope BindingKind")do { static_assert( mozilla::detail::AssertionConditionType< decltype(bi.kind() == BindingKind::Let || bi.kind() == BindingKind ::Const || bi.kind() == BindingKind::Using)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind ::Using))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" " (" "bad var scope BindingKind" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using" ") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1411); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 1412 | } | ||||
| 1413 | } | ||||
| 1414 | |||||
| 1415 | VarScope::ParserData* bindings = nullptr; | ||||
| 1416 | uint32_t numBindings = vars.length(); | ||||
| 1417 | |||||
| 1418 | if (numBindings > 0) { | ||||
| 1419 | bindings = NewEmptyBindingData<VarScope>(fc, alloc, numBindings); | ||||
| 1420 | if (!bindings) { | ||||
| 1421 | return Nothing(); | ||||
| 1422 | } | ||||
| 1423 | |||||
| 1424 | InitializeBindingData(bindings, numBindings, vars); | ||||
| 1425 | } | ||||
| 1426 | |||||
| 1427 | return Some(bindings); | ||||
| 1428 | } | ||||
| 1429 | |||||
| 1430 | // Compute if `NewVarScopeData` would return any binding list. This is done | ||||
| 1431 | // without allocate the binding list. | ||||
| 1432 | static bool VarScopeHasBindings(ParseContext* pc) { | ||||
| 1433 | for (BindingIter bi = pc->varScope().bindings(pc); bi; bi++) { | ||||
| 1434 | if (bi.kind() == BindingKind::Var) { | ||||
| 1435 | return true; | ||||
| 1436 | } | ||||
| 1437 | } | ||||
| 1438 | |||||
| 1439 | return false; | ||||
| 1440 | } | ||||
| 1441 | |||||
| 1442 | Maybe<VarScope::ParserData*> ParserBase::newVarScopeData( | ||||
| 1443 | ParseContext::Scope& scope) { | ||||
| 1444 | return NewVarScopeData(fc_, scope, stencilAlloc(), pc_); | ||||
| 1445 | } | ||||
| 1446 | |||||
| 1447 | static Maybe<LexicalScope::ParserData*> NewLexicalScopeData( | ||||
| 1448 | FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc, | ||||
| 1449 | ParseContext* pc) { | ||||
| 1450 | ParserBindingNameVector lets(fc); | ||||
| 1451 | ParserBindingNameVector consts(fc); | ||||
| 1452 | ParserBindingNameVector usings(fc); | ||||
| 1453 | |||||
| 1454 | bool allBindingsClosedOver = | ||||
| 1455 | pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize(); | ||||
| 1456 | |||||
| 1457 | for (BindingIter bi = scope.bindings(pc); bi; bi++) { | ||||
| 1458 | ParserBindingName binding(bi.name(), | ||||
| 1459 | allBindingsClosedOver || bi.closedOver()); | ||||
| 1460 | switch (bi.kind()) { | ||||
| 1461 | case BindingKind::Let: | ||||
| 1462 | if (!lets.append(binding)) { | ||||
| 1463 | return Nothing(); | ||||
| 1464 | } | ||||
| 1465 | break; | ||||
| 1466 | case BindingKind::Const: | ||||
| 1467 | if (!consts.append(binding)) { | ||||
| 1468 | return Nothing(); | ||||
| 1469 | } | ||||
| 1470 | break; | ||||
| 1471 | case BindingKind::Using: | ||||
| 1472 | if (!usings.append(binding)) { | ||||
| 1473 | return Nothing(); | ||||
| 1474 | } | ||||
| 1475 | break; | ||||
| 1476 | case BindingKind::Var: | ||||
| 1477 | case BindingKind::FormalParameter: | ||||
| 1478 | break; | ||||
| 1479 | default: | ||||
| 1480 | MOZ_CRASH("Bad lexical scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "Bad lexical scope BindingKind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1480); AnnotateMozCrashReason ("MOZ_CRASH(" "Bad lexical scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1480); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 1481 | break; | ||||
| 1482 | } | ||||
| 1483 | } | ||||
| 1484 | |||||
| 1485 | LexicalScope::ParserData* bindings = nullptr; | ||||
| 1486 | uint32_t numBindings = lets.length() + consts.length() + usings.length(); | ||||
| 1487 | |||||
| 1488 | if (numBindings > 0) { | ||||
| 1489 | bindings = NewEmptyBindingData<LexicalScope>(fc, alloc, numBindings); | ||||
| 1490 | if (!bindings) { | ||||
| 1491 | return Nothing(); | ||||
| 1492 | } | ||||
| 1493 | |||||
| 1494 | // The ordering here is important. See comments in LexicalScope. | ||||
| 1495 | InitializeBindingData(bindings, numBindings, lets, | ||||
| 1496 | &ParserLexicalScopeSlotInfo::constStart, consts, | ||||
| 1497 | &ParserLexicalScopeSlotInfo::usingStart, usings); | ||||
| 1498 | } | ||||
| 1499 | |||||
| 1500 | return Some(bindings); | ||||
| 1501 | } | ||||
| 1502 | |||||
| 1503 | // Compute if `NewLexicalScopeData` would return any binding list with any entry | ||||
| 1504 | // marked as closed-over. This is done without the need to allocate the binding | ||||
| 1505 | // list. If true, an EnvironmentObject will be needed at runtime. | ||||
| 1506 | bool LexicalScopeHasClosedOverBindings(ParseContext* pc, | ||||
| 1507 | ParseContext::Scope& scope) { | ||||
| 1508 | bool allBindingsClosedOver = | ||||
| 1509 | pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize(); | ||||
| 1510 | |||||
| 1511 | for (BindingIter bi = scope.bindings(pc); bi; bi++) { | ||||
| 1512 | switch (bi.kind()) { | ||||
| 1513 | case BindingKind::Let: | ||||
| 1514 | case BindingKind::Const: | ||||
| 1515 | case BindingKind::Using: | ||||
| 1516 | if (allBindingsClosedOver || bi.closedOver()) { | ||||
| 1517 | return true; | ||||
| 1518 | } | ||||
| 1519 | break; | ||||
| 1520 | |||||
| 1521 | default: | ||||
| 1522 | break; | ||||
| 1523 | } | ||||
| 1524 | } | ||||
| 1525 | |||||
| 1526 | return false; | ||||
| 1527 | } | ||||
| 1528 | |||||
| 1529 | Maybe<LexicalScope::ParserData*> ParserBase::newLexicalScopeData( | ||||
| 1530 | ParseContext::Scope& scope) { | ||||
| 1531 | return NewLexicalScopeData(fc_, scope, stencilAlloc(), pc_); | ||||
| 1532 | } | ||||
| 1533 | |||||
| 1534 | static Maybe<ClassBodyScope::ParserData*> NewClassBodyScopeData( | ||||
| 1535 | FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc, | ||||
| 1536 | ParseContext* pc) { | ||||
| 1537 | ParserBindingNameVector privateBrand(fc); | ||||
| 1538 | ParserBindingNameVector synthetics(fc); | ||||
| 1539 | ParserBindingNameVector privateMethods(fc); | ||||
| 1540 | |||||
| 1541 | bool allBindingsClosedOver = | ||||
| 1542 | pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize(); | ||||
| 1543 | |||||
| 1544 | for (BindingIter bi = scope.bindings(pc); bi; bi++) { | ||||
| 1545 | ParserBindingName binding(bi.name(), | ||||
| 1546 | allBindingsClosedOver || bi.closedOver()); | ||||
| 1547 | switch (bi.kind()) { | ||||
| 1548 | case BindingKind::Synthetic: | ||||
| 1549 | if (bi.name() == | ||||
| 1550 | TaggedParserAtomIndex::WellKnown::dot_privateBrand_()) { | ||||
| 1551 | MOZ_ASSERT(privateBrand.empty())do { static_assert( mozilla::detail::AssertionConditionType< decltype(privateBrand.empty())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(privateBrand.empty()))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("privateBrand.empty()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1551); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "privateBrand.empty()" ")"); do { MOZ_CrashSequence (__null, 1551); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 1552 | if (!privateBrand.append(binding)) { | ||||
| 1553 | return Nothing(); | ||||
| 1554 | } | ||||
| 1555 | } else { | ||||
| 1556 | if (!synthetics.append(binding)) { | ||||
| 1557 | return Nothing(); | ||||
| 1558 | } | ||||
| 1559 | } | ||||
| 1560 | break; | ||||
| 1561 | |||||
| 1562 | case BindingKind::PrivateMethod: | ||||
| 1563 | if (!privateMethods.append(binding)) { | ||||
| 1564 | return Nothing(); | ||||
| 1565 | } | ||||
| 1566 | break; | ||||
| 1567 | |||||
| 1568 | default: | ||||
| 1569 | MOZ_CRASH("bad class body scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "bad class body scope BindingKind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1569); AnnotateMozCrashReason ("MOZ_CRASH(" "bad class body scope BindingKind" ")"); do { MOZ_CrashSequence (__null, 1569); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 1570 | break; | ||||
| 1571 | } | ||||
| 1572 | } | ||||
| 1573 | |||||
| 1574 | // We should have zero or one private brands. | ||||
| 1575 | MOZ_ASSERT(privateBrand.length() == 0 || privateBrand.length() == 1)do { static_assert( mozilla::detail::AssertionConditionType< decltype(privateBrand.length() == 0 || privateBrand.length() == 1)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(privateBrand.length() == 0 || privateBrand.length() == 1))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("privateBrand.length() == 0 || privateBrand.length() == 1", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1575); AnnotateMozCrashReason("MOZ_ASSERT" "(" "privateBrand.length() == 0 || privateBrand.length() == 1" ")"); do { MOZ_CrashSequence(__null, 1575); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 1576 | |||||
| 1577 | ClassBodyScope::ParserData* bindings = nullptr; | ||||
| 1578 | uint32_t numBindings = | ||||
| 1579 | privateBrand.length() + synthetics.length() + privateMethods.length(); | ||||
| 1580 | |||||
| 1581 | if (numBindings > 0) { | ||||
| 1582 | bindings = NewEmptyBindingData<ClassBodyScope>(fc, alloc, numBindings); | ||||
| 1583 | if (!bindings) { | ||||
| 1584 | return Nothing(); | ||||
| 1585 | } | ||||
| 1586 | // To simplify initialization of the bindings, we concatenate the | ||||
| 1587 | // synthetics+privateBrand vector such that the private brand is always the | ||||
| 1588 | // first element, as ordering is important. See comments in ClassBodyScope. | ||||
| 1589 | ParserBindingNameVector brandAndSynthetics(fc); | ||||
| 1590 | if (!brandAndSynthetics.appendAll(privateBrand)) { | ||||
| 1591 | return Nothing(); | ||||
| 1592 | } | ||||
| 1593 | if (!brandAndSynthetics.appendAll(synthetics)) { | ||||
| 1594 | return Nothing(); | ||||
| 1595 | } | ||||
| 1596 | |||||
| 1597 | // The ordering here is important. See comments in ClassBodyScope. | ||||
| 1598 | InitializeBindingData(bindings, numBindings, brandAndSynthetics, | ||||
| 1599 | &ParserClassBodyScopeSlotInfo::privateMethodStart, | ||||
| 1600 | privateMethods); | ||||
| 1601 | } | ||||
| 1602 | |||||
| 1603 | // `EmitterScope::lookupPrivate()` requires `.privateBrand` to be stored in a | ||||
| 1604 | // predictable slot: the first slot available in the environment object, | ||||
| 1605 | // `ClassBodyLexicalEnvironmentObject::privateBrandSlot()`. We assume that | ||||
| 1606 | // if `.privateBrand` is first in the scope, it will be stored there. | ||||
| 1607 | MOZ_ASSERT_IF(!privateBrand.empty(),do { if (!privateBrand.empty()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(GetScopeDataTrailingNames (bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_ ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex ::WellKnown::dot_privateBrand_()))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1609); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()" ")"); do { MOZ_CrashSequence(__null, 1609); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 1608 | GetScopeDataTrailingNames(bindings)[0].name() ==do { if (!privateBrand.empty()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(GetScopeDataTrailingNames (bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_ ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex ::WellKnown::dot_privateBrand_()))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1609); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()" ")"); do { MOZ_CrashSequence(__null, 1609); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 1609 | TaggedParserAtomIndex::WellKnown::dot_privateBrand_())do { if (!privateBrand.empty()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(GetScopeDataTrailingNames (bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_ ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex ::WellKnown::dot_privateBrand_()))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1609); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()" ")"); do { MOZ_CrashSequence(__null, 1609); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 1610 | |||||
| 1611 | return Some(bindings); | ||||
| 1612 | } | ||||
| 1613 | |||||
| 1614 | Maybe<ClassBodyScope::ParserData*> ParserBase::newClassBodyScopeData( | ||||
| 1615 | ParseContext::Scope& scope) { | ||||
| 1616 | return NewClassBodyScopeData(fc_, scope, stencilAlloc(), pc_); | ||||
| 1617 | } | ||||
| 1618 | |||||
| 1619 | template <> | ||||
| 1620 | SyntaxParseHandler::LexicalScopeNodeResult | ||||
| 1621 | PerHandlerParser<SyntaxParseHandler>::finishLexicalScope( | ||||
| 1622 | ParseContext::Scope& scope, Node body, ScopeKind kind) { | ||||
| 1623 | if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) { | ||||
| 1624 | return errorResult(); | ||||
| 1625 | } | ||||
| 1626 | |||||
| 1627 | return handler_.newLexicalScope(body); | ||||
| 1628 | } | ||||
| 1629 | |||||
| 1630 | template <> | ||||
| 1631 | FullParseHandler::LexicalScopeNodeResult | ||||
| 1632 | PerHandlerParser<FullParseHandler>::finishLexicalScope( | ||||
| 1633 | ParseContext::Scope& scope, ParseNode* body, ScopeKind kind) { | ||||
| 1634 | if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) { | ||||
| 1635 | return errorResult(); | ||||
| 1636 | } | ||||
| 1637 | |||||
| 1638 | Maybe<LexicalScope::ParserData*> bindings = newLexicalScopeData(scope); | ||||
| 1639 | if (!bindings) { | ||||
| 1640 | return errorResult(); | ||||
| 1641 | } | ||||
| 1642 | |||||
| 1643 | return handler_.newLexicalScope(*bindings, body, kind); | ||||
| 1644 | } | ||||
| 1645 | |||||
| 1646 | template <> | ||||
| 1647 | SyntaxParseHandler::ClassBodyScopeNodeResult | ||||
| 1648 | PerHandlerParser<SyntaxParseHandler>::finishClassBodyScope( | ||||
| 1649 | ParseContext::Scope& scope, ListNodeType body) { | ||||
| 1650 | if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) { | ||||
| 1651 | return errorResult(); | ||||
| 1652 | } | ||||
| 1653 | |||||
| 1654 | return handler_.newClassBodyScope(body); | ||||
| 1655 | } | ||||
| 1656 | |||||
| 1657 | template <> | ||||
| 1658 | FullParseHandler::ClassBodyScopeNodeResult | ||||
| 1659 | PerHandlerParser<FullParseHandler>::finishClassBodyScope( | ||||
| 1660 | ParseContext::Scope& scope, ListNode* body) { | ||||
| 1661 | if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) { | ||||
| 1662 | return errorResult(); | ||||
| 1663 | } | ||||
| 1664 | |||||
| 1665 | Maybe<ClassBodyScope::ParserData*> bindings = newClassBodyScopeData(scope); | ||||
| 1666 | if (!bindings) { | ||||
| 1667 | return errorResult(); | ||||
| 1668 | } | ||||
| 1669 | |||||
| 1670 | return handler_.newClassBodyScope(*bindings, body); | ||||
| 1671 | } | ||||
| 1672 | |||||
| 1673 | template <class ParseHandler> | ||||
| 1674 | bool PerHandlerParser<ParseHandler>::checkForUndefinedPrivateFields( | ||||
| 1675 | EvalSharedContext* evalSc) { | ||||
| 1676 | if (!this->compilationState_.isInitialStencil()) { | ||||
| 1677 | // We're delazifying -- so we already checked private names during first | ||||
| 1678 | // parse. | ||||
| 1679 | return true; | ||||
| 1680 | } | ||||
| 1681 | |||||
| 1682 | Vector<UnboundPrivateName, 8> unboundPrivateNames(fc_); | ||||
| 1683 | if (!usedNames_.getUnboundPrivateNames(unboundPrivateNames)) { | ||||
| 1684 | return false; | ||||
| 1685 | } | ||||
| 1686 | |||||
| 1687 | // No unbound names, let's get out of here! | ||||
| 1688 | if (unboundPrivateNames.empty()) { | ||||
| 1689 | return true; | ||||
| 1690 | } | ||||
| 1691 | |||||
| 1692 | // It is an early error if there's private name references unbound, | ||||
| 1693 | // unless it's an eval, in which case we need to check the scope | ||||
| 1694 | // chain. | ||||
| 1695 | if (!evalSc) { | ||||
| 1696 | // The unbound private names are sorted, so just grab the first one. | ||||
| 1697 | UnboundPrivateName minimum = unboundPrivateNames[0]; | ||||
| 1698 | UniqueChars str = this->parserAtoms().toPrintableString(minimum.atom); | ||||
| 1699 | if (!str) { | ||||
| 1700 | ReportOutOfMemory(this->fc_); | ||||
| 1701 | return false; | ||||
| 1702 | } | ||||
| 1703 | |||||
| 1704 | errorAt(minimum.position.begin, JSMSG_MISSING_PRIVATE_DECL, str.get()); | ||||
| 1705 | return false; | ||||
| 1706 | } | ||||
| 1707 | |||||
| 1708 | // It's important that the unbound private names are sorted, as we | ||||
| 1709 | // want our errors to always be issued to the first textually. | ||||
| 1710 | for (UnboundPrivateName unboundName : unboundPrivateNames) { | ||||
| 1711 | // If the enclosingScope is non-syntactic, then we are in a | ||||
| 1712 | // Debugger.Frame.prototype.eval call. In order to find the declared private | ||||
| 1713 | // names, we must use the effective scope that was determined when creating | ||||
| 1714 | // the scopeContext. | ||||
| 1715 | if (!this->compilationState_.scopeContext | ||||
| 1716 | .effectiveScopePrivateFieldCacheHas(unboundName.atom)) { | ||||
| 1717 | UniqueChars str = this->parserAtoms().toPrintableString(unboundName.atom); | ||||
| 1718 | if (!str) { | ||||
| 1719 | ReportOutOfMemory(this->fc_); | ||||
| 1720 | return false; | ||||
| 1721 | } | ||||
| 1722 | errorAt(unboundName.position.begin, JSMSG_MISSING_PRIVATE_DECL, | ||||
| 1723 | str.get()); | ||||
| 1724 | return false; | ||||
| 1725 | } | ||||
| 1726 | } | ||||
| 1727 | |||||
| 1728 | return true; | ||||
| 1729 | } | ||||
| 1730 | |||||
| 1731 | template <typename Unit> | ||||
| 1732 | FullParseHandler::LexicalScopeNodeResult | ||||
| 1733 | Parser<FullParseHandler, Unit>::evalBody(EvalSharedContext* evalsc) { | ||||
| 1734 | SourceParseContext evalpc(this, evalsc, /* newDirectives = */ nullptr); | ||||
| 1735 | if (!evalpc.init()) { | ||||
| 1736 | return errorResult(); | ||||
| 1737 | } | ||||
| 1738 | |||||
| 1739 | ParseContext::VarScope varScope(this); | ||||
| 1740 | if (!varScope.init(pc_)) { | ||||
| 1741 | return errorResult(); | ||||
| 1742 | } | ||||
| 1743 | |||||
| 1744 | LexicalScopeNode* body; | ||||
| 1745 | { | ||||
| 1746 | // All evals have an implicit non-extensible lexical scope. | ||||
| 1747 | ParseContext::Scope lexicalScope(this); | ||||
| 1748 | if (!lexicalScope.init(pc_)) { | ||||
| 1749 | return errorResult(); | ||||
| 1750 | } | ||||
| 1751 | |||||
| 1752 | ListNode* list = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 1753 | |||||
| 1754 | if (!checkStatementsEOF()) { | ||||
| 1755 | return errorResult(); | ||||
| 1756 | } | ||||
| 1757 | |||||
| 1758 | // Private names not lexically defined must trigger a syntax error. | ||||
| 1759 | if (!checkForUndefinedPrivateFields(evalsc)) { | ||||
| 1760 | return errorResult(); | ||||
| 1761 | } | ||||
| 1762 | |||||
| 1763 | body = MOZ_TRY(finishLexicalScope(lexicalScope, list))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope(lexicalScope, list)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 1764 | } | ||||
| 1765 | |||||
| 1766 | #ifdef DEBUG1 | ||||
| 1767 | if (evalpc.superScopeNeedsHomeObject() && | ||||
| 1768 | !this->compilationState_.input.enclosingScope.isNull()) { | ||||
| 1769 | // If superScopeNeedsHomeObject_ is set and we are an entry-point | ||||
| 1770 | // ParseContext, then we must be emitting an eval script, and the | ||||
| 1771 | // outer function must already be marked as needing a home object | ||||
| 1772 | // since it contains an eval. | ||||
| 1773 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" " (" "Eval must have found an enclosing function box scope that " "allows super.property" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1776); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" ") (" "Eval must have found an enclosing function box scope that " "allows super.property" ")"); do { MOZ_CrashSequence(__null, 1776); __attribute__((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 1774 | this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain,do { static_assert( mozilla::detail::AssertionConditionType< decltype(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" " (" "Eval must have found an enclosing function box scope that " "allows super.property" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1776); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" ") (" "Eval must have found an enclosing function box scope that " "allows super.property" ")"); do { MOZ_CrashSequence(__null, 1776); __attribute__((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 1775 | "Eval must have found an enclosing function box scope that "do { static_assert( mozilla::detail::AssertionConditionType< decltype(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" " (" "Eval must have found an enclosing function box scope that " "allows super.property" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1776); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" ") (" "Eval must have found an enclosing function box scope that " "allows super.property" ")"); do { MOZ_CrashSequence(__null, 1776); __attribute__((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 1776 | "allows super.property")do { static_assert( mozilla::detail::AssertionConditionType< decltype(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" " (" "Eval must have found an enclosing function box scope that " "allows super.property" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 1776); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain" ") (" "Eval must have found an enclosing function box scope that " "allows super.property" ")"); do { MOZ_CrashSequence(__null, 1776); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 1777 | } | ||||
| 1778 | #endif | ||||
| 1779 | |||||
| 1780 | if (!CheckParseTree(this->fc_, alloc_, body)) { | ||||
| 1781 | return errorResult(); | ||||
| 1782 | } | ||||
| 1783 | |||||
| 1784 | ParseNode* node = body; | ||||
| 1785 | if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node, | ||||
| 1786 | &handler_)) { | ||||
| 1787 | return errorResult(); | ||||
| 1788 | } | ||||
| 1789 | body = handler_.asLexicalScopeNode(node); | ||||
| 1790 | |||||
| 1791 | if (!this->setSourceMapInfo()) { | ||||
| 1792 | return errorResult(); | ||||
| 1793 | } | ||||
| 1794 | |||||
| 1795 | if (pc_->sc()->strict()) { | ||||
| 1796 | if (!propagateFreeNamesAndMarkClosedOverBindings(varScope)) { | ||||
| 1797 | return errorResult(); | ||||
| 1798 | } | ||||
| 1799 | } else { | ||||
| 1800 | // For non-strict eval scripts, since all bindings are automatically | ||||
| 1801 | // considered closed over, we don't need to call propagateFreeNames- | ||||
| 1802 | // AndMarkClosedOverBindings. However, Annex B.3.3 functions still need to | ||||
| 1803 | // be marked. | ||||
| 1804 | if (!varScope.propagateAndMarkAnnexBFunctionBoxes(pc_, this)) { | ||||
| 1805 | return errorResult(); | ||||
| 1806 | } | ||||
| 1807 | } | ||||
| 1808 | |||||
| 1809 | Maybe<EvalScope::ParserData*> bindings = newEvalScopeData(pc_->varScope()); | ||||
| 1810 | if (!bindings) { | ||||
| 1811 | return errorResult(); | ||||
| 1812 | } | ||||
| 1813 | evalsc->bindings = *bindings; | ||||
| 1814 | |||||
| 1815 | return body; | ||||
| 1816 | } | ||||
| 1817 | |||||
| 1818 | template <typename Unit> | ||||
| 1819 | FullParseHandler::ListNodeResult Parser<FullParseHandler, Unit>::globalBody( | ||||
| 1820 | GlobalSharedContext* globalsc) { | ||||
| 1821 | SourceParseContext globalpc(this, globalsc, /* newDirectives = */ nullptr); | ||||
| 1822 | if (!globalpc.init()) { | ||||
| 1823 | return errorResult(); | ||||
| 1824 | } | ||||
| 1825 | |||||
| 1826 | ParseContext::VarScope varScope(this); | ||||
| 1827 | if (!varScope.init(pc_)) { | ||||
| 1828 | return errorResult(); | ||||
| 1829 | } | ||||
| 1830 | |||||
| 1831 | ListNode* body = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 1832 | |||||
| 1833 | if (!checkStatementsEOF()) { | ||||
| 1834 | return errorResult(); | ||||
| 1835 | } | ||||
| 1836 | |||||
| 1837 | if (!CheckParseTree(this->fc_, alloc_, body)) { | ||||
| 1838 | return errorResult(); | ||||
| 1839 | } | ||||
| 1840 | |||||
| 1841 | if (!checkForUndefinedPrivateFields()) { | ||||
| 1842 | return errorResult(); | ||||
| 1843 | } | ||||
| 1844 | |||||
| 1845 | ParseNode* node = body; | ||||
| 1846 | if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node, | ||||
| 1847 | &handler_)) { | ||||
| 1848 | return errorResult(); | ||||
| 1849 | } | ||||
| 1850 | body = &node->as<ListNode>(); | ||||
| 1851 | |||||
| 1852 | if (!this->setSourceMapInfo()) { | ||||
| 1853 | return errorResult(); | ||||
| 1854 | } | ||||
| 1855 | |||||
| 1856 | // For global scripts, whether bindings are closed over or not doesn't | ||||
| 1857 | // matter, so no need to call propagateFreeNamesAndMarkClosedOver- | ||||
| 1858 | // Bindings. However, Annex B.3.3 functions still need to be marked. | ||||
| 1859 | if (!varScope.propagateAndMarkAnnexBFunctionBoxes(pc_, this)) { | ||||
| 1860 | return errorResult(); | ||||
| 1861 | } | ||||
| 1862 | |||||
| 1863 | Maybe<GlobalScope::ParserData*> bindings = | ||||
| 1864 | newGlobalScopeData(pc_->varScope()); | ||||
| 1865 | if (!bindings) { | ||||
| 1866 | return errorResult(); | ||||
| 1867 | } | ||||
| 1868 | globalsc->bindings = *bindings; | ||||
| 1869 | |||||
| 1870 | return body; | ||||
| 1871 | } | ||||
| 1872 | |||||
| 1873 | template <typename Unit> | ||||
| 1874 | FullParseHandler::ModuleNodeResult Parser<FullParseHandler, Unit>::moduleBody( | ||||
| 1875 | ModuleSharedContext* modulesc) { | ||||
| 1876 | MOZ_ASSERT(checkOptionsCalled_)do { static_assert( mozilla::detail::AssertionConditionType< decltype(checkOptionsCalled_)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(checkOptionsCalled_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("checkOptionsCalled_" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1876); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence (__null, 1876); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 1877 | |||||
| 1878 | this->compilationState_.moduleMetadata = | ||||
| 1879 | fc_->getAllocator()->template new_<StencilModuleMetadata>(); | ||||
| 1880 | if (!this->compilationState_.moduleMetadata) { | ||||
| 1881 | return errorResult(); | ||||
| 1882 | } | ||||
| 1883 | |||||
| 1884 | SourceParseContext modulepc(this, modulesc, nullptr); | ||||
| 1885 | if (!modulepc.init()) { | ||||
| 1886 | return errorResult(); | ||||
| 1887 | } | ||||
| 1888 | |||||
| 1889 | ParseContext::VarScope varScope(this); | ||||
| 1890 | if (!varScope.init(pc_)) { | ||||
| 1891 | return errorResult(); | ||||
| 1892 | } | ||||
| 1893 | |||||
| 1894 | ModuleNodeType moduleNode = MOZ_TRY(handler_.newModule(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newModule(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 1895 | |||||
| 1896 | AutoAwaitIsKeyword<FullParseHandler, Unit> awaitIsKeyword( | ||||
| 1897 | this, AwaitIsModuleKeyword); | ||||
| 1898 | ListNode* stmtList = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 1899 | |||||
| 1900 | MOZ_ASSERT(stmtList->isKind(ParseNodeKind::StatementList))do { static_assert( mozilla::detail::AssertionConditionType< decltype(stmtList->isKind(ParseNodeKind::StatementList))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(stmtList->isKind(ParseNodeKind::StatementList)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("stmtList->isKind(ParseNodeKind::StatementList)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 1900); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "stmtList->isKind(ParseNodeKind::StatementList)" ")"); do { MOZ_CrashSequence(__null, 1900); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 1901 | moduleNode->setBody(&stmtList->template as<ListNode>()); | ||||
| 1902 | |||||
| 1903 | if (pc_->isAsync()) { | ||||
| 1904 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_generator_())) { | ||||
| 1905 | return errorResult(); | ||||
| 1906 | } | ||||
| 1907 | |||||
| 1908 | if (!pc_->declareTopLevelDotGeneratorName()) { | ||||
| 1909 | return errorResult(); | ||||
| 1910 | } | ||||
| 1911 | } | ||||
| 1912 | |||||
| 1913 | TokenKind tt; | ||||
| 1914 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 1915 | return errorResult(); | ||||
| 1916 | } | ||||
| 1917 | if (tt != TokenKind::Eof) { | ||||
| 1918 | error(JSMSG_GARBAGE_AFTER_INPUT, "module", TokenKindToDesc(tt)); | ||||
| 1919 | return errorResult(); | ||||
| 1920 | } | ||||
| 1921 | |||||
| 1922 | // Set the module to async if an await keyword was found at the top level. | ||||
| 1923 | if (pc_->isAsync()) { | ||||
| 1924 | pc_->sc()->asModuleContext()->builder.noteAsync( | ||||
| 1925 | *this->compilationState_.moduleMetadata); | ||||
| 1926 | } | ||||
| 1927 | |||||
| 1928 | // Generate the Import/Export tables and store in CompilationState. | ||||
| 1929 | if (!modulesc->builder.buildTables(*this->compilationState_.moduleMetadata)) { | ||||
| 1930 | return errorResult(); | ||||
| 1931 | } | ||||
| 1932 | |||||
| 1933 | // Check exported local bindings exist and mark them as closed over. | ||||
| 1934 | StencilModuleMetadata& moduleMetadata = | ||||
| 1935 | *this->compilationState_.moduleMetadata; | ||||
| 1936 | for (auto entry : moduleMetadata.localExportEntries) { | ||||
| 1937 | DeclaredNamePtr p = modulepc.varScope().lookupDeclaredName(entry.localName); | ||||
| 1938 | if (!p) { | ||||
| 1939 | UniqueChars str = this->parserAtoms().toPrintableString(entry.localName); | ||||
| 1940 | if (!str) { | ||||
| 1941 | ReportOutOfMemory(this->fc_); | ||||
| 1942 | return errorResult(); | ||||
| 1943 | } | ||||
| 1944 | |||||
| 1945 | errorNoOffset(JSMSG_MISSING_EXPORT, str.get()); | ||||
| 1946 | return errorResult(); | ||||
| 1947 | } | ||||
| 1948 | |||||
| 1949 | p->value()->setClosedOver(); | ||||
| 1950 | } | ||||
| 1951 | |||||
| 1952 | // Reserve an environment slot for a "*namespace*" psuedo-binding and mark as | ||||
| 1953 | // closed-over. We do not know until module linking if this will be used. | ||||
| 1954 | if (!noteDeclaredName( | ||||
| 1955 | TaggedParserAtomIndex::WellKnown::star_namespace_star_(), | ||||
| 1956 | DeclarationKind::Const, pos())) { | ||||
| 1957 | return errorResult(); | ||||
| 1958 | } | ||||
| 1959 | modulepc.varScope() | ||||
| 1960 | .lookupDeclaredName( | ||||
| 1961 | TaggedParserAtomIndex::WellKnown::star_namespace_star_()) | ||||
| 1962 | ->value() | ||||
| 1963 | ->setClosedOver(); | ||||
| 1964 | |||||
| 1965 | if (!CheckParseTree(this->fc_, alloc_, stmtList)) { | ||||
| 1966 | return errorResult(); | ||||
| 1967 | } | ||||
| 1968 | |||||
| 1969 | ParseNode* node = stmtList; | ||||
| 1970 | if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node, | ||||
| 1971 | &handler_)) { | ||||
| 1972 | return errorResult(); | ||||
| 1973 | } | ||||
| 1974 | stmtList = &node->as<ListNode>(); | ||||
| 1975 | |||||
| 1976 | if (!this->setSourceMapInfo()) { | ||||
| 1977 | return errorResult(); | ||||
| 1978 | } | ||||
| 1979 | |||||
| 1980 | // Private names not lexically defined must trigger a syntax error. | ||||
| 1981 | if (!checkForUndefinedPrivateFields()) { | ||||
| 1982 | return errorResult(); | ||||
| 1983 | } | ||||
| 1984 | |||||
| 1985 | if (!propagateFreeNamesAndMarkClosedOverBindings(modulepc.varScope())) { | ||||
| 1986 | return errorResult(); | ||||
| 1987 | } | ||||
| 1988 | |||||
| 1989 | Maybe<ModuleScope::ParserData*> bindings = | ||||
| 1990 | newModuleScopeData(modulepc.varScope()); | ||||
| 1991 | if (!bindings) { | ||||
| 1992 | return errorResult(); | ||||
| 1993 | } | ||||
| 1994 | |||||
| 1995 | modulesc->bindings = *bindings; | ||||
| 1996 | return moduleNode; | ||||
| 1997 | } | ||||
| 1998 | |||||
| 1999 | template <typename Unit> | ||||
| 2000 | SyntaxParseHandler::ModuleNodeResult | ||||
| 2001 | Parser<SyntaxParseHandler, Unit>::moduleBody(ModuleSharedContext* modulesc) { | ||||
| 2002 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2002); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 2002); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 2003 | return errorResult(); | ||||
| 2004 | } | ||||
| 2005 | |||||
| 2006 | template <class ParseHandler> | ||||
| 2007 | typename ParseHandler::NameNodeResult | ||||
| 2008 | PerHandlerParser<ParseHandler>::newInternalDotName(TaggedParserAtomIndex name) { | ||||
| 2009 | NameNodeType nameNode = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2010 | if (!noteUsedName(name)) { | ||||
| 2011 | return errorResult(); | ||||
| 2012 | } | ||||
| 2013 | return nameNode; | ||||
| 2014 | } | ||||
| 2015 | |||||
| 2016 | template <class ParseHandler> | ||||
| 2017 | typename ParseHandler::NameNodeResult | ||||
| 2018 | PerHandlerParser<ParseHandler>::newThisName() { | ||||
| 2019 | return newInternalDotName(TaggedParserAtomIndex::WellKnown::dot_this_()); | ||||
| 2020 | } | ||||
| 2021 | |||||
| 2022 | template <class ParseHandler> | ||||
| 2023 | typename ParseHandler::NameNodeResult | ||||
| 2024 | PerHandlerParser<ParseHandler>::newNewTargetName() { | ||||
| 2025 | return newInternalDotName(TaggedParserAtomIndex::WellKnown::dot_newTarget_()); | ||||
| 2026 | } | ||||
| 2027 | |||||
| 2028 | template <class ParseHandler> | ||||
| 2029 | typename ParseHandler::NameNodeResult | ||||
| 2030 | PerHandlerParser<ParseHandler>::newDotGeneratorName() { | ||||
| 2031 | return newInternalDotName(TaggedParserAtomIndex::WellKnown::dot_generator_()); | ||||
| 2032 | } | ||||
| 2033 | |||||
| 2034 | template <class ParseHandler> | ||||
| 2035 | bool PerHandlerParser<ParseHandler>::finishFunctionScopes( | ||||
| 2036 | bool isStandaloneFunction) { | ||||
| 2037 | FunctionBox* funbox = pc_->functionBox(); | ||||
| 2038 | |||||
| 2039 | if (funbox->hasParameterExprs) { | ||||
| 2040 | if (!propagateFreeNamesAndMarkClosedOverBindings(pc_->functionScope())) { | ||||
| 2041 | return false; | ||||
| 2042 | } | ||||
| 2043 | |||||
| 2044 | // Functions with parameter expressions utilize the FunctionScope for vars | ||||
| 2045 | // generated by sloppy-direct-evals, as well as arguments (which are | ||||
| 2046 | // lexicals bindings). If the function body has var bindings (or has a | ||||
| 2047 | // sloppy-direct-eval that might), then an extra VarScope must be created | ||||
| 2048 | // for them. | ||||
| 2049 | if (VarScopeHasBindings(pc_) || | ||||
| 2050 | funbox->needsExtraBodyVarEnvironmentRegardlessOfBindings()) { | ||||
| 2051 | funbox->setFunctionHasExtraBodyVarScope(); | ||||
| 2052 | } | ||||
| 2053 | } | ||||
| 2054 | |||||
| 2055 | // See: JSFunction::needsCallObject() | ||||
| 2056 | if (FunctionScopeHasClosedOverBindings(pc_) || | ||||
| 2057 | funbox->needsCallObjectRegardlessOfBindings()) { | ||||
| 2058 | funbox->setNeedsFunctionEnvironmentObjects(); | ||||
| 2059 | } | ||||
| 2060 | |||||
| 2061 | if (funbox->isNamedLambda() && !isStandaloneFunction) { | ||||
| 2062 | if (!propagateFreeNamesAndMarkClosedOverBindings(pc_->namedLambdaScope())) { | ||||
| 2063 | return false; | ||||
| 2064 | } | ||||
| 2065 | |||||
| 2066 | // See: JSFunction::needsNamedLambdaEnvironment() | ||||
| 2067 | if (LexicalScopeHasClosedOverBindings(pc_, pc_->namedLambdaScope())) { | ||||
| 2068 | funbox->setNeedsFunctionEnvironmentObjects(); | ||||
| 2069 | } | ||||
| 2070 | } | ||||
| 2071 | |||||
| 2072 | return true; | ||||
| 2073 | } | ||||
| 2074 | |||||
| 2075 | template <> | ||||
| 2076 | bool PerHandlerParser<FullParseHandler>::finishFunction( | ||||
| 2077 | bool isStandaloneFunction /* = false */) { | ||||
| 2078 | if (!finishFunctionScopes(isStandaloneFunction)) { | ||||
| 2079 | return false; | ||||
| 2080 | } | ||||
| 2081 | |||||
| 2082 | FunctionBox* funbox = pc_->functionBox(); | ||||
| 2083 | ScriptStencil& script = funbox->functionStencil(); | ||||
| 2084 | |||||
| 2085 | if (funbox->isInterpreted()) { | ||||
| 2086 | // BCE will need to generate bytecode for this. | ||||
| 2087 | funbox->emitBytecode = true; | ||||
| 2088 | this->compilationState_.nonLazyFunctionCount++; | ||||
| 2089 | } | ||||
| 2090 | |||||
| 2091 | bool hasParameterExprs = funbox->hasParameterExprs; | ||||
| 2092 | |||||
| 2093 | if (hasParameterExprs) { | ||||
| 2094 | Maybe<VarScope::ParserData*> bindings = newVarScopeData(pc_->varScope()); | ||||
| 2095 | if (!bindings) { | ||||
| 2096 | return false; | ||||
| 2097 | } | ||||
| 2098 | funbox->setExtraVarScopeBindings(*bindings); | ||||
| 2099 | |||||
| 2100 | MOZ_ASSERT(bool(*bindings) == VarScopeHasBindings(pc_))do { static_assert( mozilla::detail::AssertionConditionType< decltype(bool(*bindings) == VarScopeHasBindings(pc_))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(bool(*bindings) == VarScopeHasBindings(pc_)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("bool(*bindings) == VarScopeHasBindings(pc_)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2100); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "bool(*bindings) == VarScopeHasBindings(pc_)" ")"); do { MOZ_CrashSequence(__null, 2100); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2101 | MOZ_ASSERT_IF(!funbox->needsExtraBodyVarEnvironmentRegardlessOfBindings(),do { if (!funbox->needsExtraBodyVarEnvironmentRegardlessOfBindings ()) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(bool(*bindings) == funbox->functionHasExtraBodyVarScope ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(bool(*bindings) == funbox->functionHasExtraBodyVarScope ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("bool(*bindings) == funbox->functionHasExtraBodyVarScope()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2102); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "bool(*bindings) == funbox->functionHasExtraBodyVarScope()" ")"); do { MOZ_CrashSequence(__null, 2102); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 2102 | bool(*bindings) == funbox->functionHasExtraBodyVarScope())do { if (!funbox->needsExtraBodyVarEnvironmentRegardlessOfBindings ()) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(bool(*bindings) == funbox->functionHasExtraBodyVarScope ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(bool(*bindings) == funbox->functionHasExtraBodyVarScope ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("bool(*bindings) == funbox->functionHasExtraBodyVarScope()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2102); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "bool(*bindings) == funbox->functionHasExtraBodyVarScope()" ")"); do { MOZ_CrashSequence(__null, 2102); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 2103 | } | ||||
| 2104 | |||||
| 2105 | { | ||||
| 2106 | Maybe<FunctionScope::ParserData*> bindings = | ||||
| 2107 | newFunctionScopeData(pc_->functionScope(), hasParameterExprs); | ||||
| 2108 | if (!bindings) { | ||||
| 2109 | return false; | ||||
| 2110 | } | ||||
| 2111 | funbox->setFunctionScopeBindings(*bindings); | ||||
| 2112 | } | ||||
| 2113 | |||||
| 2114 | if (funbox->isNamedLambda() && !isStandaloneFunction) { | ||||
| 2115 | Maybe<LexicalScope::ParserData*> bindings = | ||||
| 2116 | newLexicalScopeData(pc_->namedLambdaScope()); | ||||
| 2117 | if (!bindings) { | ||||
| 2118 | return false; | ||||
| 2119 | } | ||||
| 2120 | funbox->setNamedLambdaBindings(*bindings); | ||||
| 2121 | } | ||||
| 2122 | |||||
| 2123 | funbox->finishScriptFlags(); | ||||
| 2124 | funbox->copyFunctionFields(script); | ||||
| 2125 | |||||
| 2126 | if (this->compilationState_.isInitialStencil()) { | ||||
| 2127 | ScriptStencilExtra& scriptExtra = funbox->functionExtraStencil(); | ||||
| 2128 | funbox->copyFunctionExtraFields(scriptExtra); | ||||
| 2129 | funbox->copyScriptExtraFields(scriptExtra); | ||||
| 2130 | } | ||||
| 2131 | |||||
| 2132 | return true; | ||||
| 2133 | } | ||||
| 2134 | |||||
| 2135 | template <> | ||||
| 2136 | bool PerHandlerParser<SyntaxParseHandler>::finishFunction( | ||||
| 2137 | bool isStandaloneFunction /* = false */) { | ||||
| 2138 | // The BaseScript for a lazily parsed function needs to know its set of | ||||
| 2139 | // free variables and inner functions so that when it is fully parsed, we | ||||
| 2140 | // can skip over any already syntax parsed inner functions and still | ||||
| 2141 | // retain correct scope information. | ||||
| 2142 | |||||
| 2143 | if (!finishFunctionScopes(isStandaloneFunction)) { | ||||
| 2144 | return false; | ||||
| 2145 | } | ||||
| 2146 | |||||
| 2147 | FunctionBox* funbox = pc_->functionBox(); | ||||
| 2148 | ScriptStencil& script = funbox->functionStencil(); | ||||
| 2149 | |||||
| 2150 | funbox->finishScriptFlags(); | ||||
| 2151 | funbox->copyFunctionFields(script); | ||||
| 2152 | |||||
| 2153 | ScriptStencilExtra& scriptExtra = funbox->functionExtraStencil(); | ||||
| 2154 | funbox->copyFunctionExtraFields(scriptExtra); | ||||
| 2155 | funbox->copyScriptExtraFields(scriptExtra); | ||||
| 2156 | |||||
| 2157 | // Elide nullptr sentinels from end of binding list. These are inserted for | ||||
| 2158 | // each scope regardless of if any bindings are actually closed over. | ||||
| 2159 | { | ||||
| 2160 | AtomVector& closedOver = pc_->closedOverBindingsForLazy(); | ||||
| 2161 | while (!closedOver.empty() && !closedOver.back()) { | ||||
| 2162 | closedOver.popBack(); | ||||
| 2163 | } | ||||
| 2164 | } | ||||
| 2165 | |||||
| 2166 | // Check if we will overflow the `ngcthings` field later. | ||||
| 2167 | mozilla::CheckedUint32 ngcthings = | ||||
| 2168 | mozilla::CheckedUint32(pc_->innerFunctionIndexesForLazy.length()) + | ||||
| 2169 | mozilla::CheckedUint32(pc_->closedOverBindingsForLazy().length()); | ||||
| 2170 | if (!ngcthings.isValid()) { | ||||
| 2171 | ReportAllocationOverflow(fc_); | ||||
| 2172 | return false; | ||||
| 2173 | } | ||||
| 2174 | |||||
| 2175 | // If there are no script-things, we can return early without allocating. | ||||
| 2176 | if (ngcthings.value() == 0) { | ||||
| 2177 | MOZ_ASSERT(!script.hasGCThings())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!script.hasGCThings())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!script.hasGCThings()))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("!script.hasGCThings()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2177); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!script.hasGCThings()" ")"); do { MOZ_CrashSequence (__null, 2177); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2178 | return true; | ||||
| 2179 | } | ||||
| 2180 | |||||
| 2181 | TaggedScriptThingIndex* cursor = nullptr; | ||||
| 2182 | if (!this->compilationState_.allocateGCThingsUninitialized( | ||||
| 2183 | fc_, funbox->index(), ngcthings.value(), &cursor)) { | ||||
| 2184 | return false; | ||||
| 2185 | } | ||||
| 2186 | |||||
| 2187 | // Copy inner-function and closed-over-binding info for the stencil. The order | ||||
| 2188 | // is important here. We emit functions first, followed by the bindings info. | ||||
| 2189 | // The bindings list uses nullptr as delimiter to separates the bindings per | ||||
| 2190 | // scope. | ||||
| 2191 | // | ||||
| 2192 | // See: FullParseHandler::nextLazyInnerFunction(), | ||||
| 2193 | // FullParseHandler::nextLazyClosedOverBinding() | ||||
| 2194 | for (const ScriptIndex& index : pc_->innerFunctionIndexesForLazy) { | ||||
| 2195 | void* raw = &(*cursor++); | ||||
| 2196 | new (raw) TaggedScriptThingIndex(index); | ||||
| 2197 | } | ||||
| 2198 | for (auto binding : pc_->closedOverBindingsForLazy()) { | ||||
| 2199 | void* raw = &(*cursor++); | ||||
| 2200 | if (binding) { | ||||
| 2201 | this->parserAtoms().markUsedByStencil(binding, ParserAtom::Atomize::Yes); | ||||
| 2202 | new (raw) TaggedScriptThingIndex(binding); | ||||
| 2203 | } else { | ||||
| 2204 | new (raw) TaggedScriptThingIndex(); | ||||
| 2205 | } | ||||
| 2206 | } | ||||
| 2207 | |||||
| 2208 | return true; | ||||
| 2209 | } | ||||
| 2210 | |||||
| 2211 | static YieldHandling GetYieldHandling(GeneratorKind generatorKind) { | ||||
| 2212 | if (generatorKind == GeneratorKind::NotGenerator) { | ||||
| 2213 | return YieldIsName; | ||||
| 2214 | } | ||||
| 2215 | return YieldIsKeyword; | ||||
| 2216 | } | ||||
| 2217 | |||||
| 2218 | static AwaitHandling GetAwaitHandling(FunctionAsyncKind asyncKind) { | ||||
| 2219 | if (asyncKind == FunctionAsyncKind::SyncFunction) { | ||||
| 2220 | return AwaitIsName; | ||||
| 2221 | } | ||||
| 2222 | return AwaitIsKeyword; | ||||
| 2223 | } | ||||
| 2224 | |||||
| 2225 | static FunctionFlags InitialFunctionFlags(FunctionSyntaxKind kind, | ||||
| 2226 | GeneratorKind generatorKind, | ||||
| 2227 | FunctionAsyncKind asyncKind, | ||||
| 2228 | bool isSelfHosting) { | ||||
| 2229 | FunctionFlags flags = {}; | ||||
| 2230 | |||||
| 2231 | switch (kind) { | ||||
| 2232 | case FunctionSyntaxKind::Expression: | ||||
| 2233 | flags = (generatorKind == GeneratorKind::NotGenerator && | ||||
| 2234 | asyncKind == FunctionAsyncKind::SyncFunction | ||||
| 2235 | ? FunctionFlags::INTERPRETED_LAMBDA | ||||
| 2236 | : FunctionFlags::INTERPRETED_LAMBDA_GENERATOR_OR_ASYNC); | ||||
| 2237 | break; | ||||
| 2238 | case FunctionSyntaxKind::Arrow: | ||||
| 2239 | flags = FunctionFlags::INTERPRETED_LAMBDA_ARROW; | ||||
| 2240 | break; | ||||
| 2241 | case FunctionSyntaxKind::Method: | ||||
| 2242 | case FunctionSyntaxKind::FieldInitializer: | ||||
| 2243 | case FunctionSyntaxKind::StaticClassBlock: | ||||
| 2244 | flags = FunctionFlags::INTERPRETED_METHOD; | ||||
| 2245 | break; | ||||
| 2246 | case FunctionSyntaxKind::ClassConstructor: | ||||
| 2247 | case FunctionSyntaxKind::DerivedClassConstructor: | ||||
| 2248 | flags = FunctionFlags::INTERPRETED_CLASS_CTOR; | ||||
| 2249 | break; | ||||
| 2250 | case FunctionSyntaxKind::Getter: | ||||
| 2251 | flags = FunctionFlags::INTERPRETED_GETTER; | ||||
| 2252 | break; | ||||
| 2253 | case FunctionSyntaxKind::Setter: | ||||
| 2254 | flags = FunctionFlags::INTERPRETED_SETTER; | ||||
| 2255 | break; | ||||
| 2256 | default: | ||||
| 2257 | MOZ_ASSERT(kind == FunctionSyntaxKind::Statement)do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == FunctionSyntaxKind::Statement)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(kind == FunctionSyntaxKind::Statement))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == FunctionSyntaxKind::Statement" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2257); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == FunctionSyntaxKind::Statement" ")" ); do { MOZ_CrashSequence(__null, 2257); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2258 | flags = (generatorKind == GeneratorKind::NotGenerator && | ||||
| 2259 | asyncKind == FunctionAsyncKind::SyncFunction | ||||
| 2260 | ? FunctionFlags::INTERPRETED_NORMAL | ||||
| 2261 | : FunctionFlags::INTERPRETED_GENERATOR_OR_ASYNC); | ||||
| 2262 | } | ||||
| 2263 | |||||
| 2264 | if (isSelfHosting) { | ||||
| 2265 | flags.setIsSelfHostedBuiltin(); | ||||
| 2266 | } | ||||
| 2267 | |||||
| 2268 | return flags; | ||||
| 2269 | } | ||||
| 2270 | |||||
| 2271 | template <typename Unit> | ||||
| 2272 | FullParseHandler::FunctionNodeResult | ||||
| 2273 | Parser<FullParseHandler, Unit>::standaloneFunction( | ||||
| 2274 | const Maybe<uint32_t>& parameterListEnd, FunctionSyntaxKind syntaxKind, | ||||
| 2275 | GeneratorKind generatorKind, FunctionAsyncKind asyncKind, | ||||
| 2276 | Directives inheritedDirectives, Directives* newDirectives) { | ||||
| 2277 | MOZ_ASSERT(checkOptionsCalled_)do { static_assert( mozilla::detail::AssertionConditionType< decltype(checkOptionsCalled_)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(checkOptionsCalled_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("checkOptionsCalled_" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2277); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence (__null, 2277); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2278 | // Skip prelude. | ||||
| 2279 | TokenKind tt; | ||||
| 2280 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 2281 | return errorResult(); | ||||
| 2282 | } | ||||
| 2283 | if (asyncKind == FunctionAsyncKind::AsyncFunction) { | ||||
| 2284 | MOZ_ASSERT(tt == TokenKind::Async)do { static_assert( mozilla::detail::AssertionConditionType< decltype(tt == TokenKind::Async)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(tt == TokenKind::Async))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("tt == TokenKind::Async" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2284); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "tt == TokenKind::Async" ")"); do { MOZ_CrashSequence (__null, 2284); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2285 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 2286 | return errorResult(); | ||||
| 2287 | } | ||||
| 2288 | } | ||||
| 2289 | MOZ_ASSERT(tt == TokenKind::Function)do { static_assert( mozilla::detail::AssertionConditionType< decltype(tt == TokenKind::Function)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(tt == TokenKind::Function))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("tt == TokenKind::Function" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2289); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "tt == TokenKind::Function" ")"); do { MOZ_CrashSequence (__null, 2289); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2290 | |||||
| 2291 | if (!tokenStream.getToken(&tt)) { | ||||
| 2292 | return errorResult(); | ||||
| 2293 | } | ||||
| 2294 | if (generatorKind == GeneratorKind::Generator) { | ||||
| 2295 | MOZ_ASSERT(tt == TokenKind::Mul)do { static_assert( mozilla::detail::AssertionConditionType< decltype(tt == TokenKind::Mul)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(tt == TokenKind::Mul))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("tt == TokenKind::Mul" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2295); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "tt == TokenKind::Mul" ")"); do { MOZ_CrashSequence (__null, 2295); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2296 | if (!tokenStream.getToken(&tt)) { | ||||
| 2297 | return errorResult(); | ||||
| 2298 | } | ||||
| 2299 | } | ||||
| 2300 | |||||
| 2301 | // Skip function name, if present. | ||||
| 2302 | TaggedParserAtomIndex explicitName; | ||||
| 2303 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 2304 | explicitName = anyChars.currentName(); | ||||
| 2305 | } else { | ||||
| 2306 | anyChars.ungetToken(); | ||||
| 2307 | } | ||||
| 2308 | |||||
| 2309 | FunctionNodeType funNode = MOZ_TRY(handler_.newFunction(syntaxKind, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2310 | |||||
| 2311 | ParamsBodyNodeType argsbody = MOZ_TRY(handler_.newParamsBody(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newParamsBody(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2312 | funNode->setBody(argsbody); | ||||
| 2313 | |||||
| 2314 | bool isSelfHosting = options().selfHostingMode; | ||||
| 2315 | FunctionFlags flags = | ||||
| 2316 | InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting); | ||||
| 2317 | FunctionBox* funbox = | ||||
| 2318 | newFunctionBox(funNode, explicitName, flags, /* toStringStart = */ 0, | ||||
| 2319 | inheritedDirectives, generatorKind, asyncKind); | ||||
| 2320 | if (!funbox) { | ||||
| 2321 | return errorResult(); | ||||
| 2322 | } | ||||
| 2323 | |||||
| 2324 | // Function is not syntactically part of another script. | ||||
| 2325 | MOZ_ASSERT(funbox->index() == CompilationStencil::TopLevelIndex)do { static_assert( mozilla::detail::AssertionConditionType< decltype(funbox->index() == CompilationStencil::TopLevelIndex )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(funbox->index() == CompilationStencil::TopLevelIndex ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "funbox->index() == CompilationStencil::TopLevelIndex", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2325); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->index() == CompilationStencil::TopLevelIndex" ")"); do { MOZ_CrashSequence(__null, 2325); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2326 | |||||
| 2327 | funbox->initStandalone(this->compilationState_.scopeContext, syntaxKind); | ||||
| 2328 | |||||
| 2329 | SourceParseContext funpc(this, funbox, newDirectives); | ||||
| 2330 | if (!funpc.init()) { | ||||
| 2331 | return errorResult(); | ||||
| 2332 | } | ||||
| 2333 | |||||
| 2334 | YieldHandling yieldHandling = GetYieldHandling(generatorKind); | ||||
| 2335 | AwaitHandling awaitHandling = GetAwaitHandling(asyncKind); | ||||
| 2336 | AutoAwaitIsKeyword<FullParseHandler, Unit> awaitIsKeyword(this, | ||||
| 2337 | awaitHandling); | ||||
| 2338 | if (!functionFormalParametersAndBody(InAllowed, yieldHandling, &funNode, | ||||
| 2339 | syntaxKind, parameterListEnd, | ||||
| 2340 | /* isStandaloneFunction = */ true)) { | ||||
| 2341 | return errorResult(); | ||||
| 2342 | } | ||||
| 2343 | |||||
| 2344 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 2345 | return errorResult(); | ||||
| 2346 | } | ||||
| 2347 | if (tt != TokenKind::Eof) { | ||||
| 2348 | error(JSMSG_GARBAGE_AFTER_INPUT, "function body", TokenKindToDesc(tt)); | ||||
| 2349 | return errorResult(); | ||||
| 2350 | } | ||||
| 2351 | |||||
| 2352 | if (!CheckParseTree(this->fc_, alloc_, funNode)) { | ||||
| 2353 | return errorResult(); | ||||
| 2354 | } | ||||
| 2355 | |||||
| 2356 | ParseNode* node = funNode; | ||||
| 2357 | if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node, | ||||
| 2358 | &handler_)) { | ||||
| 2359 | return errorResult(); | ||||
| 2360 | } | ||||
| 2361 | funNode = &node->as<FunctionNode>(); | ||||
| 2362 | |||||
| 2363 | if (!checkForUndefinedPrivateFields(nullptr)) { | ||||
| 2364 | return errorResult(); | ||||
| 2365 | } | ||||
| 2366 | |||||
| 2367 | if (!this->setSourceMapInfo()) { | ||||
| 2368 | return errorResult(); | ||||
| 2369 | } | ||||
| 2370 | |||||
| 2371 | return funNode; | ||||
| 2372 | } | ||||
| 2373 | |||||
| 2374 | template <class ParseHandler, typename Unit> | ||||
| 2375 | typename ParseHandler::LexicalScopeNodeResult | ||||
| 2376 | GeneralParser<ParseHandler, Unit>::functionBody(InHandling inHandling, | ||||
| 2377 | YieldHandling yieldHandling, | ||||
| 2378 | FunctionSyntaxKind kind, | ||||
| 2379 | FunctionBodyType type) { | ||||
| 2380 | MOZ_ASSERT(pc_->isFunctionBox())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isFunctionBox())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isFunctionBox()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isFunctionBox()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2380); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence (__null, 2380); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2381 | |||||
| 2382 | #ifdef DEBUG1 | ||||
| 2383 | uint32_t startYieldOffset = pc_->lastYieldOffset; | ||||
| 2384 | #endif | ||||
| 2385 | |||||
| 2386 | Node body; | ||||
| 2387 | if (type == StatementListBody) { | ||||
| 2388 | bool inheritedStrict = pc_->sc()->strict(); | ||||
| 2389 | body = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2390 | |||||
| 2391 | // When we transitioned from non-strict to strict mode, we need to | ||||
| 2392 | // validate that all parameter names are valid strict mode names. | ||||
| 2393 | if (!inheritedStrict && pc_->sc()->strict()) { | ||||
| 2394 | MOZ_ASSERT(pc_->sc()->hasExplicitUseStrict(),do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->sc()->hasExplicitUseStrict())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(pc_->sc()->hasExplicitUseStrict()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->sc()->hasExplicitUseStrict()" " (" "strict mode should only change when a 'use strict' directive " "is present" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2396); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()" ") (" "strict mode should only change when a 'use strict' directive " "is present" ")"); do { MOZ_CrashSequence(__null, 2396); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 2395 | "strict mode should only change when a 'use strict' directive "do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->sc()->hasExplicitUseStrict())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(pc_->sc()->hasExplicitUseStrict()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->sc()->hasExplicitUseStrict()" " (" "strict mode should only change when a 'use strict' directive " "is present" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2396); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()" ") (" "strict mode should only change when a 'use strict' directive " "is present" ")"); do { MOZ_CrashSequence(__null, 2396); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 2396 | "is present")do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->sc()->hasExplicitUseStrict())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(pc_->sc()->hasExplicitUseStrict()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->sc()->hasExplicitUseStrict()" " (" "strict mode should only change when a 'use strict' directive " "is present" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2396); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()" ") (" "strict mode should only change when a 'use strict' directive " "is present" ")"); do { MOZ_CrashSequence(__null, 2396); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 2397 | if (!hasValidSimpleStrictParameterNames()) { | ||||
| 2398 | // Request that this function be reparsed as strict to report | ||||
| 2399 | // the invalid parameter name at the correct source location. | ||||
| 2400 | pc_->newDirectives->setStrict(); | ||||
| 2401 | return errorResult(); | ||||
| 2402 | } | ||||
| 2403 | } | ||||
| 2404 | } else { | ||||
| 2405 | MOZ_ASSERT(type == ExpressionBody)do { static_assert( mozilla::detail::AssertionConditionType< decltype(type == ExpressionBody)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(type == ExpressionBody))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("type == ExpressionBody" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2405); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "type == ExpressionBody" ")"); do { MOZ_CrashSequence (__null, 2405); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2406 | |||||
| 2407 | // Async functions are implemented as generators, and generators are | ||||
| 2408 | // assumed to be statement lists, to prepend initial `yield`. | ||||
| 2409 | ListNodeType stmtList = null(); | ||||
| 2410 | if (pc_->isAsync()) { | ||||
| 2411 | stmtList = MOZ_TRY(handler_.newStatementList(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(pos())); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2412 | } | ||||
| 2413 | |||||
| 2414 | Node kid = | ||||
| 2415 | MOZ_TRY(assignExpr(inHandling, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 2416 | |||||
| 2417 | body = MOZ_TRY(handler_.newExpressionBody(kid))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExpressionBody(kid)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2418 | |||||
| 2419 | if (pc_->isAsync()) { | ||||
| 2420 | handler_.addStatementToList(stmtList, body); | ||||
| 2421 | body = stmtList; | ||||
| 2422 | } | ||||
| 2423 | } | ||||
| 2424 | |||||
| 2425 | MOZ_ASSERT_IF(!pc_->isGenerator() && !pc_->isAsync(),do { if (!pc_->isGenerator() && !pc_->isAsync() ) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(pc_->lastYieldOffset == startYieldOffset)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(pc_->lastYieldOffset == startYieldOffset))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->lastYieldOffset == startYieldOffset" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2426); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->lastYieldOffset == startYieldOffset" ")"); do { MOZ_CrashSequence(__null, 2426); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 2426 | pc_->lastYieldOffset == startYieldOffset)do { if (!pc_->isGenerator() && !pc_->isAsync() ) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(pc_->lastYieldOffset == startYieldOffset)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(pc_->lastYieldOffset == startYieldOffset))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->lastYieldOffset == startYieldOffset" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2426); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->lastYieldOffset == startYieldOffset" ")"); do { MOZ_CrashSequence(__null, 2426); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 2427 | MOZ_ASSERT_IF(pc_->isGenerator(), kind != FunctionSyntaxKind::Arrow)do { if (pc_->isGenerator()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(kind != FunctionSyntaxKind ::Arrow)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(kind != FunctionSyntaxKind::Arrow))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind != FunctionSyntaxKind::Arrow" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2427); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind != FunctionSyntaxKind::Arrow" ")"); do { MOZ_CrashSequence(__null, 2427); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); } } while (false ); | ||||
| 2428 | MOZ_ASSERT_IF(pc_->isGenerator(), type == StatementListBody)do { if (pc_->isGenerator()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(type == StatementListBody )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(type == StatementListBody))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("type == StatementListBody", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2428); AnnotateMozCrashReason("MOZ_ASSERT" "(" "type == StatementListBody" ")"); do { MOZ_CrashSequence(__null, 2428); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 2429 | |||||
| 2430 | if (pc_->needsDotGeneratorName()) { | ||||
| 2431 | MOZ_ASSERT_IF(!pc_->isAsync(), type == StatementListBody)do { if (!pc_->isAsync()) { do { static_assert( mozilla::detail ::AssertionConditionType<decltype(type == StatementListBody )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(type == StatementListBody))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("type == StatementListBody", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2431); AnnotateMozCrashReason("MOZ_ASSERT" "(" "type == StatementListBody" ")"); do { MOZ_CrashSequence(__null, 2431); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 2432 | if (!pc_->declareDotGeneratorName()) { | ||||
| 2433 | return errorResult(); | ||||
| 2434 | } | ||||
| 2435 | if (pc_->isGenerator()) { | ||||
| 2436 | NameNodeType generator = MOZ_TRY(newDotGeneratorName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newDotGeneratorName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2437 | if (!handler_.prependInitialYield(handler_.asListNode(body), generator)) { | ||||
| 2438 | return errorResult(); | ||||
| 2439 | } | ||||
| 2440 | } | ||||
| 2441 | } | ||||
| 2442 | |||||
| 2443 | if (pc_->numberOfArgumentsNames > 0 || kind == FunctionSyntaxKind::Arrow) { | ||||
| 2444 | MOZ_ASSERT(pc_->isFunctionBox())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isFunctionBox())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isFunctionBox()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isFunctionBox()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2444); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence (__null, 2444); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2445 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 2446 | } | ||||
| 2447 | |||||
| 2448 | // Declare the 'arguments', 'this', and 'new.target' bindings if necessary | ||||
| 2449 | // before finishing up the scope so these special bindings get marked as | ||||
| 2450 | // closed over if necessary. Arrow functions don't have these bindings. | ||||
| 2451 | if (kind != FunctionSyntaxKind::Arrow) { | ||||
| 2452 | bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings(); | ||||
| 2453 | if (!pc_->declareFunctionArgumentsObject(usedNames_, | ||||
| 2454 | canSkipLazyClosedOverBindings)) { | ||||
| 2455 | return errorResult(); | ||||
| 2456 | } | ||||
| 2457 | if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 2458 | return errorResult(); | ||||
| 2459 | } | ||||
| 2460 | if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 2461 | return errorResult(); | ||||
| 2462 | } | ||||
| 2463 | } | ||||
| 2464 | |||||
| 2465 | return finishLexicalScope(pc_->varScope(), body, ScopeKind::FunctionLexical); | ||||
| 2466 | } | ||||
| 2467 | |||||
| 2468 | template <class ParseHandler, typename Unit> | ||||
| 2469 | bool GeneralParser<ParseHandler, Unit>::matchOrInsertSemicolon( | ||||
| 2470 | Modifier modifier /* = TokenStream::SlashIsRegExp */) { | ||||
| 2471 | TokenKind tt = TokenKind::Eof; | ||||
| 2472 | if (!tokenStream.peekTokenSameLine(&tt, modifier)) { | ||||
| 2473 | return false; | ||||
| 2474 | } | ||||
| 2475 | if (tt != TokenKind::Eof && tt != TokenKind::Eol && tt != TokenKind::Semi && | ||||
| 2476 | tt != TokenKind::RightCurly) { | ||||
| 2477 | /* | ||||
| 2478 | * When current token is `await` and it's outside of async function, | ||||
| 2479 | * it's possibly intended to be an await expression. | ||||
| 2480 | * | ||||
| 2481 | * await f(); | ||||
| 2482 | * ^ | ||||
| 2483 | * | | ||||
| 2484 | * tried to insert semicolon here | ||||
| 2485 | * | ||||
| 2486 | * Detect this situation and throw an understandable error. Otherwise | ||||
| 2487 | * we'd throw a confusing "unexpected token: (unexpected token)" error. | ||||
| 2488 | */ | ||||
| 2489 | if (!pc_->isAsync() && anyChars.currentToken().type == TokenKind::Await) { | ||||
| 2490 | error(JSMSG_AWAIT_OUTSIDE_ASYNC_OR_MODULE); | ||||
| 2491 | return false; | ||||
| 2492 | } | ||||
| 2493 | if (!yieldExpressionsSupported() && | ||||
| 2494 | anyChars.currentToken().type == TokenKind::Yield) { | ||||
| 2495 | error(JSMSG_YIELD_OUTSIDE_GENERATOR); | ||||
| 2496 | return false; | ||||
| 2497 | } | ||||
| 2498 | |||||
| 2499 | if (anyChars.currentToken().type == TokenKind::Using && | ||||
| 2500 | !this->pc_->isUsingSyntaxAllowed()) { | ||||
| 2501 | error(JSMSG_USING_OUTSIDE_BLOCK_OR_MODULE); | ||||
| 2502 | return false; | ||||
| 2503 | } | ||||
| 2504 | |||||
| 2505 | /* Advance the scanner for proper error location reporting. */ | ||||
| 2506 | tokenStream.consumeKnownToken(tt, modifier); | ||||
| 2507 | error(JSMSG_UNEXPECTED_TOKEN_NO_EXPECT, TokenKindToDesc(tt)); | ||||
| 2508 | return false; | ||||
| 2509 | } | ||||
| 2510 | bool matched; | ||||
| 2511 | return tokenStream.matchToken(&matched, TokenKind::Semi, modifier); | ||||
| 2512 | } | ||||
| 2513 | |||||
| 2514 | bool ParserBase::leaveInnerFunction(ParseContext* outerpc) { | ||||
| 2515 | MOZ_ASSERT(pc_ != outerpc)do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_ != outerpc)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_ != outerpc))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_ != outerpc" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2515); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_ != outerpc" ")"); do { MOZ_CrashSequence (__null, 2515); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2516 | |||||
| 2517 | MOZ_ASSERT_IF(outerpc->isFunctionBox(),do { if (outerpc->isFunctionBox()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(outerpc->functionBox ()->index() < pc_->functionBox()->index())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(outerpc->functionBox()->index() < pc_->functionBox ()->index()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("outerpc->functionBox()->index() < pc_->functionBox()->index()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2518); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "outerpc->functionBox()->index() < pc_->functionBox()->index()" ")"); do { MOZ_CrashSequence(__null, 2518); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 2518 | outerpc->functionBox()->index() < pc_->functionBox()->index())do { if (outerpc->isFunctionBox()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(outerpc->functionBox ()->index() < pc_->functionBox()->index())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(outerpc->functionBox()->index() < pc_->functionBox ()->index()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("outerpc->functionBox()->index() < pc_->functionBox()->index()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2518); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "outerpc->functionBox()->index() < pc_->functionBox()->index()" ")"); do { MOZ_CrashSequence(__null, 2518); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 2519 | |||||
| 2520 | // If the current function allows super.property but cannot have a home | ||||
| 2521 | // object, i.e., it is an arrow function, we need to propagate the flag to | ||||
| 2522 | // the outer ParseContext. | ||||
| 2523 | if (pc_->superScopeNeedsHomeObject()) { | ||||
| 2524 | if (!pc_->isArrowFunction()) { | ||||
| 2525 | MOZ_ASSERT(pc_->functionBox()->needsHomeObject())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->functionBox()->needsHomeObject())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(pc_->functionBox()->needsHomeObject()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->functionBox()->needsHomeObject()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2525); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->functionBox()->needsHomeObject()" ")"); do { MOZ_CrashSequence(__null, 2525); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2526 | } else { | ||||
| 2527 | outerpc->setSuperScopeNeedsHomeObject(); | ||||
| 2528 | } | ||||
| 2529 | } | ||||
| 2530 | |||||
| 2531 | // Lazy functions inner to another lazy function need to be remembered by | ||||
| 2532 | // the inner function so that if the outer function is eventually parsed | ||||
| 2533 | // we do not need any further parsing or processing of the inner function. | ||||
| 2534 | // | ||||
| 2535 | // Append the inner function index here unconditionally; the vector is only | ||||
| 2536 | // used if the Parser using outerpc is a syntax parsing. See | ||||
| 2537 | // GeneralParser<SyntaxParseHandler>::finishFunction. | ||||
| 2538 | if (!outerpc->innerFunctionIndexesForLazy.append( | ||||
| 2539 | pc_->functionBox()->index())) { | ||||
| 2540 | return false; | ||||
| 2541 | } | ||||
| 2542 | |||||
| 2543 | PropagateTransitiveParseFlags(pc_->functionBox(), outerpc->sc()); | ||||
| 2544 | |||||
| 2545 | return true; | ||||
| 2546 | } | ||||
| 2547 | |||||
| 2548 | TaggedParserAtomIndex ParserBase::prefixAccessorName( | ||||
| 2549 | PropertyType propType, TaggedParserAtomIndex propAtom) { | ||||
| 2550 | StringBuilder prefixed(fc_); | ||||
| 2551 | if (propType == PropertyType::Setter) { | ||||
| 2552 | if (!prefixed.append("set ")) { | ||||
| 2553 | return TaggedParserAtomIndex::null(); | ||||
| 2554 | } | ||||
| 2555 | } else { | ||||
| 2556 | if (!prefixed.append("get ")) { | ||||
| 2557 | return TaggedParserAtomIndex::null(); | ||||
| 2558 | } | ||||
| 2559 | } | ||||
| 2560 | if (!prefixed.append(this->parserAtoms(), propAtom)) { | ||||
| 2561 | return TaggedParserAtomIndex::null(); | ||||
| 2562 | } | ||||
| 2563 | return prefixed.finishParserAtom(this->parserAtoms(), fc_); | ||||
| 2564 | } | ||||
| 2565 | |||||
| 2566 | template <class ParseHandler, typename Unit> | ||||
| 2567 | void GeneralParser<ParseHandler, Unit>::setFunctionStartAtPosition( | ||||
| 2568 | FunctionBox* funbox, TokenPos pos) const { | ||||
| 2569 | uint32_t startLine; | ||||
| 2570 | JS::LimitedColumnNumberOneOrigin startColumn; | ||||
| 2571 | tokenStream.computeLineAndColumn(pos.begin, &startLine, &startColumn); | ||||
| 2572 | |||||
| 2573 | // NOTE: `Debugger::CallData::findScripts` relies on sourceStart and | ||||
| 2574 | // lineno/column referring to the same location. | ||||
| 2575 | funbox->setStart(pos.begin, startLine, startColumn); | ||||
| 2576 | } | ||||
| 2577 | |||||
| 2578 | template <class ParseHandler, typename Unit> | ||||
| 2579 | void GeneralParser<ParseHandler, Unit>::setFunctionStartAtCurrentToken( | ||||
| 2580 | FunctionBox* funbox) const { | ||||
| 2581 | setFunctionStartAtPosition(funbox, anyChars.currentToken().pos); | ||||
| 2582 | } | ||||
| 2583 | |||||
| 2584 | template <class ParseHandler, typename Unit> | ||||
| 2585 | bool GeneralParser<ParseHandler, Unit>::functionArguments( | ||||
| 2586 | YieldHandling yieldHandling, FunctionSyntaxKind kind, | ||||
| 2587 | FunctionNodeType funNode) { | ||||
| 2588 | FunctionBox* funbox = pc_->functionBox(); | ||||
| 2589 | |||||
| 2590 | // Modifier for the following tokens. | ||||
| 2591 | // TokenStream::SlashIsDiv for the following cases: | ||||
| 2592 | // async a => 1 | ||||
| 2593 | // ^ | ||||
| 2594 | // | ||||
| 2595 | // (a) => 1 | ||||
| 2596 | // ^ | ||||
| 2597 | // | ||||
| 2598 | // async (a) => 1 | ||||
| 2599 | // ^ | ||||
| 2600 | // | ||||
| 2601 | // function f(a) {} | ||||
| 2602 | // ^ | ||||
| 2603 | // | ||||
| 2604 | // TokenStream::SlashIsRegExp for the following case: | ||||
| 2605 | // a => 1 | ||||
| 2606 | // ^ | ||||
| 2607 | Modifier firstTokenModifier = | ||||
| 2608 | kind != FunctionSyntaxKind::Arrow || funbox->isAsync() | ||||
| 2609 | ? TokenStream::SlashIsDiv | ||||
| 2610 | : TokenStream::SlashIsRegExp; | ||||
| 2611 | TokenKind tt; | ||||
| 2612 | if (!tokenStream.getToken(&tt, firstTokenModifier)) { | ||||
| 2613 | return false; | ||||
| 2614 | } | ||||
| 2615 | |||||
| 2616 | if (kind == FunctionSyntaxKind::Arrow && TokenKindIsPossibleIdentifier(tt)) { | ||||
| 2617 | // Record the start of function source (for FunctionToString). | ||||
| 2618 | setFunctionStartAtCurrentToken(funbox); | ||||
| 2619 | |||||
| 2620 | ParamsBodyNodeType argsbody; | ||||
| 2621 | MOZ_TRY_VAR_OR_RETURN(argsbody, handler_.newParamsBody(pos()), false)do { auto parserTryVarTempResult_ = (handler_.newParamsBody(pos ())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr( )), 0))) { return (false); } (argsbody) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 2622 | handler_.setFunctionFormalParametersAndBody(funNode, argsbody); | ||||
| 2623 | |||||
| 2624 | TaggedParserAtomIndex name = bindingIdentifier(yieldHandling); | ||||
| 2625 | if (!name) { | ||||
| 2626 | return false; | ||||
| 2627 | } | ||||
| 2628 | |||||
| 2629 | constexpr bool disallowDuplicateParams = true; | ||||
| 2630 | bool duplicatedParam = false; | ||||
| 2631 | if (!notePositionalFormalParameter(funNode, name, pos().begin, | ||||
| 2632 | disallowDuplicateParams, | ||||
| 2633 | &duplicatedParam)) { | ||||
| 2634 | return false; | ||||
| 2635 | } | ||||
| 2636 | MOZ_ASSERT(!duplicatedParam)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!duplicatedParam)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!duplicatedParam))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!duplicatedParam" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2636); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!duplicatedParam" ")"); do { MOZ_CrashSequence (__null, 2636); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 2637 | MOZ_ASSERT(pc_->positionalFormalParameterNames().length() == 1)do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->positionalFormalParameterNames().length() == 1)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(pc_->positionalFormalParameterNames().length() == 1))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("pc_->positionalFormalParameterNames().length() == 1", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2637); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->positionalFormalParameterNames().length() == 1" ")"); do { MOZ_CrashSequence(__null, 2637); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2638 | |||||
| 2639 | funbox->setLength(1); | ||||
| 2640 | funbox->setArgCount(1); | ||||
| 2641 | return true; | ||||
| 2642 | } | ||||
| 2643 | |||||
| 2644 | if (tt != TokenKind::LeftParen) { | ||||
| 2645 | error(kind == FunctionSyntaxKind::Arrow ? JSMSG_BAD_ARROW_ARGS | ||||
| 2646 | : JSMSG_PAREN_BEFORE_FORMAL); | ||||
| 2647 | return false; | ||||
| 2648 | } | ||||
| 2649 | |||||
| 2650 | // Record the start of function source (for FunctionToString). | ||||
| 2651 | setFunctionStartAtCurrentToken(funbox); | ||||
| 2652 | |||||
| 2653 | ParamsBodyNodeType argsbody; | ||||
| 2654 | MOZ_TRY_VAR_OR_RETURN(argsbody, handler_.newParamsBody(pos()), false)do { auto parserTryVarTempResult_ = (handler_.newParamsBody(pos ())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr( )), 0))) { return (false); } (argsbody) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 2655 | handler_.setFunctionFormalParametersAndBody(funNode, argsbody); | ||||
| 2656 | |||||
| 2657 | bool matched; | ||||
| 2658 | if (!tokenStream.matchToken(&matched, TokenKind::RightParen, | ||||
| 2659 | TokenStream::SlashIsRegExp)) { | ||||
| 2660 | return false; | ||||
| 2661 | } | ||||
| 2662 | if (!matched) { | ||||
| 2663 | bool hasRest = false; | ||||
| 2664 | bool hasDefault = false; | ||||
| 2665 | bool duplicatedParam = false; | ||||
| 2666 | bool disallowDuplicateParams = | ||||
| 2667 | kind == FunctionSyntaxKind::Arrow || | ||||
| 2668 | kind == FunctionSyntaxKind::Method || | ||||
| 2669 | kind == FunctionSyntaxKind::FieldInitializer || | ||||
| 2670 | kind == FunctionSyntaxKind::ClassConstructor; | ||||
| 2671 | AtomVector& positionalFormals = pc_->positionalFormalParameterNames(); | ||||
| 2672 | |||||
| 2673 | if (kind == FunctionSyntaxKind::Getter) { | ||||
| 2674 | error(JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s"); | ||||
| 2675 | return false; | ||||
| 2676 | } | ||||
| 2677 | |||||
| 2678 | while (true) { | ||||
| 2679 | if (hasRest) { | ||||
| 2680 | error(JSMSG_PARAMETER_AFTER_REST); | ||||
| 2681 | return false; | ||||
| 2682 | } | ||||
| 2683 | |||||
| 2684 | TokenKind tt; | ||||
| 2685 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 2686 | return false; | ||||
| 2687 | } | ||||
| 2688 | |||||
| 2689 | if (tt == TokenKind::TripleDot) { | ||||
| 2690 | if (kind == FunctionSyntaxKind::Setter) { | ||||
| 2691 | error(JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", ""); | ||||
| 2692 | return false; | ||||
| 2693 | } | ||||
| 2694 | |||||
| 2695 | disallowDuplicateParams = true; | ||||
| 2696 | if (duplicatedParam) { | ||||
| 2697 | // Has duplicated args before the rest parameter. | ||||
| 2698 | error(JSMSG_BAD_DUP_ARGS); | ||||
| 2699 | return false; | ||||
| 2700 | } | ||||
| 2701 | |||||
| 2702 | hasRest = true; | ||||
| 2703 | funbox->setHasRest(); | ||||
| 2704 | |||||
| 2705 | if (!tokenStream.getToken(&tt)) { | ||||
| 2706 | return false; | ||||
| 2707 | } | ||||
| 2708 | |||||
| 2709 | if (!TokenKindIsPossibleIdentifier(tt) && | ||||
| 2710 | tt != TokenKind::LeftBracket && tt != TokenKind::LeftCurly) { | ||||
| 2711 | error(JSMSG_NO_REST_NAME); | ||||
| 2712 | return false; | ||||
| 2713 | } | ||||
| 2714 | } | ||||
| 2715 | |||||
| 2716 | switch (tt) { | ||||
| 2717 | case TokenKind::LeftBracket: | ||||
| 2718 | case TokenKind::LeftCurly: { | ||||
| 2719 | disallowDuplicateParams = true; | ||||
| 2720 | if (duplicatedParam) { | ||||
| 2721 | // Has duplicated args before the destructuring parameter. | ||||
| 2722 | error(JSMSG_BAD_DUP_ARGS); | ||||
| 2723 | return false; | ||||
| 2724 | } | ||||
| 2725 | |||||
| 2726 | funbox->hasDestructuringArgs = true; | ||||
| 2727 | |||||
| 2728 | Node destruct; | ||||
| 2729 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait ( DeclarationKind::FormalParameter, yieldHandling, tt)); if ( (__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (destruct) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 2730 | destruct,do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait ( DeclarationKind::FormalParameter, yieldHandling, tt)); if ( (__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (destruct) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 2731 | destructuringDeclarationWithoutYieldOrAwait(do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait ( DeclarationKind::FormalParameter, yieldHandling, tt)); if ( (__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (destruct) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 2732 | DeclarationKind::FormalParameter, yieldHandling, tt),do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait ( DeclarationKind::FormalParameter, yieldHandling, tt)); if ( (__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (destruct) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 2733 | false)do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait ( DeclarationKind::FormalParameter, yieldHandling, tt)); if ( (__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (destruct) = parserTryVarTempResult_.unwrap (); } while (0); | ||||
| 2734 | |||||
| 2735 | if (!noteDestructuredPositionalFormalParameter(funNode, destruct)) { | ||||
| 2736 | return false; | ||||
| 2737 | } | ||||
| 2738 | |||||
| 2739 | break; | ||||
| 2740 | } | ||||
| 2741 | |||||
| 2742 | default: { | ||||
| 2743 | if (!TokenKindIsPossibleIdentifier(tt)) { | ||||
| 2744 | error(JSMSG_MISSING_FORMAL); | ||||
| 2745 | return false; | ||||
| 2746 | } | ||||
| 2747 | |||||
| 2748 | TaggedParserAtomIndex name = bindingIdentifier(yieldHandling); | ||||
| 2749 | if (!name) { | ||||
| 2750 | return false; | ||||
| 2751 | } | ||||
| 2752 | |||||
| 2753 | if (!notePositionalFormalParameter(funNode, name, pos().begin, | ||||
| 2754 | disallowDuplicateParams, | ||||
| 2755 | &duplicatedParam)) { | ||||
| 2756 | return false; | ||||
| 2757 | } | ||||
| 2758 | if (duplicatedParam) { | ||||
| 2759 | funbox->hasDuplicateParameters = true; | ||||
| 2760 | } | ||||
| 2761 | |||||
| 2762 | break; | ||||
| 2763 | } | ||||
| 2764 | } | ||||
| 2765 | |||||
| 2766 | if (positionalFormals.length() >= ARGNO_LIMIT) { | ||||
| 2767 | error(JSMSG_TOO_MANY_FUN_ARGS); | ||||
| 2768 | return false; | ||||
| 2769 | } | ||||
| 2770 | |||||
| 2771 | bool matched; | ||||
| 2772 | if (!tokenStream.matchToken(&matched, TokenKind::Assign, | ||||
| 2773 | TokenStream::SlashIsRegExp)) { | ||||
| 2774 | return false; | ||||
| 2775 | } | ||||
| 2776 | if (matched) { | ||||
| 2777 | if (hasRest) { | ||||
| 2778 | error(JSMSG_REST_WITH_DEFAULT); | ||||
| 2779 | return false; | ||||
| 2780 | } | ||||
| 2781 | disallowDuplicateParams = true; | ||||
| 2782 | if (duplicatedParam) { | ||||
| 2783 | error(JSMSG_BAD_DUP_ARGS); | ||||
| 2784 | return false; | ||||
| 2785 | } | ||||
| 2786 | |||||
| 2787 | if (!hasDefault) { | ||||
| 2788 | hasDefault = true; | ||||
| 2789 | |||||
| 2790 | // The Function.length property is the number of formals | ||||
| 2791 | // before the first default argument. | ||||
| 2792 | funbox->setLength(positionalFormals.length() - 1); | ||||
| 2793 | } | ||||
| 2794 | funbox->hasParameterExprs = true; | ||||
| 2795 | |||||
| 2796 | Node def_expr; | ||||
| 2797 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (assignExprWithoutYieldOrAwait (yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (def_expr) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 2798 | def_expr, assignExprWithoutYieldOrAwait(yieldHandling), false)do { auto parserTryVarTempResult_ = (assignExprWithoutYieldOrAwait (yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (def_expr) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 2799 | if (!handler_.setLastFunctionFormalParameterDefault(funNode, | ||||
| 2800 | def_expr)) { | ||||
| 2801 | return false; | ||||
| 2802 | } | ||||
| 2803 | } | ||||
| 2804 | |||||
| 2805 | // Setter syntax uniquely requires exactly one argument. | ||||
| 2806 | if (kind == FunctionSyntaxKind::Setter) { | ||||
| 2807 | break; | ||||
| 2808 | } | ||||
| 2809 | |||||
| 2810 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 2811 | TokenStream::SlashIsRegExp)) { | ||||
| 2812 | return false; | ||||
| 2813 | } | ||||
| 2814 | if (!matched) { | ||||
| 2815 | break; | ||||
| 2816 | } | ||||
| 2817 | |||||
| 2818 | if (!hasRest) { | ||||
| 2819 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 2820 | return false; | ||||
| 2821 | } | ||||
| 2822 | if (tt == TokenKind::RightParen) { | ||||
| 2823 | break; | ||||
| 2824 | } | ||||
| 2825 | } | ||||
| 2826 | } | ||||
| 2827 | |||||
| 2828 | TokenKind tt; | ||||
| 2829 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 2830 | return false; | ||||
| 2831 | } | ||||
| 2832 | if (tt != TokenKind::RightParen) { | ||||
| 2833 | if (kind == FunctionSyntaxKind::Setter) { | ||||
| 2834 | error(JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", ""); | ||||
| 2835 | return false; | ||||
| 2836 | } | ||||
| 2837 | |||||
| 2838 | error(JSMSG_PAREN_AFTER_FORMAL); | ||||
| 2839 | return false; | ||||
| 2840 | } | ||||
| 2841 | |||||
| 2842 | if (!hasDefault) { | ||||
| 2843 | funbox->setLength(positionalFormals.length() - hasRest); | ||||
| 2844 | } | ||||
| 2845 | |||||
| 2846 | funbox->setArgCount(positionalFormals.length()); | ||||
| 2847 | } else if (kind == FunctionSyntaxKind::Setter) { | ||||
| 2848 | error(JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", ""); | ||||
| 2849 | return false; | ||||
| 2850 | } | ||||
| 2851 | |||||
| 2852 | return true; | ||||
| 2853 | } | ||||
| 2854 | |||||
| 2855 | template <typename Unit> | ||||
| 2856 | bool Parser<FullParseHandler, Unit>::skipLazyInnerFunction( | ||||
| 2857 | FunctionNode* funNode, uint32_t toStringStart, bool tryAnnexB) { | ||||
| 2858 | // When a lazily-parsed function is called, we only fully parse (and emit) | ||||
| 2859 | // that function, not any of its nested children. The initial syntax-only | ||||
| 2860 | // parse recorded the free variables of nested functions and their extents, | ||||
| 2861 | // so we can skip over them after accounting for their free variables. | ||||
| 2862 | |||||
| 2863 | MOZ_ASSERT(pc_->isOutermostOfCurrentCompile())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isOutermostOfCurrentCompile())>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(pc_->isOutermostOfCurrentCompile()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isOutermostOfCurrentCompile()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2863); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isOutermostOfCurrentCompile()" ")" ); do { MOZ_CrashSequence(__null, 2863); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2864 | handler_.nextLazyInnerFunction(); | ||||
| 2865 | const ScriptStencil& cachedData = handler_.cachedScriptData(); | ||||
| 2866 | const ScriptStencilExtra& cachedExtra = handler_.cachedScriptExtra(); | ||||
| 2867 | MOZ_ASSERT(toStringStart == cachedExtra.extent.toStringStart)do { static_assert( mozilla::detail::AssertionConditionType< decltype(toStringStart == cachedExtra.extent.toStringStart)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(toStringStart == cachedExtra.extent.toStringStart))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("toStringStart == cachedExtra.extent.toStringStart" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2867); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "toStringStart == cachedExtra.extent.toStringStart" ")"); do { MOZ_CrashSequence(__null, 2867); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2868 | |||||
| 2869 | FunctionBox* funbox = newFunctionBox(funNode, cachedData, cachedExtra); | ||||
| 2870 | if (!funbox) { | ||||
| 2871 | return false; | ||||
| 2872 | } | ||||
| 2873 | |||||
| 2874 | ScriptStencil& script = funbox->functionStencil(); | ||||
| 2875 | funbox->copyFunctionFields(script); | ||||
| 2876 | |||||
| 2877 | // If the inner lazy function is class constructor, connect it to the class | ||||
| 2878 | // statement/expression we are parsing. | ||||
| 2879 | if (funbox->isClassConstructor()) { | ||||
| 2880 | auto classStmt = | ||||
| 2881 | pc_->template findInnermostStatement<ParseContext::ClassStatement>(); | ||||
| 2882 | MOZ_ASSERT(!classStmt->constructorBox)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!classStmt->constructorBox)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!classStmt->constructorBox ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "!classStmt->constructorBox", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 2882); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!classStmt->constructorBox" ")"); do { MOZ_CrashSequence(__null, 2882); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 2883 | classStmt->constructorBox = funbox; | ||||
| 2884 | } | ||||
| 2885 | |||||
| 2886 | MOZ_ASSERT_IF(pc_->isFunctionBox(),do { if (pc_->isFunctionBox()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(pc_->functionBox ()->index() < funbox->index())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->functionBox()->index () < funbox->index()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("pc_->functionBox()->index() < funbox->index()", "/root/firefox-clang/js/src/frontend/Parser.cpp", 2887); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->functionBox()->index() < funbox->index()" ")"); do { MOZ_CrashSequence(__null, 2887); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 2887 | pc_->functionBox()->index() < funbox->index())do { if (pc_->isFunctionBox()) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(pc_->functionBox ()->index() < funbox->index())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->functionBox()->index () < funbox->index()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("pc_->functionBox()->index() < funbox->index()", "/root/firefox-clang/js/src/frontend/Parser.cpp", 2887); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->functionBox()->index() < funbox->index()" ")"); do { MOZ_CrashSequence(__null, 2887); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 2888 | |||||
| 2889 | PropagateTransitiveParseFlags(funbox, pc_->sc()); | ||||
| 2890 | |||||
| 2891 | if (!tokenStream.advance(funbox->extent().sourceEnd)) { | ||||
| 2892 | return false; | ||||
| 2893 | } | ||||
| 2894 | |||||
| 2895 | // Append possible Annex B function box only upon successfully parsing. | ||||
| 2896 | if (tryAnnexB && | ||||
| 2897 | !pc_->innermostScope()->addPossibleAnnexBFunctionBox(pc_, funbox)) { | ||||
| 2898 | return false; | ||||
| 2899 | } | ||||
| 2900 | |||||
| 2901 | return true; | ||||
| 2902 | } | ||||
| 2903 | |||||
| 2904 | template <typename Unit> | ||||
| 2905 | bool Parser<SyntaxParseHandler, Unit>::skipLazyInnerFunction( | ||||
| 2906 | FunctionNodeType funNode, uint32_t toStringStart, bool tryAnnexB) { | ||||
| 2907 | MOZ_CRASH("Cannot skip lazy inner functions when syntax parsing")do { do { } while (false); MOZ_ReportCrash("" "Cannot skip lazy inner functions when syntax parsing" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 2907); AnnotateMozCrashReason ("MOZ_CRASH(" "Cannot skip lazy inner functions when syntax parsing" ")"); do { MOZ_CrashSequence(__null, 2907); __attribute__((nomerge )) ::abort(); } while (false); } while (false); | ||||
| 2908 | } | ||||
| 2909 | |||||
| 2910 | template <class ParseHandler, typename Unit> | ||||
| 2911 | bool GeneralParser<ParseHandler, Unit>::skipLazyInnerFunction( | ||||
| 2912 | FunctionNodeType funNode, uint32_t toStringStart, bool tryAnnexB) { | ||||
| 2913 | return asFinalParser()->skipLazyInnerFunction(funNode, toStringStart, | ||||
| 2914 | tryAnnexB); | ||||
| 2915 | } | ||||
| 2916 | |||||
| 2917 | template <class ParseHandler, typename Unit> | ||||
| 2918 | bool GeneralParser<ParseHandler, Unit>::addExprAndGetNextTemplStrToken( | ||||
| 2919 | YieldHandling yieldHandling, ListNodeType nodeList, TokenKind* ttp) { | ||||
| 2920 | Node pn; | ||||
| 2921 | MOZ_TRY_VAR_OR_RETURN(pn, expr(InAllowed, yieldHandling, TripledotProhibited),do { auto parserTryVarTempResult_ = (expr(InAllowed, yieldHandling , TripledotProhibited)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (pn) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 2922 | false)do { auto parserTryVarTempResult_ = (expr(InAllowed, yieldHandling , TripledotProhibited)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (pn) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 2923 | handler_.addList(nodeList, pn); | ||||
| 2924 | |||||
| 2925 | TokenKind tt; | ||||
| 2926 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 2927 | return false; | ||||
| 2928 | } | ||||
| 2929 | if (tt != TokenKind::RightCurly) { | ||||
| 2930 | error(JSMSG_TEMPLSTR_UNTERM_EXPR); | ||||
| 2931 | return false; | ||||
| 2932 | } | ||||
| 2933 | |||||
| 2934 | return tokenStream.getTemplateToken(ttp); | ||||
| 2935 | } | ||||
| 2936 | |||||
| 2937 | template <class ParseHandler, typename Unit> | ||||
| 2938 | bool GeneralParser<ParseHandler, Unit>::taggedTemplate( | ||||
| 2939 | YieldHandling yieldHandling, ListNodeType tagArgsList, TokenKind tt) { | ||||
| 2940 | CallSiteNodeType callSiteObjNode; | ||||
| 2941 | MOZ_TRY_VAR_OR_RETURN(callSiteObjNode,do { auto parserTryVarTempResult_ = (handler_.newCallSiteObject (pos().begin)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (callSiteObjNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 2942 | handler_.newCallSiteObject(pos().begin), false)do { auto parserTryVarTempResult_ = (handler_.newCallSiteObject (pos().begin)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (callSiteObjNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 2943 | handler_.addList(tagArgsList, callSiteObjNode); | ||||
| 2944 | |||||
| 2945 | pc_->sc()->setHasCallSiteObj(); | ||||
| 2946 | |||||
| 2947 | while (true) { | ||||
| 2948 | if (!appendToCallSiteObj(callSiteObjNode)) { | ||||
| 2949 | return false; | ||||
| 2950 | } | ||||
| 2951 | if (tt != TokenKind::TemplateHead) { | ||||
| 2952 | break; | ||||
| 2953 | } | ||||
| 2954 | |||||
| 2955 | if (!addExprAndGetNextTemplStrToken(yieldHandling, tagArgsList, &tt)) { | ||||
| 2956 | return false; | ||||
| 2957 | } | ||||
| 2958 | } | ||||
| 2959 | handler_.setEndPosition(tagArgsList, callSiteObjNode); | ||||
| 2960 | return true; | ||||
| 2961 | } | ||||
| 2962 | |||||
| 2963 | template <class ParseHandler, typename Unit> | ||||
| 2964 | typename ParseHandler::ListNodeResult | ||||
| 2965 | GeneralParser<ParseHandler, Unit>::templateLiteral( | ||||
| 2966 | YieldHandling yieldHandling) { | ||||
| 2967 | NameNodeType literal = MOZ_TRY(noSubstitutionUntaggedTemplate())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (noSubstitutionUntaggedTemplate()); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2968 | |||||
| 2969 | ListNodeType nodeList = | ||||
| 2970 | MOZ_TRY(handler_.newList(ParseNodeKind::TemplateStringListExpr, literal))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newList(ParseNodeKind::TemplateStringListExpr, literal )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 2971 | |||||
| 2972 | TokenKind tt; | ||||
| 2973 | do { | ||||
| 2974 | if (!addExprAndGetNextTemplStrToken(yieldHandling, nodeList, &tt)) { | ||||
| 2975 | return errorResult(); | ||||
| 2976 | } | ||||
| 2977 | |||||
| 2978 | literal = MOZ_TRY(noSubstitutionUntaggedTemplate())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (noSubstitutionUntaggedTemplate()); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 2979 | |||||
| 2980 | handler_.addList(nodeList, literal); | ||||
| 2981 | } while (tt == TokenKind::TemplateHead); | ||||
| 2982 | return nodeList; | ||||
| 2983 | } | ||||
| 2984 | |||||
| 2985 | template <class ParseHandler, typename Unit> | ||||
| 2986 | typename ParseHandler::FunctionNodeResult | ||||
| 2987 | GeneralParser<ParseHandler, Unit>::functionDefinition( | ||||
| 2988 | FunctionNodeType funNode, uint32_t toStringStart, InHandling inHandling, | ||||
| 2989 | YieldHandling yieldHandling, TaggedParserAtomIndex funName, | ||||
| 2990 | FunctionSyntaxKind kind, GeneratorKind generatorKind, | ||||
| 2991 | FunctionAsyncKind asyncKind, bool tryAnnexB /* = false */) { | ||||
| 2992 | MOZ_ASSERT_IF(kind == FunctionSyntaxKind::Statement, funName)do { if (kind == FunctionSyntaxKind::Statement) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(funName )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(funName))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("funName", "/root/firefox-clang/js/src/frontend/Parser.cpp", 2992); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funName" ")" ); do { MOZ_CrashSequence(__null, 2992); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 2993 | |||||
| 2994 | // If we see any inner function, note it on our current context. The bytecode | ||||
| 2995 | // emitter may eliminate the function later, but we use a conservative | ||||
| 2996 | // definition for consistency between lazy and full parsing. | ||||
| 2997 | pc_->sc()->setHasInnerFunctions(); | ||||
| 2998 | |||||
| 2999 | // When fully parsing a lazy script, we do not fully reparse its inner | ||||
| 3000 | // functions, which are also lazy. Instead, their free variables and source | ||||
| 3001 | // extents are recorded and may be skipped. | ||||
| 3002 | if (handler_.reuseLazyInnerFunctions()) { | ||||
| 3003 | if (!skipLazyInnerFunction(funNode, toStringStart, tryAnnexB)) { | ||||
| 3004 | return errorResult(); | ||||
| 3005 | } | ||||
| 3006 | |||||
| 3007 | return funNode; | ||||
| 3008 | } | ||||
| 3009 | |||||
| 3010 | bool isSelfHosting = options().selfHostingMode; | ||||
| 3011 | FunctionFlags flags = | ||||
| 3012 | InitialFunctionFlags(kind, generatorKind, asyncKind, isSelfHosting); | ||||
| 3013 | |||||
| 3014 | // Self-hosted functions with special function names require extended slots | ||||
| 3015 | // for various purposes. | ||||
| 3016 | bool forceExtended = | ||||
| 3017 | isSelfHosting && funName && | ||||
| 3018 | this->parserAtoms().isExtendedUnclonedSelfHostedFunctionName(funName); | ||||
| 3019 | if (forceExtended) { | ||||
| 3020 | flags.setIsExtended(); | ||||
| 3021 | } | ||||
| 3022 | |||||
| 3023 | // Speculatively parse using the directives of the parent parsing context. | ||||
| 3024 | // If a directive is encountered (e.g., "use strict") that changes how the | ||||
| 3025 | // function should have been parsed, we backup and reparse with the new set | ||||
| 3026 | // of directives. | ||||
| 3027 | Directives directives(pc_); | ||||
| 3028 | Directives newDirectives = directives; | ||||
| 3029 | |||||
| 3030 | Position start(tokenStream); | ||||
| 3031 | auto startObj = this->compilationState_.getPosition(); | ||||
| 3032 | |||||
| 3033 | // Parse the inner function. The following is a loop as we may attempt to | ||||
| 3034 | // reparse a function due to failed syntax parsing and encountering new | ||||
| 3035 | // "use foo" directives. | ||||
| 3036 | while (true) { | ||||
| 3037 | if (trySyntaxParseInnerFunction(&funNode, funName, flags, toStringStart, | ||||
| 3038 | inHandling, yieldHandling, kind, | ||||
| 3039 | generatorKind, asyncKind, tryAnnexB, | ||||
| 3040 | directives, &newDirectives)) { | ||||
| 3041 | break; | ||||
| 3042 | } | ||||
| 3043 | |||||
| 3044 | // Return on error. | ||||
| 3045 | if (anyChars.hadError() || directives == newDirectives) { | ||||
| 3046 | return errorResult(); | ||||
| 3047 | } | ||||
| 3048 | |||||
| 3049 | // Assignment must be monotonic to prevent infinitely attempting to | ||||
| 3050 | // reparse. | ||||
| 3051 | MOZ_ASSERT_IF(directives.strict(), newDirectives.strict())do { if (directives.strict()) { do { static_assert( mozilla:: detail::AssertionConditionType<decltype(newDirectives.strict ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(newDirectives.strict()))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("newDirectives.strict()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 3051); AnnotateMozCrashReason("MOZ_ASSERT" "(" "newDirectives.strict()" ")"); do { MOZ_CrashSequence(__null, 3051); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 3052 | directives = newDirectives; | ||||
| 3053 | |||||
| 3054 | // Rewind to retry parsing with new directives applied. | ||||
| 3055 | tokenStream.rewind(start); | ||||
| 3056 | this->compilationState_.rewind(startObj); | ||||
| 3057 | |||||
| 3058 | // functionFormalParametersAndBody may have already set body before failing. | ||||
| 3059 | handler_.setFunctionFormalParametersAndBody(funNode, null()); | ||||
| 3060 | } | ||||
| 3061 | |||||
| 3062 | return funNode; | ||||
| 3063 | } | ||||
| 3064 | |||||
| 3065 | template <typename Unit> | ||||
| 3066 | bool Parser<FullParseHandler, Unit>::advancePastSyntaxParsedFunction( | ||||
| 3067 | SyntaxParser* syntaxParser) { | ||||
| 3068 | MOZ_ASSERT(getSyntaxParser() == syntaxParser)do { static_assert( mozilla::detail::AssertionConditionType< decltype(getSyntaxParser() == syntaxParser)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(getSyntaxParser() == syntaxParser ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "getSyntaxParser() == syntaxParser", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 3068); AnnotateMozCrashReason("MOZ_ASSERT" "(" "getSyntaxParser() == syntaxParser" ")"); do { MOZ_CrashSequence(__null, 3068); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3069 | |||||
| 3070 | // Advance this parser over tokens processed by the syntax parser. | ||||
| 3071 | Position currentSyntaxPosition(syntaxParser->tokenStream); | ||||
| 3072 | if (!tokenStream.fastForward(currentSyntaxPosition, syntaxParser->anyChars)) { | ||||
| 3073 | return false; | ||||
| 3074 | } | ||||
| 3075 | |||||
| 3076 | anyChars.adoptState(syntaxParser->anyChars); | ||||
| 3077 | tokenStream.adoptState(syntaxParser->tokenStream); | ||||
| 3078 | return true; | ||||
| 3079 | } | ||||
| 3080 | |||||
| 3081 | template <typename Unit> | ||||
| 3082 | bool Parser<FullParseHandler, Unit>::trySyntaxParseInnerFunction( | ||||
| 3083 | FunctionNode** funNode, TaggedParserAtomIndex explicitName, | ||||
| 3084 | FunctionFlags flags, uint32_t toStringStart, InHandling inHandling, | ||||
| 3085 | YieldHandling yieldHandling, FunctionSyntaxKind kind, | ||||
| 3086 | GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB, | ||||
| 3087 | Directives inheritedDirectives, Directives* newDirectives) { | ||||
| 3088 | // Try a syntax parse for this inner function. | ||||
| 3089 | do { | ||||
| 3090 | // If we're assuming this function is an IIFE, always perform a full | ||||
| 3091 | // parse to avoid the overhead of a lazy syntax-only parse. Although | ||||
| 3092 | // the prediction may be incorrect, IIFEs are common enough that it | ||||
| 3093 | // pays off for lots of code. | ||||
| 3094 | if ((*funNode)->isLikelyIIFE() && | ||||
| 3095 | generatorKind == GeneratorKind::NotGenerator && | ||||
| 3096 | asyncKind == FunctionAsyncKind::SyncFunction) { | ||||
| 3097 | break; | ||||
| 3098 | } | ||||
| 3099 | |||||
| 3100 | SyntaxParser* syntaxParser = getSyntaxParser(); | ||||
| 3101 | if (!syntaxParser) { | ||||
| 3102 | break; | ||||
| 3103 | } | ||||
| 3104 | |||||
| 3105 | UsedNameTracker::RewindToken token = usedNames_.getRewindToken(); | ||||
| 3106 | auto statePosition = this->compilationState_.getPosition(); | ||||
| 3107 | |||||
| 3108 | // Move the syntax parser to the current position in the stream. In the | ||||
| 3109 | // common case this seeks forward, but it'll also seek backward *at least* | ||||
| 3110 | // when arrow functions appear inside arrow function argument defaults | ||||
| 3111 | // (because we rewind to reparse arrow functions once we're certain they're | ||||
| 3112 | // arrow functions): | ||||
| 3113 | // | ||||
| 3114 | // var x = (y = z => 2) => q; | ||||
| 3115 | // // ^ we first seek to here to syntax-parse this function | ||||
| 3116 | // // ^ then we seek back to here to syntax-parse the outer function | ||||
| 3117 | Position currentPosition(tokenStream); | ||||
| 3118 | if (!syntaxParser->tokenStream.seekTo(currentPosition, anyChars)) { | ||||
| 3119 | return false; | ||||
| 3120 | } | ||||
| 3121 | |||||
| 3122 | // Make a FunctionBox before we enter the syntax parser, because |pn| | ||||
| 3123 | // still expects a FunctionBox to be attached to it during BCE, and | ||||
| 3124 | // the syntax parser cannot attach one to it. | ||||
| 3125 | FunctionBox* funbox = | ||||
| 3126 | newFunctionBox(*funNode, explicitName, flags, toStringStart, | ||||
| 3127 | inheritedDirectives, generatorKind, asyncKind); | ||||
| 3128 | if (!funbox) { | ||||
| 3129 | return false; | ||||
| 3130 | } | ||||
| 3131 | funbox->initWithEnclosingParseContext(pc_, kind); | ||||
| 3132 | |||||
| 3133 | auto syntaxNodeResult = syntaxParser->innerFunctionForFunctionBox( | ||||
| 3134 | SyntaxParseHandler::Node::NodeGeneric, pc_, funbox, inHandling, | ||||
| 3135 | yieldHandling, kind, newDirectives); | ||||
| 3136 | if (syntaxNodeResult.isErr()) { | ||||
| 3137 | if (syntaxParser->hadAbortedSyntaxParse()) { | ||||
| 3138 | // Try again with a full parse. UsedNameTracker needs to be | ||||
| 3139 | // rewound to just before we tried the syntax parse for | ||||
| 3140 | // correctness. | ||||
| 3141 | syntaxParser->clearAbortedSyntaxParse(); | ||||
| 3142 | usedNames_.rewind(token); | ||||
| 3143 | this->compilationState_.rewind(statePosition); | ||||
| 3144 | MOZ_ASSERT(!fc_->hadErrors())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!fc_->hadErrors())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!fc_->hadErrors()))), 0)) ) { do { } while (false); MOZ_ReportAssertionFailure("!fc_->hadErrors()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3144); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!fc_->hadErrors()" ")"); do { MOZ_CrashSequence (__null, 3144); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 3145 | break; | ||||
| 3146 | } | ||||
| 3147 | return false; | ||||
| 3148 | } | ||||
| 3149 | |||||
| 3150 | if (!advancePastSyntaxParsedFunction(syntaxParser)) { | ||||
| 3151 | return false; | ||||
| 3152 | } | ||||
| 3153 | |||||
| 3154 | // Update the end position of the parse node. | ||||
| 3155 | (*funNode)->pn_pos.end = anyChars.currentToken().pos.end; | ||||
| 3156 | |||||
| 3157 | // Append possible Annex B function box only upon successfully parsing. | ||||
| 3158 | if (tryAnnexB) { | ||||
| 3159 | if (!pc_->innermostScope()->addPossibleAnnexBFunctionBox(pc_, funbox)) { | ||||
| 3160 | return false; | ||||
| 3161 | } | ||||
| 3162 | } | ||||
| 3163 | |||||
| 3164 | return true; | ||||
| 3165 | } while (false); | ||||
| 3166 | |||||
| 3167 | // We failed to do a syntax parse above, so do the full parse. | ||||
| 3168 | FunctionNodeType innerFunc; | ||||
| 3169 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3170 | innerFunc,do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3171 | innerFunction(*funNode, pc_, explicitName, flags, toStringStart,do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3172 | inHandling, yieldHandling, kind, generatorKind, asyncKind,do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3173 | tryAnnexB, inheritedDirectives, newDirectives),do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3174 | false)do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 3175 | |||||
| 3176 | *funNode = innerFunc; | ||||
| 3177 | return true; | ||||
| 3178 | } | ||||
| 3179 | |||||
| 3180 | template <typename Unit> | ||||
| 3181 | bool Parser<SyntaxParseHandler, Unit>::trySyntaxParseInnerFunction( | ||||
| 3182 | FunctionNodeType* funNode, TaggedParserAtomIndex explicitName, | ||||
| 3183 | FunctionFlags flags, uint32_t toStringStart, InHandling inHandling, | ||||
| 3184 | YieldHandling yieldHandling, FunctionSyntaxKind kind, | ||||
| 3185 | GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB, | ||||
| 3186 | Directives inheritedDirectives, Directives* newDirectives) { | ||||
| 3187 | // This is already a syntax parser, so just parse the inner function. | ||||
| 3188 | FunctionNodeType innerFunc; | ||||
| 3189 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3190 | innerFunc,do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3191 | innerFunction(*funNode, pc_, explicitName, flags, toStringStart,do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3192 | inHandling, yieldHandling, kind, generatorKind, asyncKind,do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3193 | tryAnnexB, inheritedDirectives, newDirectives),do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3194 | false)do { auto parserTryVarTempResult_ = (innerFunction(*funNode, pc_ , explicitName, flags, toStringStart, inHandling, yieldHandling , kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives , newDirectives)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (innerFunc) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 3195 | |||||
| 3196 | *funNode = innerFunc; | ||||
| 3197 | return true; | ||||
| 3198 | } | ||||
| 3199 | |||||
| 3200 | template <class ParseHandler, typename Unit> | ||||
| 3201 | inline bool GeneralParser<ParseHandler, Unit>::trySyntaxParseInnerFunction( | ||||
| 3202 | FunctionNodeType* funNode, TaggedParserAtomIndex explicitName, | ||||
| 3203 | FunctionFlags flags, uint32_t toStringStart, InHandling inHandling, | ||||
| 3204 | YieldHandling yieldHandling, FunctionSyntaxKind kind, | ||||
| 3205 | GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB, | ||||
| 3206 | Directives inheritedDirectives, Directives* newDirectives) { | ||||
| 3207 | return asFinalParser()->trySyntaxParseInnerFunction( | ||||
| 3208 | funNode, explicitName, flags, toStringStart, inHandling, yieldHandling, | ||||
| 3209 | kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives, | ||||
| 3210 | newDirectives); | ||||
| 3211 | } | ||||
| 3212 | |||||
| 3213 | template <class ParseHandler, typename Unit> | ||||
| 3214 | typename ParseHandler::FunctionNodeResult | ||||
| 3215 | GeneralParser<ParseHandler, Unit>::innerFunctionForFunctionBox( | ||||
| 3216 | FunctionNodeType funNode, ParseContext* outerpc, FunctionBox* funbox, | ||||
| 3217 | InHandling inHandling, YieldHandling yieldHandling, FunctionSyntaxKind kind, | ||||
| 3218 | Directives* newDirectives) { | ||||
| 3219 | // Note that it is possible for outerpc != this->pc_, as we may be | ||||
| 3220 | // attempting to syntax parse an inner function from an outer full | ||||
| 3221 | // parser. In that case, outerpc is a SourceParseContext from the full parser | ||||
| 3222 | // instead of the current top of the stack of the syntax parser. | ||||
| 3223 | |||||
| 3224 | // Push a new ParseContext. | ||||
| 3225 | SourceParseContext funpc(this, funbox, newDirectives); | ||||
| 3226 | if (!funpc.init()) { | ||||
| 3227 | return errorResult(); | ||||
| 3228 | } | ||||
| 3229 | |||||
| 3230 | if (!functionFormalParametersAndBody(inHandling, yieldHandling, &funNode, | ||||
| 3231 | kind)) { | ||||
| 3232 | return errorResult(); | ||||
| 3233 | } | ||||
| 3234 | |||||
| 3235 | if (!leaveInnerFunction(outerpc)) { | ||||
| 3236 | return errorResult(); | ||||
| 3237 | } | ||||
| 3238 | |||||
| 3239 | return funNode; | ||||
| 3240 | } | ||||
| 3241 | |||||
| 3242 | template <class ParseHandler, typename Unit> | ||||
| 3243 | typename ParseHandler::FunctionNodeResult | ||||
| 3244 | GeneralParser<ParseHandler, Unit>::innerFunction( | ||||
| 3245 | FunctionNodeType funNode, ParseContext* outerpc, | ||||
| 3246 | TaggedParserAtomIndex explicitName, FunctionFlags flags, | ||||
| 3247 | uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, | ||||
| 3248 | FunctionSyntaxKind kind, GeneratorKind generatorKind, | ||||
| 3249 | FunctionAsyncKind asyncKind, bool tryAnnexB, Directives inheritedDirectives, | ||||
| 3250 | Directives* newDirectives) { | ||||
| 3251 | // Note that it is possible for outerpc != this->pc_, as we may be | ||||
| 3252 | // attempting to syntax parse an inner function from an outer full | ||||
| 3253 | // parser. In that case, outerpc is a SourceParseContext from the full parser | ||||
| 3254 | // instead of the current top of the stack of the syntax parser. | ||||
| 3255 | |||||
| 3256 | FunctionBox* funbox = | ||||
| 3257 | newFunctionBox(funNode, explicitName, flags, toStringStart, | ||||
| 3258 | inheritedDirectives, generatorKind, asyncKind); | ||||
| 3259 | if (!funbox) { | ||||
| 3260 | return errorResult(); | ||||
| 3261 | } | ||||
| 3262 | funbox->initWithEnclosingParseContext(outerpc, kind); | ||||
| 3263 | |||||
| 3264 | FunctionNodeType innerFunc = | ||||
| 3265 | MOZ_TRY(innerFunctionForFunctionBox(funNode, outerpc, funbox, inHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (innerFunctionForFunctionBox(funNode, outerpc, funbox, inHandling , yieldHandling, kind, newDirectives)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 3266 | yieldHandling, kind, newDirectives))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (innerFunctionForFunctionBox(funNode, outerpc, funbox, inHandling , yieldHandling, kind, newDirectives)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 3267 | |||||
| 3268 | // Append possible Annex B function box only upon successfully parsing. | ||||
| 3269 | if (tryAnnexB) { | ||||
| 3270 | if (!pc_->innermostScope()->addPossibleAnnexBFunctionBox(pc_, funbox)) { | ||||
| 3271 | return errorResult(); | ||||
| 3272 | } | ||||
| 3273 | } | ||||
| 3274 | |||||
| 3275 | return innerFunc; | ||||
| 3276 | } | ||||
| 3277 | |||||
| 3278 | template <class ParseHandler, typename Unit> | ||||
| 3279 | bool GeneralParser<ParseHandler, Unit>::appendToCallSiteObj( | ||||
| 3280 | CallSiteNodeType callSiteObj) { | ||||
| 3281 | Node cookedNode; | ||||
| 3282 | MOZ_TRY_VAR_OR_RETURN(cookedNode, noSubstitutionTaggedTemplate(), false)do { auto parserTryVarTempResult_ = (noSubstitutionTaggedTemplate ()); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr() ), 0))) { return (false); } (cookedNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 3283 | |||||
| 3284 | auto atom = tokenStream.getRawTemplateStringAtom(); | ||||
| 3285 | if (!atom) { | ||||
| 3286 | return false; | ||||
| 3287 | } | ||||
| 3288 | NameNodeType rawNode; | ||||
| 3289 | MOZ_TRY_VAR_OR_RETURN(rawNode, handler_.newTemplateStringLiteral(atom, pos()),do { auto parserTryVarTempResult_ = (handler_.newTemplateStringLiteral (atom, pos())); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (rawNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 3290 | false)do { auto parserTryVarTempResult_ = (handler_.newTemplateStringLiteral (atom, pos())); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (rawNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 3291 | |||||
| 3292 | handler_.addToCallSiteObject(callSiteObj, rawNode, cookedNode); | ||||
| 3293 | return true; | ||||
| 3294 | } | ||||
| 3295 | |||||
| 3296 | template <typename Unit> | ||||
| 3297 | FullParseHandler::FunctionNodeResult | ||||
| 3298 | Parser<FullParseHandler, Unit>::standaloneLazyFunction( | ||||
| 3299 | CompilationInput& input, uint32_t toStringStart, bool strict, | ||||
| 3300 | GeneratorKind generatorKind, FunctionAsyncKind asyncKind) { | ||||
| 3301 | MOZ_ASSERT(checkOptionsCalled_)do { static_assert( mozilla::detail::AssertionConditionType< decltype(checkOptionsCalled_)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(checkOptionsCalled_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("checkOptionsCalled_" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3301); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence (__null, 3301); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 3302 | |||||
| 3303 | FunctionSyntaxKind syntaxKind = input.functionSyntaxKind(); | ||||
| 3304 | FunctionNodeType funNode = MOZ_TRY(handler_.newFunction(syntaxKind, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 3305 | |||||
| 3306 | TaggedParserAtomIndex displayAtom = | ||||
| 3307 | this->getCompilationState().previousParseCache.displayAtom(); | ||||
| 3308 | |||||
| 3309 | Directives directives(strict); | ||||
| 3310 | FunctionBox* funbox = | ||||
| 3311 | newFunctionBox(funNode, displayAtom, input.functionFlags(), toStringStart, | ||||
| 3312 | directives, generatorKind, asyncKind); | ||||
| 3313 | if (!funbox) { | ||||
| 3314 | return errorResult(); | ||||
| 3315 | } | ||||
| 3316 | const ScriptStencilExtra& funExtra = | ||||
| 3317 | this->getCompilationState().previousParseCache.funExtra(); | ||||
| 3318 | funbox->initFromLazyFunction( | ||||
| 3319 | funExtra, this->getCompilationState().scopeContext, syntaxKind); | ||||
| 3320 | if (funbox->useMemberInitializers()) { | ||||
| 3321 | funbox->setMemberInitializers(funExtra.memberInitializers()); | ||||
| 3322 | } | ||||
| 3323 | |||||
| 3324 | Directives newDirectives = directives; | ||||
| 3325 | SourceParseContext funpc(this, funbox, &newDirectives); | ||||
| 3326 | if (!funpc.init()) { | ||||
| 3327 | return errorResult(); | ||||
| 3328 | } | ||||
| 3329 | |||||
| 3330 | // Our tokenStream has no current token, so funNode's position is garbage. | ||||
| 3331 | // Substitute the position of the first token in our source. If the | ||||
| 3332 | // function is a not-async arrow, use TokenStream::SlashIsRegExp to keep | ||||
| 3333 | // verifyConsistentModifier from complaining (we will use | ||||
| 3334 | // TokenStream::SlashIsRegExp in functionArguments). | ||||
| 3335 | Modifier modifier = (input.functionFlags().isArrow() && | ||||
| 3336 | asyncKind == FunctionAsyncKind::SyncFunction) | ||||
| 3337 | ? TokenStream::SlashIsRegExp | ||||
| 3338 | : TokenStream::SlashIsDiv; | ||||
| 3339 | if (!tokenStream.peekTokenPos(&funNode->pn_pos, modifier)) { | ||||
| 3340 | return errorResult(); | ||||
| 3341 | } | ||||
| 3342 | |||||
| 3343 | YieldHandling yieldHandling = GetYieldHandling(generatorKind); | ||||
| 3344 | |||||
| 3345 | if (funbox->isSyntheticFunction()) { | ||||
| 3346 | // Currently default class constructors are the only synthetic function that | ||||
| 3347 | // supports delazification. | ||||
| 3348 | MOZ_ASSERT(funbox->isClassConstructor())do { static_assert( mozilla::detail::AssertionConditionType< decltype(funbox->isClassConstructor())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(funbox->isClassConstructor ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("funbox->isClassConstructor()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 3348); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isClassConstructor()" ")"); do { MOZ_CrashSequence(__null, 3348); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3349 | MOZ_ASSERT(funbox->extent().toStringStart == funbox->extent().sourceStart)do { static_assert( mozilla::detail::AssertionConditionType< decltype(funbox->extent().toStringStart == funbox->extent ().sourceStart)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(funbox->extent().toStringStart == funbox->extent().sourceStart))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("funbox->extent().toStringStart == funbox->extent().sourceStart" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3349); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "funbox->extent().toStringStart == funbox->extent().sourceStart" ")"); do { MOZ_CrashSequence(__null, 3349); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3350 | |||||
| 3351 | HasHeritage hasHeritage = funbox->isDerivedClassConstructor() | ||||
| 3352 | ? HasHeritage::Yes | ||||
| 3353 | : HasHeritage::No; | ||||
| 3354 | TokenPos synthesizedBodyPos(funbox->extent().toStringStart, | ||||
| 3355 | funbox->extent().toStringEnd); | ||||
| 3356 | |||||
| 3357 | // Reset pos() to the `class` keyword for predictable results. | ||||
| 3358 | tokenStream.consumeKnownToken(TokenKind::Class); | ||||
| 3359 | |||||
| 3360 | if (!this->synthesizeConstructorBody(synthesizedBodyPos, hasHeritage, | ||||
| 3361 | funNode, funbox)) { | ||||
| 3362 | return errorResult(); | ||||
| 3363 | } | ||||
| 3364 | } else { | ||||
| 3365 | if (!functionFormalParametersAndBody(InAllowed, yieldHandling, &funNode, | ||||
| 3366 | syntaxKind)) { | ||||
| 3367 | MOZ_ASSERT(directives == newDirectives)do { static_assert( mozilla::detail::AssertionConditionType< decltype(directives == newDirectives)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(directives == newDirectives) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("directives == newDirectives" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3367); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "directives == newDirectives" ")"); do { MOZ_CrashSequence (__null, 3367); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 3368 | return errorResult(); | ||||
| 3369 | } | ||||
| 3370 | } | ||||
| 3371 | |||||
| 3372 | if (!CheckParseTree(this->fc_, alloc_, funNode)) { | ||||
| 3373 | return errorResult(); | ||||
| 3374 | } | ||||
| 3375 | |||||
| 3376 | ParseNode* node = funNode; | ||||
| 3377 | if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node, | ||||
| 3378 | &handler_)) { | ||||
| 3379 | return errorResult(); | ||||
| 3380 | } | ||||
| 3381 | funNode = &node->as<FunctionNode>(); | ||||
| 3382 | |||||
| 3383 | return funNode; | ||||
| 3384 | } | ||||
| 3385 | |||||
| 3386 | void ParserBase::setFunctionEndFromCurrentToken(FunctionBox* funbox) const { | ||||
| 3387 | if (compilationState_.isInitialStencil()) { | ||||
| 3388 | MOZ_ASSERT(anyChars.currentToken().type != TokenKind::Eof)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.currentToken().type != TokenKind::Eof)>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.currentToken().type != TokenKind::Eof))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.currentToken().type != TokenKind::Eof" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3388); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.currentToken().type != TokenKind::Eof" ")"); do { MOZ_CrashSequence(__null, 3388); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3389 | MOZ_ASSERT(anyChars.currentToken().type < TokenKind::Limit)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.currentToken().type < TokenKind::Limit)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.currentToken().type < TokenKind::Limit)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.currentToken().type < TokenKind::Limit" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3389); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.currentToken().type < TokenKind::Limit" ")"); do { MOZ_CrashSequence(__null, 3389); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3390 | funbox->setEnd(anyChars.currentToken().pos.end); | ||||
| 3391 | } else { | ||||
| 3392 | // If we're delazifying an arrow function with expression body and | ||||
| 3393 | // the expression is also a function, we arrive here immediately after | ||||
| 3394 | // skipping the function by Parser::skipLazyInnerFunction. | ||||
| 3395 | // | ||||
| 3396 | // a => b => c | ||||
| 3397 | // ^ | ||||
| 3398 | // | | ||||
| 3399 | // we're here | ||||
| 3400 | // | ||||
| 3401 | // In that case, the current token's type field is either Limit or | ||||
| 3402 | // poisoned. | ||||
| 3403 | // We shouldn't read the value if it's poisoned. | ||||
| 3404 | // See TokenStreamSpecific<Unit, AnyCharsAccess>::advance and | ||||
| 3405 | // mfbt/MemoryChecking.h for more details. | ||||
| 3406 | // | ||||
| 3407 | // Also, in delazification, the FunctionBox should already have the | ||||
| 3408 | // correct extent, and we shouldn't overwrite it here. | ||||
| 3409 | // See ScriptStencil variant of PerHandlerParser::newFunctionBox. | ||||
| 3410 | #if !defined(MOZ_ASAN) && !defined(MOZ_MSAN) && !defined(MOZ_VALGRIND) | ||||
| 3411 | MOZ_ASSERT(anyChars.currentToken().type != TokenKind::Eof)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.currentToken().type != TokenKind::Eof)>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.currentToken().type != TokenKind::Eof))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.currentToken().type != TokenKind::Eof" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3411); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.currentToken().type != TokenKind::Eof" ")"); do { MOZ_CrashSequence(__null, 3411); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3412 | #endif | ||||
| 3413 | MOZ_ASSERT(funbox->extent().sourceEnd == anyChars.currentToken().pos.end)do { static_assert( mozilla::detail::AssertionConditionType< decltype(funbox->extent().sourceEnd == anyChars.currentToken ().pos.end)>::isValid, "invalid assertion condition"); if ( (__builtin_expect(!!(!(!!(funbox->extent().sourceEnd == anyChars .currentToken().pos.end))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("funbox->extent().sourceEnd == anyChars.currentToken().pos.end" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3413); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "funbox->extent().sourceEnd == anyChars.currentToken().pos.end" ")"); do { MOZ_CrashSequence(__null, 3413); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3414 | } | ||||
| 3415 | } | ||||
| 3416 | |||||
| 3417 | template <class ParseHandler, typename Unit> | ||||
| 3418 | bool GeneralParser<ParseHandler, Unit>::functionFormalParametersAndBody( | ||||
| 3419 | InHandling inHandling, YieldHandling yieldHandling, | ||||
| 3420 | FunctionNodeType* funNode, FunctionSyntaxKind kind, | ||||
| 3421 | const Maybe<uint32_t>& parameterListEnd /* = Nothing() */, | ||||
| 3422 | bool isStandaloneFunction /* = false */) { | ||||
| 3423 | // Given a properly initialized parse context, try to parse an actual | ||||
| 3424 | // function without concern for conversion to strict mode, use of lazy | ||||
| 3425 | // parsing and such. | ||||
| 3426 | |||||
| 3427 | FunctionBox* funbox = pc_->functionBox(); | ||||
| 3428 | |||||
| 3429 | if (kind == FunctionSyntaxKind::ClassConstructor || | ||||
| 3430 | kind == FunctionSyntaxKind::DerivedClassConstructor) { | ||||
| 3431 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_initializers_())) { | ||||
| 3432 | return false; | ||||
| 3433 | } | ||||
| 3434 | #ifdef ENABLE_DECORATORS | ||||
| 3435 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown:: | ||||
| 3436 | dot_instanceExtraInitializers_())) { | ||||
| 3437 | return false; | ||||
| 3438 | } | ||||
| 3439 | #endif | ||||
| 3440 | } | ||||
| 3441 | |||||
| 3442 | // See below for an explanation why arrow function parameters and arrow | ||||
| 3443 | // function bodies are parsed with different yield/await settings. | ||||
| 3444 | { | ||||
| 3445 | AwaitHandling awaitHandling = | ||||
| 3446 | kind == FunctionSyntaxKind::StaticClassBlock ? AwaitIsDisallowed | ||||
| 3447 | : (funbox->isAsync() || | ||||
| 3448 | (kind == FunctionSyntaxKind::Arrow && awaitIsKeyword())) | ||||
| 3449 | ? AwaitIsKeyword | ||||
| 3450 | : AwaitIsName; | ||||
| 3451 | AutoAwaitIsKeyword<ParseHandler, Unit> awaitIsKeyword(this, awaitHandling); | ||||
| 3452 | AutoInParametersOfAsyncFunction<ParseHandler, Unit> inParameters( | ||||
| 3453 | this, funbox->isAsync()); | ||||
| 3454 | if (!functionArguments(yieldHandling, kind, *funNode)) { | ||||
| 3455 | return false; | ||||
| 3456 | } | ||||
| 3457 | } | ||||
| 3458 | |||||
| 3459 | Maybe<ParseContext::VarScope> varScope; | ||||
| 3460 | if (funbox->hasParameterExprs) { | ||||
| 3461 | varScope.emplace(this); | ||||
| 3462 | if (!varScope->init(pc_)) { | ||||
| 3463 | return false; | ||||
| 3464 | } | ||||
| 3465 | } else { | ||||
| 3466 | pc_->functionScope().useAsVarScope(pc_); | ||||
| 3467 | } | ||||
| 3468 | |||||
| 3469 | if (kind == FunctionSyntaxKind::Arrow) { | ||||
| 3470 | TokenKind tt; | ||||
| 3471 | if (!tokenStream.peekTokenSameLine(&tt)) { | ||||
| 3472 | return false; | ||||
| 3473 | } | ||||
| 3474 | |||||
| 3475 | if (tt == TokenKind::Eol) { | ||||
| 3476 | error(JSMSG_UNEXPECTED_TOKEN, | ||||
| 3477 | "'=>' on the same line after an argument list", | ||||
| 3478 | TokenKindToDesc(tt)); | ||||
| 3479 | return false; | ||||
| 3480 | } | ||||
| 3481 | if (tt != TokenKind::Arrow) { | ||||
| 3482 | error(JSMSG_BAD_ARROW_ARGS); | ||||
| 3483 | return false; | ||||
| 3484 | } | ||||
| 3485 | tokenStream.consumeKnownToken(TokenKind::Arrow); | ||||
| 3486 | } | ||||
| 3487 | |||||
| 3488 | // When parsing something for new Function() we have to make sure to | ||||
| 3489 | // only treat a certain part of the source as a parameter list. | ||||
| 3490 | if (parameterListEnd.isSome() && parameterListEnd.value() != pos().begin) { | ||||
| 3491 | error(JSMSG_UNEXPECTED_PARAMLIST_END); | ||||
| 3492 | return false; | ||||
| 3493 | } | ||||
| 3494 | |||||
| 3495 | // Parse the function body. | ||||
| 3496 | FunctionBodyType bodyType = StatementListBody; | ||||
| 3497 | TokenKind tt; | ||||
| 3498 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 3499 | return false; | ||||
| 3500 | } | ||||
| 3501 | uint32_t openedPos = 0; | ||||
| 3502 | if (tt != TokenKind::LeftCurly) { | ||||
| 3503 | if (kind != FunctionSyntaxKind::Arrow) { | ||||
| 3504 | error(JSMSG_CURLY_BEFORE_BODY); | ||||
| 3505 | return false; | ||||
| 3506 | } | ||||
| 3507 | |||||
| 3508 | anyChars.ungetToken(); | ||||
| 3509 | bodyType = ExpressionBody; | ||||
| 3510 | funbox->setHasExprBody(); | ||||
| 3511 | } else { | ||||
| 3512 | openedPos = pos().begin; | ||||
| 3513 | } | ||||
| 3514 | |||||
| 3515 | // Arrow function parameters inherit yieldHandling from the enclosing | ||||
| 3516 | // context, but the arrow body doesn't. E.g. in |(a = yield) => yield|, | ||||
| 3517 | // |yield| in the parameters is either a name or keyword, depending on | ||||
| 3518 | // whether the arrow function is enclosed in a generator function or not. | ||||
| 3519 | // Whereas the |yield| in the function body is always parsed as a name. | ||||
| 3520 | // The same goes when parsing |await| in arrow functions. | ||||
| 3521 | YieldHandling bodyYieldHandling = GetYieldHandling(pc_->generatorKind()); | ||||
| 3522 | AwaitHandling bodyAwaitHandling = GetAwaitHandling(pc_->asyncKind()); | ||||
| 3523 | bool inheritedStrict = pc_->sc()->strict(); | ||||
| 3524 | LexicalScopeNodeType body; | ||||
| 3525 | { | ||||
| 3526 | AutoAwaitIsKeyword<ParseHandler, Unit> awaitIsKeyword(this, | ||||
| 3527 | bodyAwaitHandling); | ||||
| 3528 | AutoInParametersOfAsyncFunction<ParseHandler, Unit> inParameters(this, | ||||
| 3529 | false); | ||||
| 3530 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (functionBody(inHandling, bodyYieldHandling, kind, bodyType)); if ((__builtin_expect(! !(parserTryVarTempResult_.isErr()), 0))) { return (false); } ( body) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 3531 | body, functionBody(inHandling, bodyYieldHandling, kind, bodyType),do { auto parserTryVarTempResult_ = (functionBody(inHandling, bodyYieldHandling, kind, bodyType)); if ((__builtin_expect(! !(parserTryVarTempResult_.isErr()), 0))) { return (false); } ( body) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 3532 | false)do { auto parserTryVarTempResult_ = (functionBody(inHandling, bodyYieldHandling, kind, bodyType)); if ((__builtin_expect(! !(parserTryVarTempResult_.isErr()), 0))) { return (false); } ( body) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 3533 | } | ||||
| 3534 | |||||
| 3535 | // Revalidate the function name when we transitioned to strict mode. | ||||
| 3536 | if ((kind == FunctionSyntaxKind::Statement || | ||||
| 3537 | kind == FunctionSyntaxKind::Expression) && | ||||
| 3538 | funbox->explicitName() && !inheritedStrict && pc_->sc()->strict()) { | ||||
| 3539 | MOZ_ASSERT(pc_->sc()->hasExplicitUseStrict(),do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->sc()->hasExplicitUseStrict())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(pc_->sc()->hasExplicitUseStrict()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->sc()->hasExplicitUseStrict()" " (" "strict mode should only change when a 'use strict' directive " "is present" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 3541); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()" ") (" "strict mode should only change when a 'use strict' directive " "is present" ")"); do { MOZ_CrashSequence(__null, 3541); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 3540 | "strict mode should only change when a 'use strict' directive "do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->sc()->hasExplicitUseStrict())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(pc_->sc()->hasExplicitUseStrict()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->sc()->hasExplicitUseStrict()" " (" "strict mode should only change when a 'use strict' directive " "is present" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 3541); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()" ") (" "strict mode should only change when a 'use strict' directive " "is present" ")"); do { MOZ_CrashSequence(__null, 3541); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 3541 | "is present")do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->sc()->hasExplicitUseStrict())>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(pc_->sc()->hasExplicitUseStrict()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->sc()->hasExplicitUseStrict()" " (" "strict mode should only change when a 'use strict' directive " "is present" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 3541); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()" ") (" "strict mode should only change when a 'use strict' directive " "is present" ")"); do { MOZ_CrashSequence(__null, 3541); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 3542 | |||||
| 3543 | auto propertyName = funbox->explicitName(); | ||||
| 3544 | YieldHandling nameYieldHandling; | ||||
| 3545 | if (kind == FunctionSyntaxKind::Expression) { | ||||
| 3546 | // Named lambda has binding inside it. | ||||
| 3547 | nameYieldHandling = bodyYieldHandling; | ||||
| 3548 | } else { | ||||
| 3549 | // Otherwise YieldHandling cannot be checked at this point | ||||
| 3550 | // because of different context. | ||||
| 3551 | // It should already be checked before this point. | ||||
| 3552 | nameYieldHandling = YieldIsName; | ||||
| 3553 | } | ||||
| 3554 | |||||
| 3555 | // We already use the correct await-handling at this point, therefore | ||||
| 3556 | // we don't need call AutoAwaitIsKeyword here. | ||||
| 3557 | |||||
| 3558 | uint32_t nameOffset = handler_.getFunctionNameOffset(*funNode, anyChars); | ||||
| 3559 | if (!checkBindingIdentifier(propertyName, nameOffset, nameYieldHandling)) { | ||||
| 3560 | return false; | ||||
| 3561 | } | ||||
| 3562 | } | ||||
| 3563 | |||||
| 3564 | if (bodyType == StatementListBody) { | ||||
| 3565 | // Cannot use mustMatchToken here because of internal compiler error on | ||||
| 3566 | // gcc 6.4.0, with linux 64 SM hazard build. | ||||
| 3567 | TokenKind actual; | ||||
| 3568 | if (!tokenStream.getToken(&actual, TokenStream::SlashIsRegExp)) { | ||||
| 3569 | return false; | ||||
| 3570 | } | ||||
| 3571 | if (actual != TokenKind::RightCurly) { | ||||
| 3572 | reportMissingClosing(JSMSG_CURLY_AFTER_BODY, JSMSG_CURLY_OPENED, | ||||
| 3573 | openedPos); | ||||
| 3574 | return false; | ||||
| 3575 | } | ||||
| 3576 | |||||
| 3577 | setFunctionEndFromCurrentToken(funbox); | ||||
| 3578 | } else { | ||||
| 3579 | MOZ_ASSERT(kind == FunctionSyntaxKind::Arrow)do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == FunctionSyntaxKind::Arrow)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(kind == FunctionSyntaxKind:: Arrow))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("kind == FunctionSyntaxKind::Arrow", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 3579); AnnotateMozCrashReason("MOZ_ASSERT" "(" "kind == FunctionSyntaxKind::Arrow" ")"); do { MOZ_CrashSequence(__null, 3579); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3580 | |||||
| 3581 | if (anyChars.hadError()) { | ||||
| 3582 | return false; | ||||
| 3583 | } | ||||
| 3584 | |||||
| 3585 | setFunctionEndFromCurrentToken(funbox); | ||||
| 3586 | } | ||||
| 3587 | |||||
| 3588 | if (IsMethodDefinitionKind(kind) && pc_->superScopeNeedsHomeObject()) { | ||||
| 3589 | funbox->setNeedsHomeObject(); | ||||
| 3590 | } | ||||
| 3591 | |||||
| 3592 | if (!finishFunction(isStandaloneFunction)) { | ||||
| 3593 | return false; | ||||
| 3594 | } | ||||
| 3595 | |||||
| 3596 | handler_.setEndPosition(body, pos().begin); | ||||
| 3597 | handler_.setEndPosition(*funNode, pos().end); | ||||
| 3598 | handler_.setFunctionBody(*funNode, body); | ||||
| 3599 | |||||
| 3600 | return true; | ||||
| 3601 | } | ||||
| 3602 | |||||
| 3603 | template <class ParseHandler, typename Unit> | ||||
| 3604 | typename ParseHandler::FunctionNodeResult | ||||
| 3605 | GeneralParser<ParseHandler, Unit>::functionStmt(uint32_t toStringStart, | ||||
| 3606 | YieldHandling yieldHandling, | ||||
| 3607 | DefaultHandling defaultHandling, | ||||
| 3608 | FunctionAsyncKind asyncKind) { | ||||
| 3609 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Function))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Function))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Function)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Function)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3609); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)" ")"); do { MOZ_CrashSequence(__null, 3609); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3610 | |||||
| 3611 | // In sloppy mode, Annex B.3.2 allows labelled function declarations. | ||||
| 3612 | // Otherwise it's a parse error. | ||||
| 3613 | ParseContext::Statement* declaredInStmt = pc_->innermostStatement(); | ||||
| 3614 | if (declaredInStmt && declaredInStmt->kind() == StatementKind::Label) { | ||||
| 3615 | MOZ_ASSERT(!pc_->sc()->strict(),do { static_assert( mozilla::detail::AssertionConditionType< decltype(!pc_->sc()->strict())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!pc_->sc()->strict())) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!pc_->sc()->strict()" " (" "labeled functions shouldn't be parsed in strict mode" ")" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3616); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!pc_->sc()->strict()" ") (" "labeled functions shouldn't be parsed in strict mode" ")"); do { MOZ_CrashSequence(__null, 3616); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 3616 | "labeled functions shouldn't be parsed in strict mode")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!pc_->sc()->strict())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!pc_->sc()->strict())) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!pc_->sc()->strict()" " (" "labeled functions shouldn't be parsed in strict mode" ")" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3616); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!pc_->sc()->strict()" ") (" "labeled functions shouldn't be parsed in strict mode" ")"); do { MOZ_CrashSequence(__null, 3616); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3617 | |||||
| 3618 | // Find the innermost non-label statement. Report an error if it's | ||||
| 3619 | // unbraced: functions can't appear in it. Otherwise the statement | ||||
| 3620 | // (or its absence) determines the scope the function's bound in. | ||||
| 3621 | while (declaredInStmt && declaredInStmt->kind() == StatementKind::Label) { | ||||
| 3622 | declaredInStmt = declaredInStmt->enclosing(); | ||||
| 3623 | } | ||||
| 3624 | |||||
| 3625 | if (declaredInStmt && !StatementKindIsBraced(declaredInStmt->kind())) { | ||||
| 3626 | error(JSMSG_SLOPPY_FUNCTION_LABEL); | ||||
| 3627 | return errorResult(); | ||||
| 3628 | } | ||||
| 3629 | } | ||||
| 3630 | |||||
| 3631 | TokenKind tt; | ||||
| 3632 | if (!tokenStream.getToken(&tt)) { | ||||
| 3633 | return errorResult(); | ||||
| 3634 | } | ||||
| 3635 | |||||
| 3636 | GeneratorKind generatorKind = GeneratorKind::NotGenerator; | ||||
| 3637 | if (tt == TokenKind::Mul) { | ||||
| 3638 | generatorKind = GeneratorKind::Generator; | ||||
| 3639 | if (!tokenStream.getToken(&tt)) { | ||||
| 3640 | return errorResult(); | ||||
| 3641 | } | ||||
| 3642 | } | ||||
| 3643 | |||||
| 3644 | TaggedParserAtomIndex name; | ||||
| 3645 | if (TokenKindIsPossibleIdentifier(tt)) { | ||||
| 3646 | name = bindingIdentifier(yieldHandling); | ||||
| 3647 | if (!name) { | ||||
| 3648 | return errorResult(); | ||||
| 3649 | } | ||||
| 3650 | } else if (defaultHandling == AllowDefaultName) { | ||||
| 3651 | name = TaggedParserAtomIndex::WellKnown::default_(); | ||||
| 3652 | anyChars.ungetToken(); | ||||
| 3653 | } else { | ||||
| 3654 | /* Unnamed function expressions are forbidden in statement context. */ | ||||
| 3655 | error(JSMSG_UNNAMED_FUNCTION_STMT); | ||||
| 3656 | return errorResult(); | ||||
| 3657 | } | ||||
| 3658 | |||||
| 3659 | if (name == TaggedParserAtomIndex::WellKnown::arguments()) { | ||||
| 3660 | pc_->numberOfArgumentsNames++; | ||||
| 3661 | } | ||||
| 3662 | |||||
| 3663 | // Note the declared name and check for early errors. | ||||
| 3664 | DeclarationKind kind; | ||||
| 3665 | if (declaredInStmt) { | ||||
| 3666 | MOZ_ASSERT(declaredInStmt->kind() != StatementKind::Label)do { static_assert( mozilla::detail::AssertionConditionType< decltype(declaredInStmt->kind() != StatementKind::Label)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(declaredInStmt->kind() != StatementKind::Label))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("declaredInStmt->kind() != StatementKind::Label" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3666); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "declaredInStmt->kind() != StatementKind::Label" ")"); do { MOZ_CrashSequence(__null, 3666); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3667 | MOZ_ASSERT(StatementKindIsBraced(declaredInStmt->kind()))do { static_assert( mozilla::detail::AssertionConditionType< decltype(StatementKindIsBraced(declaredInStmt->kind()))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(StatementKindIsBraced(declaredInStmt->kind())))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("StatementKindIsBraced(declaredInStmt->kind())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3667); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "StatementKindIsBraced(declaredInStmt->kind())" ")"); do { MOZ_CrashSequence(__null, 3667); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3668 | |||||
| 3669 | kind = | ||||
| 3670 | (!pc_->sc()->strict() && generatorKind == GeneratorKind::NotGenerator && | ||||
| 3671 | asyncKind == FunctionAsyncKind::SyncFunction) | ||||
| 3672 | ? DeclarationKind::SloppyLexicalFunction | ||||
| 3673 | : DeclarationKind::LexicalFunction; | ||||
| 3674 | } else { | ||||
| 3675 | kind = pc_->atModuleLevel() ? DeclarationKind::ModuleBodyLevelFunction | ||||
| 3676 | : DeclarationKind::BodyLevelFunction; | ||||
| 3677 | } | ||||
| 3678 | |||||
| 3679 | if (!noteDeclaredName(name, kind, pos())) { | ||||
| 3680 | return errorResult(); | ||||
| 3681 | } | ||||
| 3682 | |||||
| 3683 | FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Statement; | ||||
| 3684 | FunctionNodeType funNode = MOZ_TRY(handler_.newFunction(syntaxKind, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 3685 | |||||
| 3686 | // Under sloppy mode, try Annex B.3.3 semantics. If making an additional | ||||
| 3687 | // 'var' binding of the same name does not throw an early error, do so. | ||||
| 3688 | // This 'var' binding would be assigned the function object when its | ||||
| 3689 | // declaration is reached, not at the start of the block. | ||||
| 3690 | // | ||||
| 3691 | // This semantics is implemented upon Scope exit in | ||||
| 3692 | // Scope::propagateAndMarkAnnexBFunctionBoxes. | ||||
| 3693 | bool tryAnnexB = kind == DeclarationKind::SloppyLexicalFunction; | ||||
| 3694 | |||||
| 3695 | YieldHandling newYieldHandling = GetYieldHandling(generatorKind); | ||||
| 3696 | return functionDefinition(funNode, toStringStart, InAllowed, newYieldHandling, | ||||
| 3697 | name, syntaxKind, generatorKind, asyncKind, | ||||
| 3698 | tryAnnexB); | ||||
| 3699 | } | ||||
| 3700 | |||||
| 3701 | template <class ParseHandler, typename Unit> | ||||
| 3702 | typename ParseHandler::FunctionNodeResult | ||||
| 3703 | GeneralParser<ParseHandler, Unit>::functionExpr(uint32_t toStringStart, | ||||
| 3704 | InvokedPrediction invoked, | ||||
| 3705 | FunctionAsyncKind asyncKind) { | ||||
| 3706 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Function))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Function))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Function)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Function)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3706); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)" ")"); do { MOZ_CrashSequence(__null, 3706); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 3707 | |||||
| 3708 | AutoAwaitIsKeyword<ParseHandler, Unit> awaitIsKeyword( | ||||
| 3709 | this, GetAwaitHandling(asyncKind)); | ||||
| 3710 | GeneratorKind generatorKind = GeneratorKind::NotGenerator; | ||||
| 3711 | TokenKind tt; | ||||
| 3712 | if (!tokenStream.getToken(&tt)) { | ||||
| 3713 | return errorResult(); | ||||
| 3714 | } | ||||
| 3715 | |||||
| 3716 | if (tt == TokenKind::Mul) { | ||||
| 3717 | generatorKind = GeneratorKind::Generator; | ||||
| 3718 | if (!tokenStream.getToken(&tt)) { | ||||
| 3719 | return errorResult(); | ||||
| 3720 | } | ||||
| 3721 | } | ||||
| 3722 | |||||
| 3723 | YieldHandling yieldHandling = GetYieldHandling(generatorKind); | ||||
| 3724 | |||||
| 3725 | TaggedParserAtomIndex name; | ||||
| 3726 | if (TokenKindIsPossibleIdentifier(tt)) { | ||||
| 3727 | name = bindingIdentifier(yieldHandling); | ||||
| 3728 | if (!name) { | ||||
| 3729 | return errorResult(); | ||||
| 3730 | } | ||||
| 3731 | } else { | ||||
| 3732 | anyChars.ungetToken(); | ||||
| 3733 | } | ||||
| 3734 | |||||
| 3735 | FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Expression; | ||||
| 3736 | FunctionNodeType funNode = MOZ_TRY(handler_.newFunction(syntaxKind, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 3737 | |||||
| 3738 | if (invoked) { | ||||
| 3739 | funNode = handler_.setLikelyIIFE(funNode); | ||||
| 3740 | } | ||||
| 3741 | |||||
| 3742 | return functionDefinition(funNode, toStringStart, InAllowed, yieldHandling, | ||||
| 3743 | name, syntaxKind, generatorKind, asyncKind); | ||||
| 3744 | } | ||||
| 3745 | |||||
| 3746 | /* | ||||
| 3747 | * Return true if this node, known to be an unparenthesized string literal | ||||
| 3748 | * that never contain escape sequences, could be the string of a directive in a | ||||
| 3749 | * Directive Prologue. Directive strings never contain escape sequences or line | ||||
| 3750 | * continuations. | ||||
| 3751 | */ | ||||
| 3752 | static inline bool IsUseStrictDirective(const TokenPos& pos, | ||||
| 3753 | TaggedParserAtomIndex atom) { | ||||
| 3754 | // the length of "use strict", including quotation. | ||||
| 3755 | static constexpr size_t useStrictLength = 12; | ||||
| 3756 | return atom == TaggedParserAtomIndex::WellKnown::use_strict_() && | ||||
| 3757 | pos.begin + useStrictLength == pos.end; | ||||
| 3758 | } | ||||
| 3759 | |||||
| 3760 | /* | ||||
| 3761 | * Recognize Directive Prologue members and directives. Assuming |pn| is a | ||||
| 3762 | * candidate for membership in a directive prologue, recognize directives and | ||||
| 3763 | * set |pc_|'s flags accordingly. If |pn| is indeed part of a prologue, set its | ||||
| 3764 | * |prologue| flag. | ||||
| 3765 | * | ||||
| 3766 | * Note that the following is a strict mode function: | ||||
| 3767 | * | ||||
| 3768 | * function foo() { | ||||
| 3769 | * "blah" // inserted semi colon | ||||
| 3770 | * "blurgh" | ||||
| 3771 | * "use\x20loose" | ||||
| 3772 | * "use strict" | ||||
| 3773 | * } | ||||
| 3774 | * | ||||
| 3775 | * That is, even though "use\x20loose" can never be a directive, now or in the | ||||
| 3776 | * future (because of the hex escape), the Directive Prologue extends through it | ||||
| 3777 | * to the "use strict" statement, which is indeed a directive. | ||||
| 3778 | */ | ||||
| 3779 | template <class ParseHandler, typename Unit> | ||||
| 3780 | bool GeneralParser<ParseHandler, Unit>::maybeParseDirective( | ||||
| 3781 | ListNodeType list, Node possibleDirective, bool* cont) { | ||||
| 3782 | TokenPos directivePos; | ||||
| 3783 | TaggedParserAtomIndex directive = | ||||
| 3784 | handler_.isStringExprStatement(possibleDirective, &directivePos); | ||||
| 3785 | |||||
| 3786 | *cont = !!directive; | ||||
| 3787 | if (!*cont) { | ||||
| 3788 | return true; | ||||
| 3789 | } | ||||
| 3790 | |||||
| 3791 | if (IsUseStrictDirective(directivePos, directive)) { | ||||
| 3792 | // Functions with non-simple parameter lists (destructuring, | ||||
| 3793 | // default or rest parameters) must not contain a "use strict" | ||||
| 3794 | // directive. | ||||
| 3795 | if (pc_->isFunctionBox()) { | ||||
| 3796 | FunctionBox* funbox = pc_->functionBox(); | ||||
| 3797 | if (!funbox->hasSimpleParameterList()) { | ||||
| 3798 | const char* parameterKind = funbox->hasDestructuringArgs | ||||
| 3799 | ? "destructuring" | ||||
| 3800 | : funbox->hasParameterExprs ? "default" | ||||
| 3801 | : "rest"; | ||||
| 3802 | errorAt(directivePos.begin, JSMSG_STRICT_NON_SIMPLE_PARAMS, | ||||
| 3803 | parameterKind); | ||||
| 3804 | return false; | ||||
| 3805 | } | ||||
| 3806 | } | ||||
| 3807 | |||||
| 3808 | // We're going to be in strict mode. Note that this scope explicitly | ||||
| 3809 | // had "use strict"; | ||||
| 3810 | pc_->sc()->setExplicitUseStrict(); | ||||
| 3811 | if (!pc_->sc()->strict()) { | ||||
| 3812 | // Some strict mode violations can appear before a Use Strict Directive | ||||
| 3813 | // is applied. (See the |DeprecatedContent| enum initializers.) These | ||||
| 3814 | // violations can manifest in two ways. | ||||
| 3815 | // | ||||
| 3816 | // First, the violation can appear *before* the Use Strict Directive. | ||||
| 3817 | // Numeric literals (and therefore octal literals) can only precede a | ||||
| 3818 | // Use Strict Directive if this function's parameter list is not simple, | ||||
| 3819 | // but we reported an error for non-simple parameter lists above, so | ||||
| 3820 | // octal literals present no issue. But octal escapes and \8 and \9 can | ||||
| 3821 | // appear in the directive prologue before a Use Strict Directive: | ||||
| 3822 | // | ||||
| 3823 | // function f() | ||||
| 3824 | // { | ||||
| 3825 | // "hell\157 world"; // octal escape | ||||
| 3826 | // "\8"; "\9"; // NonOctalDecimalEscape | ||||
| 3827 | // "use strict"; // retroactively makes all the above errors | ||||
| 3828 | // } | ||||
| 3829 | // | ||||
| 3830 | // Second, the violation can appear *after* the Use Strict Directive but | ||||
| 3831 | // *before* the directive is recognized as terminated. This only | ||||
| 3832 | // happens when a directive is terminated by ASI, and the next token | ||||
| 3833 | // contains a violation: | ||||
| 3834 | // | ||||
| 3835 | // function a() | ||||
| 3836 | // { | ||||
| 3837 | // "use strict" // ASI | ||||
| 3838 | // 0755; | ||||
| 3839 | // } | ||||
| 3840 | // function b() | ||||
| 3841 | // { | ||||
| 3842 | // "use strict" // ASI | ||||
| 3843 | // "hell\157 world"; | ||||
| 3844 | // } | ||||
| 3845 | // function c() | ||||
| 3846 | // { | ||||
| 3847 | // "use strict" // ASI | ||||
| 3848 | // "\8"; | ||||
| 3849 | // } | ||||
| 3850 | // | ||||
| 3851 | // We note such violations when tokenizing. Then, if a violation has | ||||
| 3852 | // been observed at the time a "use strict" is applied, we report the | ||||
| 3853 | // error. | ||||
| 3854 | switch (anyChars.sawDeprecatedContent()) { | ||||
| 3855 | case DeprecatedContent::None: | ||||
| 3856 | break; | ||||
| 3857 | case DeprecatedContent::OctalLiteral: | ||||
| 3858 | error(JSMSG_DEPRECATED_OCTAL_LITERAL); | ||||
| 3859 | return false; | ||||
| 3860 | case DeprecatedContent::OctalEscape: | ||||
| 3861 | error(JSMSG_DEPRECATED_OCTAL_ESCAPE); | ||||
| 3862 | return false; | ||||
| 3863 | case DeprecatedContent::EightOrNineEscape: | ||||
| 3864 | error(JSMSG_DEPRECATED_EIGHT_OR_NINE_ESCAPE); | ||||
| 3865 | return false; | ||||
| 3866 | } | ||||
| 3867 | |||||
| 3868 | pc_->sc()->setStrictScript(); | ||||
| 3869 | } | ||||
| 3870 | } | ||||
| 3871 | return true; | ||||
| 3872 | } | ||||
| 3873 | |||||
| 3874 | template <class ParseHandler, typename Unit> | ||||
| 3875 | typename ParseHandler::ListNodeResult | ||||
| 3876 | GeneralParser<ParseHandler, Unit>::statementList(YieldHandling yieldHandling) { | ||||
| 3877 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 3878 | if (!recursion.check(this->fc_)) { | ||||
| 3879 | return errorResult(); | ||||
| 3880 | } | ||||
| 3881 | |||||
| 3882 | ListNodeType stmtList = MOZ_TRY(handler_.newStatementList(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(pos())); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 3883 | |||||
| 3884 | bool canHaveDirectives = pc_->atBodyLevel(); | ||||
| 3885 | if (canHaveDirectives) { | ||||
| 3886 | // Clear flags for deprecated content that might have been seen in an | ||||
| 3887 | // enclosing context. | ||||
| 3888 | anyChars.clearSawDeprecatedContent(); | ||||
| 3889 | } | ||||
| 3890 | |||||
| 3891 | bool canHaveHashbangComment = pc_->atTopLevel(); | ||||
| 3892 | if (canHaveHashbangComment) { | ||||
| 3893 | tokenStream.consumeOptionalHashbangComment(); | ||||
| 3894 | } | ||||
| 3895 | |||||
| 3896 | bool afterReturn = false; | ||||
| 3897 | bool warnedAboutStatementsAfterReturn = false; | ||||
| 3898 | uint32_t statementBegin = 0; | ||||
| 3899 | for (;;) { | ||||
| 3900 | TokenKind tt = TokenKind::Eof; | ||||
| 3901 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 3902 | if (anyChars.isEOF()) { | ||||
| 3903 | isUnexpectedEOF_ = true; | ||||
| 3904 | } | ||||
| 3905 | return errorResult(); | ||||
| 3906 | } | ||||
| 3907 | if (tt == TokenKind::Eof || tt == TokenKind::RightCurly) { | ||||
| 3908 | TokenPos pos; | ||||
| 3909 | if (!tokenStream.peekTokenPos(&pos, TokenStream::SlashIsRegExp)) { | ||||
| 3910 | return errorResult(); | ||||
| 3911 | } | ||||
| 3912 | handler_.setListEndPosition(stmtList, pos); | ||||
| 3913 | break; | ||||
| 3914 | } | ||||
| 3915 | if (afterReturn) { | ||||
| 3916 | if (!tokenStream.peekOffset(&statementBegin, | ||||
| 3917 | TokenStream::SlashIsRegExp)) { | ||||
| 3918 | return errorResult(); | ||||
| 3919 | } | ||||
| 3920 | } | ||||
| 3921 | auto nextResult = statementListItem(yieldHandling, canHaveDirectives); | ||||
| 3922 | if (nextResult.isErr()) { | ||||
| 3923 | if (anyChars.isEOF()) { | ||||
| 3924 | isUnexpectedEOF_ = true; | ||||
| 3925 | } | ||||
| 3926 | return errorResult(); | ||||
| 3927 | } | ||||
| 3928 | Node next = nextResult.unwrap(); | ||||
| 3929 | if (!warnedAboutStatementsAfterReturn) { | ||||
| 3930 | if (afterReturn) { | ||||
| 3931 | if (!handler_.isStatementPermittedAfterReturnStatement(next)) { | ||||
| 3932 | if (!warningAt(statementBegin, JSMSG_STMT_AFTER_RETURN)) { | ||||
| 3933 | return errorResult(); | ||||
| 3934 | } | ||||
| 3935 | |||||
| 3936 | warnedAboutStatementsAfterReturn = true; | ||||
| 3937 | } | ||||
| 3938 | } else if (handler_.isReturnStatement(next)) { | ||||
| 3939 | afterReturn = true; | ||||
| 3940 | } | ||||
| 3941 | } | ||||
| 3942 | |||||
| 3943 | if (canHaveDirectives) { | ||||
| 3944 | if (!maybeParseDirective(stmtList, next, &canHaveDirectives)) { | ||||
| 3945 | return errorResult(); | ||||
| 3946 | } | ||||
| 3947 | } | ||||
| 3948 | |||||
| 3949 | handler_.addStatementToList(stmtList, next); | ||||
| 3950 | } | ||||
| 3951 | |||||
| 3952 | return stmtList; | ||||
| 3953 | } | ||||
| 3954 | |||||
| 3955 | template <class ParseHandler, typename Unit> | ||||
| 3956 | typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::condition( | ||||
| 3957 | InHandling inHandling, YieldHandling yieldHandling) { | ||||
| 3958 | if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_COND)) { | ||||
| 3959 | return errorResult(); | ||||
| 3960 | } | ||||
| 3961 | |||||
| 3962 | Node pn = | ||||
| 3963 | MOZ_TRY(exprInParens(inHandling, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (exprInParens(inHandling, yieldHandling, TripledotProhibited) ); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)) ) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 3964 | |||||
| 3965 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_COND)) { | ||||
| 3966 | return errorResult(); | ||||
| 3967 | } | ||||
| 3968 | |||||
| 3969 | return pn; | ||||
| 3970 | } | ||||
| 3971 | |||||
| 3972 | template <class ParseHandler, typename Unit> | ||||
| 3973 | bool GeneralParser<ParseHandler, Unit>::matchLabel( | ||||
| 3974 | YieldHandling yieldHandling, TaggedParserAtomIndex* labelOut) { | ||||
| 3975 | MOZ_ASSERT(labelOut != nullptr)do { static_assert( mozilla::detail::AssertionConditionType< decltype(labelOut != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(labelOut != nullptr))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("labelOut != nullptr" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 3975); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "labelOut != nullptr" ")"); do { MOZ_CrashSequence (__null, 3975); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 3976 | TokenKind tt = TokenKind::Eof; | ||||
| 3977 | if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 3978 | return false; | ||||
| 3979 | } | ||||
| 3980 | |||||
| 3981 | if (TokenKindIsPossibleIdentifier(tt)) { | ||||
| 3982 | tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp); | ||||
| 3983 | |||||
| 3984 | *labelOut = labelIdentifier(yieldHandling); | ||||
| 3985 | if (!*labelOut) { | ||||
| 3986 | return false; | ||||
| 3987 | } | ||||
| 3988 | } else { | ||||
| 3989 | *labelOut = TaggedParserAtomIndex::null(); | ||||
| 3990 | } | ||||
| 3991 | return true; | ||||
| 3992 | } | ||||
| 3993 | |||||
| 3994 | template <class ParseHandler, typename Unit> | ||||
| 3995 | GeneralParser<ParseHandler, Unit>::PossibleError::PossibleError( | ||||
| 3996 | GeneralParser<ParseHandler, Unit>& parser) | ||||
| 3997 | : parser_(parser) {} | ||||
| 3998 | |||||
| 3999 | template <class ParseHandler, typename Unit> | ||||
| 4000 | typename GeneralParser<ParseHandler, Unit>::PossibleError::Error& | ||||
| 4001 | GeneralParser<ParseHandler, Unit>::PossibleError::error(ErrorKind kind) { | ||||
| 4002 | if (kind == ErrorKind::Expression) { | ||||
| 4003 | return exprError_; | ||||
| 4004 | } | ||||
| 4005 | MOZ_ASSERT(kind == ErrorKind::Destructuring)do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == ErrorKind::Destructuring)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(kind == ErrorKind::Destructuring ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "kind == ErrorKind::Destructuring", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4005); AnnotateMozCrashReason("MOZ_ASSERT" "(" "kind == ErrorKind::Destructuring" ")"); do { MOZ_CrashSequence(__null, 4005); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4006 | return destructuringError_; | ||||
| 4007 | } | ||||
| 4008 | |||||
| 4009 | template <class ParseHandler, typename Unit> | ||||
| 4010 | void GeneralParser<ParseHandler, Unit>::PossibleError::setResolved( | ||||
| 4011 | ErrorKind kind) { | ||||
| 4012 | error(kind).state_ = ErrorState::None; | ||||
| 4013 | } | ||||
| 4014 | |||||
| 4015 | template <class ParseHandler, typename Unit> | ||||
| 4016 | bool GeneralParser<ParseHandler, Unit>::PossibleError::hasError( | ||||
| 4017 | ErrorKind kind) { | ||||
| 4018 | return error(kind).state_ == ErrorState::Pending; | ||||
| 4019 | } | ||||
| 4020 | |||||
| 4021 | template <class ParseHandler, typename Unit> | ||||
| 4022 | bool GeneralParser<ParseHandler, | ||||
| 4023 | Unit>::PossibleError::hasPendingDestructuringError() { | ||||
| 4024 | return hasError(ErrorKind::Destructuring); | ||||
| 4025 | } | ||||
| 4026 | |||||
| 4027 | template <class ParseHandler, typename Unit> | ||||
| 4028 | void GeneralParser<ParseHandler, Unit>::PossibleError::setPending( | ||||
| 4029 | ErrorKind kind, const TokenPos& pos, unsigned errorNumber) { | ||||
| 4030 | // Don't overwrite a previously recorded error. | ||||
| 4031 | if (hasError(kind)) { | ||||
| 4032 | return; | ||||
| 4033 | } | ||||
| 4034 | |||||
| 4035 | // If we report an error later, we'll do it from the position where we set | ||||
| 4036 | // the state to pending. | ||||
| 4037 | Error& err = error(kind); | ||||
| 4038 | err.offset_ = pos.begin; | ||||
| 4039 | err.errorNumber_ = errorNumber; | ||||
| 4040 | err.state_ = ErrorState::Pending; | ||||
| 4041 | } | ||||
| 4042 | |||||
| 4043 | template <class ParseHandler, typename Unit> | ||||
| 4044 | void GeneralParser<ParseHandler, Unit>::PossibleError:: | ||||
| 4045 | setPendingDestructuringErrorAt(const TokenPos& pos, unsigned errorNumber) { | ||||
| 4046 | setPending(ErrorKind::Destructuring, pos, errorNumber); | ||||
| 4047 | } | ||||
| 4048 | |||||
| 4049 | template <class ParseHandler, typename Unit> | ||||
| 4050 | void GeneralParser<ParseHandler, Unit>::PossibleError:: | ||||
| 4051 | setPendingExpressionErrorAt(const TokenPos& pos, unsigned errorNumber) { | ||||
| 4052 | setPending(ErrorKind::Expression, pos, errorNumber); | ||||
| 4053 | } | ||||
| 4054 | |||||
| 4055 | template <class ParseHandler, typename Unit> | ||||
| 4056 | bool GeneralParser<ParseHandler, Unit>::PossibleError::checkForError( | ||||
| 4057 | ErrorKind kind) { | ||||
| 4058 | if (!hasError(kind)) { | ||||
| 4059 | return true; | ||||
| 4060 | } | ||||
| 4061 | |||||
| 4062 | Error& err = error(kind); | ||||
| 4063 | parser_.errorAt(err.offset_, err.errorNumber_); | ||||
| 4064 | return false; | ||||
| 4065 | } | ||||
| 4066 | |||||
| 4067 | template <class ParseHandler, typename Unit> | ||||
| 4068 | bool GeneralParser<ParseHandler, | ||||
| 4069 | Unit>::PossibleError::checkForDestructuringErrorOrWarning() { | ||||
| 4070 | // Clear pending expression error, because we're definitely not in an | ||||
| 4071 | // expression context. | ||||
| 4072 | setResolved(ErrorKind::Expression); | ||||
| 4073 | |||||
| 4074 | // Report any pending destructuring error. | ||||
| 4075 | return checkForError(ErrorKind::Destructuring); | ||||
| 4076 | } | ||||
| 4077 | |||||
| 4078 | template <class ParseHandler, typename Unit> | ||||
| 4079 | bool GeneralParser<ParseHandler, | ||||
| 4080 | Unit>::PossibleError::checkForExpressionError() { | ||||
| 4081 | // Clear pending destructuring error, because we're definitely not | ||||
| 4082 | // in a destructuring context. | ||||
| 4083 | setResolved(ErrorKind::Destructuring); | ||||
| 4084 | |||||
| 4085 | // Report any pending expression error. | ||||
| 4086 | return checkForError(ErrorKind::Expression); | ||||
| 4087 | } | ||||
| 4088 | |||||
| 4089 | template <class ParseHandler, typename Unit> | ||||
| 4090 | void GeneralParser<ParseHandler, Unit>::PossibleError::transferErrorTo( | ||||
| 4091 | ErrorKind kind, PossibleError* other) { | ||||
| 4092 | if (hasError(kind) && !other->hasError(kind)) { | ||||
| 4093 | Error& err = error(kind); | ||||
| 4094 | Error& otherErr = other->error(kind); | ||||
| 4095 | otherErr.offset_ = err.offset_; | ||||
| 4096 | otherErr.errorNumber_ = err.errorNumber_; | ||||
| 4097 | otherErr.state_ = err.state_; | ||||
| 4098 | } | ||||
| 4099 | } | ||||
| 4100 | |||||
| 4101 | template <class ParseHandler, typename Unit> | ||||
| 4102 | void GeneralParser<ParseHandler, Unit>::PossibleError::transferErrorsTo( | ||||
| 4103 | PossibleError* other) { | ||||
| 4104 | MOZ_ASSERT(other)do { static_assert( mozilla::detail::AssertionConditionType< decltype(other)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(other))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("other", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4104); AnnotateMozCrashReason("MOZ_ASSERT" "(" "other" ")") ; do { MOZ_CrashSequence(__null, 4104); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4105 | MOZ_ASSERT(this != other)do { static_assert( mozilla::detail::AssertionConditionType< decltype(this != other)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(this != other))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("this != other", "/root/firefox-clang/js/src/frontend/Parser.cpp", 4105); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "this != other" ")"); do { MOZ_CrashSequence (__null, 4105); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 4106 | MOZ_ASSERT(&parser_ == &other->parser_,do { static_assert( mozilla::detail::AssertionConditionType< decltype(&parser_ == &other->parser_)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(&parser_ == &other->parser_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&parser_ == &other->parser_" " (" "Can't transfer fields to an instance which belongs to a " "different parser" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4108); AnnotateMozCrashReason("MOZ_ASSERT" "(" "&parser_ == &other->parser_" ") (" "Can't transfer fields to an instance which belongs to a " "different parser" ")"); do { MOZ_CrashSequence(__null, 4108 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 4107 | "Can't transfer fields to an instance which belongs to a "do { static_assert( mozilla::detail::AssertionConditionType< decltype(&parser_ == &other->parser_)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(&parser_ == &other->parser_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&parser_ == &other->parser_" " (" "Can't transfer fields to an instance which belongs to a " "different parser" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4108); AnnotateMozCrashReason("MOZ_ASSERT" "(" "&parser_ == &other->parser_" ") (" "Can't transfer fields to an instance which belongs to a " "different parser" ")"); do { MOZ_CrashSequence(__null, 4108 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 4108 | "different parser")do { static_assert( mozilla::detail::AssertionConditionType< decltype(&parser_ == &other->parser_)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(&parser_ == &other->parser_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("&parser_ == &other->parser_" " (" "Can't transfer fields to an instance which belongs to a " "different parser" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4108); AnnotateMozCrashReason("MOZ_ASSERT" "(" "&parser_ == &other->parser_" ") (" "Can't transfer fields to an instance which belongs to a " "different parser" ")"); do { MOZ_CrashSequence(__null, 4108 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 4109 | |||||
| 4110 | transferErrorTo(ErrorKind::Destructuring, other); | ||||
| 4111 | transferErrorTo(ErrorKind::Expression, other); | ||||
| 4112 | } | ||||
| 4113 | |||||
| 4114 | template <class ParseHandler, typename Unit> | ||||
| 4115 | typename ParseHandler::BinaryNodeResult | ||||
| 4116 | GeneralParser<ParseHandler, Unit>::bindingInitializer( | ||||
| 4117 | Node lhs, DeclarationKind kind, YieldHandling yieldHandling) { | ||||
| 4118 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Assign))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Assign))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Assign)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Assign)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4118); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Assign)" ")"); do { MOZ_CrashSequence(__null, 4118); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4119 | |||||
| 4120 | if (kind == DeclarationKind::FormalParameter) { | ||||
| 4121 | pc_->functionBox()->hasParameterExprs = true; | ||||
| 4122 | } | ||||
| 4123 | |||||
| 4124 | Node rhs = MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 4125 | |||||
| 4126 | BinaryNodeType assign = | ||||
| 4127 | MOZ_TRY(handler_.newAssignment(ParseNodeKind::AssignExpr, lhs, rhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newAssignment(ParseNodeKind::AssignExpr, lhs, rhs)) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 4128 | |||||
| 4129 | return assign; | ||||
| 4130 | } | ||||
| 4131 | |||||
| 4132 | template <class ParseHandler, typename Unit> | ||||
| 4133 | typename ParseHandler::NameNodeResult | ||||
| 4134 | GeneralParser<ParseHandler, Unit>::bindingIdentifier( | ||||
| 4135 | DeclarationKind kind, YieldHandling yieldHandling) { | ||||
| 4136 | TaggedParserAtomIndex name = bindingIdentifier(yieldHandling); | ||||
| 4137 | if (!name) { | ||||
| 4138 | return errorResult(); | ||||
| 4139 | } | ||||
| 4140 | |||||
| 4141 | NameNodeType binding = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4142 | if (!noteDeclaredName(name, kind, pos())) { | ||||
| 4143 | return errorResult(); | ||||
| 4144 | } | ||||
| 4145 | |||||
| 4146 | return binding; | ||||
| 4147 | } | ||||
| 4148 | |||||
| 4149 | template <class ParseHandler, typename Unit> | ||||
| 4150 | typename ParseHandler::NodeResult | ||||
| 4151 | GeneralParser<ParseHandler, Unit>::bindingIdentifierOrPattern( | ||||
| 4152 | DeclarationKind kind, YieldHandling yieldHandling, TokenKind tt) { | ||||
| 4153 | if (tt == TokenKind::LeftBracket) { | ||||
| 4154 | return arrayBindingPattern(kind, yieldHandling); | ||||
| 4155 | } | ||||
| 4156 | |||||
| 4157 | if (tt == TokenKind::LeftCurly) { | ||||
| 4158 | return objectBindingPattern(kind, yieldHandling); | ||||
| 4159 | } | ||||
| 4160 | |||||
| 4161 | if (!TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 4162 | error(JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt)); | ||||
| 4163 | return errorResult(); | ||||
| 4164 | } | ||||
| 4165 | |||||
| 4166 | return bindingIdentifier(kind, yieldHandling); | ||||
| 4167 | } | ||||
| 4168 | |||||
| 4169 | template <class ParseHandler, typename Unit> | ||||
| 4170 | typename ParseHandler::ListNodeResult | ||||
| 4171 | GeneralParser<ParseHandler, Unit>::objectBindingPattern( | ||||
| 4172 | DeclarationKind kind, YieldHandling yieldHandling) { | ||||
| 4173 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftCurly))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftCurly))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftCurly)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftCurly)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4173); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)" ")"); do { MOZ_CrashSequence(__null, 4173); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4174 | |||||
| 4175 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 4176 | if (!recursion.check(this->fc_)) { | ||||
| 4177 | return errorResult(); | ||||
| 4178 | } | ||||
| 4179 | |||||
| 4180 | uint32_t begin = pos().begin; | ||||
| 4181 | ListNodeType literal = MOZ_TRY(handler_.newObjectLiteral(begin))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newObjectLiteral(begin)); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4182 | |||||
| 4183 | Maybe<DeclarationKind> declKind = Some(kind); | ||||
| 4184 | TaggedParserAtomIndex propAtom; | ||||
| 4185 | for (;;) { | ||||
| 4186 | TokenKind tt; | ||||
| 4187 | if (!tokenStream.peekToken(&tt)) { | ||||
| 4188 | return errorResult(); | ||||
| 4189 | } | ||||
| 4190 | if (tt == TokenKind::RightCurly) { | ||||
| 4191 | break; | ||||
| 4192 | } | ||||
| 4193 | |||||
| 4194 | if (tt == TokenKind::TripleDot) { | ||||
| 4195 | tokenStream.consumeKnownToken(TokenKind::TripleDot); | ||||
| 4196 | uint32_t begin = pos().begin; | ||||
| 4197 | |||||
| 4198 | TokenKind tt; | ||||
| 4199 | if (!tokenStream.getToken(&tt)) { | ||||
| 4200 | return errorResult(); | ||||
| 4201 | } | ||||
| 4202 | |||||
| 4203 | if (!TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 4204 | error(JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt)); | ||||
| 4205 | return errorResult(); | ||||
| 4206 | } | ||||
| 4207 | |||||
| 4208 | NameNodeType inner = MOZ_TRY(bindingIdentifier(kind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifier(kind, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4209 | |||||
| 4210 | if (!handler_.addSpreadProperty(literal, begin, inner)) { | ||||
| 4211 | return errorResult(); | ||||
| 4212 | } | ||||
| 4213 | } else { | ||||
| 4214 | TokenPos namePos = anyChars.nextToken().pos; | ||||
| 4215 | |||||
| 4216 | PropertyType propType; | ||||
| 4217 | Node propName = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyOrMethodName(yieldHandling, PropertyNameInPattern, declKind , literal, &propType, &propAtom)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4218 | propertyOrMethodName(yieldHandling, PropertyNameInPattern, declKind,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyOrMethodName(yieldHandling, PropertyNameInPattern, declKind , literal, &propType, &propAtom)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4219 | literal, &propType, &propAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyOrMethodName(yieldHandling, PropertyNameInPattern, declKind , literal, &propType, &propAtom)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4220 | |||||
| 4221 | if (propType == PropertyType::Normal) { | ||||
| |||||
| 4222 | // Handle e.g., |var {p: x} = o| and |var {p: x=0} = o|. | ||||
| 4223 | |||||
| 4224 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 4225 | return errorResult(); | ||||
| 4226 | } | ||||
| 4227 | |||||
| 4228 | Node binding = | ||||
| 4229 | MOZ_TRY(bindingIdentifierOrPattern(kind, yieldHandling, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifierOrPattern(kind, yieldHandling, tt)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4230 | |||||
| 4231 | bool hasInitializer; | ||||
| 4232 | if (!tokenStream.matchToken(&hasInitializer, TokenKind::Assign, | ||||
| 4233 | TokenStream::SlashIsRegExp)) { | ||||
| 4234 | return errorResult(); | ||||
| 4235 | } | ||||
| 4236 | |||||
| 4237 | Node bindingExpr; | ||||
| 4238 | if (hasInitializer) { | ||||
| 4239 | bindingExpr = | ||||
| 4240 | MOZ_TRY(bindingInitializer(binding, kind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingInitializer(binding, kind, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4241 | } else { | ||||
| 4242 | bindingExpr = binding; | ||||
| 4243 | } | ||||
| 4244 | |||||
| 4245 | if (!handler_.addPropertyDefinition(literal, propName, bindingExpr)) { | ||||
| 4246 | return errorResult(); | ||||
| 4247 | } | ||||
| 4248 | } else if (propType == PropertyType::Shorthand) { | ||||
| 4249 | // Handle e.g., |var {x, y} = o| as destructuring shorthand | ||||
| 4250 | // for |var {x: x, y: y} = o|. | ||||
| 4251 | MOZ_ASSERT(TokenKindIsPossibleIdentifierName(tt))do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifierName(tt))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(TokenKindIsPossibleIdentifierName(tt)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("TokenKindIsPossibleIdentifierName(tt)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4251); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(tt)" ")" ); do { MOZ_CrashSequence(__null, 4251); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4252 | |||||
| 4253 | NameNodeType binding = MOZ_TRY(bindingIdentifier(kind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifier(kind, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4254 | |||||
| 4255 | if (!handler_.addShorthand(literal, handler_.asNameNode(propName), | ||||
| 4256 | binding)) { | ||||
| 4257 | return errorResult(); | ||||
| 4258 | } | ||||
| 4259 | } else if (propType == PropertyType::CoverInitializedName) { | ||||
| 4260 | // Handle e.g., |var {x=1, y=2} = o| as destructuring | ||||
| 4261 | // shorthand with default values. | ||||
| 4262 | MOZ_ASSERT(TokenKindIsPossibleIdentifierName(tt))do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifierName(tt))>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(TokenKindIsPossibleIdentifierName(tt)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("TokenKindIsPossibleIdentifierName(tt)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4262); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(tt)" ")" ); do { MOZ_CrashSequence(__null, 4262); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4263 | |||||
| 4264 | NameNodeType binding = MOZ_TRY(bindingIdentifier(kind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifier(kind, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4265 | |||||
| 4266 | tokenStream.consumeKnownToken(TokenKind::Assign); | ||||
| 4267 | |||||
| 4268 | BinaryNodeType bindingExpr = | ||||
| 4269 | MOZ_TRY(bindingInitializer(binding, kind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingInitializer(binding, kind, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4270 | |||||
| 4271 | if (!handler_.addPropertyDefinition(literal, propName, bindingExpr)) { | ||||
| 4272 | return errorResult(); | ||||
| 4273 | } | ||||
| 4274 | } else { | ||||
| 4275 | errorAt(namePos.begin, JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt)); | ||||
| 4276 | return errorResult(); | ||||
| 4277 | } | ||||
| 4278 | } | ||||
| 4279 | |||||
| 4280 | bool matched; | ||||
| 4281 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 4282 | TokenStream::SlashIsInvalid)) { | ||||
| 4283 | return errorResult(); | ||||
| 4284 | } | ||||
| 4285 | if (!matched) { | ||||
| 4286 | break; | ||||
| 4287 | } | ||||
| 4288 | if (tt == TokenKind::TripleDot) { | ||||
| 4289 | error(JSMSG_REST_WITH_COMMA); | ||||
| 4290 | return errorResult(); | ||||
| 4291 | } | ||||
| 4292 | } | ||||
| 4293 | |||||
| 4294 | if (!mustMatchToken(TokenKind::RightCurly, [this, begin](TokenKind actual) { | ||||
| 4295 | this->reportMissingClosing(JSMSG_CURLY_AFTER_LIST, JSMSG_CURLY_OPENED, | ||||
| 4296 | begin); | ||||
| 4297 | })) { | ||||
| 4298 | return errorResult(); | ||||
| 4299 | } | ||||
| 4300 | |||||
| 4301 | handler_.setEndPosition(literal, pos().end); | ||||
| 4302 | return literal; | ||||
| 4303 | } | ||||
| 4304 | |||||
| 4305 | template <class ParseHandler, typename Unit> | ||||
| 4306 | typename ParseHandler::ListNodeResult | ||||
| 4307 | GeneralParser<ParseHandler, Unit>::arrayBindingPattern( | ||||
| 4308 | DeclarationKind kind, YieldHandling yieldHandling) { | ||||
| 4309 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftBracket))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftBracket)) >::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftBracket)) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftBracket)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4309); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket)" ")"); do { MOZ_CrashSequence(__null, 4309); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4310 | |||||
| 4311 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 4312 | if (!recursion.check(this->fc_)) { | ||||
| 4313 | return errorResult(); | ||||
| 4314 | } | ||||
| 4315 | |||||
| 4316 | uint32_t begin = pos().begin; | ||||
| 4317 | ListNodeType literal = MOZ_TRY(handler_.newArrayLiteral(begin))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newArrayLiteral(begin)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4318 | |||||
| 4319 | uint32_t index = 0; | ||||
| 4320 | for (;; index++) { | ||||
| 4321 | if (index >= NativeObject::MAX_DENSE_ELEMENTS_COUNT) { | ||||
| 4322 | error(JSMSG_ARRAY_INIT_TOO_BIG); | ||||
| 4323 | return errorResult(); | ||||
| 4324 | } | ||||
| 4325 | |||||
| 4326 | TokenKind tt; | ||||
| 4327 | if (!tokenStream.getToken(&tt)) { | ||||
| 4328 | return errorResult(); | ||||
| 4329 | } | ||||
| 4330 | |||||
| 4331 | if (tt == TokenKind::RightBracket) { | ||||
| 4332 | anyChars.ungetToken(); | ||||
| 4333 | break; | ||||
| 4334 | } | ||||
| 4335 | |||||
| 4336 | if (tt == TokenKind::Comma) { | ||||
| 4337 | if (!handler_.addElision(literal, pos())) { | ||||
| 4338 | return errorResult(); | ||||
| 4339 | } | ||||
| 4340 | } else if (tt == TokenKind::TripleDot) { | ||||
| 4341 | uint32_t begin = pos().begin; | ||||
| 4342 | |||||
| 4343 | TokenKind tt; | ||||
| 4344 | if (!tokenStream.getToken(&tt)) { | ||||
| 4345 | return errorResult(); | ||||
| 4346 | } | ||||
| 4347 | |||||
| 4348 | Node inner = MOZ_TRY(bindingIdentifierOrPattern(kind, yieldHandling, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifierOrPattern(kind, yieldHandling, tt)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4349 | |||||
| 4350 | if (!handler_.addSpreadElement(literal, begin, inner)) { | ||||
| 4351 | return errorResult(); | ||||
| 4352 | } | ||||
| 4353 | } else { | ||||
| 4354 | Node binding = | ||||
| 4355 | MOZ_TRY(bindingIdentifierOrPattern(kind, yieldHandling, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifierOrPattern(kind, yieldHandling, tt)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4356 | |||||
| 4357 | bool hasInitializer; | ||||
| 4358 | if (!tokenStream.matchToken(&hasInitializer, TokenKind::Assign, | ||||
| 4359 | TokenStream::SlashIsRegExp)) { | ||||
| 4360 | return errorResult(); | ||||
| 4361 | } | ||||
| 4362 | |||||
| 4363 | Node element; | ||||
| 4364 | if (hasInitializer) { | ||||
| 4365 | element = MOZ_TRY(bindingInitializer(binding, kind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingInitializer(binding, kind, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4366 | } else { | ||||
| 4367 | element = binding; | ||||
| 4368 | } | ||||
| 4369 | |||||
| 4370 | handler_.addArrayElement(literal, element); | ||||
| 4371 | } | ||||
| 4372 | |||||
| 4373 | if (tt != TokenKind::Comma) { | ||||
| 4374 | // If we didn't already match TokenKind::Comma in above case. | ||||
| 4375 | bool matched; | ||||
| 4376 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 4377 | TokenStream::SlashIsRegExp)) { | ||||
| 4378 | return errorResult(); | ||||
| 4379 | } | ||||
| 4380 | if (!matched) { | ||||
| 4381 | break; | ||||
| 4382 | } | ||||
| 4383 | |||||
| 4384 | if (tt == TokenKind::TripleDot) { | ||||
| 4385 | error(JSMSG_REST_WITH_COMMA); | ||||
| 4386 | return errorResult(); | ||||
| 4387 | } | ||||
| 4388 | } | ||||
| 4389 | } | ||||
| 4390 | |||||
| 4391 | if (!mustMatchToken(TokenKind::RightBracket, [this, begin](TokenKind actual) { | ||||
| 4392 | this->reportMissingClosing(JSMSG_BRACKET_AFTER_LIST, | ||||
| 4393 | JSMSG_BRACKET_OPENED, begin); | ||||
| 4394 | })) { | ||||
| 4395 | return errorResult(); | ||||
| 4396 | } | ||||
| 4397 | |||||
| 4398 | handler_.setEndPosition(literal, pos().end); | ||||
| 4399 | return literal; | ||||
| 4400 | } | ||||
| 4401 | |||||
| 4402 | template <class ParseHandler, typename Unit> | ||||
| 4403 | typename ParseHandler::NodeResult | ||||
| 4404 | GeneralParser<ParseHandler, Unit>::destructuringDeclaration( | ||||
| 4405 | DeclarationKind kind, YieldHandling yieldHandling, TokenKind tt) { | ||||
| 4406 | MOZ_ASSERT(anyChars.isCurrentTokenType(tt))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(tt))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( tt)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(tt)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4406); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)" ")"); do { MOZ_CrashSequence(__null, 4406); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4407 | MOZ_ASSERT(tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly)do { static_assert( mozilla::detail::AssertionConditionType< decltype(tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly", "/root/firefox-clang/js/src/frontend/Parser.cpp", 4407); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly" ")"); do { MOZ_CrashSequence(__null, 4407); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4408 | |||||
| 4409 | if (tt
| ||||
| 4410 | return arrayBindingPattern(kind, yieldHandling); | ||||
| 4411 | } | ||||
| 4412 | return objectBindingPattern(kind, yieldHandling); | ||||
| 4413 | } | ||||
| 4414 | |||||
| 4415 | template <class ParseHandler, typename Unit> | ||||
| 4416 | typename ParseHandler::NodeResult | ||||
| 4417 | GeneralParser<ParseHandler, Unit>::destructuringDeclarationWithoutYieldOrAwait( | ||||
| 4418 | DeclarationKind kind, YieldHandling yieldHandling, TokenKind tt) { | ||||
| 4419 | uint32_t startYieldOffset = pc_->lastYieldOffset; | ||||
| 4420 | uint32_t startAwaitOffset = pc_->lastAwaitOffset; | ||||
| 4421 | |||||
| 4422 | Node res = MOZ_TRY(destructuringDeclaration(kind, yieldHandling, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (destructuringDeclaration(kind, yieldHandling, tt)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4423 | |||||
| 4424 | if (pc_->lastYieldOffset != startYieldOffset) { | ||||
| 4425 | errorAt(pc_->lastYieldOffset, JSMSG_YIELD_IN_PARAMETER); | ||||
| 4426 | return errorResult(); | ||||
| 4427 | } | ||||
| 4428 | if (pc_->lastAwaitOffset != startAwaitOffset) { | ||||
| 4429 | errorAt(pc_->lastAwaitOffset, JSMSG_AWAIT_IN_PARAMETER); | ||||
| 4430 | return errorResult(); | ||||
| 4431 | } | ||||
| 4432 | return res; | ||||
| 4433 | } | ||||
| 4434 | |||||
| 4435 | template <class ParseHandler, typename Unit> | ||||
| 4436 | typename ParseHandler::LexicalScopeNodeResult | ||||
| 4437 | GeneralParser<ParseHandler, Unit>::blockStatement(YieldHandling yieldHandling, | ||||
| 4438 | unsigned errorNumber) { | ||||
| 4439 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftCurly))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftCurly))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftCurly)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftCurly)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4439); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)" ")"); do { MOZ_CrashSequence(__null, 4439); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4440 | uint32_t openedPos = pos().begin; | ||||
| 4441 | |||||
| 4442 | ParseContext::Statement stmt(pc_, StatementKind::Block); | ||||
| 4443 | ParseContext::Scope scope(this); | ||||
| 4444 | if (!scope.init(pc_)) { | ||||
| 4445 | return errorResult(); | ||||
| 4446 | } | ||||
| 4447 | |||||
| 4448 | ListNodeType list = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4449 | |||||
| 4450 | if (!mustMatchToken(TokenKind::RightCurly, [this, errorNumber, | ||||
| 4451 | openedPos](TokenKind actual) { | ||||
| 4452 | this->reportMissingClosing(errorNumber, JSMSG_CURLY_OPENED, openedPos); | ||||
| 4453 | })) { | ||||
| 4454 | return errorResult(); | ||||
| 4455 | } | ||||
| 4456 | |||||
| 4457 | return finishLexicalScope(scope, list); | ||||
| 4458 | } | ||||
| 4459 | |||||
| 4460 | template <class ParseHandler, typename Unit> | ||||
| 4461 | typename ParseHandler::NodeResult | ||||
| 4462 | GeneralParser<ParseHandler, Unit>::expressionAfterForInOrOf( | ||||
| 4463 | ParseNodeKind forHeadKind, YieldHandling yieldHandling) { | ||||
| 4464 | MOZ_ASSERT(forHeadKind == ParseNodeKind::ForIn ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(forHeadKind == ParseNodeKind ::ForIn || forHeadKind == ParseNodeKind::ForOf))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4465); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf" ")"); do { MOZ_CrashSequence(__null, 4465); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 4465 | forHeadKind == ParseNodeKind::ForOf)do { static_assert( mozilla::detail::AssertionConditionType< decltype(forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(forHeadKind == ParseNodeKind ::ForIn || forHeadKind == ParseNodeKind::ForOf))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4465); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf" ")"); do { MOZ_CrashSequence(__null, 4465); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4466 | if (forHeadKind == ParseNodeKind::ForOf) { | ||||
| 4467 | return assignExpr(InAllowed, yieldHandling, TripledotProhibited); | ||||
| 4468 | } | ||||
| 4469 | |||||
| 4470 | return expr(InAllowed, yieldHandling, TripledotProhibited); | ||||
| 4471 | } | ||||
| 4472 | |||||
| 4473 | template <class ParseHandler, typename Unit> | ||||
| 4474 | typename ParseHandler::NodeResult | ||||
| 4475 | GeneralParser<ParseHandler, Unit>::declarationPattern( | ||||
| 4476 | DeclarationKind declKind, TokenKind tt, bool initialDeclaration, | ||||
| 4477 | YieldHandling yieldHandling, ParseNodeKind* forHeadKind, | ||||
| 4478 | Node* forInOrOfExpression) { | ||||
| 4479 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftBracket) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars .isCurrentTokenType(TokenKind::LeftCurly)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4480); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly)" ")"); do { MOZ_CrashSequence(__null, 4480); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 4480 | anyChars.isCurrentTokenType(TokenKind::LeftCurly))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars .isCurrentTokenType(TokenKind::LeftCurly)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4480); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly)" ")"); do { MOZ_CrashSequence(__null, 4480); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4481 | |||||
| 4482 | Node pattern = MOZ_TRY(destructuringDeclaration(declKind, yieldHandling, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (destructuringDeclaration(declKind, yieldHandling, tt)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 4483 | |||||
| 4484 | if (initialDeclaration && forHeadKind) { | ||||
| 4485 | bool isForIn, isForOf; | ||||
| 4486 | if (!matchInOrOf(&isForIn, &isForOf)) { | ||||
| 4487 | return errorResult(); | ||||
| 4488 | } | ||||
| 4489 | |||||
| 4490 | if (isForIn) { | ||||
| 4491 | *forHeadKind = ParseNodeKind::ForIn; | ||||
| 4492 | } else if (isForOf) { | ||||
| 4493 | *forHeadKind = ParseNodeKind::ForOf; | ||||
| 4494 | } else { | ||||
| 4495 | *forHeadKind = ParseNodeKind::ForHead; | ||||
| 4496 | } | ||||
| 4497 | |||||
| 4498 | if (*forHeadKind != ParseNodeKind::ForHead) { | ||||
| 4499 | *forInOrOfExpression = | ||||
| 4500 | MOZ_TRY(expressionAfterForInOrOf(*forHeadKind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expressionAfterForInOrOf(*forHeadKind, yieldHandling)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 4501 | |||||
| 4502 | return pattern; | ||||
| 4503 | } | ||||
| 4504 | } | ||||
| 4505 | |||||
| 4506 | if (!mustMatchToken(TokenKind::Assign, JSMSG_BAD_DESTRUCT_DECL)) { | ||||
| 4507 | return errorResult(); | ||||
| 4508 | } | ||||
| 4509 | |||||
| 4510 | Node init = MOZ_TRY(assignExpr(forHeadKind ? InProhibited : InAllowed,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(forHeadKind ? InProhibited : InAllowed, yieldHandling , TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4511 | yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(forHeadKind ? InProhibited : InAllowed, yieldHandling , TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4512 | |||||
| 4513 | return handler_.newAssignment(ParseNodeKind::AssignExpr, pattern, init); | ||||
| 4514 | } | ||||
| 4515 | |||||
| 4516 | template <class ParseHandler, typename Unit> | ||||
| 4517 | typename ParseHandler::AssignmentNodeResult | ||||
| 4518 | GeneralParser<ParseHandler, Unit>::initializerInNameDeclaration( | ||||
| 4519 | NameNodeType binding, DeclarationKind declKind, bool initialDeclaration, | ||||
| 4520 | YieldHandling yieldHandling, ParseNodeKind* forHeadKind, | ||||
| 4521 | Node* forInOrOfExpression) { | ||||
| 4522 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Assign))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Assign))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Assign)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Assign)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4522); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Assign)" ")"); do { MOZ_CrashSequence(__null, 4522); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4523 | |||||
| 4524 | uint32_t initializerOffset; | ||||
| 4525 | if (!tokenStream.peekOffset(&initializerOffset, TokenStream::SlashIsRegExp)) { | ||||
| 4526 | return errorResult(); | ||||
| 4527 | } | ||||
| 4528 | |||||
| 4529 | Node initializer = MOZ_TRY(assignExpr(forHeadKind ? InProhibited : InAllowed,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(forHeadKind ? InProhibited : InAllowed, yieldHandling , TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4530 | yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(forHeadKind ? InProhibited : InAllowed, yieldHandling , TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4531 | |||||
| 4532 | if (forHeadKind && initialDeclaration) { | ||||
| 4533 | bool isForIn, isForOf; | ||||
| 4534 | if (!matchInOrOf(&isForIn, &isForOf)) { | ||||
| 4535 | return errorResult(); | ||||
| 4536 | } | ||||
| 4537 | |||||
| 4538 | // An initialized declaration can't appear in a for-of: | ||||
| 4539 | // | ||||
| 4540 | // for (var/let/const x = ... of ...); // BAD | ||||
| 4541 | if (isForOf) { | ||||
| 4542 | errorAt(initializerOffset, JSMSG_OF_AFTER_FOR_LOOP_DECL); | ||||
| 4543 | return errorResult(); | ||||
| 4544 | } | ||||
| 4545 | |||||
| 4546 | if (isForIn) { | ||||
| 4547 | // Lexical declarations in for-in loops can't be initialized: | ||||
| 4548 | // | ||||
| 4549 | // for (let/const x = ... in ...); // BAD | ||||
| 4550 | if (DeclarationKindIsLexical(declKind)) { | ||||
| 4551 | errorAt(initializerOffset, JSMSG_IN_AFTER_LEXICAL_FOR_DECL); | ||||
| 4552 | return errorResult(); | ||||
| 4553 | } | ||||
| 4554 | |||||
| 4555 | // This leaves only initialized for-in |var| declarations. ES6 | ||||
| 4556 | // forbids these; later ES un-forbids in non-strict mode code. | ||||
| 4557 | *forHeadKind = ParseNodeKind::ForIn; | ||||
| 4558 | if (!strictModeErrorAt(initializerOffset, | ||||
| 4559 | JSMSG_INVALID_FOR_IN_DECL_WITH_INIT)) { | ||||
| 4560 | return errorResult(); | ||||
| 4561 | } | ||||
| 4562 | |||||
| 4563 | *forInOrOfExpression = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expressionAfterForInOrOf(ParseNodeKind::ForIn, yieldHandling )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 4564 | expressionAfterForInOrOf(ParseNodeKind::ForIn, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expressionAfterForInOrOf(ParseNodeKind::ForIn, yieldHandling )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 4565 | } else { | ||||
| 4566 | *forHeadKind = ParseNodeKind::ForHead; | ||||
| 4567 | } | ||||
| 4568 | } | ||||
| 4569 | |||||
| 4570 | return handler_.finishInitializerAssignment(binding, initializer); | ||||
| 4571 | } | ||||
| 4572 | |||||
| 4573 | template <class ParseHandler, typename Unit> | ||||
| 4574 | typename ParseHandler::NodeResult | ||||
| 4575 | GeneralParser<ParseHandler, Unit>::declarationName(DeclarationKind declKind, | ||||
| 4576 | TokenKind tt, | ||||
| 4577 | bool initialDeclaration, | ||||
| 4578 | YieldHandling yieldHandling, | ||||
| 4579 | ParseNodeKind* forHeadKind, | ||||
| 4580 | Node* forInOrOfExpression) { | ||||
| 4581 | // Anything other than possible identifier is an error. | ||||
| 4582 | if (!TokenKindIsPossibleIdentifier(tt)) { | ||||
| 4583 | error(JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt)); | ||||
| 4584 | return errorResult(); | ||||
| 4585 | } | ||||
| 4586 | |||||
| 4587 | TaggedParserAtomIndex name = bindingIdentifier(yieldHandling); | ||||
| 4588 | if (!name) { | ||||
| 4589 | return errorResult(); | ||||
| 4590 | } | ||||
| 4591 | |||||
| 4592 | NameNodeType binding = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4593 | |||||
| 4594 | TokenPos namePos = pos(); | ||||
| 4595 | |||||
| 4596 | // The '=' context after a variable name in a declaration is an opportunity | ||||
| 4597 | // for ASI, and thus for the next token to start an ExpressionStatement: | ||||
| 4598 | // | ||||
| 4599 | // var foo // VariableDeclaration | ||||
| 4600 | // /bar/g; // ExpressionStatement | ||||
| 4601 | // | ||||
| 4602 | // Therefore get the token here with SlashIsRegExp. | ||||
| 4603 | bool matched; | ||||
| 4604 | if (!tokenStream.matchToken(&matched, TokenKind::Assign, | ||||
| 4605 | TokenStream::SlashIsRegExp)) { | ||||
| 4606 | return errorResult(); | ||||
| 4607 | } | ||||
| 4608 | |||||
| 4609 | Node declaration; | ||||
| 4610 | if (matched) { | ||||
| 4611 | declaration = MOZ_TRY(initializerInNameDeclaration(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (initializerInNameDeclaration( binding, declKind, initialDeclaration , yieldHandling, forHeadKind, forInOrOfExpression)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4612 | binding, declKind, initialDeclaration, yieldHandling, forHeadKind,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (initializerInNameDeclaration( binding, declKind, initialDeclaration , yieldHandling, forHeadKind, forInOrOfExpression)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4613 | forInOrOfExpression))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (initializerInNameDeclaration( binding, declKind, initialDeclaration , yieldHandling, forHeadKind, forInOrOfExpression)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4614 | } else { | ||||
| 4615 | declaration = binding; | ||||
| 4616 | |||||
| 4617 | if (initialDeclaration && forHeadKind) { | ||||
| 4618 | bool isForIn, isForOf; | ||||
| 4619 | if (!matchInOrOf(&isForIn, &isForOf)) { | ||||
| 4620 | return errorResult(); | ||||
| 4621 | } | ||||
| 4622 | |||||
| 4623 | if (isForIn) { | ||||
| 4624 | *forHeadKind = ParseNodeKind::ForIn; | ||||
| 4625 | if (declKind == DeclarationKind::Using || | ||||
| 4626 | declKind == DeclarationKind::AwaitUsing) { | ||||
| 4627 | errorAt(namePos.begin, JSMSG_NO_IN_WITH_USING); | ||||
| 4628 | return errorResult(); | ||||
| 4629 | } | ||||
| 4630 | } else if (isForOf) { | ||||
| 4631 | *forHeadKind = ParseNodeKind::ForOf; | ||||
| 4632 | } else { | ||||
| 4633 | *forHeadKind = ParseNodeKind::ForHead; | ||||
| 4634 | } | ||||
| 4635 | } | ||||
| 4636 | |||||
| 4637 | if (forHeadKind && *forHeadKind != ParseNodeKind::ForHead) { | ||||
| 4638 | *forInOrOfExpression = | ||||
| 4639 | MOZ_TRY(expressionAfterForInOrOf(*forHeadKind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expressionAfterForInOrOf(*forHeadKind, yieldHandling)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 4640 | } else { | ||||
| 4641 | // Normal const declarations, and const declarations in for(;;) | ||||
| 4642 | // heads, must be initialized. | ||||
| 4643 | if (declKind == DeclarationKind::Const) { | ||||
| 4644 | errorAt(namePos.begin, JSMSG_BAD_CONST_DECL); | ||||
| 4645 | return errorResult(); | ||||
| 4646 | } | ||||
| 4647 | if (declKind == DeclarationKind::Using || | ||||
| 4648 | declKind == DeclarationKind::AwaitUsing) { | ||||
| 4649 | errorAt(namePos.begin, JSMSG_BAD_USING_DECL); | ||||
| 4650 | return errorResult(); | ||||
| 4651 | } | ||||
| 4652 | } | ||||
| 4653 | } | ||||
| 4654 | |||||
| 4655 | // Note the declared name after knowing whether or not we are in a for-of | ||||
| 4656 | // loop, due to special early error semantics in Annex B.3.5. | ||||
| 4657 | if (!noteDeclaredName(name, declKind, namePos)) { | ||||
| 4658 | return errorResult(); | ||||
| 4659 | } | ||||
| 4660 | |||||
| 4661 | return declaration; | ||||
| 4662 | } | ||||
| 4663 | |||||
| 4664 | template <class ParseHandler, typename Unit> | ||||
| 4665 | typename ParseHandler::DeclarationListNodeResult | ||||
| 4666 | GeneralParser<ParseHandler, Unit>::declarationList( | ||||
| 4667 | YieldHandling yieldHandling, ParseNodeKind kind, | ||||
| 4668 | ParseNodeKind* forHeadKind /* = nullptr */, | ||||
| 4669 | Node* forInOrOfExpression /* = nullptr */) { | ||||
| 4670 | MOZ_ASSERT(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind ::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4673); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" ")"); do { MOZ_CrashSequence(__null, 4673); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 4671 | kind == ParseNodeKind::ConstDecl ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind ::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4673); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" ")"); do { MOZ_CrashSequence(__null, 4673); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 4672 | kind == ParseNodeKind::UsingDecl ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind ::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4673); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" ")"); do { MOZ_CrashSequence(__null, 4673); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 4673 | kind == ParseNodeKind::AwaitUsingDecl)do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind ::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind ::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4673); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl" ")"); do { MOZ_CrashSequence(__null, 4673); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4674 | |||||
| 4675 | DeclarationKind declKind; | ||||
| 4676 | switch (kind) { | ||||
| 4677 | case ParseNodeKind::VarStmt: | ||||
| 4678 | declKind = DeclarationKind::Var; | ||||
| 4679 | break; | ||||
| 4680 | case ParseNodeKind::ConstDecl: | ||||
| 4681 | declKind = DeclarationKind::Const; | ||||
| 4682 | break; | ||||
| 4683 | case ParseNodeKind::LetDecl: | ||||
| 4684 | declKind = DeclarationKind::Let; | ||||
| 4685 | break; | ||||
| 4686 | case ParseNodeKind::UsingDecl: | ||||
| 4687 | declKind = DeclarationKind::Using; | ||||
| 4688 | break; | ||||
| 4689 | case ParseNodeKind::AwaitUsingDecl: | ||||
| 4690 | declKind = DeclarationKind::AwaitUsing; | ||||
| 4691 | break; | ||||
| 4692 | default: | ||||
| 4693 | MOZ_CRASH("Unknown declaration kind")do { do { } while (false); MOZ_ReportCrash("" "Unknown declaration kind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4693); AnnotateMozCrashReason ("MOZ_CRASH(" "Unknown declaration kind" ")"); do { MOZ_CrashSequence (__null, 4693); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 4694 | } | ||||
| 4695 | |||||
| 4696 | DeclarationListNodeType decl = | ||||
| 4697 | MOZ_TRY(handler_.newDeclarationList(kind, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newDeclarationList(kind, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4698 | |||||
| 4699 | bool moreDeclarations; | ||||
| 4700 | bool initialDeclaration = true; | ||||
| 4701 | do { | ||||
| 4702 | MOZ_ASSERT_IF(!initialDeclaration && forHeadKind,do { if (!initialDeclaration && forHeadKind) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(*forHeadKind == ParseNodeKind::ForHead)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(*forHeadKind == ParseNodeKind ::ForHead))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("*forHeadKind == ParseNodeKind::ForHead", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4703); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*forHeadKind == ParseNodeKind::ForHead" ")"); do { MOZ_CrashSequence(__null, 4703); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 4703 | *forHeadKind == ParseNodeKind::ForHead)do { if (!initialDeclaration && forHeadKind) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(*forHeadKind == ParseNodeKind::ForHead)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(*forHeadKind == ParseNodeKind ::ForHead))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("*forHeadKind == ParseNodeKind::ForHead", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4703); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*forHeadKind == ParseNodeKind::ForHead" ")"); do { MOZ_CrashSequence(__null, 4703); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 4704 | |||||
| 4705 | TokenKind tt; | ||||
| 4706 | if (!tokenStream.getToken(&tt)) { | ||||
| 4707 | return errorResult(); | ||||
| 4708 | } | ||||
| 4709 | |||||
| 4710 | Node binding; | ||||
| 4711 | if (tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly) { | ||||
| 4712 | if (declKind == DeclarationKind::Using || | ||||
| 4713 | declKind == DeclarationKind::AwaitUsing) { | ||||
| 4714 | MOZ_ASSERT(!initialDeclaration)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!initialDeclaration)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!initialDeclaration))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!initialDeclaration" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4714); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!initialDeclaration" ")"); do { MOZ_CrashSequence (__null, 4714); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 4715 | error(JSMSG_NO_DESTRUCT_IN_USING); | ||||
| 4716 | return errorResult(); | ||||
| 4717 | } | ||||
| 4718 | binding = MOZ_TRY(declarationPattern(declKind, tt, initialDeclaration,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationPattern(declKind, tt, initialDeclaration, yieldHandling , forHeadKind, forInOrOfExpression)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4719 | yieldHandling, forHeadKind,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationPattern(declKind, tt, initialDeclaration, yieldHandling , forHeadKind, forInOrOfExpression)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4720 | forInOrOfExpression))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationPattern(declKind, tt, initialDeclaration, yieldHandling , forHeadKind, forInOrOfExpression)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4721 | } else { | ||||
| 4722 | binding = MOZ_TRY(declarationName(declKind, tt, initialDeclaration,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationName(declKind, tt, initialDeclaration, yieldHandling , forHeadKind, forInOrOfExpression)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4723 | yieldHandling, forHeadKind,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationName(declKind, tt, initialDeclaration, yieldHandling , forHeadKind, forInOrOfExpression)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 4724 | forInOrOfExpression))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationName(declKind, tt, initialDeclaration, yieldHandling , forHeadKind, forInOrOfExpression)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4725 | } | ||||
| 4726 | |||||
| 4727 | handler_.addList(decl, binding); | ||||
| 4728 | |||||
| 4729 | // If we have a for-in/of loop, the above call matches the entirety | ||||
| 4730 | // of the loop head (up to the closing parenthesis). | ||||
| 4731 | if (forHeadKind && *forHeadKind != ParseNodeKind::ForHead) { | ||||
| 4732 | break; | ||||
| 4733 | } | ||||
| 4734 | |||||
| 4735 | initialDeclaration = false; | ||||
| 4736 | |||||
| 4737 | if (!tokenStream.matchToken(&moreDeclarations, TokenKind::Comma, | ||||
| 4738 | TokenStream::SlashIsRegExp)) { | ||||
| 4739 | return errorResult(); | ||||
| 4740 | } | ||||
| 4741 | } while (moreDeclarations); | ||||
| 4742 | |||||
| 4743 | return decl; | ||||
| 4744 | } | ||||
| 4745 | |||||
| 4746 | template <class ParseHandler, typename Unit> | ||||
| 4747 | typename ParseHandler::DeclarationListNodeResult | ||||
| 4748 | GeneralParser<ParseHandler, Unit>::lexicalDeclaration( | ||||
| 4749 | YieldHandling yieldHandling, DeclarationKind kind) { | ||||
| 4750 | MOZ_ASSERT(kind == DeclarationKind::Const || kind == DeclarationKind::Let ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == DeclarationKind::Const || kind == DeclarationKind ::Let || kind == DeclarationKind::Using || kind == DeclarationKind ::AwaitUsing)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4752); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing" ")"); do { MOZ_CrashSequence(__null, 4752); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 4751 | kind == DeclarationKind::Using ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == DeclarationKind::Const || kind == DeclarationKind ::Let || kind == DeclarationKind::Using || kind == DeclarationKind ::AwaitUsing)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4752); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing" ")"); do { MOZ_CrashSequence(__null, 4752); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 4752 | kind == DeclarationKind::AwaitUsing)do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == DeclarationKind::Const || kind == DeclarationKind ::Let || kind == DeclarationKind::Using || kind == DeclarationKind ::AwaitUsing)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4752); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing" ")"); do { MOZ_CrashSequence(__null, 4752); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4753 | |||||
| 4754 | if (options().selfHostingMode) { | ||||
| 4755 | error(JSMSG_SELFHOSTED_LEXICAL); | ||||
| 4756 | return errorResult(); | ||||
| 4757 | } | ||||
| 4758 | |||||
| 4759 | /* | ||||
| 4760 | * Parse body-level lets without a new block object. ES6 specs | ||||
| 4761 | * that an execution environment's initial lexical environment | ||||
| 4762 | * is the VariableEnvironment, i.e., body-level lets are in | ||||
| 4763 | * the same environment record as vars. | ||||
| 4764 | * | ||||
| 4765 | * However, they cannot be parsed exactly as vars, as ES6 | ||||
| 4766 | * requires that uninitialized lets throw ReferenceError on use. | ||||
| 4767 | * | ||||
| 4768 | * See 8.1.1.1.6 and the note in 13.2.1. | ||||
| 4769 | */ | ||||
| 4770 | ParseNodeKind pnk; | ||||
| 4771 | switch (kind) { | ||||
| 4772 | case DeclarationKind::Const: | ||||
| 4773 | pnk = ParseNodeKind::ConstDecl; | ||||
| 4774 | break; | ||||
| 4775 | case DeclarationKind::Using: | ||||
| 4776 | pnk = ParseNodeKind::UsingDecl; | ||||
| 4777 | break; | ||||
| 4778 | case DeclarationKind::AwaitUsing: | ||||
| 4779 | pnk = ParseNodeKind::AwaitUsingDecl; | ||||
| 4780 | break; | ||||
| 4781 | case DeclarationKind::Let: | ||||
| 4782 | pnk = ParseNodeKind::LetDecl; | ||||
| 4783 | break; | ||||
| 4784 | default: | ||||
| 4785 | MOZ_CRASH("unexpected node kind")do { do { } while (false); MOZ_ReportCrash("" "unexpected node kind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4785); AnnotateMozCrashReason ("MOZ_CRASH(" "unexpected node kind" ")"); do { MOZ_CrashSequence (__null, 4785); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 4786 | } | ||||
| 4787 | DeclarationListNodeType decl = MOZ_TRY(declarationList(yieldHandling, pnk))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationList(yieldHandling, pnk)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 4788 | if (!matchOrInsertSemicolon()) { | ||||
| 4789 | return errorResult(); | ||||
| 4790 | } | ||||
| 4791 | |||||
| 4792 | return decl; | ||||
| 4793 | } | ||||
| 4794 | |||||
| 4795 | template <class ParseHandler, typename Unit> | ||||
| 4796 | typename ParseHandler::NameNodeResult | ||||
| 4797 | GeneralParser<ParseHandler, Unit>::moduleExportName() { | ||||
| 4798 | MOZ_ASSERT(anyChars.currentToken().type == TokenKind::String)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.currentToken().type == TokenKind::String)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.currentToken().type == TokenKind::String))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.currentToken().type == TokenKind::String" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4798); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::String" ")"); do { MOZ_CrashSequence(__null, 4798); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4799 | TaggedParserAtomIndex name = anyChars.currentToken().atom(); | ||||
| 4800 | if (!this->parserAtoms().isModuleExportName(name)) { | ||||
| 4801 | error(JSMSG_UNPAIRED_SURROGATE_EXPORT); | ||||
| 4802 | return errorResult(); | ||||
| 4803 | } | ||||
| 4804 | return handler_.newStringLiteral(name, pos()); | ||||
| 4805 | } | ||||
| 4806 | |||||
| 4807 | template <class ParseHandler, typename Unit> | ||||
| 4808 | bool GeneralParser<ParseHandler, Unit>::withClause(ListNodeType attributesSet) { | ||||
| 4809 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::With))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::With))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::With)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::With)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 4809); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::With)" ")"); do { MOZ_CrashSequence(__null, 4809); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4810 | |||||
| 4811 | if (!abortIfSyntaxParser()) { | ||||
| 4812 | return false; | ||||
| 4813 | } | ||||
| 4814 | |||||
| 4815 | // https://tc39.es/ecma262/#prod-WithClause | ||||
| 4816 | // WithClause: | ||||
| 4817 | // with { } | ||||
| 4818 | // with { WithEntries ,opt } | ||||
| 4819 | if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_AFTER_WITH)) { | ||||
| 4820 | return false; | ||||
| 4821 | } | ||||
| 4822 | |||||
| 4823 | js::HashSet<TaggedParserAtomIndex, TaggedParserAtomIndexHasher, | ||||
| 4824 | js::SystemAllocPolicy> | ||||
| 4825 | usedAttributeKeys; | ||||
| 4826 | |||||
| 4827 | bool empty; | ||||
| 4828 | if (!tokenStream.matchToken(&empty, TokenKind::RightCurly)) { | ||||
| 4829 | return false; | ||||
| 4830 | } | ||||
| 4831 | if (empty) { | ||||
| 4832 | // WithClause: with { } | ||||
| 4833 | return true; | ||||
| 4834 | } | ||||
| 4835 | |||||
| 4836 | // WithClause: with { WithEntries ,opt } | ||||
| 4837 | // WithEntries: | ||||
| 4838 | // AttributeKey : StringLiteral | ||||
| 4839 | // AttributeKey : StringLiteral , WithEntries | ||||
| 4840 | for (;;) { | ||||
| 4841 | TokenKind token; | ||||
| 4842 | if (!tokenStream.getToken(&token)) { | ||||
| 4843 | return false; | ||||
| 4844 | } | ||||
| 4845 | |||||
| 4846 | TaggedParserAtomIndex keyName; | ||||
| 4847 | if (TokenKindIsPossibleIdentifierName(token)) { | ||||
| 4848 | keyName = anyChars.currentName(); | ||||
| 4849 | } else if (token == TokenKind::String) { | ||||
| 4850 | keyName = anyChars.currentToken().atom(); | ||||
| 4851 | } else { | ||||
| 4852 | error(JSMSG_ATTRIBUTE_KEY_EXPECTED); | ||||
| 4853 | return false; | ||||
| 4854 | } | ||||
| 4855 | |||||
| 4856 | auto p = usedAttributeKeys.lookupForAdd(keyName); | ||||
| 4857 | if (p) { | ||||
| 4858 | UniqueChars str = this->parserAtoms().toPrintableString(keyName); | ||||
| 4859 | if (!str) { | ||||
| 4860 | ReportOutOfMemory(this->fc_); | ||||
| 4861 | return false; | ||||
| 4862 | } | ||||
| 4863 | error(JSMSG_DUPLICATE_ATTRIBUTE_KEY, str.get()); | ||||
| 4864 | return false; | ||||
| 4865 | } | ||||
| 4866 | if (!usedAttributeKeys.add(p, keyName)) { | ||||
| 4867 | ReportOutOfMemory(this->fc_); | ||||
| 4868 | return false; | ||||
| 4869 | } | ||||
| 4870 | |||||
| 4871 | NameNodeType keyNode; | ||||
| 4872 | MOZ_TRY_VAR_OR_RETURN(keyNode, newName(keyName), false)do { auto parserTryVarTempResult_ = (newName(keyName)); if (( __builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (keyNode) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 4873 | |||||
| 4874 | if (!mustMatchToken(TokenKind::Colon, JSMSG_COLON_AFTER_ATTRIBUTE_KEY)) { | ||||
| 4875 | return false; | ||||
| 4876 | } | ||||
| 4877 | if (!mustMatchToken(TokenKind::String, JSMSG_WITH_CLAUSE_STRING_LITERAL)) { | ||||
| 4878 | return false; | ||||
| 4879 | } | ||||
| 4880 | |||||
| 4881 | NameNodeType valueNode; | ||||
| 4882 | MOZ_TRY_VAR_OR_RETURN(valueNode, stringLiteral(), false)do { auto parserTryVarTempResult_ = (stringLiteral()); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (valueNode) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 4883 | |||||
| 4884 | BinaryNodeType importAttributeNode; | ||||
| 4885 | MOZ_TRY_VAR_OR_RETURN(importAttributeNode,do { auto parserTryVarTempResult_ = (handler_.newImportAttribute (keyNode, valueNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importAttributeNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 4886 | handler_.newImportAttribute(keyNode, valueNode),do { auto parserTryVarTempResult_ = (handler_.newImportAttribute (keyNode, valueNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importAttributeNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 4887 | false)do { auto parserTryVarTempResult_ = (handler_.newImportAttribute (keyNode, valueNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importAttributeNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 4888 | handler_.addList(attributesSet, importAttributeNode); | ||||
| 4889 | |||||
| 4890 | bool hasComma; | ||||
| 4891 | if (!tokenStream.matchToken(&hasComma, TokenKind::Comma)) { | ||||
| 4892 | return false; | ||||
| 4893 | } | ||||
| 4894 | if (!hasComma) { | ||||
| 4895 | // No comma: end of WithEntries, expect closing '}'. | ||||
| 4896 | break; | ||||
| 4897 | } | ||||
| 4898 | // The comma is either the optional trailing ',' in WithClause | ||||
| 4899 | // (with { WithEntries ,opt }), or the ',' separator in WithEntries | ||||
| 4900 | // (AttributeKey : StringLiteral , WithEntries). | ||||
| 4901 | TokenKind next; | ||||
| 4902 | if (!tokenStream.peekToken(&next)) { | ||||
| 4903 | return false; | ||||
| 4904 | } | ||||
| 4905 | if (next == TokenKind::RightCurly) { | ||||
| 4906 | // Optional trailing comma in WithClause — '}' consumed below. | ||||
| 4907 | break; | ||||
| 4908 | } | ||||
| 4909 | // Comma was the WithEntries separator — another WithEntries must follow. | ||||
| 4910 | } | ||||
| 4911 | |||||
| 4912 | return mustMatchToken(TokenKind::RightCurly, | ||||
| 4913 | JSMSG_RC_AFTER_IMPORT_ATTRIBUTE_LIST); | ||||
| 4914 | } | ||||
| 4915 | |||||
| 4916 | template <class ParseHandler, typename Unit> | ||||
| 4917 | bool GeneralParser<ParseHandler, Unit>::namedImports( | ||||
| 4918 | ListNodeType importSpecSet) { | ||||
| 4919 | if (!abortIfSyntaxParser()) { | ||||
| 4920 | return false; | ||||
| 4921 | } | ||||
| 4922 | |||||
| 4923 | while (true) { | ||||
| 4924 | // Handle the forms |import {} from 'a'| and | ||||
| 4925 | // |import { ..., } from 'a'| (where ... is non empty), by | ||||
| 4926 | // escaping the loop early if the next token is }. | ||||
| 4927 | TokenKind tt; | ||||
| 4928 | if (!tokenStream.getToken(&tt)) { | ||||
| 4929 | return false; | ||||
| 4930 | } | ||||
| 4931 | |||||
| 4932 | if (tt == TokenKind::RightCurly) { | ||||
| 4933 | break; | ||||
| 4934 | } | ||||
| 4935 | |||||
| 4936 | TaggedParserAtomIndex importName; | ||||
| 4937 | NameNodeType importNameNode = null(); | ||||
| 4938 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 4939 | importName = anyChars.currentName(); | ||||
| 4940 | MOZ_TRY_VAR_OR_RETURN(importNameNode, newName(importName), false)do { auto parserTryVarTempResult_ = (newName(importName)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (importNameNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 4941 | } else if (tt == TokenKind::String) { | ||||
| 4942 | MOZ_TRY_VAR_OR_RETURN(importNameNode, moduleExportName(), false)do { auto parserTryVarTempResult_ = (moduleExportName()); if ( (__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (importNameNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 4943 | } else { | ||||
| 4944 | error(JSMSG_NO_IMPORT_NAME); | ||||
| 4945 | return false; | ||||
| 4946 | } | ||||
| 4947 | |||||
| 4948 | bool matched; | ||||
| 4949 | if (!tokenStream.matchToken(&matched, TokenKind::As)) { | ||||
| 4950 | return false; | ||||
| 4951 | } | ||||
| 4952 | |||||
| 4953 | if (matched) { | ||||
| 4954 | TokenKind afterAs; | ||||
| 4955 | if (!tokenStream.getToken(&afterAs)) { | ||||
| 4956 | return false; | ||||
| 4957 | } | ||||
| 4958 | |||||
| 4959 | if (!TokenKindIsPossibleIdentifierName(afterAs)) { | ||||
| 4960 | error(JSMSG_NO_BINDING_NAME); | ||||
| 4961 | return false; | ||||
| 4962 | } | ||||
| 4963 | } else { | ||||
| 4964 | // String export names can't refer to local bindings. | ||||
| 4965 | if (tt == TokenKind::String) { | ||||
| 4966 | error(JSMSG_AS_AFTER_STRING); | ||||
| 4967 | return false; | ||||
| 4968 | } | ||||
| 4969 | |||||
| 4970 | // Keywords cannot be bound to themselves, so an import name | ||||
| 4971 | // that is a keyword is a syntax error if it is not followed | ||||
| 4972 | // by the keyword 'as'. | ||||
| 4973 | // See the ImportSpecifier production in ES6 section 15.2.2. | ||||
| 4974 | MOZ_ASSERT(importName)do { static_assert( mozilla::detail::AssertionConditionType< decltype(importName)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(importName))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("importName", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 4974); AnnotateMozCrashReason("MOZ_ASSERT" "(" "importName" ")"); do { MOZ_CrashSequence(__null, 4974); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 4975 | if (IsKeyword(importName)) { | ||||
| 4976 | error(JSMSG_AS_AFTER_RESERVED_WORD, ReservedWordToCharZ(importName)); | ||||
| 4977 | return false; | ||||
| 4978 | } | ||||
| 4979 | } | ||||
| 4980 | |||||
| 4981 | TaggedParserAtomIndex bindingAtom = importedBinding(); | ||||
| 4982 | if (!bindingAtom) { | ||||
| 4983 | return false; | ||||
| 4984 | } | ||||
| 4985 | |||||
| 4986 | NameNodeType bindingName; | ||||
| 4987 | MOZ_TRY_VAR_OR_RETURN(bindingName, newName(bindingAtom), false)do { auto parserTryVarTempResult_ = (newName(bindingAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (bindingName) = parserTryVarTempResult_. unwrap(); } while (0); | ||||
| 4988 | if (!noteDeclaredName(bindingAtom, DeclarationKind::Import, pos())) { | ||||
| 4989 | return false; | ||||
| 4990 | } | ||||
| 4991 | |||||
| 4992 | BinaryNodeType importSpec; | ||||
| 4993 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newImportSpec(importNameNode , bindingName)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importSpec) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 4994 | importSpec, handler_.newImportSpec(importNameNode, bindingName), false)do { auto parserTryVarTempResult_ = (handler_.newImportSpec(importNameNode , bindingName)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importSpec) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 4995 | |||||
| 4996 | handler_.addList(importSpecSet, importSpec); | ||||
| 4997 | |||||
| 4998 | TokenKind next; | ||||
| 4999 | if (!tokenStream.getToken(&next)) { | ||||
| 5000 | return false; | ||||
| 5001 | } | ||||
| 5002 | |||||
| 5003 | if (next == TokenKind::RightCurly) { | ||||
| 5004 | break; | ||||
| 5005 | } | ||||
| 5006 | |||||
| 5007 | if (next != TokenKind::Comma) { | ||||
| 5008 | error(JSMSG_RC_AFTER_IMPORT_SPEC_LIST); | ||||
| 5009 | return false; | ||||
| 5010 | } | ||||
| 5011 | } | ||||
| 5012 | |||||
| 5013 | return true; | ||||
| 5014 | } | ||||
| 5015 | |||||
| 5016 | template <class ParseHandler, typename Unit> | ||||
| 5017 | bool GeneralParser<ParseHandler, Unit>::namespaceImport( | ||||
| 5018 | ListNodeType importSpecSet) { | ||||
| 5019 | if (!abortIfSyntaxParser()) { | ||||
| 5020 | return false; | ||||
| 5021 | } | ||||
| 5022 | |||||
| 5023 | if (!mustMatchToken(TokenKind::As, JSMSG_AS_AFTER_IMPORT_STAR)) { | ||||
| 5024 | return false; | ||||
| 5025 | } | ||||
| 5026 | uint32_t begin = pos().begin; | ||||
| 5027 | |||||
| 5028 | if (!mustMatchToken(TokenKindIsPossibleIdentifierName, | ||||
| 5029 | JSMSG_NO_BINDING_NAME)) { | ||||
| 5030 | return false; | ||||
| 5031 | } | ||||
| 5032 | |||||
| 5033 | // Namespace imports are not indirect bindings but lexical | ||||
| 5034 | // definitions that hold a module namespace object. They are treated | ||||
| 5035 | // as const variables which are initialized during the | ||||
| 5036 | // ModuleInstantiate step. | ||||
| 5037 | TaggedParserAtomIndex bindingName = importedBinding(); | ||||
| 5038 | if (!bindingName) { | ||||
| 5039 | return false; | ||||
| 5040 | } | ||||
| 5041 | NameNodeType bindingNameNode; | ||||
| 5042 | MOZ_TRY_VAR_OR_RETURN(bindingNameNode, newName(bindingName), false)do { auto parserTryVarTempResult_ = (newName(bindingName)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (bindingNameNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 5043 | if (!noteDeclaredName(bindingName, DeclarationKind::Const, pos())) { | ||||
| 5044 | return false; | ||||
| 5045 | } | ||||
| 5046 | |||||
| 5047 | // The namespace import name is currently required to live on the | ||||
| 5048 | // environment. | ||||
| 5049 | pc_->varScope().lookupDeclaredName(bindingName)->value()->setClosedOver(); | ||||
| 5050 | |||||
| 5051 | UnaryNodeType importSpec; | ||||
| 5052 | MOZ_TRY_VAR_OR_RETURN(importSpec,do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec (begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importSpec) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 5053 | handler_.newImportNamespaceSpec(begin, bindingNameNode),do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec (begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importSpec) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 5054 | false)do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec (begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (importSpec) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 5055 | |||||
| 5056 | handler_.addList(importSpecSet, importSpec); | ||||
| 5057 | |||||
| 5058 | return true; | ||||
| 5059 | } | ||||
| 5060 | |||||
| 5061 | template <class ParseHandler, typename Unit> | ||||
| 5062 | typename ParseHandler::BinaryNodeResult | ||||
| 5063 | GeneralParser<ParseHandler, Unit>::importDeclaration() { | ||||
| 5064 | if (!abortIfSyntaxParser()) { | ||||
| 5065 | return errorResult(); | ||||
| 5066 | } | ||||
| 5067 | |||||
| 5068 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Import))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Import))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Import)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Import)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5068); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Import)" ")"); do { MOZ_CrashSequence(__null, 5068); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5069 | |||||
| 5070 | if (!pc_->atModuleLevel()) { | ||||
| 5071 | error(JSMSG_IMPORT_DECL_AT_TOP_LEVEL); | ||||
| 5072 | return errorResult(); | ||||
| 5073 | } | ||||
| 5074 | |||||
| 5075 | uint32_t begin = pos().begin; | ||||
| 5076 | TokenKind tt; | ||||
| 5077 | if (!tokenStream.getToken(&tt)) { | ||||
| 5078 | return errorResult(); | ||||
| 5079 | } | ||||
| 5080 | |||||
| 5081 | ListNodeType importSpecSet = | ||||
| 5082 | MOZ_TRY(handler_.newList(ParseNodeKind::ImportSpecList, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newList(ParseNodeKind::ImportSpecList, pos())); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 5083 | |||||
| 5084 | ImportPhase phase = ImportPhase::Evaluation; | ||||
| 5085 | NameNodeType importSourceBinding; | ||||
| 5086 | if (tt == TokenKind::String) { | ||||
| 5087 | // Handle the form |import 'a'| by leaving the list empty. This is | ||||
| 5088 | // equivalent to |import {} from 'a'|. | ||||
| 5089 | handler_.setEndPosition(importSpecSet, pos().begin); | ||||
| 5090 | } else { | ||||
| 5091 | if (tt == TokenKind::LeftCurly) { | ||||
| 5092 | if (!namedImports(importSpecSet)) { | ||||
| 5093 | return errorResult(); | ||||
| 5094 | } | ||||
| 5095 | } else if (tt == TokenKind::Mul) { | ||||
| 5096 | if (!namespaceImport(importSpecSet)) { | ||||
| 5097 | return errorResult(); | ||||
| 5098 | } | ||||
| 5099 | } else if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 5100 | // `source` is a contextual keyword: |import source x from 'b'| is a | ||||
| 5101 | // source phase import, but |import source from 'b'| imports the default | ||||
| 5102 | // export under the binding name `source`. Disambiguate with lookahead | ||||
| 5103 | // before committing to a phase, leaving `source` as the current token. | ||||
| 5104 | if (options().sourcePhaseImports() && tt == TokenKind::Source) { | ||||
| 5105 | if (!tokenStream.peekToken(&tt)) { | ||||
| 5106 | return errorResult(); | ||||
| 5107 | } | ||||
| 5108 | if (tt == TokenKind::From) { | ||||
| 5109 | // |import source from ...| is a source phase import only if a second | ||||
| 5110 | // `from` follows, as in |import source from from 'b'|. | ||||
| 5111 | tokenStream.consumeKnownToken(TokenKind::From); | ||||
| 5112 | if (!tokenStream.peekToken(&tt)) { | ||||
| 5113 | return errorResult(); | ||||
| 5114 | } | ||||
| 5115 | if (tt == TokenKind::From) { | ||||
| 5116 | phase = ImportPhase::Source; | ||||
| 5117 | } | ||||
| 5118 | anyChars.ungetToken(); | ||||
| 5119 | } else if (tt != TokenKind::Comma) { | ||||
| 5120 | // |import source <binding> from 'b'| | ||||
| 5121 | phase = ImportPhase::Source; | ||||
| 5122 | } | ||||
| 5123 | } | ||||
| 5124 | |||||
| 5125 | if (phase == ImportPhase::Source) { | ||||
| 5126 | // Handle the form |import source a from 'b'|. | ||||
| 5127 | if (!tokenStream.getToken(&tt)) { | ||||
| 5128 | return errorResult(); | ||||
| 5129 | } | ||||
| 5130 | |||||
| 5131 | if (!TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 5132 | error(JSMSG_DECLARATION_AFTER_IMPORT_SOURCE); | ||||
| 5133 | return errorResult(); | ||||
| 5134 | } | ||||
| 5135 | |||||
| 5136 | TaggedParserAtomIndex bindingAtom = importedBinding(); | ||||
| 5137 | if (!bindingAtom) { | ||||
| 5138 | return errorResult(); | ||||
| 5139 | } | ||||
| 5140 | |||||
| 5141 | importSourceBinding = MOZ_TRY(newName(bindingAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(bindingAtom)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5142 | |||||
| 5143 | // We handle import source like namespace imports. | ||||
| 5144 | // It's not an indirect binding, but instead a lexical definition, | ||||
| 5145 | // that's treated like a const variable. | ||||
| 5146 | if (!noteDeclaredName(bindingAtom, DeclarationKind::Const, pos())) { | ||||
| 5147 | return errorResult(); | ||||
| 5148 | } | ||||
| 5149 | |||||
| 5150 | // The source phase import name is currently required to live on the | ||||
| 5151 | // environment. | ||||
| 5152 | pc_->varScope() | ||||
| 5153 | .lookupDeclaredName(bindingAtom) | ||||
| 5154 | ->value() | ||||
| 5155 | ->setClosedOver(); | ||||
| 5156 | } else { | ||||
| 5157 | // Handle the form |import a from 'b'|, by adding a single import | ||||
| 5158 | // specifier to the list, with 'default' as the import name and | ||||
| 5159 | // 'a' as the binding name. This is equivalent to | ||||
| 5160 | // |import { default as a } from 'b'|. | ||||
| 5161 | NameNodeType importName = | ||||
| 5162 | MOZ_TRY(newName(TaggedParserAtomIndex::WellKnown::default_()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(TaggedParserAtomIndex::WellKnown::default_())); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 5163 | |||||
| 5164 | TaggedParserAtomIndex bindingAtom = importedBinding(); | ||||
| 5165 | if (!bindingAtom) { | ||||
| 5166 | return errorResult(); | ||||
| 5167 | } | ||||
| 5168 | |||||
| 5169 | NameNodeType bindingName = MOZ_TRY(newName(bindingAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(bindingAtom)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5170 | |||||
| 5171 | if (!noteDeclaredName(bindingAtom, DeclarationKind::Import, pos())) { | ||||
| 5172 | return errorResult(); | ||||
| 5173 | } | ||||
| 5174 | |||||
| 5175 | BinaryNodeType importSpec = | ||||
| 5176 | MOZ_TRY(handler_.newImportSpec(importName, bindingName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newImportSpec(importName, bindingName)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5177 | |||||
| 5178 | handler_.addList(importSpecSet, importSpec); | ||||
| 5179 | |||||
| 5180 | if (!tokenStream.peekToken(&tt)) { | ||||
| 5181 | return errorResult(); | ||||
| 5182 | } | ||||
| 5183 | |||||
| 5184 | if (tt == TokenKind::Comma) { | ||||
| 5185 | tokenStream.consumeKnownToken(tt); | ||||
| 5186 | if (!tokenStream.getToken(&tt)) { | ||||
| 5187 | return errorResult(); | ||||
| 5188 | } | ||||
| 5189 | |||||
| 5190 | if (tt == TokenKind::LeftCurly) { | ||||
| 5191 | if (!namedImports(importSpecSet)) { | ||||
| 5192 | return errorResult(); | ||||
| 5193 | } | ||||
| 5194 | } else if (tt == TokenKind::Mul) { | ||||
| 5195 | if (!namespaceImport(importSpecSet)) { | ||||
| 5196 | return errorResult(); | ||||
| 5197 | } | ||||
| 5198 | } else { | ||||
| 5199 | error(JSMSG_NAMED_IMPORTS_OR_NAMESPACE_IMPORT); | ||||
| 5200 | return errorResult(); | ||||
| 5201 | } | ||||
| 5202 | } | ||||
| 5203 | } | ||||
| 5204 | } else { | ||||
| 5205 | error(JSMSG_DECLARATION_AFTER_IMPORT); | ||||
| 5206 | return errorResult(); | ||||
| 5207 | } | ||||
| 5208 | |||||
| 5209 | if (!mustMatchToken(TokenKind::From, JSMSG_FROM_AFTER_IMPORT_CLAUSE)) { | ||||
| 5210 | return errorResult(); | ||||
| 5211 | } | ||||
| 5212 | |||||
| 5213 | if (!mustMatchToken(TokenKind::String, JSMSG_MODULE_SPEC_AFTER_FROM)) { | ||||
| 5214 | return errorResult(); | ||||
| 5215 | } | ||||
| 5216 | } | ||||
| 5217 | |||||
| 5218 | NameNodeType moduleSpec = MOZ_TRY(stringLiteral())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (stringLiteral()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5219 | |||||
| 5220 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 5221 | return errorResult(); | ||||
| 5222 | } | ||||
| 5223 | |||||
| 5224 | Node importAttributeList; | ||||
| 5225 | if (phase == ImportPhase::Source) { | ||||
| 5226 | // Source phase imports do not support import attributes | ||||
| 5227 | importAttributeList = MOZ_TRY(handler_.newPosHolder(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPosHolder(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5228 | } else { | ||||
| 5229 | ListNodeType attributeList = | ||||
| 5230 | MOZ_TRY(handler_.newList(ParseNodeKind::ImportAttributeList, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newList(ParseNodeKind::ImportAttributeList, pos())) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5231 | |||||
| 5232 | if (tt == TokenKind::With) { | ||||
| 5233 | tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp); | ||||
| 5234 | |||||
| 5235 | if (!withClause(attributeList)) { | ||||
| 5236 | return errorResult(); | ||||
| 5237 | } | ||||
| 5238 | } | ||||
| 5239 | |||||
| 5240 | importAttributeList = attributeList; | ||||
| 5241 | } | ||||
| 5242 | |||||
| 5243 | if (!matchOrInsertSemicolon(TokenStream::SlashIsRegExp)) { | ||||
| 5244 | return errorResult(); | ||||
| 5245 | } | ||||
| 5246 | |||||
| 5247 | BinaryNodeType moduleRequest = MOZ_TRY(handler_.newModuleRequest(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newModuleRequest( moduleSpec, importAttributeList, TokenPos (begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 5248 | moduleSpec, importAttributeList, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newModuleRequest( moduleSpec, importAttributeList, TokenPos (begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5249 | |||||
| 5250 | Node importClause; | ||||
| 5251 | if (phase == ImportPhase::Source) { | ||||
| 5252 | importClause = importSourceBinding; | ||||
| 5253 | } else { | ||||
| 5254 | importClause = importSpecSet; | ||||
| 5255 | } | ||||
| 5256 | |||||
| 5257 | BinaryNodeType node = MOZ_TRY(handler_.newImportDeclaration(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newImportDeclaration( importClause, moduleRequest, phase , TokenPos(begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 5258 | importClause, moduleRequest, phase, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newImportDeclaration( importClause, moduleRequest, phase , TokenPos(begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5259 | if (!processImport(node)) { | ||||
| 5260 | return errorResult(); | ||||
| 5261 | } | ||||
| 5262 | |||||
| 5263 | return node; | ||||
| 5264 | } | ||||
| 5265 | |||||
| 5266 | template <class ParseHandler, typename Unit> | ||||
| 5267 | inline typename ParseHandler::NodeResult | ||||
| 5268 | GeneralParser<ParseHandler, Unit>::importDeclarationOrImportExpr( | ||||
| 5269 | YieldHandling yieldHandling) { | ||||
| 5270 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Import))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Import))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Import)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Import)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5270); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Import)" ")"); do { MOZ_CrashSequence(__null, 5270); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5271 | |||||
| 5272 | TokenKind tt; | ||||
| 5273 | if (!tokenStream.peekToken(&tt)) { | ||||
| 5274 | return errorResult(); | ||||
| 5275 | } | ||||
| 5276 | |||||
| 5277 | if (tt == TokenKind::Dot || tt == TokenKind::LeftParen) { | ||||
| 5278 | return expressionStatement(yieldHandling); | ||||
| 5279 | } | ||||
| 5280 | |||||
| 5281 | return importDeclaration(); | ||||
| 5282 | } | ||||
| 5283 | |||||
| 5284 | template <typename Unit> | ||||
| 5285 | bool Parser<FullParseHandler, Unit>::checkExportedName( | ||||
| 5286 | TaggedParserAtomIndex exportName) { | ||||
| 5287 | switch (pc_->sc()->asModuleContext()->builder.noteExportedName(exportName)) { | ||||
| 5288 | case ModuleBuilder::NoteExportedNameResult::Success: | ||||
| 5289 | return true; | ||||
| 5290 | case ModuleBuilder::NoteExportedNameResult::OutOfMemory: | ||||
| 5291 | return false; | ||||
| 5292 | case ModuleBuilder::NoteExportedNameResult::AlreadyDeclared: | ||||
| 5293 | break; | ||||
| 5294 | } | ||||
| 5295 | |||||
| 5296 | UniqueChars str = this->parserAtoms().toPrintableString(exportName); | ||||
| 5297 | if (!str) { | ||||
| 5298 | ReportOutOfMemory(this->fc_); | ||||
| 5299 | return false; | ||||
| 5300 | } | ||||
| 5301 | |||||
| 5302 | error(JSMSG_DUPLICATE_EXPORT_NAME, str.get()); | ||||
| 5303 | return false; | ||||
| 5304 | } | ||||
| 5305 | |||||
| 5306 | template <typename Unit> | ||||
| 5307 | inline bool Parser<SyntaxParseHandler, Unit>::checkExportedName( | ||||
| 5308 | TaggedParserAtomIndex exportName) { | ||||
| 5309 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5309); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5309); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5310 | return false; | ||||
| 5311 | } | ||||
| 5312 | |||||
| 5313 | template <class ParseHandler, typename Unit> | ||||
| 5314 | inline bool GeneralParser<ParseHandler, Unit>::checkExportedName( | ||||
| 5315 | TaggedParserAtomIndex exportName) { | ||||
| 5316 | return asFinalParser()->checkExportedName(exportName); | ||||
| 5317 | } | ||||
| 5318 | |||||
| 5319 | template <typename Unit> | ||||
| 5320 | bool Parser<FullParseHandler, Unit>::checkExportedNamesForArrayBinding( | ||||
| 5321 | ListNode* array) { | ||||
| 5322 | MOZ_ASSERT(array->isKind(ParseNodeKind::ArrayExpr))do { static_assert( mozilla::detail::AssertionConditionType< decltype(array->isKind(ParseNodeKind::ArrayExpr))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(array->isKind(ParseNodeKind::ArrayExpr)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("array->isKind(ParseNodeKind::ArrayExpr)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5322); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "array->isKind(ParseNodeKind::ArrayExpr)" ")"); do { MOZ_CrashSequence(__null, 5322); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5323 | |||||
| 5324 | for (ParseNode* node : array->contents()) { | ||||
| 5325 | if (node->isKind(ParseNodeKind::Elision)) { | ||||
| 5326 | continue; | ||||
| 5327 | } | ||||
| 5328 | |||||
| 5329 | ParseNode* binding; | ||||
| 5330 | if (node->isKind(ParseNodeKind::Spread)) { | ||||
| 5331 | binding = node->as<UnaryNode>().kid(); | ||||
| 5332 | } else if (node->isKind(ParseNodeKind::AssignExpr)) { | ||||
| 5333 | binding = node->as<AssignmentNode>().left(); | ||||
| 5334 | } else { | ||||
| 5335 | binding = node; | ||||
| 5336 | } | ||||
| 5337 | |||||
| 5338 | if (!checkExportedNamesForDeclaration(binding)) { | ||||
| 5339 | return false; | ||||
| 5340 | } | ||||
| 5341 | } | ||||
| 5342 | |||||
| 5343 | return true; | ||||
| 5344 | } | ||||
| 5345 | |||||
| 5346 | template <typename Unit> | ||||
| 5347 | inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNamesForArrayBinding( | ||||
| 5348 | ListNodeType array) { | ||||
| 5349 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5349); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5349); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5350 | return false; | ||||
| 5351 | } | ||||
| 5352 | |||||
| 5353 | template <class ParseHandler, typename Unit> | ||||
| 5354 | inline bool | ||||
| 5355 | GeneralParser<ParseHandler, Unit>::checkExportedNamesForArrayBinding( | ||||
| 5356 | ListNodeType array) { | ||||
| 5357 | return asFinalParser()->checkExportedNamesForArrayBinding(array); | ||||
| 5358 | } | ||||
| 5359 | |||||
| 5360 | template <typename Unit> | ||||
| 5361 | bool Parser<FullParseHandler, Unit>::checkExportedNamesForObjectBinding( | ||||
| 5362 | ListNode* obj) { | ||||
| 5363 | MOZ_ASSERT(obj->isKind(ParseNodeKind::ObjectExpr))do { static_assert( mozilla::detail::AssertionConditionType< decltype(obj->isKind(ParseNodeKind::ObjectExpr))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(obj->isKind(ParseNodeKind::ObjectExpr)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("obj->isKind(ParseNodeKind::ObjectExpr)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5363); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "obj->isKind(ParseNodeKind::ObjectExpr)" ")"); do { MOZ_CrashSequence(__null, 5363); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5364 | |||||
| 5365 | for (ParseNode* node : obj->contents()) { | ||||
| 5366 | MOZ_ASSERT(node->isKind(ParseNodeKind::MutateProto) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5369); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" ")"); do { MOZ_CrashSequence(__null, 5369); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 5367 | node->isKind(ParseNodeKind::PropertyDefinition) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5369); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" ")"); do { MOZ_CrashSequence(__null, 5369); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 5368 | node->isKind(ParseNodeKind::Shorthand) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5369); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" ")"); do { MOZ_CrashSequence(__null, 5369); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 5369 | node->isKind(ParseNodeKind::Spread))do { static_assert( mozilla::detail::AssertionConditionType< decltype(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread ))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(node->isKind(ParseNodeKind::MutateProto) || node-> isKind(ParseNodeKind::PropertyDefinition) || node->isKind( ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5369); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)" ")"); do { MOZ_CrashSequence(__null, 5369); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5370 | |||||
| 5371 | ParseNode* target; | ||||
| 5372 | if (node->isKind(ParseNodeKind::Spread)) { | ||||
| 5373 | target = node->as<UnaryNode>().kid(); | ||||
| 5374 | } else { | ||||
| 5375 | if (node->isKind(ParseNodeKind::MutateProto)) { | ||||
| 5376 | target = node->as<UnaryNode>().kid(); | ||||
| 5377 | } else { | ||||
| 5378 | target = node->as<BinaryNode>().right(); | ||||
| 5379 | } | ||||
| 5380 | |||||
| 5381 | if (target->isKind(ParseNodeKind::AssignExpr)) { | ||||
| 5382 | target = target->as<AssignmentNode>().left(); | ||||
| 5383 | } | ||||
| 5384 | } | ||||
| 5385 | |||||
| 5386 | if (!checkExportedNamesForDeclaration(target)) { | ||||
| 5387 | return false; | ||||
| 5388 | } | ||||
| 5389 | } | ||||
| 5390 | |||||
| 5391 | return true; | ||||
| 5392 | } | ||||
| 5393 | |||||
| 5394 | template <typename Unit> | ||||
| 5395 | inline bool Parser<SyntaxParseHandler, | ||||
| 5396 | Unit>::checkExportedNamesForObjectBinding(ListNodeType obj) { | ||||
| 5397 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5397); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5397); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5398 | return false; | ||||
| 5399 | } | ||||
| 5400 | |||||
| 5401 | template <class ParseHandler, typename Unit> | ||||
| 5402 | inline bool | ||||
| 5403 | GeneralParser<ParseHandler, Unit>::checkExportedNamesForObjectBinding( | ||||
| 5404 | ListNodeType obj) { | ||||
| 5405 | return asFinalParser()->checkExportedNamesForObjectBinding(obj); | ||||
| 5406 | } | ||||
| 5407 | |||||
| 5408 | template <typename Unit> | ||||
| 5409 | bool Parser<FullParseHandler, Unit>::checkExportedNamesForDeclaration( | ||||
| 5410 | ParseNode* node) { | ||||
| 5411 | if (node->isKind(ParseNodeKind::Name)) { | ||||
| 5412 | if (!checkExportedName(node->as<NameNode>().atom())) { | ||||
| 5413 | return false; | ||||
| 5414 | } | ||||
| 5415 | } else if (node->isKind(ParseNodeKind::ArrayExpr)) { | ||||
| 5416 | if (!checkExportedNamesForArrayBinding(&node->as<ListNode>())) { | ||||
| 5417 | return false; | ||||
| 5418 | } | ||||
| 5419 | } else { | ||||
| 5420 | MOZ_ASSERT(node->isKind(ParseNodeKind::ObjectExpr))do { static_assert( mozilla::detail::AssertionConditionType< decltype(node->isKind(ParseNodeKind::ObjectExpr))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(node->isKind(ParseNodeKind::ObjectExpr)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("node->isKind(ParseNodeKind::ObjectExpr)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5420); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::ObjectExpr)" ")"); do { MOZ_CrashSequence(__null, 5420); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5421 | if (!checkExportedNamesForObjectBinding(&node->as<ListNode>())) { | ||||
| 5422 | return false; | ||||
| 5423 | } | ||||
| 5424 | } | ||||
| 5425 | |||||
| 5426 | return true; | ||||
| 5427 | } | ||||
| 5428 | |||||
| 5429 | template <typename Unit> | ||||
| 5430 | inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNamesForDeclaration( | ||||
| 5431 | Node node) { | ||||
| 5432 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5432); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5432); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5433 | return false; | ||||
| 5434 | } | ||||
| 5435 | |||||
| 5436 | template <class ParseHandler, typename Unit> | ||||
| 5437 | inline bool GeneralParser<ParseHandler, Unit>::checkExportedNamesForDeclaration( | ||||
| 5438 | Node node) { | ||||
| 5439 | return asFinalParser()->checkExportedNamesForDeclaration(node); | ||||
| 5440 | } | ||||
| 5441 | |||||
| 5442 | template <typename Unit> | ||||
| 5443 | bool Parser<FullParseHandler, Unit>::checkExportedNamesForDeclarationList( | ||||
| 5444 | DeclarationListNodeType node) { | ||||
| 5445 | for (ParseNode* binding : node->contents()) { | ||||
| 5446 | if (binding->isKind(ParseNodeKind::AssignExpr)) { | ||||
| 5447 | binding = binding->as<AssignmentNode>().left(); | ||||
| 5448 | } else { | ||||
| 5449 | MOZ_ASSERT(binding->isKind(ParseNodeKind::Name))do { static_assert( mozilla::detail::AssertionConditionType< decltype(binding->isKind(ParseNodeKind::Name))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(binding->isKind(ParseNodeKind::Name)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("binding->isKind(ParseNodeKind::Name)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5449); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "binding->isKind(ParseNodeKind::Name)" ")" ); do { MOZ_CrashSequence(__null, 5449); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5450 | } | ||||
| 5451 | |||||
| 5452 | if (!checkExportedNamesForDeclaration(binding)) { | ||||
| 5453 | return false; | ||||
| 5454 | } | ||||
| 5455 | } | ||||
| 5456 | |||||
| 5457 | return true; | ||||
| 5458 | } | ||||
| 5459 | |||||
| 5460 | template <typename Unit> | ||||
| 5461 | inline bool | ||||
| 5462 | Parser<SyntaxParseHandler, Unit>::checkExportedNamesForDeclarationList( | ||||
| 5463 | DeclarationListNodeType node) { | ||||
| 5464 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5464); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5464); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5465 | return false; | ||||
| 5466 | } | ||||
| 5467 | |||||
| 5468 | template <class ParseHandler, typename Unit> | ||||
| 5469 | inline bool | ||||
| 5470 | GeneralParser<ParseHandler, Unit>::checkExportedNamesForDeclarationList( | ||||
| 5471 | DeclarationListNodeType node) { | ||||
| 5472 | return asFinalParser()->checkExportedNamesForDeclarationList(node); | ||||
| 5473 | } | ||||
| 5474 | |||||
| 5475 | template <typename Unit> | ||||
| 5476 | inline bool Parser<FullParseHandler, Unit>::checkExportedNameForClause( | ||||
| 5477 | NameNode* nameNode) { | ||||
| 5478 | return checkExportedName(nameNode->atom()); | ||||
| 5479 | } | ||||
| 5480 | |||||
| 5481 | template <typename Unit> | ||||
| 5482 | inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNameForClause( | ||||
| 5483 | NameNodeType nameNode) { | ||||
| 5484 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5484); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5484); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5485 | return false; | ||||
| 5486 | } | ||||
| 5487 | |||||
| 5488 | template <class ParseHandler, typename Unit> | ||||
| 5489 | inline bool GeneralParser<ParseHandler, Unit>::checkExportedNameForClause( | ||||
| 5490 | NameNodeType nameNode) { | ||||
| 5491 | return asFinalParser()->checkExportedNameForClause(nameNode); | ||||
| 5492 | } | ||||
| 5493 | |||||
| 5494 | template <typename Unit> | ||||
| 5495 | bool Parser<FullParseHandler, Unit>::checkExportedNameForFunction( | ||||
| 5496 | FunctionNode* funNode) { | ||||
| 5497 | return checkExportedName(funNode->funbox()->explicitName()); | ||||
| 5498 | } | ||||
| 5499 | |||||
| 5500 | template <typename Unit> | ||||
| 5501 | inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNameForFunction( | ||||
| 5502 | FunctionNodeType funNode) { | ||||
| 5503 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5503); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5503); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5504 | return false; | ||||
| 5505 | } | ||||
| 5506 | |||||
| 5507 | template <class ParseHandler, typename Unit> | ||||
| 5508 | inline bool GeneralParser<ParseHandler, Unit>::checkExportedNameForFunction( | ||||
| 5509 | FunctionNodeType funNode) { | ||||
| 5510 | return asFinalParser()->checkExportedNameForFunction(funNode); | ||||
| 5511 | } | ||||
| 5512 | |||||
| 5513 | template <typename Unit> | ||||
| 5514 | bool Parser<FullParseHandler, Unit>::checkExportedNameForClass( | ||||
| 5515 | ClassNode* classNode) { | ||||
| 5516 | MOZ_ASSERT(classNode->names())do { static_assert( mozilla::detail::AssertionConditionType< decltype(classNode->names())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(classNode->names()))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("classNode->names()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5516); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "classNode->names()" ")"); do { MOZ_CrashSequence (__null, 5516); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 5517 | return checkExportedName(classNode->names()->innerBinding()->atom()); | ||||
| 5518 | } | ||||
| 5519 | |||||
| 5520 | template <typename Unit> | ||||
| 5521 | inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNameForClass( | ||||
| 5522 | ClassNodeType classNode) { | ||||
| 5523 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5523); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5523); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5524 | return false; | ||||
| 5525 | } | ||||
| 5526 | |||||
| 5527 | template <class ParseHandler, typename Unit> | ||||
| 5528 | inline bool GeneralParser<ParseHandler, Unit>::checkExportedNameForClass( | ||||
| 5529 | ClassNodeType classNode) { | ||||
| 5530 | return asFinalParser()->checkExportedNameForClass(classNode); | ||||
| 5531 | } | ||||
| 5532 | |||||
| 5533 | template <> | ||||
| 5534 | inline bool PerHandlerParser<FullParseHandler>::processExport(ParseNode* node) { | ||||
| 5535 | return pc_->sc()->asModuleContext()->builder.processExport(node); | ||||
| 5536 | } | ||||
| 5537 | |||||
| 5538 | template <> | ||||
| 5539 | inline bool PerHandlerParser<SyntaxParseHandler>::processExport(Node node) { | ||||
| 5540 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5540); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5540); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5541 | return false; | ||||
| 5542 | } | ||||
| 5543 | |||||
| 5544 | template <> | ||||
| 5545 | inline bool PerHandlerParser<FullParseHandler>::processExportFrom( | ||||
| 5546 | BinaryNodeType node) { | ||||
| 5547 | return pc_->sc()->asModuleContext()->builder.processExportFrom(node); | ||||
| 5548 | } | ||||
| 5549 | |||||
| 5550 | template <> | ||||
| 5551 | inline bool PerHandlerParser<SyntaxParseHandler>::processExportFrom( | ||||
| 5552 | BinaryNodeType node) { | ||||
| 5553 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5553); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5553); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5554 | return false; | ||||
| 5555 | } | ||||
| 5556 | |||||
| 5557 | template <> | ||||
| 5558 | inline bool PerHandlerParser<FullParseHandler>::processImport( | ||||
| 5559 | BinaryNodeType node) { | ||||
| 5560 | return pc_->sc()->asModuleContext()->builder.processImport(node); | ||||
| 5561 | } | ||||
| 5562 | |||||
| 5563 | template <> | ||||
| 5564 | inline bool PerHandlerParser<SyntaxParseHandler>::processImport( | ||||
| 5565 | BinaryNodeType node) { | ||||
| 5566 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5566); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5566); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5567 | return false; | ||||
| 5568 | } | ||||
| 5569 | |||||
| 5570 | template <class ParseHandler, typename Unit> | ||||
| 5571 | typename ParseHandler::BinaryNodeResult | ||||
| 5572 | GeneralParser<ParseHandler, Unit>::exportFrom(uint32_t begin, Node specList) { | ||||
| 5573 | if (!abortIfSyntaxParser()) { | ||||
| 5574 | return errorResult(); | ||||
| 5575 | } | ||||
| 5576 | |||||
| 5577 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::From))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::From))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::From)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::From)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5577); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::From)" ")"); do { MOZ_CrashSequence(__null, 5577); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5578 | |||||
| 5579 | if (!mustMatchToken(TokenKind::String, JSMSG_MODULE_SPEC_AFTER_FROM)) { | ||||
| 5580 | return errorResult(); | ||||
| 5581 | } | ||||
| 5582 | |||||
| 5583 | NameNodeType moduleSpec = MOZ_TRY(stringLiteral())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (stringLiteral()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5584 | |||||
| 5585 | TokenKind tt; | ||||
| 5586 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 5587 | return errorResult(); | ||||
| 5588 | } | ||||
| 5589 | |||||
| 5590 | uint32_t moduleSpecPos = pos().begin; | ||||
| 5591 | |||||
| 5592 | ListNodeType importAttributeList = | ||||
| 5593 | MOZ_TRY(handler_.newList(ParseNodeKind::ImportAttributeList, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newList(ParseNodeKind::ImportAttributeList, pos())) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5594 | if (tt == TokenKind::With) { | ||||
| 5595 | tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp); | ||||
| 5596 | |||||
| 5597 | if (!withClause(importAttributeList)) { | ||||
| 5598 | return errorResult(); | ||||
| 5599 | } | ||||
| 5600 | } | ||||
| 5601 | |||||
| 5602 | if (!matchOrInsertSemicolon(TokenStream::SlashIsRegExp)) { | ||||
| 5603 | return errorResult(); | ||||
| 5604 | } | ||||
| 5605 | |||||
| 5606 | BinaryNodeType moduleRequest = MOZ_TRY(handler_.newModuleRequest(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newModuleRequest( moduleSpec, importAttributeList, TokenPos (moduleSpecPos, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 5607 | moduleSpec, importAttributeList, TokenPos(moduleSpecPos, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newModuleRequest( moduleSpec, importAttributeList, TokenPos (moduleSpecPos, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5608 | |||||
| 5609 | BinaryNodeType node = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportFromDeclaration(begin, specList, moduleRequest )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 5610 | handler_.newExportFromDeclaration(begin, specList, moduleRequest))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportFromDeclaration(begin, specList, moduleRequest )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5611 | |||||
| 5612 | if (!processExportFrom(node)) { | ||||
| 5613 | return errorResult(); | ||||
| 5614 | } | ||||
| 5615 | |||||
| 5616 | return node; | ||||
| 5617 | } | ||||
| 5618 | |||||
| 5619 | template <class ParseHandler, typename Unit> | ||||
| 5620 | typename ParseHandler::BinaryNodeResult | ||||
| 5621 | GeneralParser<ParseHandler, Unit>::exportBatch(uint32_t begin) { | ||||
| 5622 | if (!abortIfSyntaxParser()) { | ||||
| 5623 | return errorResult(); | ||||
| 5624 | } | ||||
| 5625 | |||||
| 5626 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Mul))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Mul))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::Mul)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Mul)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5626); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Mul)" ")"); do { MOZ_CrashSequence(__null, 5626); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5627 | uint32_t beginExportSpec = pos().begin; | ||||
| 5628 | |||||
| 5629 | ListNodeType kid = | ||||
| 5630 | MOZ_TRY(handler_.newList(ParseNodeKind::ExportSpecList, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newList(ParseNodeKind::ExportSpecList, pos())); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 5631 | |||||
| 5632 | bool foundAs; | ||||
| 5633 | if (!tokenStream.matchToken(&foundAs, TokenKind::As)) { | ||||
| 5634 | return errorResult(); | ||||
| 5635 | } | ||||
| 5636 | |||||
| 5637 | if (foundAs) { | ||||
| 5638 | TokenKind tt; | ||||
| 5639 | if (!tokenStream.getToken(&tt)) { | ||||
| 5640 | return errorResult(); | ||||
| 5641 | } | ||||
| 5642 | |||||
| 5643 | NameNodeType exportName = null(); | ||||
| 5644 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 5645 | exportName = MOZ_TRY(newName(anyChars.currentName()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(anyChars.currentName())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5646 | } else if (tt == TokenKind::String) { | ||||
| 5647 | exportName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5648 | } else { | ||||
| 5649 | error(JSMSG_NO_EXPORT_NAME); | ||||
| 5650 | return errorResult(); | ||||
| 5651 | } | ||||
| 5652 | |||||
| 5653 | if (!checkExportedNameForClause(exportName)) { | ||||
| 5654 | return errorResult(); | ||||
| 5655 | } | ||||
| 5656 | |||||
| 5657 | UnaryNodeType exportSpec = | ||||
| 5658 | MOZ_TRY(handler_.newExportNamespaceSpec(beginExportSpec, exportName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportNamespaceSpec(beginExportSpec, exportName) ); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)) ) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5659 | |||||
| 5660 | handler_.addList(kid, exportSpec); | ||||
| 5661 | } else { | ||||
| 5662 | // Handle the form |export *| by adding a special export batch | ||||
| 5663 | // specifier to the list. | ||||
| 5664 | NullaryNodeType exportSpec = MOZ_TRY(handler_.newExportBatchSpec(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportBatchSpec(pos())); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5665 | |||||
| 5666 | handler_.addList(kid, exportSpec); | ||||
| 5667 | } | ||||
| 5668 | |||||
| 5669 | if (!mustMatchToken(TokenKind::From, JSMSG_FROM_AFTER_EXPORT_STAR)) { | ||||
| 5670 | return errorResult(); | ||||
| 5671 | } | ||||
| 5672 | |||||
| 5673 | return exportFrom(begin, kid); | ||||
| 5674 | } | ||||
| 5675 | |||||
| 5676 | template <typename Unit> | ||||
| 5677 | bool Parser<FullParseHandler, Unit>::checkLocalExportNames(ListNode* node) { | ||||
| 5678 | // ES 2017 draft 15.2.3.1. | ||||
| 5679 | for (ParseNode* next : node->contents()) { | ||||
| 5680 | ParseNode* name = next->as<BinaryNode>().left(); | ||||
| 5681 | |||||
| 5682 | if (name->isKind(ParseNodeKind::StringExpr)) { | ||||
| 5683 | errorAt(name->pn_pos.begin, JSMSG_BAD_LOCAL_STRING_EXPORT); | ||||
| 5684 | return false; | ||||
| 5685 | } | ||||
| 5686 | |||||
| 5687 | MOZ_ASSERT(name->isKind(ParseNodeKind::Name))do { static_assert( mozilla::detail::AssertionConditionType< decltype(name->isKind(ParseNodeKind::Name))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(name->isKind(ParseNodeKind ::Name)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("name->isKind(ParseNodeKind::Name)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 5687); AnnotateMozCrashReason("MOZ_ASSERT" "(" "name->isKind(ParseNodeKind::Name)" ")"); do { MOZ_CrashSequence(__null, 5687); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5688 | |||||
| 5689 | TaggedParserAtomIndex ident = name->as<NameNode>().atom(); | ||||
| 5690 | if (!checkLocalExportName(ident, name->pn_pos.begin)) { | ||||
| 5691 | return false; | ||||
| 5692 | } | ||||
| 5693 | } | ||||
| 5694 | |||||
| 5695 | return true; | ||||
| 5696 | } | ||||
| 5697 | |||||
| 5698 | template <typename Unit> | ||||
| 5699 | bool Parser<SyntaxParseHandler, Unit>::checkLocalExportNames( | ||||
| 5700 | ListNodeType node) { | ||||
| 5701 | MOZ_ALWAYS_FALSE(abortIfSyntaxParser())do { if ((__builtin_expect(!!(!(abortIfSyntaxParser())), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "!(abortIfSyntaxParser())" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5701); AnnotateMozCrashReason ("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence (__null, 5701); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); } } while (false); | ||||
| 5702 | return false; | ||||
| 5703 | } | ||||
| 5704 | |||||
| 5705 | template <class ParseHandler, typename Unit> | ||||
| 5706 | inline bool GeneralParser<ParseHandler, Unit>::checkLocalExportNames( | ||||
| 5707 | ListNodeType node) { | ||||
| 5708 | return asFinalParser()->checkLocalExportNames(node); | ||||
| 5709 | } | ||||
| 5710 | |||||
| 5711 | template <class ParseHandler, typename Unit> | ||||
| 5712 | typename ParseHandler::NodeResult | ||||
| 5713 | GeneralParser<ParseHandler, Unit>::exportClause(uint32_t begin) { | ||||
| 5714 | if (!abortIfSyntaxParser()) { | ||||
| 5715 | return errorResult(); | ||||
| 5716 | } | ||||
| 5717 | |||||
| 5718 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftCurly))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftCurly))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftCurly)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftCurly)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5718); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)" ")"); do { MOZ_CrashSequence(__null, 5718); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5719 | |||||
| 5720 | ListNodeType kid = | ||||
| 5721 | MOZ_TRY(handler_.newList(ParseNodeKind::ExportSpecList, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newList(ParseNodeKind::ExportSpecList, pos())); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 5722 | |||||
| 5723 | TokenKind tt; | ||||
| 5724 | while (true) { | ||||
| 5725 | // Handle the forms |export {}| and |export { ..., }| (where ... is non | ||||
| 5726 | // empty), by escaping the loop early if the next token is }. | ||||
| 5727 | if (!tokenStream.getToken(&tt)) { | ||||
| 5728 | return errorResult(); | ||||
| 5729 | } | ||||
| 5730 | |||||
| 5731 | if (tt == TokenKind::RightCurly) { | ||||
| 5732 | break; | ||||
| 5733 | } | ||||
| 5734 | |||||
| 5735 | NameNodeType bindingName = null(); | ||||
| 5736 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 5737 | bindingName = MOZ_TRY(newName(anyChars.currentName()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(anyChars.currentName())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5738 | } else if (tt == TokenKind::String) { | ||||
| 5739 | bindingName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5740 | } else { | ||||
| 5741 | error(JSMSG_NO_BINDING_NAME); | ||||
| 5742 | return errorResult(); | ||||
| 5743 | } | ||||
| 5744 | |||||
| 5745 | bool foundAs; | ||||
| 5746 | if (!tokenStream.matchToken(&foundAs, TokenKind::As)) { | ||||
| 5747 | return errorResult(); | ||||
| 5748 | } | ||||
| 5749 | |||||
| 5750 | NameNodeType exportName = null(); | ||||
| 5751 | if (foundAs) { | ||||
| 5752 | TokenKind tt; | ||||
| 5753 | if (!tokenStream.getToken(&tt)) { | ||||
| 5754 | return errorResult(); | ||||
| 5755 | } | ||||
| 5756 | |||||
| 5757 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 5758 | exportName = MOZ_TRY(newName(anyChars.currentName()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(anyChars.currentName())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5759 | } else if (tt == TokenKind::String) { | ||||
| 5760 | exportName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5761 | } else { | ||||
| 5762 | error(JSMSG_NO_EXPORT_NAME); | ||||
| 5763 | return errorResult(); | ||||
| 5764 | } | ||||
| 5765 | } else { | ||||
| 5766 | if (tt != TokenKind::String) { | ||||
| 5767 | exportName = MOZ_TRY(newName(anyChars.currentName()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(anyChars.currentName())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5768 | } else { | ||||
| 5769 | exportName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5770 | } | ||||
| 5771 | } | ||||
| 5772 | |||||
| 5773 | if (!checkExportedNameForClause(exportName)) { | ||||
| 5774 | return errorResult(); | ||||
| 5775 | } | ||||
| 5776 | |||||
| 5777 | BinaryNodeType exportSpec = | ||||
| 5778 | MOZ_TRY(handler_.newExportSpec(bindingName, exportName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportSpec(bindingName, exportName)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5779 | |||||
| 5780 | handler_.addList(kid, exportSpec); | ||||
| 5781 | |||||
| 5782 | TokenKind next; | ||||
| 5783 | if (!tokenStream.getToken(&next)) { | ||||
| 5784 | return errorResult(); | ||||
| 5785 | } | ||||
| 5786 | |||||
| 5787 | if (next == TokenKind::RightCurly) { | ||||
| 5788 | break; | ||||
| 5789 | } | ||||
| 5790 | |||||
| 5791 | if (next != TokenKind::Comma) { | ||||
| 5792 | error(JSMSG_RC_AFTER_EXPORT_SPEC_LIST); | ||||
| 5793 | return errorResult(); | ||||
| 5794 | } | ||||
| 5795 | } | ||||
| 5796 | |||||
| 5797 | // Careful! If |from| follows, even on a new line, it must start a | ||||
| 5798 | // FromClause: | ||||
| 5799 | // | ||||
| 5800 | // export { x } | ||||
| 5801 | // from "foo"; // a single ExportDeclaration | ||||
| 5802 | // | ||||
| 5803 | // But if it doesn't, we might have an ASI opportunity in SlashIsRegExp | ||||
| 5804 | // context: | ||||
| 5805 | // | ||||
| 5806 | // export { x } // ExportDeclaration, terminated by ASI | ||||
| 5807 | // fro\u006D // ExpressionStatement, the name "from" | ||||
| 5808 | // | ||||
| 5809 | // In that case let matchOrInsertSemicolon sort out ASI or any necessary | ||||
| 5810 | // error. | ||||
| 5811 | bool matched; | ||||
| 5812 | if (!tokenStream.matchToken(&matched, TokenKind::From, | ||||
| 5813 | TokenStream::SlashIsRegExp)) { | ||||
| 5814 | return errorResult(); | ||||
| 5815 | } | ||||
| 5816 | |||||
| 5817 | if (matched) { | ||||
| 5818 | return exportFrom(begin, kid); | ||||
| 5819 | } | ||||
| 5820 | |||||
| 5821 | if (!matchOrInsertSemicolon()) { | ||||
| 5822 | return errorResult(); | ||||
| 5823 | } | ||||
| 5824 | |||||
| 5825 | if (!checkLocalExportNames(kid)) { | ||||
| 5826 | return errorResult(); | ||||
| 5827 | } | ||||
| 5828 | |||||
| 5829 | UnaryNodeType node = | ||||
| 5830 | MOZ_TRY(handler_.newExportDeclaration(kid, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDeclaration(kid, TokenPos(begin, pos().end ))); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5831 | |||||
| 5832 | if (!processExport(node)) { | ||||
| 5833 | return errorResult(); | ||||
| 5834 | } | ||||
| 5835 | |||||
| 5836 | return node; | ||||
| 5837 | } | ||||
| 5838 | |||||
| 5839 | template <class ParseHandler, typename Unit> | ||||
| 5840 | typename ParseHandler::UnaryNodeResult | ||||
| 5841 | GeneralParser<ParseHandler, Unit>::exportVariableStatement(uint32_t begin) { | ||||
| 5842 | if (!abortIfSyntaxParser()) { | ||||
| 5843 | return errorResult(); | ||||
| 5844 | } | ||||
| 5845 | |||||
| 5846 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Var))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Var))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::Var)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Var)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5846); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Var)" ")"); do { MOZ_CrashSequence(__null, 5846); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5847 | |||||
| 5848 | DeclarationListNodeType kid = | ||||
| 5849 | MOZ_TRY(declarationList(YieldIsName, ParseNodeKind::VarStmt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationList(YieldIsName, ParseNodeKind::VarStmt)); if (( __builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 5850 | if (!matchOrInsertSemicolon()) { | ||||
| 5851 | return errorResult(); | ||||
| 5852 | } | ||||
| 5853 | if (!checkExportedNamesForDeclarationList(kid)) { | ||||
| 5854 | return errorResult(); | ||||
| 5855 | } | ||||
| 5856 | |||||
| 5857 | UnaryNodeType node = | ||||
| 5858 | MOZ_TRY(handler_.newExportDeclaration(kid, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDeclaration(kid, TokenPos(begin, pos().end ))); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5859 | |||||
| 5860 | if (!processExport(node)) { | ||||
| 5861 | return errorResult(); | ||||
| 5862 | } | ||||
| 5863 | |||||
| 5864 | return node; | ||||
| 5865 | } | ||||
| 5866 | |||||
| 5867 | template <class ParseHandler, typename Unit> | ||||
| 5868 | typename ParseHandler::UnaryNodeResult | ||||
| 5869 | GeneralParser<ParseHandler, Unit>::exportFunctionDeclaration( | ||||
| 5870 | uint32_t begin, uint32_t toStringStart, | ||||
| 5871 | FunctionAsyncKind asyncKind /* = SyncFunction */) { | ||||
| 5872 | if (!abortIfSyntaxParser()) { | ||||
| 5873 | return errorResult(); | ||||
| 5874 | } | ||||
| 5875 | |||||
| 5876 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Function))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Function))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Function)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Function)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5876); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)" ")"); do { MOZ_CrashSequence(__null, 5876); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5877 | |||||
| 5878 | Node kid = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (functionStmt(toStringStart, YieldIsName, NameRequired, asyncKind )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 5879 | functionStmt(toStringStart, YieldIsName, NameRequired, asyncKind))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (functionStmt(toStringStart, YieldIsName, NameRequired, asyncKind )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5880 | |||||
| 5881 | if (!checkExportedNameForFunction(handler_.asFunctionNode(kid))) { | ||||
| 5882 | return errorResult(); | ||||
| 5883 | } | ||||
| 5884 | |||||
| 5885 | UnaryNodeType node = | ||||
| 5886 | MOZ_TRY(handler_.newExportDeclaration(kid, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDeclaration(kid, TokenPos(begin, pos().end ))); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5887 | |||||
| 5888 | if (!processExport(node)) { | ||||
| 5889 | return errorResult(); | ||||
| 5890 | } | ||||
| 5891 | |||||
| 5892 | return node; | ||||
| 5893 | } | ||||
| 5894 | |||||
| 5895 | template <class ParseHandler, typename Unit> | ||||
| 5896 | typename ParseHandler::UnaryNodeResult | ||||
| 5897 | GeneralParser<ParseHandler, Unit>::exportClassDeclaration(uint32_t begin) { | ||||
| 5898 | if (!abortIfSyntaxParser()) { | ||||
| 5899 | return errorResult(); | ||||
| 5900 | } | ||||
| 5901 | |||||
| 5902 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Class))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Class))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Class)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Class)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5902); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Class)" ")"); do { MOZ_CrashSequence(__null, 5902); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5903 | |||||
| 5904 | ClassNodeType kid = | ||||
| 5905 | MOZ_TRY(classDefinition(YieldIsName, ClassStatement, NameRequired))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (classDefinition(YieldIsName, ClassStatement, NameRequired)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5906 | |||||
| 5907 | if (!checkExportedNameForClass(kid)) { | ||||
| 5908 | return errorResult(); | ||||
| 5909 | } | ||||
| 5910 | |||||
| 5911 | UnaryNodeType node = | ||||
| 5912 | MOZ_TRY(handler_.newExportDeclaration(kid, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDeclaration(kid, TokenPos(begin, pos().end ))); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5913 | |||||
| 5914 | if (!processExport(node)) { | ||||
| 5915 | return errorResult(); | ||||
| 5916 | } | ||||
| 5917 | |||||
| 5918 | return node; | ||||
| 5919 | } | ||||
| 5920 | |||||
| 5921 | template <class ParseHandler, typename Unit> | ||||
| 5922 | typename ParseHandler::UnaryNodeResult | ||||
| 5923 | GeneralParser<ParseHandler, Unit>::exportLexicalDeclaration( | ||||
| 5924 | uint32_t begin, DeclarationKind kind) { | ||||
| 5925 | if (!abortIfSyntaxParser()) { | ||||
| 5926 | return errorResult(); | ||||
| 5927 | } | ||||
| 5928 | |||||
| 5929 | MOZ_ASSERT(kind == DeclarationKind::Const || kind == DeclarationKind::Let)do { static_assert( mozilla::detail::AssertionConditionType< decltype(kind == DeclarationKind::Const || kind == DeclarationKind ::Let)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(kind == DeclarationKind::Const || kind == DeclarationKind ::Let))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("kind == DeclarationKind::Const || kind == DeclarationKind::Let" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5929); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let" ")"); do { MOZ_CrashSequence(__null, 5929); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5930 | MOZ_ASSERT_IF(kind == DeclarationKind::Const,do { if (kind == DeclarationKind::Const) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(anyChars .isCurrentTokenType(TokenKind::Const))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::Const)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::Const)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 5931); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Const)" ")"); do { MOZ_CrashSequence(__null, 5931); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 5931 | anyChars.isCurrentTokenType(TokenKind::Const))do { if (kind == DeclarationKind::Const) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(anyChars .isCurrentTokenType(TokenKind::Const))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::Const)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::Const)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 5931); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Const)" ")"); do { MOZ_CrashSequence(__null, 5931); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 5932 | MOZ_ASSERT_IF(kind == DeclarationKind::Let,do { if (kind == DeclarationKind::Let) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(anyChars.isCurrentTokenType (TokenKind::Let))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::Let)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::Let)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 5933); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Let)" ")"); do { MOZ_CrashSequence(__null, 5933); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) | ||||
| 5933 | anyChars.isCurrentTokenType(TokenKind::Let))do { if (kind == DeclarationKind::Let) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(anyChars.isCurrentTokenType (TokenKind::Let))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::Let)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::Let)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 5933); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Let)" ")"); do { MOZ_CrashSequence(__null, 5933); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 5934 | |||||
| 5935 | DeclarationListNodeType kid = MOZ_TRY(lexicalDeclaration(YieldIsName, kind))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (lexicalDeclaration(YieldIsName, kind)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5936 | if (!checkExportedNamesForDeclarationList(kid)) { | ||||
| 5937 | return errorResult(); | ||||
| 5938 | } | ||||
| 5939 | |||||
| 5940 | UnaryNodeType node = | ||||
| 5941 | MOZ_TRY(handler_.newExportDeclaration(kid, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDeclaration(kid, TokenPos(begin, pos().end ))); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5942 | |||||
| 5943 | if (!processExport(node)) { | ||||
| 5944 | return errorResult(); | ||||
| 5945 | } | ||||
| 5946 | |||||
| 5947 | return node; | ||||
| 5948 | } | ||||
| 5949 | |||||
| 5950 | template <class ParseHandler, typename Unit> | ||||
| 5951 | typename ParseHandler::BinaryNodeResult | ||||
| 5952 | GeneralParser<ParseHandler, Unit>::exportDefaultFunctionDeclaration( | ||||
| 5953 | uint32_t begin, uint32_t toStringStart, | ||||
| 5954 | FunctionAsyncKind asyncKind /* = SyncFunction */) { | ||||
| 5955 | if (!abortIfSyntaxParser()) { | ||||
| 5956 | return errorResult(); | ||||
| 5957 | } | ||||
| 5958 | |||||
| 5959 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Function))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Function))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Function)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Function)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5959); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)" ")"); do { MOZ_CrashSequence(__null, 5959); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5960 | |||||
| 5961 | Node kid = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (functionStmt(toStringStart, YieldIsName, AllowDefaultName, asyncKind )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 5962 | functionStmt(toStringStart, YieldIsName, AllowDefaultName, asyncKind))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (functionStmt(toStringStart, YieldIsName, AllowDefaultName, asyncKind )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5963 | |||||
| 5964 | BinaryNodeType node = MOZ_TRY(handler_.newExportDefaultDeclaration(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDefaultDeclaration( kid, null(), TokenPos( begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 5965 | kid, null(), TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDefaultDeclaration( kid, null(), TokenPos( begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5966 | |||||
| 5967 | if (!processExport(node)) { | ||||
| 5968 | return errorResult(); | ||||
| 5969 | } | ||||
| 5970 | |||||
| 5971 | return node; | ||||
| 5972 | } | ||||
| 5973 | |||||
| 5974 | template <class ParseHandler, typename Unit> | ||||
| 5975 | typename ParseHandler::BinaryNodeResult | ||||
| 5976 | GeneralParser<ParseHandler, Unit>::exportDefaultClassDeclaration( | ||||
| 5977 | uint32_t begin) { | ||||
| 5978 | if (!abortIfSyntaxParser()) { | ||||
| 5979 | return errorResult(); | ||||
| 5980 | } | ||||
| 5981 | |||||
| 5982 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Class))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Class))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Class)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Class)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 5982); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Class)" ")"); do { MOZ_CrashSequence(__null, 5982); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 5983 | |||||
| 5984 | ClassNodeType kid = | ||||
| 5985 | MOZ_TRY(classDefinition(YieldIsName, ClassStatement, AllowDefaultName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (classDefinition(YieldIsName, ClassStatement, AllowDefaultName )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 5986 | |||||
| 5987 | BinaryNodeType node = MOZ_TRY(handler_.newExportDefaultDeclaration(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDefaultDeclaration( kid, null(), TokenPos( begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 5988 | kid, null(), TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDefaultDeclaration( kid, null(), TokenPos( begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 5989 | |||||
| 5990 | if (!processExport(node)) { | ||||
| 5991 | return errorResult(); | ||||
| 5992 | } | ||||
| 5993 | |||||
| 5994 | return node; | ||||
| 5995 | } | ||||
| 5996 | |||||
| 5997 | template <class ParseHandler, typename Unit> | ||||
| 5998 | typename ParseHandler::BinaryNodeResult | ||||
| 5999 | GeneralParser<ParseHandler, Unit>::exportDefaultAssignExpr(uint32_t begin) { | ||||
| 6000 | if (!abortIfSyntaxParser()) { | ||||
| 6001 | return errorResult(); | ||||
| 6002 | } | ||||
| 6003 | |||||
| 6004 | TaggedParserAtomIndex name = TaggedParserAtomIndex::WellKnown::default_(); | ||||
| 6005 | NameNodeType nameNode = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6006 | if (!noteDeclaredName(name, DeclarationKind::Const, pos())) { | ||||
| 6007 | return errorResult(); | ||||
| 6008 | } | ||||
| 6009 | |||||
| 6010 | Node kid = MOZ_TRY(assignExpr(InAllowed, YieldIsName, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, YieldIsName, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 6011 | |||||
| 6012 | if (!matchOrInsertSemicolon()) { | ||||
| 6013 | return errorResult(); | ||||
| 6014 | } | ||||
| 6015 | |||||
| 6016 | BinaryNodeType node = MOZ_TRY(handler_.newExportDefaultDeclaration(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDefaultDeclaration( kid, nameNode, TokenPos (begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 6017 | kid, nameNode, TokenPos(begin, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExportDefaultDeclaration( kid, nameNode, TokenPos (begin, pos().end))); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6018 | |||||
| 6019 | if (!processExport(node)) { | ||||
| 6020 | return errorResult(); | ||||
| 6021 | } | ||||
| 6022 | |||||
| 6023 | return node; | ||||
| 6024 | } | ||||
| 6025 | |||||
| 6026 | template <class ParseHandler, typename Unit> | ||||
| 6027 | typename ParseHandler::BinaryNodeResult | ||||
| 6028 | GeneralParser<ParseHandler, Unit>::exportDefault(uint32_t begin) { | ||||
| 6029 | if (!abortIfSyntaxParser()) { | ||||
| 6030 | return errorResult(); | ||||
| 6031 | } | ||||
| 6032 | |||||
| 6033 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Default))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Default))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Default)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Default)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6033); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Default)" ")"); do { MOZ_CrashSequence(__null, 6033); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6034 | |||||
| 6035 | TokenKind tt; | ||||
| 6036 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6037 | return errorResult(); | ||||
| 6038 | } | ||||
| 6039 | |||||
| 6040 | if (!checkExportedName(TaggedParserAtomIndex::WellKnown::default_())) { | ||||
| 6041 | return errorResult(); | ||||
| 6042 | } | ||||
| 6043 | |||||
| 6044 | switch (tt) { | ||||
| 6045 | case TokenKind::Function: | ||||
| 6046 | return exportDefaultFunctionDeclaration(begin, pos().begin); | ||||
| 6047 | |||||
| 6048 | case TokenKind::Async: { | ||||
| 6049 | TokenKind nextSameLine = TokenKind::Eof; | ||||
| 6050 | if (!tokenStream.peekTokenSameLine(&nextSameLine)) { | ||||
| 6051 | return errorResult(); | ||||
| 6052 | } | ||||
| 6053 | |||||
| 6054 | if (nextSameLine == TokenKind::Function) { | ||||
| 6055 | uint32_t toStringStart = pos().begin; | ||||
| 6056 | tokenStream.consumeKnownToken(TokenKind::Function); | ||||
| 6057 | return exportDefaultFunctionDeclaration( | ||||
| 6058 | begin, toStringStart, FunctionAsyncKind::AsyncFunction); | ||||
| 6059 | } | ||||
| 6060 | |||||
| 6061 | anyChars.ungetToken(); | ||||
| 6062 | return exportDefaultAssignExpr(begin); | ||||
| 6063 | } | ||||
| 6064 | |||||
| 6065 | case TokenKind::Class: | ||||
| 6066 | return exportDefaultClassDeclaration(begin); | ||||
| 6067 | |||||
| 6068 | default: | ||||
| 6069 | anyChars.ungetToken(); | ||||
| 6070 | return exportDefaultAssignExpr(begin); | ||||
| 6071 | } | ||||
| 6072 | } | ||||
| 6073 | |||||
| 6074 | template <class ParseHandler, typename Unit> | ||||
| 6075 | typename ParseHandler::NodeResult | ||||
| 6076 | GeneralParser<ParseHandler, Unit>::exportDeclaration() { | ||||
| 6077 | if (!abortIfSyntaxParser()) { | ||||
| 6078 | return errorResult(); | ||||
| 6079 | } | ||||
| 6080 | |||||
| 6081 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Export))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Export))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Export)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Export)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6081); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Export)" ")"); do { MOZ_CrashSequence(__null, 6081); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6082 | |||||
| 6083 | if (!pc_->atModuleLevel()) { | ||||
| 6084 | error(JSMSG_EXPORT_DECL_AT_TOP_LEVEL); | ||||
| 6085 | return errorResult(); | ||||
| 6086 | } | ||||
| 6087 | |||||
| 6088 | uint32_t begin = pos().begin; | ||||
| 6089 | |||||
| 6090 | TokenKind tt; | ||||
| 6091 | if (!tokenStream.getToken(&tt)) { | ||||
| 6092 | return errorResult(); | ||||
| 6093 | } | ||||
| 6094 | switch (tt) { | ||||
| 6095 | case TokenKind::Mul: | ||||
| 6096 | return exportBatch(begin); | ||||
| 6097 | |||||
| 6098 | case TokenKind::LeftCurly: | ||||
| 6099 | return exportClause(begin); | ||||
| 6100 | |||||
| 6101 | case TokenKind::Var: | ||||
| 6102 | return exportVariableStatement(begin); | ||||
| 6103 | |||||
| 6104 | case TokenKind::Function: | ||||
| 6105 | return exportFunctionDeclaration(begin, pos().begin); | ||||
| 6106 | |||||
| 6107 | case TokenKind::Async: { | ||||
| 6108 | TokenKind nextSameLine = TokenKind::Eof; | ||||
| 6109 | if (!tokenStream.peekTokenSameLine(&nextSameLine)) { | ||||
| 6110 | return errorResult(); | ||||
| 6111 | } | ||||
| 6112 | |||||
| 6113 | if (nextSameLine == TokenKind::Function) { | ||||
| 6114 | uint32_t toStringStart = pos().begin; | ||||
| 6115 | tokenStream.consumeKnownToken(TokenKind::Function); | ||||
| 6116 | return exportFunctionDeclaration(begin, toStringStart, | ||||
| 6117 | FunctionAsyncKind::AsyncFunction); | ||||
| 6118 | } | ||||
| 6119 | |||||
| 6120 | error(JSMSG_DECLARATION_AFTER_EXPORT); | ||||
| 6121 | return errorResult(); | ||||
| 6122 | } | ||||
| 6123 | |||||
| 6124 | case TokenKind::Class: | ||||
| 6125 | return exportClassDeclaration(begin); | ||||
| 6126 | |||||
| 6127 | case TokenKind::Const: | ||||
| 6128 | return exportLexicalDeclaration(begin, DeclarationKind::Const); | ||||
| 6129 | |||||
| 6130 | case TokenKind::Let: | ||||
| 6131 | return exportLexicalDeclaration(begin, DeclarationKind::Let); | ||||
| 6132 | |||||
| 6133 | case TokenKind::Default: | ||||
| 6134 | return exportDefault(begin); | ||||
| 6135 | |||||
| 6136 | default: | ||||
| 6137 | error(JSMSG_DECLARATION_AFTER_EXPORT); | ||||
| 6138 | return errorResult(); | ||||
| 6139 | } | ||||
| 6140 | } | ||||
| 6141 | |||||
| 6142 | template <class ParseHandler, typename Unit> | ||||
| 6143 | typename ParseHandler::UnaryNodeResult | ||||
| 6144 | GeneralParser<ParseHandler, Unit>::expressionStatement( | ||||
| 6145 | YieldHandling yieldHandling, InvokedPrediction invoked) { | ||||
| 6146 | anyChars.ungetToken(); | ||||
| 6147 | Node pnexpr = MOZ_TRY(expr(InAllowed, yieldHandling, TripledotProhibited,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited, nullptr, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 6148 | /* possibleError = */ nullptr, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited, nullptr, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 6149 | if (!matchOrInsertSemicolon()) { | ||||
| 6150 | return errorResult(); | ||||
| 6151 | } | ||||
| 6152 | return handler_.newExprStatement(pnexpr, pos().end); | ||||
| 6153 | } | ||||
| 6154 | |||||
| 6155 | template <class ParseHandler, typename Unit> | ||||
| 6156 | typename ParseHandler::NodeResult | ||||
| 6157 | GeneralParser<ParseHandler, Unit>::consequentOrAlternative( | ||||
| 6158 | YieldHandling yieldHandling) { | ||||
| 6159 | TokenKind next; | ||||
| 6160 | if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) { | ||||
| 6161 | return errorResult(); | ||||
| 6162 | } | ||||
| 6163 | |||||
| 6164 | // Annex B.3.4 says that unbraced FunctionDeclarations under if/else in | ||||
| 6165 | // non-strict code act as if they were braced: |if (x) function f() {}| | ||||
| 6166 | // parses as |if (x) { function f() {} }|. | ||||
| 6167 | // | ||||
| 6168 | // Careful! FunctionDeclaration doesn't include generators or async | ||||
| 6169 | // functions. | ||||
| 6170 | if (next == TokenKind::Function) { | ||||
| 6171 | tokenStream.consumeKnownToken(next, TokenStream::SlashIsRegExp); | ||||
| 6172 | |||||
| 6173 | // Parser::statement would handle this, but as this function handles | ||||
| 6174 | // every other error case, it seems best to handle this. | ||||
| 6175 | if (pc_->sc()->strict()) { | ||||
| 6176 | error(JSMSG_FORBIDDEN_AS_STATEMENT, "function declarations"); | ||||
| 6177 | return errorResult(); | ||||
| 6178 | } | ||||
| 6179 | |||||
| 6180 | TokenKind maybeStar; | ||||
| 6181 | if (!tokenStream.peekToken(&maybeStar)) { | ||||
| 6182 | return errorResult(); | ||||
| 6183 | } | ||||
| 6184 | |||||
| 6185 | if (maybeStar == TokenKind::Mul) { | ||||
| 6186 | error(JSMSG_FORBIDDEN_AS_STATEMENT, "generator declarations"); | ||||
| 6187 | return errorResult(); | ||||
| 6188 | } | ||||
| 6189 | |||||
| 6190 | ParseContext::Statement stmt(pc_, StatementKind::Block); | ||||
| 6191 | ParseContext::Scope scope(this); | ||||
| 6192 | if (!scope.init(pc_)) { | ||||
| 6193 | return errorResult(); | ||||
| 6194 | } | ||||
| 6195 | |||||
| 6196 | TokenPos funcPos = pos(); | ||||
| 6197 | Node fun = MOZ_TRY(functionStmt(pos().begin, yieldHandling, NameRequired))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (functionStmt(pos().begin, yieldHandling, NameRequired)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 6198 | |||||
| 6199 | ListNodeType block = MOZ_TRY(handler_.newStatementList(funcPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(funcPos)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6200 | |||||
| 6201 | handler_.addStatementToList(block, fun); | ||||
| 6202 | return finishLexicalScope(scope, block); | ||||
| 6203 | } | ||||
| 6204 | |||||
| 6205 | return statement(yieldHandling); | ||||
| 6206 | } | ||||
| 6207 | |||||
| 6208 | template <class ParseHandler, typename Unit> | ||||
| 6209 | typename ParseHandler::TernaryNodeResult | ||||
| 6210 | GeneralParser<ParseHandler, Unit>::ifStatement(YieldHandling yieldHandling) { | ||||
| 6211 | Vector<Node, 4> condList(fc_), thenList(fc_); | ||||
| 6212 | Vector<uint32_t, 4> posList(fc_); | ||||
| 6213 | Node elseBranch; | ||||
| 6214 | |||||
| 6215 | ParseContext::Statement stmt(pc_, StatementKind::If); | ||||
| 6216 | |||||
| 6217 | while (true) { | ||||
| 6218 | uint32_t begin = pos().begin; | ||||
| 6219 | |||||
| 6220 | /* An IF node has three kids: condition, then, and optional else. */ | ||||
| 6221 | Node cond = MOZ_TRY(condition(InAllowed, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (condition(InAllowed, yieldHandling)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6222 | |||||
| 6223 | TokenKind tt; | ||||
| 6224 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6225 | return errorResult(); | ||||
| 6226 | } | ||||
| 6227 | |||||
| 6228 | Node thenBranch = MOZ_TRY(consequentOrAlternative(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (consequentOrAlternative(yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6229 | |||||
| 6230 | if (!condList.append(cond) || !thenList.append(thenBranch) || | ||||
| 6231 | !posList.append(begin)) { | ||||
| 6232 | return errorResult(); | ||||
| 6233 | } | ||||
| 6234 | |||||
| 6235 | bool matched; | ||||
| 6236 | if (!tokenStream.matchToken(&matched, TokenKind::Else, | ||||
| 6237 | TokenStream::SlashIsRegExp)) { | ||||
| 6238 | return errorResult(); | ||||
| 6239 | } | ||||
| 6240 | if (matched) { | ||||
| 6241 | if (!tokenStream.matchToken(&matched, TokenKind::If, | ||||
| 6242 | TokenStream::SlashIsRegExp)) { | ||||
| 6243 | return errorResult(); | ||||
| 6244 | } | ||||
| 6245 | if (matched) { | ||||
| 6246 | continue; | ||||
| 6247 | } | ||||
| 6248 | elseBranch = MOZ_TRY(consequentOrAlternative(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (consequentOrAlternative(yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6249 | } else { | ||||
| 6250 | elseBranch = null(); | ||||
| 6251 | } | ||||
| 6252 | break; | ||||
| 6253 | } | ||||
| 6254 | |||||
| 6255 | TernaryNodeType ifNode; | ||||
| 6256 | for (int i = condList.length() - 1; i >= 0; i--) { | ||||
| 6257 | ifNode = MOZ_TRY(handler_.newIfStatement(posList[i], condList[i],__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newIfStatement(posList[i], condList[i], thenList[i] , elseBranch)); if ((__builtin_expect(!!(mozTryVarTempResult. isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 6258 | thenList[i], elseBranch))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newIfStatement(posList[i], condList[i], thenList[i] , elseBranch)); if ((__builtin_expect(!!(mozTryVarTempResult. isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6259 | elseBranch = ifNode; | ||||
| 6260 | } | ||||
| 6261 | |||||
| 6262 | return ifNode; | ||||
| 6263 | } | ||||
| 6264 | |||||
| 6265 | template <class ParseHandler, typename Unit> | ||||
| 6266 | typename ParseHandler::BinaryNodeResult | ||||
| 6267 | GeneralParser<ParseHandler, Unit>::doWhileStatement( | ||||
| 6268 | YieldHandling yieldHandling) { | ||||
| 6269 | uint32_t begin = pos().begin; | ||||
| 6270 | ParseContext::Statement stmt(pc_, StatementKind::DoLoop); | ||||
| 6271 | Node body = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6272 | if (!mustMatchToken(TokenKind::While, JSMSG_WHILE_AFTER_DO)) { | ||||
| 6273 | return errorResult(); | ||||
| 6274 | } | ||||
| 6275 | Node cond = MOZ_TRY(condition(InAllowed, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (condition(InAllowed, yieldHandling)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6276 | |||||
| 6277 | // The semicolon after do-while is even more optional than most | ||||
| 6278 | // semicolons in JS. Web compat required this by 2004: | ||||
| 6279 | // http://bugzilla.mozilla.org/show_bug.cgi?id=238945 | ||||
| 6280 | // ES3 and ES5 disagreed, but ES6 conforms to Web reality: | ||||
| 6281 | // https://bugs.ecmascript.org/show_bug.cgi?id=157 | ||||
| 6282 | // To parse |do {} while (true) false| correctly, use SlashIsRegExp. | ||||
| 6283 | bool ignored; | ||||
| 6284 | if (!tokenStream.matchToken(&ignored, TokenKind::Semi, | ||||
| 6285 | TokenStream::SlashIsRegExp)) { | ||||
| 6286 | return errorResult(); | ||||
| 6287 | } | ||||
| 6288 | return handler_.newDoWhileStatement(body, cond, TokenPos(begin, pos().end)); | ||||
| 6289 | } | ||||
| 6290 | |||||
| 6291 | template <class ParseHandler, typename Unit> | ||||
| 6292 | typename ParseHandler::BinaryNodeResult | ||||
| 6293 | GeneralParser<ParseHandler, Unit>::whileStatement(YieldHandling yieldHandling) { | ||||
| 6294 | uint32_t begin = pos().begin; | ||||
| 6295 | ParseContext::Statement stmt(pc_, StatementKind::WhileLoop); | ||||
| 6296 | Node cond = MOZ_TRY(condition(InAllowed, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (condition(InAllowed, yieldHandling)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6297 | Node body = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6298 | return handler_.newWhileStatement(begin, cond, body); | ||||
| 6299 | } | ||||
| 6300 | |||||
| 6301 | template <class ParseHandler, typename Unit> | ||||
| 6302 | bool GeneralParser<ParseHandler, Unit>::matchInOrOf(bool* isForInp, | ||||
| 6303 | bool* isForOfp) { | ||||
| 6304 | TokenKind tt; | ||||
| 6305 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6306 | return false; | ||||
| 6307 | } | ||||
| 6308 | |||||
| 6309 | *isForInp = tt == TokenKind::In; | ||||
| 6310 | *isForOfp = tt == TokenKind::Of; | ||||
| 6311 | if (!*isForInp && !*isForOfp) { | ||||
| 6312 | anyChars.ungetToken(); | ||||
| 6313 | } | ||||
| 6314 | |||||
| 6315 | MOZ_ASSERT_IF(*isForInp || *isForOfp, *isForInp != *isForOfp)do { if (*isForInp || *isForOfp) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(*isForInp != *isForOfp )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(*isForInp != *isForOfp))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("*isForInp != *isForOfp", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 6315); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*isForInp != *isForOfp" ")"); do { MOZ_CrashSequence(__null, 6315); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); | ||||
| 6316 | return true; | ||||
| 6317 | } | ||||
| 6318 | |||||
| 6319 | template <class ParseHandler, typename Unit> | ||||
| 6320 | bool GeneralParser<ParseHandler, Unit>::forHeadStart( | ||||
| 6321 | YieldHandling yieldHandling, IteratorKind iterKind, | ||||
| 6322 | ParseNodeKind* forHeadKind, Node* forInitialPart, | ||||
| 6323 | Maybe<ParseContext::Scope>& forLoopLexicalScope, | ||||
| 6324 | Node* forInOrOfExpression) { | ||||
| 6325 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftParen))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftParen))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftParen)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftParen)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6325); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftParen)" ")"); do { MOZ_CrashSequence(__null, 6325); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6326 | |||||
| 6327 | TokenKind tt; | ||||
| 6328 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6329 | return false; | ||||
| 6330 | } | ||||
| 6331 | |||||
| 6332 | // Super-duper easy case: |for (;| is a C-style for-loop with no init | ||||
| 6333 | // component. | ||||
| 6334 | if (tt == TokenKind::Semi) { | ||||
| 6335 | *forInitialPart = null(); | ||||
| 6336 | *forHeadKind = ParseNodeKind::ForHead; | ||||
| 6337 | return true; | ||||
| 6338 | } | ||||
| 6339 | |||||
| 6340 | // Parsing after |for (var| is also relatively simple (from this method's | ||||
| 6341 | // point of view). No block-related work complicates matters, so delegate | ||||
| 6342 | // to Parser::declaration. | ||||
| 6343 | if (tt == TokenKind::Var) { | ||||
| 6344 | tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp); | ||||
| 6345 | |||||
| 6346 | // Pass null for block object because |var| declarations don't use one. | ||||
| 6347 | MOZ_TRY_VAR_OR_RETURN(*forInitialPart,do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , ParseNodeKind::VarStmt, forHeadKind, forInOrOfExpression)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0 ))) { return (false); } (*forInitialPart) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 6348 | declarationList(yieldHandling, ParseNodeKind::VarStmt,do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , ParseNodeKind::VarStmt, forHeadKind, forInOrOfExpression)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0 ))) { return (false); } (*forInitialPart) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 6349 | forHeadKind, forInOrOfExpression),do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , ParseNodeKind::VarStmt, forHeadKind, forInOrOfExpression)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0 ))) { return (false); } (*forInitialPart) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 6350 | false)do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , ParseNodeKind::VarStmt, forHeadKind, forInOrOfExpression)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0 ))) { return (false); } (*forInitialPart) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 6351 | return true; | ||||
| 6352 | } | ||||
| 6353 | |||||
| 6354 | // Otherwise we have a lexical declaration or an expression. | ||||
| 6355 | |||||
| 6356 | // For-in loop backwards compatibility requires that |let| starting a | ||||
| 6357 | // for-loop that's not a (new to ES6) for-of loop, in non-strict mode code, | ||||
| 6358 | // parse as an identifier. (|let| in for-of is always a declaration.) | ||||
| 6359 | // | ||||
| 6360 | // For-of loops can't start with the token sequence "async of", because that | ||||
| 6361 | // leads to a shift-reduce conflict when parsing |for (async of => {};;)| or | ||||
| 6362 | // |for (async of [])|. | ||||
| 6363 | bool parsingLexicalDeclaration = false; | ||||
| 6364 | bool letIsIdentifier = false; | ||||
| 6365 | bool startsWithForOf = false; | ||||
| 6366 | |||||
| 6367 | if (tt == TokenKind::Const) { | ||||
| 6368 | parsingLexicalDeclaration = true; | ||||
| 6369 | tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp); | ||||
| 6370 | } else if (tt == TokenKind::Await) { | ||||
| 6371 | if (!pc_->isAsync()) { | ||||
| 6372 | if (pc_->atModuleTopLevel()) { | ||||
| 6373 | if (!options().topLevelAwait) { | ||||
| 6374 | error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED); | ||||
| 6375 | return false; | ||||
| 6376 | } | ||||
| 6377 | pc_->sc()->asModuleContext()->setIsAsync(); | ||||
| 6378 | MOZ_ASSERT(pc_->isAsync())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isAsync())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isAsync()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isAsync()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6378); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence (__null, 6378); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 6379 | } | ||||
| 6380 | } | ||||
| 6381 | if (pc_->isAsync()) { | ||||
| 6382 | // Try finding evidence of a AwaitUsingDeclaration the syntax for which | ||||
| 6383 | // would be: | ||||
| 6384 | // await [no LineTerminator here] using [no LineTerminator here] | ||||
| 6385 | // identifier | ||||
| 6386 | tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp); | ||||
| 6387 | |||||
| 6388 | TokenKind nextTok = TokenKind::Eof; | ||||
| 6389 | if (!tokenStream.peekTokenSameLine(&nextTok, | ||||
| 6390 | TokenStream::SlashIsRegExp)) { | ||||
| 6391 | return false; | ||||
| 6392 | } | ||||
| 6393 | |||||
| 6394 | if (nextTok == TokenKind::Using) { | ||||
| 6395 | tokenStream.consumeKnownToken(nextTok, TokenStream::SlashIsRegExp); | ||||
| 6396 | |||||
| 6397 | TokenKind nextTokIdent = TokenKind::Eof; | ||||
| 6398 | if (!tokenStream.peekTokenSameLine(&nextTokIdent)) { | ||||
| 6399 | return false; | ||||
| 6400 | } | ||||
| 6401 | |||||
| 6402 | if (TokenKindIsPossibleIdentifier(nextTokIdent)) { | ||||
| 6403 | parsingLexicalDeclaration = true; | ||||
| 6404 | } else { | ||||
| 6405 | anyChars.ungetToken(); // put back using token | ||||
| 6406 | anyChars.ungetToken(); // put back await token | ||||
| 6407 | } | ||||
| 6408 | } else { | ||||
| 6409 | anyChars.ungetToken(); // put back await token | ||||
| 6410 | } | ||||
| 6411 | } | ||||
| 6412 | } else if (tt == TokenKind::Using) { | ||||
| 6413 | tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp); | ||||
| 6414 | |||||
| 6415 | // Look ahead to find either a 'of' token or if not identifier | ||||
| 6416 | TokenKind nextTok = TokenKind::Eof; | ||||
| 6417 | if (!tokenStream.peekTokenSameLine(&nextTok)) { | ||||
| 6418 | return false; | ||||
| 6419 | } | ||||
| 6420 | |||||
| 6421 | if (!TokenKindIsPossibleIdentifier(nextTok)) { | ||||
| 6422 | anyChars.ungetToken(); // we didnt find a valid case of using decl put | ||||
| 6423 | // back the token | ||||
| 6424 | } else if (nextTok == TokenKind::Of) { | ||||
| 6425 | // "for (using of" can be a prefix of the following: | ||||
| 6426 | // * "for (using of = 0;;) { ... }" | ||||
| 6427 | // * "for (using of [1, 2, 3]) { ... }" | ||||
| 6428 | // | ||||
| 6429 | // If the "of" token is followed by the assignment token, the loop is | ||||
| 6430 | // considered a C-style for-statement with a using declaration where | ||||
| 6431 | // "of" is an identifier. | ||||
| 6432 | // https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-for-statement&secAll=true | ||||
| 6433 | // | ||||
| 6434 | // If the "of" token is followed by anything else, this is a for-of | ||||
| 6435 | // statement with the "using" being an identifier", and the token after | ||||
| 6436 | // the "of" token being the first token of the iterated expression (thus | ||||
| 6437 | // SlashIsRegExp is used as the modifier). | ||||
| 6438 | // https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-for-in-and-for-of-statements&secAll=true | ||||
| 6439 | tokenStream.consumeKnownToken(nextTok); | ||||
| 6440 | TokenKind nextTokAssign; | ||||
| 6441 | if (!tokenStream.peekToken(&nextTokAssign, TokenStream::SlashIsRegExp)) { | ||||
| 6442 | return false; | ||||
| 6443 | } | ||||
| 6444 | if (nextTokAssign == TokenKind::Assign) { | ||||
| 6445 | parsingLexicalDeclaration = true; | ||||
| 6446 | anyChars.ungetToken(); // put back the assignment token | ||||
| 6447 | } else { | ||||
| 6448 | anyChars.ungetToken(); // put back the token after the "of" token | ||||
| 6449 | anyChars.ungetToken(); // put back the of token | ||||
| 6450 | } | ||||
| 6451 | } else { | ||||
| 6452 | parsingLexicalDeclaration = true; | ||||
| 6453 | } | ||||
| 6454 | } else if (tt == TokenKind::Let) { | ||||
| 6455 | // We could have a {For,Lexical}Declaration, or we could have a | ||||
| 6456 | // LeftHandSideExpression with lookahead restrictions so it's not | ||||
| 6457 | // ambiguous with the former. Check for a continuation of the former | ||||
| 6458 | // to decide which we have. | ||||
| 6459 | tokenStream.consumeKnownToken(TokenKind::Let, TokenStream::SlashIsRegExp); | ||||
| 6460 | |||||
| 6461 | TokenKind next; | ||||
| 6462 | if (!tokenStream.peekToken(&next)) { | ||||
| 6463 | return false; | ||||
| 6464 | } | ||||
| 6465 | |||||
| 6466 | parsingLexicalDeclaration = nextTokenContinuesLetDeclaration(next); | ||||
| 6467 | if (!parsingLexicalDeclaration) { | ||||
| 6468 | // If we end up here, we may have `for (let <reserved word> of/in ...`, | ||||
| 6469 | // which is not valid. | ||||
| 6470 | if (next != TokenKind::In && next != TokenKind::Of && | ||||
| 6471 | TokenKindIsReservedWord(next)) { | ||||
| 6472 | tokenStream.consumeKnownToken(next); | ||||
| 6473 | error(JSMSG_UNEXPECTED_TOKEN_NO_EXPECT, TokenKindToDesc(next)); | ||||
| 6474 | return false; | ||||
| 6475 | } | ||||
| 6476 | |||||
| 6477 | anyChars.ungetToken(); | ||||
| 6478 | letIsIdentifier = true; | ||||
| 6479 | } | ||||
| 6480 | } else if (tt == TokenKind::Async && iterKind == IteratorKind::Sync) { | ||||
| 6481 | tokenStream.consumeKnownToken(TokenKind::Async, TokenStream::SlashIsRegExp); | ||||
| 6482 | |||||
| 6483 | TokenKind next; | ||||
| 6484 | if (!tokenStream.peekToken(&next)) { | ||||
| 6485 | return false; | ||||
| 6486 | } | ||||
| 6487 | |||||
| 6488 | if (next == TokenKind::Of) { | ||||
| 6489 | startsWithForOf = true; | ||||
| 6490 | } | ||||
| 6491 | anyChars.ungetToken(); | ||||
| 6492 | } | ||||
| 6493 | |||||
| 6494 | if (parsingLexicalDeclaration) { | ||||
| 6495 | if (options().selfHostingMode) { | ||||
| 6496 | error(JSMSG_SELFHOSTED_LEXICAL); | ||||
| 6497 | return false; | ||||
| 6498 | } | ||||
| 6499 | |||||
| 6500 | forLoopLexicalScope.emplace(this); | ||||
| 6501 | if (!forLoopLexicalScope->init(pc_)) { | ||||
| 6502 | return false; | ||||
| 6503 | } | ||||
| 6504 | |||||
| 6505 | // Push a temporary ForLoopLexicalHead Statement that allows for | ||||
| 6506 | // lexical declarations, as they are usually allowed only in braced | ||||
| 6507 | // statements. | ||||
| 6508 | ParseContext::Statement forHeadStmt(pc_, StatementKind::ForLoopLexicalHead); | ||||
| 6509 | |||||
| 6510 | ParseNodeKind declKind; | ||||
| 6511 | switch (tt) { | ||||
| 6512 | case TokenKind::Const: | ||||
| 6513 | declKind = ParseNodeKind::ConstDecl; | ||||
| 6514 | break; | ||||
| 6515 | case TokenKind::Using: | ||||
| 6516 | declKind = ParseNodeKind::UsingDecl; | ||||
| 6517 | break; | ||||
| 6518 | case TokenKind::Await: | ||||
| 6519 | declKind = ParseNodeKind::AwaitUsingDecl; | ||||
| 6520 | break; | ||||
| 6521 | case TokenKind::Let: | ||||
| 6522 | declKind = ParseNodeKind::LetDecl; | ||||
| 6523 | break; | ||||
| 6524 | default: | ||||
| 6525 | MOZ_CRASH("unexpected node kind")do { do { } while (false); MOZ_ReportCrash("" "unexpected node kind" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6525); AnnotateMozCrashReason ("MOZ_CRASH(" "unexpected node kind" ")"); do { MOZ_CrashSequence (__null, 6525); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 6526 | } | ||||
| 6527 | |||||
| 6528 | MOZ_TRY_VAR_OR_RETURN(*forInitialPart,do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , declKind, forHeadKind, forInOrOfExpression)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 6529 | declarationList(yieldHandling, declKind, forHeadKind,do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , declKind, forHeadKind, forInOrOfExpression)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 6530 | forInOrOfExpression),do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , declKind, forHeadKind, forInOrOfExpression)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 6531 | false)do { auto parserTryVarTempResult_ = (declarationList(yieldHandling , declKind, forHeadKind, forInOrOfExpression)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 6532 | return true; | ||||
| 6533 | } | ||||
| 6534 | |||||
| 6535 | uint32_t exprOffset; | ||||
| 6536 | if (!tokenStream.peekOffset(&exprOffset, TokenStream::SlashIsRegExp)) { | ||||
| 6537 | return false; | ||||
| 6538 | } | ||||
| 6539 | |||||
| 6540 | // Finally, handle for-loops that start with expressions. Pass | ||||
| 6541 | // |InProhibited| so that |in| isn't parsed in a RelationalExpression as a | ||||
| 6542 | // binary operator. |in| makes it a for-in loop, *not* an |in| expression. | ||||
| 6543 | PossibleError possibleError(*this); | ||||
| 6544 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (expr(InProhibited, yieldHandling , TripledotProhibited, &possibleError)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 6545 | *forInitialPart,do { auto parserTryVarTempResult_ = (expr(InProhibited, yieldHandling , TripledotProhibited, &possibleError)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 6546 | expr(InProhibited, yieldHandling, TripledotProhibited, &possibleError),do { auto parserTryVarTempResult_ = (expr(InProhibited, yieldHandling , TripledotProhibited, &possibleError)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 6547 | false)do { auto parserTryVarTempResult_ = (expr(InProhibited, yieldHandling , TripledotProhibited, &possibleError)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (*forInitialPart) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 6548 | |||||
| 6549 | bool isForIn, isForOf; | ||||
| 6550 | if (!matchInOrOf(&isForIn, &isForOf)) { | ||||
| 6551 | return false; | ||||
| 6552 | } | ||||
| 6553 | |||||
| 6554 | // If we don't encounter 'in'/'of', we have a for(;;) loop. We've handled | ||||
| 6555 | // the init expression; the caller handles the rest. | ||||
| 6556 | if (!isForIn && !isForOf) { | ||||
| 6557 | if (!possibleError.checkForExpressionError()) { | ||||
| 6558 | return false; | ||||
| 6559 | } | ||||
| 6560 | |||||
| 6561 | *forHeadKind = ParseNodeKind::ForHead; | ||||
| 6562 | return true; | ||||
| 6563 | } | ||||
| 6564 | |||||
| 6565 | MOZ_ASSERT(isForIn != isForOf)do { static_assert( mozilla::detail::AssertionConditionType< decltype(isForIn != isForOf)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(isForIn != isForOf))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("isForIn != isForOf" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6565); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "isForIn != isForOf" ")"); do { MOZ_CrashSequence (__null, 6565); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 6566 | |||||
| 6567 | // In a for-of loop, 'let' that starts the loop head is a |let| keyword, | ||||
| 6568 | // per the [lookahead ≠ let] restriction on the LeftHandSideExpression | ||||
| 6569 | // variant of such loops. Expressions that start with |let| can't be used | ||||
| 6570 | // here. | ||||
| 6571 | // | ||||
| 6572 | // var let = {}; | ||||
| 6573 | // for (let.prop of [1]) // BAD | ||||
| 6574 | // break; | ||||
| 6575 | // | ||||
| 6576 | // See ES6 13.7. | ||||
| 6577 | if (isForOf && letIsIdentifier) { | ||||
| 6578 | errorAt(exprOffset, JSMSG_BAD_STARTING_FOROF_LHS, "let"); | ||||
| 6579 | return false; | ||||
| 6580 | } | ||||
| 6581 | |||||
| 6582 | // In a for-of loop, the LeftHandSideExpression isn't allowed to be an | ||||
| 6583 | // identifier named "async" per the [lookahead ≠ async of] restriction. | ||||
| 6584 | if (isForOf && startsWithForOf) { | ||||
| 6585 | errorAt(exprOffset, JSMSG_BAD_STARTING_FOROF_LHS, "async of"); | ||||
| 6586 | return false; | ||||
| 6587 | } | ||||
| 6588 | |||||
| 6589 | *forHeadKind = isForIn ? ParseNodeKind::ForIn : ParseNodeKind::ForOf; | ||||
| 6590 | |||||
| 6591 | // Verify the left-hand side expression doesn't have a forbidden form. | ||||
| 6592 | if (handler_.isUnparenthesizedDestructuringPattern(*forInitialPart)) { | ||||
| 6593 | if (!possibleError.checkForDestructuringErrorOrWarning()) { | ||||
| 6594 | return false; | ||||
| 6595 | } | ||||
| 6596 | } else if (handler_.isName(*forInitialPart)) { | ||||
| 6597 | if (const char* chars = nameIsArgumentsOrEval(*forInitialPart)) { | ||||
| 6598 | // |chars| is "arguments" or "eval" here. | ||||
| 6599 | if (!strictModeErrorAt(exprOffset, JSMSG_BAD_STRICT_ASSIGN, chars)) { | ||||
| 6600 | return false; | ||||
| 6601 | } | ||||
| 6602 | } | ||||
| 6603 | } else if (handler_.isArgumentsLength(*forInitialPart)) { | ||||
| 6604 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 6605 | } else if (handler_.isPropertyOrPrivateMemberAccess(*forInitialPart)) { | ||||
| 6606 | // Permitted: no additional testing/fixup needed. | ||||
| 6607 | } else if (handler_.isFunctionCall(*forInitialPart)) { | ||||
| 6608 | if (!strictModeErrorAt(exprOffset, JSMSG_BAD_FOR_LEFTSIDE)) { | ||||
| 6609 | return false; | ||||
| 6610 | } | ||||
| 6611 | } else { | ||||
| 6612 | errorAt(exprOffset, JSMSG_BAD_FOR_LEFTSIDE); | ||||
| 6613 | return false; | ||||
| 6614 | } | ||||
| 6615 | |||||
| 6616 | if (!possibleError.checkForExpressionError()) { | ||||
| 6617 | return false; | ||||
| 6618 | } | ||||
| 6619 | |||||
| 6620 | // Finally, parse the iterated expression, making the for-loop's closing | ||||
| 6621 | // ')' the next token. | ||||
| 6622 | MOZ_TRY_VAR_OR_RETURN(*forInOrOfExpression,do { auto parserTryVarTempResult_ = (expressionAfterForInOrOf (*forHeadKind, yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (*forInOrOfExpression) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 6623 | expressionAfterForInOrOf(*forHeadKind, yieldHandling),do { auto parserTryVarTempResult_ = (expressionAfterForInOrOf (*forHeadKind, yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (*forInOrOfExpression) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 6624 | false)do { auto parserTryVarTempResult_ = (expressionAfterForInOrOf (*forHeadKind, yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (*forInOrOfExpression) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 6625 | return true; | ||||
| 6626 | } | ||||
| 6627 | |||||
| 6628 | template <class ParseHandler, typename Unit> | ||||
| 6629 | typename ParseHandler::NodeResult | ||||
| 6630 | GeneralParser<ParseHandler, Unit>::forStatement(YieldHandling yieldHandling) { | ||||
| 6631 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::For))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::For))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::For)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::For)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6631); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::For)" ")"); do { MOZ_CrashSequence(__null, 6631); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6632 | |||||
| 6633 | uint32_t begin = pos().begin; | ||||
| 6634 | |||||
| 6635 | ParseContext::Statement stmt(pc_, StatementKind::ForLoop); | ||||
| 6636 | |||||
| 6637 | IteratorKind iterKind = IteratorKind::Sync; | ||||
| 6638 | unsigned iflags = 0; | ||||
| 6639 | |||||
| 6640 | if (pc_->isAsync() || pc_->sc()->isModuleContext()) { | ||||
| 6641 | bool matched; | ||||
| 6642 | if (!tokenStream.matchToken(&matched, TokenKind::Await)) { | ||||
| 6643 | return errorResult(); | ||||
| 6644 | } | ||||
| 6645 | |||||
| 6646 | // If we come across a top level await here, mark the module as async. | ||||
| 6647 | if (matched && pc_->sc()->isModuleContext() && !pc_->isAsync()) { | ||||
| 6648 | if (!options().topLevelAwait) { | ||||
| 6649 | error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED); | ||||
| 6650 | return errorResult(); | ||||
| 6651 | } | ||||
| 6652 | pc_->sc()->asModuleContext()->setIsAsync(); | ||||
| 6653 | MOZ_ASSERT(pc_->isAsync())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isAsync())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isAsync()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isAsync()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6653); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence (__null, 6653); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 6654 | } | ||||
| 6655 | |||||
| 6656 | if (matched) { | ||||
| 6657 | iflags |= JSITER_FORAWAITOF0x80; | ||||
| 6658 | iterKind = IteratorKind::Async; | ||||
| 6659 | } | ||||
| 6660 | } | ||||
| 6661 | |||||
| 6662 | if (!mustMatchToken(TokenKind::LeftParen, [this](TokenKind actual) { | ||||
| 6663 | this->error((actual == TokenKind::Await && !this->pc_->isAsync()) | ||||
| 6664 | ? JSMSG_FOR_AWAIT_OUTSIDE_ASYNC | ||||
| 6665 | : JSMSG_PAREN_AFTER_FOR); | ||||
| 6666 | })) { | ||||
| 6667 | return errorResult(); | ||||
| 6668 | } | ||||
| 6669 | |||||
| 6670 | // ParseNodeKind::ForHead, ParseNodeKind::ForIn, or | ||||
| 6671 | // ParseNodeKind::ForOf depending on the loop type. | ||||
| 6672 | ParseNodeKind headKind; | ||||
| 6673 | |||||
| 6674 | // |x| in either |for (x; ...; ...)| or |for (x in/of ...)|. | ||||
| 6675 | Node startNode; | ||||
| 6676 | |||||
| 6677 | // The next two variables are used to implement `for (let/const ...)`. | ||||
| 6678 | // | ||||
| 6679 | // We generate an implicit block, wrapping the whole loop, to store loop | ||||
| 6680 | // variables declared this way. Note that if the loop uses `for (var...)` | ||||
| 6681 | // instead, those variables go on some existing enclosing scope, so no | ||||
| 6682 | // implicit block scope is created. | ||||
| 6683 | // | ||||
| 6684 | // Both variables remain null/none if the loop is any other form. | ||||
| 6685 | |||||
| 6686 | // The static block scope for the implicit block scope. | ||||
| 6687 | Maybe<ParseContext::Scope> forLoopLexicalScope; | ||||
| 6688 | |||||
| 6689 | // The expression being iterated over, for for-in/of loops only. Unused | ||||
| 6690 | // for for(;;) loops. | ||||
| 6691 | Node iteratedExpr; | ||||
| 6692 | |||||
| 6693 | // Parse the entirety of the loop-head for a for-in/of loop (so the next | ||||
| 6694 | // token is the closing ')'): | ||||
| 6695 | // | ||||
| 6696 | // for (... in/of ...) ... | ||||
| 6697 | // ^next token | ||||
| 6698 | // | ||||
| 6699 | // ...OR, parse up to the first ';' in a C-style for-loop: | ||||
| 6700 | // | ||||
| 6701 | // for (...; ...; ...) ... | ||||
| 6702 | // ^next token | ||||
| 6703 | // | ||||
| 6704 | // In either case the subsequent token can be consistently accessed using | ||||
| 6705 | // TokenStream::SlashIsDiv semantics. | ||||
| 6706 | if (!forHeadStart(yieldHandling, iterKind, &headKind, &startNode, | ||||
| 6707 | forLoopLexicalScope, &iteratedExpr)) { | ||||
| 6708 | return errorResult(); | ||||
| 6709 | } | ||||
| 6710 | |||||
| 6711 | MOZ_ASSERT(headKind == ParseNodeKind::ForIn ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind ::ForOf || headKind == ParseNodeKind::ForHead)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind ::ForHead))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6713); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead" ")"); do { MOZ_CrashSequence(__null, 6713); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 6712 | headKind == ParseNodeKind::ForOf ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind ::ForOf || headKind == ParseNodeKind::ForHead)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind ::ForHead))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6713); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead" ")"); do { MOZ_CrashSequence(__null, 6713); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 6713 | headKind == ParseNodeKind::ForHead)do { static_assert( mozilla::detail::AssertionConditionType< decltype(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind ::ForOf || headKind == ParseNodeKind::ForHead)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind ::ForHead))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6713); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead" ")"); do { MOZ_CrashSequence(__null, 6713); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6714 | |||||
| 6715 | if (iterKind == IteratorKind::Async && headKind != ParseNodeKind::ForOf) { | ||||
| 6716 | errorAt(begin, JSMSG_FOR_AWAIT_NOT_OF); | ||||
| 6717 | return errorResult(); | ||||
| 6718 | } | ||||
| 6719 | |||||
| 6720 | TernaryNodeType forHead; | ||||
| 6721 | if (headKind == ParseNodeKind::ForHead) { | ||||
| 6722 | Node init = startNode; | ||||
| 6723 | |||||
| 6724 | // Look for an operand: |for (;| means we might have already examined | ||||
| 6725 | // this semicolon with that modifier. | ||||
| 6726 | if (!mustMatchToken(TokenKind::Semi, JSMSG_SEMI_AFTER_FOR_INIT)) { | ||||
| 6727 | return errorResult(); | ||||
| 6728 | } | ||||
| 6729 | |||||
| 6730 | TokenKind tt; | ||||
| 6731 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6732 | return errorResult(); | ||||
| 6733 | } | ||||
| 6734 | |||||
| 6735 | Node test; | ||||
| 6736 | if (tt == TokenKind::Semi) { | ||||
| 6737 | test = null(); | ||||
| 6738 | } else { | ||||
| 6739 | test = MOZ_TRY(expr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6740 | } | ||||
| 6741 | |||||
| 6742 | if (!mustMatchToken(TokenKind::Semi, JSMSG_SEMI_AFTER_FOR_COND)) { | ||||
| 6743 | return errorResult(); | ||||
| 6744 | } | ||||
| 6745 | |||||
| 6746 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6747 | return errorResult(); | ||||
| 6748 | } | ||||
| 6749 | |||||
| 6750 | Node update; | ||||
| 6751 | if (tt == TokenKind::RightParen) { | ||||
| 6752 | update = null(); | ||||
| 6753 | } else { | ||||
| 6754 | update = MOZ_TRY(expr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6755 | } | ||||
| 6756 | |||||
| 6757 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_FOR_CTRL)) { | ||||
| 6758 | return errorResult(); | ||||
| 6759 | } | ||||
| 6760 | |||||
| 6761 | TokenPos headPos(begin, pos().end); | ||||
| 6762 | forHead = MOZ_TRY(handler_.newForHead(init, test, update, headPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newForHead(init, test, update, headPos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6763 | } else { | ||||
| 6764 | MOZ_ASSERT(headKind == ParseNodeKind::ForIn ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind ::ForOf)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind ::ForOf))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6765); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf" ")"); do { MOZ_CrashSequence(__null, 6765); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 6765 | headKind == ParseNodeKind::ForOf)do { static_assert( mozilla::detail::AssertionConditionType< decltype(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind ::ForOf)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind ::ForOf))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6765); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf" ")"); do { MOZ_CrashSequence(__null, 6765); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6766 | |||||
| 6767 | // |target| is the LeftHandSideExpression or declaration to which the | ||||
| 6768 | // per-iteration value (an arbitrary value exposed by the iteration | ||||
| 6769 | // protocol, or a string naming a property) is assigned. | ||||
| 6770 | Node target = startNode; | ||||
| 6771 | |||||
| 6772 | // Parse the rest of the for-in/of head. | ||||
| 6773 | if (headKind == ParseNodeKind::ForIn) { | ||||
| 6774 | stmt.refineForKind(StatementKind::ForInLoop); | ||||
| 6775 | } else { | ||||
| 6776 | stmt.refineForKind(StatementKind::ForOfLoop); | ||||
| 6777 | } | ||||
| 6778 | |||||
| 6779 | // Parser::declaration consumed everything up to the closing ')'. That | ||||
| 6780 | // token follows an {Assignment,}Expression and so must be interpreted | ||||
| 6781 | // as an operand to be consistent with normal expression tokenizing. | ||||
| 6782 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_FOR_CTRL)) { | ||||
| 6783 | return errorResult(); | ||||
| 6784 | } | ||||
| 6785 | |||||
| 6786 | TokenPos headPos(begin, pos().end); | ||||
| 6787 | forHead = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newForInOrOfHead(headKind, target, iteratedExpr, headPos )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 6788 | handler_.newForInOrOfHead(headKind, target, iteratedExpr, headPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newForInOrOfHead(headKind, target, iteratedExpr, headPos )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 6789 | } | ||||
| 6790 | |||||
| 6791 | Node body = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6792 | |||||
| 6793 | ForNodeType forLoop = | ||||
| 6794 | MOZ_TRY(handler_.newForStatement(begin, forHead, body, iflags))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newForStatement(begin, forHead, body, iflags)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 6795 | |||||
| 6796 | if (forLoopLexicalScope) { | ||||
| 6797 | return finishLexicalScope(*forLoopLexicalScope, forLoop); | ||||
| 6798 | } | ||||
| 6799 | |||||
| 6800 | return forLoop; | ||||
| 6801 | } | ||||
| 6802 | |||||
| 6803 | template <class ParseHandler, typename Unit> | ||||
| 6804 | typename ParseHandler::SwitchStatementResult | ||||
| 6805 | GeneralParser<ParseHandler, Unit>::switchStatement( | ||||
| 6806 | YieldHandling yieldHandling) { | ||||
| 6807 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Switch))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Switch))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Switch)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Switch)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6807); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Switch)" ")"); do { MOZ_CrashSequence(__null, 6807); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6808 | uint32_t begin = pos().begin; | ||||
| 6809 | |||||
| 6810 | if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_SWITCH)) { | ||||
| 6811 | return errorResult(); | ||||
| 6812 | } | ||||
| 6813 | |||||
| 6814 | Node discriminant = | ||||
| 6815 | MOZ_TRY(exprInParens(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (exprInParens(InAllowed, yieldHandling, TripledotProhibited)) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 6816 | |||||
| 6817 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_SWITCH)) { | ||||
| 6818 | return errorResult(); | ||||
| 6819 | } | ||||
| 6820 | if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_SWITCH)) { | ||||
| 6821 | return errorResult(); | ||||
| 6822 | } | ||||
| 6823 | |||||
| 6824 | ParseContext::Statement stmt(pc_, StatementKind::Switch); | ||||
| 6825 | ParseContext::Scope scope(this); | ||||
| 6826 | if (!scope.init(pc_)) { | ||||
| 6827 | return errorResult(); | ||||
| 6828 | } | ||||
| 6829 | |||||
| 6830 | ListNodeType caseList = MOZ_TRY(handler_.newStatementList(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(pos())); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6831 | |||||
| 6832 | bool seenDefault = false; | ||||
| 6833 | TokenKind tt; | ||||
| 6834 | while (true) { | ||||
| 6835 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6836 | return errorResult(); | ||||
| 6837 | } | ||||
| 6838 | if (tt == TokenKind::RightCurly) { | ||||
| 6839 | break; | ||||
| 6840 | } | ||||
| 6841 | uint32_t caseBegin = pos().begin; | ||||
| 6842 | |||||
| 6843 | Node caseExpr; | ||||
| 6844 | switch (tt) { | ||||
| 6845 | case TokenKind::Default: | ||||
| 6846 | if (seenDefault) { | ||||
| 6847 | error(JSMSG_TOO_MANY_DEFAULTS); | ||||
| 6848 | return errorResult(); | ||||
| 6849 | } | ||||
| 6850 | seenDefault = true; | ||||
| 6851 | caseExpr = null(); // The default case has pn_left == nullptr. | ||||
| 6852 | break; | ||||
| 6853 | |||||
| 6854 | case TokenKind::Case: | ||||
| 6855 | caseExpr = MOZ_TRY(expr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6856 | break; | ||||
| 6857 | |||||
| 6858 | default: | ||||
| 6859 | error(JSMSG_BAD_SWITCH); | ||||
| 6860 | return errorResult(); | ||||
| 6861 | } | ||||
| 6862 | |||||
| 6863 | if (!mustMatchToken(TokenKind::Colon, JSMSG_COLON_AFTER_CASE)) { | ||||
| 6864 | return errorResult(); | ||||
| 6865 | } | ||||
| 6866 | |||||
| 6867 | ListNodeType body = MOZ_TRY(handler_.newStatementList(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(pos())); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6868 | |||||
| 6869 | bool afterReturn = false; | ||||
| 6870 | bool warnedAboutStatementsAfterReturn = false; | ||||
| 6871 | uint32_t statementBegin = 0; | ||||
| 6872 | while (true) { | ||||
| 6873 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6874 | return errorResult(); | ||||
| 6875 | } | ||||
| 6876 | if (tt == TokenKind::RightCurly || tt == TokenKind::Case || | ||||
| 6877 | tt == TokenKind::Default) { | ||||
| 6878 | break; | ||||
| 6879 | } | ||||
| 6880 | if (afterReturn) { | ||||
| 6881 | if (!tokenStream.peekOffset(&statementBegin, | ||||
| 6882 | TokenStream::SlashIsRegExp)) { | ||||
| 6883 | return errorResult(); | ||||
| 6884 | } | ||||
| 6885 | } | ||||
| 6886 | Node stmt = MOZ_TRY(statementListItem(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementListItem(yieldHandling)); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6887 | if (!warnedAboutStatementsAfterReturn) { | ||||
| 6888 | if (afterReturn) { | ||||
| 6889 | if (!handler_.isStatementPermittedAfterReturnStatement(stmt)) { | ||||
| 6890 | if (!warningAt(statementBegin, JSMSG_STMT_AFTER_RETURN)) { | ||||
| 6891 | return errorResult(); | ||||
| 6892 | } | ||||
| 6893 | |||||
| 6894 | warnedAboutStatementsAfterReturn = true; | ||||
| 6895 | } | ||||
| 6896 | } else if (handler_.isReturnStatement(stmt)) { | ||||
| 6897 | afterReturn = true; | ||||
| 6898 | } | ||||
| 6899 | } | ||||
| 6900 | handler_.addStatementToList(body, stmt); | ||||
| 6901 | } | ||||
| 6902 | |||||
| 6903 | CaseClauseType caseClause = | ||||
| 6904 | MOZ_TRY(handler_.newCaseOrDefault(caseBegin, caseExpr, body))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newCaseOrDefault(caseBegin, caseExpr, body)); if (( __builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 6905 | handler_.addCaseStatementToList(caseList, caseClause); | ||||
| 6906 | } | ||||
| 6907 | |||||
| 6908 | LexicalScopeNodeType lexicalForCaseList = | ||||
| 6909 | MOZ_TRY(finishLexicalScope(scope, caseList))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope(scope, caseList)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 6910 | |||||
| 6911 | handler_.setEndPosition(lexicalForCaseList, pos().end); | ||||
| 6912 | |||||
| 6913 | return handler_.newSwitchStatement(begin, discriminant, lexicalForCaseList, | ||||
| 6914 | seenDefault); | ||||
| 6915 | } | ||||
| 6916 | |||||
| 6917 | template <class ParseHandler, typename Unit> | ||||
| 6918 | typename ParseHandler::ContinueStatementResult | ||||
| 6919 | GeneralParser<ParseHandler, Unit>::continueStatement( | ||||
| 6920 | YieldHandling yieldHandling) { | ||||
| 6921 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Continue))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Continue))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Continue)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Continue)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6921); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Continue)" ")"); do { MOZ_CrashSequence(__null, 6921); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6922 | uint32_t begin = pos().begin; | ||||
| 6923 | |||||
| 6924 | TaggedParserAtomIndex label; | ||||
| 6925 | if (!matchLabel(yieldHandling, &label)) { | ||||
| 6926 | return errorResult(); | ||||
| 6927 | } | ||||
| 6928 | |||||
| 6929 | auto validity = pc_->checkContinueStatement(label); | ||||
| 6930 | if (validity.isErr()) { | ||||
| 6931 | switch (validity.unwrapErr()) { | ||||
| 6932 | case ParseContext::ContinueStatementError::NotInALoop: | ||||
| 6933 | errorAt(begin, JSMSG_BAD_CONTINUE); | ||||
| 6934 | break; | ||||
| 6935 | case ParseContext::ContinueStatementError::LabelNotFound: | ||||
| 6936 | error(JSMSG_LABEL_NOT_FOUND); | ||||
| 6937 | break; | ||||
| 6938 | } | ||||
| 6939 | return errorResult(); | ||||
| 6940 | } | ||||
| 6941 | |||||
| 6942 | if (!matchOrInsertSemicolon()) { | ||||
| 6943 | return errorResult(); | ||||
| 6944 | } | ||||
| 6945 | |||||
| 6946 | return handler_.newContinueStatement(label, TokenPos(begin, pos().end)); | ||||
| 6947 | } | ||||
| 6948 | |||||
| 6949 | template <class ParseHandler, typename Unit> | ||||
| 6950 | typename ParseHandler::BreakStatementResult | ||||
| 6951 | GeneralParser<ParseHandler, Unit>::breakStatement(YieldHandling yieldHandling) { | ||||
| 6952 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Break))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Break))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Break)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Break)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6952); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Break)" ")"); do { MOZ_CrashSequence(__null, 6952); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6953 | uint32_t begin = pos().begin; | ||||
| 6954 | |||||
| 6955 | TaggedParserAtomIndex label; | ||||
| 6956 | if (!matchLabel(yieldHandling, &label)) { | ||||
| 6957 | return errorResult(); | ||||
| 6958 | } | ||||
| 6959 | |||||
| 6960 | auto validity = pc_->checkBreakStatement(label); | ||||
| 6961 | if (validity.isErr()) { | ||||
| 6962 | switch (validity.unwrapErr()) { | ||||
| 6963 | case ParseContext::BreakStatementError::ToughBreak: | ||||
| 6964 | errorAt(begin, JSMSG_TOUGH_BREAK); | ||||
| 6965 | return errorResult(); | ||||
| 6966 | case ParseContext::BreakStatementError::LabelNotFound: | ||||
| 6967 | error(JSMSG_LABEL_NOT_FOUND); | ||||
| 6968 | return errorResult(); | ||||
| 6969 | } | ||||
| 6970 | } | ||||
| 6971 | |||||
| 6972 | if (!matchOrInsertSemicolon()) { | ||||
| 6973 | return errorResult(); | ||||
| 6974 | } | ||||
| 6975 | |||||
| 6976 | return handler_.newBreakStatement(label, TokenPos(begin, pos().end)); | ||||
| 6977 | } | ||||
| 6978 | |||||
| 6979 | template <class ParseHandler, typename Unit> | ||||
| 6980 | typename ParseHandler::UnaryNodeResult | ||||
| 6981 | GeneralParser<ParseHandler, Unit>::returnStatement( | ||||
| 6982 | YieldHandling yieldHandling) { | ||||
| 6983 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Return))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Return))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Return)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Return)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6983); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Return)" ")"); do { MOZ_CrashSequence(__null, 6983); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 6984 | uint32_t begin = pos().begin; | ||||
| 6985 | |||||
| 6986 | MOZ_ASSERT(pc_->isFunctionBox())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isFunctionBox())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isFunctionBox()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isFunctionBox()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 6986); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence (__null, 6986); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 6987 | |||||
| 6988 | // Parse an optional operand. | ||||
| 6989 | // | ||||
| 6990 | // This is ugly, but we don't want to require a semicolon. | ||||
| 6991 | TokenKind tt = TokenKind::Eof; | ||||
| 6992 | if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 6993 | return errorResult(); | ||||
| 6994 | } | ||||
| 6995 | |||||
| 6996 | Node exprNode; | ||||
| 6997 | switch (tt) { | ||||
| 6998 | case TokenKind::Eol: | ||||
| 6999 | case TokenKind::Eof: | ||||
| 7000 | case TokenKind::Semi: | ||||
| 7001 | case TokenKind::RightCurly: | ||||
| 7002 | exprNode = null(); | ||||
| 7003 | break; | ||||
| 7004 | default: { | ||||
| 7005 | exprNode = MOZ_TRY(expr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7006 | } | ||||
| 7007 | } | ||||
| 7008 | |||||
| 7009 | if (!matchOrInsertSemicolon()) { | ||||
| 7010 | return errorResult(); | ||||
| 7011 | } | ||||
| 7012 | |||||
| 7013 | return handler_.newReturnStatement(exprNode, TokenPos(begin, pos().end)); | ||||
| 7014 | } | ||||
| 7015 | |||||
| 7016 | template <class ParseHandler, typename Unit> | ||||
| 7017 | typename ParseHandler::UnaryNodeResult | ||||
| 7018 | GeneralParser<ParseHandler, Unit>::yieldExpression(InHandling inHandling) { | ||||
| 7019 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Yield))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Yield))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Yield)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Yield)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7019); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Yield)" ")"); do { MOZ_CrashSequence(__null, 7019); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 7020 | uint32_t begin = pos().begin; | ||||
| 7021 | |||||
| 7022 | MOZ_ASSERT(pc_->isGenerator())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isGenerator())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isGenerator()))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isGenerator()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7022); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isGenerator()" ")"); do { MOZ_CrashSequence (__null, 7022); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 7023 | MOZ_ASSERT(pc_->isFunctionBox())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isFunctionBox())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isFunctionBox()))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isFunctionBox()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7023); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence (__null, 7023); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 7024 | |||||
| 7025 | pc_->lastYieldOffset = begin; | ||||
| 7026 | |||||
| 7027 | Node exprNode; | ||||
| 7028 | ParseNodeKind kind = ParseNodeKind::YieldExpr; | ||||
| 7029 | TokenKind tt = TokenKind::Eof; | ||||
| 7030 | if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 7031 | return errorResult(); | ||||
| 7032 | } | ||||
| 7033 | switch (tt) { | ||||
| 7034 | // TokenKind::Eol is special; it implements the [no LineTerminator here] | ||||
| 7035 | // quirk in the grammar. | ||||
| 7036 | case TokenKind::Eol: | ||||
| 7037 | // The rest of these make up the complete set of tokens that can | ||||
| 7038 | // appear after any of the places where AssignmentExpression is used | ||||
| 7039 | // throughout the grammar. Conveniently, none of them can also be the | ||||
| 7040 | // start an expression. | ||||
| 7041 | case TokenKind::Eof: | ||||
| 7042 | case TokenKind::Semi: | ||||
| 7043 | case TokenKind::RightCurly: | ||||
| 7044 | case TokenKind::RightBracket: | ||||
| 7045 | case TokenKind::RightParen: | ||||
| 7046 | case TokenKind::Colon: | ||||
| 7047 | case TokenKind::Comma: | ||||
| 7048 | case TokenKind::In: // Annex B.3.6 `for (x = yield in y) ;` | ||||
| 7049 | // No value. | ||||
| 7050 | exprNode = null(); | ||||
| 7051 | break; | ||||
| 7052 | case TokenKind::Mul: | ||||
| 7053 | kind = ParseNodeKind::YieldStarExpr; | ||||
| 7054 | tokenStream.consumeKnownToken(TokenKind::Mul, TokenStream::SlashIsRegExp); | ||||
| 7055 | [[fallthrough]]; | ||||
| 7056 | default: | ||||
| 7057 | exprNode = | ||||
| 7058 | MOZ_TRY(assignExpr(inHandling, YieldIsKeyword, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, YieldIsKeyword, TripledotProhibited)) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 7059 | } | ||||
| 7060 | if (kind == ParseNodeKind::YieldStarExpr) { | ||||
| 7061 | return handler_.newYieldStarExpression(begin, exprNode); | ||||
| 7062 | } | ||||
| 7063 | return handler_.newYieldExpression(begin, exprNode); | ||||
| 7064 | } | ||||
| 7065 | |||||
| 7066 | template <class ParseHandler, typename Unit> | ||||
| 7067 | typename ParseHandler::BinaryNodeResult | ||||
| 7068 | GeneralParser<ParseHandler, Unit>::withStatement(YieldHandling yieldHandling) { | ||||
| 7069 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::With))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::With))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::With)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::With)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7069); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::With)" ")"); do { MOZ_CrashSequence(__null, 7069); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 7070 | uint32_t begin = pos().begin; | ||||
| 7071 | |||||
| 7072 | if (pc_->sc()->strict()) { | ||||
| 7073 | if (!strictModeError(JSMSG_STRICT_CODE_WITH)) { | ||||
| 7074 | return errorResult(); | ||||
| 7075 | } | ||||
| 7076 | } | ||||
| 7077 | |||||
| 7078 | if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_WITH)) { | ||||
| 7079 | return errorResult(); | ||||
| 7080 | } | ||||
| 7081 | |||||
| 7082 | Node objectExpr = | ||||
| 7083 | MOZ_TRY(exprInParens(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (exprInParens(InAllowed, yieldHandling, TripledotProhibited)) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 7084 | |||||
| 7085 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_WITH)) { | ||||
| 7086 | return errorResult(); | ||||
| 7087 | } | ||||
| 7088 | |||||
| 7089 | Node innerBlock; | ||||
| 7090 | { | ||||
| 7091 | ParseContext::Statement stmt(pc_, StatementKind::With); | ||||
| 7092 | innerBlock = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7093 | } | ||||
| 7094 | |||||
| 7095 | pc_->sc()->setBindingsAccessedDynamically(); | ||||
| 7096 | |||||
| 7097 | return handler_.newWithStatement(begin, objectExpr, innerBlock); | ||||
| 7098 | } | ||||
| 7099 | |||||
| 7100 | template <class ParseHandler, typename Unit> | ||||
| 7101 | typename ParseHandler::NodeResult | ||||
| 7102 | GeneralParser<ParseHandler, Unit>::labeledItem(YieldHandling yieldHandling) { | ||||
| 7103 | TokenKind tt; | ||||
| 7104 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 7105 | return errorResult(); | ||||
| 7106 | } | ||||
| 7107 | |||||
| 7108 | if (tt == TokenKind::Function) { | ||||
| 7109 | TokenKind next; | ||||
| 7110 | if (!tokenStream.peekToken(&next)) { | ||||
| 7111 | return errorResult(); | ||||
| 7112 | } | ||||
| 7113 | |||||
| 7114 | // GeneratorDeclaration is only matched by HoistableDeclaration in | ||||
| 7115 | // StatementListItem, so generators can't be inside labels. | ||||
| 7116 | if (next == TokenKind::Mul) { | ||||
| 7117 | error(JSMSG_GENERATOR_LABEL); | ||||
| 7118 | return errorResult(); | ||||
| 7119 | } | ||||
| 7120 | |||||
| 7121 | // Per 13.13.1 it's a syntax error if LabelledItem: FunctionDeclaration | ||||
| 7122 | // is ever matched. Per Annex B.3.2 that modifies this text, this | ||||
| 7123 | // applies only to strict mode code. | ||||
| 7124 | if (pc_->sc()->strict()) { | ||||
| 7125 | error(JSMSG_FUNCTION_LABEL); | ||||
| 7126 | return errorResult(); | ||||
| 7127 | } | ||||
| 7128 | |||||
| 7129 | return functionStmt(pos().begin, yieldHandling, NameRequired); | ||||
| 7130 | } | ||||
| 7131 | |||||
| 7132 | anyChars.ungetToken(); | ||||
| 7133 | return statement(yieldHandling); | ||||
| 7134 | } | ||||
| 7135 | |||||
| 7136 | template <class ParseHandler, typename Unit> | ||||
| 7137 | typename ParseHandler::LabeledStatementResult | ||||
| 7138 | GeneralParser<ParseHandler, Unit>::labeledStatement( | ||||
| 7139 | YieldHandling yieldHandling) { | ||||
| 7140 | TaggedParserAtomIndex label = labelIdentifier(yieldHandling); | ||||
| 7141 | if (!label) { | ||||
| 7142 | return errorResult(); | ||||
| 7143 | } | ||||
| 7144 | |||||
| 7145 | auto hasSameLabel = [&label](ParseContext::LabelStatement* stmt) { | ||||
| 7146 | return stmt->label() == label; | ||||
| 7147 | }; | ||||
| 7148 | |||||
| 7149 | uint32_t begin = pos().begin; | ||||
| 7150 | |||||
| 7151 | if (pc_->template findInnermostStatement<ParseContext::LabelStatement>( | ||||
| 7152 | hasSameLabel)) { | ||||
| 7153 | errorAt(begin, JSMSG_DUPLICATE_LABEL); | ||||
| 7154 | return errorResult(); | ||||
| 7155 | } | ||||
| 7156 | |||||
| 7157 | tokenStream.consumeKnownToken(TokenKind::Colon); | ||||
| 7158 | |||||
| 7159 | /* Push a label struct and parse the statement. */ | ||||
| 7160 | ParseContext::LabelStatement stmt(pc_, label); | ||||
| 7161 | Node pn = MOZ_TRY(labeledItem(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (labeledItem(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7162 | |||||
| 7163 | return handler_.newLabeledStatement(label, pn, begin); | ||||
| 7164 | } | ||||
| 7165 | |||||
| 7166 | template <class ParseHandler, typename Unit> | ||||
| 7167 | typename ParseHandler::UnaryNodeResult | ||||
| 7168 | GeneralParser<ParseHandler, Unit>::throwStatement(YieldHandling yieldHandling) { | ||||
| 7169 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Throw))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Throw))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Throw)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Throw)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7169); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Throw)" ")"); do { MOZ_CrashSequence(__null, 7169); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 7170 | uint32_t begin = pos().begin; | ||||
| 7171 | |||||
| 7172 | /* ECMA-262 Edition 3 says 'throw [no LineTerminator here] Expr'. */ | ||||
| 7173 | TokenKind tt = TokenKind::Eof; | ||||
| 7174 | if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 7175 | return errorResult(); | ||||
| 7176 | } | ||||
| 7177 | if (tt == TokenKind::Eof || tt == TokenKind::Semi || | ||||
| 7178 | tt == TokenKind::RightCurly) { | ||||
| 7179 | error(JSMSG_MISSING_EXPR_AFTER_THROW); | ||||
| 7180 | return errorResult(); | ||||
| 7181 | } | ||||
| 7182 | if (tt == TokenKind::Eol) { | ||||
| 7183 | error(JSMSG_LINE_BREAK_AFTER_THROW); | ||||
| 7184 | return errorResult(); | ||||
| 7185 | } | ||||
| 7186 | |||||
| 7187 | Node throwExpr = MOZ_TRY(expr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7188 | |||||
| 7189 | if (!matchOrInsertSemicolon()) { | ||||
| 7190 | return errorResult(); | ||||
| 7191 | } | ||||
| 7192 | |||||
| 7193 | return handler_.newThrowStatement(throwExpr, TokenPos(begin, pos().end)); | ||||
| 7194 | } | ||||
| 7195 | |||||
| 7196 | template <class ParseHandler, typename Unit> | ||||
| 7197 | typename ParseHandler::TernaryNodeResult | ||||
| 7198 | GeneralParser<ParseHandler, Unit>::tryStatement(YieldHandling yieldHandling) { | ||||
| 7199 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Try))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Try))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::Try)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Try)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7199); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Try)" ")"); do { MOZ_CrashSequence(__null, 7199); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 7200 | uint32_t begin = pos().begin; | ||||
| 7201 | |||||
| 7202 | /* | ||||
| 7203 | * try nodes are ternary. | ||||
| 7204 | * kid1 is the try statement | ||||
| 7205 | * kid2 is the catch node list or null | ||||
| 7206 | * kid3 is the finally statement | ||||
| 7207 | * | ||||
| 7208 | * catch nodes are binary. | ||||
| 7209 | * left is the catch-name/pattern or null | ||||
| 7210 | * right is the catch block | ||||
| 7211 | * | ||||
| 7212 | * catch lvalue nodes are either: | ||||
| 7213 | * a single identifier | ||||
| 7214 | * TokenKind::RightBracket for a destructuring left-hand side | ||||
| 7215 | * TokenKind::RightCurly for a destructuring left-hand side | ||||
| 7216 | * | ||||
| 7217 | * finally nodes are TokenKind::LeftCurly statement lists. | ||||
| 7218 | */ | ||||
| 7219 | |||||
| 7220 | Node innerBlock; | ||||
| 7221 | { | ||||
| 7222 | if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_TRY)) { | ||||
| 7223 | return errorResult(); | ||||
| 7224 | } | ||||
| 7225 | |||||
| 7226 | uint32_t openedPos = pos().begin; | ||||
| 7227 | |||||
| 7228 | ParseContext::Statement stmt(pc_, StatementKind::Try); | ||||
| 7229 | ParseContext::Scope scope(this); | ||||
| 7230 | if (!scope.init(pc_)) { | ||||
| 7231 | return errorResult(); | ||||
| 7232 | } | ||||
| 7233 | |||||
| 7234 | innerBlock = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7235 | |||||
| 7236 | innerBlock = MOZ_TRY(finishLexicalScope(scope, innerBlock))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope(scope, innerBlock)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7237 | |||||
| 7238 | if (!mustMatchToken( | ||||
| 7239 | TokenKind::RightCurly, [this, openedPos](TokenKind actual) { | ||||
| 7240 | this->reportMissingClosing(JSMSG_CURLY_AFTER_TRY, | ||||
| 7241 | JSMSG_CURLY_OPENED, openedPos); | ||||
| 7242 | })) { | ||||
| 7243 | return errorResult(); | ||||
| 7244 | } | ||||
| 7245 | } | ||||
| 7246 | |||||
| 7247 | LexicalScopeNodeType catchScope = null(); | ||||
| 7248 | TokenKind tt; | ||||
| 7249 | if (!tokenStream.getToken(&tt)) { | ||||
| 7250 | return errorResult(); | ||||
| 7251 | } | ||||
| 7252 | if (tt == TokenKind::Catch) { | ||||
| 7253 | /* | ||||
| 7254 | * Create a lexical scope node around the whole catch clause, | ||||
| 7255 | * including the head. | ||||
| 7256 | */ | ||||
| 7257 | ParseContext::Statement stmt(pc_, StatementKind::Catch); | ||||
| 7258 | ParseContext::Scope scope(this); | ||||
| 7259 | if (!scope.init(pc_)) { | ||||
| 7260 | return errorResult(); | ||||
| 7261 | } | ||||
| 7262 | |||||
| 7263 | /* | ||||
| 7264 | * Legal catch forms are: | ||||
| 7265 | * catch (lhs) { | ||||
| 7266 | * catch { | ||||
| 7267 | * where lhs is a name or a destructuring left-hand side. | ||||
| 7268 | */ | ||||
| 7269 | bool omittedBinding; | ||||
| 7270 | if (!tokenStream.matchToken(&omittedBinding, TokenKind::LeftCurly)) { | ||||
| 7271 | return errorResult(); | ||||
| 7272 | } | ||||
| 7273 | |||||
| 7274 | Node catchName; | ||||
| 7275 | if (omittedBinding) { | ||||
| 7276 | catchName = null(); | ||||
| 7277 | } else { | ||||
| 7278 | if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_CATCH)) { | ||||
| 7279 | return errorResult(); | ||||
| 7280 | } | ||||
| 7281 | |||||
| 7282 | if (!tokenStream.getToken(&tt)) { | ||||
| 7283 | return errorResult(); | ||||
| 7284 | } | ||||
| 7285 | switch (tt) { | ||||
| 7286 | case TokenKind::LeftBracket: | ||||
| 7287 | case TokenKind::LeftCurly: | ||||
| 7288 | catchName = MOZ_TRY(destructuringDeclaration(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (destructuringDeclaration( DeclarationKind::CatchParameter, yieldHandling , tt)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 7289 | DeclarationKind::CatchParameter, yieldHandling, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (destructuringDeclaration( DeclarationKind::CatchParameter, yieldHandling , tt)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 7290 | break; | ||||
| 7291 | |||||
| 7292 | default: { | ||||
| 7293 | if (!TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 7294 | error(JSMSG_CATCH_IDENTIFIER); | ||||
| 7295 | return errorResult(); | ||||
| 7296 | } | ||||
| 7297 | |||||
| 7298 | catchName = MOZ_TRY(bindingIdentifier(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifier( DeclarationKind::SimpleCatchParameter, yieldHandling )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 7299 | DeclarationKind::SimpleCatchParameter, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (bindingIdentifier( DeclarationKind::SimpleCatchParameter, yieldHandling )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 7300 | break; | ||||
| 7301 | } | ||||
| 7302 | } | ||||
| 7303 | |||||
| 7304 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_CATCH)) { | ||||
| 7305 | return errorResult(); | ||||
| 7306 | } | ||||
| 7307 | |||||
| 7308 | if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_CATCH)) { | ||||
| 7309 | return errorResult(); | ||||
| 7310 | } | ||||
| 7311 | } | ||||
| 7312 | |||||
| 7313 | LexicalScopeNodeType catchBody = | ||||
| 7314 | MOZ_TRY(catchBlockStatement(yieldHandling, scope))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (catchBlockStatement(yieldHandling, scope)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7315 | |||||
| 7316 | catchScope = MOZ_TRY(finishLexicalScope(scope, catchBody))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope(scope, catchBody)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7317 | |||||
| 7318 | if (!handler_.setupCatchScope(catchScope, catchName, catchBody)) { | ||||
| 7319 | return errorResult(); | ||||
| 7320 | } | ||||
| 7321 | handler_.setEndPosition(catchScope, pos().end); | ||||
| 7322 | |||||
| 7323 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 7324 | return errorResult(); | ||||
| 7325 | } | ||||
| 7326 | } | ||||
| 7327 | |||||
| 7328 | Node finallyBlock = null(); | ||||
| 7329 | |||||
| 7330 | if (tt == TokenKind::Finally) { | ||||
| 7331 | if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_FINALLY)) { | ||||
| 7332 | return errorResult(); | ||||
| 7333 | } | ||||
| 7334 | |||||
| 7335 | uint32_t openedPos = pos().begin; | ||||
| 7336 | |||||
| 7337 | ParseContext::Statement stmt(pc_, StatementKind::Finally); | ||||
| 7338 | ParseContext::Scope scope(this); | ||||
| 7339 | if (!scope.init(pc_)) { | ||||
| 7340 | return errorResult(); | ||||
| 7341 | } | ||||
| 7342 | |||||
| 7343 | finallyBlock = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7344 | |||||
| 7345 | finallyBlock = MOZ_TRY(finishLexicalScope(scope, finallyBlock))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope(scope, finallyBlock)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7346 | |||||
| 7347 | if (!mustMatchToken( | ||||
| 7348 | TokenKind::RightCurly, [this, openedPos](TokenKind actual) { | ||||
| 7349 | this->reportMissingClosing(JSMSG_CURLY_AFTER_FINALLY, | ||||
| 7350 | JSMSG_CURLY_OPENED, openedPos); | ||||
| 7351 | })) { | ||||
| 7352 | return errorResult(); | ||||
| 7353 | } | ||||
| 7354 | } else { | ||||
| 7355 | anyChars.ungetToken(); | ||||
| 7356 | } | ||||
| 7357 | if (!catchScope && !finallyBlock) { | ||||
| 7358 | error(JSMSG_CATCH_OR_FINALLY); | ||||
| 7359 | return errorResult(); | ||||
| 7360 | } | ||||
| 7361 | |||||
| 7362 | return handler_.newTryStatement(begin, innerBlock, catchScope, finallyBlock); | ||||
| 7363 | } | ||||
| 7364 | |||||
| 7365 | template <class ParseHandler, typename Unit> | ||||
| 7366 | typename ParseHandler::LexicalScopeNodeResult | ||||
| 7367 | GeneralParser<ParseHandler, Unit>::catchBlockStatement( | ||||
| 7368 | YieldHandling yieldHandling, ParseContext::Scope& catchParamScope) { | ||||
| 7369 | uint32_t openedPos = pos().begin; | ||||
| 7370 | |||||
| 7371 | ParseContext::Statement stmt(pc_, StatementKind::Block); | ||||
| 7372 | |||||
| 7373 | // ES 13.15.7 CatchClauseEvaluation | ||||
| 7374 | // | ||||
| 7375 | // Step 8 means that the body of a catch block always has an additional | ||||
| 7376 | // lexical scope. | ||||
| 7377 | ParseContext::Scope scope(this); | ||||
| 7378 | if (!scope.init(pc_)) { | ||||
| 7379 | return errorResult(); | ||||
| 7380 | } | ||||
| 7381 | |||||
| 7382 | // The catch parameter names cannot be redeclared inside the catch | ||||
| 7383 | // block, so declare the name in the inner scope. | ||||
| 7384 | if (!scope.addCatchParameters(pc_, catchParamScope)) { | ||||
| 7385 | return errorResult(); | ||||
| 7386 | } | ||||
| 7387 | |||||
| 7388 | ListNodeType list = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7389 | |||||
| 7390 | if (!mustMatchToken( | ||||
| 7391 | TokenKind::RightCurly, [this, openedPos](TokenKind actual) { | ||||
| 7392 | this->reportMissingClosing(JSMSG_CURLY_AFTER_CATCH, | ||||
| 7393 | JSMSG_CURLY_OPENED, openedPos); | ||||
| 7394 | })) { | ||||
| 7395 | return errorResult(); | ||||
| 7396 | } | ||||
| 7397 | |||||
| 7398 | // The catch parameter names are not bound in the body scope, so remove | ||||
| 7399 | // them before generating bindings. | ||||
| 7400 | scope.removeCatchParameters(pc_, catchParamScope); | ||||
| 7401 | return finishLexicalScope(scope, list); | ||||
| 7402 | } | ||||
| 7403 | |||||
| 7404 | template <class ParseHandler, typename Unit> | ||||
| 7405 | typename ParseHandler::DebuggerStatementResult | ||||
| 7406 | GeneralParser<ParseHandler, Unit>::debuggerStatement() { | ||||
| 7407 | TokenPos p; | ||||
| 7408 | p.begin = pos().begin; | ||||
| 7409 | if (!matchOrInsertSemicolon()) { | ||||
| 7410 | return errorResult(); | ||||
| 7411 | } | ||||
| 7412 | p.end = pos().end; | ||||
| 7413 | |||||
| 7414 | return handler_.newDebuggerStatement(p); | ||||
| 7415 | } | ||||
| 7416 | |||||
| 7417 | static AccessorType ToAccessorType(PropertyType propType) { | ||||
| 7418 | switch (propType) { | ||||
| 7419 | case PropertyType::Getter: | ||||
| 7420 | return AccessorType::Getter; | ||||
| 7421 | case PropertyType::Setter: | ||||
| 7422 | return AccessorType::Setter; | ||||
| 7423 | case PropertyType::Normal: | ||||
| 7424 | case PropertyType::Method: | ||||
| 7425 | case PropertyType::GeneratorMethod: | ||||
| 7426 | case PropertyType::AsyncMethod: | ||||
| 7427 | case PropertyType::AsyncGeneratorMethod: | ||||
| 7428 | case PropertyType::Constructor: | ||||
| 7429 | case PropertyType::DerivedConstructor: | ||||
| 7430 | return AccessorType::None; | ||||
| 7431 | default: | ||||
| 7432 | MOZ_CRASH("unexpected property type")do { do { } while (false); MOZ_ReportCrash("" "unexpected property type" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7432); AnnotateMozCrashReason ("MOZ_CRASH(" "unexpected property type" ")"); do { MOZ_CrashSequence (__null, 7432); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 7433 | } | ||||
| 7434 | } | ||||
| 7435 | |||||
| 7436 | #ifdef ENABLE_DECORATORS | ||||
| 7437 | template <class ParseHandler, typename Unit> | ||||
| 7438 | typename ParseHandler::ListNodeResult | ||||
| 7439 | GeneralParser<ParseHandler, Unit>::decoratorList(YieldHandling yieldHandling) { | ||||
| 7440 | ListNodeType decorators = | ||||
| 7441 | MOZ_TRY(handler_.newList(ParseNodeKind::DecoratorList, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newList(ParseNodeKind::DecoratorList, pos())); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 7442 | |||||
| 7443 | // Build a decorator list element. At each entry point to this loop we have | ||||
| 7444 | // already consumed the |@| token | ||||
| 7445 | TokenKind tt; | ||||
| 7446 | for (;;) { | ||||
| 7447 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsInvalid)) { | ||||
| 7448 | return errorResult(); | ||||
| 7449 | } | ||||
| 7450 | |||||
| 7451 | Node decorator = MOZ_TRY(decoratorExpr(yieldHandling, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (decoratorExpr(yieldHandling, tt)); if ((__builtin_expect(!!( mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7452 | |||||
| 7453 | handler_.addList(decorators, decorator); | ||||
| 7454 | |||||
| 7455 | if (!tokenStream.getToken(&tt)) { | ||||
| 7456 | return errorResult(); | ||||
| 7457 | } | ||||
| 7458 | if (tt != TokenKind::At) { | ||||
| 7459 | anyChars.ungetToken(); | ||||
| 7460 | break; | ||||
| 7461 | } | ||||
| 7462 | } | ||||
| 7463 | return decorators; | ||||
| 7464 | } | ||||
| 7465 | #endif | ||||
| 7466 | |||||
| 7467 | template <class ParseHandler, typename Unit> | ||||
| 7468 | bool GeneralParser<ParseHandler, Unit>::classMember( | ||||
| 7469 | YieldHandling yieldHandling, const ParseContext::ClassStatement& classStmt, | ||||
| 7470 | TaggedParserAtomIndex className, uint32_t classStartOffset, | ||||
| 7471 | HasHeritage hasHeritage, ClassInitializedMembers& classInitializedMembers, | ||||
| 7472 | ListNodeType& classMembers, bool* done) { | ||||
| 7473 | *done = false; | ||||
| 7474 | |||||
| 7475 | TokenKind tt; | ||||
| 7476 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsInvalid)) { | ||||
| 7477 | return false; | ||||
| 7478 | } | ||||
| 7479 | if (tt == TokenKind::RightCurly) { | ||||
| 7480 | *done = true; | ||||
| 7481 | return true; | ||||
| 7482 | } | ||||
| 7483 | |||||
| 7484 | if (tt == TokenKind::Semi) { | ||||
| 7485 | return true; | ||||
| 7486 | } | ||||
| 7487 | |||||
| 7488 | #ifdef ENABLE_DECORATORS | ||||
| 7489 | ListNodeType decorators = null(); | ||||
| 7490 | if (tt == TokenKind::At) { | ||||
| 7491 | if (fuzzingSafe) { | ||||
| 7492 | error(JSMSG_DECORATOR_FUZZING_UNSAFE); | ||||
| 7493 | return false; | ||||
| 7494 | } | ||||
| 7495 | |||||
| 7496 | MOZ_TRY_VAR_OR_RETURN(decorators, decoratorList(yieldHandling), false)do { auto parserTryVarTempResult_ = (decoratorList(yieldHandling )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (decorators) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7497 | |||||
| 7498 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsInvalid)) { | ||||
| 7499 | return false; | ||||
| 7500 | } | ||||
| 7501 | } | ||||
| 7502 | #endif | ||||
| 7503 | |||||
| 7504 | bool isStatic = false; | ||||
| 7505 | if (tt == TokenKind::Static) { | ||||
| 7506 | if (!tokenStream.peekToken(&tt)) { | ||||
| 7507 | return false; | ||||
| 7508 | } | ||||
| 7509 | |||||
| 7510 | if (tt == TokenKind::LeftCurly) { | ||||
| 7511 | /* Parsing static class block: static { ... } */ | ||||
| 7512 | FunctionNodeType staticBlockBody; | ||||
| 7513 | MOZ_TRY_VAR_OR_RETURN(staticBlockBody,do { auto parserTryVarTempResult_ = (staticClassBlock(classInitializedMembers )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (staticBlockBody) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7514 | staticClassBlock(classInitializedMembers), false)do { auto parserTryVarTempResult_ = (staticClassBlock(classInitializedMembers )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (staticBlockBody) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7515 | |||||
| 7516 | StaticClassBlockType classBlock; | ||||
| 7517 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newStaticClassBlock (staticBlockBody)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (classBlock) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7518 | classBlock, handler_.newStaticClassBlock(staticBlockBody), false)do { auto parserTryVarTempResult_ = (handler_.newStaticClassBlock (staticBlockBody)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (classBlock) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7519 | |||||
| 7520 | return handler_.addClassMemberDefinition(classMembers, classBlock); | ||||
| 7521 | } | ||||
| 7522 | |||||
| 7523 | if (tt != TokenKind::LeftParen && tt != TokenKind::Assign && | ||||
| 7524 | tt != TokenKind::Semi && tt != TokenKind::RightCurly) { | ||||
| 7525 | isStatic = true; | ||||
| 7526 | } else { | ||||
| 7527 | anyChars.ungetToken(); | ||||
| 7528 | } | ||||
| 7529 | } else { | ||||
| 7530 | anyChars.ungetToken(); | ||||
| 7531 | } | ||||
| 7532 | |||||
| 7533 | uint32_t propNameOffset; | ||||
| 7534 | if (!tokenStream.peekOffset(&propNameOffset, TokenStream::SlashIsInvalid)) { | ||||
| 7535 | return false; | ||||
| 7536 | } | ||||
| 7537 | |||||
| 7538 | TaggedParserAtomIndex propAtom; | ||||
| 7539 | PropertyType propType; | ||||
| 7540 | Node propName; | ||||
| 7541 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling , PropertyNameInClass, Nothing(), classMembers, &propType , &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7542 | propName,do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling , PropertyNameInClass, Nothing(), classMembers, &propType , &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7543 | propertyOrMethodName(yieldHandling, PropertyNameInClass,do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling , PropertyNameInClass, Nothing(), classMembers, &propType , &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7544 | /* maybeDecl = */ Nothing(), classMembers, &propType,do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling , PropertyNameInClass, Nothing(), classMembers, &propType , &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7545 | &propAtom),do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling , PropertyNameInClass, Nothing(), classMembers, &propType , &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7546 | false)do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling , PropertyNameInClass, Nothing(), classMembers, &propType , &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7547 | |||||
| 7548 | #ifdef ENABLE_DECORATORS | ||||
| 7549 | if (!propAtom && | ||||
| 7550 | (decorators || propType == PropertyType::FieldWithAccessor)) { | ||||
| 7551 | error(JSMSG_DECORATOR_COMPUTED_NYI); | ||||
| 7552 | return false; | ||||
| 7553 | } | ||||
| 7554 | #endif | ||||
| 7555 | |||||
| 7556 | if (propType == PropertyType::Field || | ||||
| 7557 | propType == PropertyType::FieldWithAccessor) { | ||||
| 7558 | if (isStatic) { | ||||
| 7559 | if (propAtom == TaggedParserAtomIndex::WellKnown::prototype()) { | ||||
| 7560 | errorAt(propNameOffset, JSMSG_CLASS_STATIC_PROTO); | ||||
| 7561 | return false; | ||||
| 7562 | } | ||||
| 7563 | } | ||||
| 7564 | |||||
| 7565 | if (propAtom == TaggedParserAtomIndex::WellKnown::constructor()) { | ||||
| 7566 | errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF); | ||||
| 7567 | return false; | ||||
| 7568 | } | ||||
| 7569 | |||||
| 7570 | if (handler_.isPrivateName(propName)) { | ||||
| 7571 | if (propAtom == TaggedParserAtomIndex::WellKnown::hash_constructor_()) { | ||||
| 7572 | errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF); | ||||
| 7573 | return false; | ||||
| 7574 | } | ||||
| 7575 | |||||
| 7576 | auto privateName = propAtom; | ||||
| 7577 | if (!noteDeclaredPrivateName( | ||||
| 7578 | propName, privateName, propType, | ||||
| 7579 | isStatic ? FieldPlacement::Static : FieldPlacement::Instance, | ||||
| 7580 | pos())) { | ||||
| 7581 | return false; | ||||
| 7582 | } | ||||
| 7583 | } | ||||
| 7584 | |||||
| 7585 | #ifdef ENABLE_DECORATORS | ||||
| 7586 | ClassMethodType accessorGetterNode = null(); | ||||
| 7587 | ClassMethodType accessorSetterNode = null(); | ||||
| 7588 | if (propType == PropertyType::FieldWithAccessor) { | ||||
| 7589 | // Decorators Proposal | ||||
| 7590 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-runtime-semantics-classfielddefinitionevaluation | ||||
| 7591 | // | ||||
| 7592 | // FieldDefinition : accessor ClassElementName Initializeropt | ||||
| 7593 | // | ||||
| 7594 | // Step 1. Let name be the result of evaluating ClassElementName. | ||||
| 7595 | // ... | ||||
| 7596 | // Step 3. Let privateStateDesc be the string-concatenation of name | ||||
| 7597 | // and " accessor storage". | ||||
| 7598 | StringBuilder privateStateDesc(fc_); | ||||
| 7599 | if (!privateStateDesc.append(this->parserAtoms(), propAtom)) { | ||||
| 7600 | return false; | ||||
| 7601 | } | ||||
| 7602 | if (!privateStateDesc.append(" accessor storage")) { | ||||
| 7603 | return false; | ||||
| 7604 | } | ||||
| 7605 | // Step 4. Let privateStateName be a new Private Name whose | ||||
| 7606 | // [[Description]] value is privateStateDesc. | ||||
| 7607 | TokenPos propNamePos(propNameOffset, pos().end); | ||||
| 7608 | auto privateStateName = | ||||
| 7609 | privateStateDesc.finishParserAtom(this->parserAtoms(), fc_); | ||||
| 7610 | if (!noteDeclaredPrivateName( | ||||
| 7611 | propName, privateStateName, propType, | ||||
| 7612 | isStatic ? FieldPlacement::Static : FieldPlacement::Instance, | ||||
| 7613 | propNamePos)) { | ||||
| 7614 | return false; | ||||
| 7615 | } | ||||
| 7616 | |||||
| 7617 | // Step 5. Let getter be MakeAutoAccessorGetter(homeObject, name, | ||||
| 7618 | // privateStateName). | ||||
| 7619 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Getter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorGetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7620 | accessorGetterNode,do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Getter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorGetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7621 | synthesizeAccessor(propName, propNamePos, propAtom, privateStateName,do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Getter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorGetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7622 | isStatic, FunctionSyntaxKind::Getter,do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Getter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorGetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7623 | classInitializedMembers),do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Getter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorGetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7624 | false)do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Getter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorGetterNode) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 7625 | |||||
| 7626 | // If the accessor is not decorated or is a non-static private field, | ||||
| 7627 | // add it to the class here. Otherwise, we'll handle this when the | ||||
| 7628 | // decorators are called. We don't need to keep a reference to the node | ||||
| 7629 | // after this except for non-static private accessors. Please see the | ||||
| 7630 | // comment in the definition of ClassField for details. | ||||
| 7631 | bool addAccessorImmediately = | ||||
| 7632 | !decorators || (!isStatic && handler_.isPrivateName(propName)); | ||||
| 7633 | if (addAccessorImmediately) { | ||||
| 7634 | if (!handler_.addClassMemberDefinition(classMembers, | ||||
| 7635 | accessorGetterNode)) { | ||||
| 7636 | return false; | ||||
| 7637 | } | ||||
| 7638 | if (!handler_.isPrivateName(propName)) { | ||||
| 7639 | accessorGetterNode = null(); | ||||
| 7640 | } | ||||
| 7641 | } | ||||
| 7642 | |||||
| 7643 | // Step 6. Let setter be MakeAutoAccessorSetter(homeObject, name, | ||||
| 7644 | // privateStateName). | ||||
| 7645 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Setter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorSetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7646 | accessorSetterNode,do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Setter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorSetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7647 | synthesizeAccessor(propName, propNamePos, propAtom, privateStateName,do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Setter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorSetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7648 | isStatic, FunctionSyntaxKind::Setter,do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Setter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorSetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7649 | classInitializedMembers),do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Setter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorSetterNode) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7650 | false)do { auto parserTryVarTempResult_ = (synthesizeAccessor(propName , propNamePos, propAtom, privateStateName, isStatic, FunctionSyntaxKind ::Setter, classInitializedMembers)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( accessorSetterNode) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 7651 | |||||
| 7652 | if (addAccessorImmediately) { | ||||
| 7653 | if (!handler_.addClassMemberDefinition(classMembers, | ||||
| 7654 | accessorSetterNode)) { | ||||
| 7655 | return false; | ||||
| 7656 | } | ||||
| 7657 | if (!handler_.isPrivateName(propName)) { | ||||
| 7658 | accessorSetterNode = null(); | ||||
| 7659 | } | ||||
| 7660 | } | ||||
| 7661 | |||||
| 7662 | // Step 10. Return ClassElementDefinition Record { [[Key]]: name, | ||||
| 7663 | // [[Kind]]: accessor, [[Get]]: getter, [[Set]]: setter, | ||||
| 7664 | // [[BackingStorageKey]]: privateStateName, [[Initializers]]: | ||||
| 7665 | // initializers, [[Decorators]]: empty }. | ||||
| 7666 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newPrivateName( privateStateName, pos())); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7667 | propName, handler_.newPrivateName(privateStateName, pos()), false)do { auto parserTryVarTempResult_ = (handler_.newPrivateName( privateStateName, pos())); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7668 | propAtom = privateStateName; | ||||
| 7669 | // We maintain `decorators` here to perform this step at the same time: | ||||
| 7670 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-static-semantics-classelementevaluation | ||||
| 7671 | // 4. Set fieldDefinition.[[Decorators]] to decorators. | ||||
| 7672 | } | ||||
| 7673 | #endif | ||||
| 7674 | if (isStatic) { | ||||
| 7675 | classInitializedMembers.staticFields++; | ||||
| 7676 | } else { | ||||
| 7677 | classInitializedMembers.instanceFields++; | ||||
| 7678 | #ifdef ENABLE_DECORATORS | ||||
| 7679 | if (decorators) { | ||||
| 7680 | classInitializedMembers.hasInstanceDecorators = true; | ||||
| 7681 | } | ||||
| 7682 | #endif | ||||
| 7683 | } | ||||
| 7684 | |||||
| 7685 | TokenPos propNamePos(propNameOffset, pos().end); | ||||
| 7686 | FunctionNodeType initializer; | ||||
| 7687 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (fieldInitializerOpt(propNamePos , propName, propAtom, classInitializedMembers, isStatic, hasHeritage )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (initializer) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7688 | initializer,do { auto parserTryVarTempResult_ = (fieldInitializerOpt(propNamePos , propName, propAtom, classInitializedMembers, isStatic, hasHeritage )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (initializer) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7689 | fieldInitializerOpt(propNamePos, propName, propAtom,do { auto parserTryVarTempResult_ = (fieldInitializerOpt(propNamePos , propName, propAtom, classInitializedMembers, isStatic, hasHeritage )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (initializer) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7690 | classInitializedMembers, isStatic, hasHeritage),do { auto parserTryVarTempResult_ = (fieldInitializerOpt(propNamePos , propName, propAtom, classInitializedMembers, isStatic, hasHeritage )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (initializer) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7691 | false)do { auto parserTryVarTempResult_ = (fieldInitializerOpt(propNamePos , propName, propAtom, classInitializedMembers, isStatic, hasHeritage )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (initializer) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7692 | |||||
| 7693 | if (!matchOrInsertSemicolon(TokenStream::SlashIsInvalid)) { | ||||
| 7694 | return false; | ||||
| 7695 | } | ||||
| 7696 | |||||
| 7697 | ClassFieldType field; | ||||
| 7698 | MOZ_TRY_VAR_OR_RETURN(field,do { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7699 | handler_.newClassFieldDefinition(do { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7700 | propName, initializer, isStaticdo { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7701 | #ifdef ENABLE_DECORATORSdo { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7702 | ,do { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7703 | decorators, accessorGetterNode, accessorSetterNodedo { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7704 | #endifdo { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7705 | ),do { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7706 | false)do { auto parserTryVarTempResult_ = (handler_.newClassFieldDefinition ( propName, initializer, isStatic ifdef ENABLE_DECORATORS , decorators , accessorGetterNode, accessorSetterNode endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (field) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 7707 | |||||
| 7708 | return handler_.addClassMemberDefinition(classMembers, field); | ||||
| 7709 | } | ||||
| 7710 | |||||
| 7711 | if (propType != PropertyType::Getter && propType != PropertyType::Setter && | ||||
| 7712 | propType != PropertyType::Method && | ||||
| 7713 | propType != PropertyType::GeneratorMethod && | ||||
| 7714 | propType != PropertyType::AsyncMethod && | ||||
| 7715 | propType != PropertyType::AsyncGeneratorMethod) { | ||||
| 7716 | errorAt(propNameOffset, JSMSG_BAD_CLASS_MEMBER_DEF); | ||||
| 7717 | return false; | ||||
| 7718 | } | ||||
| 7719 | |||||
| 7720 | bool isConstructor = | ||||
| 7721 | !isStatic && propAtom == TaggedParserAtomIndex::WellKnown::constructor(); | ||||
| 7722 | if (isConstructor) { | ||||
| 7723 | if (propType != PropertyType::Method) { | ||||
| 7724 | errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF); | ||||
| 7725 | return false; | ||||
| 7726 | } | ||||
| 7727 | if (classStmt.constructorBox) { | ||||
| 7728 | errorAt(propNameOffset, JSMSG_DUPLICATE_CONSTRUCTOR); | ||||
| 7729 | return false; | ||||
| 7730 | } | ||||
| 7731 | propType = hasHeritage == HasHeritage::Yes | ||||
| 7732 | ? PropertyType::DerivedConstructor | ||||
| 7733 | : PropertyType::Constructor; | ||||
| 7734 | } else if (isStatic && | ||||
| 7735 | propAtom == TaggedParserAtomIndex::WellKnown::prototype()) { | ||||
| 7736 | errorAt(propNameOffset, JSMSG_CLASS_STATIC_PROTO); | ||||
| 7737 | return false; | ||||
| 7738 | } | ||||
| 7739 | |||||
| 7740 | TaggedParserAtomIndex funName; | ||||
| 7741 | switch (propType) { | ||||
| 7742 | case PropertyType::Getter: | ||||
| 7743 | case PropertyType::Setter: { | ||||
| 7744 | bool hasStaticName = | ||||
| 7745 | !anyChars.isCurrentTokenType(TokenKind::RightBracket) && propAtom; | ||||
| 7746 | if (hasStaticName) { | ||||
| 7747 | funName = prefixAccessorName(propType, propAtom); | ||||
| 7748 | if (!funName) { | ||||
| 7749 | return false; | ||||
| 7750 | } | ||||
| 7751 | } | ||||
| 7752 | break; | ||||
| 7753 | } | ||||
| 7754 | case PropertyType::Constructor: | ||||
| 7755 | case PropertyType::DerivedConstructor: | ||||
| 7756 | funName = className; | ||||
| 7757 | break; | ||||
| 7758 | default: | ||||
| 7759 | if (!anyChars.isCurrentTokenType(TokenKind::RightBracket)) { | ||||
| 7760 | funName = propAtom; | ||||
| 7761 | } | ||||
| 7762 | } | ||||
| 7763 | |||||
| 7764 | // When |super()| is invoked, we search for the nearest scope containing | ||||
| 7765 | // |.initializers| to initialize the class fields. This set-up precludes | ||||
| 7766 | // declaring |.initializers| in the class scope, because in some syntactic | ||||
| 7767 | // contexts |super()| can appear nested in a class, while actually belonging | ||||
| 7768 | // to an outer class definition. | ||||
| 7769 | // | ||||
| 7770 | // Example: | ||||
| 7771 | // class Outer extends Base { | ||||
| 7772 | // field = 1; | ||||
| 7773 | // constructor() { | ||||
| 7774 | // class Inner { | ||||
| 7775 | // field = 2; | ||||
| 7776 | // | ||||
| 7777 | // // The super() call in the computed property name mustn't access | ||||
| 7778 | // // Inner's |.initializers| array, but instead Outer's. | ||||
| 7779 | // [super()]() {} | ||||
| 7780 | // } | ||||
| 7781 | // } | ||||
| 7782 | // } | ||||
| 7783 | Maybe<ParseContext::Scope> dotInitializersScope; | ||||
| 7784 | if (isConstructor && !options().selfHostingMode) { | ||||
| 7785 | dotInitializersScope.emplace(this); | ||||
| 7786 | if (!dotInitializersScope->init(pc_)) { | ||||
| 7787 | return false; | ||||
| 7788 | } | ||||
| 7789 | |||||
| 7790 | if (!noteDeclaredName(TaggedParserAtomIndex::WellKnown::dot_initializers_(), | ||||
| 7791 | DeclarationKind::Let, pos())) { | ||||
| 7792 | return false; | ||||
| 7793 | } | ||||
| 7794 | |||||
| 7795 | #ifdef ENABLE_DECORATORS | ||||
| 7796 | if (!noteDeclaredName( | ||||
| 7797 | TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_(), | ||||
| 7798 | DeclarationKind::Let, pos())) { | ||||
| 7799 | return false; | ||||
| 7800 | } | ||||
| 7801 | #endif | ||||
| 7802 | } | ||||
| 7803 | |||||
| 7804 | // Calling toString on constructors need to return the source text for | ||||
| 7805 | // the entire class. The end offset is unknown at this point in | ||||
| 7806 | // parsing and will be amended when class parsing finishes below. | ||||
| 7807 | FunctionNodeType funNode; | ||||
| 7808 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor ? classStartOffset : propNameOffset, propType, funName)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (funNode) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 7809 | funNode,do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor ? classStartOffset : propNameOffset, propType, funName)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (funNode) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 7810 | methodDefinition(isConstructor ? classStartOffset : propNameOffset,do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor ? classStartOffset : propNameOffset, propType, funName)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (funNode) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 7811 | propType, funName),do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor ? classStartOffset : propNameOffset, propType, funName)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (funNode) = parserTryVarTempResult_.unwrap (); } while (0) | ||||
| 7812 | false)do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor ? classStartOffset : propNameOffset, propType, funName)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (funNode) = parserTryVarTempResult_.unwrap (); } while (0); | ||||
| 7813 | |||||
| 7814 | AccessorType atype = ToAccessorType(propType); | ||||
| 7815 | |||||
| 7816 | Maybe<FunctionNodeType> initializerIfPrivate = Nothing(); | ||||
| 7817 | if (handler_.isPrivateName(propName)) { | ||||
| 7818 | if (propAtom == TaggedParserAtomIndex::WellKnown::hash_constructor_()) { | ||||
| 7819 | // #constructor is an invalid private name. | ||||
| 7820 | errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF); | ||||
| 7821 | return false; | ||||
| 7822 | } | ||||
| 7823 | |||||
| 7824 | TaggedParserAtomIndex privateName = propAtom; | ||||
| 7825 | if (!noteDeclaredPrivateName( | ||||
| 7826 | propName, privateName, propType, | ||||
| 7827 | isStatic ? FieldPlacement::Static : FieldPlacement::Instance, | ||||
| 7828 | pos())) { | ||||
| 7829 | return false; | ||||
| 7830 | } | ||||
| 7831 | |||||
| 7832 | // Private non-static methods are stored in the class body environment. | ||||
| 7833 | // Private non-static accessors are stamped onto every instance using | ||||
| 7834 | // initializers. Private static methods are stamped onto the constructor | ||||
| 7835 | // during class evaluation; see BytecodeEmitter::emitPropertyList. | ||||
| 7836 | if (!isStatic) { | ||||
| 7837 | if (atype == AccessorType::Getter || atype == AccessorType::Setter) { | ||||
| 7838 | classInitializedMembers.privateAccessors++; | ||||
| 7839 | TokenPos propNamePos(propNameOffset, pos().end); | ||||
| 7840 | FunctionNodeType initializerNode; | ||||
| 7841 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (synthesizePrivateMethodInitializer (propAtom, atype, propNamePos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (initializerNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7842 | initializerNode,do { auto parserTryVarTempResult_ = (synthesizePrivateMethodInitializer (propAtom, atype, propNamePos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (initializerNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7843 | synthesizePrivateMethodInitializer(propAtom, atype, propNamePos),do { auto parserTryVarTempResult_ = (synthesizePrivateMethodInitializer (propAtom, atype, propNamePos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (initializerNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7844 | false)do { auto parserTryVarTempResult_ = (synthesizePrivateMethodInitializer (propAtom, atype, propNamePos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (initializerNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7845 | initializerIfPrivate = Some(initializerNode); | ||||
| 7846 | } else { | ||||
| 7847 | MOZ_ASSERT(atype == AccessorType::None)do { static_assert( mozilla::detail::AssertionConditionType< decltype(atype == AccessorType::None)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(atype == AccessorType::None) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("atype == AccessorType::None" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7847); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "atype == AccessorType::None" ")"); do { MOZ_CrashSequence (__null, 7847); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 7848 | classInitializedMembers.privateMethods++; | ||||
| 7849 | } | ||||
| 7850 | } | ||||
| 7851 | } | ||||
| 7852 | |||||
| 7853 | #ifdef ENABLE_DECORATORS | ||||
| 7854 | if (decorators) { | ||||
| 7855 | classInitializedMembers.hasInstanceDecorators = true; | ||||
| 7856 | } | ||||
| 7857 | #endif | ||||
| 7858 | |||||
| 7859 | Node method; | ||||
| 7860 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7861 | method,do { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7862 | handler_.newClassMethodDefinition(propName, funNode, atype, isStatic,do { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7863 | initializerIfPrivatedo { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7864 | #ifdef ENABLE_DECORATORSdo { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7865 | ,do { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7866 | decoratorsdo { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7867 | #endifdo { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7868 | ),do { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7869 | false)do { auto parserTryVarTempResult_ = (handler_.newClassMethodDefinition (propName, funNode, atype, isStatic, initializerIfPrivate ifdef ENABLE_DECORATORS , decorators endif )); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 7870 | |||||
| 7871 | if (dotInitializersScope.isSome()) { | ||||
| 7872 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (finishLexicalScope(*dotInitializersScope , method)); if ((__builtin_expect(!!(parserTryVarTempResult_. isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7873 | method, finishLexicalScope(*dotInitializersScope, method), false)do { auto parserTryVarTempResult_ = (finishLexicalScope(*dotInitializersScope , method)); if ((__builtin_expect(!!(parserTryVarTempResult_. isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7874 | dotInitializersScope.reset(); | ||||
| 7875 | } | ||||
| 7876 | |||||
| 7877 | return handler_.addClassMemberDefinition(classMembers, method); | ||||
| 7878 | } | ||||
| 7879 | |||||
| 7880 | template <class ParseHandler, typename Unit> | ||||
| 7881 | bool GeneralParser<ParseHandler, Unit>::finishClassConstructor( | ||||
| 7882 | const ParseContext::ClassStatement& classStmt, | ||||
| 7883 | TaggedParserAtomIndex className, HasHeritage hasHeritage, | ||||
| 7884 | uint32_t classStartOffset, uint32_t classEndOffset, | ||||
| 7885 | const ClassInitializedMembers& classInitializedMembers, | ||||
| 7886 | ListNodeType& classMembers) { | ||||
| 7887 | if (classStmt.constructorBox == nullptr) { | ||||
| 7888 | MOZ_ASSERT(!options().selfHostingMode)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!options().selfHostingMode)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!options().selfHostingMode)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!options().selfHostingMode" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7888); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!options().selfHostingMode" ")"); do { MOZ_CrashSequence (__null, 7888); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 7889 | // Unconditionally create the scope here, because it's always the | ||||
| 7890 | // constructor. | ||||
| 7891 | ParseContext::Scope dotInitializersScope(this); | ||||
| 7892 | if (!dotInitializersScope.init(pc_)) { | ||||
| 7893 | return false; | ||||
| 7894 | } | ||||
| 7895 | |||||
| 7896 | if (!noteDeclaredName(TaggedParserAtomIndex::WellKnown::dot_initializers_(), | ||||
| 7897 | DeclarationKind::Let, pos())) { | ||||
| 7898 | return false; | ||||
| 7899 | } | ||||
| 7900 | |||||
| 7901 | #ifdef ENABLE_DECORATORS | ||||
| 7902 | if (!noteDeclaredName( | ||||
| 7903 | TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_(), | ||||
| 7904 | DeclarationKind::Let, pos(), ClosedOver::Yes)) { | ||||
| 7905 | return false; | ||||
| 7906 | } | ||||
| 7907 | #endif | ||||
| 7908 | |||||
| 7909 | // synthesizeConstructor assigns to classStmt.constructorBox | ||||
| 7910 | TokenPos synthesizedBodyPos(classStartOffset, classEndOffset); | ||||
| 7911 | FunctionNodeType synthesizedCtor; | ||||
| 7912 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (synthesizeConstructor(className , synthesizedBodyPos, hasHeritage)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( synthesizedCtor) = parserTryVarTempResult_.unwrap(); } while ( 0) | ||||
| 7913 | synthesizedCtor,do { auto parserTryVarTempResult_ = (synthesizeConstructor(className , synthesizedBodyPos, hasHeritage)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( synthesizedCtor) = parserTryVarTempResult_.unwrap(); } while ( 0) | ||||
| 7914 | synthesizeConstructor(className, synthesizedBodyPos, hasHeritage),do { auto parserTryVarTempResult_ = (synthesizeConstructor(className , synthesizedBodyPos, hasHeritage)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( synthesizedCtor) = parserTryVarTempResult_.unwrap(); } while ( 0) | ||||
| 7915 | false)do { auto parserTryVarTempResult_ = (synthesizeConstructor(className , synthesizedBodyPos, hasHeritage)); if ((__builtin_expect(!! (parserTryVarTempResult_.isErr()), 0))) { return (false); } ( synthesizedCtor) = parserTryVarTempResult_.unwrap(); } while ( 0); | ||||
| 7916 | |||||
| 7917 | // Note: the *function* has the name of the class, but the *property* | ||||
| 7918 | // containing the function has the name "constructor" | ||||
| 7919 | Node constructorNameNode; | ||||
| 7920 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName ( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (constructorNameNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7921 | constructorNameNode,do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName ( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (constructorNameNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7922 | handler_.newObjectLiteralPropertyName(do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName ( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (constructorNameNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7923 | TaggedParserAtomIndex::WellKnown::constructor(), pos()),do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName ( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (constructorNameNode) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7924 | false)do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName ( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (constructorNameNode) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7925 | ClassMethodType method; | ||||
| 7926 | MOZ_TRY_VAR_OR_RETURN(method,do { auto parserTryVarTempResult_ = (handler_.newDefaultClassConstructor ( constructorNameNode, synthesizedCtor)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7927 | handler_.newDefaultClassConstructor(do { auto parserTryVarTempResult_ = (handler_.newDefaultClassConstructor ( constructorNameNode, synthesizedCtor)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7928 | constructorNameNode, synthesizedCtor),do { auto parserTryVarTempResult_ = (handler_.newDefaultClassConstructor ( constructorNameNode, synthesizedCtor)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 7929 | false)do { auto parserTryVarTempResult_ = (handler_.newDefaultClassConstructor ( constructorNameNode, synthesizedCtor)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 7930 | LexicalScopeNodeType scope; | ||||
| 7931 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (finishLexicalScope(dotInitializersScope , method)); if ((__builtin_expect(!!(parserTryVarTempResult_. isErr()), 0))) { return (false); } (scope) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 7932 | scope, finishLexicalScope(dotInitializersScope, method), false)do { auto parserTryVarTempResult_ = (finishLexicalScope(dotInitializersScope , method)); if ((__builtin_expect(!!(parserTryVarTempResult_. isErr()), 0))) { return (false); } (scope) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 7933 | if (!handler_.addClassMemberDefinition(classMembers, scope)) { | ||||
| 7934 | return false; | ||||
| 7935 | } | ||||
| 7936 | } | ||||
| 7937 | |||||
| 7938 | MOZ_ASSERT(classStmt.constructorBox)do { static_assert( mozilla::detail::AssertionConditionType< decltype(classStmt.constructorBox)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(classStmt.constructorBox))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("classStmt.constructorBox" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7938); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "classStmt.constructorBox" ")"); do { MOZ_CrashSequence (__null, 7938); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 7939 | FunctionBox* ctorbox = classStmt.constructorBox; | ||||
| 7940 | |||||
| 7941 | // Amend the toStringEnd offset for the constructor now that we've | ||||
| 7942 | // finished parsing the class. | ||||
| 7943 | ctorbox->setCtorToStringEnd(classEndOffset); | ||||
| 7944 | |||||
| 7945 | size_t numMemberInitializers = classInitializedMembers.privateAccessors + | ||||
| 7946 | classInitializedMembers.instanceFields; | ||||
| 7947 | bool hasPrivateBrand = classInitializedMembers.hasPrivateBrand(); | ||||
| 7948 | if (hasPrivateBrand || numMemberInitializers > 0) { | ||||
| 7949 | // Now that we have full set of initializers, update the constructor. | ||||
| 7950 | MemberInitializers initializers( | ||||
| 7951 | hasPrivateBrand, | ||||
| 7952 | #ifdef ENABLE_DECORATORS | ||||
| 7953 | classInitializedMembers.hasInstanceDecorators, | ||||
| 7954 | #endif | ||||
| 7955 | numMemberInitializers); | ||||
| 7956 | ctorbox->setMemberInitializers(initializers); | ||||
| 7957 | |||||
| 7958 | // Field initialization need access to `this`. | ||||
| 7959 | ctorbox->setCtorFunctionHasThisBinding(); | ||||
| 7960 | } | ||||
| 7961 | |||||
| 7962 | return true; | ||||
| 7963 | } | ||||
| 7964 | |||||
| 7965 | template <class ParseHandler, typename Unit> | ||||
| 7966 | typename ParseHandler::ClassNodeResult | ||||
| 7967 | GeneralParser<ParseHandler, Unit>::classDefinition( | ||||
| 7968 | YieldHandling yieldHandling, ClassContext classContext, | ||||
| 7969 | DefaultHandling defaultHandling) { | ||||
| 7970 | #ifdef ENABLE_DECORATORS | ||||
| 7971 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::At) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::At) || anyChars .isCurrentTokenType(TokenKind::Class))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7972); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class)" ")"); do { MOZ_CrashSequence(__null, 7972); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 7972 | anyChars.isCurrentTokenType(TokenKind::Class))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::At) || anyChars .isCurrentTokenType(TokenKind::Class))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7972); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class)" ")"); do { MOZ_CrashSequence(__null, 7972); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 7973 | |||||
| 7974 | ListNodeType decorators = null(); | ||||
| 7975 | FunctionNodeType addInitializerFunction = null(); | ||||
| 7976 | if (anyChars.isCurrentTokenType(TokenKind::At)) { | ||||
| 7977 | if (fuzzingSafe) { | ||||
| 7978 | error(JSMSG_DECORATOR_FUZZING_UNSAFE); | ||||
| 7979 | return errorResult(); | ||||
| 7980 | } | ||||
| 7981 | |||||
| 7982 | decorators = MOZ_TRY(decoratorList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (decoratorList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 7983 | TokenKind next; | ||||
| 7984 | if (!tokenStream.getToken(&next)) { | ||||
| 7985 | return errorResult(); | ||||
| 7986 | } | ||||
| 7987 | if (next != TokenKind::Class) { | ||||
| 7988 | error(JSMSG_CLASS_EXPECTED); | ||||
| 7989 | return errorResult(); | ||||
| 7990 | } | ||||
| 7991 | } | ||||
| 7992 | #else | ||||
| 7993 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Class))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Class))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Class)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Class)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 7993); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Class)" ")"); do { MOZ_CrashSequence(__null, 7993); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 7994 | #endif | ||||
| 7995 | |||||
| 7996 | uint32_t classStartOffset = pos().begin; | ||||
| 7997 | bool savedStrictness = setLocalStrictMode(true); | ||||
| 7998 | |||||
| 7999 | // Classes are quite broken in self-hosted code. | ||||
| 8000 | if (options().selfHostingMode) { | ||||
| 8001 | error(JSMSG_SELFHOSTED_CLASS); | ||||
| 8002 | return errorResult(); | ||||
| 8003 | } | ||||
| 8004 | |||||
| 8005 | TokenKind tt; | ||||
| 8006 | if (!tokenStream.getToken(&tt)) { | ||||
| 8007 | return errorResult(); | ||||
| 8008 | } | ||||
| 8009 | |||||
| 8010 | TaggedParserAtomIndex className; | ||||
| 8011 | if (TokenKindIsPossibleIdentifier(tt)) { | ||||
| 8012 | className = bindingIdentifier(yieldHandling); | ||||
| 8013 | if (!className) { | ||||
| 8014 | return errorResult(); | ||||
| 8015 | } | ||||
| 8016 | } else if (classContext == ClassStatement) { | ||||
| 8017 | if (defaultHandling == AllowDefaultName) { | ||||
| 8018 | className = TaggedParserAtomIndex::WellKnown::default_(); | ||||
| 8019 | anyChars.ungetToken(); | ||||
| 8020 | } else { | ||||
| 8021 | // Class statements must have a bound name | ||||
| 8022 | error(JSMSG_UNNAMED_CLASS_STMT); | ||||
| 8023 | return errorResult(); | ||||
| 8024 | } | ||||
| 8025 | } else { | ||||
| 8026 | // Make sure to put it back, whatever it was | ||||
| 8027 | anyChars.ungetToken(); | ||||
| 8028 | } | ||||
| 8029 | |||||
| 8030 | // Because the binding definitions keep track of their blockId, we need to | ||||
| 8031 | // create at least the inner binding later. Keep track of the name's | ||||
| 8032 | // position in order to provide it for the nodes created later. | ||||
| 8033 | TokenPos namePos = pos(); | ||||
| 8034 | |||||
| 8035 | auto isClass = [](ParseContext::Statement* stmt) { | ||||
| 8036 | return stmt->kind() == StatementKind::Class; | ||||
| 8037 | }; | ||||
| 8038 | |||||
| 8039 | bool isInClass = pc_->sc()->inClass() || pc_->findInnermostStatement(isClass); | ||||
| 8040 | |||||
| 8041 | // Push a ParseContext::ClassStatement to keep track of the constructor | ||||
| 8042 | // funbox. | ||||
| 8043 | ParseContext::ClassStatement classStmt(pc_); | ||||
| 8044 | |||||
| 8045 | NameNodeType innerName; | ||||
| 8046 | Node nameNode = null(); | ||||
| 8047 | Node classHeritage = null(); | ||||
| 8048 | LexicalScopeNodeType classBlock = null(); | ||||
| 8049 | ClassBodyScopeNodeType classBodyBlock = null(); | ||||
| 8050 | uint32_t classEndOffset; | ||||
| 8051 | { | ||||
| 8052 | // A named class creates a new lexical scope with a const binding of the | ||||
| 8053 | // class name for the "inner name". | ||||
| 8054 | ParseContext::Statement innerScopeStmt(pc_, StatementKind::Block); | ||||
| 8055 | ParseContext::Scope innerScope(this); | ||||
| 8056 | if (!innerScope.init(pc_)) { | ||||
| 8057 | return errorResult(); | ||||
| 8058 | } | ||||
| 8059 | |||||
| 8060 | bool hasHeritageBool; | ||||
| 8061 | if (!tokenStream.matchToken(&hasHeritageBool, TokenKind::Extends)) { | ||||
| 8062 | return errorResult(); | ||||
| 8063 | } | ||||
| 8064 | HasHeritage hasHeritage = | ||||
| 8065 | hasHeritageBool ? HasHeritage::Yes : HasHeritage::No; | ||||
| 8066 | if (hasHeritage == HasHeritage::Yes) { | ||||
| 8067 | if (!tokenStream.getToken(&tt)) { | ||||
| 8068 | return errorResult(); | ||||
| 8069 | } | ||||
| 8070 | classHeritage = | ||||
| 8071 | MOZ_TRY(optionalExpr(yieldHandling, TripledotProhibited, tt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (optionalExpr(yieldHandling, TripledotProhibited, tt)); if (( __builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 8072 | } | ||||
| 8073 | |||||
| 8074 | if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_CLASS)) { | ||||
| 8075 | return errorResult(); | ||||
| 8076 | } | ||||
| 8077 | |||||
| 8078 | { | ||||
| 8079 | ParseContext::Statement bodyScopeStmt(pc_, StatementKind::Block); | ||||
| 8080 | ParseContext::Scope bodyScope(this); | ||||
| 8081 | if (!bodyScope.init(pc_)) { | ||||
| 8082 | return errorResult(); | ||||
| 8083 | } | ||||
| 8084 | |||||
| 8085 | ListNodeType classMembers = | ||||
| 8086 | MOZ_TRY(handler_.newClassMemberList(pos().begin))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newClassMemberList(pos().begin)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8087 | |||||
| 8088 | ClassInitializedMembers classInitializedMembers{}; | ||||
| 8089 | for (;;) { | ||||
| 8090 | bool done; | ||||
| 8091 | if (!classMember(yieldHandling, classStmt, className, classStartOffset, | ||||
| 8092 | hasHeritage, classInitializedMembers, classMembers, | ||||
| 8093 | &done)) { | ||||
| 8094 | return errorResult(); | ||||
| 8095 | } | ||||
| 8096 | if (done) { | ||||
| 8097 | break; | ||||
| 8098 | } | ||||
| 8099 | } | ||||
| 8100 | #ifdef ENABLE_DECORATORS | ||||
| 8101 | if (classInitializedMembers.hasInstanceDecorators) { | ||||
| 8102 | addInitializerFunction = MOZ_TRY(synthesizeAddInitializerFunction(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (synthesizeAddInitializerFunction( TaggedParserAtomIndex::WellKnown ::dot_instanceExtraInitializers_(), yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8103 | TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_(),__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (synthesizeAddInitializerFunction( TaggedParserAtomIndex::WellKnown ::dot_instanceExtraInitializers_(), yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8104 | yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (synthesizeAddInitializerFunction( TaggedParserAtomIndex::WellKnown ::dot_instanceExtraInitializers_(), yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8105 | } | ||||
| 8106 | #endif | ||||
| 8107 | |||||
| 8108 | if (classInitializedMembers.privateMethods + | ||||
| 8109 | classInitializedMembers.privateAccessors > | ||||
| 8110 | 0) { | ||||
| 8111 | // We declare `.privateBrand` as ClosedOver because the constructor | ||||
| 8112 | // always uses it, even a default constructor. We could equivalently | ||||
| 8113 | // `noteUsedName` when parsing the constructor, except that at that | ||||
| 8114 | // time, we don't necessarily know if the class has a private brand. | ||||
| 8115 | if (!noteDeclaredName( | ||||
| 8116 | TaggedParserAtomIndex::WellKnown::dot_privateBrand_(), | ||||
| 8117 | DeclarationKind::Synthetic, namePos, ClosedOver::Yes)) { | ||||
| 8118 | return errorResult(); | ||||
| 8119 | } | ||||
| 8120 | } | ||||
| 8121 | |||||
| 8122 | if (classInitializedMembers.instanceFieldKeys > 0) { | ||||
| 8123 | if (!noteDeclaredName( | ||||
| 8124 | TaggedParserAtomIndex::WellKnown::dot_fieldKeys_(), | ||||
| 8125 | DeclarationKind::Synthetic, namePos)) { | ||||
| 8126 | return errorResult(); | ||||
| 8127 | } | ||||
| 8128 | } | ||||
| 8129 | |||||
| 8130 | if (classInitializedMembers.staticFields > 0) { | ||||
| 8131 | if (!noteDeclaredName( | ||||
| 8132 | TaggedParserAtomIndex::WellKnown::dot_staticInitializers_(), | ||||
| 8133 | DeclarationKind::Synthetic, namePos)) { | ||||
| 8134 | return errorResult(); | ||||
| 8135 | } | ||||
| 8136 | } | ||||
| 8137 | |||||
| 8138 | if (classInitializedMembers.staticFieldKeys > 0) { | ||||
| 8139 | if (!noteDeclaredName( | ||||
| 8140 | TaggedParserAtomIndex::WellKnown::dot_staticFieldKeys_(), | ||||
| 8141 | DeclarationKind::Synthetic, namePos)) { | ||||
| 8142 | return errorResult(); | ||||
| 8143 | } | ||||
| 8144 | } | ||||
| 8145 | |||||
| 8146 | classEndOffset = pos().end; | ||||
| 8147 | if (!finishClassConstructor(classStmt, className, hasHeritage, | ||||
| 8148 | classStartOffset, classEndOffset, | ||||
| 8149 | classInitializedMembers, classMembers)) { | ||||
| 8150 | return errorResult(); | ||||
| 8151 | } | ||||
| 8152 | |||||
| 8153 | classBodyBlock = MOZ_TRY(finishClassBodyScope(bodyScope, classMembers))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishClassBodyScope(bodyScope, classMembers)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8154 | |||||
| 8155 | // Pop the class body scope | ||||
| 8156 | } | ||||
| 8157 | |||||
| 8158 | if (className) { | ||||
| 8159 | // The inner name is immutable. | ||||
| 8160 | if (!noteDeclaredName(className, DeclarationKind::Const, namePos)) { | ||||
| 8161 | return errorResult(); | ||||
| 8162 | } | ||||
| 8163 | |||||
| 8164 | innerName = MOZ_TRY(newName(className, namePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(className, namePos)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8165 | } | ||||
| 8166 | |||||
| 8167 | classBlock = MOZ_TRY(finishLexicalScope(innerScope, classBodyBlock))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope(innerScope, classBodyBlock)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8168 | |||||
| 8169 | // Pop the inner scope. | ||||
| 8170 | } | ||||
| 8171 | |||||
| 8172 | if (className) { | ||||
| 8173 | NameNodeType outerName = null(); | ||||
| 8174 | if (classContext == ClassStatement) { | ||||
| 8175 | // The outer name is mutable. | ||||
| 8176 | if (!noteDeclaredName(className, DeclarationKind::Class, namePos)) { | ||||
| 8177 | return errorResult(); | ||||
| 8178 | } | ||||
| 8179 | |||||
| 8180 | outerName = MOZ_TRY(newName(className, namePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(className, namePos)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8181 | } | ||||
| 8182 | |||||
| 8183 | nameNode = MOZ_TRY(handler_.newClassNames(outerName, innerName, namePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newClassNames(outerName, innerName, namePos)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 8184 | } | ||||
| 8185 | MOZ_ALWAYS_TRUE(setLocalStrictMode(savedStrictness))do { if ((__builtin_expect(!!(setLocalStrictMode(savedStrictness )), 1))) { } else { do { do { } while (false); MOZ_ReportCrash ("" "setLocalStrictMode(savedStrictness)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 8185); AnnotateMozCrashReason("MOZ_CRASH(" "setLocalStrictMode(savedStrictness)" ")"); do { MOZ_CrashSequence(__null, 8185); __attribute__((nomerge )) ::abort(); } while (false); } while (false); } } while (false ); | ||||
| 8186 | // We're leaving a class definition that was not itself nested within a class | ||||
| 8187 | if (!isInClass) { | ||||
| 8188 | mozilla::Maybe<UnboundPrivateName> maybeUnboundName; | ||||
| 8189 | if (!usedNames_.hasUnboundPrivateNames(fc_, maybeUnboundName)) { | ||||
| 8190 | return errorResult(); | ||||
| 8191 | } | ||||
| 8192 | if (maybeUnboundName) { | ||||
| 8193 | UniqueChars str = | ||||
| 8194 | this->parserAtoms().toPrintableString(maybeUnboundName->atom); | ||||
| 8195 | if (!str) { | ||||
| 8196 | ReportOutOfMemory(this->fc_); | ||||
| 8197 | return errorResult(); | ||||
| 8198 | } | ||||
| 8199 | |||||
| 8200 | errorAt(maybeUnboundName->position.begin, JSMSG_MISSING_PRIVATE_DECL, | ||||
| 8201 | str.get()); | ||||
| 8202 | return errorResult(); | ||||
| 8203 | } | ||||
| 8204 | } | ||||
| 8205 | |||||
| 8206 | return handler_.newClass(nameNode, classHeritage, classBlock, | ||||
| 8207 | #ifdef ENABLE_DECORATORS | ||||
| 8208 | decorators, addInitializerFunction, | ||||
| 8209 | #endif | ||||
| 8210 | TokenPos(classStartOffset, classEndOffset)); | ||||
| 8211 | } | ||||
| 8212 | |||||
| 8213 | template <class ParseHandler, typename Unit> | ||||
| 8214 | typename ParseHandler::FunctionNodeResult | ||||
| 8215 | GeneralParser<ParseHandler, Unit>::synthesizeConstructor( | ||||
| 8216 | TaggedParserAtomIndex className, TokenPos synthesizedBodyPos, | ||||
| 8217 | HasHeritage hasHeritage) { | ||||
| 8218 | FunctionSyntaxKind functionSyntaxKind = | ||||
| 8219 | hasHeritage == HasHeritage::Yes | ||||
| 8220 | ? FunctionSyntaxKind::DerivedClassConstructor | ||||
| 8221 | : FunctionSyntaxKind::ClassConstructor; | ||||
| 8222 | |||||
| 8223 | bool isSelfHosting = options().selfHostingMode; | ||||
| 8224 | FunctionFlags flags = | ||||
| 8225 | InitialFunctionFlags(functionSyntaxKind, GeneratorKind::NotGenerator, | ||||
| 8226 | FunctionAsyncKind::SyncFunction, isSelfHosting); | ||||
| 8227 | |||||
| 8228 | // Create the top-level field initializer node. | ||||
| 8229 | FunctionNodeType funNode = | ||||
| 8230 | MOZ_TRY(handler_.newFunction(functionSyntaxKind, synthesizedBodyPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(functionSyntaxKind, synthesizedBodyPos) ); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)) ) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8231 | |||||
| 8232 | // If we see any inner function, note it on our current context. The bytecode | ||||
| 8233 | // emitter may eliminate the function later, but we use a conservative | ||||
| 8234 | // definition for consistency between lazy and full parsing. | ||||
| 8235 | pc_->sc()->setHasInnerFunctions(); | ||||
| 8236 | |||||
| 8237 | // When fully parsing a lazy script, we do not fully reparse its inner | ||||
| 8238 | // functions, which are also lazy. Instead, their free variables and source | ||||
| 8239 | // extents are recorded and may be skipped. | ||||
| 8240 | if (handler_.reuseLazyInnerFunctions()) { | ||||
| 8241 | if (!skipLazyInnerFunction(funNode, synthesizedBodyPos.begin, | ||||
| 8242 | /* tryAnnexB = */ false)) { | ||||
| 8243 | return errorResult(); | ||||
| 8244 | } | ||||
| 8245 | |||||
| 8246 | return funNode; | ||||
| 8247 | } | ||||
| 8248 | |||||
| 8249 | // Create the FunctionBox and link it to the function object. | ||||
| 8250 | Directives directives(true); | ||||
| 8251 | FunctionBox* funbox = newFunctionBox( | ||||
| 8252 | funNode, className, flags, synthesizedBodyPos.begin, directives, | ||||
| 8253 | GeneratorKind::NotGenerator, FunctionAsyncKind::SyncFunction); | ||||
| 8254 | if (!funbox) { | ||||
| 8255 | return errorResult(); | ||||
| 8256 | } | ||||
| 8257 | funbox->initWithEnclosingParseContext(pc_, functionSyntaxKind); | ||||
| 8258 | setFunctionEndFromCurrentToken(funbox); | ||||
| 8259 | |||||
| 8260 | // Mark this function as being synthesized by the parser. This means special | ||||
| 8261 | // handling in delazification will be used since we don't have typical | ||||
| 8262 | // function syntax. | ||||
| 8263 | funbox->setSyntheticFunction(); | ||||
| 8264 | |||||
| 8265 | // Push a SourceParseContext on to the stack. | ||||
| 8266 | ParseContext* outerpc = pc_; | ||||
| 8267 | SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr); | ||||
| 8268 | if (!funpc.init()) { | ||||
| 8269 | return errorResult(); | ||||
| 8270 | } | ||||
| 8271 | |||||
| 8272 | if (!synthesizeConstructorBody(synthesizedBodyPos, hasHeritage, funNode, | ||||
| 8273 | funbox)) { | ||||
| 8274 | return errorResult(); | ||||
| 8275 | } | ||||
| 8276 | |||||
| 8277 | if (!leaveInnerFunction(outerpc)) { | ||||
| 8278 | return errorResult(); | ||||
| 8279 | } | ||||
| 8280 | |||||
| 8281 | return funNode; | ||||
| 8282 | } | ||||
| 8283 | |||||
| 8284 | template <class ParseHandler, typename Unit> | ||||
| 8285 | bool GeneralParser<ParseHandler, Unit>::synthesizeConstructorBody( | ||||
| 8286 | TokenPos synthesizedBodyPos, HasHeritage hasHeritage, | ||||
| 8287 | FunctionNodeType funNode, FunctionBox* funbox) { | ||||
| 8288 | MOZ_ASSERT(funbox->isClassConstructor())do { static_assert( mozilla::detail::AssertionConditionType< decltype(funbox->isClassConstructor())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(funbox->isClassConstructor ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("funbox->isClassConstructor()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 8288); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isClassConstructor()" ")"); do { MOZ_CrashSequence(__null, 8288); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8289 | |||||
| 8290 | // Create a ParamsBodyNode for the parameters + body (there are no | ||||
| 8291 | // parameters). | ||||
| 8292 | ParamsBodyNodeType argsbody; | ||||
| 8293 | MOZ_TRY_VAR_OR_RETURN(argsbody, handler_.newParamsBody(synthesizedBodyPos),do { auto parserTryVarTempResult_ = (handler_.newParamsBody(synthesizedBodyPos )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (argsbody) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8294 | false)do { auto parserTryVarTempResult_ = (handler_.newParamsBody(synthesizedBodyPos )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (argsbody) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 8295 | handler_.setFunctionFormalParametersAndBody(funNode, argsbody); | ||||
| 8296 | setFunctionStartAtPosition(funbox, synthesizedBodyPos); | ||||
| 8297 | |||||
| 8298 | if (hasHeritage == HasHeritage::Yes) { | ||||
| 8299 | // Synthesize the equivalent to `function f(...args)` | ||||
| 8300 | funbox->setHasRest(); | ||||
| 8301 | if (!notePositionalFormalParameter( | ||||
| 8302 | funNode, TaggedParserAtomIndex::WellKnown::dot_args_(), | ||||
| 8303 | synthesizedBodyPos.begin, | ||||
| 8304 | /* disallowDuplicateParams = */ false, | ||||
| 8305 | /* duplicatedParam = */ nullptr)) { | ||||
| 8306 | return false; | ||||
| 8307 | } | ||||
| 8308 | funbox->setArgCount(1); | ||||
| 8309 | } else { | ||||
| 8310 | funbox->setArgCount(0); | ||||
| 8311 | } | ||||
| 8312 | |||||
| 8313 | pc_->functionScope().useAsVarScope(pc_); | ||||
| 8314 | |||||
| 8315 | ListNodeType stmtList; | ||||
| 8316 | MOZ_TRY_VAR_OR_RETURN(stmtList, handler_.newStatementList(synthesizedBodyPos),do { auto parserTryVarTempResult_ = (handler_.newStatementList (synthesizedBodyPos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (stmtList) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8317 | false)do { auto parserTryVarTempResult_ = (handler_.newStatementList (synthesizedBodyPos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (stmtList) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 8318 | |||||
| 8319 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_this_())) { | ||||
| 8320 | return false; | ||||
| 8321 | } | ||||
| 8322 | |||||
| 8323 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_initializers_())) { | ||||
| 8324 | return false; | ||||
| 8325 | } | ||||
| 8326 | |||||
| 8327 | #ifdef ENABLE_DECORATORS | ||||
| 8328 | if (!noteUsedName( | ||||
| 8329 | TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_())) { | ||||
| 8330 | return false; | ||||
| 8331 | } | ||||
| 8332 | #endif | ||||
| 8333 | |||||
| 8334 | if (hasHeritage == HasHeritage::Yes) { | ||||
| 8335 | // |super()| implicitly reads |new.target|. | ||||
| 8336 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_newTarget_())) { | ||||
| 8337 | return false; | ||||
| 8338 | } | ||||
| 8339 | |||||
| 8340 | NameNodeType thisName; | ||||
| 8341 | MOZ_TRY_VAR_OR_RETURN(thisName, newThisName(), false)do { auto parserTryVarTempResult_ = (newThisName()); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (thisName) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 8342 | |||||
| 8343 | UnaryNodeType superBase; | ||||
| 8344 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newSuperBase(thisName , synthesizedBodyPos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (superBase) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8345 | superBase, handler_.newSuperBase(thisName, synthesizedBodyPos), false)do { auto parserTryVarTempResult_ = (handler_.newSuperBase(thisName , synthesizedBodyPos)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (superBase) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 8346 | |||||
| 8347 | ListNodeType arguments; | ||||
| 8348 | MOZ_TRY_VAR_OR_RETURN(arguments, handler_.newArguments(synthesizedBodyPos),do { auto parserTryVarTempResult_ = (handler_.newArguments(synthesizedBodyPos )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (arguments) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8349 | false)do { auto parserTryVarTempResult_ = (handler_.newArguments(synthesizedBodyPos )); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()) , 0))) { return (false); } (arguments) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 8350 | |||||
| 8351 | NameNodeType argsNameNode; | ||||
| 8352 | MOZ_TRY_VAR_OR_RETURN(argsNameNode,do { auto parserTryVarTempResult_ = (newName(TaggedParserAtomIndex ::WellKnown::dot_args_(), synthesizedBodyPos)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (argsNameNode) = parserTryVarTempResult_.unwrap(); } while ( 0) | ||||
| 8353 | newName(TaggedParserAtomIndex::WellKnown::dot_args_(),do { auto parserTryVarTempResult_ = (newName(TaggedParserAtomIndex ::WellKnown::dot_args_(), synthesizedBodyPos)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (argsNameNode) = parserTryVarTempResult_.unwrap(); } while ( 0) | ||||
| 8354 | synthesizedBodyPos),do { auto parserTryVarTempResult_ = (newName(TaggedParserAtomIndex ::WellKnown::dot_args_(), synthesizedBodyPos)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (argsNameNode) = parserTryVarTempResult_.unwrap(); } while ( 0) | ||||
| 8355 | false)do { auto parserTryVarTempResult_ = (newName(TaggedParserAtomIndex ::WellKnown::dot_args_(), synthesizedBodyPos)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (argsNameNode) = parserTryVarTempResult_.unwrap(); } while ( 0); | ||||
| 8356 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_args_())) { | ||||
| 8357 | return false; | ||||
| 8358 | } | ||||
| 8359 | |||||
| 8360 | UnaryNodeType spreadArgs; | ||||
| 8361 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newSpread(synthesizedBodyPos .begin, argsNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (spreadArgs) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8362 | spreadArgs, handler_.newSpread(synthesizedBodyPos.begin, argsNameNode),do { auto parserTryVarTempResult_ = (handler_.newSpread(synthesizedBodyPos .begin, argsNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (spreadArgs) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8363 | false)do { auto parserTryVarTempResult_ = (handler_.newSpread(synthesizedBodyPos .begin, argsNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (spreadArgs) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 8364 | handler_.addList(arguments, spreadArgs); | ||||
| 8365 | |||||
| 8366 | CallNodeType superCall; | ||||
| 8367 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newSuperCall(superBase , arguments, true)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (superCall) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8368 | superCall,do { auto parserTryVarTempResult_ = (handler_.newSuperCall(superBase , arguments, true)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (superCall) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8369 | handler_.newSuperCall(superBase, arguments, /* isSpread = */ true),do { auto parserTryVarTempResult_ = (handler_.newSuperCall(superBase , arguments, true)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (superCall) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8370 | false)do { auto parserTryVarTempResult_ = (handler_.newSuperCall(superBase , arguments, true)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (superCall) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 8371 | |||||
| 8372 | BinaryNodeType setThis; | ||||
| 8373 | MOZ_TRY_VAR_OR_RETURN(setThis, handler_.newSetThis(thisName, superCall),do { auto parserTryVarTempResult_ = (handler_.newSetThis(thisName , superCall)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (setThis) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 8374 | false)do { auto parserTryVarTempResult_ = (handler_.newSetThis(thisName , superCall)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (setThis) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 8375 | |||||
| 8376 | UnaryNodeType exprStatement; | ||||
| 8377 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newExprStatement (setThis, synthesizedBodyPos.end)); if ((__builtin_expect(!!( parserTryVarTempResult_.isErr()), 0))) { return (false); } (exprStatement ) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 8378 | exprStatement,do { auto parserTryVarTempResult_ = (handler_.newExprStatement (setThis, synthesizedBodyPos.end)); if ((__builtin_expect(!!( parserTryVarTempResult_.isErr()), 0))) { return (false); } (exprStatement ) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 8379 | handler_.newExprStatement(setThis, synthesizedBodyPos.end), false)do { auto parserTryVarTempResult_ = (handler_.newExprStatement (setThis, synthesizedBodyPos.end)); if ((__builtin_expect(!!( parserTryVarTempResult_.isErr()), 0))) { return (false); } (exprStatement ) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 8380 | |||||
| 8381 | handler_.addStatementToList(stmtList, exprStatement); | ||||
| 8382 | } | ||||
| 8383 | |||||
| 8384 | bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings(); | ||||
| 8385 | if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8386 | return false; | ||||
| 8387 | } | ||||
| 8388 | if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8389 | return false; | ||||
| 8390 | } | ||||
| 8391 | |||||
| 8392 | LexicalScopeNodeType initializerBody; | ||||
| 8393 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (finishLexicalScope(pc_-> varScope(), stmtList, ScopeKind::FunctionLexical)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (initializerBody) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 8394 | initializerBody,do { auto parserTryVarTempResult_ = (finishLexicalScope(pc_-> varScope(), stmtList, ScopeKind::FunctionLexical)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (initializerBody) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 8395 | finishLexicalScope(pc_->varScope(), stmtList, ScopeKind::FunctionLexical),do { auto parserTryVarTempResult_ = (finishLexicalScope(pc_-> varScope(), stmtList, ScopeKind::FunctionLexical)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (initializerBody) = parserTryVarTempResult_.unwrap(); } while (0) | ||||
| 8396 | false)do { auto parserTryVarTempResult_ = (finishLexicalScope(pc_-> varScope(), stmtList, ScopeKind::FunctionLexical)); if ((__builtin_expect (!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (initializerBody) = parserTryVarTempResult_.unwrap(); } while (0); | ||||
| 8397 | handler_.setBeginPosition(initializerBody, stmtList); | ||||
| 8398 | handler_.setEndPosition(initializerBody, stmtList); | ||||
| 8399 | |||||
| 8400 | handler_.setFunctionBody(funNode, initializerBody); | ||||
| 8401 | |||||
| 8402 | return finishFunction(); | ||||
| 8403 | } | ||||
| 8404 | |||||
| 8405 | template <class ParseHandler, typename Unit> | ||||
| 8406 | typename ParseHandler::FunctionNodeResult | ||||
| 8407 | GeneralParser<ParseHandler, Unit>::privateMethodInitializer( | ||||
| 8408 | TokenPos propNamePos, TaggedParserAtomIndex propAtom, | ||||
| 8409 | TaggedParserAtomIndex storedMethodAtom) { | ||||
| 8410 | if (!abortIfSyntaxParser()) { | ||||
| 8411 | return errorResult(); | ||||
| 8412 | } | ||||
| 8413 | |||||
| 8414 | // Synthesize an initializer function that the constructor can use to stamp a | ||||
| 8415 | // private method onto an instance object. | ||||
| 8416 | FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::FieldInitializer; | ||||
| 8417 | FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction; | ||||
| 8418 | GeneratorKind generatorKind = GeneratorKind::NotGenerator; | ||||
| 8419 | bool isSelfHosting = options().selfHostingMode; | ||||
| 8420 | FunctionFlags flags = | ||||
| 8421 | InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting); | ||||
| 8422 | |||||
| 8423 | FunctionNodeType funNode = | ||||
| 8424 | MOZ_TRY(handler_.newFunction(syntaxKind, propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8425 | |||||
| 8426 | Directives directives(true); | ||||
| 8427 | FunctionBox* funbox = | ||||
| 8428 | newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags, | ||||
| 8429 | propNamePos.begin, directives, generatorKind, asyncKind); | ||||
| 8430 | if (!funbox) { | ||||
| 8431 | return errorResult(); | ||||
| 8432 | } | ||||
| 8433 | funbox->initWithEnclosingParseContext(pc_, syntaxKind); | ||||
| 8434 | |||||
| 8435 | // Push a SourceParseContext on to the stack. | ||||
| 8436 | ParseContext* outerpc = pc_; | ||||
| 8437 | SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr); | ||||
| 8438 | if (!funpc.init()) { | ||||
| 8439 | return errorResult(); | ||||
| 8440 | } | ||||
| 8441 | pc_->functionScope().useAsVarScope(pc_); | ||||
| 8442 | |||||
| 8443 | // Add empty parameter list. | ||||
| 8444 | ParamsBodyNodeType argsbody = MOZ_TRY(handler_.newParamsBody(propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newParamsBody(propNamePos)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8445 | handler_.setFunctionFormalParametersAndBody(funNode, argsbody); | ||||
| 8446 | setFunctionStartAtCurrentToken(funbox); | ||||
| 8447 | funbox->setArgCount(0); | ||||
| 8448 | |||||
| 8449 | // Note both the stored private method body and it's private name as being | ||||
| 8450 | // used in the initializer. They will be emitted into the method body in the | ||||
| 8451 | // BCE. | ||||
| 8452 | if (!noteUsedName(storedMethodAtom)) { | ||||
| 8453 | return errorResult(); | ||||
| 8454 | } | ||||
| 8455 | MOZ_TRY(privateNameReference(propAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (privateNameReference(propAtom)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8456 | |||||
| 8457 | // Unlike field initializers, private method initializers are not created with | ||||
| 8458 | // a body of synthesized AST nodes. Instead, the body is left empty and the | ||||
| 8459 | // initializer is synthesized at the bytecode level. | ||||
| 8460 | // See BytecodeEmitter::emitPrivateMethodInitializer. | ||||
| 8461 | ListNodeType stmtList = MOZ_TRY(handler_.newStatementList(propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8462 | |||||
| 8463 | bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings(); | ||||
| 8464 | if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8465 | return errorResult(); | ||||
| 8466 | } | ||||
| 8467 | if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8468 | return errorResult(); | ||||
| 8469 | } | ||||
| 8470 | |||||
| 8471 | LexicalScopeNodeType initializerBody = MOZ_TRY(finishLexicalScope(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), stmtList, ScopeKind:: FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8472 | pc_->varScope(), stmtList, ScopeKind::FunctionLexical))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), stmtList, ScopeKind:: FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8473 | handler_.setBeginPosition(initializerBody, stmtList); | ||||
| 8474 | handler_.setEndPosition(initializerBody, stmtList); | ||||
| 8475 | handler_.setFunctionBody(funNode, initializerBody); | ||||
| 8476 | |||||
| 8477 | // Set field-initializer lambda boundary to start at property name and end | ||||
| 8478 | // after method body. | ||||
| 8479 | setFunctionStartAtPosition(funbox, propNamePos); | ||||
| 8480 | setFunctionEndFromCurrentToken(funbox); | ||||
| 8481 | |||||
| 8482 | if (!finishFunction()) { | ||||
| 8483 | return errorResult(); | ||||
| 8484 | } | ||||
| 8485 | |||||
| 8486 | if (!leaveInnerFunction(outerpc)) { | ||||
| 8487 | return errorResult(); | ||||
| 8488 | } | ||||
| 8489 | |||||
| 8490 | return funNode; | ||||
| 8491 | } | ||||
| 8492 | |||||
| 8493 | template <class ParseHandler, typename Unit> | ||||
| 8494 | typename ParseHandler::FunctionNodeResult | ||||
| 8495 | GeneralParser<ParseHandler, Unit>::staticClassBlock( | ||||
| 8496 | ClassInitializedMembers& classInitializedMembers) { | ||||
| 8497 | // Both for getting-this-done, and because this will invariably be executed, | ||||
| 8498 | // syntax parsing should be aborted. | ||||
| 8499 | if (!abortIfSyntaxParser()) { | ||||
| 8500 | return errorResult(); | ||||
| 8501 | } | ||||
| 8502 | |||||
| 8503 | FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::StaticClassBlock; | ||||
| 8504 | FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction; | ||||
| 8505 | GeneratorKind generatorKind = GeneratorKind::NotGenerator; | ||||
| 8506 | bool isSelfHosting = options().selfHostingMode; | ||||
| 8507 | FunctionFlags flags = | ||||
| 8508 | InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting); | ||||
| 8509 | |||||
| 8510 | AutoAwaitIsKeyword awaitIsKeyword(this, AwaitHandling::AwaitIsDisallowed); | ||||
| 8511 | |||||
| 8512 | // Create the function node for the static class body. | ||||
| 8513 | FunctionNodeType funNode = MOZ_TRY(handler_.newFunction(syntaxKind, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8514 | |||||
| 8515 | // Create the FunctionBox and link it to the function object. | ||||
| 8516 | Directives directives(true); | ||||
| 8517 | FunctionBox* funbox = | ||||
| 8518 | newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags, pos().begin, | ||||
| 8519 | directives, generatorKind, asyncKind); | ||||
| 8520 | if (!funbox) { | ||||
| 8521 | return errorResult(); | ||||
| 8522 | } | ||||
| 8523 | funbox->initWithEnclosingParseContext(pc_, syntaxKind); | ||||
| 8524 | MOZ_ASSERT(funbox->isSyntheticFunction())do { static_assert( mozilla::detail::AssertionConditionType< decltype(funbox->isSyntheticFunction())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(funbox->isSyntheticFunction ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("funbox->isSyntheticFunction()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 8524); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isSyntheticFunction()" ")"); do { MOZ_CrashSequence(__null, 8524); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8525 | MOZ_ASSERT(!funbox->allowSuperCall())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!funbox->allowSuperCall())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!funbox->allowSuperCall() ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "!funbox->allowSuperCall()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 8525); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!funbox->allowSuperCall()" ")"); do { MOZ_CrashSequence(__null, 8525); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8526 | MOZ_ASSERT(!funbox->allowArguments())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!funbox->allowArguments())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!funbox->allowArguments() ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "!funbox->allowArguments()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 8526); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!funbox->allowArguments()" ")"); do { MOZ_CrashSequence(__null, 8526); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8527 | MOZ_ASSERT(!funbox->allowReturn())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!funbox->allowReturn())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!funbox->allowReturn()))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("!funbox->allowReturn()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 8527); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!funbox->allowReturn()" ")"); do { MOZ_CrashSequence (__null, 8527); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 8528 | |||||
| 8529 | // Set start at `static` token. | ||||
| 8530 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Static))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Static))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Static)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Static)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 8530); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Static)" ")"); do { MOZ_CrashSequence(__null, 8530); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8531 | setFunctionStartAtCurrentToken(funbox); | ||||
| 8532 | |||||
| 8533 | // Push a SourceParseContext on to the stack. | ||||
| 8534 | ParseContext* outerpc = pc_; | ||||
| 8535 | SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr); | ||||
| 8536 | if (!funpc.init()) { | ||||
| 8537 | return errorResult(); | ||||
| 8538 | } | ||||
| 8539 | |||||
| 8540 | pc_->functionScope().useAsVarScope(pc_); | ||||
| 8541 | |||||
| 8542 | uint32_t start = pos().begin; | ||||
| 8543 | |||||
| 8544 | tokenStream.consumeKnownToken(TokenKind::LeftCurly); | ||||
| 8545 | |||||
| 8546 | // Static class blocks are code-generated as if they were static field | ||||
| 8547 | // initializers, so we bump the staticFields count here, which ensures | ||||
| 8548 | // .staticInitializers is noted as used. | ||||
| 8549 | classInitializedMembers.staticFields++; | ||||
| 8550 | |||||
| 8551 | LexicalScopeNodeType body = | ||||
| 8552 | MOZ_TRY(functionBody(InHandling::InAllowed, YieldHandling::YieldIsKeyword,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (functionBody(InHandling::InAllowed, YieldHandling::YieldIsKeyword , syntaxKind, FunctionBodyType::StatementListBody)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8553 | syntaxKind, FunctionBodyType::StatementListBody))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (functionBody(InHandling::InAllowed, YieldHandling::YieldIsKeyword , syntaxKind, FunctionBodyType::StatementListBody)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8554 | |||||
| 8555 | if (anyChars.isEOF()) { | ||||
| 8556 | error(JSMSG_UNTERMINATED_STATIC_CLASS_BLOCK); | ||||
| 8557 | return errorResult(); | ||||
| 8558 | } | ||||
| 8559 | |||||
| 8560 | tokenStream.consumeKnownToken(TokenKind::RightCurly, | ||||
| 8561 | TokenStream::Modifier::SlashIsRegExp); | ||||
| 8562 | |||||
| 8563 | TokenPos wholeBodyPos(start, pos().end); | ||||
| 8564 | |||||
| 8565 | handler_.setEndPosition(funNode, wholeBodyPos.end); | ||||
| 8566 | setFunctionEndFromCurrentToken(funbox); | ||||
| 8567 | |||||
| 8568 | // Create a ParamsBodyNode for the parameters + body (there are no | ||||
| 8569 | // parameters). | ||||
| 8570 | ParamsBodyNodeType argsbody = MOZ_TRY(handler_.newParamsBody(wholeBodyPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newParamsBody(wholeBodyPos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8571 | |||||
| 8572 | handler_.setFunctionFormalParametersAndBody(funNode, argsbody); | ||||
| 8573 | funbox->setArgCount(0); | ||||
| 8574 | |||||
| 8575 | if (pc_->superScopeNeedsHomeObject()) { | ||||
| 8576 | funbox->setNeedsHomeObject(); | ||||
| 8577 | } | ||||
| 8578 | |||||
| 8579 | handler_.setEndPosition(body, pos().begin); | ||||
| 8580 | handler_.setEndPosition(funNode, pos().end); | ||||
| 8581 | handler_.setFunctionBody(funNode, body); | ||||
| 8582 | |||||
| 8583 | if (!finishFunction()) { | ||||
| 8584 | return errorResult(); | ||||
| 8585 | } | ||||
| 8586 | |||||
| 8587 | if (!leaveInnerFunction(outerpc)) { | ||||
| 8588 | return errorResult(); | ||||
| 8589 | } | ||||
| 8590 | |||||
| 8591 | return funNode; | ||||
| 8592 | } | ||||
| 8593 | |||||
| 8594 | template <class ParseHandler, typename Unit> | ||||
| 8595 | typename ParseHandler::FunctionNodeResult | ||||
| 8596 | GeneralParser<ParseHandler, Unit>::fieldInitializerOpt( | ||||
| 8597 | TokenPos propNamePos, Node propName, TaggedParserAtomIndex propAtom, | ||||
| 8598 | ClassInitializedMembers& classInitializedMembers, bool isStatic, | ||||
| 8599 | HasHeritage hasHeritage) { | ||||
| 8600 | if (!abortIfSyntaxParser()) { | ||||
| 8601 | return errorResult(); | ||||
| 8602 | } | ||||
| 8603 | |||||
| 8604 | bool hasInitializer = false; | ||||
| 8605 | if (!tokenStream.matchToken(&hasInitializer, TokenKind::Assign, | ||||
| 8606 | TokenStream::SlashIsDiv)) { | ||||
| 8607 | return errorResult(); | ||||
| 8608 | } | ||||
| 8609 | |||||
| 8610 | FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::FieldInitializer; | ||||
| 8611 | FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction; | ||||
| 8612 | GeneratorKind generatorKind = GeneratorKind::NotGenerator; | ||||
| 8613 | bool isSelfHosting = options().selfHostingMode; | ||||
| 8614 | FunctionFlags flags = | ||||
| 8615 | InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting); | ||||
| 8616 | |||||
| 8617 | // Create the top-level field initializer node. | ||||
| 8618 | FunctionNodeType funNode = | ||||
| 8619 | MOZ_TRY(handler_.newFunction(syntaxKind, propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8620 | |||||
| 8621 | // Create the FunctionBox and link it to the function object. | ||||
| 8622 | Directives directives(true); | ||||
| 8623 | FunctionBox* funbox = | ||||
| 8624 | newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags, | ||||
| 8625 | propNamePos.begin, directives, generatorKind, asyncKind); | ||||
| 8626 | if (!funbox) { | ||||
| 8627 | return errorResult(); | ||||
| 8628 | } | ||||
| 8629 | funbox->initWithEnclosingParseContext(pc_, syntaxKind); | ||||
| 8630 | MOZ_ASSERT(funbox->isSyntheticFunction())do { static_assert( mozilla::detail::AssertionConditionType< decltype(funbox->isSyntheticFunction())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(funbox->isSyntheticFunction ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("funbox->isSyntheticFunction()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 8630); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isSyntheticFunction()" ")"); do { MOZ_CrashSequence(__null, 8630); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8631 | |||||
| 8632 | // We can't use setFunctionStartAtCurrentToken because that uses pos().begin, | ||||
| 8633 | // which is incorrect for fields without initializers (pos() points to the | ||||
| 8634 | // field identifier) | ||||
| 8635 | setFunctionStartAtPosition(funbox, propNamePos); | ||||
| 8636 | |||||
| 8637 | // Push a SourceParseContext on to the stack. | ||||
| 8638 | ParseContext* outerpc = pc_; | ||||
| 8639 | SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr); | ||||
| 8640 | if (!funpc.init()) { | ||||
| 8641 | return errorResult(); | ||||
| 8642 | } | ||||
| 8643 | |||||
| 8644 | pc_->functionScope().useAsVarScope(pc_); | ||||
| 8645 | |||||
| 8646 | Node initializerExpr; | ||||
| 8647 | if (hasInitializer) { | ||||
| 8648 | // Parse the expression for the field initializer. | ||||
| 8649 | { | ||||
| 8650 | AutoAwaitIsKeyword awaitHandling(this, AwaitIsName); | ||||
| 8651 | initializerExpr = | ||||
| 8652 | MOZ_TRY(assignExpr(InAllowed, YieldIsName, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, YieldIsName, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 8653 | } | ||||
| 8654 | |||||
| 8655 | handler_.checkAndSetIsDirectRHSAnonFunction(initializerExpr); | ||||
| 8656 | } else { | ||||
| 8657 | initializerExpr = MOZ_TRY(handler_.newRawUndefinedLiteral(propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newRawUndefinedLiteral(propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8658 | } | ||||
| 8659 | |||||
| 8660 | TokenPos wholeInitializerPos(propNamePos.begin, pos().end); | ||||
| 8661 | |||||
| 8662 | // Update the end position of the parse node. | ||||
| 8663 | handler_.setEndPosition(funNode, wholeInitializerPos.end); | ||||
| 8664 | setFunctionEndFromCurrentToken(funbox); | ||||
| 8665 | |||||
| 8666 | // Create a ParamsBodyNode for the parameters + body (there are no | ||||
| 8667 | // parameters). | ||||
| 8668 | ParamsBodyNodeType argsbody = | ||||
| 8669 | MOZ_TRY(handler_.newParamsBody(wholeInitializerPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newParamsBody(wholeInitializerPos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8670 | handler_.setFunctionFormalParametersAndBody(funNode, argsbody); | ||||
| 8671 | funbox->setArgCount(0); | ||||
| 8672 | |||||
| 8673 | NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8674 | |||||
| 8675 | // Build `this.field` expression. | ||||
| 8676 | ThisLiteralType propAssignThis = | ||||
| 8677 | MOZ_TRY(handler_.newThisLiteral(wholeInitializerPos, thisName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newThisLiteral(wholeInitializerPos, thisName)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 8678 | |||||
| 8679 | Node propAssignFieldAccess; | ||||
| 8680 | uint32_t indexValue; | ||||
| 8681 | if (!propAtom) { | ||||
| 8682 | // See BytecodeEmitter::emitCreateFieldKeys for an explanation of what | ||||
| 8683 | // .fieldKeys means and its purpose. | ||||
| 8684 | NameNodeType fieldKeysName; | ||||
| 8685 | if (isStatic) { | ||||
| 8686 | fieldKeysName = MOZ_TRY(newInternalDotName(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newInternalDotName( TaggedParserAtomIndex::WellKnown::dot_staticFieldKeys_ ())); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 8687 | TaggedParserAtomIndex::WellKnown::dot_staticFieldKeys_()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newInternalDotName( TaggedParserAtomIndex::WellKnown::dot_staticFieldKeys_ ())); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8688 | } else { | ||||
| 8689 | fieldKeysName = MOZ_TRY(newInternalDotName(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newInternalDotName( TaggedParserAtomIndex::WellKnown::dot_fieldKeys_ ())); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 8690 | TaggedParserAtomIndex::WellKnown::dot_fieldKeys_()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newInternalDotName( TaggedParserAtomIndex::WellKnown::dot_fieldKeys_ ())); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0 ))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8691 | } | ||||
| 8692 | if (!fieldKeysName) { | ||||
| 8693 | return errorResult(); | ||||
| 8694 | } | ||||
| 8695 | |||||
| 8696 | double fieldKeyIndex; | ||||
| 8697 | if (isStatic) { | ||||
| 8698 | fieldKeyIndex = classInitializedMembers.staticFieldKeys++; | ||||
| 8699 | } else { | ||||
| 8700 | fieldKeyIndex = classInitializedMembers.instanceFieldKeys++; | ||||
| 8701 | } | ||||
| 8702 | Node fieldKeyIndexNode = MOZ_TRY(handler_.newNumber(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newNumber( fieldKeyIndex, DecimalPoint::NoDecimal, wholeInitializerPos )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 8703 | fieldKeyIndex, DecimalPoint::NoDecimal, wholeInitializerPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newNumber( fieldKeyIndex, DecimalPoint::NoDecimal, wholeInitializerPos )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8704 | |||||
| 8705 | Node fieldKeyValue = MOZ_TRY(handler_.newPropertyByValue(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyByValue( fieldKeysName, fieldKeyIndexNode , wholeInitializerPos.end)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8706 | fieldKeysName, fieldKeyIndexNode, wholeInitializerPos.end))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyByValue( fieldKeysName, fieldKeyIndexNode , wholeInitializerPos.end)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8707 | |||||
| 8708 | propAssignFieldAccess = MOZ_TRY(handler_.newPropertyByValue(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyByValue( propAssignThis, fieldKeyValue, wholeInitializerPos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 8709 | propAssignThis, fieldKeyValue, wholeInitializerPos.end))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyByValue( propAssignThis, fieldKeyValue, wholeInitializerPos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8710 | } else if (handler_.isPrivateName(propName)) { | ||||
| 8711 | // It would be nice if we could tweak this here such that only if | ||||
| 8712 | // HasHeritage::Yes we end up emitting CheckPrivateField, but otherwise we | ||||
| 8713 | // emit InitElem -- this is an optimization to minimize HasOwn checks | ||||
| 8714 | // in InitElem for classes without heritage. | ||||
| 8715 | // | ||||
| 8716 | // Further tweaking would be to ultimately only do CheckPrivateField for the | ||||
| 8717 | // -first- field in a derived class, which would suffice to match the | ||||
| 8718 | // semantic check. | ||||
| 8719 | |||||
| 8720 | NameNodeType privateNameNode = MOZ_TRY(privateNameReference(propAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (privateNameReference(propAtom)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8721 | |||||
| 8722 | propAssignFieldAccess = MOZ_TRY(handler_.newPrivateMemberAccess(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPrivateMemberAccess( propAssignThis, privateNameNode , wholeInitializerPos.end)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8723 | propAssignThis, privateNameNode, wholeInitializerPos.end))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPrivateMemberAccess( propAssignThis, privateNameNode , wholeInitializerPos.end)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8724 | } else if (this->parserAtoms().isIndex(propAtom, &indexValue)) { | ||||
| 8725 | propAssignFieldAccess = MOZ_TRY(handler_.newPropertyByValue(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyByValue( propAssignThis, propName, wholeInitializerPos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 8726 | propAssignThis, propName, wholeInitializerPos.end))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyByValue( propAssignThis, propName, wholeInitializerPos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8727 | } else { | ||||
| 8728 | NameNodeType propAssignName = | ||||
| 8729 | MOZ_TRY(handler_.newPropertyName(propAtom, wholeInitializerPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyName(propAtom, wholeInitializerPos)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 8730 | |||||
| 8731 | propAssignFieldAccess = | ||||
| 8732 | MOZ_TRY(handler_.newPropertyAccess(propAssignThis, propAssignName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyAccess(propAssignThis, propAssignName)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8733 | } | ||||
| 8734 | |||||
| 8735 | // Synthesize an property init. | ||||
| 8736 | BinaryNodeType initializerPropInit = | ||||
| 8737 | MOZ_TRY(handler_.newInitExpr(propAssignFieldAccess, initializerExpr))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newInitExpr(propAssignFieldAccess, initializerExpr) ); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)) ) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8738 | |||||
| 8739 | UnaryNodeType exprStatement = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExprStatement(initializerPropInit, wholeInitializerPos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 8740 | handler_.newExprStatement(initializerPropInit, wholeInitializerPos.end))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExprStatement(initializerPropInit, wholeInitializerPos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8741 | |||||
| 8742 | ListNodeType statementList = | ||||
| 8743 | MOZ_TRY(handler_.newStatementList(wholeInitializerPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(wholeInitializerPos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8744 | handler_.addStatementToList(statementList, exprStatement); | ||||
| 8745 | |||||
| 8746 | bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings(); | ||||
| 8747 | if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8748 | return errorResult(); | ||||
| 8749 | } | ||||
| 8750 | if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8751 | return errorResult(); | ||||
| 8752 | } | ||||
| 8753 | |||||
| 8754 | // Set the function's body to the field assignment. | ||||
| 8755 | LexicalScopeNodeType initializerBody = MOZ_TRY(finishLexicalScope(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), statementList, ScopeKind ::FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8756 | pc_->varScope(), statementList, ScopeKind::FunctionLexical))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), statementList, ScopeKind ::FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8757 | |||||
| 8758 | handler_.setFunctionBody(funNode, initializerBody); | ||||
| 8759 | |||||
| 8760 | if (pc_->superScopeNeedsHomeObject()) { | ||||
| 8761 | funbox->setNeedsHomeObject(); | ||||
| 8762 | } | ||||
| 8763 | |||||
| 8764 | if (!finishFunction()) { | ||||
| 8765 | return errorResult(); | ||||
| 8766 | } | ||||
| 8767 | |||||
| 8768 | if (!leaveInnerFunction(outerpc)) { | ||||
| 8769 | return errorResult(); | ||||
| 8770 | } | ||||
| 8771 | |||||
| 8772 | return funNode; | ||||
| 8773 | } | ||||
| 8774 | |||||
| 8775 | template <class ParseHandler, typename Unit> | ||||
| 8776 | typename ParseHandler::FunctionNodeResult | ||||
| 8777 | GeneralParser<ParseHandler, Unit>::synthesizePrivateMethodInitializer( | ||||
| 8778 | TaggedParserAtomIndex propAtom, AccessorType accessorType, | ||||
| 8779 | TokenPos propNamePos) { | ||||
| 8780 | if (!abortIfSyntaxParser()) { | ||||
| 8781 | return errorResult(); | ||||
| 8782 | } | ||||
| 8783 | |||||
| 8784 | // Synthesize a name for the lexical variable that will store the | ||||
| 8785 | // accessor body. | ||||
| 8786 | StringBuilder storedMethodName(fc_); | ||||
| 8787 | if (!storedMethodName.append(this->parserAtoms(), propAtom)) { | ||||
| 8788 | return errorResult(); | ||||
| 8789 | } | ||||
| 8790 | if (!storedMethodName.append( | ||||
| 8791 | accessorType == AccessorType::Getter ? ".getter" : ".setter")) { | ||||
| 8792 | return errorResult(); | ||||
| 8793 | } | ||||
| 8794 | auto storedMethodProp = | ||||
| 8795 | storedMethodName.finishParserAtom(this->parserAtoms(), fc_); | ||||
| 8796 | if (!storedMethodProp) { | ||||
| 8797 | return errorResult(); | ||||
| 8798 | } | ||||
| 8799 | if (!noteDeclaredName(storedMethodProp, DeclarationKind::Synthetic, pos())) { | ||||
| 8800 | return errorResult(); | ||||
| 8801 | } | ||||
| 8802 | |||||
| 8803 | return privateMethodInitializer(propNamePos, propAtom, storedMethodProp); | ||||
| 8804 | } | ||||
| 8805 | |||||
| 8806 | #ifdef ENABLE_DECORATORS | ||||
| 8807 | template <class ParseHandler, typename Unit> | ||||
| 8808 | typename ParseHandler::FunctionNodeResult | ||||
| 8809 | GeneralParser<ParseHandler, Unit>::synthesizeAddInitializerFunction( | ||||
| 8810 | TaggedParserAtomIndex initializers, YieldHandling yieldHandling) { | ||||
| 8811 | if (!abortIfSyntaxParser()) { | ||||
| 8812 | return errorResult(); | ||||
| 8813 | } | ||||
| 8814 | |||||
| 8815 | // TODO: Add support for static and class extra initializers, see bug 1868220 | ||||
| 8816 | // and bug 1868221. | ||||
| 8817 | MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType< decltype(initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_ ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_ ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 8819); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()" ")"); do { MOZ_CrashSequence(__null, 8819); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 8818 | initializers ==do { static_assert( mozilla::detail::AssertionConditionType< decltype(initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_ ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_ ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 8819); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()" ")"); do { MOZ_CrashSequence(__null, 8819); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 8819 | TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_())do { static_assert( mozilla::detail::AssertionConditionType< decltype(initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_ ())>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_ ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 8819); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()" ")"); do { MOZ_CrashSequence(__null, 8819); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8820 | |||||
| 8821 | TokenPos propNamePos = pos(); | ||||
| 8822 | |||||
| 8823 | // Synthesize an addInitializer function that can be used to append to | ||||
| 8824 | // .initializers | ||||
| 8825 | FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Statement; | ||||
| 8826 | FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction; | ||||
| 8827 | GeneratorKind generatorKind = GeneratorKind::NotGenerator; | ||||
| 8828 | bool isSelfHosting = options().selfHostingMode; | ||||
| 8829 | FunctionFlags flags = | ||||
| 8830 | InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting); | ||||
| 8831 | |||||
| 8832 | FunctionNodeType funNode = | ||||
| 8833 | MOZ_TRY(handler_.newFunction(syntaxKind, propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8834 | |||||
| 8835 | Directives directives(true); | ||||
| 8836 | FunctionBox* funbox = | ||||
| 8837 | newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags, | ||||
| 8838 | propNamePos.begin, directives, generatorKind, asyncKind); | ||||
| 8839 | if (!funbox) { | ||||
| 8840 | return errorResult(); | ||||
| 8841 | } | ||||
| 8842 | funbox->initWithEnclosingParseContext(pc_, syntaxKind); | ||||
| 8843 | |||||
| 8844 | ParseContext* outerpc = pc_; | ||||
| 8845 | SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr); | ||||
| 8846 | if (!funpc.init()) { | ||||
| 8847 | return errorResult(); | ||||
| 8848 | } | ||||
| 8849 | pc_->functionScope().useAsVarScope(pc_); | ||||
| 8850 | |||||
| 8851 | // Takes a single parameter, `initializer`. | ||||
| 8852 | ParamsBodyNodeType params = MOZ_TRY(handler_.newParamsBody(propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newParamsBody(propNamePos)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8853 | |||||
| 8854 | handler_.setFunctionFormalParametersAndBody(funNode, params); | ||||
| 8855 | |||||
| 8856 | constexpr bool disallowDuplicateParams = true; | ||||
| 8857 | bool duplicatedParam = false; | ||||
| 8858 | if (!notePositionalFormalParameter( | ||||
| 8859 | funNode, TaggedParserAtomIndex::WellKnown::initializer(), pos().begin, | ||||
| 8860 | disallowDuplicateParams, &duplicatedParam)) { | ||||
| 8861 | return errorResult(); | ||||
| 8862 | } | ||||
| 8863 | MOZ_ASSERT(!duplicatedParam)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!duplicatedParam)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!duplicatedParam))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!duplicatedParam" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 8863); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!duplicatedParam" ")"); do { MOZ_CrashSequence (__null, 8863); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 8864 | MOZ_ASSERT(pc_->positionalFormalParameterNames().length() == 1)do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->positionalFormalParameterNames().length() == 1)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(pc_->positionalFormalParameterNames().length() == 1))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("pc_->positionalFormalParameterNames().length() == 1", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 8864); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->positionalFormalParameterNames().length() == 1" ")"); do { MOZ_CrashSequence(__null, 8864); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 8865 | |||||
| 8866 | funbox->setLength(1); | ||||
| 8867 | funbox->setArgCount(1); | ||||
| 8868 | setFunctionStartAtCurrentToken(funbox); | ||||
| 8869 | |||||
| 8870 | // Like private method initializers, the addInitializer method is not created | ||||
| 8871 | // with a body of synthesized AST nodes. Instead, the body is left empty and | ||||
| 8872 | // the initializer is synthesized at the bytecode level. See | ||||
| 8873 | // DecoratorEmitter::emitCreateAddInitializerFunction. | ||||
| 8874 | ListNodeType stmtList = MOZ_TRY(handler_.newStatementList(propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8875 | |||||
| 8876 | if (!noteUsedName(initializers)) { | ||||
| 8877 | return errorResult(); | ||||
| 8878 | } | ||||
| 8879 | |||||
| 8880 | bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings(); | ||||
| 8881 | if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8882 | return errorResult(); | ||||
| 8883 | } | ||||
| 8884 | if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 8885 | return errorResult(); | ||||
| 8886 | } | ||||
| 8887 | |||||
| 8888 | LexicalScopeNodeType addInitializerBody = MOZ_TRY(finishLexicalScope(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), stmtList, ScopeKind:: FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8889 | pc_->varScope(), stmtList, ScopeKind::FunctionLexical))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), stmtList, ScopeKind:: FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8890 | handler_.setBeginPosition(addInitializerBody, stmtList); | ||||
| 8891 | handler_.setEndPosition(addInitializerBody, stmtList); | ||||
| 8892 | handler_.setFunctionBody(funNode, addInitializerBody); | ||||
| 8893 | |||||
| 8894 | // Set field-initializer lambda boundary to start at property name and end | ||||
| 8895 | // after method body. | ||||
| 8896 | setFunctionStartAtPosition(funbox, propNamePos); | ||||
| 8897 | setFunctionEndFromCurrentToken(funbox); | ||||
| 8898 | |||||
| 8899 | if (!finishFunction()) { | ||||
| 8900 | return errorResult(); | ||||
| 8901 | } | ||||
| 8902 | |||||
| 8903 | if (!leaveInnerFunction(outerpc)) { | ||||
| 8904 | return errorResult(); | ||||
| 8905 | } | ||||
| 8906 | |||||
| 8907 | return funNode; | ||||
| 8908 | } | ||||
| 8909 | |||||
| 8910 | template <class ParseHandler, typename Unit> | ||||
| 8911 | typename ParseHandler::ClassMethodResult | ||||
| 8912 | GeneralParser<ParseHandler, Unit>::synthesizeAccessor( | ||||
| 8913 | Node propName, TokenPos propNamePos, TaggedParserAtomIndex propAtom, | ||||
| 8914 | TaggedParserAtomIndex privateStateNameAtom, bool isStatic, | ||||
| 8915 | FunctionSyntaxKind syntaxKind, | ||||
| 8916 | ClassInitializedMembers& classInitializedMembers) { | ||||
| 8917 | // Decorators Proposal | ||||
| 8918 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter | ||||
| 8919 | // The abstract operation MakeAutoAccessorGetter takes arguments homeObject | ||||
| 8920 | // (an Object), name (a property key or Private Name), and privateStateName (a | ||||
| 8921 | // Private Name) and returns a function object. | ||||
| 8922 | // | ||||
| 8923 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter | ||||
| 8924 | // The abstract operation MakeAutoAccessorSetter takes arguments homeObject | ||||
| 8925 | // (an Object), name (a property key or Private Name), and privateStateName (a | ||||
| 8926 | // Private Name) and returns a function object. | ||||
| 8927 | if (!abortIfSyntaxParser()) { | ||||
| 8928 | return errorResult(); | ||||
| 8929 | } | ||||
| 8930 | |||||
| 8931 | AccessorType accessorType = syntaxKind == FunctionSyntaxKind::Getter | ||||
| 8932 | ? AccessorType::Getter | ||||
| 8933 | : AccessorType::Setter; | ||||
| 8934 | |||||
| 8935 | mozilla::Maybe<FunctionNodeType> initializerIfPrivate = Nothing(); | ||||
| 8936 | if (!isStatic && handler_.isPrivateName(propName)) { | ||||
| 8937 | classInitializedMembers.privateAccessors++; | ||||
| 8938 | FunctionNodeType initializerNode = | ||||
| 8939 | MOZ_TRY(synthesizePrivateMethodInitializer(propAtom, accessorType,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (synthesizePrivateMethodInitializer(propAtom, accessorType, propNamePos )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 8940 | propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (synthesizePrivateMethodInitializer(propAtom, accessorType, propNamePos )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 8941 | initializerIfPrivate = Some(initializerNode); | ||||
| 8942 | handler_.setPrivateNameKind(propName, PrivateNameKind::GetterSetter); | ||||
| 8943 | } | ||||
| 8944 | |||||
| 8945 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter | ||||
| 8946 | // 2. Let getter be CreateBuiltinFunction(getterClosure, 0, "get", « »). | ||||
| 8947 | // | ||||
| 8948 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter | ||||
| 8949 | // 2. Let setter be CreateBuiltinFunction(setterClosure, 1, "set", « »). | ||||
| 8950 | StringBuilder storedMethodName(fc_); | ||||
| 8951 | if (!storedMethodName.append(accessorType == AccessorType::Getter ? "get" | ||||
| 8952 | : "set")) { | ||||
| 8953 | return errorResult(); | ||||
| 8954 | } | ||||
| 8955 | TaggedParserAtomIndex funNameAtom = | ||||
| 8956 | storedMethodName.finishParserAtom(this->parserAtoms(), fc_); | ||||
| 8957 | |||||
| 8958 | FunctionNodeType funNode = MOZ_TRY(synthesizeAccessorBody(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (synthesizeAccessorBody( funNameAtom, propNamePos, privateStateNameAtom , syntaxKind)); if ((__builtin_expect(!!(mozTryVarTempResult. isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 8959 | funNameAtom, propNamePos, privateStateNameAtom, syntaxKind))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (synthesizeAccessorBody( funNameAtom, propNamePos, privateStateNameAtom , syntaxKind)); if ((__builtin_expect(!!(mozTryVarTempResult. isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8960 | |||||
| 8961 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter | ||||
| 8962 | // 3. Perform MakeMethod(getter, homeObject). | ||||
| 8963 | // 4. Return getter. | ||||
| 8964 | // | ||||
| 8965 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter | ||||
| 8966 | // 3. Perform MakeMethod(setter, homeObject). | ||||
| 8967 | // 4. Return setter. | ||||
| 8968 | return handler_.newClassMethodDefinition( | ||||
| 8969 | propName, funNode, accessorType, isStatic, initializerIfPrivate, null()); | ||||
| 8970 | } | ||||
| 8971 | |||||
| 8972 | template <class ParseHandler, typename Unit> | ||||
| 8973 | typename ParseHandler::FunctionNodeResult | ||||
| 8974 | GeneralParser<ParseHandler, Unit>::synthesizeAccessorBody( | ||||
| 8975 | TaggedParserAtomIndex funNameAtom, TokenPos propNamePos, | ||||
| 8976 | TaggedParserAtomIndex propNameAtom, FunctionSyntaxKind syntaxKind) { | ||||
| 8977 | if (!abortIfSyntaxParser()) { | ||||
| 8978 | return errorResult(); | ||||
| 8979 | } | ||||
| 8980 | |||||
| 8981 | FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction; | ||||
| 8982 | GeneratorKind generatorKind = GeneratorKind::NotGenerator; | ||||
| 8983 | bool isSelfHosting = options().selfHostingMode; | ||||
| 8984 | FunctionFlags flags = | ||||
| 8985 | InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting); | ||||
| 8986 | |||||
| 8987 | // Create the top-level function node. | ||||
| 8988 | FunctionNodeType funNode = | ||||
| 8989 | MOZ_TRY(handler_.newFunction(syntaxKind, propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 8990 | |||||
| 8991 | // Create the FunctionBox and link it to the function object. | ||||
| 8992 | Directives directives(true); | ||||
| 8993 | FunctionBox* funbox = | ||||
| 8994 | newFunctionBox(funNode, funNameAtom, flags, propNamePos.begin, directives, | ||||
| 8995 | generatorKind, asyncKind); | ||||
| 8996 | if (!funbox) { | ||||
| 8997 | return errorResult(); | ||||
| 8998 | } | ||||
| 8999 | funbox->initWithEnclosingParseContext(pc_, syntaxKind); | ||||
| 9000 | funbox->setSyntheticFunction(); | ||||
| 9001 | |||||
| 9002 | // Push a SourceParseContext on to the stack. | ||||
| 9003 | ParseContext* outerpc = pc_; | ||||
| 9004 | SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr); | ||||
| 9005 | if (!funpc.init()) { | ||||
| 9006 | return errorResult(); | ||||
| 9007 | } | ||||
| 9008 | |||||
| 9009 | pc_->functionScope().useAsVarScope(pc_); | ||||
| 9010 | |||||
| 9011 | // The function we synthesize is located at the field with the | ||||
| 9012 | // accessor. | ||||
| 9013 | setFunctionStartAtCurrentToken(funbox); | ||||
| 9014 | setFunctionEndFromCurrentToken(funbox); | ||||
| 9015 | |||||
| 9016 | // Create a ListNode for the parameters + body | ||||
| 9017 | ParamsBodyNodeType paramsbody = MOZ_TRY(handler_.newParamsBody(propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newParamsBody(propNamePos)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9018 | handler_.setFunctionFormalParametersAndBody(funNode, paramsbody); | ||||
| 9019 | |||||
| 9020 | if (syntaxKind == FunctionSyntaxKind::Getter) { | ||||
| 9021 | funbox->setArgCount(0); | ||||
| 9022 | } else { | ||||
| 9023 | funbox->setArgCount(1); | ||||
| 9024 | } | ||||
| 9025 | |||||
| 9026 | // Build `this` expression to access the privateStateName for use in the | ||||
| 9027 | // operations to create the getter and setter below. | ||||
| 9028 | NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9029 | |||||
| 9030 | ThisLiteralType propThis = | ||||
| 9031 | MOZ_TRY(handler_.newThisLiteral(propNamePos, thisName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newThisLiteral(propNamePos, thisName)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9032 | |||||
| 9033 | NameNodeType privateNameNode = MOZ_TRY(privateNameReference(propNameAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (privateNameReference(propNameAtom)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9034 | |||||
| 9035 | Node propFieldAccess = MOZ_TRY(handler_.newPrivateMemberAccess(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPrivateMemberAccess( propThis, privateNameNode, propNamePos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 9036 | propThis, privateNameNode, propNamePos.end))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPrivateMemberAccess( propThis, privateNameNode, propNamePos .end)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()) , 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 9037 | |||||
| 9038 | Node accessorBody; | ||||
| 9039 | if (syntaxKind == FunctionSyntaxKind::Getter) { | ||||
| 9040 | // Decorators Proposal | ||||
| 9041 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter | ||||
| 9042 | // 1. Let getterClosure be a new Abstract Closure with no parameters that | ||||
| 9043 | // captures privateStateName and performs the following steps when called: | ||||
| 9044 | // 1.a. Let o be the this value. | ||||
| 9045 | // 1.b. Return ? PrivateGet(privateStateName, o). | ||||
| 9046 | accessorBody = | ||||
| 9047 | MOZ_TRY(handler_.newReturnStatement(propFieldAccess, propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newReturnStatement(propFieldAccess, propNamePos)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 9048 | } else { | ||||
| 9049 | // Decorators Proposal | ||||
| 9050 | // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter | ||||
| 9051 | // The abstract operation MakeAutoAccessorSetter takes arguments homeObject | ||||
| 9052 | // (an Object), name (a property key or Private Name), and privateStateName | ||||
| 9053 | // (a Private Name) and returns a function object. | ||||
| 9054 | // 1. Let setterClosure be a new Abstract Closure with parameters (value) | ||||
| 9055 | // that captures privateStateName and performs the following steps when | ||||
| 9056 | // called: | ||||
| 9057 | // 1.a. Let o be the this value. | ||||
| 9058 | if (!notePositionalFormalParameter( | ||||
| 9059 | funNode, TaggedParserAtomIndex::WellKnown::value(), | ||||
| 9060 | /* pos = */ 0, false, | ||||
| 9061 | /* duplicatedParam = */ nullptr)) { | ||||
| 9062 | return errorResult(); | ||||
| 9063 | } | ||||
| 9064 | |||||
| 9065 | Node initializerExpr = MOZ_TRY(handler_.newName(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newName( TaggedParserAtomIndex::WellKnown::value(), propNamePos)); if ((__builtin_expect(!!(mozTryVarTempResult. isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 9066 | TaggedParserAtomIndex::WellKnown::value(), propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newName( TaggedParserAtomIndex::WellKnown::value(), propNamePos)); if ((__builtin_expect(!!(mozTryVarTempResult. isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9067 | |||||
| 9068 | // 1.b. Perform ? PrivateSet(privateStateName, o, value). | ||||
| 9069 | Node assignment = MOZ_TRY(handler_.newAssignment(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newAssignment( ParseNodeKind::AssignExpr, propFieldAccess , initializerExpr)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 9070 | ParseNodeKind::AssignExpr, propFieldAccess, initializerExpr))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newAssignment( ParseNodeKind::AssignExpr, propFieldAccess , initializerExpr)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9071 | |||||
| 9072 | accessorBody = | ||||
| 9073 | MOZ_TRY(handler_.newExprStatement(assignment, propNamePos.end))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newExprStatement(assignment, propNamePos.end)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 9074 | |||||
| 9075 | // 1.c. Return undefined. | ||||
| 9076 | } | ||||
| 9077 | |||||
| 9078 | ListNodeType statementList = MOZ_TRY(handler_.newStatementList(propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newStatementList(propNamePos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9079 | handler_.addStatementToList(statementList, accessorBody); | ||||
| 9080 | |||||
| 9081 | bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings(); | ||||
| 9082 | if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 9083 | return errorResult(); | ||||
| 9084 | } | ||||
| 9085 | if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) { | ||||
| 9086 | return errorResult(); | ||||
| 9087 | } | ||||
| 9088 | |||||
| 9089 | LexicalScopeNodeType initializerBody = MOZ_TRY(finishLexicalScope(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), statementList, ScopeKind ::FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 9090 | pc_->varScope(), statementList, ScopeKind::FunctionLexical))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (finishLexicalScope( pc_->varScope(), statementList, ScopeKind ::FunctionLexical)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9091 | |||||
| 9092 | handler_.setFunctionBody(funNode, initializerBody); | ||||
| 9093 | |||||
| 9094 | if (pc_->superScopeNeedsHomeObject()) { | ||||
| 9095 | funbox->setNeedsHomeObject(); | ||||
| 9096 | } | ||||
| 9097 | |||||
| 9098 | if (!finishFunction()) { | ||||
| 9099 | return errorResult(); | ||||
| 9100 | } | ||||
| 9101 | |||||
| 9102 | if (!leaveInnerFunction(outerpc)) { | ||||
| 9103 | return errorResult(); | ||||
| 9104 | } | ||||
| 9105 | |||||
| 9106 | return funNode; | ||||
| 9107 | } | ||||
| 9108 | |||||
| 9109 | #endif | ||||
| 9110 | |||||
| 9111 | bool ParserBase::nextTokenContinuesLetDeclaration(TokenKind next) { | ||||
| 9112 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Let))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Let))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::Let)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Let)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9112); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Let)" ")"); do { MOZ_CrashSequence(__null, 9112); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 9113 | MOZ_ASSERT(anyChars.nextToken().type == next)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.nextToken().type == next)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.nextToken().type == next))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.nextToken().type == next", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 9113); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.nextToken().type == next" ")"); do { MOZ_CrashSequence(__null, 9113); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 9114 | |||||
| 9115 | TokenStreamShared::verifyConsistentModifier(TokenStreamShared::SlashIsDiv, | ||||
| 9116 | anyChars.nextToken()); | ||||
| 9117 | |||||
| 9118 | // Destructuring continues a let declaration. | ||||
| 9119 | if (next == TokenKind::LeftBracket || next == TokenKind::LeftCurly) { | ||||
| 9120 | return true; | ||||
| 9121 | } | ||||
| 9122 | |||||
| 9123 | // A "let" edge case deserves special comment. Consider this: | ||||
| 9124 | // | ||||
| 9125 | // let // not an ASI opportunity | ||||
| 9126 | // let; | ||||
| 9127 | // | ||||
| 9128 | // Static semantics in §13.3.1.1 turn a LexicalDeclaration that binds | ||||
| 9129 | // "let" into an early error. Does this retroactively permit ASI so | ||||
| 9130 | // that we should parse this as two ExpressionStatements? No. ASI | ||||
| 9131 | // resolves during parsing. Static semantics only apply to the full | ||||
| 9132 | // parse tree with ASI applied. No backsies! | ||||
| 9133 | |||||
| 9134 | // Otherwise a let declaration must have a name. | ||||
| 9135 | return TokenKindIsPossibleIdentifier(next); | ||||
| 9136 | } | ||||
| 9137 | |||||
| 9138 | template <class ParseHandler, typename Unit> | ||||
| 9139 | typename ParseHandler::DeclarationListNodeResult | ||||
| 9140 | GeneralParser<ParseHandler, Unit>::variableStatement( | ||||
| 9141 | YieldHandling yieldHandling) { | ||||
| 9142 | DeclarationListNodeType vars = | ||||
| 9143 | MOZ_TRY(declarationList(yieldHandling, ParseNodeKind::VarStmt))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (declarationList(yieldHandling, ParseNodeKind::VarStmt)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 9144 | if (!matchOrInsertSemicolon()) { | ||||
| 9145 | return errorResult(); | ||||
| 9146 | } | ||||
| 9147 | return vars; | ||||
| 9148 | } | ||||
| 9149 | |||||
| 9150 | template <class ParseHandler, typename Unit> | ||||
| 9151 | typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::statement( | ||||
| 9152 | YieldHandling yieldHandling) { | ||||
| 9153 | MOZ_ASSERT(checkOptionsCalled_)do { static_assert( mozilla::detail::AssertionConditionType< decltype(checkOptionsCalled_)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(checkOptionsCalled_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("checkOptionsCalled_" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9153); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence (__null, 9153); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 9154 | |||||
| 9155 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 9156 | if (!recursion.check(this->fc_)) { | ||||
| 9157 | return errorResult(); | ||||
| 9158 | } | ||||
| 9159 | |||||
| 9160 | TokenKind tt; | ||||
| 9161 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 9162 | return errorResult(); | ||||
| 9163 | } | ||||
| 9164 | |||||
| 9165 | switch (tt) { | ||||
| 9166 | // BlockStatement[?Yield, ?Return] | ||||
| 9167 | case TokenKind::LeftCurly: | ||||
| 9168 | return blockStatement(yieldHandling); | ||||
| 9169 | |||||
| 9170 | // VariableStatement[?Yield] | ||||
| 9171 | case TokenKind::Var: | ||||
| 9172 | return variableStatement(yieldHandling); | ||||
| 9173 | |||||
| 9174 | // EmptyStatement | ||||
| 9175 | case TokenKind::Semi: | ||||
| 9176 | return handler_.newEmptyStatement(pos()); | ||||
| 9177 | |||||
| 9178 | // ExpressionStatement[?Yield]. | ||||
| 9179 | |||||
| 9180 | case TokenKind::Yield: { | ||||
| 9181 | // Don't use a ternary operator here due to obscure linker issues | ||||
| 9182 | // around using static consts in the arms of a ternary. | ||||
| 9183 | Modifier modifier; | ||||
| 9184 | if (yieldExpressionsSupported()) { | ||||
| 9185 | modifier = TokenStream::SlashIsRegExp; | ||||
| 9186 | } else { | ||||
| 9187 | modifier = TokenStream::SlashIsDiv; | ||||
| 9188 | } | ||||
| 9189 | |||||
| 9190 | TokenKind next; | ||||
| 9191 | if (!tokenStream.peekToken(&next, modifier)) { | ||||
| 9192 | return errorResult(); | ||||
| 9193 | } | ||||
| 9194 | |||||
| 9195 | if (next == TokenKind::Colon) { | ||||
| 9196 | return labeledStatement(yieldHandling); | ||||
| 9197 | } | ||||
| 9198 | |||||
| 9199 | return expressionStatement(yieldHandling); | ||||
| 9200 | } | ||||
| 9201 | |||||
| 9202 | default: { | ||||
| 9203 | // If we encounter an await in a module, and the module is not marked | ||||
| 9204 | // as async, mark the module as async. | ||||
| 9205 | if (tt == TokenKind::Await && !pc_->isAsync()) { | ||||
| 9206 | if (pc_->atModuleTopLevel()) { | ||||
| 9207 | if (!options().topLevelAwait) { | ||||
| 9208 | error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED); | ||||
| 9209 | return errorResult(); | ||||
| 9210 | } | ||||
| 9211 | pc_->sc()->asModuleContext()->setIsAsync(); | ||||
| 9212 | MOZ_ASSERT(pc_->isAsync())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isAsync())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isAsync()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isAsync()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9212); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence (__null, 9212); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 9213 | } | ||||
| 9214 | } | ||||
| 9215 | |||||
| 9216 | // Avoid getting next token with SlashIsDiv. | ||||
| 9217 | if (tt == TokenKind::Await && pc_->isAsync()) { | ||||
| 9218 | return expressionStatement(yieldHandling); | ||||
| 9219 | } | ||||
| 9220 | |||||
| 9221 | if (!TokenKindIsPossibleIdentifier(tt)) { | ||||
| 9222 | return expressionStatement(yieldHandling); | ||||
| 9223 | } | ||||
| 9224 | |||||
| 9225 | TokenKind next; | ||||
| 9226 | if (!tokenStream.peekToken(&next)) { | ||||
| 9227 | return errorResult(); | ||||
| 9228 | } | ||||
| 9229 | |||||
| 9230 | // |let| here can only be an Identifier, not a declaration. Give nicer | ||||
| 9231 | // errors for declaration-looking typos. | ||||
| 9232 | if (tt == TokenKind::Let) { | ||||
| 9233 | bool forbiddenLetDeclaration = false; | ||||
| 9234 | |||||
| 9235 | if (next == TokenKind::LeftBracket) { | ||||
| 9236 | // Enforce ExpressionStatement's 'let [' lookahead restriction. | ||||
| 9237 | forbiddenLetDeclaration = true; | ||||
| 9238 | } else if (next == TokenKind::LeftCurly || | ||||
| 9239 | TokenKindIsPossibleIdentifier(next)) { | ||||
| 9240 | // 'let {' and 'let foo' aren't completely forbidden, if ASI | ||||
| 9241 | // causes 'let' to be the entire Statement. But if they're | ||||
| 9242 | // same-line, we can aggressively give a better error message. | ||||
| 9243 | // | ||||
| 9244 | // Note that this ignores 'yield' as TokenKind::Yield: we'll handle it | ||||
| 9245 | // correctly but with a worse error message. | ||||
| 9246 | TokenKind nextSameLine; | ||||
| 9247 | if (!tokenStream.peekTokenSameLine(&nextSameLine)) { | ||||
| 9248 | return errorResult(); | ||||
| 9249 | } | ||||
| 9250 | |||||
| 9251 | MOZ_ASSERT(TokenKindIsPossibleIdentifier(nextSameLine) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9253); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol" ")"); do { MOZ_CrashSequence(__null, 9253); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 9252 | nextSameLine == TokenKind::LeftCurly ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9253); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol" ")"); do { MOZ_CrashSequence(__null, 9253); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 9253 | nextSameLine == TokenKind::Eol)do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9253); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol" ")"); do { MOZ_CrashSequence(__null, 9253); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 9254 | |||||
| 9255 | forbiddenLetDeclaration = nextSameLine != TokenKind::Eol; | ||||
| 9256 | } | ||||
| 9257 | |||||
| 9258 | if (forbiddenLetDeclaration) { | ||||
| 9259 | error(JSMSG_FORBIDDEN_AS_STATEMENT, "lexical declarations"); | ||||
| 9260 | return errorResult(); | ||||
| 9261 | } | ||||
| 9262 | } else if (tt == TokenKind::Async) { | ||||
| 9263 | // Peek only on the same line: ExpressionStatement's lookahead | ||||
| 9264 | // restriction is phrased as | ||||
| 9265 | // | ||||
| 9266 | // [lookahead ∉ { '{', | ||||
| 9267 | // function, | ||||
| 9268 | // async [no LineTerminator here] function, | ||||
| 9269 | // class, | ||||
| 9270 | // let '[' }] | ||||
| 9271 | // | ||||
| 9272 | // meaning that code like this is valid: | ||||
| 9273 | // | ||||
| 9274 | // if (true) | ||||
| 9275 | // async // ASI opportunity | ||||
| 9276 | // function clownshoes() {} | ||||
| 9277 | TokenKind maybeFunction; | ||||
| 9278 | if (!tokenStream.peekTokenSameLine(&maybeFunction)) { | ||||
| 9279 | return errorResult(); | ||||
| 9280 | } | ||||
| 9281 | |||||
| 9282 | if (maybeFunction == TokenKind::Function) { | ||||
| 9283 | error(JSMSG_FORBIDDEN_AS_STATEMENT, "async function declarations"); | ||||
| 9284 | return errorResult(); | ||||
| 9285 | } | ||||
| 9286 | |||||
| 9287 | // Otherwise this |async| begins an ExpressionStatement or is a | ||||
| 9288 | // label name. | ||||
| 9289 | } | ||||
| 9290 | |||||
| 9291 | // NOTE: It's unfortunately allowed to have a label named 'let' in | ||||
| 9292 | // non-strict code. 💯 | ||||
| 9293 | if (next == TokenKind::Colon) { | ||||
| 9294 | return labeledStatement(yieldHandling); | ||||
| 9295 | } | ||||
| 9296 | |||||
| 9297 | return expressionStatement(yieldHandling); | ||||
| 9298 | } | ||||
| 9299 | |||||
| 9300 | case TokenKind::New: | ||||
| 9301 | return expressionStatement(yieldHandling, PredictInvoked); | ||||
| 9302 | |||||
| 9303 | // IfStatement[?Yield, ?Return] | ||||
| 9304 | case TokenKind::If: | ||||
| 9305 | return ifStatement(yieldHandling); | ||||
| 9306 | |||||
| 9307 | // BreakableStatement[?Yield, ?Return] | ||||
| 9308 | // | ||||
| 9309 | // BreakableStatement[Yield, Return]: | ||||
| 9310 | // IterationStatement[?Yield, ?Return] | ||||
| 9311 | // SwitchStatement[?Yield, ?Return] | ||||
| 9312 | case TokenKind::Do: | ||||
| 9313 | return doWhileStatement(yieldHandling); | ||||
| 9314 | |||||
| 9315 | case TokenKind::While: | ||||
| 9316 | return whileStatement(yieldHandling); | ||||
| 9317 | |||||
| 9318 | case TokenKind::For: | ||||
| 9319 | return forStatement(yieldHandling); | ||||
| 9320 | |||||
| 9321 | case TokenKind::Switch: | ||||
| 9322 | return switchStatement(yieldHandling); | ||||
| 9323 | |||||
| 9324 | // ContinueStatement[?Yield] | ||||
| 9325 | case TokenKind::Continue: | ||||
| 9326 | return continueStatement(yieldHandling); | ||||
| 9327 | |||||
| 9328 | // BreakStatement[?Yield] | ||||
| 9329 | case TokenKind::Break: | ||||
| 9330 | return breakStatement(yieldHandling); | ||||
| 9331 | |||||
| 9332 | // [+Return] ReturnStatement[?Yield] | ||||
| 9333 | case TokenKind::Return: | ||||
| 9334 | // The Return parameter is only used here, and the effect is easily | ||||
| 9335 | // detected this way, so don't bother passing around an extra parameter | ||||
| 9336 | // everywhere. | ||||
| 9337 | if (!pc_->allowReturn()) { | ||||
| 9338 | error(JSMSG_BAD_RETURN_OR_YIELD, "return"); | ||||
| 9339 | return errorResult(); | ||||
| 9340 | } | ||||
| 9341 | return returnStatement(yieldHandling); | ||||
| 9342 | |||||
| 9343 | // WithStatement[?Yield, ?Return] | ||||
| 9344 | case TokenKind::With: | ||||
| 9345 | return withStatement(yieldHandling); | ||||
| 9346 | |||||
| 9347 | // LabelledStatement[?Yield, ?Return] | ||||
| 9348 | // This is really handled by default and TokenKind::Yield cases above. | ||||
| 9349 | |||||
| 9350 | // ThrowStatement[?Yield] | ||||
| 9351 | case TokenKind::Throw: | ||||
| 9352 | return throwStatement(yieldHandling); | ||||
| 9353 | |||||
| 9354 | // TryStatement[?Yield, ?Return] | ||||
| 9355 | case TokenKind::Try: | ||||
| 9356 | return tryStatement(yieldHandling); | ||||
| 9357 | |||||
| 9358 | // DebuggerStatement | ||||
| 9359 | case TokenKind::Debugger: | ||||
| 9360 | return debuggerStatement(); | ||||
| 9361 | |||||
| 9362 | // |function| is forbidden by lookahead restriction (unless as child | ||||
| 9363 | // statement of |if| or |else|, but Parser::consequentOrAlternative | ||||
| 9364 | // handles that). | ||||
| 9365 | case TokenKind::Function: | ||||
| 9366 | error(JSMSG_FORBIDDEN_AS_STATEMENT, "function declarations"); | ||||
| 9367 | return errorResult(); | ||||
| 9368 | |||||
| 9369 | // |class| is also forbidden by lookahead restriction. | ||||
| 9370 | case TokenKind::Class: | ||||
| 9371 | error(JSMSG_FORBIDDEN_AS_STATEMENT, "classes"); | ||||
| 9372 | return errorResult(); | ||||
| 9373 | |||||
| 9374 | // ImportDeclaration (only inside modules) | ||||
| 9375 | case TokenKind::Import: | ||||
| 9376 | return importDeclarationOrImportExpr(yieldHandling); | ||||
| 9377 | |||||
| 9378 | // ExportDeclaration (only inside modules) | ||||
| 9379 | case TokenKind::Export: | ||||
| 9380 | return exportDeclaration(); | ||||
| 9381 | |||||
| 9382 | // Miscellaneous error cases arguably better caught here than elsewhere. | ||||
| 9383 | |||||
| 9384 | case TokenKind::Catch: | ||||
| 9385 | error(JSMSG_CATCH_WITHOUT_TRY); | ||||
| 9386 | return errorResult(); | ||||
| 9387 | |||||
| 9388 | case TokenKind::Finally: | ||||
| 9389 | error(JSMSG_FINALLY_WITHOUT_TRY); | ||||
| 9390 | return errorResult(); | ||||
| 9391 | |||||
| 9392 | // NOTE: default case handled in the ExpressionStatement section. | ||||
| 9393 | } | ||||
| 9394 | } | ||||
| 9395 | |||||
| 9396 | template <class ParseHandler, typename Unit> | ||||
| 9397 | typename ParseHandler::NodeResult | ||||
| 9398 | GeneralParser<ParseHandler, Unit>::statementListItem( | ||||
| 9399 | YieldHandling yieldHandling, bool canHaveDirectives /* = false */) { | ||||
| 9400 | MOZ_ASSERT(checkOptionsCalled_)do { static_assert( mozilla::detail::AssertionConditionType< decltype(checkOptionsCalled_)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(checkOptionsCalled_))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("checkOptionsCalled_" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9400); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence (__null, 9400); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 9401 | |||||
| 9402 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 9403 | if (!recursion.check(this->fc_)) { | ||||
| 9404 | return errorResult(); | ||||
| 9405 | } | ||||
| 9406 | |||||
| 9407 | TokenKind tt; | ||||
| 9408 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 9409 | return errorResult(); | ||||
| 9410 | } | ||||
| 9411 | |||||
| 9412 | switch (tt) { | ||||
| 9413 | // BlockStatement[?Yield, ?Return] | ||||
| 9414 | case TokenKind::LeftCurly: | ||||
| 9415 | return blockStatement(yieldHandling); | ||||
| 9416 | |||||
| 9417 | // VariableStatement[?Yield] | ||||
| 9418 | case TokenKind::Var: | ||||
| 9419 | return variableStatement(yieldHandling); | ||||
| 9420 | |||||
| 9421 | // EmptyStatement | ||||
| 9422 | case TokenKind::Semi: | ||||
| 9423 | return handler_.newEmptyStatement(pos()); | ||||
| 9424 | |||||
| 9425 | // ExpressionStatement[?Yield]. | ||||
| 9426 | // | ||||
| 9427 | // These should probably be handled by a single ExpressionStatement | ||||
| 9428 | // function in a default, not split up this way. | ||||
| 9429 | case TokenKind::String: | ||||
| 9430 | return expressionStatement(yieldHandling); | ||||
| 9431 | |||||
| 9432 | case TokenKind::Yield: { | ||||
| 9433 | // Don't use a ternary operator here due to obscure linker issues | ||||
| 9434 | // around using static consts in the arms of a ternary. | ||||
| 9435 | Modifier modifier; | ||||
| 9436 | if (yieldExpressionsSupported()) { | ||||
| 9437 | modifier = TokenStream::SlashIsRegExp; | ||||
| 9438 | } else { | ||||
| 9439 | modifier = TokenStream::SlashIsDiv; | ||||
| 9440 | } | ||||
| 9441 | |||||
| 9442 | TokenKind next; | ||||
| 9443 | if (!tokenStream.peekToken(&next, modifier)) { | ||||
| 9444 | return errorResult(); | ||||
| 9445 | } | ||||
| 9446 | |||||
| 9447 | if (next == TokenKind::Colon) { | ||||
| 9448 | return labeledStatement(yieldHandling); | ||||
| 9449 | } | ||||
| 9450 | |||||
| 9451 | return expressionStatement(yieldHandling); | ||||
| 9452 | } | ||||
| 9453 | |||||
| 9454 | default: { | ||||
| 9455 | // If we encounter an await in a module, and the module is not marked | ||||
| 9456 | // as async, mark the module as async. | ||||
| 9457 | if (tt == TokenKind::Await && !pc_->isAsync()) { | ||||
| 9458 | if (pc_->atModuleTopLevel()) { | ||||
| 9459 | if (!options().topLevelAwait) { | ||||
| 9460 | error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED); | ||||
| 9461 | return errorResult(); | ||||
| 9462 | } | ||||
| 9463 | pc_->sc()->asModuleContext()->setIsAsync(); | ||||
| 9464 | MOZ_ASSERT(pc_->isAsync())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isAsync())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isAsync()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isAsync()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9464); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence (__null, 9464); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 9465 | } | ||||
| 9466 | } | ||||
| 9467 | |||||
| 9468 | if (tt == TokenKind::Await && pc_->isAsync()) { | ||||
| 9469 | // Try finding evidence of a AwaitUsingDeclaration the syntax for which | ||||
| 9470 | // would be: | ||||
| 9471 | // await [no LineTerminator here] using [no LineTerminator here] | ||||
| 9472 | // identifier | ||||
| 9473 | |||||
| 9474 | TokenKind nextTokUsing = TokenKind::Eof; | ||||
| 9475 | // Scan with regex modifier because when its await expression, `/` | ||||
| 9476 | // should be treated as a regexp. | ||||
| 9477 | if (!tokenStream.peekTokenSameLine(&nextTokUsing, | ||||
| 9478 | TokenStream::SlashIsRegExp)) { | ||||
| 9479 | return errorResult(); | ||||
| 9480 | } | ||||
| 9481 | |||||
| 9482 | if (nextTokUsing == TokenKind::Using && | ||||
| 9483 | this->pc_->isUsingSyntaxAllowed()) { | ||||
| 9484 | tokenStream.consumeKnownToken(nextTokUsing, | ||||
| 9485 | TokenStream::SlashIsRegExp); | ||||
| 9486 | TokenKind nextTokIdentifier = TokenKind::Eof; | ||||
| 9487 | // Here we can use the Div modifier because if the next token is | ||||
| 9488 | // using then a `/` as the next token can only be considered a | ||||
| 9489 | // division. | ||||
| 9490 | if (!tokenStream.peekTokenSameLine(&nextTokIdentifier)) { | ||||
| 9491 | return errorResult(); | ||||
| 9492 | } | ||||
| 9493 | if (TokenKindIsPossibleIdentifier(nextTokIdentifier)) { | ||||
| 9494 | return lexicalDeclaration(yieldHandling, | ||||
| 9495 | DeclarationKind::AwaitUsing); | ||||
| 9496 | } | ||||
| 9497 | anyChars.ungetToken(); // put back using. | ||||
| 9498 | } | ||||
| 9499 | return expressionStatement(yieldHandling); | ||||
| 9500 | } | ||||
| 9501 | |||||
| 9502 | if (!TokenKindIsPossibleIdentifier(tt)) { | ||||
| 9503 | return expressionStatement(yieldHandling); | ||||
| 9504 | } | ||||
| 9505 | |||||
| 9506 | TokenKind next; | ||||
| 9507 | if (!tokenStream.peekToken(&next)) { | ||||
| 9508 | return errorResult(); | ||||
| 9509 | } | ||||
| 9510 | |||||
| 9511 | if (tt == TokenKind::Let && nextTokenContinuesLetDeclaration(next)) { | ||||
| 9512 | return lexicalDeclaration(yieldHandling, DeclarationKind::Let); | ||||
| 9513 | } | ||||
| 9514 | |||||
| 9515 | if (tt == TokenKind::Async) { | ||||
| 9516 | TokenKind nextSameLine = TokenKind::Eof; | ||||
| 9517 | if (!tokenStream.peekTokenSameLine(&nextSameLine)) { | ||||
| 9518 | return errorResult(); | ||||
| 9519 | } | ||||
| 9520 | if (nextSameLine == TokenKind::Function) { | ||||
| 9521 | uint32_t toStringStart = pos().begin; | ||||
| 9522 | tokenStream.consumeKnownToken(TokenKind::Function); | ||||
| 9523 | return functionStmt(toStringStart, yieldHandling, NameRequired, | ||||
| 9524 | FunctionAsyncKind::AsyncFunction); | ||||
| 9525 | } | ||||
| 9526 | } | ||||
| 9527 | |||||
| 9528 | if (next == TokenKind::Colon) { | ||||
| 9529 | return labeledStatement(yieldHandling); | ||||
| 9530 | } | ||||
| 9531 | |||||
| 9532 | return expressionStatement(yieldHandling); | ||||
| 9533 | } | ||||
| 9534 | |||||
| 9535 | case TokenKind::New: | ||||
| 9536 | return expressionStatement(yieldHandling, PredictInvoked); | ||||
| 9537 | |||||
| 9538 | // IfStatement[?Yield, ?Return] | ||||
| 9539 | case TokenKind::If: | ||||
| 9540 | return ifStatement(yieldHandling); | ||||
| 9541 | |||||
| 9542 | // BreakableStatement[?Yield, ?Return] | ||||
| 9543 | // | ||||
| 9544 | // BreakableStatement[Yield, Return]: | ||||
| 9545 | // IterationStatement[?Yield, ?Return] | ||||
| 9546 | // SwitchStatement[?Yield, ?Return] | ||||
| 9547 | case TokenKind::Do: | ||||
| 9548 | return doWhileStatement(yieldHandling); | ||||
| 9549 | |||||
| 9550 | case TokenKind::While: | ||||
| 9551 | return whileStatement(yieldHandling); | ||||
| 9552 | |||||
| 9553 | case TokenKind::For: | ||||
| 9554 | return forStatement(yieldHandling); | ||||
| 9555 | |||||
| 9556 | case TokenKind::Switch: | ||||
| 9557 | return switchStatement(yieldHandling); | ||||
| 9558 | |||||
| 9559 | // ContinueStatement[?Yield] | ||||
| 9560 | case TokenKind::Continue: | ||||
| 9561 | return continueStatement(yieldHandling); | ||||
| 9562 | |||||
| 9563 | // BreakStatement[?Yield] | ||||
| 9564 | case TokenKind::Break: | ||||
| 9565 | return breakStatement(yieldHandling); | ||||
| 9566 | |||||
| 9567 | // [+Return] ReturnStatement[?Yield] | ||||
| 9568 | case TokenKind::Return: | ||||
| 9569 | // The Return parameter is only used here, and the effect is easily | ||||
| 9570 | // detected this way, so don't bother passing around an extra parameter | ||||
| 9571 | // everywhere. | ||||
| 9572 | if (!pc_->allowReturn()) { | ||||
| 9573 | error(JSMSG_BAD_RETURN_OR_YIELD, "return"); | ||||
| 9574 | return errorResult(); | ||||
| 9575 | } | ||||
| 9576 | return returnStatement(yieldHandling); | ||||
| 9577 | |||||
| 9578 | // WithStatement[?Yield, ?Return] | ||||
| 9579 | case TokenKind::With: | ||||
| 9580 | return withStatement(yieldHandling); | ||||
| 9581 | |||||
| 9582 | // LabelledStatement[?Yield, ?Return] | ||||
| 9583 | // This is really handled by default and TokenKind::Yield cases above. | ||||
| 9584 | |||||
| 9585 | // ThrowStatement[?Yield] | ||||
| 9586 | case TokenKind::Throw: | ||||
| 9587 | return throwStatement(yieldHandling); | ||||
| 9588 | |||||
| 9589 | // TryStatement[?Yield, ?Return] | ||||
| 9590 | case TokenKind::Try: | ||||
| 9591 | return tryStatement(yieldHandling); | ||||
| 9592 | |||||
| 9593 | // DebuggerStatement | ||||
| 9594 | case TokenKind::Debugger: | ||||
| 9595 | return debuggerStatement(); | ||||
| 9596 | |||||
| 9597 | // Declaration[Yield]: | ||||
| 9598 | |||||
| 9599 | // HoistableDeclaration[?Yield, ~Default] | ||||
| 9600 | case TokenKind::Function: | ||||
| 9601 | return functionStmt(pos().begin, yieldHandling, NameRequired); | ||||
| 9602 | |||||
| 9603 | // DecoratorList[?Yield, ?Await] opt ClassDeclaration[?Yield, ~Default] | ||||
| 9604 | #ifdef ENABLE_DECORATORS | ||||
| 9605 | case TokenKind::At: | ||||
| 9606 | if (fuzzingSafe) { | ||||
| 9607 | error(JSMSG_DECORATOR_FUZZING_UNSAFE); | ||||
| 9608 | return errorResult(); | ||||
| 9609 | } | ||||
| 9610 | return classDefinition(yieldHandling, ClassStatement, NameRequired); | ||||
| 9611 | #endif | ||||
| 9612 | |||||
| 9613 | case TokenKind::Class: | ||||
| 9614 | return classDefinition(yieldHandling, ClassStatement, NameRequired); | ||||
| 9615 | |||||
| 9616 | // LexicalDeclaration[In, ?Yield] | ||||
| 9617 | // LetOrConst BindingList[?In, ?Yield] | ||||
| 9618 | case TokenKind::Const: | ||||
| 9619 | // [In] is the default behavior, because for-loops specially parse | ||||
| 9620 | // their heads to handle |in| in this situation. | ||||
| 9621 | return lexicalDeclaration(yieldHandling, DeclarationKind::Const); | ||||
| 9622 | |||||
| 9623 | case TokenKind::Using: { | ||||
| 9624 | TokenKind nextTok = TokenKind::Eol; | ||||
| 9625 | if (!tokenStream.peekTokenSameLine(&nextTok)) { | ||||
| 9626 | return errorResult(); | ||||
| 9627 | } | ||||
| 9628 | if (!TokenKindIsPossibleIdentifier(nextTok) || | ||||
| 9629 | !this->pc_->isUsingSyntaxAllowed()) { | ||||
| 9630 | if (!tokenStream.peekToken(&nextTok)) { | ||||
| 9631 | return errorResult(); | ||||
| 9632 | } | ||||
| 9633 | // labelled statement could be like using\n:\nexpr | ||||
| 9634 | if (nextTok == TokenKind::Colon) { | ||||
| 9635 | return labeledStatement(yieldHandling); | ||||
| 9636 | } | ||||
| 9637 | return expressionStatement(yieldHandling); | ||||
| 9638 | } | ||||
| 9639 | return lexicalDeclaration(yieldHandling, DeclarationKind::Using); | ||||
| 9640 | } | ||||
| 9641 | |||||
| 9642 | // ImportDeclaration (only inside modules) | ||||
| 9643 | case TokenKind::Import: | ||||
| 9644 | return importDeclarationOrImportExpr(yieldHandling); | ||||
| 9645 | |||||
| 9646 | // ExportDeclaration (only inside modules) | ||||
| 9647 | case TokenKind::Export: | ||||
| 9648 | return exportDeclaration(); | ||||
| 9649 | |||||
| 9650 | // Miscellaneous error cases arguably better caught here than elsewhere. | ||||
| 9651 | |||||
| 9652 | case TokenKind::Catch: | ||||
| 9653 | error(JSMSG_CATCH_WITHOUT_TRY); | ||||
| 9654 | return errorResult(); | ||||
| 9655 | |||||
| 9656 | case TokenKind::Finally: | ||||
| 9657 | error(JSMSG_FINALLY_WITHOUT_TRY); | ||||
| 9658 | return errorResult(); | ||||
| 9659 | |||||
| 9660 | // NOTE: default case handled in the ExpressionStatement section. | ||||
| 9661 | } | ||||
| 9662 | } | ||||
| 9663 | |||||
| 9664 | template <class ParseHandler, typename Unit> | ||||
| 9665 | typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::expr( | ||||
| 9666 | InHandling inHandling, YieldHandling yieldHandling, | ||||
| 9667 | TripledotHandling tripledotHandling, | ||||
| 9668 | PossibleError* possibleError /* = nullptr */, | ||||
| 9669 | InvokedPrediction invoked /* = PredictUninvoked */) { | ||||
| 9670 | Node pn = MOZ_TRY(assignExpr(inHandling, yieldHandling, tripledotHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, yieldHandling, tripledotHandling, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 9671 | possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, yieldHandling, tripledotHandling, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 9672 | |||||
| 9673 | bool matched; | ||||
| 9674 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 9675 | TokenStream::SlashIsRegExp)) { | ||||
| 9676 | return errorResult(); | ||||
| 9677 | } | ||||
| 9678 | if (!matched) { | ||||
| 9679 | return pn; | ||||
| 9680 | } | ||||
| 9681 | |||||
| 9682 | ListNodeType seq = MOZ_TRY(handler_.newCommaExpressionList(pn))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newCommaExpressionList(pn)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9683 | while (true) { | ||||
| 9684 | // Trailing comma before the closing parenthesis is valid in an arrow | ||||
| 9685 | // function parameters list: `(a, b, ) => body`. Check if we are | ||||
| 9686 | // directly under CoverParenthesizedExpressionAndArrowParameterList, | ||||
| 9687 | // and the next two tokens are closing parenthesis and arrow. If all | ||||
| 9688 | // are present allow the trailing comma. | ||||
| 9689 | if (tripledotHandling == TripledotAllowed) { | ||||
| 9690 | TokenKind tt; | ||||
| 9691 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 9692 | return errorResult(); | ||||
| 9693 | } | ||||
| 9694 | |||||
| 9695 | if (tt == TokenKind::RightParen) { | ||||
| 9696 | tokenStream.consumeKnownToken(TokenKind::RightParen, | ||||
| 9697 | TokenStream::SlashIsRegExp); | ||||
| 9698 | |||||
| 9699 | if (!tokenStream.peekToken(&tt)) { | ||||
| 9700 | return errorResult(); | ||||
| 9701 | } | ||||
| 9702 | if (tt != TokenKind::Arrow) { | ||||
| 9703 | error(JSMSG_UNEXPECTED_TOKEN, "expression", | ||||
| 9704 | TokenKindToDesc(TokenKind::RightParen)); | ||||
| 9705 | return errorResult(); | ||||
| 9706 | } | ||||
| 9707 | |||||
| 9708 | anyChars.ungetToken(); // put back right paren | ||||
| 9709 | break; | ||||
| 9710 | } | ||||
| 9711 | } | ||||
| 9712 | |||||
| 9713 | // Additional calls to assignExpr should not reuse the possibleError | ||||
| 9714 | // which had been passed into the function. Otherwise we would lose | ||||
| 9715 | // information needed to determine whether or not we're dealing with | ||||
| 9716 | // a non-recoverable situation. | ||||
| 9717 | PossibleError possibleErrorInner(*this); | ||||
| 9718 | pn = MOZ_TRY(assignExpr(inHandling, yieldHandling, tripledotHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, yieldHandling, tripledotHandling, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 9719 | &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, yieldHandling, tripledotHandling, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9720 | |||||
| 9721 | if (!possibleError) { | ||||
| 9722 | // Report any pending expression error. | ||||
| 9723 | if (!possibleErrorInner.checkForExpressionError()) { | ||||
| 9724 | return errorResult(); | ||||
| 9725 | } | ||||
| 9726 | } else { | ||||
| 9727 | possibleErrorInner.transferErrorsTo(possibleError); | ||||
| 9728 | } | ||||
| 9729 | |||||
| 9730 | handler_.addList(seq, pn); | ||||
| 9731 | |||||
| 9732 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 9733 | TokenStream::SlashIsRegExp)) { | ||||
| 9734 | return errorResult(); | ||||
| 9735 | } | ||||
| 9736 | if (!matched) { | ||||
| 9737 | break; | ||||
| 9738 | } | ||||
| 9739 | } | ||||
| 9740 | return seq; | ||||
| 9741 | } | ||||
| 9742 | |||||
| 9743 | static ParseNodeKind BinaryOpTokenKindToParseNodeKind(TokenKind tok) { | ||||
| 9744 | MOZ_ASSERT(TokenKindIsBinaryOp(tok))do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsBinaryOp(tok))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(TokenKindIsBinaryOp(tok)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("TokenKindIsBinaryOp(tok)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 9744); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsBinaryOp(tok)" ")"); do { MOZ_CrashSequence (__null, 9744); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 9745 | return ParseNodeKind(size_t(ParseNodeKind::BinOpFirst) + | ||||
| 9746 | (size_t(tok) - size_t(TokenKind::BinOpFirst))); | ||||
| 9747 | } | ||||
| 9748 | |||||
| 9749 | // This list must be kept in the same order in several places: | ||||
| 9750 | // - The binary operators in ParseNode.h , | ||||
| 9751 | // - the binary operators in TokenKind.h | ||||
| 9752 | // - the JSOp code list in BytecodeEmitter.cpp | ||||
| 9753 | static const int PrecedenceTable[] = { | ||||
| 9754 | 1, /* ParseNodeKind::Coalesce */ | ||||
| 9755 | 2, /* ParseNodeKind::Or */ | ||||
| 9756 | 3, /* ParseNodeKind::And */ | ||||
| 9757 | 4, /* ParseNodeKind::BitOr */ | ||||
| 9758 | 5, /* ParseNodeKind::BitXor */ | ||||
| 9759 | 6, /* ParseNodeKind::BitAnd */ | ||||
| 9760 | 7, /* ParseNodeKind::StrictEq */ | ||||
| 9761 | 7, /* ParseNodeKind::Eq */ | ||||
| 9762 | 7, /* ParseNodeKind::StrictNe */ | ||||
| 9763 | 7, /* ParseNodeKind::Ne */ | ||||
| 9764 | 8, /* ParseNodeKind::Lt */ | ||||
| 9765 | 8, /* ParseNodeKind::Le */ | ||||
| 9766 | 8, /* ParseNodeKind::Gt */ | ||||
| 9767 | 8, /* ParseNodeKind::Ge */ | ||||
| 9768 | 8, /* ParseNodeKind::InstanceOf */ | ||||
| 9769 | 8, /* ParseNodeKind::In */ | ||||
| 9770 | 8, /* ParseNodeKind::PrivateIn */ | ||||
| 9771 | 9, /* ParseNodeKind::Lsh */ | ||||
| 9772 | 9, /* ParseNodeKind::Rsh */ | ||||
| 9773 | 9, /* ParseNodeKind::Ursh */ | ||||
| 9774 | 10, /* ParseNodeKind::Add */ | ||||
| 9775 | 10, /* ParseNodeKind::Sub */ | ||||
| 9776 | 11, /* ParseNodeKind::Star */ | ||||
| 9777 | 11, /* ParseNodeKind::Div */ | ||||
| 9778 | 11, /* ParseNodeKind::Mod */ | ||||
| 9779 | 12 /* ParseNodeKind::Pow */ | ||||
| 9780 | }; | ||||
| 9781 | |||||
| 9782 | static const int PRECEDENCE_CLASSES = 12; | ||||
| 9783 | |||||
| 9784 | static int Precedence(ParseNodeKind pnk) { | ||||
| 9785 | // Everything binds tighter than ParseNodeKind::Limit, because we want | ||||
| 9786 | // to reduce all nodes to a single node when we reach a token that is not | ||||
| 9787 | // another binary operator. | ||||
| 9788 | if (pnk == ParseNodeKind::Limit) { | ||||
| 9789 | return 0; | ||||
| 9790 | } | ||||
| 9791 | |||||
| 9792 | MOZ_ASSERT(pnk >= ParseNodeKind::BinOpFirst)do { static_assert( mozilla::detail::AssertionConditionType< decltype(pnk >= ParseNodeKind::BinOpFirst)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pnk >= ParseNodeKind::BinOpFirst ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "pnk >= ParseNodeKind::BinOpFirst", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 9792); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pnk >= ParseNodeKind::BinOpFirst" ")"); do { MOZ_CrashSequence(__null, 9792); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 9793 | MOZ_ASSERT(pnk <= ParseNodeKind::BinOpLast)do { static_assert( mozilla::detail::AssertionConditionType< decltype(pnk <= ParseNodeKind::BinOpLast)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pnk <= ParseNodeKind::BinOpLast ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "pnk <= ParseNodeKind::BinOpLast", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 9793); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pnk <= ParseNodeKind::BinOpLast" ")"); do { MOZ_CrashSequence(__null, 9793); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 9794 | return PrecedenceTable[size_t(pnk) - size_t(ParseNodeKind::BinOpFirst)]; | ||||
| 9795 | } | ||||
| 9796 | |||||
| 9797 | enum class EnforcedParentheses : uint8_t { CoalesceExpr, AndOrExpr, None }; | ||||
| 9798 | |||||
| 9799 | template <class ParseHandler, typename Unit> | ||||
| 9800 | MOZ_ALWAYS_INLINEinline typename ParseHandler::NodeResult | ||||
| 9801 | GeneralParser<ParseHandler, Unit>::orExpr(InHandling inHandling, | ||||
| 9802 | YieldHandling yieldHandling, | ||||
| 9803 | TripledotHandling tripledotHandling, | ||||
| 9804 | PossibleError* possibleError, | ||||
| 9805 | InvokedPrediction invoked) { | ||||
| 9806 | // Shift-reduce parser for the binary operator part of the JS expression | ||||
| 9807 | // syntax. | ||||
| 9808 | |||||
| 9809 | // Conceptually there's just one stack, a stack of pairs (lhs, op). | ||||
| 9810 | // It's implemented using two separate arrays, though. | ||||
| 9811 | Node nodeStack[PRECEDENCE_CLASSES]; | ||||
| 9812 | ParseNodeKind kindStack[PRECEDENCE_CLASSES]; | ||||
| 9813 | int depth = 0; | ||||
| 9814 | Node pn; | ||||
| 9815 | EnforcedParentheses unparenthesizedExpression = EnforcedParentheses::None; | ||||
| 9816 | for (;;) { | ||||
| 9817 | pn = MOZ_TRY(unaryExpr(yieldHandling, tripledotHandling, possibleError,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked , PrivateNameHandling::PrivateNameAllowed)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 9818 | invoked, PrivateNameHandling::PrivateNameAllowed))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked , PrivateNameHandling::PrivateNameAllowed)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 9819 | |||||
| 9820 | // If a binary operator follows, consume it and compute the | ||||
| 9821 | // corresponding operator. | ||||
| 9822 | TokenKind tok; | ||||
| 9823 | if (!tokenStream.getToken(&tok)) { | ||||
| 9824 | return errorResult(); | ||||
| 9825 | } | ||||
| 9826 | |||||
| 9827 | // Ensure that if we have a private name lhs we are legally constructing a | ||||
| 9828 | // `#x in obj` expessions: | ||||
| 9829 | if (handler_.isPrivateName(pn)) { | ||||
| 9830 | if (tok != TokenKind::In || inHandling != InAllowed) { | ||||
| 9831 | error(JSMSG_ILLEGAL_PRIVATE_NAME); | ||||
| 9832 | return errorResult(); | ||||
| 9833 | } | ||||
| 9834 | } | ||||
| 9835 | |||||
| 9836 | ParseNodeKind pnk; | ||||
| 9837 | if (tok == TokenKind::In ? inHandling == InAllowed | ||||
| 9838 | : TokenKindIsBinaryOp(tok)) { | ||||
| 9839 | // We're definitely not in a destructuring context, so report any | ||||
| 9840 | // pending expression error now. | ||||
| 9841 | if (possibleError && !possibleError->checkForExpressionError()) { | ||||
| 9842 | return errorResult(); | ||||
| 9843 | } | ||||
| 9844 | |||||
| 9845 | bool isErgonomicBrandCheck = false; | ||||
| 9846 | switch (tok) { | ||||
| 9847 | // Report an error for unary expressions on the LHS of **. | ||||
| 9848 | case TokenKind::Pow: | ||||
| 9849 | if (handler_.isUnparenthesizedUnaryExpression(pn)) { | ||||
| 9850 | error(JSMSG_BAD_POW_LEFTSIDE); | ||||
| 9851 | return errorResult(); | ||||
| 9852 | } | ||||
| 9853 | break; | ||||
| 9854 | |||||
| 9855 | case TokenKind::Or: | ||||
| 9856 | case TokenKind::And: | ||||
| 9857 | // In the case that the `??` is on the left hand side of the | ||||
| 9858 | // expression: Disallow Mixing of ?? and other logical operators (|| | ||||
| 9859 | // and &&) unless one expression is parenthesized | ||||
| 9860 | if (unparenthesizedExpression == EnforcedParentheses::CoalesceExpr) { | ||||
| 9861 | error(JSMSG_BAD_COALESCE_MIXING); | ||||
| 9862 | return errorResult(); | ||||
| 9863 | } | ||||
| 9864 | // If we have not detected a mixing error at this point, record that | ||||
| 9865 | // we have an unparenthesized expression, in case we have one later. | ||||
| 9866 | unparenthesizedExpression = EnforcedParentheses::AndOrExpr; | ||||
| 9867 | break; | ||||
| 9868 | |||||
| 9869 | case TokenKind::Coalesce: | ||||
| 9870 | if (unparenthesizedExpression == EnforcedParentheses::AndOrExpr) { | ||||
| 9871 | error(JSMSG_BAD_COALESCE_MIXING); | ||||
| 9872 | return errorResult(); | ||||
| 9873 | } | ||||
| 9874 | // If we have not detected a mixing error at this point, record that | ||||
| 9875 | // we have an unparenthesized expression, in case we have one later. | ||||
| 9876 | unparenthesizedExpression = EnforcedParentheses::CoalesceExpr; | ||||
| 9877 | break; | ||||
| 9878 | |||||
| 9879 | case TokenKind::In: | ||||
| 9880 | // if the LHS is a private name, and the operator is In, | ||||
| 9881 | // ensure we're construcing an ergonomic brand check of | ||||
| 9882 | // '#x in y', rather than having a higher precedence operator | ||||
| 9883 | // like + cause a different reduction, such as | ||||
| 9884 | // 1 + #x in y. | ||||
| 9885 | if (handler_.isPrivateName(pn)) { | ||||
| 9886 | if (depth > 0 && Precedence(kindStack[depth - 1]) >= | ||||
| 9887 | Precedence(ParseNodeKind::InExpr)) { | ||||
| 9888 | error(JSMSG_INVALID_PRIVATE_NAME_PRECEDENCE); | ||||
| 9889 | return errorResult(); | ||||
| 9890 | } | ||||
| 9891 | |||||
| 9892 | isErgonomicBrandCheck = true; | ||||
| 9893 | } | ||||
| 9894 | break; | ||||
| 9895 | |||||
| 9896 | default: | ||||
| 9897 | // do nothing in other cases | ||||
| 9898 | break; | ||||
| 9899 | } | ||||
| 9900 | |||||
| 9901 | if (isErgonomicBrandCheck) { | ||||
| 9902 | pnk = ParseNodeKind::PrivateInExpr; | ||||
| 9903 | } else { | ||||
| 9904 | pnk = BinaryOpTokenKindToParseNodeKind(tok); | ||||
| 9905 | } | ||||
| 9906 | |||||
| 9907 | } else { | ||||
| 9908 | tok = TokenKind::Eof; | ||||
| 9909 | pnk = ParseNodeKind::Limit; | ||||
| 9910 | } | ||||
| 9911 | |||||
| 9912 | // From this point on, destructuring defaults are definitely an error. | ||||
| 9913 | possibleError = nullptr; | ||||
| 9914 | |||||
| 9915 | // If pnk has precedence less than or equal to another operator on the | ||||
| 9916 | // stack, reduce. This combines nodes on the stack until we form the | ||||
| 9917 | // actual lhs of pnk. | ||||
| 9918 | // | ||||
| 9919 | // The >= in this condition works because it is appendOrCreateList's | ||||
| 9920 | // job to decide if the operator in question is left- or | ||||
| 9921 | // right-associative, and build the corresponding tree. | ||||
| 9922 | while (depth > 0 && Precedence(kindStack[depth - 1]) >= Precedence(pnk)) { | ||||
| 9923 | depth--; | ||||
| 9924 | ParseNodeKind combiningPnk = kindStack[depth]; | ||||
| 9925 | pn = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.appendOrCreateList(combiningPnk, nodeStack[depth], pn , pc_)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr() ), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 9926 | handler_.appendOrCreateList(combiningPnk, nodeStack[depth], pn, pc_))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.appendOrCreateList(combiningPnk, nodeStack[depth], pn , pc_)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr() ), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 9927 | } | ||||
| 9928 | |||||
| 9929 | if (pnk == ParseNodeKind::Limit) { | ||||
| 9930 | break; | ||||
| 9931 | } | ||||
| 9932 | |||||
| 9933 | nodeStack[depth] = pn; | ||||
| 9934 | kindStack[depth] = pnk; | ||||
| 9935 | depth++; | ||||
| 9936 | MOZ_ASSERT(depth <= PRECEDENCE_CLASSES)do { static_assert( mozilla::detail::AssertionConditionType< decltype(depth <= PRECEDENCE_CLASSES)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(depth <= PRECEDENCE_CLASSES ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "depth <= PRECEDENCE_CLASSES", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 9936); AnnotateMozCrashReason("MOZ_ASSERT" "(" "depth <= PRECEDENCE_CLASSES" ")"); do { MOZ_CrashSequence(__null, 9936); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 9937 | } | ||||
| 9938 | |||||
| 9939 | anyChars.ungetToken(); | ||||
| 9940 | |||||
| 9941 | // Had the next token been a Div, we would have consumed it. So there's no | ||||
| 9942 | // ambiguity if we later (after ASI) re-get this token with SlashIsRegExp. | ||||
| 9943 | anyChars.allowGettingNextTokenWithSlashIsRegExp(); | ||||
| 9944 | |||||
| 9945 | MOZ_ASSERT(depth == 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(depth == 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(depth == 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("depth == 0", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 9945); AnnotateMozCrashReason("MOZ_ASSERT" "(" "depth == 0" ")"); do { MOZ_CrashSequence(__null, 9945); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 9946 | return pn; | ||||
| 9947 | } | ||||
| 9948 | |||||
| 9949 | template <class ParseHandler, typename Unit> | ||||
| 9950 | MOZ_ALWAYS_INLINEinline typename ParseHandler::NodeResult | ||||
| 9951 | GeneralParser<ParseHandler, Unit>::condExpr(InHandling inHandling, | ||||
| 9952 | YieldHandling yieldHandling, | ||||
| 9953 | TripledotHandling tripledotHandling, | ||||
| 9954 | PossibleError* possibleError, | ||||
| 9955 | InvokedPrediction invoked) { | ||||
| 9956 | Node condition = MOZ_TRY(orExpr(inHandling, yieldHandling, tripledotHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (orExpr(inHandling, yieldHandling, tripledotHandling, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 9957 | possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (orExpr(inHandling, yieldHandling, tripledotHandling, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 9958 | |||||
| 9959 | bool matched; | ||||
| 9960 | if (!tokenStream.matchToken(&matched, TokenKind::Hook, | ||||
| 9961 | TokenStream::SlashIsInvalid)) { | ||||
| 9962 | return errorResult(); | ||||
| 9963 | } | ||||
| 9964 | if (!matched) { | ||||
| 9965 | return condition; | ||||
| 9966 | } | ||||
| 9967 | |||||
| 9968 | Node thenExpr = | ||||
| 9969 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 9970 | |||||
| 9971 | if (!mustMatchToken(TokenKind::Colon, JSMSG_COLON_IN_COND)) { | ||||
| 9972 | return errorResult(); | ||||
| 9973 | } | ||||
| 9974 | |||||
| 9975 | Node elseExpr = | ||||
| 9976 | MOZ_TRY(assignExpr(inHandling, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 9977 | |||||
| 9978 | return handler_.newConditional(condition, thenExpr, elseExpr); | ||||
| 9979 | } | ||||
| 9980 | |||||
| 9981 | template <class ParseHandler, typename Unit> | ||||
| 9982 | typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::assignExpr( | ||||
| 9983 | InHandling inHandling, YieldHandling yieldHandling, | ||||
| 9984 | TripledotHandling tripledotHandling, | ||||
| 9985 | PossibleError* possibleError /* = nullptr */, | ||||
| 9986 | InvokedPrediction invoked /* = PredictUninvoked */) { | ||||
| 9987 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 9988 | if (!recursion.check(this->fc_)) { | ||||
| 9989 | return errorResult(); | ||||
| 9990 | } | ||||
| 9991 | |||||
| 9992 | // It's very common at this point to have a "detectably simple" expression, | ||||
| 9993 | // i.e. a name/number/string token followed by one of the following tokens | ||||
| 9994 | // that obviously isn't part of an expression: , ; : ) ] } | ||||
| 9995 | // | ||||
| 9996 | // (In Parsemark this happens 81.4% of the time; in code with large | ||||
| 9997 | // numeric arrays, such as some Kraken benchmarks, it happens more often.) | ||||
| 9998 | // | ||||
| 9999 | // In such cases, we can avoid the full expression parsing route through | ||||
| 10000 | // assignExpr(), condExpr(), orExpr(), unaryExpr(), memberExpr(), and | ||||
| 10001 | // primaryExpr(). | ||||
| 10002 | |||||
| 10003 | TokenKind firstToken; | ||||
| 10004 | if (!tokenStream.getToken(&firstToken, TokenStream::SlashIsRegExp)) { | ||||
| 10005 | return errorResult(); | ||||
| 10006 | } | ||||
| 10007 | |||||
| 10008 | TokenPos exprPos = pos(); | ||||
| 10009 | |||||
| 10010 | bool endsExpr; | ||||
| 10011 | |||||
| 10012 | // This only handles identifiers that *never* have special meaning anywhere | ||||
| 10013 | // in the language. Contextual keywords, reserved words in strict mode, | ||||
| 10014 | // and other hard cases are handled outside this fast path. | ||||
| 10015 | if (firstToken == TokenKind::Name) { | ||||
| 10016 | if (!tokenStream.nextTokenEndsExpr(&endsExpr)) { | ||||
| 10017 | return errorResult(); | ||||
| 10018 | } | ||||
| 10019 | if (endsExpr) { | ||||
| 10020 | TaggedParserAtomIndex name = identifierReference(yieldHandling); | ||||
| 10021 | if (!name) { | ||||
| 10022 | return errorResult(); | ||||
| 10023 | } | ||||
| 10024 | |||||
| 10025 | return identifierReference(name); | ||||
| 10026 | } | ||||
| 10027 | } | ||||
| 10028 | |||||
| 10029 | if (firstToken == TokenKind::Number) { | ||||
| 10030 | if (!tokenStream.nextTokenEndsExpr(&endsExpr)) { | ||||
| 10031 | return errorResult(); | ||||
| 10032 | } | ||||
| 10033 | if (endsExpr) { | ||||
| 10034 | return newNumber(anyChars.currentToken()); | ||||
| 10035 | } | ||||
| 10036 | } | ||||
| 10037 | |||||
| 10038 | if (firstToken == TokenKind::String) { | ||||
| 10039 | if (!tokenStream.nextTokenEndsExpr(&endsExpr)) { | ||||
| 10040 | return errorResult(); | ||||
| 10041 | } | ||||
| 10042 | if (endsExpr) { | ||||
| 10043 | return stringLiteral(); | ||||
| 10044 | } | ||||
| 10045 | } | ||||
| 10046 | |||||
| 10047 | if (firstToken == TokenKind::Yield && yieldExpressionsSupported()) { | ||||
| 10048 | return yieldExpression(inHandling); | ||||
| 10049 | } | ||||
| 10050 | |||||
| 10051 | bool maybeAsyncArrow = false; | ||||
| 10052 | if (firstToken == TokenKind::Async) { | ||||
| 10053 | TokenKind nextSameLine = TokenKind::Eof; | ||||
| 10054 | if (!tokenStream.peekTokenSameLine(&nextSameLine)) { | ||||
| 10055 | return errorResult(); | ||||
| 10056 | } | ||||
| 10057 | |||||
| 10058 | if (TokenKindIsPossibleIdentifier(nextSameLine)) { | ||||
| 10059 | maybeAsyncArrow = true; | ||||
| 10060 | } | ||||
| 10061 | } | ||||
| 10062 | |||||
| 10063 | anyChars.ungetToken(); | ||||
| 10064 | |||||
| 10065 | // Save the tokenizer state in case we find an arrow function and have to | ||||
| 10066 | // rewind. | ||||
| 10067 | Position start(tokenStream); | ||||
| 10068 | auto ghostToken = this->compilationState_.getPosition(); | ||||
| 10069 | |||||
| 10070 | PossibleError possibleErrorInner(*this); | ||||
| 10071 | Node lhs; | ||||
| 10072 | TokenKind tokenAfterLHS; | ||||
| 10073 | bool isArrow; | ||||
| 10074 | if (maybeAsyncArrow) { | ||||
| 10075 | tokenStream.consumeKnownToken(TokenKind::Async, TokenStream::SlashIsRegExp); | ||||
| 10076 | |||||
| 10077 | TokenKind tokenAfterAsync; | ||||
| 10078 | if (!tokenStream.getToken(&tokenAfterAsync)) { | ||||
| 10079 | return errorResult(); | ||||
| 10080 | } | ||||
| 10081 | MOZ_ASSERT(TokenKindIsPossibleIdentifier(tokenAfterAsync))do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifier(tokenAfterAsync))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(TokenKindIsPossibleIdentifier(tokenAfterAsync)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("TokenKindIsPossibleIdentifier(tokenAfterAsync)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10081); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(tokenAfterAsync)" ")"); do { MOZ_CrashSequence(__null, 10081); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 10082 | |||||
| 10083 | // Check yield validity here. | ||||
| 10084 | TaggedParserAtomIndex name = bindingIdentifier(yieldHandling); | ||||
| 10085 | if (!name) { | ||||
| 10086 | return errorResult(); | ||||
| 10087 | } | ||||
| 10088 | |||||
| 10089 | if (!tokenStream.peekToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)) { | ||||
| 10090 | return errorResult(); | ||||
| 10091 | } | ||||
| 10092 | |||||
| 10093 | isArrow = tokenAfterLHS == TokenKind::Arrow; | ||||
| 10094 | |||||
| 10095 | // |async [no LineTerminator] of| without being followed by => is only | ||||
| 10096 | // possible in for-await-of loops, e.g. |for await (async of [])|. Pretend | ||||
| 10097 | // the |async| token was parsed an identifier reference and then proceed | ||||
| 10098 | // with the rest of this function. | ||||
| 10099 | if (!isArrow) { | ||||
| 10100 | anyChars.ungetToken(); // unget the binding identifier | ||||
| 10101 | |||||
| 10102 | // The next token is guaranteed to never be a Div (, because it's an | ||||
| 10103 | // identifier), so it's okay to re-get the token with SlashIsRegExp. | ||||
| 10104 | anyChars.allowGettingNextTokenWithSlashIsRegExp(); | ||||
| 10105 | |||||
| 10106 | TaggedParserAtomIndex asyncName = identifierReference(yieldHandling); | ||||
| 10107 | if (!asyncName) { | ||||
| 10108 | return errorResult(); | ||||
| 10109 | } | ||||
| 10110 | |||||
| 10111 | lhs = MOZ_TRY(identifierReference(asyncName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (identifierReference(asyncName)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10112 | } | ||||
| 10113 | } else { | ||||
| 10114 | lhs = MOZ_TRY(condExpr(inHandling, yieldHandling, tripledotHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (condExpr(inHandling, yieldHandling, tripledotHandling, & possibleErrorInner, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 10115 | &possibleErrorInner, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (condExpr(inHandling, yieldHandling, tripledotHandling, & possibleErrorInner, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10116 | |||||
| 10117 | // Use SlashIsRegExp here because the ConditionalExpression parsed above | ||||
| 10118 | // could be the entirety of this AssignmentExpression, and then ASI | ||||
| 10119 | // permits this token to be a regular expression. | ||||
| 10120 | if (!tokenStream.peekToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)) { | ||||
| 10121 | return errorResult(); | ||||
| 10122 | } | ||||
| 10123 | |||||
| 10124 | isArrow = tokenAfterLHS == TokenKind::Arrow; | ||||
| 10125 | } | ||||
| 10126 | |||||
| 10127 | if (isArrow) { | ||||
| 10128 | // Rewind to reparse as an arrow function. | ||||
| 10129 | // | ||||
| 10130 | // Note: We do not call CompilationState::rewind here because parsing | ||||
| 10131 | // during delazification will see the same rewind and need the same sequence | ||||
| 10132 | // of inner functions to skip over. | ||||
| 10133 | // Instead, we mark inner functions as "ghost". | ||||
| 10134 | // | ||||
| 10135 | // See GHOST_FUNCTION in FunctionFlags.h for more details. | ||||
| 10136 | tokenStream.rewind(start); | ||||
| 10137 | this->compilationState_.markGhost(ghostToken); | ||||
| 10138 | |||||
| 10139 | TokenKind next; | ||||
| 10140 | if (!tokenStream.getToken(&next, TokenStream::SlashIsRegExp)) { | ||||
| 10141 | return errorResult(); | ||||
| 10142 | } | ||||
| 10143 | TokenPos startPos = pos(); | ||||
| 10144 | uint32_t toStringStart = startPos.begin; | ||||
| 10145 | anyChars.ungetToken(); | ||||
| 10146 | |||||
| 10147 | FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction; | ||||
| 10148 | |||||
| 10149 | if (next == TokenKind::Async) { | ||||
| 10150 | tokenStream.consumeKnownToken(next, TokenStream::SlashIsRegExp); | ||||
| 10151 | |||||
| 10152 | TokenKind nextSameLine = TokenKind::Eof; | ||||
| 10153 | if (!tokenStream.peekTokenSameLine(&nextSameLine)) { | ||||
| 10154 | return errorResult(); | ||||
| 10155 | } | ||||
| 10156 | |||||
| 10157 | // The AsyncArrowFunction production are | ||||
| 10158 | // async [no LineTerminator here] AsyncArrowBindingIdentifier ... | ||||
| 10159 | // async [no LineTerminator here] ArrowFormalParameters ... | ||||
| 10160 | if (TokenKindIsPossibleIdentifier(nextSameLine) || | ||||
| 10161 | nextSameLine == TokenKind::LeftParen) { | ||||
| 10162 | asyncKind = FunctionAsyncKind::AsyncFunction; | ||||
| 10163 | } else { | ||||
| 10164 | anyChars.ungetToken(); | ||||
| 10165 | } | ||||
| 10166 | } | ||||
| 10167 | |||||
| 10168 | FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Arrow; | ||||
| 10169 | FunctionNodeType funNode = | ||||
| 10170 | MOZ_TRY(handler_.newFunction(syntaxKind, startPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, startPos)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10171 | |||||
| 10172 | return functionDefinition(funNode, toStringStart, inHandling, yieldHandling, | ||||
| 10173 | TaggedParserAtomIndex::null(), syntaxKind, | ||||
| 10174 | GeneratorKind::NotGenerator, asyncKind); | ||||
| 10175 | } | ||||
| 10176 | |||||
| 10177 | MOZ_ALWAYS_TRUE(do { if ((__builtin_expect(!!(tokenStream.getToken(&tokenAfterLHS , TokenStream::SlashIsRegExp)), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "tokenStream.getToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10178); AnnotateMozCrashReason ("MOZ_CRASH(" "tokenStream.getToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)" ")"); do { MOZ_CrashSequence(__null, 10178); __attribute__(( nomerge)) ::abort(); } while (false); } while (false); } } while (false) | ||||
| 10178 | tokenStream.getToken(&tokenAfterLHS, TokenStream::SlashIsRegExp))do { if ((__builtin_expect(!!(tokenStream.getToken(&tokenAfterLHS , TokenStream::SlashIsRegExp)), 1))) { } else { do { do { } while (false); MOZ_ReportCrash("" "tokenStream.getToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10178); AnnotateMozCrashReason ("MOZ_CRASH(" "tokenStream.getToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)" ")"); do { MOZ_CrashSequence(__null, 10178); __attribute__(( nomerge)) ::abort(); } while (false); } while (false); } } while (false); | ||||
| 10179 | |||||
| 10180 | ParseNodeKind kind; | ||||
| 10181 | switch (tokenAfterLHS) { | ||||
| 10182 | case TokenKind::Assign: | ||||
| 10183 | kind = ParseNodeKind::AssignExpr; | ||||
| 10184 | break; | ||||
| 10185 | case TokenKind::AddAssign: | ||||
| 10186 | kind = ParseNodeKind::AddAssignExpr; | ||||
| 10187 | break; | ||||
| 10188 | case TokenKind::SubAssign: | ||||
| 10189 | kind = ParseNodeKind::SubAssignExpr; | ||||
| 10190 | break; | ||||
| 10191 | case TokenKind::CoalesceAssign: | ||||
| 10192 | kind = ParseNodeKind::CoalesceAssignExpr; | ||||
| 10193 | break; | ||||
| 10194 | case TokenKind::OrAssign: | ||||
| 10195 | kind = ParseNodeKind::OrAssignExpr; | ||||
| 10196 | break; | ||||
| 10197 | case TokenKind::AndAssign: | ||||
| 10198 | kind = ParseNodeKind::AndAssignExpr; | ||||
| 10199 | break; | ||||
| 10200 | case TokenKind::BitOrAssign: | ||||
| 10201 | kind = ParseNodeKind::BitOrAssignExpr; | ||||
| 10202 | break; | ||||
| 10203 | case TokenKind::BitXorAssign: | ||||
| 10204 | kind = ParseNodeKind::BitXorAssignExpr; | ||||
| 10205 | break; | ||||
| 10206 | case TokenKind::BitAndAssign: | ||||
| 10207 | kind = ParseNodeKind::BitAndAssignExpr; | ||||
| 10208 | break; | ||||
| 10209 | case TokenKind::LshAssign: | ||||
| 10210 | kind = ParseNodeKind::LshAssignExpr; | ||||
| 10211 | break; | ||||
| 10212 | case TokenKind::RshAssign: | ||||
| 10213 | kind = ParseNodeKind::RshAssignExpr; | ||||
| 10214 | break; | ||||
| 10215 | case TokenKind::UrshAssign: | ||||
| 10216 | kind = ParseNodeKind::UrshAssignExpr; | ||||
| 10217 | break; | ||||
| 10218 | case TokenKind::MulAssign: | ||||
| 10219 | kind = ParseNodeKind::MulAssignExpr; | ||||
| 10220 | break; | ||||
| 10221 | case TokenKind::DivAssign: | ||||
| 10222 | kind = ParseNodeKind::DivAssignExpr; | ||||
| 10223 | break; | ||||
| 10224 | case TokenKind::ModAssign: | ||||
| 10225 | kind = ParseNodeKind::ModAssignExpr; | ||||
| 10226 | break; | ||||
| 10227 | case TokenKind::PowAssign: | ||||
| 10228 | kind = ParseNodeKind::PowAssignExpr; | ||||
| 10229 | break; | ||||
| 10230 | |||||
| 10231 | default: | ||||
| 10232 | MOZ_ASSERT(!anyChars.isCurrentTokenAssignment())do { static_assert( mozilla::detail::AssertionConditionType< decltype(!anyChars.isCurrentTokenAssignment())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!anyChars.isCurrentTokenAssignment ()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!anyChars.isCurrentTokenAssignment()", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10232); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!anyChars.isCurrentTokenAssignment()" ")"); do { MOZ_CrashSequence(__null, 10232); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 10233 | if (!possibleError) { | ||||
| 10234 | if (!possibleErrorInner.checkForExpressionError()) { | ||||
| 10235 | return errorResult(); | ||||
| 10236 | } | ||||
| 10237 | } else { | ||||
| 10238 | possibleErrorInner.transferErrorsTo(possibleError); | ||||
| 10239 | } | ||||
| 10240 | |||||
| 10241 | anyChars.ungetToken(); | ||||
| 10242 | return lhs; | ||||
| 10243 | } | ||||
| 10244 | |||||
| 10245 | // Verify the left-hand side expression doesn't have a forbidden form. | ||||
| 10246 | if (handler_.isUnparenthesizedDestructuringPattern(lhs)) { | ||||
| 10247 | if (kind != ParseNodeKind::AssignExpr) { | ||||
| 10248 | error(JSMSG_BAD_DESTRUCT_ASS); | ||||
| 10249 | return errorResult(); | ||||
| 10250 | } | ||||
| 10251 | |||||
| 10252 | if (!possibleErrorInner.checkForDestructuringErrorOrWarning()) { | ||||
| 10253 | return errorResult(); | ||||
| 10254 | } | ||||
| 10255 | } else if (handler_.isName(lhs)) { | ||||
| 10256 | if (const char* chars = nameIsArgumentsOrEval(lhs)) { | ||||
| 10257 | // |chars| is "arguments" or "eval" here. | ||||
| 10258 | if (!strictModeErrorAt(exprPos.begin, JSMSG_BAD_STRICT_ASSIGN, chars)) { | ||||
| 10259 | return errorResult(); | ||||
| 10260 | } | ||||
| 10261 | } | ||||
| 10262 | } else if (handler_.isArgumentsLength(lhs)) { | ||||
| 10263 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 10264 | } else if (handler_.isPropertyOrPrivateMemberAccess(lhs)) { | ||||
| 10265 | // Permitted: no additional testing/fixup needed. | ||||
| 10266 | } else if (handler_.isFunctionCall(lhs)) { | ||||
| 10267 | // We don't have to worry about backward compatibility issues with the new | ||||
| 10268 | // compound assignment operators, so we always throw here. Also that way we | ||||
| 10269 | // don't have to worry if |f() &&= expr| should always throw an error or | ||||
| 10270 | // only if |f()| returns true. | ||||
| 10271 | if (kind == ParseNodeKind::CoalesceAssignExpr || | ||||
| 10272 | kind == ParseNodeKind::OrAssignExpr || | ||||
| 10273 | kind == ParseNodeKind::AndAssignExpr) { | ||||
| 10274 | errorAt(exprPos.begin, JSMSG_BAD_LEFTSIDE_OF_ASS); | ||||
| 10275 | return errorResult(); | ||||
| 10276 | } | ||||
| 10277 | |||||
| 10278 | if (!strictModeErrorAt(exprPos.begin, JSMSG_BAD_LEFTSIDE_OF_ASS)) { | ||||
| 10279 | return errorResult(); | ||||
| 10280 | } | ||||
| 10281 | |||||
| 10282 | if (possibleError) { | ||||
| 10283 | possibleError->setPendingDestructuringErrorAt(exprPos, | ||||
| 10284 | JSMSG_BAD_DESTRUCT_TARGET); | ||||
| 10285 | } | ||||
| 10286 | } else { | ||||
| 10287 | errorAt(exprPos.begin, JSMSG_BAD_LEFTSIDE_OF_ASS); | ||||
| 10288 | return errorResult(); | ||||
| 10289 | } | ||||
| 10290 | |||||
| 10291 | if (!possibleErrorInner.checkForExpressionError()) { | ||||
| 10292 | return errorResult(); | ||||
| 10293 | } | ||||
| 10294 | |||||
| 10295 | Node rhs = | ||||
| 10296 | MOZ_TRY(assignExpr(inHandling, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(inHandling, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10297 | |||||
| 10298 | return handler_.newAssignment(kind, lhs, rhs); | ||||
| 10299 | } | ||||
| 10300 | |||||
| 10301 | template <class ParseHandler> | ||||
| 10302 | const char* PerHandlerParser<ParseHandler>::nameIsArgumentsOrEval(Node node) { | ||||
| 10303 | MOZ_ASSERT(handler_.isName(node),do { static_assert( mozilla::detail::AssertionConditionType< decltype(handler_.isName(node))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(handler_.isName(node)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("handler_.isName(node)" " (" "must only call this function on known names" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10304); AnnotateMozCrashReason("MOZ_ASSERT" "(" "handler_.isName(node)" ") (" "must only call this function on known names" ")"); do { MOZ_CrashSequence(__null, 10304); __attribute__((nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 10304 | "must only call this function on known names")do { static_assert( mozilla::detail::AssertionConditionType< decltype(handler_.isName(node))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(handler_.isName(node)))), 0) )) { do { } while (false); MOZ_ReportAssertionFailure("handler_.isName(node)" " (" "must only call this function on known names" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10304); AnnotateMozCrashReason("MOZ_ASSERT" "(" "handler_.isName(node)" ") (" "must only call this function on known names" ")"); do { MOZ_CrashSequence(__null, 10304); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 10305 | |||||
| 10306 | if (handler_.isEvalName(node)) { | ||||
| 10307 | return "eval"; | ||||
| 10308 | } | ||||
| 10309 | if (handler_.isArgumentsName(node)) { | ||||
| 10310 | return "arguments"; | ||||
| 10311 | } | ||||
| 10312 | return nullptr; | ||||
| 10313 | } | ||||
| 10314 | |||||
| 10315 | template <class ParseHandler, typename Unit> | ||||
| 10316 | bool GeneralParser<ParseHandler, Unit>::checkIncDecOperand( | ||||
| 10317 | Node operand, uint32_t operandOffset) { | ||||
| 10318 | if (handler_.isName(operand)) { | ||||
| 10319 | if (const char* chars = nameIsArgumentsOrEval(operand)) { | ||||
| 10320 | if (!strictModeErrorAt(operandOffset, JSMSG_BAD_STRICT_ASSIGN, chars)) { | ||||
| 10321 | return false; | ||||
| 10322 | } | ||||
| 10323 | } | ||||
| 10324 | } else if (handler_.isArgumentsLength(operand)) { | ||||
| 10325 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 10326 | } else if (handler_.isPropertyOrPrivateMemberAccess(operand)) { | ||||
| 10327 | // Permitted: no additional testing/fixup needed. | ||||
| 10328 | } else if (handler_.isFunctionCall(operand)) { | ||||
| 10329 | // Assignment to function calls is forbidden in ES6. We're still | ||||
| 10330 | // somewhat concerned about sites using this in dead code, so forbid it | ||||
| 10331 | // only in strict mode code. | ||||
| 10332 | if (!strictModeErrorAt(operandOffset, JSMSG_BAD_INCOP_OPERAND)) { | ||||
| 10333 | return false; | ||||
| 10334 | } | ||||
| 10335 | } else { | ||||
| 10336 | errorAt(operandOffset, JSMSG_BAD_INCOP_OPERAND); | ||||
| 10337 | return false; | ||||
| 10338 | } | ||||
| 10339 | return true; | ||||
| 10340 | } | ||||
| 10341 | |||||
| 10342 | template <class ParseHandler, typename Unit> | ||||
| 10343 | typename ParseHandler::UnaryNodeResult | ||||
| 10344 | GeneralParser<ParseHandler, Unit>::unaryOpExpr(YieldHandling yieldHandling, | ||||
| 10345 | ParseNodeKind kind, | ||||
| 10346 | uint32_t begin) { | ||||
| 10347 | Node kid = MOZ_TRY(unaryExpr(yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (unaryExpr(yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10348 | return handler_.newUnary(kind, begin, kid); | ||||
| 10349 | } | ||||
| 10350 | |||||
| 10351 | template <class ParseHandler, typename Unit> | ||||
| 10352 | typename ParseHandler::NodeResult | ||||
| 10353 | GeneralParser<ParseHandler, Unit>::optionalExpr( | ||||
| 10354 | YieldHandling yieldHandling, TripledotHandling tripledotHandling, | ||||
| 10355 | TokenKind tt, PossibleError* possibleError /* = nullptr */, | ||||
| 10356 | InvokedPrediction invoked /* = PredictUninvoked */) { | ||||
| 10357 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 10358 | if (!recursion.check(this->fc_)) { | ||||
| 10359 | return errorResult(); | ||||
| 10360 | } | ||||
| 10361 | |||||
| 10362 | uint32_t begin = pos().begin; | ||||
| 10363 | |||||
| 10364 | Node lhs = | ||||
| 10365 | MOZ_TRY(memberExpr(yieldHandling, tripledotHandling, tt,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberExpr(yieldHandling, tripledotHandling, tt, true, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10366 | /* allowCallSyntax = */ true, possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberExpr(yieldHandling, tripledotHandling, tt, true, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10367 | |||||
| 10368 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsDiv)) { | ||||
| 10369 | return errorResult(); | ||||
| 10370 | } | ||||
| 10371 | |||||
| 10372 | if (tt != TokenKind::OptionalChain) { | ||||
| 10373 | return lhs; | ||||
| 10374 | } | ||||
| 10375 | |||||
| 10376 | while (true) { | ||||
| 10377 | if (!tokenStream.getToken(&tt)) { | ||||
| 10378 | return errorResult(); | ||||
| 10379 | } | ||||
| 10380 | |||||
| 10381 | if (tt == TokenKind::Eof) { | ||||
| 10382 | anyChars.ungetToken(); | ||||
| 10383 | break; | ||||
| 10384 | } | ||||
| 10385 | |||||
| 10386 | Node nextMember; | ||||
| 10387 | if (tt == TokenKind::OptionalChain) { | ||||
| 10388 | if (!tokenStream.getToken(&tt)) { | ||||
| 10389 | return errorResult(); | ||||
| 10390 | } | ||||
| 10391 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 10392 | nextMember = MOZ_TRY(memberPropertyAccess(lhs, OptionalKind::Optional))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPropertyAccess(lhs, OptionalKind::Optional)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10393 | } else if (tt == TokenKind::PrivateName) { | ||||
| 10394 | nextMember = MOZ_TRY(memberPrivateAccess(lhs, OptionalKind::Optional))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPrivateAccess(lhs, OptionalKind::Optional)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10395 | } else if (tt == TokenKind::LeftBracket) { | ||||
| 10396 | nextMember = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberElemAccess(lhs, yieldHandling, OptionalKind::Optional) ); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)) ) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10397 | memberElemAccess(lhs, yieldHandling, OptionalKind::Optional))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberElemAccess(lhs, yieldHandling, OptionalKind::Optional) ); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)) ) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10398 | } else if (tt == TokenKind::LeftParen) { | ||||
| 10399 | nextMember = MOZ_TRY(memberCall(tt, lhs, yieldHandling, possibleError,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberCall(tt, lhs, yieldHandling, possibleError, OptionalKind ::Optional)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10400 | OptionalKind::Optional))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberCall(tt, lhs, yieldHandling, possibleError, OptionalKind ::Optional)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10401 | } else { | ||||
| 10402 | error(JSMSG_NAME_AFTER_DOT); | ||||
| 10403 | return errorResult(); | ||||
| 10404 | } | ||||
| 10405 | } else if (tt == TokenKind::Dot) { | ||||
| 10406 | if (!tokenStream.getToken(&tt)) { | ||||
| 10407 | return errorResult(); | ||||
| 10408 | } | ||||
| 10409 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 10410 | nextMember = MOZ_TRY(memberPropertyAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPropertyAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10411 | } else if (tt == TokenKind::PrivateName) { | ||||
| 10412 | nextMember = MOZ_TRY(memberPrivateAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPrivateAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10413 | } else { | ||||
| 10414 | error(JSMSG_NAME_AFTER_DOT); | ||||
| 10415 | return errorResult(); | ||||
| 10416 | } | ||||
| 10417 | } else if (tt == TokenKind::LeftBracket) { | ||||
| 10418 | nextMember = MOZ_TRY(memberElemAccess(lhs, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberElemAccess(lhs, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10419 | } else if (tt == TokenKind::LeftParen) { | ||||
| 10420 | nextMember = MOZ_TRY(memberCall(tt, lhs, yieldHandling, possibleError))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberCall(tt, lhs, yieldHandling, possibleError)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10421 | } else if (tt == TokenKind::TemplateHead || | ||||
| 10422 | tt == TokenKind::NoSubsTemplate) { | ||||
| 10423 | error(JSMSG_BAD_OPTIONAL_TEMPLATE); | ||||
| 10424 | return errorResult(); | ||||
| 10425 | } else { | ||||
| 10426 | anyChars.ungetToken(); | ||||
| 10427 | break; | ||||
| 10428 | } | ||||
| 10429 | |||||
| 10430 | MOZ_ASSERT(nextMember)do { static_assert( mozilla::detail::AssertionConditionType< decltype(nextMember)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(nextMember))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("nextMember", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10430); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nextMember" ")"); do { MOZ_CrashSequence(__null, 10430); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 10431 | lhs = nextMember; | ||||
| 10432 | } | ||||
| 10433 | |||||
| 10434 | return handler_.newOptionalChain(begin, lhs); | ||||
| 10435 | } | ||||
| 10436 | |||||
| 10437 | template <class ParseHandler, typename Unit> | ||||
| 10438 | typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::unaryExpr( | ||||
| 10439 | YieldHandling yieldHandling, TripledotHandling tripledotHandling, | ||||
| 10440 | PossibleError* possibleError /* = nullptr */, | ||||
| 10441 | InvokedPrediction invoked /* = PredictUninvoked */, | ||||
| 10442 | PrivateNameHandling privateNameHandling /* = PrivateNameProhibited */) { | ||||
| 10443 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 10444 | if (!recursion.check(this->fc_)) { | ||||
| 10445 | return errorResult(); | ||||
| 10446 | } | ||||
| 10447 | |||||
| 10448 | TokenKind tt; | ||||
| 10449 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 10450 | return errorResult(); | ||||
| 10451 | } | ||||
| 10452 | uint32_t begin = pos().begin; | ||||
| 10453 | switch (tt) { | ||||
| 10454 | case TokenKind::Void: | ||||
| 10455 | return unaryOpExpr(yieldHandling, ParseNodeKind::VoidExpr, begin); | ||||
| 10456 | case TokenKind::Not: | ||||
| 10457 | return unaryOpExpr(yieldHandling, ParseNodeKind::NotExpr, begin); | ||||
| 10458 | case TokenKind::BitNot: | ||||
| 10459 | return unaryOpExpr(yieldHandling, ParseNodeKind::BitNotExpr, begin); | ||||
| 10460 | case TokenKind::Add: | ||||
| 10461 | return unaryOpExpr(yieldHandling, ParseNodeKind::PosExpr, begin); | ||||
| 10462 | case TokenKind::Sub: | ||||
| 10463 | return unaryOpExpr(yieldHandling, ParseNodeKind::NegExpr, begin); | ||||
| 10464 | |||||
| 10465 | case TokenKind::TypeOf: { | ||||
| 10466 | // The |typeof| operator is specially parsed to distinguish its | ||||
| 10467 | // application to a name, from its application to a non-name | ||||
| 10468 | // expression: | ||||
| 10469 | // | ||||
| 10470 | // // Looks up the name, doesn't find it and so evaluates to | ||||
| 10471 | // // "undefined". | ||||
| 10472 | // assertEq(typeof nonExistentName, "undefined"); | ||||
| 10473 | // | ||||
| 10474 | // // Evaluates expression, triggering a runtime ReferenceError for | ||||
| 10475 | // // the undefined name. | ||||
| 10476 | // typeof (1, nonExistentName); | ||||
| 10477 | Node kid = MOZ_TRY(unaryExpr(yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (unaryExpr(yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10478 | |||||
| 10479 | return handler_.newTypeof(begin, kid); | ||||
| 10480 | } | ||||
| 10481 | |||||
| 10482 | case TokenKind::Inc: | ||||
| 10483 | case TokenKind::Dec: { | ||||
| 10484 | TokenKind tt2; | ||||
| 10485 | if (!tokenStream.getToken(&tt2, TokenStream::SlashIsRegExp)) { | ||||
| 10486 | return errorResult(); | ||||
| 10487 | } | ||||
| 10488 | |||||
| 10489 | uint32_t operandOffset = pos().begin; | ||||
| 10490 | Node operand = | ||||
| 10491 | MOZ_TRY(optionalExpr(yieldHandling, TripledotProhibited, tt2))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (optionalExpr(yieldHandling, TripledotProhibited, tt2)); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 10492 | if (!checkIncDecOperand(operand, operandOffset)) { | ||||
| 10493 | return errorResult(); | ||||
| 10494 | } | ||||
| 10495 | ParseNodeKind pnk = (tt == TokenKind::Inc) | ||||
| 10496 | ? ParseNodeKind::PreIncrementExpr | ||||
| 10497 | : ParseNodeKind::PreDecrementExpr; | ||||
| 10498 | return handler_.newUpdate(pnk, begin, operand); | ||||
| 10499 | } | ||||
| 10500 | case TokenKind::PrivateName: { | ||||
| 10501 | if (privateNameHandling == PrivateNameHandling::PrivateNameAllowed) { | ||||
| 10502 | TaggedParserAtomIndex field = anyChars.currentName(); | ||||
| 10503 | return privateNameReference(field); | ||||
| 10504 | } | ||||
| 10505 | error(JSMSG_INVALID_PRIVATE_NAME_IN_UNARY_EXPR); | ||||
| 10506 | return errorResult(); | ||||
| 10507 | } | ||||
| 10508 | |||||
| 10509 | case TokenKind::Delete: { | ||||
| 10510 | uint32_t exprOffset; | ||||
| 10511 | if (!tokenStream.peekOffset(&exprOffset, TokenStream::SlashIsRegExp)) { | ||||
| 10512 | return errorResult(); | ||||
| 10513 | } | ||||
| 10514 | |||||
| 10515 | Node expr = MOZ_TRY(unaryExpr(yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (unaryExpr(yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10516 | |||||
| 10517 | // Per spec, deleting most unary expressions is valid -- it simply | ||||
| 10518 | // returns true -- except for two cases: | ||||
| 10519 | // 1. `var x; ...; delete x` is a syntax error in strict mode. | ||||
| 10520 | // 2. Private fields cannot be deleted. | ||||
| 10521 | if (handler_.isName(expr)) { | ||||
| 10522 | if (!strictModeErrorAt(exprOffset, JSMSG_DEPRECATED_DELETE_OPERAND)) { | ||||
| 10523 | return errorResult(); | ||||
| 10524 | } | ||||
| 10525 | |||||
| 10526 | pc_->sc()->setBindingsAccessedDynamically(); | ||||
| 10527 | } | ||||
| 10528 | |||||
| 10529 | if (handler_.isPrivateMemberAccess(expr)) { | ||||
| 10530 | errorAt(exprOffset, JSMSG_PRIVATE_DELETE); | ||||
| 10531 | return errorResult(); | ||||
| 10532 | } | ||||
| 10533 | |||||
| 10534 | if (handler_.isArgumentsLength(expr)) { | ||||
| 10535 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 10536 | } | ||||
| 10537 | |||||
| 10538 | return handler_.newDelete(begin, expr); | ||||
| 10539 | } | ||||
| 10540 | case TokenKind::Await: { | ||||
| 10541 | // If we encounter an await in a module, mark it as async. | ||||
| 10542 | if (!pc_->isAsync() && pc_->sc()->isModule()) { | ||||
| 10543 | if (!options().topLevelAwait) { | ||||
| 10544 | error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED); | ||||
| 10545 | return errorResult(); | ||||
| 10546 | } | ||||
| 10547 | pc_->sc()->asModuleContext()->setIsAsync(); | ||||
| 10548 | MOZ_ASSERT(pc_->isAsync())do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->isAsync())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(pc_->isAsync()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->isAsync()" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10548); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence (__null, 10548); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 10549 | } | ||||
| 10550 | |||||
| 10551 | if (pc_->isAsync()) { | ||||
| 10552 | if (inParametersOfAsyncFunction()) { | ||||
| 10553 | error(JSMSG_AWAIT_IN_PARAMETER); | ||||
| 10554 | return errorResult(); | ||||
| 10555 | } | ||||
| 10556 | Node kid = MOZ_TRY(unaryExpr(yieldHandling, tripledotHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10557 | possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10558 | pc_->lastAwaitOffset = begin; | ||||
| 10559 | return handler_.newAwaitExpression(begin, kid); | ||||
| 10560 | } | ||||
| 10561 | } | ||||
| 10562 | |||||
| 10563 | [[fallthrough]]; | ||||
| 10564 | |||||
| 10565 | default: { | ||||
| 10566 | Node expr = MOZ_TRY(optionalExpr(yieldHandling, tripledotHandling, tt,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (optionalExpr(yieldHandling, tripledotHandling, tt, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10567 | possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (optionalExpr(yieldHandling, tripledotHandling, tt, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10568 | |||||
| 10569 | /* Don't look across a newline boundary for a postfix incop. */ | ||||
| 10570 | if (!tokenStream.peekTokenSameLine(&tt)) { | ||||
| 10571 | return errorResult(); | ||||
| 10572 | } | ||||
| 10573 | |||||
| 10574 | if (tt != TokenKind::Inc && tt != TokenKind::Dec) { | ||||
| 10575 | return expr; | ||||
| 10576 | } | ||||
| 10577 | |||||
| 10578 | tokenStream.consumeKnownToken(tt); | ||||
| 10579 | if (!checkIncDecOperand(expr, begin)) { | ||||
| 10580 | return errorResult(); | ||||
| 10581 | } | ||||
| 10582 | |||||
| 10583 | ParseNodeKind pnk = (tt == TokenKind::Inc) | ||||
| 10584 | ? ParseNodeKind::PostIncrementExpr | ||||
| 10585 | : ParseNodeKind::PostDecrementExpr; | ||||
| 10586 | return handler_.newUpdate(pnk, begin, expr); | ||||
| 10587 | } | ||||
| 10588 | } | ||||
| 10589 | } | ||||
| 10590 | |||||
| 10591 | template <class ParseHandler, typename Unit> | ||||
| 10592 | typename ParseHandler::NodeResult | ||||
| 10593 | GeneralParser<ParseHandler, Unit>::assignExprWithoutYieldOrAwait( | ||||
| 10594 | YieldHandling yieldHandling) { | ||||
| 10595 | uint32_t startYieldOffset = pc_->lastYieldOffset; | ||||
| 10596 | uint32_t startAwaitOffset = pc_->lastAwaitOffset; | ||||
| 10597 | |||||
| 10598 | Node res = MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 10599 | |||||
| 10600 | if (pc_->lastYieldOffset != startYieldOffset) { | ||||
| 10601 | errorAt(pc_->lastYieldOffset, JSMSG_YIELD_IN_PARAMETER); | ||||
| 10602 | return errorResult(); | ||||
| 10603 | } | ||||
| 10604 | if (pc_->lastAwaitOffset != startAwaitOffset) { | ||||
| 10605 | errorAt(pc_->lastAwaitOffset, JSMSG_AWAIT_IN_PARAMETER); | ||||
| 10606 | return errorResult(); | ||||
| 10607 | } | ||||
| 10608 | return res; | ||||
| 10609 | } | ||||
| 10610 | |||||
| 10611 | template <class ParseHandler, typename Unit> | ||||
| 10612 | typename ParseHandler::ListNodeResult | ||||
| 10613 | GeneralParser<ParseHandler, Unit>::argumentList( | ||||
| 10614 | YieldHandling yieldHandling, bool* isSpread, | ||||
| 10615 | PossibleError* possibleError /* = nullptr */) { | ||||
| 10616 | ListNodeType argsList = MOZ_TRY(handler_.newArguments(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newArguments(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10617 | |||||
| 10618 | bool matched; | ||||
| 10619 | if (!tokenStream.matchToken(&matched, TokenKind::RightParen, | ||||
| 10620 | TokenStream::SlashIsRegExp)) { | ||||
| 10621 | return errorResult(); | ||||
| 10622 | } | ||||
| 10623 | if (matched) { | ||||
| 10624 | handler_.setEndPosition(argsList, pos().end); | ||||
| 10625 | return argsList; | ||||
| 10626 | } | ||||
| 10627 | |||||
| 10628 | while (true) { | ||||
| 10629 | bool spread = false; | ||||
| 10630 | uint32_t begin = 0; | ||||
| 10631 | if (!tokenStream.matchToken(&matched, TokenKind::TripleDot, | ||||
| 10632 | TokenStream::SlashIsRegExp)) { | ||||
| 10633 | return errorResult(); | ||||
| 10634 | } | ||||
| 10635 | if (matched) { | ||||
| 10636 | spread = true; | ||||
| 10637 | begin = pos().begin; | ||||
| 10638 | *isSpread = true; | ||||
| 10639 | } | ||||
| 10640 | |||||
| 10641 | Node argNode = MOZ_TRY(assignExpr(InAllowed, yieldHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, possibleError )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10642 | TripledotProhibited, possibleError))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, possibleError )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10643 | if (spread) { | ||||
| 10644 | argNode = MOZ_TRY(handler_.newSpread(begin, argNode))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newSpread(begin, argNode)); if ((__builtin_expect(! !(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10645 | } | ||||
| 10646 | |||||
| 10647 | handler_.addList(argsList, argNode); | ||||
| 10648 | |||||
| 10649 | bool matched; | ||||
| 10650 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 10651 | TokenStream::SlashIsRegExp)) { | ||||
| 10652 | return errorResult(); | ||||
| 10653 | } | ||||
| 10654 | if (!matched) { | ||||
| 10655 | break; | ||||
| 10656 | } | ||||
| 10657 | |||||
| 10658 | TokenKind tt; | ||||
| 10659 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 10660 | return errorResult(); | ||||
| 10661 | } | ||||
| 10662 | if (tt == TokenKind::RightParen) { | ||||
| 10663 | break; | ||||
| 10664 | } | ||||
| 10665 | } | ||||
| 10666 | |||||
| 10667 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_ARGS)) { | ||||
| 10668 | return errorResult(); | ||||
| 10669 | } | ||||
| 10670 | |||||
| 10671 | handler_.setEndPosition(argsList, pos().end); | ||||
| 10672 | return argsList; | ||||
| 10673 | } | ||||
| 10674 | |||||
| 10675 | bool ParserBase::checkAndMarkSuperScope() { | ||||
| 10676 | if (!pc_->sc()->allowSuperProperty()) { | ||||
| 10677 | return false; | ||||
| 10678 | } | ||||
| 10679 | |||||
| 10680 | pc_->setSuperScopeNeedsHomeObject(); | ||||
| 10681 | return true; | ||||
| 10682 | } | ||||
| 10683 | |||||
| 10684 | template <class ParseHandler, typename Unit> | ||||
| 10685 | bool GeneralParser<ParseHandler, Unit>::computeErrorMetadata( | ||||
| 10686 | ErrorMetadata* err, const ErrorReportMixin::ErrorOffset& offset) const { | ||||
| 10687 | if (offset.is<ErrorReportMixin::Current>()) { | ||||
| 10688 | return tokenStream.computeErrorMetadata(err, AsVariant(pos().begin)); | ||||
| 10689 | } | ||||
| 10690 | return tokenStream.computeErrorMetadata(err, offset); | ||||
| 10691 | } | ||||
| 10692 | |||||
| 10693 | template <class ParseHandler, typename Unit> | ||||
| 10694 | typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::memberExpr( | ||||
| 10695 | YieldHandling yieldHandling, TripledotHandling tripledotHandling, | ||||
| 10696 | TokenKind tt, bool allowCallSyntax, PossibleError* possibleError, | ||||
| 10697 | InvokedPrediction invoked) { | ||||
| 10698 | MOZ_ASSERT(anyChars.isCurrentTokenType(tt))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(tt))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( tt)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(tt)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10698); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)" ")"); do { MOZ_CrashSequence(__null, 10698); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| |||||
| 10699 | |||||
| 10700 | Node lhs; | ||||
| 10701 | |||||
| 10702 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 10703 | if (!recursion.check(this->fc_)) { | ||||
| 10704 | return errorResult(); | ||||
| 10705 | } | ||||
| 10706 | |||||
| 10707 | /* Check for new expression first. */ | ||||
| 10708 | if (tt == TokenKind::New) { | ||||
| 10709 | uint32_t newBegin = pos().begin; | ||||
| 10710 | // Make sure this wasn't a |new.target| in disguise. | ||||
| 10711 | NewTargetNodeType newTarget; | ||||
| 10712 | if (!tryNewTarget(&newTarget)) { | ||||
| 10713 | return errorResult(); | ||||
| 10714 | } | ||||
| 10715 | if (newTarget) { | ||||
| 10716 | lhs = newTarget; | ||||
| 10717 | } else { | ||||
| 10718 | // Gotten by tryNewTarget | ||||
| 10719 | tt = anyChars.currentToken().type; | ||||
| 10720 | Node ctorExpr = | ||||
| 10721 | MOZ_TRY(memberExpr(yieldHandling, TripledotProhibited, tt,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberExpr(yieldHandling, TripledotProhibited, tt, false, nullptr , PredictInvoked)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 10722 | /* allowCallSyntax = */ false,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberExpr(yieldHandling, TripledotProhibited, tt, false, nullptr , PredictInvoked)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 10723 | /* possibleError = */ nullptr, PredictInvoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberExpr(yieldHandling, TripledotProhibited, tt, false, nullptr , PredictInvoked)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10724 | |||||
| 10725 | // If we have encountered an optional chain, in the form of `new | ||||
| 10726 | // ClassName?.()` then we need to throw, as this is disallowed by the | ||||
| 10727 | // spec. | ||||
| 10728 | bool optionalToken; | ||||
| 10729 | if (!tokenStream.matchToken(&optionalToken, TokenKind::OptionalChain)) { | ||||
| 10730 | return errorResult(); | ||||
| 10731 | } | ||||
| 10732 | if (optionalToken) { | ||||
| 10733 | errorAt(newBegin, JSMSG_BAD_NEW_OPTIONAL); | ||||
| 10734 | return errorResult(); | ||||
| 10735 | } | ||||
| 10736 | |||||
| 10737 | bool matched; | ||||
| 10738 | if (!tokenStream.matchToken(&matched, TokenKind::LeftParen)) { | ||||
| 10739 | return errorResult(); | ||||
| 10740 | } | ||||
| 10741 | |||||
| 10742 | bool isSpread = false; | ||||
| 10743 | ListNodeType args; | ||||
| 10744 | if (matched) { | ||||
| 10745 | args = MOZ_TRY(argumentList(yieldHandling, &isSpread))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (argumentList(yieldHandling, &isSpread)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10746 | } else { | ||||
| 10747 | args = MOZ_TRY(handler_.newArguments(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newArguments(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10748 | } | ||||
| 10749 | |||||
| 10750 | if (!args) { | ||||
| 10751 | return errorResult(); | ||||
| 10752 | } | ||||
| 10753 | |||||
| 10754 | lhs = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newNewExpression(newBegin, ctorExpr, args, isSpread )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10755 | handler_.newNewExpression(newBegin, ctorExpr, args, isSpread))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newNewExpression(newBegin, ctorExpr, args, isSpread )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10756 | } | ||||
| 10757 | } else if (tt == TokenKind::Super) { | ||||
| 10758 | NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10759 | lhs = MOZ_TRY(handler_.newSuperBase(thisName, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newSuperBase(thisName, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10760 | } else if (tt == TokenKind::Import) { | ||||
| 10761 | lhs = MOZ_TRY(importExpr(yieldHandling, allowCallSyntax))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (importExpr(yieldHandling, allowCallSyntax)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10762 | } else { | ||||
| 10763 | lhs = MOZ_TRY(primaryExpr(yieldHandling, tripledotHandling, tt,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (primaryExpr(yieldHandling, tripledotHandling, tt, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10764 | possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (primaryExpr(yieldHandling, tripledotHandling, tt, possibleError , invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10765 | } | ||||
| 10766 | |||||
| 10767 | MOZ_ASSERT_IF(handler_.isSuperBase(lhs),do { if (handler_.isSuperBase(lhs)) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(anyChars.isCurrentTokenType (TokenKind::Super))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::Super)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::Super)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10768); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Super)" ")"); do { MOZ_CrashSequence(__null, 10768); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); } } while (false) | ||||
| 10768 | anyChars.isCurrentTokenType(TokenKind::Super))do { if (handler_.isSuperBase(lhs)) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(anyChars.isCurrentTokenType (TokenKind::Super))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( TokenKind::Super)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(TokenKind::Super)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10768); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Super)" ")"); do { MOZ_CrashSequence(__null, 10768); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); } } while (false); | ||||
| 10769 | |||||
| 10770 | while (true) { | ||||
| 10771 | if (!tokenStream.getToken(&tt)) { | ||||
| 10772 | return errorResult(); | ||||
| 10773 | } | ||||
| 10774 | if (tt == TokenKind::Eof) { | ||||
| 10775 | anyChars.ungetToken(); | ||||
| 10776 | break; | ||||
| 10777 | } | ||||
| 10778 | |||||
| 10779 | Node nextMember; | ||||
| 10780 | if (tt == TokenKind::Dot) { | ||||
| 10781 | if (!tokenStream.getToken(&tt)) { | ||||
| 10782 | return errorResult(); | ||||
| 10783 | } | ||||
| 10784 | |||||
| 10785 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 10786 | nextMember = MOZ_TRY(memberPropertyAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPropertyAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10787 | } else if (tt == TokenKind::PrivateName) { | ||||
| 10788 | nextMember = MOZ_TRY(memberPrivateAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPrivateAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10789 | } else { | ||||
| 10790 | error(JSMSG_NAME_AFTER_DOT); | ||||
| 10791 | return errorResult(); | ||||
| 10792 | } | ||||
| 10793 | } else if (tt == TokenKind::LeftBracket) { | ||||
| 10794 | nextMember = MOZ_TRY(memberElemAccess(lhs, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberElemAccess(lhs, yieldHandling)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10795 | } else if ((allowCallSyntax && tt == TokenKind::LeftParen) || | ||||
| 10796 | tt == TokenKind::TemplateHead || | ||||
| 10797 | tt == TokenKind::NoSubsTemplate) { | ||||
| 10798 | if (handler_.isSuperBase(lhs)) { | ||||
| 10799 | if (!pc_->sc()->allowSuperCall()) { | ||||
| 10800 | error(JSMSG_BAD_SUPERCALL); | ||||
| 10801 | return errorResult(); | ||||
| 10802 | } | ||||
| 10803 | |||||
| 10804 | if (tt != TokenKind::LeftParen) { | ||||
| 10805 | error(JSMSG_BAD_SUPER); | ||||
| 10806 | return errorResult(); | ||||
| 10807 | } | ||||
| 10808 | |||||
| 10809 | nextMember = MOZ_TRY(memberSuperCall(lhs, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberSuperCall(lhs, yieldHandling)); if ((__builtin_expect( !!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10810 | |||||
| 10811 | if (!noteUsedName( | ||||
| 10812 | TaggedParserAtomIndex::WellKnown::dot_initializers_())) { | ||||
| 10813 | return errorResult(); | ||||
| 10814 | } | ||||
| 10815 | #ifdef ENABLE_DECORATORS | ||||
| 10816 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown:: | ||||
| 10817 | dot_instanceExtraInitializers_())) { | ||||
| 10818 | return errorResult(); | ||||
| 10819 | } | ||||
| 10820 | #endif | ||||
| 10821 | } else { | ||||
| 10822 | nextMember = MOZ_TRY(memberCall(tt, lhs, yieldHandling, possibleError))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberCall(tt, lhs, yieldHandling, possibleError)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10823 | } | ||||
| 10824 | } else { | ||||
| 10825 | anyChars.ungetToken(); | ||||
| 10826 | if (handler_.isSuperBase(lhs)) { | ||||
| 10827 | break; | ||||
| 10828 | } | ||||
| 10829 | return lhs; | ||||
| 10830 | } | ||||
| 10831 | |||||
| 10832 | lhs = nextMember; | ||||
| 10833 | } | ||||
| 10834 | |||||
| 10835 | if (handler_.isSuperBase(lhs)) { | ||||
| 10836 | error(JSMSG_BAD_SUPER); | ||||
| 10837 | return errorResult(); | ||||
| 10838 | } | ||||
| 10839 | |||||
| 10840 | return lhs; | ||||
| 10841 | } | ||||
| 10842 | |||||
| 10843 | template <class ParseHandler, typename Unit> | ||||
| 10844 | typename ParseHandler::NodeResult | ||||
| 10845 | GeneralParser<ParseHandler, Unit>::decoratorExpr(YieldHandling yieldHandling, | ||||
| 10846 | TokenKind tt) { | ||||
| 10847 | MOZ_ASSERT(anyChars.isCurrentTokenType(tt))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(tt))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( tt)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(tt)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10847); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)" ")"); do { MOZ_CrashSequence(__null, 10847); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 10848 | |||||
| 10849 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 10850 | if (!recursion.check(this->fc_)) { | ||||
| 10851 | return errorResult(); | ||||
| 10852 | } | ||||
| 10853 | |||||
| 10854 | if (tt == TokenKind::LeftParen) { | ||||
| 10855 | // DecoratorParenthesizedExpression | ||||
| 10856 | Node expr = MOZ_TRY(exprInParens(InAllowed, yieldHandling, TripledotAllowed,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (exprInParens(InAllowed, yieldHandling, TripledotAllowed, nullptr )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 10857 | /* possibleError*/ nullptr))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (exprInParens(InAllowed, yieldHandling, TripledotAllowed, nullptr )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 10858 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_DECORATOR)) { | ||||
| 10859 | return errorResult(); | ||||
| 10860 | } | ||||
| 10861 | |||||
| 10862 | return handler_.parenthesize(expr); | ||||
| 10863 | } | ||||
| 10864 | |||||
| 10865 | if (!TokenKindIsPossibleIdentifier(tt)) { | ||||
| 10866 | error(JSMSG_DECORATOR_NAME_EXPECTED); | ||||
| 10867 | return errorResult(); | ||||
| 10868 | } | ||||
| 10869 | |||||
| 10870 | TaggedParserAtomIndex name = identifierReference(yieldHandling); | ||||
| 10871 | if (!name) { | ||||
| 10872 | return errorResult(); | ||||
| 10873 | } | ||||
| 10874 | |||||
| 10875 | Node lhs = MOZ_TRY(identifierReference(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (identifierReference(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10876 | |||||
| 10877 | while (true) { | ||||
| 10878 | if (!tokenStream.getToken(&tt)) { | ||||
| 10879 | return errorResult(); | ||||
| 10880 | } | ||||
| 10881 | if (tt == TokenKind::Eof) { | ||||
| 10882 | anyChars.ungetToken(); | ||||
| 10883 | break; | ||||
| 10884 | } | ||||
| 10885 | |||||
| 10886 | Node nextMember; | ||||
| 10887 | if (tt == TokenKind::Dot) { | ||||
| 10888 | if (!tokenStream.getToken(&tt)) { | ||||
| 10889 | return errorResult(); | ||||
| 10890 | } | ||||
| 10891 | |||||
| 10892 | if (TokenKindIsPossibleIdentifierName(tt)) { | ||||
| 10893 | nextMember = MOZ_TRY(memberPropertyAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPropertyAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10894 | } else if (tt == TokenKind::PrivateName) { | ||||
| 10895 | nextMember = MOZ_TRY(memberPrivateAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberPrivateAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10896 | } else { | ||||
| 10897 | error(JSMSG_NAME_AFTER_DOT); | ||||
| 10898 | return errorResult(); | ||||
| 10899 | } | ||||
| 10900 | } else if (tt == TokenKind::LeftParen) { | ||||
| 10901 | nextMember = MOZ_TRY(memberCall(tt, lhs, yieldHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberCall(tt, lhs, yieldHandling, nullptr)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 10902 | /* possibleError */ nullptr))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (memberCall(tt, lhs, yieldHandling, nullptr)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10903 | lhs = nextMember; | ||||
| 10904 | // This is a `DecoratorCallExpression` and it's defined at the top level | ||||
| 10905 | // of `Decorator`, no other `DecoratorMemberExpression` is allowed to | ||||
| 10906 | // follow after the arguments. | ||||
| 10907 | break; | ||||
| 10908 | } else { | ||||
| 10909 | anyChars.ungetToken(); | ||||
| 10910 | break; | ||||
| 10911 | } | ||||
| 10912 | |||||
| 10913 | lhs = nextMember; | ||||
| 10914 | } | ||||
| 10915 | |||||
| 10916 | return lhs; | ||||
| 10917 | } | ||||
| 10918 | |||||
| 10919 | template <class ParseHandler> | ||||
| 10920 | inline typename ParseHandler::NameNodeResult | ||||
| 10921 | PerHandlerParser<ParseHandler>::newName(TaggedParserAtomIndex name) { | ||||
| 10922 | return newName(name, pos()); | ||||
| 10923 | } | ||||
| 10924 | |||||
| 10925 | template <class ParseHandler> | ||||
| 10926 | inline typename ParseHandler::NameNodeResult | ||||
| 10927 | PerHandlerParser<ParseHandler>::newName(TaggedParserAtomIndex name, | ||||
| 10928 | TokenPos pos) { | ||||
| 10929 | if (name == TaggedParserAtomIndex::WellKnown::arguments()) { | ||||
| 10930 | this->pc_->numberOfArgumentsNames++; | ||||
| 10931 | } | ||||
| 10932 | return handler_.newName(name, pos); | ||||
| 10933 | } | ||||
| 10934 | |||||
| 10935 | template <class ParseHandler> | ||||
| 10936 | inline typename ParseHandler::NameNodeResult | ||||
| 10937 | PerHandlerParser<ParseHandler>::newPrivateName(TaggedParserAtomIndex name) { | ||||
| 10938 | return handler_.newPrivateName(name, pos()); | ||||
| 10939 | } | ||||
| 10940 | |||||
| 10941 | template <class ParseHandler, typename Unit> | ||||
| 10942 | typename ParseHandler::NodeResult | ||||
| 10943 | GeneralParser<ParseHandler, Unit>::memberPropertyAccess( | ||||
| 10944 | Node lhs, OptionalKind optionalKind /* = OptionalKind::NonOptional */) { | ||||
| 10945 | MOZ_ASSERT(TokenKindIsPossibleIdentifierName(anyChars.currentToken().type) ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifierName(anyChars.currentToken ().type) || anyChars.currentToken().type == TokenKind::PrivateName )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(TokenKindIsPossibleIdentifierName(anyChars.currentToken ().type) || anyChars.currentToken().type == TokenKind::PrivateName ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "TokenKindIsPossibleIdentifierName(anyChars.currentToken().type) || anyChars.currentToken().type == TokenKind::PrivateName" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10946); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(anyChars.currentToken().type) || anyChars.currentToken().type == TokenKind::PrivateName" ")"); do { MOZ_CrashSequence(__null, 10946); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false) | ||||
| 10946 | anyChars.currentToken().type == TokenKind::PrivateName)do { static_assert( mozilla::detail::AssertionConditionType< decltype(TokenKindIsPossibleIdentifierName(anyChars.currentToken ().type) || anyChars.currentToken().type == TokenKind::PrivateName )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(TokenKindIsPossibleIdentifierName(anyChars.currentToken ().type) || anyChars.currentToken().type == TokenKind::PrivateName ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "TokenKindIsPossibleIdentifierName(anyChars.currentToken().type) || anyChars.currentToken().type == TokenKind::PrivateName" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10946); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(anyChars.currentToken().type) || anyChars.currentToken().type == TokenKind::PrivateName" ")"); do { MOZ_CrashSequence(__null, 10946); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 10947 | TaggedParserAtomIndex field = anyChars.currentName(); | ||||
| 10948 | if (handler_.isSuperBase(lhs) && !checkAndMarkSuperScope()) { | ||||
| 10949 | error(JSMSG_BAD_SUPERPROP, "property"); | ||||
| 10950 | return errorResult(); | ||||
| 10951 | } | ||||
| 10952 | |||||
| 10953 | NameNodeType name = MOZ_TRY(handler_.newPropertyName(field, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyName(field, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10954 | |||||
| 10955 | if (optionalKind == OptionalKind::Optional) { | ||||
| 10956 | MOZ_ASSERT(!handler_.isSuperBase(lhs))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!handler_.isSuperBase(lhs))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!handler_.isSuperBase(lhs))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!handler_.isSuperBase(lhs)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10956); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!handler_.isSuperBase(lhs)" ")"); do { MOZ_CrashSequence (__null, 10956); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 10957 | return handler_.newOptionalPropertyAccess(lhs, name); | ||||
| 10958 | } | ||||
| 10959 | |||||
| 10960 | if (handler_.isArgumentsName(lhs) && handler_.isLengthName(name)) { | ||||
| 10961 | MOZ_ASSERT(pc_->numberOfArgumentsNames > 0)do { static_assert( mozilla::detail::AssertionConditionType< decltype(pc_->numberOfArgumentsNames > 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(! !(pc_->numberOfArgumentsNames > 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("pc_->numberOfArgumentsNames > 0" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10961); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "pc_->numberOfArgumentsNames > 0" ")" ); do { MOZ_CrashSequence(__null, 10961); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 10962 | pc_->numberOfArgumentsNames--; | ||||
| 10963 | // Resumed generators and async functions have numActualArgs == 0. | ||||
| 10964 | // See e.g. InterpreterStack::createGeneratorResumeFrame and its call to | ||||
| 10965 | // initCallFrame. | ||||
| 10966 | if (pc_->isGeneratorOrAsync()) { | ||||
| 10967 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 10968 | } | ||||
| 10969 | return handler_.newArgumentsLength(lhs, name); | ||||
| 10970 | } | ||||
| 10971 | |||||
| 10972 | return handler_.newPropertyAccess(lhs, name); | ||||
| 10973 | } | ||||
| 10974 | |||||
| 10975 | template <class ParseHandler, typename Unit> | ||||
| 10976 | typename ParseHandler::NodeResult | ||||
| 10977 | GeneralParser<ParseHandler, Unit>::memberPrivateAccess( | ||||
| 10978 | Node lhs, OptionalKind optionalKind /* = OptionalKind::NonOptional */) { | ||||
| 10979 | MOZ_ASSERT(anyChars.currentToken().type == TokenKind::PrivateName)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.currentToken().type == TokenKind::PrivateName )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.currentToken().type == TokenKind::PrivateName ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "anyChars.currentToken().type == TokenKind::PrivateName", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 10979); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::PrivateName" ")"); do { MOZ_CrashSequence(__null, 10979); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 10980 | |||||
| 10981 | TaggedParserAtomIndex field = anyChars.currentName(); | ||||
| 10982 | // Cannot access private fields on super. | ||||
| 10983 | if (handler_.isSuperBase(lhs)) { | ||||
| 10984 | error(JSMSG_BAD_SUPERPRIVATE); | ||||
| 10985 | return errorResult(); | ||||
| 10986 | } | ||||
| 10987 | |||||
| 10988 | NameNodeType privateName = MOZ_TRY(privateNameReference(field))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (privateNameReference(field)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 10989 | |||||
| 10990 | if (optionalKind == OptionalKind::Optional) { | ||||
| 10991 | MOZ_ASSERT(!handler_.isSuperBase(lhs))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!handler_.isSuperBase(lhs))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!handler_.isSuperBase(lhs))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!handler_.isSuperBase(lhs)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 10991); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!handler_.isSuperBase(lhs)" ")"); do { MOZ_CrashSequence (__null, 10991); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 10992 | return handler_.newOptionalPrivateMemberAccess(lhs, privateName, pos().end); | ||||
| 10993 | } | ||||
| 10994 | return handler_.newPrivateMemberAccess(lhs, privateName, pos().end); | ||||
| 10995 | } | ||||
| 10996 | |||||
| 10997 | template <class ParseHandler, typename Unit> | ||||
| 10998 | typename ParseHandler::NodeResult | ||||
| 10999 | GeneralParser<ParseHandler, Unit>::memberElemAccess( | ||||
| 11000 | Node lhs, YieldHandling yieldHandling, | ||||
| 11001 | OptionalKind optionalKind /* = OptionalKind::NonOptional */) { | ||||
| 11002 | MOZ_ASSERT(anyChars.currentToken().type == TokenKind::LeftBracket)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.currentToken().type == TokenKind::LeftBracket )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.currentToken().type == TokenKind::LeftBracket ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "anyChars.currentToken().type == TokenKind::LeftBracket", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11002); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::LeftBracket" ")"); do { MOZ_CrashSequence(__null, 11002); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 11003 | Node propExpr = MOZ_TRY(expr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (expr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11004 | |||||
| 11005 | if (!mustMatchToken(TokenKind::RightBracket, JSMSG_BRACKET_IN_INDEX)) { | ||||
| 11006 | return errorResult(); | ||||
| 11007 | } | ||||
| 11008 | |||||
| 11009 | if (handler_.isSuperBase(lhs) && !checkAndMarkSuperScope()) { | ||||
| 11010 | error(JSMSG_BAD_SUPERPROP, "member"); | ||||
| 11011 | return errorResult(); | ||||
| 11012 | } | ||||
| 11013 | if (optionalKind == OptionalKind::Optional) { | ||||
| 11014 | MOZ_ASSERT(!handler_.isSuperBase(lhs))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!handler_.isSuperBase(lhs))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!handler_.isSuperBase(lhs))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!handler_.isSuperBase(lhs)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 11014); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!handler_.isSuperBase(lhs)" ")"); do { MOZ_CrashSequence (__null, 11014); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 11015 | return handler_.newOptionalPropertyByValue(lhs, propExpr, pos().end); | ||||
| 11016 | } | ||||
| 11017 | return handler_.newPropertyByValue(lhs, propExpr, pos().end); | ||||
| 11018 | } | ||||
| 11019 | |||||
| 11020 | template <class ParseHandler, typename Unit> | ||||
| 11021 | typename ParseHandler::NodeResult | ||||
| 11022 | GeneralParser<ParseHandler, Unit>::memberSuperCall( | ||||
| 11023 | Node lhs, YieldHandling yieldHandling) { | ||||
| 11024 | MOZ_ASSERT(anyChars.currentToken().type == TokenKind::LeftParen)do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.currentToken().type == TokenKind::LeftParen )>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.currentToken().type == TokenKind::LeftParen ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "anyChars.currentToken().type == TokenKind::LeftParen", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11024); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::LeftParen" ")"); do { MOZ_CrashSequence(__null, 11024); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 11025 | // Despite the fact that it's impossible to have |super()| in a | ||||
| 11026 | // generator, we still inherit the yieldHandling of the | ||||
| 11027 | // memberExpression, per spec. Curious. | ||||
| 11028 | bool isSpread = false; | ||||
| 11029 | ListNodeType args = MOZ_TRY(argumentList(yieldHandling, &isSpread))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (argumentList(yieldHandling, &isSpread)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11030 | |||||
| 11031 | CallNodeType superCall = MOZ_TRY(handler_.newSuperCall(lhs, args, isSpread))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newSuperCall(lhs, args, isSpread)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11032 | |||||
| 11033 | // |super()| implicitly reads |new.target|. | ||||
| 11034 | if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_newTarget_())) { | ||||
| 11035 | return errorResult(); | ||||
| 11036 | } | ||||
| 11037 | |||||
| 11038 | NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11039 | |||||
| 11040 | return handler_.newSetThis(thisName, superCall); | ||||
| 11041 | } | ||||
| 11042 | |||||
| 11043 | template <class ParseHandler, typename Unit> | ||||
| 11044 | typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::memberCall( | ||||
| 11045 | TokenKind tt, Node lhs, YieldHandling yieldHandling, | ||||
| 11046 | PossibleError* possibleError /* = nullptr */, | ||||
| 11047 | OptionalKind optionalKind /* = OptionalKind::NonOptional */) { | ||||
| 11048 | if (options().selfHostingMode && | ||||
| 11049 | (handler_.isPropertyOrPrivateMemberAccess(lhs) || | ||||
| 11050 | handler_.isOptionalPropertyOrPrivateMemberAccess(lhs))) { | ||||
| 11051 | error(JSMSG_SELFHOSTED_METHOD_CALL); | ||||
| 11052 | return errorResult(); | ||||
| 11053 | } | ||||
| 11054 | |||||
| 11055 | MOZ_ASSERT(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead ||do { static_assert( mozilla::detail::AssertionConditionType< decltype(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate" " (" "Unexpected token kind for member call" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11057); AnnotateMozCrashReason("MOZ_ASSERT" "(" "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate" ") (" "Unexpected token kind for member call" ")"); do { MOZ_CrashSequence (__null, 11057); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false) | ||||
| 11056 | tt == TokenKind::NoSubsTemplate,do { static_assert( mozilla::detail::AssertionConditionType< decltype(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate" " (" "Unexpected token kind for member call" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11057); AnnotateMozCrashReason("MOZ_ASSERT" "(" "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate" ") (" "Unexpected token kind for member call" ")"); do { MOZ_CrashSequence (__null, 11057); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false) | ||||
| 11057 | "Unexpected token kind for member call")do { static_assert( mozilla::detail::AssertionConditionType< decltype(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate" " (" "Unexpected token kind for member call" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11057); AnnotateMozCrashReason("MOZ_ASSERT" "(" "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate" ") (" "Unexpected token kind for member call" ")"); do { MOZ_CrashSequence (__null, 11057); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 11058 | |||||
| 11059 | JSOp op = JSOp::Call; | ||||
| 11060 | bool maybeAsyncArrow = false; | ||||
| 11061 | if (tt == TokenKind::LeftParen && optionalKind == OptionalKind::NonOptional) { | ||||
| 11062 | if (handler_.isAsyncKeyword(lhs)) { | ||||
| 11063 | // |async (| can be the start of an async arrow | ||||
| 11064 | // function, so we need to defer reporting possible | ||||
| 11065 | // errors from destructuring syntax. To give better | ||||
| 11066 | // error messages, we only allow the AsyncArrowHead | ||||
| 11067 | // part of the CoverCallExpressionAndAsyncArrowHead | ||||
| 11068 | // syntax when the initial name is "async". | ||||
| 11069 | maybeAsyncArrow = true; | ||||
| 11070 | } else if (handler_.isEvalName(lhs)) { | ||||
| 11071 | // Select the right Eval op and flag pc_ as having a | ||||
| 11072 | // direct eval. | ||||
| 11073 | op = pc_->sc()->strict() ? JSOp::StrictEval : JSOp::Eval; | ||||
| 11074 | pc_->sc()->setBindingsAccessedDynamically(); | ||||
| 11075 | pc_->sc()->setHasDirectEval(); | ||||
| 11076 | |||||
| 11077 | // In non-strict mode code, direct calls to eval can | ||||
| 11078 | // add variables to the call object. | ||||
| 11079 | if (pc_->isFunctionBox() && !pc_->sc()->strict()) { | ||||
| 11080 | pc_->functionBox()->setFunHasExtensibleScope(); | ||||
| 11081 | } | ||||
| 11082 | |||||
| 11083 | // If we're in a method, mark the method as requiring | ||||
| 11084 | // support for 'super', since direct eval code can use | ||||
| 11085 | // it. (If we're not in a method, that's fine, so | ||||
| 11086 | // ignore the return value.) | ||||
| 11087 | checkAndMarkSuperScope(); | ||||
| 11088 | } | ||||
| 11089 | } | ||||
| 11090 | |||||
| 11091 | if (tt == TokenKind::LeftParen) { | ||||
| 11092 | bool isSpread = false; | ||||
| 11093 | PossibleError* asyncPossibleError = | ||||
| 11094 | maybeAsyncArrow ? possibleError : nullptr; | ||||
| 11095 | ListNodeType args = | ||||
| 11096 | MOZ_TRY(argumentList(yieldHandling, &isSpread, asyncPossibleError))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (argumentList(yieldHandling, &isSpread, asyncPossibleError )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 11097 | if (isSpread) { | ||||
| 11098 | if (op == JSOp::Eval) { | ||||
| 11099 | op = JSOp::SpreadEval; | ||||
| 11100 | } else if (op == JSOp::StrictEval) { | ||||
| 11101 | op = JSOp::StrictSpreadEval; | ||||
| 11102 | } else { | ||||
| 11103 | op = JSOp::SpreadCall; | ||||
| 11104 | } | ||||
| 11105 | } | ||||
| 11106 | |||||
| 11107 | if (optionalKind == OptionalKind::Optional) { | ||||
| 11108 | return handler_.newOptionalCall(lhs, args, op); | ||||
| 11109 | } | ||||
| 11110 | return handler_.newCall(lhs, args, op); | ||||
| 11111 | } | ||||
| 11112 | |||||
| 11113 | ListNodeType args = MOZ_TRY(handler_.newArguments(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newArguments(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11114 | |||||
| 11115 | if (!taggedTemplate(yieldHandling, args, tt)) { | ||||
| 11116 | return errorResult(); | ||||
| 11117 | } | ||||
| 11118 | |||||
| 11119 | if (optionalKind == OptionalKind::Optional) { | ||||
| 11120 | error(JSMSG_BAD_OPTIONAL_TEMPLATE); | ||||
| 11121 | return errorResult(); | ||||
| 11122 | } | ||||
| 11123 | |||||
| 11124 | return handler_.newTaggedTemplate(lhs, args, op); | ||||
| 11125 | } | ||||
| 11126 | |||||
| 11127 | template <class ParseHandler, typename Unit> | ||||
| 11128 | bool GeneralParser<ParseHandler, Unit>::checkLabelOrIdentifierReference( | ||||
| 11129 | TaggedParserAtomIndex ident, uint32_t offset, YieldHandling yieldHandling, | ||||
| 11130 | TokenKind hint /* = TokenKind::Limit */) { | ||||
| 11131 | TokenKind tt; | ||||
| 11132 | if (hint == TokenKind::Limit) { | ||||
| 11133 | tt = ReservedWordTokenKind(ident); | ||||
| 11134 | } else { | ||||
| 11135 | // All non-reserved word kinds are folded into TokenKind::Limit in | ||||
| 11136 | // ReservedWordTokenKind and the following code. | ||||
| 11137 | if (hint == TokenKind::Name || hint == TokenKind::PrivateName) { | ||||
| 11138 | hint = TokenKind::Limit; | ||||
| 11139 | } | ||||
| 11140 | MOZ_ASSERT(hint == ReservedWordTokenKind(ident),do { static_assert( mozilla::detail::AssertionConditionType< decltype(hint == ReservedWordTokenKind(ident))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(hint == ReservedWordTokenKind (ident)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("hint == ReservedWordTokenKind(ident)" " (" "hint doesn't match actual token kind" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp", 11141 ); AnnotateMozCrashReason("MOZ_ASSERT" "(" "hint == ReservedWordTokenKind(ident)" ") (" "hint doesn't match actual token kind" ")"); do { MOZ_CrashSequence (__null, 11141); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false) | ||||
| 11141 | "hint doesn't match actual token kind")do { static_assert( mozilla::detail::AssertionConditionType< decltype(hint == ReservedWordTokenKind(ident))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(hint == ReservedWordTokenKind (ident)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("hint == ReservedWordTokenKind(ident)" " (" "hint doesn't match actual token kind" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp", 11141 ); AnnotateMozCrashReason("MOZ_ASSERT" "(" "hint == ReservedWordTokenKind(ident)" ") (" "hint doesn't match actual token kind" ")"); do { MOZ_CrashSequence (__null, 11141); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 11142 | tt = hint; | ||||
| 11143 | } | ||||
| 11144 | |||||
| 11145 | if (!pc_->sc()->allowArguments() && | ||||
| 11146 | ident == TaggedParserAtomIndex::WellKnown::arguments()) { | ||||
| 11147 | error(JSMSG_BAD_ARGUMENTS); | ||||
| 11148 | return false; | ||||
| 11149 | } | ||||
| 11150 | |||||
| 11151 | if (tt == TokenKind::Limit) { | ||||
| 11152 | // Either TokenKind::Name or TokenKind::PrivateName | ||||
| 11153 | return true; | ||||
| 11154 | } | ||||
| 11155 | if (TokenKindIsContextualKeyword(tt)) { | ||||
| 11156 | if (tt == TokenKind::Yield) { | ||||
| 11157 | if (yieldHandling == YieldIsKeyword) { | ||||
| 11158 | errorAt(offset, JSMSG_RESERVED_ID, "yield"); | ||||
| 11159 | return false; | ||||
| 11160 | } | ||||
| 11161 | if (pc_->sc()->strict()) { | ||||
| 11162 | if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, "yield")) { | ||||
| 11163 | return false; | ||||
| 11164 | } | ||||
| 11165 | } | ||||
| 11166 | return true; | ||||
| 11167 | } | ||||
| 11168 | if (tt == TokenKind::Await) { | ||||
| 11169 | if (awaitIsKeyword() || awaitIsDisallowed()) { | ||||
| 11170 | errorAt(offset, JSMSG_RESERVED_ID, "await"); | ||||
| 11171 | return false; | ||||
| 11172 | } | ||||
| 11173 | return true; | ||||
| 11174 | } | ||||
| 11175 | if (pc_->sc()->strict()) { | ||||
| 11176 | if (tt == TokenKind::Let) { | ||||
| 11177 | if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, "let")) { | ||||
| 11178 | return false; | ||||
| 11179 | } | ||||
| 11180 | return true; | ||||
| 11181 | } | ||||
| 11182 | if (tt == TokenKind::Static) { | ||||
| 11183 | if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, "static")) { | ||||
| 11184 | return false; | ||||
| 11185 | } | ||||
| 11186 | return true; | ||||
| 11187 | } | ||||
| 11188 | } | ||||
| 11189 | return true; | ||||
| 11190 | } | ||||
| 11191 | if (TokenKindIsStrictReservedWord(tt)) { | ||||
| 11192 | if (pc_->sc()->strict()) { | ||||
| 11193 | if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, | ||||
| 11194 | ReservedWordToCharZ(tt))) { | ||||
| 11195 | return false; | ||||
| 11196 | } | ||||
| 11197 | } | ||||
| 11198 | return true; | ||||
| 11199 | } | ||||
| 11200 | if (TokenKindIsKeyword(tt) || TokenKindIsReservedWordLiteral(tt)) { | ||||
| 11201 | errorAt(offset, JSMSG_INVALID_ID, ReservedWordToCharZ(tt)); | ||||
| 11202 | return false; | ||||
| 11203 | } | ||||
| 11204 | if (TokenKindIsFutureReservedWord(tt)) { | ||||
| 11205 | errorAt(offset, JSMSG_RESERVED_ID, ReservedWordToCharZ(tt)); | ||||
| 11206 | return false; | ||||
| 11207 | } | ||||
| 11208 | MOZ_ASSERT_UNREACHABLE("Unexpected reserved word kind.")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "MOZ_ASSERT_UNREACHABLE: " "Unexpected reserved word kind." ")", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11208); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") (" "MOZ_ASSERT_UNREACHABLE: " "Unexpected reserved word kind." ")" ); do { MOZ_CrashSequence(__null, 11208); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 11209 | return false; | ||||
| 11210 | } | ||||
| 11211 | |||||
| 11212 | template <class ParseHandler, typename Unit> | ||||
| 11213 | bool GeneralParser<ParseHandler, Unit>::checkBindingIdentifier( | ||||
| 11214 | TaggedParserAtomIndex ident, uint32_t offset, YieldHandling yieldHandling, | ||||
| 11215 | TokenKind hint /* = TokenKind::Limit */) { | ||||
| 11216 | if (pc_->sc()->strict()) { | ||||
| 11217 | if (ident == TaggedParserAtomIndex::WellKnown::arguments()) { | ||||
| 11218 | if (!strictModeErrorAt(offset, JSMSG_BAD_STRICT_ASSIGN, "arguments")) { | ||||
| 11219 | return false; | ||||
| 11220 | } | ||||
| 11221 | return true; | ||||
| 11222 | } | ||||
| 11223 | |||||
| 11224 | if (ident == TaggedParserAtomIndex::WellKnown::eval()) { | ||||
| 11225 | if (!strictModeErrorAt(offset, JSMSG_BAD_STRICT_ASSIGN, "eval")) { | ||||
| 11226 | return false; | ||||
| 11227 | } | ||||
| 11228 | return true; | ||||
| 11229 | } | ||||
| 11230 | } | ||||
| 11231 | |||||
| 11232 | return checkLabelOrIdentifierReference(ident, offset, yieldHandling, hint); | ||||
| 11233 | } | ||||
| 11234 | |||||
| 11235 | template <class ParseHandler, typename Unit> | ||||
| 11236 | TaggedParserAtomIndex | ||||
| 11237 | GeneralParser<ParseHandler, Unit>::labelOrIdentifierReference( | ||||
| 11238 | YieldHandling yieldHandling) { | ||||
| 11239 | // ES 2017 draft 12.1.1. | ||||
| 11240 | // StringValue of IdentifierName normalizes any Unicode escape sequences | ||||
| 11241 | // in IdentifierName hence such escapes cannot be used to write an | ||||
| 11242 | // Identifier whose code point sequence is the same as a ReservedWord. | ||||
| 11243 | // | ||||
| 11244 | // Use const ParserName* instead of TokenKind to reflect the normalization. | ||||
| 11245 | |||||
| 11246 | // Unless the name contains escapes, we can reuse the current TokenKind | ||||
| 11247 | // to determine if the name is a restricted identifier. | ||||
| 11248 | TokenKind hint = !anyChars.currentNameHasEscapes(this->parserAtoms()) | ||||
| 11249 | ? anyChars.currentToken().type | ||||
| 11250 | : TokenKind::Limit; | ||||
| 11251 | TaggedParserAtomIndex ident = anyChars.currentName(); | ||||
| 11252 | if (!checkLabelOrIdentifierReference(ident, pos().begin, yieldHandling, | ||||
| 11253 | hint)) { | ||||
| 11254 | return TaggedParserAtomIndex::null(); | ||||
| 11255 | } | ||||
| 11256 | return ident; | ||||
| 11257 | } | ||||
| 11258 | |||||
| 11259 | template <class ParseHandler, typename Unit> | ||||
| 11260 | TaggedParserAtomIndex GeneralParser<ParseHandler, Unit>::bindingIdentifier( | ||||
| 11261 | YieldHandling yieldHandling) { | ||||
| 11262 | TokenKind hint = !anyChars.currentNameHasEscapes(this->parserAtoms()) | ||||
| 11263 | ? anyChars.currentToken().type | ||||
| 11264 | : TokenKind::Limit; | ||||
| 11265 | TaggedParserAtomIndex ident = anyChars.currentName(); | ||||
| 11266 | if (!checkBindingIdentifier(ident, pos().begin, yieldHandling, hint)) { | ||||
| 11267 | return TaggedParserAtomIndex::null(); | ||||
| 11268 | } | ||||
| 11269 | return ident; | ||||
| 11270 | } | ||||
| 11271 | |||||
| 11272 | template <class ParseHandler> | ||||
| 11273 | typename ParseHandler::NameNodeResult | ||||
| 11274 | PerHandlerParser<ParseHandler>::identifierReference( | ||||
| 11275 | TaggedParserAtomIndex name) { | ||||
| 11276 | NameNodeType id = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11277 | |||||
| 11278 | if (!noteUsedName(name)) { | ||||
| 11279 | return errorResult(); | ||||
| 11280 | } | ||||
| 11281 | |||||
| 11282 | return id; | ||||
| 11283 | } | ||||
| 11284 | |||||
| 11285 | template <class ParseHandler> | ||||
| 11286 | typename ParseHandler::NameNodeResult | ||||
| 11287 | PerHandlerParser<ParseHandler>::privateNameReference( | ||||
| 11288 | TaggedParserAtomIndex name) { | ||||
| 11289 | NameNodeType id = MOZ_TRY(newPrivateName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newPrivateName(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11290 | |||||
| 11291 | if (!noteUsedName(name, NameVisibility::Private, Some(pos()))) { | ||||
| 11292 | return errorResult(); | ||||
| 11293 | } | ||||
| 11294 | |||||
| 11295 | return id; | ||||
| 11296 | } | ||||
| 11297 | |||||
| 11298 | template <class ParseHandler> | ||||
| 11299 | typename ParseHandler::NameNodeResult | ||||
| 11300 | PerHandlerParser<ParseHandler>::stringLiteral() { | ||||
| 11301 | return handler_.newStringLiteral(anyChars.currentToken().atom(), pos()); | ||||
| 11302 | } | ||||
| 11303 | |||||
| 11304 | template <class ParseHandler> | ||||
| 11305 | typename ParseHandler::NodeResult | ||||
| 11306 | PerHandlerParser<ParseHandler>::noSubstitutionTaggedTemplate() { | ||||
| 11307 | if (anyChars.hasInvalidTemplateEscape()) { | ||||
| 11308 | anyChars.clearInvalidTemplateEscape(); | ||||
| 11309 | return handler_.newRawUndefinedLiteral(pos()); | ||||
| 11310 | } | ||||
| 11311 | |||||
| 11312 | return handler_.newTemplateStringLiteral(anyChars.currentToken().atom(), | ||||
| 11313 | pos()); | ||||
| 11314 | } | ||||
| 11315 | |||||
| 11316 | template <class ParseHandler, typename Unit> | ||||
| 11317 | typename ParseHandler::NameNodeResult | ||||
| 11318 | GeneralParser<ParseHandler, Unit>::noSubstitutionUntaggedTemplate() { | ||||
| 11319 | if (!tokenStream.checkForInvalidTemplateEscapeError()) { | ||||
| 11320 | return errorResult(); | ||||
| 11321 | } | ||||
| 11322 | |||||
| 11323 | return handler_.newTemplateStringLiteral(anyChars.currentToken().atom(), | ||||
| 11324 | pos()); | ||||
| 11325 | } | ||||
| 11326 | |||||
| 11327 | template <typename Unit> | ||||
| 11328 | FullParseHandler::RegExpLiteralResult | ||||
| 11329 | Parser<FullParseHandler, Unit>::newRegExp() { | ||||
| 11330 | MOZ_ASSERT(!options().selfHostingMode)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!options().selfHostingMode)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!options().selfHostingMode)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!options().selfHostingMode" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 11330); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!options().selfHostingMode" ")"); do { MOZ_CrashSequence (__null, 11330); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 11331 | |||||
| 11332 | // Create the regexp and check its syntax. | ||||
| 11333 | const auto& chars = tokenStream.getCharBuffer(); | ||||
| 11334 | mozilla::Range<const char16_t> range(chars.begin(), chars.length()); | ||||
| 11335 | RegExpFlags flags = anyChars.currentToken().regExpFlags(); | ||||
| 11336 | |||||
| 11337 | uint32_t offset = anyChars.currentToken().pos.begin; | ||||
| 11338 | uint32_t line; | ||||
| 11339 | JS::LimitedColumnNumberOneOrigin column; | ||||
| 11340 | tokenStream.computeLineAndColumn(offset, &line, &column); | ||||
| 11341 | |||||
| 11342 | if (!handler_.reuseRegexpSyntaxParse()) { | ||||
| 11343 | // Verify that the Regexp will syntax parse when the time comes to | ||||
| 11344 | // instantiate it. If we have already done a syntax parse, we can | ||||
| 11345 | // skip this. | ||||
| 11346 | if (!irregexp::CheckPatternSyntax( | ||||
| 11347 | this->alloc_, this->fc_->stackLimit(), anyChars, range, flags, | ||||
| 11348 | Some(line), Some(JS::ColumnNumberOneOrigin(column)))) { | ||||
| 11349 | return errorResult(); | ||||
| 11350 | } | ||||
| 11351 | } | ||||
| 11352 | |||||
| 11353 | auto atom = | ||||
| 11354 | this->parserAtoms().internChar16(fc_, chars.begin(), chars.length()); | ||||
| 11355 | if (!atom) { | ||||
| 11356 | return errorResult(); | ||||
| 11357 | } | ||||
| 11358 | // RegExp patterm must be atomized. | ||||
| 11359 | this->parserAtoms().markUsedByStencil(atom, ParserAtom::Atomize::Yes); | ||||
| 11360 | |||||
| 11361 | RegExpIndex index(this->compilationState_.regExpData.length()); | ||||
| 11362 | if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) { | ||||
| 11363 | ReportAllocationOverflow(fc_); | ||||
| 11364 | return errorResult(); | ||||
| 11365 | } | ||||
| 11366 | if (!this->compilationState_.regExpData.emplaceBack(atom, flags)) { | ||||
| 11367 | js::ReportOutOfMemory(this->fc_); | ||||
| 11368 | return errorResult(); | ||||
| 11369 | } | ||||
| 11370 | |||||
| 11371 | return handler_.newRegExp(index, pos()); | ||||
| 11372 | } | ||||
| 11373 | |||||
| 11374 | template <typename Unit> | ||||
| 11375 | SyntaxParseHandler::RegExpLiteralResult | ||||
| 11376 | Parser<SyntaxParseHandler, Unit>::newRegExp() { | ||||
| 11377 | MOZ_ASSERT(!options().selfHostingMode)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!options().selfHostingMode)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!options().selfHostingMode)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!options().selfHostingMode" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 11377); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "!options().selfHostingMode" ")"); do { MOZ_CrashSequence (__null, 11377); __attribute__((nomerge)) ::abort(); } while ( false); } } while (false); | ||||
| 11378 | |||||
| 11379 | // Only check the regexp's syntax, but don't create a regexp object. | ||||
| 11380 | const auto& chars = tokenStream.getCharBuffer(); | ||||
| 11381 | RegExpFlags flags = anyChars.currentToken().regExpFlags(); | ||||
| 11382 | |||||
| 11383 | uint32_t offset = anyChars.currentToken().pos.begin; | ||||
| 11384 | uint32_t line; | ||||
| 11385 | JS::LimitedColumnNumberOneOrigin column; | ||||
| 11386 | tokenStream.computeLineAndColumn(offset, &line, &column); | ||||
| 11387 | |||||
| 11388 | mozilla::Range<const char16_t> source(chars.begin(), chars.length()); | ||||
| 11389 | if (!irregexp::CheckPatternSyntax(this->alloc_, this->fc_->stackLimit(), | ||||
| 11390 | anyChars, source, flags, Some(line), | ||||
| 11391 | Some(JS::ColumnNumberOneOrigin(column)))) { | ||||
| 11392 | return errorResult(); | ||||
| 11393 | } | ||||
| 11394 | |||||
| 11395 | return handler_.newRegExp(SyntaxParseHandler::Node::NodeGeneric, pos()); | ||||
| 11396 | } | ||||
| 11397 | |||||
| 11398 | template <class ParseHandler, typename Unit> | ||||
| 11399 | typename ParseHandler::RegExpLiteralResult | ||||
| 11400 | GeneralParser<ParseHandler, Unit>::newRegExp() { | ||||
| 11401 | return asFinalParser()->newRegExp(); | ||||
| 11402 | } | ||||
| 11403 | |||||
| 11404 | template <typename Unit> | ||||
| 11405 | FullParseHandler::BigIntLiteralResult | ||||
| 11406 | Parser<FullParseHandler, Unit>::newBigInt() { | ||||
| 11407 | // The token's charBuffer contains the DecimalIntegerLiteral or | ||||
| 11408 | // NonDecimalIntegerLiteral production, and as such does not include the | ||||
| 11409 | // BigIntLiteralSuffix (the trailing "n"). Note that NonDecimalIntegerLiteral | ||||
| 11410 | // productions start with 0[bBoOxX], indicating binary/octal/hex. | ||||
| 11411 | const auto& chars = tokenStream.getCharBuffer(); | ||||
| 11412 | if (chars.length() > UINT32_MAX(4294967295U)) { | ||||
| 11413 | ReportAllocationOverflow(fc_); | ||||
| 11414 | return errorResult(); | ||||
| 11415 | } | ||||
| 11416 | |||||
| 11417 | BigIntIndex index(this->bigInts().length()); | ||||
| 11418 | if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) { | ||||
| 11419 | ReportAllocationOverflow(fc_); | ||||
| 11420 | return errorResult(); | ||||
| 11421 | } | ||||
| 11422 | if (!this->bigInts().emplaceBack()) { | ||||
| 11423 | js::ReportOutOfMemory(this->fc_); | ||||
| 11424 | return errorResult(); | ||||
| 11425 | } | ||||
| 11426 | |||||
| 11427 | if (!this->bigInts()[index].init(this->fc_, this->stencilAlloc(), chars)) { | ||||
| 11428 | return errorResult(); | ||||
| 11429 | } | ||||
| 11430 | |||||
| 11431 | // Should the operations below fail, the buffer held by data will | ||||
| 11432 | // be cleaned up by the CompilationState destructor. | ||||
| 11433 | return handler_.newBigInt(index, pos()); | ||||
| 11434 | } | ||||
| 11435 | |||||
| 11436 | template <typename Unit> | ||||
| 11437 | SyntaxParseHandler::BigIntLiteralResult | ||||
| 11438 | Parser<SyntaxParseHandler, Unit>::newBigInt() { | ||||
| 11439 | // The tokenizer has already checked the syntax of the bigint. | ||||
| 11440 | |||||
| 11441 | return handler_.newBigInt(); | ||||
| 11442 | } | ||||
| 11443 | |||||
| 11444 | template <class ParseHandler, typename Unit> | ||||
| 11445 | typename ParseHandler::BigIntLiteralResult | ||||
| 11446 | GeneralParser<ParseHandler, Unit>::newBigInt() { | ||||
| 11447 | return asFinalParser()->newBigInt(); | ||||
| 11448 | } | ||||
| 11449 | |||||
| 11450 | // |exprPossibleError| is the PossibleError state within |expr|, | ||||
| 11451 | // |possibleError| is the surrounding PossibleError state. | ||||
| 11452 | template <class ParseHandler, typename Unit> | ||||
| 11453 | bool GeneralParser<ParseHandler, Unit>::checkDestructuringAssignmentTarget( | ||||
| 11454 | Node expr, TokenPos exprPos, PossibleError* exprPossibleError, | ||||
| 11455 | PossibleError* possibleError, TargetBehavior behavior) { | ||||
| 11456 | // |arguments.length| is reported as a property access by the check below, so | ||||
| 11457 | // the property-access early-return would otherwise swallow it before the | ||||
| 11458 | // ArgumentsLength optimization is disabled. Mirror the | ||||
| 11459 | // isArgumentsLength-first pattern used by assignExpr. | ||||
| 11460 | if (handler_.isArgumentsLength(expr)) { | ||||
| 11461 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 11462 | } | ||||
| 11463 | |||||
| 11464 | // Report any pending expression error if we're definitely not in a | ||||
| 11465 | // destructuring context or the possible destructuring target is a | ||||
| 11466 | // property accessor. | ||||
| 11467 | if (!possibleError || handler_.isPropertyOrPrivateMemberAccess(expr)) { | ||||
| 11468 | return exprPossibleError->checkForExpressionError(); | ||||
| 11469 | } | ||||
| 11470 | |||||
| 11471 | // |expr| may end up as a destructuring assignment target, so we need to | ||||
| 11472 | // validate it's either a name or can be parsed as a nested destructuring | ||||
| 11473 | // pattern. Property accessors are also valid assignment targets, but | ||||
| 11474 | // those are already handled above. | ||||
| 11475 | |||||
| 11476 | exprPossibleError->transferErrorsTo(possibleError); | ||||
| 11477 | |||||
| 11478 | // Return early if a pending destructuring error is already present. | ||||
| 11479 | if (possibleError->hasPendingDestructuringError()) { | ||||
| 11480 | return true; | ||||
| 11481 | } | ||||
| 11482 | |||||
| 11483 | if (handler_.isName(expr)) { | ||||
| 11484 | checkDestructuringAssignmentName(handler_.asNameNode(expr), exprPos, | ||||
| 11485 | possibleError); | ||||
| 11486 | return true; | ||||
| 11487 | } | ||||
| 11488 | |||||
| 11489 | if (handler_.isUnparenthesizedDestructuringPattern(expr)) { | ||||
| 11490 | if (behavior == TargetBehavior::ForbidAssignmentPattern) { | ||||
| 11491 | possibleError->setPendingDestructuringErrorAt(exprPos, | ||||
| 11492 | JSMSG_BAD_DESTRUCT_TARGET); | ||||
| 11493 | } | ||||
| 11494 | return true; | ||||
| 11495 | } | ||||
| 11496 | |||||
| 11497 | // Parentheses are forbidden around destructuring *patterns* (but allowed | ||||
| 11498 | // around names). Use our nicer error message for parenthesized, nested | ||||
| 11499 | // patterns if nested destructuring patterns are allowed. | ||||
| 11500 | if (handler_.isParenthesizedDestructuringPattern(expr) && | ||||
| 11501 | behavior != TargetBehavior::ForbidAssignmentPattern) { | ||||
| 11502 | possibleError->setPendingDestructuringErrorAt(exprPos, | ||||
| 11503 | JSMSG_BAD_DESTRUCT_PARENS); | ||||
| 11504 | } else { | ||||
| 11505 | possibleError->setPendingDestructuringErrorAt(exprPos, | ||||
| 11506 | JSMSG_BAD_DESTRUCT_TARGET); | ||||
| 11507 | } | ||||
| 11508 | |||||
| 11509 | return true; | ||||
| 11510 | } | ||||
| 11511 | |||||
| 11512 | template <class ParseHandler, typename Unit> | ||||
| 11513 | void GeneralParser<ParseHandler, Unit>::checkDestructuringAssignmentName( | ||||
| 11514 | NameNodeType name, TokenPos namePos, PossibleError* possibleError) { | ||||
| 11515 | #ifdef DEBUG1 | ||||
| 11516 | // GCC 8.0.1 crashes if this is a one-liner. | ||||
| 11517 | bool isName = handler_.isName(name); | ||||
| 11518 | MOZ_ASSERT(isName)do { static_assert( mozilla::detail::AssertionConditionType< decltype(isName)>::isValid, "invalid assertion condition") ; if ((__builtin_expect(!!(!(!!(isName))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("isName", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11518); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isName" ")" ); do { MOZ_CrashSequence(__null, 11518); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 11519 | #endif | ||||
| 11520 | |||||
| 11521 | // Return early if a pending destructuring error is already present. | ||||
| 11522 | if (possibleError->hasPendingDestructuringError()) { | ||||
| 11523 | return; | ||||
| 11524 | } | ||||
| 11525 | |||||
| 11526 | if (handler_.isArgumentsLength(name)) { | ||||
| 11527 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 11528 | } | ||||
| 11529 | |||||
| 11530 | if (pc_->sc()->strict()) { | ||||
| 11531 | if (handler_.isArgumentsName(name)) { | ||||
| 11532 | possibleError->setPendingDestructuringErrorAt( | ||||
| 11533 | namePos, JSMSG_BAD_STRICT_ASSIGN_ARGUMENTS); | ||||
| 11534 | return; | ||||
| 11535 | } | ||||
| 11536 | if (handler_.isEvalName(name)) { | ||||
| 11537 | possibleError->setPendingDestructuringErrorAt( | ||||
| 11538 | namePos, JSMSG_BAD_STRICT_ASSIGN_EVAL); | ||||
| 11539 | return; | ||||
| 11540 | } | ||||
| 11541 | } | ||||
| 11542 | } | ||||
| 11543 | |||||
| 11544 | template <class ParseHandler, typename Unit> | ||||
| 11545 | bool GeneralParser<ParseHandler, Unit>::checkDestructuringAssignmentElement( | ||||
| 11546 | Node expr, TokenPos exprPos, PossibleError* exprPossibleError, | ||||
| 11547 | PossibleError* possibleError) { | ||||
| 11548 | // ES2018 draft rev 0719f44aab93215ed9a626b2f45bd34f36916834 | ||||
| 11549 | // 12.15.5 Destructuring Assignment | ||||
| 11550 | // | ||||
| 11551 | // AssignmentElement[Yield, Await]: | ||||
| 11552 | // DestructuringAssignmentTarget[?Yield, ?Await] | ||||
| 11553 | // DestructuringAssignmentTarget[?Yield, ?Await] Initializer[+In, | ||||
| 11554 | // ?Yield, | ||||
| 11555 | // ?Await] | ||||
| 11556 | |||||
| 11557 | // If |expr| is an assignment element with an initializer expression, its | ||||
| 11558 | // destructuring assignment target was already validated in assignExpr(). | ||||
| 11559 | // Otherwise we need to check that |expr| is a valid destructuring target. | ||||
| 11560 | if (handler_.isUnparenthesizedAssignment(expr)) { | ||||
| 11561 | // Report any pending expression error if we're definitely not in a | ||||
| 11562 | // destructuring context. | ||||
| 11563 | if (!possibleError) { | ||||
| 11564 | return exprPossibleError->checkForExpressionError(); | ||||
| 11565 | } | ||||
| 11566 | |||||
| 11567 | exprPossibleError->transferErrorsTo(possibleError); | ||||
| 11568 | return true; | ||||
| 11569 | } | ||||
| 11570 | return checkDestructuringAssignmentTarget(expr, exprPos, exprPossibleError, | ||||
| 11571 | possibleError); | ||||
| 11572 | } | ||||
| 11573 | |||||
| 11574 | template <class ParseHandler, typename Unit> | ||||
| 11575 | typename ParseHandler::ListNodeResult | ||||
| 11576 | GeneralParser<ParseHandler, Unit>::arrayInitializer( | ||||
| 11577 | YieldHandling yieldHandling, PossibleError* possibleError) { | ||||
| 11578 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftBracket))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftBracket)) >::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftBracket)) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftBracket)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 11578); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket)" ")"); do { MOZ_CrashSequence(__null, 11578); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 11579 | |||||
| 11580 | uint32_t begin = pos().begin; | ||||
| 11581 | ListNodeType literal = MOZ_TRY(handler_.newArrayLiteral(begin))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newArrayLiteral(begin)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11582 | |||||
| 11583 | TokenKind tt; | ||||
| 11584 | if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 11585 | return errorResult(); | ||||
| 11586 | } | ||||
| 11587 | |||||
| 11588 | if (tt == TokenKind::RightBracket) { | ||||
| 11589 | /* | ||||
| 11590 | * Mark empty arrays as non-constant, since we cannot easily | ||||
| 11591 | * determine their type. | ||||
| 11592 | */ | ||||
| 11593 | handler_.setListHasNonConstInitializer(literal); | ||||
| 11594 | } else { | ||||
| 11595 | anyChars.ungetToken(); | ||||
| 11596 | |||||
| 11597 | for (uint32_t index = 0;; index++) { | ||||
| 11598 | if (index >= NativeObject::MAX_DENSE_ELEMENTS_COUNT) { | ||||
| 11599 | error(JSMSG_ARRAY_INIT_TOO_BIG); | ||||
| 11600 | return errorResult(); | ||||
| 11601 | } | ||||
| 11602 | |||||
| 11603 | TokenKind tt; | ||||
| 11604 | if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) { | ||||
| 11605 | return errorResult(); | ||||
| 11606 | } | ||||
| 11607 | if (tt == TokenKind::RightBracket) { | ||||
| 11608 | break; | ||||
| 11609 | } | ||||
| 11610 | |||||
| 11611 | if (tt == TokenKind::Comma) { | ||||
| 11612 | tokenStream.consumeKnownToken(TokenKind::Comma, | ||||
| 11613 | TokenStream::SlashIsRegExp); | ||||
| 11614 | if (!handler_.addElision(literal, pos())) { | ||||
| 11615 | return errorResult(); | ||||
| 11616 | } | ||||
| 11617 | continue; | ||||
| 11618 | } | ||||
| 11619 | |||||
| 11620 | if (tt == TokenKind::TripleDot) { | ||||
| 11621 | tokenStream.consumeKnownToken(TokenKind::TripleDot, | ||||
| 11622 | TokenStream::SlashIsRegExp); | ||||
| 11623 | uint32_t begin = pos().begin; | ||||
| 11624 | |||||
| 11625 | TokenPos innerPos; | ||||
| 11626 | if (!tokenStream.peekTokenPos(&innerPos, TokenStream::SlashIsRegExp)) { | ||||
| 11627 | return errorResult(); | ||||
| 11628 | } | ||||
| 11629 | |||||
| 11630 | PossibleError possibleErrorInner(*this); | ||||
| 11631 | Node inner = | ||||
| 11632 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 11633 | &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11634 | if (!checkDestructuringAssignmentTarget( | ||||
| 11635 | inner, innerPos, &possibleErrorInner, possibleError)) { | ||||
| 11636 | return errorResult(); | ||||
| 11637 | } | ||||
| 11638 | |||||
| 11639 | if (!handler_.addSpreadElement(literal, begin, inner)) { | ||||
| 11640 | return errorResult(); | ||||
| 11641 | } | ||||
| 11642 | } else { | ||||
| 11643 | TokenPos elementPos; | ||||
| 11644 | if (!tokenStream.peekTokenPos(&elementPos, | ||||
| 11645 | TokenStream::SlashIsRegExp)) { | ||||
| 11646 | return errorResult(); | ||||
| 11647 | } | ||||
| 11648 | |||||
| 11649 | PossibleError possibleErrorInner(*this); | ||||
| 11650 | Node element = | ||||
| 11651 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 11652 | &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11653 | if (!checkDestructuringAssignmentElement( | ||||
| 11654 | element, elementPos, &possibleErrorInner, possibleError)) { | ||||
| 11655 | return errorResult(); | ||||
| 11656 | } | ||||
| 11657 | handler_.addArrayElement(literal, element); | ||||
| 11658 | } | ||||
| 11659 | |||||
| 11660 | bool matched; | ||||
| 11661 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 11662 | TokenStream::SlashIsRegExp)) { | ||||
| 11663 | return errorResult(); | ||||
| 11664 | } | ||||
| 11665 | if (!matched) { | ||||
| 11666 | break; | ||||
| 11667 | } | ||||
| 11668 | |||||
| 11669 | if (tt == TokenKind::TripleDot && possibleError) { | ||||
| 11670 | possibleError->setPendingDestructuringErrorAt(pos(), | ||||
| 11671 | JSMSG_REST_WITH_COMMA); | ||||
| 11672 | } | ||||
| 11673 | } | ||||
| 11674 | |||||
| 11675 | if (!mustMatchToken( | ||||
| 11676 | TokenKind::RightBracket, [this, begin](TokenKind actual) { | ||||
| 11677 | this->reportMissingClosing(JSMSG_BRACKET_AFTER_LIST, | ||||
| 11678 | JSMSG_BRACKET_OPENED, begin); | ||||
| 11679 | })) { | ||||
| 11680 | return errorResult(); | ||||
| 11681 | } | ||||
| 11682 | } | ||||
| 11683 | |||||
| 11684 | handler_.setEndPosition(literal, pos().end); | ||||
| 11685 | return literal; | ||||
| 11686 | } | ||||
| 11687 | |||||
| 11688 | template <class ParseHandler, typename Unit> | ||||
| 11689 | typename ParseHandler::NodeResult | ||||
| 11690 | GeneralParser<ParseHandler, Unit>::propertyName( | ||||
| 11691 | YieldHandling yieldHandling, PropertyNameContext propertyNameContext, | ||||
| 11692 | const Maybe<DeclarationKind>& maybeDecl, ListNodeType propList, | ||||
| 11693 | TaggedParserAtomIndex* propAtomOut) { | ||||
| 11694 | // PropertyName[Yield, Await]: | ||||
| 11695 | // LiteralPropertyName | ||||
| 11696 | // ComputedPropertyName[?Yield, ?Await] | ||||
| 11697 | // | ||||
| 11698 | // LiteralPropertyName: | ||||
| 11699 | // IdentifierName | ||||
| 11700 | // StringLiteral | ||||
| 11701 | // NumericLiteral | ||||
| 11702 | TokenKind ltok = anyChars.currentToken().type; | ||||
| 11703 | |||||
| 11704 | *propAtomOut = TaggedParserAtomIndex::null(); | ||||
| 11705 | switch (ltok) { | ||||
| 11706 | case TokenKind::Number: { | ||||
| 11707 | auto numAtom = NumberToParserAtom(fc_, this->parserAtoms(), | ||||
| 11708 | anyChars.currentToken().number()); | ||||
| 11709 | if (!numAtom) { | ||||
| 11710 | return errorResult(); | ||||
| 11711 | } | ||||
| 11712 | *propAtomOut = numAtom; | ||||
| 11713 | return newNumber(anyChars.currentToken()); | ||||
| 11714 | } | ||||
| 11715 | |||||
| 11716 | case TokenKind::BigInt: { | ||||
| 11717 | Node biNode = MOZ_TRY(newBigInt())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newBigInt()); if ((__builtin_expect(!!(mozTryVarTempResult.isErr ()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 11718 | return handler_.newSyntheticComputedName(biNode, pos().begin, pos().end); | ||||
| 11719 | } | ||||
| 11720 | case TokenKind::String: { | ||||
| 11721 | auto str = anyChars.currentToken().atom(); | ||||
| 11722 | *propAtomOut = str; | ||||
| 11723 | uint32_t index; | ||||
| 11724 | if (this->parserAtoms().isIndex(str, &index)) { | ||||
| 11725 | return handler_.newNumber(index, NoDecimal, pos()); | ||||
| 11726 | } | ||||
| 11727 | return stringLiteral(); | ||||
| 11728 | } | ||||
| 11729 | |||||
| 11730 | case TokenKind::LeftBracket: | ||||
| 11731 | return computedPropertyName(yieldHandling, maybeDecl, propertyNameContext, | ||||
| 11732 | propList); | ||||
| 11733 | |||||
| 11734 | case TokenKind::PrivateName: { | ||||
| 11735 | if (propertyNameContext != PropertyNameContext::PropertyNameInClass) { | ||||
| 11736 | error(JSMSG_ILLEGAL_PRIVATE_FIELD); | ||||
| 11737 | return errorResult(); | ||||
| 11738 | } | ||||
| 11739 | |||||
| 11740 | TaggedParserAtomIndex propName = anyChars.currentName(); | ||||
| 11741 | *propAtomOut = propName; | ||||
| 11742 | return privateNameReference(propName); | ||||
| 11743 | } | ||||
| 11744 | |||||
| 11745 | default: { | ||||
| 11746 | if (!TokenKindIsPossibleIdentifierName(ltok)) { | ||||
| 11747 | error(JSMSG_UNEXPECTED_TOKEN, "property name", TokenKindToDesc(ltok)); | ||||
| 11748 | return errorResult(); | ||||
| 11749 | } | ||||
| 11750 | |||||
| 11751 | TaggedParserAtomIndex name = anyChars.currentName(); | ||||
| 11752 | *propAtomOut = name; | ||||
| 11753 | return handler_.newObjectLiteralPropertyName(name, pos()); | ||||
| 11754 | } | ||||
| 11755 | } | ||||
| 11756 | } | ||||
| 11757 | |||||
| 11758 | // True if `kind` can be the first token of a PropertyName. | ||||
| 11759 | static bool TokenKindCanStartPropertyName(TokenKind tt) { | ||||
| 11760 | return TokenKindIsPossibleIdentifierName(tt) || tt == TokenKind::String || | ||||
| 11761 | tt == TokenKind::Number || tt == TokenKind::LeftBracket || | ||||
| 11762 | tt == TokenKind::BigInt || tt == TokenKind::PrivateName; | ||||
| 11763 | } | ||||
| 11764 | |||||
| 11765 | template <class ParseHandler, typename Unit> | ||||
| 11766 | typename ParseHandler::NodeResult | ||||
| 11767 | GeneralParser<ParseHandler, Unit>::propertyOrMethodName( | ||||
| 11768 | YieldHandling yieldHandling, PropertyNameContext propertyNameContext, | ||||
| 11769 | const Maybe<DeclarationKind>& maybeDecl, ListNodeType propList, | ||||
| 11770 | PropertyType* propType, TaggedParserAtomIndex* propAtomOut) { | ||||
| 11771 | // We're parsing an object literal, class, or destructuring pattern; | ||||
| 11772 | // propertyNameContext tells which one. This method parses any of the | ||||
| 11773 | // following, storing the corresponding PropertyType in `*propType` to tell | ||||
| 11774 | // the caller what we parsed: | ||||
| 11775 | // | ||||
| 11776 | // async [no LineTerminator here] PropertyName | ||||
| 11777 | // ==> PropertyType::AsyncMethod | ||||
| 11778 | // async [no LineTerminator here] * PropertyName | ||||
| 11779 | // ==> PropertyType::AsyncGeneratorMethod | ||||
| 11780 | // * PropertyName ==> PropertyType::GeneratorMethod | ||||
| 11781 | // get PropertyName ==> PropertyType::Getter | ||||
| 11782 | // set PropertyName ==> PropertyType::Setter | ||||
| 11783 | // accessor PropertyName ==> PropertyType::FieldWithAccessor | ||||
| 11784 | // PropertyName : ==> PropertyType::Normal | ||||
| 11785 | // PropertyName ==> see below | ||||
| 11786 | // | ||||
| 11787 | // In the last case, where there's not a `:` token to consume, we peek at | ||||
| 11788 | // (but don't consume) the next token to decide how to set `*propType`. | ||||
| 11789 | // | ||||
| 11790 | // `,` or `}` ==> PropertyType::Shorthand | ||||
| 11791 | // `(` ==> PropertyType::Method | ||||
| 11792 | // `=`, not in a class ==> PropertyType::CoverInitializedName | ||||
| 11793 | // '=', in a class ==> PropertyType::Field | ||||
| 11794 | // any token, in a class ==> PropertyType::Field (ASI) | ||||
| 11795 | // | ||||
| 11796 | // The caller must check `*propType` and throw if whatever we parsed isn't | ||||
| 11797 | // allowed here (for example, a getter in a destructuring pattern). | ||||
| 11798 | // | ||||
| 11799 | // This method does *not* match `static` (allowed in classes) or `...` | ||||
| 11800 | // (allowed in object literals and patterns). The caller must take care of | ||||
| 11801 | // those before calling this method. | ||||
| 11802 | |||||
| 11803 | TokenKind ltok; | ||||
| 11804 | if (!tokenStream.getToken(<ok, TokenStream::SlashIsInvalid)) { | ||||
| 11805 | return errorResult(); | ||||
| 11806 | } | ||||
| 11807 | |||||
| 11808 | MOZ_ASSERT(ltok != TokenKind::RightCurly,do { static_assert( mozilla::detail::AssertionConditionType< decltype(ltok != TokenKind::RightCurly)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(ltok != TokenKind::RightCurly ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "ltok != TokenKind::RightCurly" " (" "caller should have handled TokenKind::RightCurly" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp", 11809 ); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ltok != TokenKind::RightCurly" ") (" "caller should have handled TokenKind::RightCurly" ")" ); do { MOZ_CrashSequence(__null, 11809); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) | ||||
| 11809 | "caller should have handled TokenKind::RightCurly")do { static_assert( mozilla::detail::AssertionConditionType< decltype(ltok != TokenKind::RightCurly)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(ltok != TokenKind::RightCurly ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "ltok != TokenKind::RightCurly" " (" "caller should have handled TokenKind::RightCurly" ")", "/root/firefox-clang/js/src/frontend/Parser.cpp", 11809 ); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ltok != TokenKind::RightCurly" ") (" "caller should have handled TokenKind::RightCurly" ")" ); do { MOZ_CrashSequence(__null, 11809); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); | ||||
| 11810 | |||||
| 11811 | // Accept `async` and/or `*`, indicating an async or generator method; | ||||
| 11812 | // or `get` or `set` or `accessor`, indicating an accessor. | ||||
| 11813 | bool isGenerator = false; | ||||
| 11814 | bool isAsync = false; | ||||
| 11815 | bool isGetter = false; | ||||
| 11816 | bool isSetter = false; | ||||
| 11817 | #ifdef ENABLE_DECORATORS | ||||
| 11818 | bool hasAccessor = false; | ||||
| 11819 | #endif | ||||
| 11820 | |||||
| 11821 | if (ltok == TokenKind::Async) { | ||||
| 11822 | // `async` is also a PropertyName by itself (it's a conditional keyword), | ||||
| 11823 | // so peek at the next token to see if we're really looking at a method. | ||||
| 11824 | TokenKind tt = TokenKind::Eof; | ||||
| 11825 | if (!tokenStream.peekTokenSameLine(&tt)) { | ||||
| 11826 | return errorResult(); | ||||
| 11827 | } | ||||
| 11828 | if (TokenKindCanStartPropertyName(tt) || tt == TokenKind::Mul) { | ||||
| 11829 | isAsync = true; | ||||
| 11830 | tokenStream.consumeKnownToken(tt); | ||||
| 11831 | ltok = tt; | ||||
| 11832 | } | ||||
| 11833 | } | ||||
| 11834 | |||||
| 11835 | if (ltok == TokenKind::Mul) { | ||||
| 11836 | isGenerator = true; | ||||
| 11837 | if (!tokenStream.getToken(<ok)) { | ||||
| 11838 | return errorResult(); | ||||
| 11839 | } | ||||
| 11840 | } | ||||
| 11841 | |||||
| 11842 | if (!isAsync
| ||||
| 11843 | (ltok == TokenKind::Get || ltok == TokenKind::Set)) { | ||||
| 11844 | // We have parsed |get| or |set|. Look for an accessor property | ||||
| 11845 | // name next. | ||||
| 11846 | TokenKind tt; | ||||
| 11847 | if (!tokenStream.peekToken(&tt)) { | ||||
| 11848 | return errorResult(); | ||||
| 11849 | } | ||||
| 11850 | if (TokenKindCanStartPropertyName(tt)) { | ||||
| 11851 | tokenStream.consumeKnownToken(tt); | ||||
| 11852 | isGetter = (ltok == TokenKind::Get); | ||||
| 11853 | isSetter = (ltok == TokenKind::Set); | ||||
| 11854 | } | ||||
| 11855 | } | ||||
| 11856 | |||||
| 11857 | #ifdef ENABLE_DECORATORS | ||||
| 11858 | if (!isGenerator && !isAsync && propertyNameContext == PropertyNameInClass && | ||||
| 11859 | ltok == TokenKind::Accessor) { | ||||
| 11860 | MOZ_ASSERT(!isGetter && !isSetter)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!isGetter && !isSetter)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!isGetter && !isSetter ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "!isGetter && !isSetter", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11860); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!isGetter && !isSetter" ")"); do { MOZ_CrashSequence(__null, 11860); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 11861 | TokenKind tt; | ||||
| 11862 | if (!tokenStream.peekTokenSameLine(&tt)) { | ||||
| 11863 | return errorResult(); | ||||
| 11864 | } | ||||
| 11865 | |||||
| 11866 | // The target rule is `accessor [no LineTerminator here] | ||||
| 11867 | // ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt` | ||||
| 11868 | if (TokenKindCanStartPropertyName(tt)) { | ||||
| 11869 | tokenStream.consumeKnownToken(tt); | ||||
| 11870 | if (fuzzingSafe) { | ||||
| 11871 | error(JSMSG_DECORATOR_FUZZING_UNSAFE); | ||||
| 11872 | return errorResult(); | ||||
| 11873 | } | ||||
| 11874 | hasAccessor = true; | ||||
| 11875 | } | ||||
| 11876 | } | ||||
| 11877 | #endif | ||||
| 11878 | |||||
| 11879 | Node propName = MOZ_TRY(propertyName(yieldHandling, propertyNameContext,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyName(yieldHandling, propertyNameContext, maybeDecl, propList , propAtomOut)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 11880 | maybeDecl, propList, propAtomOut))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyName(yieldHandling, propertyNameContext, maybeDecl, propList , propAtomOut)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 11881 | |||||
| 11882 | // Grab the next token following the property/method name. | ||||
| 11883 | // (If this isn't a colon, we're going to either put it back or throw.) | ||||
| 11884 | TokenKind tt; | ||||
| 11885 | if (!tokenStream.getToken(&tt)) { | ||||
| 11886 | return errorResult(); | ||||
| 11887 | } | ||||
| 11888 | |||||
| 11889 | if (tt == TokenKind::Colon) { | ||||
| 11890 | if (isGenerator || isAsync || isGetter || isSetter | ||||
| 11891 | #ifdef ENABLE_DECORATORS | ||||
| 11892 | || hasAccessor | ||||
| 11893 | #endif | ||||
| 11894 | ) { | ||||
| 11895 | error(JSMSG_BAD_PROP_ID); | ||||
| 11896 | return errorResult(); | ||||
| 11897 | } | ||||
| 11898 | *propType = PropertyType::Normal; | ||||
| 11899 | return propName; | ||||
| 11900 | } | ||||
| 11901 | |||||
| 11902 | if (propertyNameContext != PropertyNameInClass && | ||||
| 11903 | TokenKindIsPossibleIdentifierName(ltok) && | ||||
| 11904 | (tt == TokenKind::Comma || tt == TokenKind::RightCurly || | ||||
| 11905 | tt == TokenKind::Assign)) { | ||||
| 11906 | #ifdef ENABLE_DECORATORS | ||||
| 11907 | MOZ_ASSERT(!hasAccessor)do { static_assert( mozilla::detail::AssertionConditionType< decltype(!hasAccessor)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!hasAccessor))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!hasAccessor", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 11907); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasAccessor" ")"); do { MOZ_CrashSequence(__null, 11907); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 11908 | #endif | ||||
| 11909 | if (isGenerator || isAsync || isGetter || isSetter) { | ||||
| 11910 | error(JSMSG_BAD_PROP_ID); | ||||
| 11911 | return errorResult(); | ||||
| 11912 | } | ||||
| 11913 | |||||
| 11914 | anyChars.ungetToken(); | ||||
| 11915 | *propType = tt == TokenKind::Assign ? PropertyType::CoverInitializedName | ||||
| 11916 | : PropertyType::Shorthand; | ||||
| 11917 | return propName; | ||||
| 11918 | } | ||||
| 11919 | |||||
| 11920 | if (tt == TokenKind::LeftParen) { | ||||
| 11921 | anyChars.ungetToken(); | ||||
| 11922 | |||||
| 11923 | #ifdef ENABLE_DECORATORS | ||||
| 11924 | if (hasAccessor) { | ||||
| 11925 | error(JSMSG_BAD_PROP_ID); | ||||
| 11926 | return errorResult(); | ||||
| 11927 | } | ||||
| 11928 | #endif | ||||
| 11929 | |||||
| 11930 | if (isGenerator && isAsync) { | ||||
| 11931 | *propType = PropertyType::AsyncGeneratorMethod; | ||||
| 11932 | } else if (isGenerator) { | ||||
| 11933 | *propType = PropertyType::GeneratorMethod; | ||||
| 11934 | } else if (isAsync) { | ||||
| 11935 | *propType = PropertyType::AsyncMethod; | ||||
| 11936 | } else if (isGetter) { | ||||
| 11937 | *propType = PropertyType::Getter; | ||||
| 11938 | } else if (isSetter) { | ||||
| 11939 | *propType = PropertyType::Setter; | ||||
| 11940 | } else { | ||||
| 11941 | *propType = PropertyType::Method; | ||||
| 11942 | } | ||||
| 11943 | return propName; | ||||
| 11944 | } | ||||
| 11945 | |||||
| 11946 | if (propertyNameContext == PropertyNameInClass) { | ||||
| 11947 | if (isGenerator || isAsync || isGetter || isSetter) { | ||||
| 11948 | error(JSMSG_BAD_PROP_ID); | ||||
| 11949 | return errorResult(); | ||||
| 11950 | } | ||||
| 11951 | anyChars.ungetToken(); | ||||
| 11952 | #ifdef ENABLE_DECORATORS | ||||
| 11953 | if (!hasAccessor) { | ||||
| 11954 | *propType = PropertyType::Field; | ||||
| 11955 | } else { | ||||
| 11956 | *propType = PropertyType::FieldWithAccessor; | ||||
| 11957 | } | ||||
| 11958 | #else | ||||
| 11959 | *propType = PropertyType::Field; | ||||
| 11960 | #endif | ||||
| 11961 | return propName; | ||||
| 11962 | } | ||||
| 11963 | |||||
| 11964 | error(JSMSG_COLON_AFTER_ID); | ||||
| 11965 | return errorResult(); | ||||
| 11966 | } | ||||
| 11967 | |||||
| 11968 | template <class ParseHandler, typename Unit> | ||||
| 11969 | typename ParseHandler::UnaryNodeResult | ||||
| 11970 | GeneralParser<ParseHandler, Unit>::computedPropertyName( | ||||
| 11971 | YieldHandling yieldHandling, const Maybe<DeclarationKind>& maybeDecl, | ||||
| 11972 | PropertyNameContext propertyNameContext, ListNodeType literal) { | ||||
| 11973 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftBracket))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftBracket)) >::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftBracket)) )), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftBracket)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 11973); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket)" ")"); do { MOZ_CrashSequence(__null, 11973); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 11974 | |||||
| 11975 | uint32_t begin = pos().begin; | ||||
| 11976 | |||||
| 11977 | if (maybeDecl) { | ||||
| 11978 | if (*maybeDecl == DeclarationKind::FormalParameter) { | ||||
| 11979 | pc_->functionBox()->hasParameterExprs = true; | ||||
| 11980 | } | ||||
| 11981 | } else if (propertyNameContext == | ||||
| 11982 | PropertyNameContext::PropertyNameInLiteral) { | ||||
| 11983 | handler_.setListHasNonConstInitializer(literal); | ||||
| 11984 | } | ||||
| 11985 | |||||
| 11986 | Node assignNode = | ||||
| 11987 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 11988 | |||||
| 11989 | if (!mustMatchToken(TokenKind::RightBracket, JSMSG_COMP_PROP_UNTERM_EXPR)) { | ||||
| 11990 | return errorResult(); | ||||
| 11991 | } | ||||
| 11992 | return handler_.newComputedName(assignNode, begin, pos().end); | ||||
| 11993 | } | ||||
| 11994 | |||||
| 11995 | template <class ParseHandler, typename Unit> | ||||
| 11996 | typename ParseHandler::ListNodeResult | ||||
| 11997 | GeneralParser<ParseHandler, Unit>::objectLiteral(YieldHandling yieldHandling, | ||||
| 11998 | PossibleError* possibleError) { | ||||
| 11999 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftCurly))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftCurly))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftCurly)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftCurly)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 11999); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)" ")"); do { MOZ_CrashSequence(__null, 11999); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 12000 | |||||
| 12001 | uint32_t openedPos = pos().begin; | ||||
| 12002 | |||||
| 12003 | ListNodeType literal = MOZ_TRY(handler_.newObjectLiteral(pos().begin))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newObjectLiteral(pos().begin)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12004 | |||||
| 12005 | bool seenPrototypeMutation = false; | ||||
| 12006 | bool seenCoverInitializedName = false; | ||||
| 12007 | Maybe<DeclarationKind> declKind = Nothing(); | ||||
| 12008 | TaggedParserAtomIndex propAtom; | ||||
| 12009 | for (;;) { | ||||
| 12010 | TokenKind tt; | ||||
| 12011 | if (!tokenStream.peekToken(&tt)) { | ||||
| 12012 | return errorResult(); | ||||
| 12013 | } | ||||
| 12014 | if (tt == TokenKind::RightCurly) { | ||||
| 12015 | break; | ||||
| 12016 | } | ||||
| 12017 | |||||
| 12018 | if (tt == TokenKind::TripleDot) { | ||||
| 12019 | tokenStream.consumeKnownToken(TokenKind::TripleDot); | ||||
| 12020 | uint32_t begin = pos().begin; | ||||
| 12021 | |||||
| 12022 | TokenPos innerPos; | ||||
| 12023 | if (!tokenStream.peekTokenPos(&innerPos, TokenStream::SlashIsRegExp)) { | ||||
| 12024 | return errorResult(); | ||||
| 12025 | } | ||||
| 12026 | |||||
| 12027 | PossibleError possibleErrorInner(*this); | ||||
| 12028 | Node inner = MOZ_TRY(assignExpr(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr( InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 12029 | InAllowed, yieldHandling, TripledotProhibited, &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr( InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12030 | if (!checkDestructuringAssignmentTarget( | ||||
| 12031 | inner, innerPos, &possibleErrorInner, possibleError, | ||||
| 12032 | TargetBehavior::ForbidAssignmentPattern)) { | ||||
| 12033 | return errorResult(); | ||||
| 12034 | } | ||||
| 12035 | if (!handler_.addSpreadProperty(literal, begin, inner)) { | ||||
| 12036 | return errorResult(); | ||||
| 12037 | } | ||||
| 12038 | } else { | ||||
| 12039 | TokenPos namePos = anyChars.nextToken().pos; | ||||
| 12040 | |||||
| 12041 | PropertyType propType; | ||||
| 12042 | Node propName = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyOrMethodName(yieldHandling, PropertyNameInLiteral, declKind , literal, &propType, &propAtom)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 12043 | propertyOrMethodName(yieldHandling, PropertyNameInLiteral, declKind,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyOrMethodName(yieldHandling, PropertyNameInLiteral, declKind , literal, &propType, &propAtom)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 12044 | literal, &propType, &propAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (propertyOrMethodName(yieldHandling, PropertyNameInLiteral, declKind , literal, &propType, &propAtom)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12045 | |||||
| 12046 | if (propType == PropertyType::Normal) { | ||||
| 12047 | TokenPos exprPos; | ||||
| 12048 | if (!tokenStream.peekTokenPos(&exprPos, TokenStream::SlashIsRegExp)) { | ||||
| 12049 | return errorResult(); | ||||
| 12050 | } | ||||
| 12051 | |||||
| 12052 | PossibleError possibleErrorInner(*this); | ||||
| 12053 | Node propExpr = | ||||
| 12054 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 12055 | &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited, & possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12056 | |||||
| 12057 | if (!checkDestructuringAssignmentElement( | ||||
| 12058 | propExpr, exprPos, &possibleErrorInner, possibleError)) { | ||||
| 12059 | return errorResult(); | ||||
| 12060 | } | ||||
| 12061 | |||||
| 12062 | if (propAtom == TaggedParserAtomIndex::WellKnown::proto_()) { | ||||
| 12063 | if (seenPrototypeMutation) { | ||||
| 12064 | // Directly report the error when we're definitely not | ||||
| 12065 | // in a destructuring context. | ||||
| 12066 | if (!possibleError) { | ||||
| 12067 | errorAt(namePos.begin, JSMSG_DUPLICATE_PROTO_PROPERTY); | ||||
| 12068 | return errorResult(); | ||||
| 12069 | } | ||||
| 12070 | |||||
| 12071 | // Otherwise delay error reporting until we've | ||||
| 12072 | // determined whether or not we're destructuring. | ||||
| 12073 | possibleError->setPendingExpressionErrorAt( | ||||
| 12074 | namePos, JSMSG_DUPLICATE_PROTO_PROPERTY); | ||||
| 12075 | } | ||||
| 12076 | seenPrototypeMutation = true; | ||||
| 12077 | |||||
| 12078 | // This occurs *only* if we observe PropertyType::Normal! | ||||
| 12079 | // Only |__proto__: v| mutates [[Prototype]]. Getters, | ||||
| 12080 | // setters, method/generator definitions, computed | ||||
| 12081 | // property name versions of all of these, and shorthands | ||||
| 12082 | // do not. | ||||
| 12083 | if (!handler_.addPrototypeMutation(literal, namePos.begin, | ||||
| 12084 | propExpr)) { | ||||
| 12085 | return errorResult(); | ||||
| 12086 | } | ||||
| 12087 | } else { | ||||
| 12088 | BinaryNodeType propDef = | ||||
| 12089 | MOZ_TRY(handler_.newPropertyDefinition(propName, propExpr))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPropertyDefinition(propName, propExpr)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12090 | |||||
| 12091 | handler_.addPropertyDefinition(literal, propDef); | ||||
| 12092 | } | ||||
| 12093 | } else if (propType == PropertyType::Shorthand) { | ||||
| 12094 | /* | ||||
| 12095 | * Support, e.g., |({x, y} = o)| as destructuring shorthand | ||||
| 12096 | * for |({x: x, y: y} = o)|, and |var o = {x, y}| as | ||||
| 12097 | * initializer shorthand for |var o = {x: x, y: y}|. | ||||
| 12098 | */ | ||||
| 12099 | TaggedParserAtomIndex name = identifierReference(yieldHandling); | ||||
| 12100 | if (!name) { | ||||
| 12101 | return errorResult(); | ||||
| 12102 | } | ||||
| 12103 | |||||
| 12104 | NameNodeType nameExpr = MOZ_TRY(identifierReference(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (identifierReference(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12105 | |||||
| 12106 | if (possibleError) { | ||||
| 12107 | checkDestructuringAssignmentName(nameExpr, namePos, possibleError); | ||||
| 12108 | } | ||||
| 12109 | |||||
| 12110 | if (!handler_.addShorthand(literal, handler_.asNameNode(propName), | ||||
| 12111 | nameExpr)) { | ||||
| 12112 | return errorResult(); | ||||
| 12113 | } | ||||
| 12114 | } else if (propType == PropertyType::CoverInitializedName) { | ||||
| 12115 | /* | ||||
| 12116 | * Support, e.g., |({x=1, y=2} = o)| as destructuring | ||||
| 12117 | * shorthand with default values, as per ES6 12.14.5 | ||||
| 12118 | */ | ||||
| 12119 | TaggedParserAtomIndex name = identifierReference(yieldHandling); | ||||
| 12120 | if (!name) { | ||||
| 12121 | return errorResult(); | ||||
| 12122 | } | ||||
| 12123 | |||||
| 12124 | Node lhs = MOZ_TRY(identifierReference(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (identifierReference(name)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12125 | |||||
| 12126 | tokenStream.consumeKnownToken(TokenKind::Assign); | ||||
| 12127 | |||||
| 12128 | if (!seenCoverInitializedName) { | ||||
| 12129 | // "shorthand default" or "CoverInitializedName" syntax is | ||||
| 12130 | // only valid in the case of destructuring. | ||||
| 12131 | seenCoverInitializedName = true; | ||||
| 12132 | |||||
| 12133 | if (!possibleError) { | ||||
| 12134 | // Destructuring defaults are definitely not allowed | ||||
| 12135 | // in this object literal, because of something the | ||||
| 12136 | // caller knows about the preceding code. For example, | ||||
| 12137 | // maybe the preceding token is an operator: | ||||
| 12138 | // |x + {y=z}|. | ||||
| 12139 | error(JSMSG_COLON_AFTER_ID); | ||||
| 12140 | return errorResult(); | ||||
| 12141 | } | ||||
| 12142 | |||||
| 12143 | // Here we set a pending error so that later in the parse, | ||||
| 12144 | // once we've determined whether or not we're | ||||
| 12145 | // destructuring, the error can be reported or ignored | ||||
| 12146 | // appropriately. | ||||
| 12147 | possibleError->setPendingExpressionErrorAt(pos(), | ||||
| 12148 | JSMSG_COLON_AFTER_ID); | ||||
| 12149 | } | ||||
| 12150 | |||||
| 12151 | if (const char* chars = nameIsArgumentsOrEval(lhs)) { | ||||
| 12152 | // |chars| is "arguments" or "eval" here. | ||||
| 12153 | if (!strictModeErrorAt(namePos.begin, JSMSG_BAD_STRICT_ASSIGN, | ||||
| 12154 | chars)) { | ||||
| 12155 | return errorResult(); | ||||
| 12156 | } | ||||
| 12157 | } | ||||
| 12158 | |||||
| 12159 | if (handler_.isArgumentsLength(lhs)) { | ||||
| 12160 | pc_->sc()->setIneligibleForArgumentsLength(); | ||||
| 12161 | } | ||||
| 12162 | |||||
| 12163 | Node rhs = | ||||
| 12164 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 12165 | |||||
| 12166 | BinaryNodeType propExpr = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newAssignment(ParseNodeKind::AssignExpr, lhs, rhs)) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 12167 | handler_.newAssignment(ParseNodeKind::AssignExpr, lhs, rhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newAssignment(ParseNodeKind::AssignExpr, lhs, rhs)) ; if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 12168 | |||||
| 12169 | if (!handler_.addPropertyDefinition(literal, propName, propExpr)) { | ||||
| 12170 | return errorResult(); | ||||
| 12171 | } | ||||
| 12172 | } else { | ||||
| 12173 | TaggedParserAtomIndex funName; | ||||
| 12174 | bool hasStaticName = | ||||
| 12175 | !anyChars.isCurrentTokenType(TokenKind::RightBracket) && propAtom; | ||||
| 12176 | if (hasStaticName) { | ||||
| 12177 | funName = propAtom; | ||||
| 12178 | |||||
| 12179 | if (propType == PropertyType::Getter || | ||||
| 12180 | propType == PropertyType::Setter) { | ||||
| 12181 | funName = prefixAccessorName(propType, propAtom); | ||||
| 12182 | if (!funName) { | ||||
| 12183 | return errorResult(); | ||||
| 12184 | } | ||||
| 12185 | } | ||||
| 12186 | } | ||||
| 12187 | |||||
| 12188 | FunctionNodeType funNode = | ||||
| 12189 | MOZ_TRY(methodDefinition(namePos.begin, propType, funName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (methodDefinition(namePos.begin, propType, funName)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12190 | |||||
| 12191 | AccessorType atype = ToAccessorType(propType); | ||||
| 12192 | if (!handler_.addObjectMethodDefinition(literal, propName, funNode, | ||||
| 12193 | atype)) { | ||||
| 12194 | return errorResult(); | ||||
| 12195 | } | ||||
| 12196 | |||||
| 12197 | if (possibleError) { | ||||
| 12198 | possibleError->setPendingDestructuringErrorAt( | ||||
| 12199 | namePos, JSMSG_BAD_DESTRUCT_TARGET); | ||||
| 12200 | } | ||||
| 12201 | } | ||||
| 12202 | } | ||||
| 12203 | |||||
| 12204 | bool matched; | ||||
| 12205 | if (!tokenStream.matchToken(&matched, TokenKind::Comma, | ||||
| 12206 | TokenStream::SlashIsInvalid)) { | ||||
| 12207 | return errorResult(); | ||||
| 12208 | } | ||||
| 12209 | if (!matched) { | ||||
| 12210 | break; | ||||
| 12211 | } | ||||
| 12212 | if (tt == TokenKind::TripleDot && possibleError) { | ||||
| 12213 | possibleError->setPendingDestructuringErrorAt(pos(), | ||||
| 12214 | JSMSG_REST_WITH_COMMA); | ||||
| 12215 | } | ||||
| 12216 | } | ||||
| 12217 | |||||
| 12218 | if (!mustMatchToken( | ||||
| 12219 | TokenKind::RightCurly, [this, openedPos](TokenKind actual) { | ||||
| 12220 | this->reportMissingClosing(JSMSG_CURLY_AFTER_LIST, | ||||
| 12221 | JSMSG_CURLY_OPENED, openedPos); | ||||
| 12222 | })) { | ||||
| 12223 | return errorResult(); | ||||
| 12224 | } | ||||
| 12225 | |||||
| 12226 | handler_.setEndPosition(literal, pos().end); | ||||
| 12227 | return literal; | ||||
| 12228 | } | ||||
| 12229 | |||||
| 12230 | template <class ParseHandler, typename Unit> | ||||
| 12231 | typename ParseHandler::FunctionNodeResult | ||||
| 12232 | GeneralParser<ParseHandler, Unit>::methodDefinition( | ||||
| 12233 | uint32_t toStringStart, PropertyType propType, | ||||
| 12234 | TaggedParserAtomIndex funName) { | ||||
| 12235 | FunctionSyntaxKind syntaxKind; | ||||
| 12236 | switch (propType) { | ||||
| 12237 | case PropertyType::Getter: | ||||
| 12238 | syntaxKind = FunctionSyntaxKind::Getter; | ||||
| 12239 | break; | ||||
| 12240 | |||||
| 12241 | case PropertyType::Setter: | ||||
| 12242 | syntaxKind = FunctionSyntaxKind::Setter; | ||||
| 12243 | break; | ||||
| 12244 | |||||
| 12245 | case PropertyType::Method: | ||||
| 12246 | case PropertyType::GeneratorMethod: | ||||
| 12247 | case PropertyType::AsyncMethod: | ||||
| 12248 | case PropertyType::AsyncGeneratorMethod: | ||||
| 12249 | syntaxKind = FunctionSyntaxKind::Method; | ||||
| 12250 | break; | ||||
| 12251 | |||||
| 12252 | case PropertyType::Constructor: | ||||
| 12253 | syntaxKind = FunctionSyntaxKind::ClassConstructor; | ||||
| 12254 | break; | ||||
| 12255 | |||||
| 12256 | case PropertyType::DerivedConstructor: | ||||
| 12257 | syntaxKind = FunctionSyntaxKind::DerivedClassConstructor; | ||||
| 12258 | break; | ||||
| 12259 | |||||
| 12260 | default: | ||||
| 12261 | MOZ_CRASH("unexpected property type")do { do { } while (false); MOZ_ReportCrash("" "unexpected property type" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 12261); AnnotateMozCrashReason ("MOZ_CRASH(" "unexpected property type" ")"); do { MOZ_CrashSequence (__null, 12261); __attribute__((nomerge)) ::abort(); } while ( false); } while (false); | ||||
| 12262 | } | ||||
| 12263 | |||||
| 12264 | GeneratorKind generatorKind = (propType == PropertyType::GeneratorMethod || | ||||
| 12265 | propType == PropertyType::AsyncGeneratorMethod) | ||||
| 12266 | ? GeneratorKind::Generator | ||||
| 12267 | : GeneratorKind::NotGenerator; | ||||
| 12268 | |||||
| 12269 | FunctionAsyncKind asyncKind = (propType == PropertyType::AsyncMethod || | ||||
| 12270 | propType == PropertyType::AsyncGeneratorMethod) | ||||
| 12271 | ? FunctionAsyncKind::AsyncFunction | ||||
| 12272 | : FunctionAsyncKind::SyncFunction; | ||||
| 12273 | |||||
| 12274 | YieldHandling yieldHandling = GetYieldHandling(generatorKind); | ||||
| 12275 | |||||
| 12276 | FunctionNodeType funNode = MOZ_TRY(handler_.newFunction(syntaxKind, pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newFunction(syntaxKind, pos())); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12277 | |||||
| 12278 | return functionDefinition(funNode, toStringStart, InAllowed, yieldHandling, | ||||
| 12279 | funName, syntaxKind, generatorKind, asyncKind); | ||||
| 12280 | } | ||||
| 12281 | |||||
| 12282 | template <class ParseHandler, typename Unit> | ||||
| 12283 | bool GeneralParser<ParseHandler, Unit>::tryNewTarget( | ||||
| 12284 | NewTargetNodeType* newTarget) { | ||||
| 12285 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::New))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::New))>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(anyChars.isCurrentTokenType(TokenKind::New)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::New)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 12285); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::New)" ")"); do { MOZ_CrashSequence(__null, 12285); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 12286 | |||||
| 12287 | *newTarget = null(); | ||||
| 12288 | |||||
| 12289 | NullaryNodeType newHolder; | ||||
| 12290 | MOZ_TRY_VAR_OR_RETURN(newHolder, handler_.newPosHolder(pos()), false)do { auto parserTryVarTempResult_ = (handler_.newPosHolder(pos ())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr( )), 0))) { return (false); } (newHolder) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 12291 | |||||
| 12292 | uint32_t begin = pos().begin; | ||||
| 12293 | |||||
| 12294 | // |new| expects to look for an operand, so we will honor that. | ||||
| 12295 | TokenKind next; | ||||
| 12296 | if (!tokenStream.getToken(&next, TokenStream::SlashIsRegExp)) { | ||||
| 12297 | return false; | ||||
| 12298 | } | ||||
| 12299 | |||||
| 12300 | // Don't unget the token, since lookahead cannot handle someone calling | ||||
| 12301 | // getToken() with a different modifier. Callers should inspect | ||||
| 12302 | // currentToken(). | ||||
| 12303 | if (next != TokenKind::Dot) { | ||||
| 12304 | return true; | ||||
| 12305 | } | ||||
| 12306 | |||||
| 12307 | if (!tokenStream.getToken(&next)) { | ||||
| 12308 | return false; | ||||
| 12309 | } | ||||
| 12310 | if (next != TokenKind::Target) { | ||||
| 12311 | error(JSMSG_UNEXPECTED_TOKEN, "target", TokenKindToDesc(next)); | ||||
| 12312 | return false; | ||||
| 12313 | } | ||||
| 12314 | |||||
| 12315 | if (!pc_->sc()->allowNewTarget()) { | ||||
| 12316 | errorAt(begin, JSMSG_BAD_NEWTARGET); | ||||
| 12317 | return false; | ||||
| 12318 | } | ||||
| 12319 | |||||
| 12320 | NullaryNodeType targetHolder; | ||||
| 12321 | MOZ_TRY_VAR_OR_RETURN(targetHolder, handler_.newPosHolder(pos()), false)do { auto parserTryVarTempResult_ = (handler_.newPosHolder(pos ())); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr( )), 0))) { return (false); } (targetHolder) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 12322 | |||||
| 12323 | NameNodeType newTargetName; | ||||
| 12324 | MOZ_TRY_VAR_OR_RETURN(newTargetName, newNewTargetName(), false)do { auto parserTryVarTempResult_ = (newNewTargetName()); if ( (__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (newTargetName) = parserTryVarTempResult_. unwrap(); } while (0); | ||||
| 12325 | |||||
| 12326 | MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newNewTarget(newHolder , targetHolder, newTargetName)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (*newTarget) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 12327 | *newTarget, handler_.newNewTarget(newHolder, targetHolder, newTargetName),do { auto parserTryVarTempResult_ = (handler_.newNewTarget(newHolder , targetHolder, newTargetName)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (*newTarget) = parserTryVarTempResult_ .unwrap(); } while (0) | ||||
| 12328 | false)do { auto parserTryVarTempResult_ = (handler_.newNewTarget(newHolder , targetHolder, newTargetName)); if ((__builtin_expect(!!(parserTryVarTempResult_ .isErr()), 0))) { return (false); } (*newTarget) = parserTryVarTempResult_ .unwrap(); } while (0); | ||||
| 12329 | |||||
| 12330 | return true; | ||||
| 12331 | } | ||||
| 12332 | |||||
| 12333 | template <class ParseHandler, typename Unit> | ||||
| 12334 | typename ParseHandler::BinaryNodeResult | ||||
| 12335 | GeneralParser<ParseHandler, Unit>::importExpr(YieldHandling yieldHandling, | ||||
| 12336 | bool allowCallSyntax) { | ||||
| 12337 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::Import))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::Import))>:: isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::Import)))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::Import)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 12337); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Import)" ")"); do { MOZ_CrashSequence(__null, 12337); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 12338 | |||||
| 12339 | NullaryNodeType importHolder = MOZ_TRY(handler_.newPosHolder(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPosHolder(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12340 | |||||
| 12341 | TokenKind next; | ||||
| 12342 | if (!tokenStream.getToken(&next)) { | ||||
| 12343 | return errorResult(); | ||||
| 12344 | } | ||||
| 12345 | |||||
| 12346 | ImportPhase phase = ImportPhase::Evaluation; | ||||
| 12347 | |||||
| 12348 | if (next == TokenKind::Dot) { | ||||
| 12349 | if (!tokenStream.getToken(&next)) { | ||||
| 12350 | return errorResult(); | ||||
| 12351 | } | ||||
| 12352 | if (next == TokenKind::Meta) { | ||||
| 12353 | if (parseGoal() != ParseGoal::Module) { | ||||
| 12354 | errorAt(pos().begin, JSMSG_IMPORT_META_OUTSIDE_MODULE); | ||||
| 12355 | return errorResult(); | ||||
| 12356 | } | ||||
| 12357 | |||||
| 12358 | NullaryNodeType metaHolder = MOZ_TRY(handler_.newPosHolder(pos()))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPosHolder(pos())); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12359 | |||||
| 12360 | return handler_.newImportMeta(importHolder, metaHolder); | ||||
| 12361 | } | ||||
| 12362 | |||||
| 12363 | if (options().sourcePhaseImports() && next == TokenKind::Source) { | ||||
| 12364 | phase = ImportPhase::Source; | ||||
| 12365 | } else { | ||||
| 12366 | error(JSMSG_UNEXPECTED_TOKEN, | ||||
| 12367 | options().sourcePhaseImports() ? "meta or source" : "meta", | ||||
| 12368 | TokenKindToDesc(next)); | ||||
| 12369 | return errorResult(); | ||||
| 12370 | } | ||||
| 12371 | |||||
| 12372 | if (!tokenStream.getToken(&next)) { | ||||
| 12373 | return errorResult(); | ||||
| 12374 | } | ||||
| 12375 | } | ||||
| 12376 | |||||
| 12377 | if (next == TokenKind::LeftParen && allowCallSyntax) { | ||||
| 12378 | Node arg = | ||||
| 12379 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 12380 | |||||
| 12381 | if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) { | ||||
| 12382 | return errorResult(); | ||||
| 12383 | } | ||||
| 12384 | |||||
| 12385 | Node optionalArg; | ||||
| 12386 | if (next == TokenKind::Comma | ||||
| 12387 | // Unlike `import`, `import.source` does not have an optional parameter. | ||||
| 12388 | && phase != ImportPhase::Source) { | ||||
| 12389 | tokenStream.consumeKnownToken(TokenKind::Comma, | ||||
| 12390 | TokenStream::SlashIsRegExp); | ||||
| 12391 | |||||
| 12392 | if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) { | ||||
| 12393 | return errorResult(); | ||||
| 12394 | } | ||||
| 12395 | |||||
| 12396 | if (next != TokenKind::RightParen) { | ||||
| 12397 | optionalArg = | ||||
| 12398 | MOZ_TRY(assignExpr(InAllowed, yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (assignExpr(InAllowed, yieldHandling, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 12399 | |||||
| 12400 | if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) { | ||||
| 12401 | return errorResult(); | ||||
| 12402 | } | ||||
| 12403 | |||||
| 12404 | if (next == TokenKind::Comma) { | ||||
| 12405 | tokenStream.consumeKnownToken(TokenKind::Comma, | ||||
| 12406 | TokenStream::SlashIsRegExp); | ||||
| 12407 | } | ||||
| 12408 | } else { | ||||
| 12409 | optionalArg = | ||||
| 12410 | MOZ_TRY(handler_.newPosHolder(TokenPos(pos().end, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPosHolder(TokenPos(pos().end, pos().end))); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 12411 | } | ||||
| 12412 | } else { | ||||
| 12413 | optionalArg = | ||||
| 12414 | MOZ_TRY(handler_.newPosHolder(TokenPos(pos().end, pos().end)))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newPosHolder(TokenPos(pos().end, pos().end))); if ( (__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap (); }); | ||||
| 12415 | } | ||||
| 12416 | |||||
| 12417 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_ARGS)) { | ||||
| 12418 | return errorResult(); | ||||
| 12419 | } | ||||
| 12420 | |||||
| 12421 | Node spec = MOZ_TRY(handler_.newCallImportSpec(arg, optionalArg))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (handler_.newCallImportSpec(arg, optionalArg)); if ((__builtin_expect (!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult .propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12422 | |||||
| 12423 | return handler_.newCallImport(importHolder, spec, phase); | ||||
| 12424 | } | ||||
| 12425 | |||||
| 12426 | error(JSMSG_UNEXPECTED_TOKEN_NO_EXPECT, TokenKindToDesc(next)); | ||||
| 12427 | return errorResult(); | ||||
| 12428 | } | ||||
| 12429 | |||||
| 12430 | template <class ParseHandler, typename Unit> | ||||
| 12431 | typename ParseHandler::NodeResult | ||||
| 12432 | GeneralParser<ParseHandler, Unit>::primaryExpr( | ||||
| 12433 | YieldHandling yieldHandling, TripledotHandling tripledotHandling, | ||||
| 12434 | TokenKind tt, PossibleError* possibleError, InvokedPrediction invoked) { | ||||
| 12435 | MOZ_ASSERT(anyChars.isCurrentTokenType(tt))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(tt))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(anyChars.isCurrentTokenType( tt)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("anyChars.isCurrentTokenType(tt)", "/root/firefox-clang/js/src/frontend/Parser.cpp" , 12435); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)" ")"); do { MOZ_CrashSequence(__null, 12435); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 12436 | AutoCheckRecursionLimit recursion(this->fc_); | ||||
| 12437 | if (!recursion.check(this->fc_)) { | ||||
| 12438 | return errorResult(); | ||||
| 12439 | } | ||||
| 12440 | |||||
| 12441 | switch (tt) { | ||||
| 12442 | case TokenKind::Function: | ||||
| 12443 | return functionExpr(pos().begin, invoked, | ||||
| 12444 | FunctionAsyncKind::SyncFunction); | ||||
| 12445 | |||||
| 12446 | case TokenKind::Class: | ||||
| 12447 | return classDefinition(yieldHandling, ClassExpression, NameRequired); | ||||
| 12448 | |||||
| 12449 | case TokenKind::LeftBracket: | ||||
| 12450 | return arrayInitializer(yieldHandling, possibleError); | ||||
| 12451 | |||||
| 12452 | case TokenKind::LeftCurly: | ||||
| 12453 | return objectLiteral(yieldHandling, possibleError); | ||||
| 12454 | |||||
| 12455 | #ifdef ENABLE_DECORATORS | ||||
| 12456 | case TokenKind::At: | ||||
| 12457 | if (fuzzingSafe) { | ||||
| 12458 | error(JSMSG_DECORATOR_FUZZING_UNSAFE); | ||||
| 12459 | return errorResult(); | ||||
| 12460 | } | ||||
| 12461 | |||||
| 12462 | return classDefinition(yieldHandling, ClassExpression, NameRequired); | ||||
| 12463 | #endif | ||||
| 12464 | |||||
| 12465 | case TokenKind::LeftParen: { | ||||
| 12466 | TokenKind next; | ||||
| 12467 | if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) { | ||||
| 12468 | return errorResult(); | ||||
| 12469 | } | ||||
| 12470 | |||||
| 12471 | if (next == TokenKind::RightParen) { | ||||
| 12472 | // Not valid expression syntax, but this is valid in an arrow function | ||||
| 12473 | // with no params: `() => body`. | ||||
| 12474 | tokenStream.consumeKnownToken(TokenKind::RightParen, | ||||
| 12475 | TokenStream::SlashIsRegExp); | ||||
| 12476 | |||||
| 12477 | if (!tokenStream.peekToken(&next)) { | ||||
| 12478 | return errorResult(); | ||||
| 12479 | } | ||||
| 12480 | if (next != TokenKind::Arrow) { | ||||
| 12481 | error(JSMSG_UNEXPECTED_TOKEN, "expression", | ||||
| 12482 | TokenKindToDesc(TokenKind::RightParen)); | ||||
| 12483 | return errorResult(); | ||||
| 12484 | } | ||||
| 12485 | |||||
| 12486 | // Now just return something that will allow parsing to continue. | ||||
| 12487 | // It doesn't matter what; when we reach the =>, we will rewind and | ||||
| 12488 | // reparse the whole arrow function. See Parser::assignExpr. | ||||
| 12489 | return handler_.newNullLiteral(pos()); | ||||
| 12490 | } | ||||
| 12491 | |||||
| 12492 | // Pass |possibleError| to support destructuring in arrow parameters. | ||||
| 12493 | Node expr = MOZ_TRY(exprInParens(InAllowed, yieldHandling,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (exprInParens(InAllowed, yieldHandling, TripledotAllowed, possibleError )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }) | ||||
| 12494 | TripledotAllowed, possibleError))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (exprInParens(InAllowed, yieldHandling, TripledotAllowed, possibleError )); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0) )) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult .unwrap(); }); | ||||
| 12495 | if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_IN_PAREN)) { | ||||
| 12496 | return errorResult(); | ||||
| 12497 | } | ||||
| 12498 | return handler_.parenthesize(expr); | ||||
| 12499 | } | ||||
| 12500 | |||||
| 12501 | case TokenKind::TemplateHead: | ||||
| 12502 | return templateLiteral(yieldHandling); | ||||
| 12503 | |||||
| 12504 | case TokenKind::NoSubsTemplate: | ||||
| 12505 | return noSubstitutionUntaggedTemplate(); | ||||
| 12506 | |||||
| 12507 | case TokenKind::String: | ||||
| 12508 | return stringLiteral(); | ||||
| 12509 | |||||
| 12510 | default: { | ||||
| 12511 | if (!TokenKindIsPossibleIdentifier(tt)) { | ||||
| 12512 | error(JSMSG_UNEXPECTED_TOKEN, "expression", TokenKindToDesc(tt)); | ||||
| 12513 | return errorResult(); | ||||
| 12514 | } | ||||
| 12515 | |||||
| 12516 | if (tt == TokenKind::Async) { | ||||
| 12517 | TokenKind nextSameLine = TokenKind::Eof; | ||||
| 12518 | if (!tokenStream.peekTokenSameLine(&nextSameLine)) { | ||||
| 12519 | return errorResult(); | ||||
| 12520 | } | ||||
| 12521 | |||||
| 12522 | if (nextSameLine == TokenKind::Function) { | ||||
| 12523 | uint32_t toStringStart = pos().begin; | ||||
| 12524 | tokenStream.consumeKnownToken(TokenKind::Function); | ||||
| 12525 | return functionExpr(toStringStart, PredictUninvoked, | ||||
| 12526 | FunctionAsyncKind::AsyncFunction); | ||||
| 12527 | } | ||||
| 12528 | } | ||||
| 12529 | |||||
| 12530 | TaggedParserAtomIndex name = identifierReference(yieldHandling); | ||||
| 12531 | if (!name) { | ||||
| 12532 | return errorResult(); | ||||
| 12533 | } | ||||
| 12534 | |||||
| 12535 | return identifierReference(name); | ||||
| 12536 | } | ||||
| 12537 | |||||
| 12538 | case TokenKind::RegExp: | ||||
| 12539 | return newRegExp(); | ||||
| 12540 | |||||
| 12541 | case TokenKind::Number: | ||||
| 12542 | return newNumber(anyChars.currentToken()); | ||||
| 12543 | |||||
| 12544 | case TokenKind::BigInt: | ||||
| 12545 | return newBigInt(); | ||||
| 12546 | |||||
| 12547 | case TokenKind::True: | ||||
| 12548 | return handler_.newBooleanLiteral(true, pos()); | ||||
| 12549 | case TokenKind::False: | ||||
| 12550 | return handler_.newBooleanLiteral(false, pos()); | ||||
| 12551 | case TokenKind::This: { | ||||
| 12552 | NameNodeType thisName = null(); | ||||
| 12553 | if (pc_->sc()->hasFunctionThisBinding()) { | ||||
| 12554 | thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12555 | } | ||||
| 12556 | return handler_.newThisLiteral(pos(), thisName); | ||||
| 12557 | } | ||||
| 12558 | case TokenKind::Null: | ||||
| 12559 | return handler_.newNullLiteral(pos()); | ||||
| 12560 | |||||
| 12561 | case TokenKind::TripleDot: { | ||||
| 12562 | // This isn't valid expression syntax, but it's valid in an arrow | ||||
| 12563 | // function as a trailing rest param: `(a, b, ...rest) => body`. Check | ||||
| 12564 | // if it's directly under | ||||
| 12565 | // CoverParenthesizedExpressionAndArrowParameterList, and check for a | ||||
| 12566 | // name, closing parenthesis, and arrow, and allow it only if all are | ||||
| 12567 | // present. | ||||
| 12568 | if (tripledotHandling != TripledotAllowed) { | ||||
| 12569 | error(JSMSG_UNEXPECTED_TOKEN, "expression", TokenKindToDesc(tt)); | ||||
| 12570 | return errorResult(); | ||||
| 12571 | } | ||||
| 12572 | |||||
| 12573 | TokenKind next; | ||||
| 12574 | if (!tokenStream.getToken(&next)) { | ||||
| 12575 | return errorResult(); | ||||
| 12576 | } | ||||
| 12577 | |||||
| 12578 | if (next == TokenKind::LeftBracket || next == TokenKind::LeftCurly) { | ||||
| 12579 | // Validate, but don't store the pattern right now. The whole arrow | ||||
| 12580 | // function is reparsed in functionFormalParametersAndBody(). | ||||
| 12581 | MOZ_TRY(destructuringDeclaration(DeclarationKind::CoverArrowParameter,__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (destructuringDeclaration(DeclarationKind::CoverArrowParameter , yieldHandling, next)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }) | ||||
| 12582 | yieldHandling, next))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult (destructuringDeclaration(DeclarationKind::CoverArrowParameter , yieldHandling, next)); if ((__builtin_expect(!!(mozTryVarTempResult .isErr()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap(); }); | ||||
| 12583 | } else { | ||||
| 12584 | // This doesn't check that the provided name is allowed, e.g. if | ||||
| 12585 | // the enclosing code is strict mode code, any of "let", "yield", | ||||
| 12586 | // or "arguments" should be prohibited. Argument-parsing code | ||||
| 12587 | // handles that. | ||||
| 12588 | if (!TokenKindIsPossibleIdentifier(next)) { | ||||
| 12589 | error(JSMSG_UNEXPECTED_TOKEN, "rest argument name", | ||||
| 12590 | TokenKindToDesc(next)); | ||||
| 12591 | return errorResult(); | ||||
| 12592 | } | ||||
| 12593 | } | ||||
| 12594 | |||||
| 12595 | if (!tokenStream.getToken(&next)) { | ||||
| 12596 | return errorResult(); | ||||
| 12597 | } | ||||
| 12598 | if (next != TokenKind::RightParen) { | ||||
| 12599 | error(JSMSG_UNEXPECTED_TOKEN, "closing parenthesis", | ||||
| 12600 | TokenKindToDesc(next)); | ||||
| 12601 | return errorResult(); | ||||
| 12602 | } | ||||
| 12603 | |||||
| 12604 | if (!tokenStream.peekToken(&next)) { | ||||
| 12605 | return errorResult(); | ||||
| 12606 | } | ||||
| 12607 | if (next != TokenKind::Arrow) { | ||||
| 12608 | // Advance the scanner for proper error location reporting. | ||||
| 12609 | tokenStream.consumeKnownToken(next); | ||||
| 12610 | error(JSMSG_UNEXPECTED_TOKEN, "'=>' after argument list", | ||||
| 12611 | TokenKindToDesc(next)); | ||||
| 12612 | return errorResult(); | ||||
| 12613 | } | ||||
| 12614 | |||||
| 12615 | anyChars.ungetToken(); // put back right paren | ||||
| 12616 | |||||
| 12617 | // Return an arbitrary expression node. See case TokenKind::RightParen | ||||
| 12618 | // above. | ||||
| 12619 | return handler_.newNullLiteral(pos()); | ||||
| 12620 | } | ||||
| 12621 | } | ||||
| 12622 | } | ||||
| 12623 | |||||
| 12624 | template <class ParseHandler, typename Unit> | ||||
| 12625 | typename ParseHandler::NodeResult | ||||
| 12626 | GeneralParser<ParseHandler, Unit>::exprInParens( | ||||
| 12627 | InHandling inHandling, YieldHandling yieldHandling, | ||||
| 12628 | TripledotHandling tripledotHandling, | ||||
| 12629 | PossibleError* possibleError /* = nullptr */) { | ||||
| 12630 | MOZ_ASSERT(anyChars.isCurrentTokenType(TokenKind::LeftParen))do { static_assert( mozilla::detail::AssertionConditionType< decltype(anyChars.isCurrentTokenType(TokenKind::LeftParen))> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(anyChars.isCurrentTokenType(TokenKind::LeftParen)))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("anyChars.isCurrentTokenType(TokenKind::LeftParen)" , "/root/firefox-clang/js/src/frontend/Parser.cpp", 12630); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftParen)" ")"); do { MOZ_CrashSequence(__null, 12630); __attribute__(( nomerge)) ::abort(); } while (false); } } while (false); | ||||
| 12631 | return expr(inHandling, yieldHandling, tripledotHandling, possibleError, | ||||
| 12632 | PredictInvoked); | ||||
| 12633 | } | ||||
| 12634 | |||||
| 12635 | template class PerHandlerParser<FullParseHandler>; | ||||
| 12636 | template class PerHandlerParser<SyntaxParseHandler>; | ||||
| 12637 | template class GeneralParser<FullParseHandler, Utf8Unit>; | ||||
| 12638 | template class GeneralParser<SyntaxParseHandler, Utf8Unit>; | ||||
| 12639 | template class GeneralParser<FullParseHandler, char16_t>; | ||||
| 12640 | template class GeneralParser<SyntaxParseHandler, char16_t>; | ||||
| 12641 | template class Parser<FullParseHandler, Utf8Unit>; | ||||
| 12642 | template class Parser<SyntaxParseHandler, Utf8Unit>; | ||||
| 12643 | template class Parser<FullParseHandler, char16_t>; | ||||
| 12644 | template class Parser<SyntaxParseHandler, char16_t>; | ||||
| 12645 | |||||
| 12646 | } // namespace js::frontend |