Bug Summary

File:root/firefox-clang/js/src/frontend/Parser.cpp
Warning:line 567, column 22
Dereference of null pointer (loaded from variable 'duplicatedParam')

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Parser.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/src/frontend -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/src/frontend -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D WASM_SUPPORTS_HUGE_MEMORY -D JS_CACHEIR_SPEW -D JS_STRUCTURED_SPEW -D JS_HAS_CTYPES -D FFI_BUILDING -D EXPORT_JS_API -D MOZ_HAS_MOZGLUE -D MOZ_SUPPORT_LEAKCHECKING -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/js/src -I /root/firefox-clang/js/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-10-01-230942-3519934-1 -x c++ /root/firefox-clang/js/src/frontend/Parser.cpp
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
66using namespace js;
67
68using mozilla::AssertedCast;
69using mozilla::AsVariant;
70using mozilla::Maybe;
71using mozilla::Nothing;
72using mozilla::PointerRangeSize;
73using mozilla::Some;
74using mozilla::Utf8Unit;
75
76using JS::ReadOnlyCompileOptions;
77using JS::RegExpFlags;
78
79namespace js::frontend {
80
81using DeclaredNamePtr = ParseContext::Scope::DeclaredNamePtr;
82using AddDeclaredNamePtr = ParseContext::Scope::AddDeclaredNamePtr;
83using BindingIter = ParseContext::Scope::BindingIter;
84using UsedNamePtr = UsedNameTracker::UsedNameMap::Ptr;
85
86using ParserBindingNameVector = Vector<ParserBindingName, 6>;
87
88static 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
98static 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
104template <class ParseHandler, typename Unit>
105inline typename GeneralParser<ParseHandler, Unit>::FinalParser*
106GeneralParser<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
114template <class ParseHandler, typename Unit>
115inline const typename GeneralParser<ParseHandler, Unit>::FinalParser*
116GeneralParser<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
124template <class ParseHandler, typename Unit>
125template <typename ConditionT, typename ErrorReportT>
126bool 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#if defined(DEBUG1) || defined(JS_JITSPEW1)
144void ParserBase::dumpAtom(TaggedParserAtomIndex index) const {
145 parserAtoms().dump(index);
146}
147#endif
148
149ParserBase::ParserBase(FrontendContext* fc,
150 const ReadOnlyCompileOptions& options,
151 CompilationState& compilationState)
152 : fc_(fc),
153 alloc_(compilationState.parserAllocScope.alloc()),
154 compilationState_(compilationState),
155 pc_(nullptr),
156 usedNames_(compilationState.usedNames),
157 anyChars(fc, options, this),
158 ss(nullptr),
159#ifdef DEBUG1
160 checkOptionsCalled_(false),
161#endif
162 isUnexpectedEOF_(false),
163 awaitHandling_(AwaitIsName),
164 inParametersOfAsyncFunction_(false) {
165 fc_->nameCollectionPool().addActiveCompilation();
166}
167
168bool ParserBase::checkOptions() {
169#ifdef DEBUG1
170 checkOptionsCalled_ = true;
171#endif
172
173 return anyChars.checkOptions();
174}
175
176ParserBase::~ParserBase() {
177 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", 177); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence
(__null, 177); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
178 fc_->nameCollectionPool().removeActiveCompilation();
179}
180
181JSAtom* ParserBase::liftParserAtomToJSAtom(TaggedParserAtomIndex index) {
182 JSContext* cx = fc_->maybeCurrentJSContext();
183 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"
, 183); AnnotateMozCrashReason("MOZ_ASSERT" "(" "cx" ")"); do
{ MOZ_CrashSequence(__null, 183); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
184 return parserAtoms().toJSAtom(cx, fc_, index,
185 compilationState_.input.atomCache);
186}
187
188template <class ParseHandler>
189PerHandlerParser<ParseHandler>::PerHandlerParser(
190 FrontendContext* fc, const ReadOnlyCompileOptions& options,
191 CompilationState& compilationState, void* internalSyntaxParser)
192 : ParserBase(fc, options, compilationState),
193 handler_(fc, compilationState),
194 internalSyntaxParser_(internalSyntaxParser) {
195 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", 196); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "compilationState.isInitialStencil() == compilationState.input.isInitialStencil()"
")"); do { MOZ_CrashSequence(__null, 196); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
196 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", 196); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "compilationState.isInitialStencil() == compilationState.input.isInitialStencil()"
")"); do { MOZ_CrashSequence(__null, 196); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
197}
198
199template <class ParseHandler, typename Unit>
200GeneralParser<ParseHandler, Unit>::GeneralParser(
201 FrontendContext* fc, const ReadOnlyCompileOptions& options,
202 const Unit* units, size_t length, CompilationState& compilationState,
203 SyntaxParser* syntaxParser)
204 : Base(fc, options, compilationState, syntaxParser),
205 tokenStream(fc, &compilationState.parserAtoms, options, units, length) {}
206
207template <typename Unit>
208void Parser<SyntaxParseHandler, Unit>::setAwaitHandling(
209 AwaitHandling awaitHandling) {
210 this->awaitHandling_ = awaitHandling;
211}
212
213template <typename Unit>
214void Parser<FullParseHandler, Unit>::setAwaitHandling(
215 AwaitHandling awaitHandling) {
216 this->awaitHandling_ = awaitHandling;
217 if (SyntaxParser* syntaxParser = getSyntaxParser()) {
218 syntaxParser->setAwaitHandling(awaitHandling);
219 }
220}
221
222template <class ParseHandler, typename Unit>
223inline void GeneralParser<ParseHandler, Unit>::setAwaitHandling(
224 AwaitHandling awaitHandling) {
225 asFinalParser()->setAwaitHandling(awaitHandling);
226}
227
228template <typename Unit>
229void Parser<SyntaxParseHandler, Unit>::setInParametersOfAsyncFunction(
230 bool inParameters) {
231 this->inParametersOfAsyncFunction_ = inParameters;
232}
233
234template <typename Unit>
235void Parser<FullParseHandler, Unit>::setInParametersOfAsyncFunction(
236 bool inParameters) {
237 this->inParametersOfAsyncFunction_ = inParameters;
238 if (SyntaxParser* syntaxParser = getSyntaxParser()) {
239 syntaxParser->setInParametersOfAsyncFunction(inParameters);
240 }
241}
242
243template <class ParseHandler, typename Unit>
244inline void GeneralParser<ParseHandler, Unit>::setInParametersOfAsyncFunction(
245 bool inParameters) {
246 asFinalParser()->setInParametersOfAsyncFunction(inParameters);
247}
248
249template <class ParseHandler>
250FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox(
251 FunctionNodeType funNode, TaggedParserAtomIndex explicitName,
252 FunctionFlags flags, uint32_t toStringStart, Directives inheritedDirectives,
253 GeneratorKind generatorKind, FunctionAsyncKind asyncKind) {
254 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"
, 254); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funNode" ")"
); do { MOZ_CrashSequence(__null, 254); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
255
256 ScriptIndex index = ScriptIndex(compilationState_.scriptData.length());
257 if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) {
258 ReportAllocationOverflow(fc_);
259 return nullptr;
260 }
261 if (!compilationState_.appendScriptStencilAndData(fc_)) {
262 return nullptr;
263 }
264
265 bool isInitialStencil = compilationState_.isInitialStencil();
266
267 // This source extent will be further filled in during the remainder of parse.
268 SourceExtent extent;
269 extent.toStringStart = toStringStart;
270
271 FunctionBox* funbox = alloc_.new_<FunctionBox>(
272 fc_, extent, compilationState_, inheritedDirectives, generatorKind,
273 asyncKind, isInitialStencil, explicitName, flags, index);
274 if (!funbox) {
275 ReportOutOfMemory(fc_);
276 return nullptr;
277 }
278
279 handler_.setFunctionBox(funNode, funbox);
280
281 return funbox;
282}
283
284template <class ParseHandler>
285FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox(
286 FunctionNodeType funNode, const ScriptStencil& cachedScriptData,
287 const ScriptStencilExtra& cachedScriptExtra) {
288 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"
, 288); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funNode" ")"
); do { MOZ_CrashSequence(__null, 288); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
289
290 ScriptIndex index = ScriptIndex(compilationState_.scriptData.length());
291 if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) {
292 ReportAllocationOverflow(fc_);
293 return nullptr;
294 }
295 if (!compilationState_.appendScriptStencilAndData(fc_)) {
296 return nullptr;
297 }
298
299 FunctionBox* funbox = alloc_.new_<FunctionBox>(
300 fc_, cachedScriptExtra.extent, compilationState_,
301 Directives(/* strict = */ false), cachedScriptExtra.generatorKind(),
302 cachedScriptExtra.asyncKind(), compilationState_.isInitialStencil(),
303 cachedScriptData.functionAtom, cachedScriptData.functionFlags, index);
304 if (!funbox) {
305 ReportOutOfMemory(fc_);
306 return nullptr;
307 }
308
309 handler_.setFunctionBox(funNode, funbox);
310 funbox->initFromScriptStencilExtra(cachedScriptExtra);
311
312 return funbox;
313}
314
315bool ParserBase::setSourceMapInfo() {
316 // If support for source pragmas have been fully disabled, we can skip
317 // processing of all of these values.
318 if (!options().sourcePragmas()) {
319 return true;
320 }
321
322 // Not all clients initialize ss. Can't update info to an object that isn't
323 // there.
324 if (!ss) {
325 return true;
326 }
327
328 if (anyChars.hasDisplayURL()) {
329 if (!ss->setDisplayURL(fc_, anyChars.displayURL())) {
330 return false;
331 }
332 }
333
334 if (anyChars.hasSourceMapURL()) {
335 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", 335); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!ss->hasSourceMapURL()" ")"); do { MOZ_CrashSequence
(__null, 335); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
336 if (!ss->setSourceMapURL(fc_, anyChars.sourceMapURL())) {
337 return false;
338 }
339 }
340
341 /*
342 * Source map URLs passed as a compile option (usually via a HTTP source map
343 * header) override any source map urls passed as comment pragmas.
344 */
345 if (options().sourceMapURL()) {
346 // Warn about the replacement, but use the new one.
347 if (ss->hasSourceMapURL()) {
348 if (!warningNoOffset(JSMSG_ALREADY_HAS_PRAGMA, ss->filename(),
349 "//# sourceMappingURL")) {
350 return false;
351 }
352 }
353
354 if (!ss->setSourceMapURL(fc_, options().sourceMapURL())) {
355 return false;
356 }
357 }
358
359 return true;
360}
361
362/*
363 * Parse a top-level JS script.
364 */
365template <class ParseHandler, typename Unit>
366typename ParseHandler::ListNodeResult
367GeneralParser<ParseHandler, Unit>::parse() {
368 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", 368); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence
(__null, 368); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
369
370 if (!this->fc_->checkCompilationCancellation()) {
371 return errorResult();
372 }
373
374 SourceExtent extent = SourceExtent::makeGlobalExtent(
375 /* len = */ 0, options().lineno,
376 JS::LimitedColumnNumberOneOrigin::fromUnlimited(
377 JS::ColumnNumberOneOrigin(options().column)));
378 Directives directives(options().forceStrictMode());
379 GlobalSharedContext globalsc(this->fc_, ScopeKind::Global, options(),
380 directives, extent);
381 SourceParseContext globalpc(this, &globalsc, /* newDirectives = */ nullptr);
382 if (!globalpc.init()) {
383 return errorResult();
384 }
385
386 ParseContext::VarScope varScope(this);
387 if (!varScope.init(pc_)) {
388 return errorResult();
389 }
390
391 ListNodeType stmtList = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
392
393 TokenKind tt;
394 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
395 return errorResult();
396 }
397 if (tt != TokenKind::Eof) {
398 error(JSMSG_GARBAGE_AFTER_INPUT, "script", TokenKindToDesc(tt));
399 return errorResult();
400 }
401
402 if (!CheckParseTree(this->fc_, alloc_, stmtList)) {
403 return errorResult();
404 }
405
406 return stmtList;
407}
408
409/*
410 * Strict mode forbids introducing new definitions for 'eval', 'arguments',
411 * 'let', 'static', 'yield', or for any strict mode reserved word.
412 */
413bool ParserBase::isValidStrictBinding(TaggedParserAtomIndex name) {
414 TokenKind tt = ReservedWordTokenKind(name);
415 if (tt == TokenKind::Limit) {
416 return name != TaggedParserAtomIndex::WellKnown::eval() &&
417 name != TaggedParserAtomIndex::WellKnown::arguments();
418 }
419 return tt != TokenKind::Let && tt != TokenKind::Static &&
420 tt != TokenKind::Yield && !TokenKindIsStrictReservedWord(tt);
421}
422
423/*
424 * Returns true if all parameter names are valid strict mode binding names and
425 * no duplicate parameter names are present.
426 */
427bool ParserBase::hasValidSimpleStrictParameterNames() {
428 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", 429); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()"
")"); do { MOZ_CrashSequence(__null, 429); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
429 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", 429); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isFunctionBox() && pc_->functionBox()->hasSimpleParameterList()"
")"); do { MOZ_CrashSequence(__null, 429); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
430
431 if (pc_->functionBox()->hasDuplicateParameters) {
432 return false;
433 }
434
435 for (auto name : pc_->positionalFormalParameterNames()) {
436 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"
, 436); AnnotateMozCrashReason("MOZ_ASSERT" "(" "name" ")"); do
{ MOZ_CrashSequence(__null, 436); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
437 if (!isValidStrictBinding(name)) {
438 return false;
439 }
440 }
441 return true;
442}
443
444template <class ParseHandler, typename Unit>
445void GeneralParser<ParseHandler, Unit>::reportMissingClosing(
446 unsigned errorNumber, unsigned noteNumber, uint32_t openedPos) {
447 auto notes = MakeUnique<JSErrorNotes>();
448 if (!notes) {
449 ReportOutOfMemory(this->fc_);
450 return;
451 }
452
453 uint32_t line;
454 JS::LimitedColumnNumberOneOrigin column;
455 tokenStream.computeLineAndColumn(openedPos, &line, &column);
456
457 const size_t MaxWidth = sizeof("4294967295");
458 char columnNumber[MaxWidth];
459 SprintfLiteral(columnNumber, "%" PRIu32"u", column.oneOriginValue());
460 char lineNumber[MaxWidth];
461 SprintfLiteral(lineNumber, "%" PRIu32"u", line);
462
463 if (!notes->addNoteASCII(this->fc_, getFilename().c_str(), 0, line,
464 JS::ColumnNumberOneOrigin(column), GetErrorMessage,
465 nullptr, noteNumber, lineNumber, columnNumber)) {
466 return;
467 }
468
469 errorWithNotes(std::move(notes), errorNumber);
470}
471
472template <class ParseHandler, typename Unit>
473void GeneralParser<ParseHandler, Unit>::reportRedeclarationHelper(
474 TaggedParserAtomIndex& name, DeclarationKind& prevKind, TokenPos& pos,
475 uint32_t& prevPos, const unsigned& errorNumber,
476 const unsigned& noteErrorNumber) {
477 UniqueChars bytes = this->parserAtoms().toPrintableString(name);
478 if (!bytes) {
479 ReportOutOfMemory(this->fc_);
480 return;
481 }
482
483 if (prevPos == DeclaredNameInfo::npos) {
484 errorAt(pos.begin, errorNumber, DeclarationKindString(prevKind),
485 bytes.get());
486 return;
487 }
488
489 auto notes = MakeUnique<JSErrorNotes>();
490 if (!notes) {
491 ReportOutOfMemory(this->fc_);
492 return;
493 }
494
495 uint32_t line;
496 JS::LimitedColumnNumberOneOrigin column;
497 tokenStream.computeLineAndColumn(prevPos, &line, &column);
498
499 const size_t MaxWidth = sizeof("4294967295");
500 char columnNumber[MaxWidth];
501 SprintfLiteral(columnNumber, "%" PRIu32"u", column.oneOriginValue());
502 char lineNumber[MaxWidth];
503 SprintfLiteral(lineNumber, "%" PRIu32"u", line);
504
505 if (!notes->addNoteASCII(this->fc_, getFilename().c_str(), 0, line,
506 JS::ColumnNumberOneOrigin(column), GetErrorMessage,
507 nullptr, noteErrorNumber, lineNumber,
508 columnNumber)) {
509 return;
510 }
511
512 errorWithNotesAt(std::move(notes), pos.begin, errorNumber,
513 DeclarationKindString(prevKind), bytes.get());
514}
515
516template <class ParseHandler, typename Unit>
517void GeneralParser<ParseHandler, Unit>::reportRedeclaration(
518 TaggedParserAtomIndex name, DeclarationKind prevKind, TokenPos pos,
519 uint32_t prevPos) {
520 reportRedeclarationHelper(name, prevKind, pos, prevPos, JSMSG_REDECLARED_VAR,
521 JSMSG_PREV_DECLARATION);
522}
523
524template <class ParseHandler, typename Unit>
525void GeneralParser<ParseHandler, Unit>::reportMismatchedPlacement(
526 TaggedParserAtomIndex name, DeclarationKind prevKind, TokenPos pos,
527 uint32_t prevPos) {
528 reportRedeclarationHelper(name, prevKind, pos, prevPos,
529 JSMSG_MISMATCHED_PLACEMENT, JSMSG_PREV_DECLARATION);
530}
531
532// notePositionalFormalParameter is called for both the arguments of a regular
533// function definition and the arguments specified by the Function
534// constructor.
535//
536// The 'disallowDuplicateParams' bool indicates whether the use of another
537// feature (destructuring or default arguments) disables duplicate arguments.
538// (ECMA-262 requires us to support duplicate parameter names, but, for newer
539// features, we consider the code to have "opted in" to higher standards and
540// forbid duplicates.)
541template <class ParseHandler, typename Unit>
542bool GeneralParser<ParseHandler, Unit>::notePositionalFormalParameter(
543 FunctionNodeType funNode, TaggedParserAtomIndex name, uint32_t beginPos,
544 bool disallowDuplicateParams, bool* duplicatedParam) {
545 if (AddDeclaredNamePtr p =
27
Taking true branch
546 pc_->functionScope().lookupDeclaredNameForAdd(name)) {
547 if (disallowDuplicateParams
27.1
'disallowDuplicateParams' is false
) {
28
Taking false branch
548 error(JSMSG_BAD_DUP_ARGS);
549 return false;
550 }
551
552 // Strict-mode disallows duplicate args. We may not know whether we are
553 // in strict mode or not (since the function body hasn't been parsed).
554 // In such cases, report will queue up the potential error and return
555 // 'true'.
556 if (pc_->sc()->strict()) {
29
Assuming the condition is false
30
Taking false branch
557 UniqueChars bytes = this->parserAtoms().toPrintableString(name);
558 if (!bytes) {
559 ReportOutOfMemory(this->fc_);
560 return false;
561 }
562 if (!strictModeError(JSMSG_DUPLICATE_FORMAL, bytes.get())) {
563 return false;
564 }
565 }
566
567 *duplicatedParam = true;
31
Dereference of null pointer (loaded from variable 'duplicatedParam')
568 } else {
569 DeclarationKind kind = DeclarationKind::PositionalFormalParameter;
570 if (!pc_->functionScope().addDeclaredName(pc_, p, name, kind, beginPos)) {
571 return false;
572 }
573 }
574
575 if (!pc_->positionalFormalParameterNames().append(
576 TrivialTaggedParserAtomIndex::from(name))) {
577 ReportOutOfMemory(this->fc_);
578 return false;
579 }
580
581 NameNodeType paramNode;
582 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)
;
583
584 handler_.addFunctionFormalParameter(funNode, paramNode);
585 return true;
586}
587
588template <class ParseHandler>
589bool PerHandlerParser<ParseHandler>::noteDestructuredPositionalFormalParameter(
590 FunctionNodeType funNode, Node destruct) {
591 // Append an empty name to the positional formals vector to keep track of
592 // argument slots when making FunctionScope::ParserData.
593 if (!pc_->positionalFormalParameterNames().append(
594 TrivialTaggedParserAtomIndex::null())) {
595 ReportOutOfMemory(fc_);
596 return false;
597 }
598
599 handler_.addFunctionFormalParameter(funNode, destruct);
600 return true;
601}
602
603template <class ParseHandler, typename Unit>
604bool GeneralParser<ParseHandler, Unit>::noteDeclaredName(
605 TaggedParserAtomIndex name, DeclarationKind kind, TokenPos pos,
606 ClosedOver isClosedOver) {
607 switch (kind) {
608 case DeclarationKind::Var:
609 case DeclarationKind::BodyLevelFunction: {
610 Maybe<DeclarationKind> redeclaredKind;
611 uint32_t prevPos;
612 if (!pc_->tryDeclareVar(name, this, kind, pos.begin, &redeclaredKind,
613 &prevPos)) {
614 return false;
615 }
616
617 if (redeclaredKind) {
618 reportRedeclaration(name, *redeclaredKind, pos, prevPos);
619 return false;
620 }
621
622 break;
623 }
624
625 case DeclarationKind::ModuleBodyLevelFunction: {
626 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", 626); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->atModuleLevel()" ")"); do { MOZ_CrashSequence
(__null, 626); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
627
628 AddDeclaredNamePtr p = pc_->varScope().lookupDeclaredNameForAdd(name);
629 if (p) {
630 reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos());
631 return false;
632 }
633
634 if (!pc_->varScope().addDeclaredName(pc_, p, name, kind, pos.begin,
635 isClosedOver)) {
636 return false;
637 }
638
639 // Body-level functions in modules are always closed over.
640 pc_->varScope().lookupDeclaredName(name)->value()->setClosedOver();
641
642 break;
643 }
644
645 case DeclarationKind::FormalParameter: {
646 // It is an early error if any non-positional formal parameter name
647 // (e.g., destructuring formal parameter) is duplicated.
648
649 AddDeclaredNamePtr p =
650 pc_->functionScope().lookupDeclaredNameForAdd(name);
651 if (p) {
652 error(JSMSG_BAD_DUP_ARGS);
653 return false;
654 }
655
656 if (!pc_->functionScope().addDeclaredName(pc_, p, name, kind, pos.begin,
657 isClosedOver)) {
658 return false;
659 }
660
661 break;
662 }
663
664 case DeclarationKind::LexicalFunction:
665 case DeclarationKind::PrivateName:
666 case DeclarationKind::Synthetic:
667 case DeclarationKind::PrivateMethod: {
668 ParseContext::Scope* scope = pc_->innermostScope();
669 AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name);
670 if (p) {
671 reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos());
672 return false;
673 }
674
675 if (!scope->addDeclaredName(pc_, p, name, kind, pos.begin,
676 isClosedOver)) {
677 return false;
678 }
679
680 break;
681 }
682
683 case DeclarationKind::SloppyLexicalFunction: {
684 // Functions in block have complex allowances in sloppy mode for being
685 // labelled that other lexical declarations do not have. Those checks
686 // are done in functionStmt.
687
688 ParseContext::Scope* scope = pc_->innermostScope();
689 if (AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name)) {
690 // It is usually an early error if there is another declaration
691 // with the same name in the same scope.
692 //
693 // Sloppy lexical functions may redeclare other sloppy lexical
694 // functions for web compatibility reasons.
695 if (p->value()->kind() != DeclarationKind::SloppyLexicalFunction) {
696 reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos());
697 return false;
698 }
699 } else {
700 if (!scope->addDeclaredName(pc_, p, name, kind, pos.begin,
701 isClosedOver)) {
702 return false;
703 }
704 }
705
706 break;
707 }
708
709 case DeclarationKind::Let:
710 case DeclarationKind::Const:
711 case DeclarationKind::Using:
712 case DeclarationKind::AwaitUsing:
713 case DeclarationKind::Class:
714 // The BoundNames of LexicalDeclaration and ForDeclaration must not
715 // contain 'let'. (CatchParameter is the only lexical binding form
716 // without this restriction.)
717 if (name == TaggedParserAtomIndex::WellKnown::let()) {
718 errorAt(pos.begin, JSMSG_LEXICAL_DECL_DEFINES_LET);
719 return false;
720 }
721
722 // For body-level lexically declared names in a function, it is an
723 // early error if there is a formal parameter of the same name. This
724 // needs a special check if there is an extra var scope due to
725 // parameter expressions.
726 if (pc_->isFunctionExtraBodyVarScopeInnermost()) {
727 DeclaredNamePtr p = pc_->functionScope().lookupDeclaredName(name);
728 if (p && DeclarationKindIsParameter(p->value()->kind())) {
729 reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos());
730 return false;
731 }
732 }
733
734 [[fallthrough]];
735
736 case DeclarationKind::Import:
737 // Module code is always strict, so 'let' is always a keyword and never a
738 // name.
739 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", 739); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "name != TaggedParserAtomIndex::WellKnown::let()"
")"); do { MOZ_CrashSequence(__null, 739); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
740 [[fallthrough]];
741
742 case DeclarationKind::SimpleCatchParameter:
743 case DeclarationKind::CatchParameter: {
744 ParseContext::Scope* scope = pc_->innermostScope();
745
746 // It is an early error if there is another declaration with the same
747 // name in the same scope.
748 AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name);
749 if (p) {
750 reportRedeclaration(name, p->value()->kind(), pos, p->value()->pos());
751 return false;
752 }
753
754 if (!scope->addDeclaredName(pc_, p, name, kind, pos.begin,
755 isClosedOver)) {
756 return false;
757 }
758
759 break;
760 }
761
762 case DeclarationKind::CoverArrowParameter:
763 // CoverArrowParameter is only used as a placeholder declaration kind.
764 break;
765
766 case DeclarationKind::PositionalFormalParameter:
767 MOZ_CRASH(do { do { } while (false); MOZ_ReportCrash("" "Positional formal parameter names should use "
"notePositionalFormalParameter", "/root/firefox-clang/js/src/frontend/Parser.cpp"
, 769); AnnotateMozCrashReason("MOZ_CRASH(" "Positional formal parameter names should use "
"notePositionalFormalParameter" ")"); do { MOZ_CrashSequence
(__null, 769); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
768 "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"
, 769); AnnotateMozCrashReason("MOZ_CRASH(" "Positional formal parameter names should use "
"notePositionalFormalParameter" ")"); do { MOZ_CrashSequence
(__null, 769); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
769 "notePositionalFormalParameter")do { do { } while (false); MOZ_ReportCrash("" "Positional formal parameter names should use "
"notePositionalFormalParameter", "/root/firefox-clang/js/src/frontend/Parser.cpp"
, 769); AnnotateMozCrashReason("MOZ_CRASH(" "Positional formal parameter names should use "
"notePositionalFormalParameter" ")"); do { MOZ_CrashSequence
(__null, 769); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
;
770 break;
771
772 case DeclarationKind::VarForAnnexBLexicalFunction:
773 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", 776); AnnotateMozCrashReason
("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and "
"propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence
(__null, 776); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
774 "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", 776); AnnotateMozCrashReason
("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and "
"propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence
(__null, 776); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
775 "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", 776); AnnotateMozCrashReason
("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and "
"propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence
(__null, 776); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
776 "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", 776); AnnotateMozCrashReason
("MOZ_CRASH(" "Synthesized Annex B vars should go through " "addPossibleAnnexBFunctionBox, and "
"propagateAndMarkAnnexBFunctionBoxes" ")"); do { MOZ_CrashSequence
(__null, 776); __attribute__((nomerge)) ::abort(); } while (false
); } while (false)
;
777 break;
778 }
779
780 return true;
781}
782
783template <class ParseHandler, typename Unit>
784bool GeneralParser<ParseHandler, Unit>::noteDeclaredPrivateName(
785 Node nameNode, TaggedParserAtomIndex name, PropertyType propType,
786 FieldPlacement placement, TokenPos pos) {
787 ParseContext::Scope* scope = pc_->innermostScope();
788 AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name);
789
790 DeclarationKind declKind = DeclarationKind::PrivateName;
791
792 // Our strategy for enabling debugger functionality is to mark names as closed
793 // over, even if they don't necessarily need to be, to ensure that they are
794 // included in the environment object. This allows us to easily look them up
795 // by name when needed, even if there is no corresponding property on an
796 // object, as is the case with getter, setters and private methods.
797 ClosedOver closedOver = ClosedOver::Yes;
798 PrivateNameKind kind;
799 switch (propType) {
800 case PropertyType::Field:
801 kind = PrivateNameKind::Field;
802 closedOver = ClosedOver::No;
803 break;
804 case PropertyType::FieldWithAccessor:
805 // In this case, we create a new private field for the underlying storage,
806 // and use the current name for the getter and setter.
807 kind = PrivateNameKind::GetterSetter;
808 break;
809 case PropertyType::Method:
810 case PropertyType::GeneratorMethod:
811 case PropertyType::AsyncMethod:
812 case PropertyType::AsyncGeneratorMethod:
813 if (placement == FieldPlacement::Instance) {
814 // Optimized private method. Non-optimized paths still get
815 // DeclarationKind::Synthetic.
816 declKind = DeclarationKind::PrivateMethod;
817 }
818 kind = PrivateNameKind::Method;
819 break;
820 case PropertyType::Getter:
821 kind = PrivateNameKind::Getter;
822 break;
823 case PropertyType::Setter:
824 kind = PrivateNameKind::Setter;
825 break;
826 default:
827 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", 827); AnnotateMozCrashReason
("MOZ_CRASH(" "Invalid Property Type for noteDeclarePrivateName"
")"); do { MOZ_CrashSequence(__null, 827); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
828 }
829
830 if (p) {
831 PrivateNameKind prevKind = p->value()->privateNameKind();
832 if ((prevKind == PrivateNameKind::Getter &&
833 kind == PrivateNameKind::Setter) ||
834 (prevKind == PrivateNameKind::Setter &&
835 kind == PrivateNameKind::Getter)) {
836 // Private methods demands that
837 //
838 // class A {
839 // static set #x(_) {}
840 // get #x() { }
841 // }
842 //
843 // Report a SyntaxError.
844 if (placement == p->value()->placement()) {
845 p->value()->setPrivateNameKind(PrivateNameKind::GetterSetter);
846 handler_.setPrivateNameKind(nameNode, PrivateNameKind::GetterSetter);
847 return true;
848 }
849 }
850
851 reportMismatchedPlacement(name, p->value()->kind(), pos, p->value()->pos());
852 return false;
853 }
854
855 if (!scope->addDeclaredName(pc_, p, name, declKind, pos.begin, closedOver)) {
856 return false;
857 }
858
859 DeclaredNamePtr declared = scope->lookupDeclaredName(name);
860 declared->value()->setPrivateNameKind(kind);
861 declared->value()->setFieldPlacement(placement);
862 handler_.setPrivateNameKind(nameNode, kind);
863
864 return true;
865}
866
867bool ParserBase::noteUsedNameInternal(TaggedParserAtomIndex name,
868 NameVisibility visibility,
869 mozilla::Maybe<TokenPos> tokenPosition) {
870 // Global bindings are properties and not actual bindings; we don't need
871 // to know if they are closed over. So no need to track used name at the
872 // global scope. It is not incorrect to track them, this is an
873 // optimization.
874 //
875 // Exceptions:
876 // (a) Track private name references, as the used names tracker is used to
877 // provide early errors for undeclared private name references
878 // (b) If the script has extra bindings, track all references to detect
879 // references to extra bindings
880 ParseContext::Scope* scope = pc_->innermostScope();
881 if (pc_->sc()->isGlobalContext() && scope == &pc_->varScope() &&
882 visibility == NameVisibility::Public &&
883 !this->compilationState_.input.hasExtraBindings()) {
884 return true;
885 }
886
887 return usedNames_.noteUse(fc_, name, visibility, pc_->scriptId(), scope->id(),
888 tokenPosition);
889}
890
891template <class ParseHandler>
892bool PerHandlerParser<ParseHandler>::
893 propagateFreeNamesAndMarkClosedOverBindings(ParseContext::Scope& scope) {
894 // Now that we have all the declared names in the scope, check which
895 // functions should exhibit Annex B semantics.
896 if (!scope.propagateAndMarkAnnexBFunctionBoxes(pc_, this)) {
897 return false;
898 }
899
900 if (handler_.reuseClosedOverBindings()) {
901 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", 901); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isOutermostOfCurrentCompile()" ")"
); do { MOZ_CrashSequence(__null, 901); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
902
903 // Closed over bindings for all scopes are stored in a contiguous array, in
904 // the same order as the order in which scopes are visited, and seprated by
905 // TaggedParserAtomIndex::null().
906 uint32_t slotCount = scope.declaredCount();
907 while (auto parserAtom = handler_.nextLazyClosedOverBinding()) {
908 scope.lookupDeclaredName(parserAtom)->value()->setClosedOver();
909 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", 909); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "slotCount > 0" ")"); do { MOZ_CrashSequence
(__null, 909); __attribute__((nomerge)) ::abort(); } while (false
); } } while (false)
;
910 slotCount--;
911 }
912
913 if (pc_->isGeneratorOrAsync()) {
914 scope.setOwnStackSlotCount(slotCount);
915 }
916 return true;
917 }
918
919 constexpr bool isSyntaxParser =
920 std::is_same_v<ParseHandler, SyntaxParseHandler>;
921 uint32_t scriptId = pc_->scriptId();
922 uint32_t scopeId = scope.id();
923
924 uint32_t slotCount = 0;
925 for (BindingIter bi = scope.bindings(pc_); bi; bi++) {
926 bool closedOver = false;
927 if (UsedNamePtr p = usedNames_.lookup(bi.name())) {
928 p->value().noteBoundInScope(scriptId, scopeId, &closedOver);
929 if (closedOver) {
930 bi.setClosedOver();
931
932 if constexpr (isSyntaxParser) {
933 if (!pc_->closedOverBindingsForLazy().append(
934 TrivialTaggedParserAtomIndex::from(bi.name()))) {
935 ReportOutOfMemory(fc_);
936 return false;
937 }
938 }
939 }
940 }
941
942 if constexpr (!isSyntaxParser) {
943 if (!closedOver) {
944 slotCount++;
945 }
946 }
947 }
948 if constexpr (!isSyntaxParser) {
949 if (pc_->isGeneratorOrAsync()) {
950 scope.setOwnStackSlotCount(slotCount);
951 }
952 }
953
954 // Append a nullptr to denote end-of-scope.
955 if constexpr (isSyntaxParser) {
956 if (!pc_->closedOverBindingsForLazy().append(
957 TrivialTaggedParserAtomIndex::null())) {
958 ReportOutOfMemory(fc_);
959 return false;
960 }
961 }
962
963 return true;
964}
965
966template <typename Unit>
967bool Parser<FullParseHandler, Unit>::checkStatementsEOF() {
968 // This is designed to be paired with parsing a statement list at the top
969 // level.
970 //
971 // The statementList() call breaks on TokenKind::RightCurly, so make sure
972 // we've reached EOF here.
973 TokenKind tt;
974 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
975 return false;
976 }
977 if (tt != TokenKind::Eof) {
978 error(JSMSG_UNEXPECTED_TOKEN, "expression", TokenKindToDesc(tt));
979 return false;
980 }
981 return true;
982}
983
984template <typename ScopeT>
985typename ScopeT::ParserData* NewEmptyBindingData(FrontendContext* fc,
986 LifoAlloc& alloc,
987 uint32_t numBindings) {
988 using Data = typename ScopeT::ParserData;
989 size_t allocSize = SizeOfScopeData<Data>(numBindings);
990 auto* bindings = alloc.newWithSize<Data>(allocSize, numBindings);
991 if (!bindings) {
992 ReportOutOfMemory(fc);
993 }
994 return bindings;
995}
996
997GlobalScope::ParserData* NewEmptyGlobalScopeData(FrontendContext* fc,
998 LifoAlloc& alloc,
999 uint32_t numBindings) {
1000 return NewEmptyBindingData<GlobalScope>(fc, alloc, numBindings);
1001}
1002
1003LexicalScope::ParserData* NewEmptyLexicalScopeData(FrontendContext* fc,
1004 LifoAlloc& alloc,
1005 uint32_t numBindings) {
1006 return NewEmptyBindingData<LexicalScope>(fc, alloc, numBindings);
1007}
1008
1009FunctionScope::ParserData* NewEmptyFunctionScopeData(FrontendContext* fc,
1010 LifoAlloc& alloc,
1011 uint32_t numBindings) {
1012 return NewEmptyBindingData<FunctionScope>(fc, alloc, numBindings);
1013}
1014
1015namespace detail {
1016
1017template <class SlotInfo>
1018static MOZ_ALWAYS_INLINEinline ParserBindingName* InitializeIndexedBindings(
1019 SlotInfo& slotInfo, ParserBindingName* start, ParserBindingName* cursor) {
1020 return cursor;
1021}
1022
1023template <class SlotInfo, typename UnsignedInteger, typename... Step>
1024static MOZ_ALWAYS_INLINEinline ParserBindingName* InitializeIndexedBindings(
1025 SlotInfo& slotInfo, ParserBindingName* start, ParserBindingName* cursor,
1026 UnsignedInteger SlotInfo::* field, const ParserBindingNameVector& bindings,
1027 Step&&... step) {
1028 slotInfo.*field =
1029 AssertedCast<UnsignedInteger>(PointerRangeSize(start, cursor));
1030
1031 ParserBindingName* newCursor =
1032 std::uninitialized_copy(bindings.begin(), bindings.end(), cursor);
1033
1034 return InitializeIndexedBindings(slotInfo, start, newCursor,
1035 std::forward<Step>(step)...);
1036}
1037
1038} // namespace detail
1039
1040// Initialize the trailing name bindings of |data|, then set |data->length| to
1041// the count of bindings added (which must equal |count|).
1042//
1043// First, |firstBindings| are added to the trailing names. Then any
1044// "steps" present are performed first to last. Each step is 1) a pointer to a
1045// member of |data| to be set to the current number of bindings added, and 2) a
1046// vector of |ParserBindingName|s to then copy into |data->trailingNames|.
1047// (Thus each |data| member field indicates where the corresponding vector's
1048// names start.)
1049template <class Data, typename... Step>
1050static MOZ_ALWAYS_INLINEinline void InitializeBindingData(
1051 Data* data, uint32_t count, const ParserBindingNameVector& firstBindings,
1052 Step&&... step) {
1053 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"
, 1053); AnnotateMozCrashReason("MOZ_ASSERT" "(" "data->length == 0"
") (" "data shouldn't be filled yet" ")"); do { MOZ_CrashSequence
(__null, 1053); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1054
1055 ParserBindingName* start = GetScopeDataTrailingNamesPointer(data);
1056 ParserBindingName* cursor = std::uninitialized_copy(
1057 firstBindings.begin(), firstBindings.end(), start);
1058
1059#ifdef DEBUG1
1060 ParserBindingName* end =
1061#endif
1062 detail::InitializeIndexedBindings(data->slotInfo, start, cursor,
1063 std::forward<Step>(step)...);
1064
1065 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", 1065); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "PointerRangeSize(start, end) == count" ")"
); do { MOZ_CrashSequence(__null, 1065); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1066 data->length = count;
1067}
1068
1069static Maybe<GlobalScope::ParserData*> NewGlobalScopeData(
1070 FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc,
1071 ParseContext* pc) {
1072 ParserBindingNameVector vars(fc);
1073 ParserBindingNameVector lets(fc);
1074 ParserBindingNameVector consts(fc);
1075
1076 bool allBindingsClosedOver = pc->sc()->allBindingsClosedOver();
1077 for (BindingIter bi = scope.bindings(pc); bi; bi++) {
1078 bool closedOver = allBindingsClosedOver || bi.closedOver();
1079
1080 switch (bi.kind()) {
1081 case BindingKind::Var: {
1082 bool isTopLevelFunction =
1083 bi.declarationKind() == DeclarationKind::BodyLevelFunction;
1084
1085 ParserBindingName binding(bi.name(), closedOver, isTopLevelFunction);
1086 if (!vars.append(binding)) {
1087 return Nothing();
1088 }
1089 break;
1090 }
1091 case BindingKind::Let: {
1092 ParserBindingName binding(bi.name(), closedOver);
1093 if (!lets.append(binding)) {
1094 return Nothing();
1095 }
1096 break;
1097 }
1098 case BindingKind::Const: {
1099 ParserBindingName binding(bi.name(), closedOver);
1100 if (!consts.append(binding)) {
1101 return Nothing();
1102 }
1103 break;
1104 }
1105 default:
1106 MOZ_CRASH("Bad global scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "Bad global scope BindingKind"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 1106); AnnotateMozCrashReason
("MOZ_CRASH(" "Bad global scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1106); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
1107 }
1108 }
1109
1110 GlobalScope::ParserData* bindings = nullptr;
1111 uint32_t numBindings = vars.length() + lets.length() + consts.length();
1112
1113 if (numBindings > 0) {
1114 bindings = NewEmptyBindingData<GlobalScope>(fc, alloc, numBindings);
1115 if (!bindings) {
1116 return Nothing();
1117 }
1118
1119 // The ordering here is important. See comments in GlobalScope.
1120 InitializeBindingData(bindings, numBindings, vars,
1121 &ParserGlobalScopeSlotInfo::letStart, lets,
1122 &ParserGlobalScopeSlotInfo::constStart, consts);
1123 }
1124
1125 return Some(bindings);
1126}
1127
1128Maybe<GlobalScope::ParserData*> ParserBase::newGlobalScopeData(
1129 ParseContext::Scope& scope) {
1130 return NewGlobalScopeData(fc_, scope, stencilAlloc(), pc_);
1131}
1132
1133static Maybe<ModuleScope::ParserData*> NewModuleScopeData(
1134 FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc,
1135 ParseContext* pc) {
1136 ParserBindingNameVector imports(fc);
1137 ParserBindingNameVector vars(fc);
1138 ParserBindingNameVector lets(fc);
1139 ParserBindingNameVector consts(fc);
1140 ParserBindingNameVector usings(fc);
1141
1142 bool allBindingsClosedOver =
1143 pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize();
1144
1145 for (BindingIter bi = scope.bindings(pc); bi; bi++) {
1146 // Imports are indirect bindings and must not be given known slots.
1147 ParserBindingName binding(bi.name(),
1148 (allBindingsClosedOver || bi.closedOver()) &&
1149 bi.kind() != BindingKind::Import);
1150 switch (bi.kind()) {
1151 case BindingKind::Import:
1152 if (!imports.append(binding)) {
1153 return Nothing();
1154 }
1155 break;
1156 case BindingKind::Var:
1157 if (!vars.append(binding)) {
1158 return Nothing();
1159 }
1160 break;
1161 case BindingKind::Let:
1162 if (!lets.append(binding)) {
1163 return Nothing();
1164 }
1165 break;
1166 case BindingKind::Const:
1167 if (!consts.append(binding)) {
1168 return Nothing();
1169 }
1170 break;
1171 case BindingKind::Using:
1172 if (!usings.append(binding)) {
1173 return Nothing();
1174 }
1175 break;
1176 default:
1177 MOZ_CRASH("Bad module scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "Bad module scope BindingKind"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 1177); AnnotateMozCrashReason
("MOZ_CRASH(" "Bad module scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1177); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
1178 }
1179 }
1180
1181 ModuleScope::ParserData* bindings = nullptr;
1182 uint32_t numBindings = imports.length() + vars.length() + lets.length() +
1183 consts.length() + usings.length();
1184
1185 if (numBindings > 0) {
1186 bindings = NewEmptyBindingData<ModuleScope>(fc, alloc, numBindings);
1187 if (!bindings) {
1188 return Nothing();
1189 }
1190
1191 // The ordering here is important. See comments in ModuleScope.
1192 InitializeBindingData(bindings, numBindings, imports,
1193 &ParserModuleScopeSlotInfo::varStart, vars,
1194 &ParserModuleScopeSlotInfo::letStart, lets,
1195 &ParserModuleScopeSlotInfo::constStart, consts,
1196 &ParserModuleScopeSlotInfo::usingStart, usings);
1197 }
1198
1199 return Some(bindings);
1200}
1201
1202Maybe<ModuleScope::ParserData*> ParserBase::newModuleScopeData(
1203 ParseContext::Scope& scope) {
1204 return NewModuleScopeData(fc_, scope, stencilAlloc(), pc_);
1205}
1206
1207static Maybe<EvalScope::ParserData*> NewEvalScopeData(
1208 FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc,
1209 ParseContext* pc) {
1210 ParserBindingNameVector vars(fc);
1211
1212 // Treat all bindings as closed over in non-strict eval.
1213 bool allBindingsClosedOver =
1214 !pc->sc()->strict() || pc->sc()->allBindingsClosedOver();
1215 for (BindingIter bi = scope.bindings(pc); bi; bi++) {
1216 // Eval scopes only contain 'var' bindings.
1217 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"
, 1217); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Var"
")"); do { MOZ_CrashSequence(__null, 1217); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1218 bool isTopLevelFunction =
1219 bi.declarationKind() == DeclarationKind::BodyLevelFunction;
1220 bool closedOver = allBindingsClosedOver || bi.closedOver();
1221
1222 ParserBindingName binding(bi.name(), closedOver, isTopLevelFunction);
1223 if (!vars.append(binding)) {
1224 return Nothing();
1225 }
1226 }
1227
1228 EvalScope::ParserData* bindings = nullptr;
1229 uint32_t numBindings = vars.length();
1230
1231 if (numBindings > 0) {
1232 bindings = NewEmptyBindingData<EvalScope>(fc, alloc, numBindings);
1233 if (!bindings) {
1234 return Nothing();
1235 }
1236
1237 InitializeBindingData(bindings, numBindings, vars);
1238 }
1239
1240 return Some(bindings);
1241}
1242
1243Maybe<EvalScope::ParserData*> ParserBase::newEvalScopeData(
1244 ParseContext::Scope& scope) {
1245 return NewEvalScopeData(fc_, scope, stencilAlloc(), pc_);
1246}
1247
1248Maybe<FunctionScope::ParserData*> ParserBase::newFunctionScopeData(
1249 ParseContext::Scope& scope, bool hasParameterExprs) {
1250 ParserBindingNameVector positionalFormals(fc_);
1251 ParserBindingNameVector formals(fc_);
1252 ParserBindingNameVector vars(fc_);
1253
1254 bool allBindingsClosedOver =
1255 pc_->sc()->allBindingsClosedOver() || scope.tooBigToOptimize();
1256 bool argumentBindingsClosedOver =
1257 allBindingsClosedOver || pc_->isGeneratorOrAsync();
1258 bool hasDuplicateParams = pc_->functionBox()->hasDuplicateParameters;
1259
1260 // Positional parameter names must be added in order of appearance as they are
1261 // referenced using argument slots.
1262 for (size_t i = 0; i < pc_->positionalFormalParameterNames().length(); i++) {
1263 TaggedParserAtomIndex name = pc_->positionalFormalParameterNames()[i];
1264
1265 ParserBindingName bindName;
1266 if (name) {
1267 DeclaredNamePtr p = scope.lookupDeclaredName(name);
1268
1269 // Do not consider any positional formal parameters closed over if
1270 // there are parameter defaults. It is the binding in the defaults
1271 // scope that is closed over instead.
1272 bool closedOver =
1273 argumentBindingsClosedOver || (p && p->value()->closedOver());
1274
1275 // If the parameter name has duplicates, only the final parameter
1276 // name should be on the environment, as otherwise the environment
1277 // object would have multiple, same-named properties.
1278 if (hasDuplicateParams) {
1279 for (size_t j = pc_->positionalFormalParameterNames().length() - 1;
1280 j > i; j--) {
1281 if (TaggedParserAtomIndex(pc_->positionalFormalParameterNames()[j]) ==
1282 name) {
1283 closedOver = false;
1284 break;
1285 }
1286 }
1287 }
1288
1289 bindName = ParserBindingName(name, closedOver);
1290 }
1291
1292 if (!positionalFormals.append(bindName)) {
1293 return Nothing();
1294 }
1295 }
1296
1297 for (BindingIter bi = scope.bindings(pc_); bi; bi++) {
1298 ParserBindingName binding(bi.name(),
1299 allBindingsClosedOver || bi.closedOver());
1300 switch (bi.kind()) {
1301 case BindingKind::FormalParameter:
1302 // Positional parameter names are already handled above.
1303 if (bi.declarationKind() == DeclarationKind::FormalParameter) {
1304 if (!formals.append(binding)) {
1305 return Nothing();
1306 }
1307 }
1308 break;
1309 case BindingKind::Var:
1310 // The only vars in the function scope when there are parameter
1311 // exprs, which induces a separate var environment, should be the
1312 // special bindings.
1313 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"
, 1314); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FunctionScope::isSpecialName(bi.name())"
")"); do { MOZ_CrashSequence(__null, 1314); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1314 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"
, 1314); AnnotateMozCrashReason("MOZ_ASSERT" "(" "FunctionScope::isSpecialName(bi.name())"
")"); do { MOZ_CrashSequence(__null, 1314); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
1315 if (!vars.append(binding)) {
1316 return Nothing();
1317 }
1318 break;
1319 case BindingKind::Let:
1320 case BindingKind::Const:
1321 case BindingKind::Using:
1322 break;
1323 default:
1324 MOZ_CRASH("bad function scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "bad function scope BindingKind"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 1324); AnnotateMozCrashReason
("MOZ_CRASH(" "bad function scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1324); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
1325 break;
1326 }
1327 }
1328
1329 // This should already be checked by GeneralParser::functionArguments.
1330 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", 1330); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "positionalFormals.length() <= (65535)" ")"
); do { MOZ_CrashSequence(__null, 1330); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1331
1332 if (positionalFormals.length() + formals.length() > UINT16_MAX(65535)) {
1333 error(JSMSG_TOO_MANY_FUN_ARGS);
1334 return Nothing();
1335 }
1336
1337 FunctionScope::ParserData* bindings = nullptr;
1338 uint32_t numBindings =
1339 positionalFormals.length() + formals.length() + vars.length();
1340
1341 if (numBindings > 0) {
1342 bindings =
1343 NewEmptyBindingData<FunctionScope>(fc_, stencilAlloc(), numBindings);
1344 if (!bindings) {
1345 return Nothing();
1346 }
1347
1348 // The ordering here is important. See comments in FunctionScope.
1349 InitializeBindingData(
1350 bindings, numBindings, positionalFormals,
1351 &ParserFunctionScopeSlotInfo::nonPositionalFormalStart, formals,
1352 &ParserFunctionScopeSlotInfo::varStart, vars);
1353 }
1354
1355 return Some(bindings);
1356}
1357
1358// Compute if `newFunctionScopeData` would return any binding list with any
1359// entry marked as closed-over. This is done without the need to allocate the
1360// binding list. If true, an EnvironmentObject will be needed at runtime.
1361bool FunctionScopeHasClosedOverBindings(ParseContext* pc) {
1362 bool allBindingsClosedOver = pc->sc()->allBindingsClosedOver() ||
1363 pc->functionScope().tooBigToOptimize();
1364
1365 for (BindingIter bi = pc->functionScope().bindings(pc); bi; bi++) {
1366 switch (bi.kind()) {
1367 case BindingKind::FormalParameter:
1368 case BindingKind::Var:
1369 if (allBindingsClosedOver || bi.closedOver()) {
1370 return true;
1371 }
1372 break;
1373
1374 default:
1375 break;
1376 }
1377 }
1378
1379 return false;
1380}
1381
1382VarScope::ParserData* NewEmptyVarScopeData(FrontendContext* fc,
1383 LifoAlloc& alloc,
1384 uint32_t numBindings) {
1385 return NewEmptyBindingData<VarScope>(fc, alloc, numBindings);
1386}
1387
1388static Maybe<VarScope::ParserData*> NewVarScopeData(FrontendContext* fc,
1389 ParseContext::Scope& scope,
1390 LifoAlloc& alloc,
1391 ParseContext* pc) {
1392 ParserBindingNameVector vars(fc);
1393
1394 bool allBindingsClosedOver =
1395 pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize();
1396
1397 for (BindingIter bi = scope.bindings(pc); bi; bi++) {
1398 if (bi.kind() == BindingKind::Var) {
1399 ParserBindingName binding(bi.name(),
1400 allBindingsClosedOver || bi.closedOver());
1401 if (!vars.append(binding)) {
1402 return Nothing();
1403 }
1404 } else {
1405 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"
, 1408); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using"
") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1408); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
1406 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"
, 1408); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using"
") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1408); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
1407 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"
, 1408); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using"
") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1408); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
1408 "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"
, 1408); AnnotateMozCrashReason("MOZ_ASSERT" "(" "bi.kind() == BindingKind::Let || bi.kind() == BindingKind::Const || bi.kind() == BindingKind::Using"
") (" "bad var scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1408); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1409 }
1410 }
1411
1412 VarScope::ParserData* bindings = nullptr;
1413 uint32_t numBindings = vars.length();
1414
1415 if (numBindings > 0) {
1416 bindings = NewEmptyBindingData<VarScope>(fc, alloc, numBindings);
1417 if (!bindings) {
1418 return Nothing();
1419 }
1420
1421 InitializeBindingData(bindings, numBindings, vars);
1422 }
1423
1424 return Some(bindings);
1425}
1426
1427// Compute if `NewVarScopeData` would return any binding list. This is done
1428// without allocate the binding list.
1429static bool VarScopeHasBindings(ParseContext* pc) {
1430 for (BindingIter bi = pc->varScope().bindings(pc); bi; bi++) {
1431 if (bi.kind() == BindingKind::Var) {
1432 return true;
1433 }
1434 }
1435
1436 return false;
1437}
1438
1439Maybe<VarScope::ParserData*> ParserBase::newVarScopeData(
1440 ParseContext::Scope& scope) {
1441 return NewVarScopeData(fc_, scope, stencilAlloc(), pc_);
1442}
1443
1444static Maybe<LexicalScope::ParserData*> NewLexicalScopeData(
1445 FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc,
1446 ParseContext* pc) {
1447 ParserBindingNameVector lets(fc);
1448 ParserBindingNameVector consts(fc);
1449 ParserBindingNameVector usings(fc);
1450
1451 bool allBindingsClosedOver =
1452 pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize();
1453
1454 for (BindingIter bi = scope.bindings(pc); bi; bi++) {
1455 ParserBindingName binding(bi.name(),
1456 allBindingsClosedOver || bi.closedOver());
1457 switch (bi.kind()) {
1458 case BindingKind::Let:
1459 if (!lets.append(binding)) {
1460 return Nothing();
1461 }
1462 break;
1463 case BindingKind::Const:
1464 if (!consts.append(binding)) {
1465 return Nothing();
1466 }
1467 break;
1468 case BindingKind::Using:
1469 if (!usings.append(binding)) {
1470 return Nothing();
1471 }
1472 break;
1473 case BindingKind::Var:
1474 case BindingKind::FormalParameter:
1475 break;
1476 default:
1477 MOZ_CRASH("Bad lexical scope BindingKind")do { do { } while (false); MOZ_ReportCrash("" "Bad lexical scope BindingKind"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 1477); AnnotateMozCrashReason
("MOZ_CRASH(" "Bad lexical scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1477); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
1478 break;
1479 }
1480 }
1481
1482 LexicalScope::ParserData* bindings = nullptr;
1483 uint32_t numBindings = lets.length() + consts.length() + usings.length();
1484
1485 if (numBindings > 0) {
1486 bindings = NewEmptyBindingData<LexicalScope>(fc, alloc, numBindings);
1487 if (!bindings) {
1488 return Nothing();
1489 }
1490
1491 // The ordering here is important. See comments in LexicalScope.
1492 InitializeBindingData(bindings, numBindings, lets,
1493 &ParserLexicalScopeSlotInfo::constStart, consts,
1494 &ParserLexicalScopeSlotInfo::usingStart, usings);
1495 }
1496
1497 return Some(bindings);
1498}
1499
1500// Compute if `NewLexicalScopeData` would return any binding list with any entry
1501// marked as closed-over. This is done without the need to allocate the binding
1502// list. If true, an EnvironmentObject will be needed at runtime.
1503bool LexicalScopeHasClosedOverBindings(ParseContext* pc,
1504 ParseContext::Scope& scope) {
1505 bool allBindingsClosedOver =
1506 pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize();
1507
1508 for (BindingIter bi = scope.bindings(pc); bi; bi++) {
1509 switch (bi.kind()) {
1510 case BindingKind::Let:
1511 case BindingKind::Const:
1512 case BindingKind::Using:
1513 if (allBindingsClosedOver || bi.closedOver()) {
1514 return true;
1515 }
1516 break;
1517
1518 default:
1519 break;
1520 }
1521 }
1522
1523 return false;
1524}
1525
1526Maybe<LexicalScope::ParserData*> ParserBase::newLexicalScopeData(
1527 ParseContext::Scope& scope) {
1528 return NewLexicalScopeData(fc_, scope, stencilAlloc(), pc_);
1529}
1530
1531static Maybe<ClassBodyScope::ParserData*> NewClassBodyScopeData(
1532 FrontendContext* fc, ParseContext::Scope& scope, LifoAlloc& alloc,
1533 ParseContext* pc) {
1534 ParserBindingNameVector privateBrand(fc);
1535 ParserBindingNameVector synthetics(fc);
1536 ParserBindingNameVector privateMethods(fc);
1537
1538 bool allBindingsClosedOver =
1539 pc->sc()->allBindingsClosedOver() || scope.tooBigToOptimize();
1540
1541 for (BindingIter bi = scope.bindings(pc); bi; bi++) {
1542 ParserBindingName binding(bi.name(),
1543 allBindingsClosedOver || bi.closedOver());
1544 switch (bi.kind()) {
1545 case BindingKind::Synthetic:
1546 if (bi.name() ==
1547 TaggedParserAtomIndex::WellKnown::dot_privateBrand_()) {
1548 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", 1548); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "privateBrand.empty()" ")"); do { MOZ_CrashSequence
(__null, 1548); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1549 if (!privateBrand.append(binding)) {
1550 return Nothing();
1551 }
1552 } else {
1553 if (!synthetics.append(binding)) {
1554 return Nothing();
1555 }
1556 }
1557 break;
1558
1559 case BindingKind::PrivateMethod:
1560 if (!privateMethods.append(binding)) {
1561 return Nothing();
1562 }
1563 break;
1564
1565 default:
1566 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", 1566); AnnotateMozCrashReason
("MOZ_CRASH(" "bad class body scope BindingKind" ")"); do { MOZ_CrashSequence
(__null, 1566); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
1567 break;
1568 }
1569 }
1570
1571 // We should have zero or one private brands.
1572 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"
, 1572); AnnotateMozCrashReason("MOZ_ASSERT" "(" "privateBrand.length() == 0 || privateBrand.length() == 1"
")"); do { MOZ_CrashSequence(__null, 1572); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1573
1574 ClassBodyScope::ParserData* bindings = nullptr;
1575 uint32_t numBindings =
1576 privateBrand.length() + synthetics.length() + privateMethods.length();
1577
1578 if (numBindings > 0) {
1579 bindings = NewEmptyBindingData<ClassBodyScope>(fc, alloc, numBindings);
1580 if (!bindings) {
1581 return Nothing();
1582 }
1583 // To simplify initialization of the bindings, we concatenate the
1584 // synthetics+privateBrand vector such that the private brand is always the
1585 // first element, as ordering is important. See comments in ClassBodyScope.
1586 ParserBindingNameVector brandAndSynthetics(fc);
1587 if (!brandAndSynthetics.appendAll(privateBrand)) {
1588 return Nothing();
1589 }
1590 if (!brandAndSynthetics.appendAll(synthetics)) {
1591 return Nothing();
1592 }
1593
1594 // The ordering here is important. See comments in ClassBodyScope.
1595 InitializeBindingData(bindings, numBindings, brandAndSynthetics,
1596 &ParserClassBodyScopeSlotInfo::privateMethodStart,
1597 privateMethods);
1598 }
1599
1600 // `EmitterScope::lookupPrivate()` requires `.privateBrand` to be stored in a
1601 // predictable slot: the first slot available in the environment object,
1602 // `ClassBodyLexicalEnvironmentObject::privateBrandSlot()`. We assume that
1603 // if `.privateBrand` is first in the scope, it will be stored there.
1604 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", 1606); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()"
")"); do { MOZ_CrashSequence(__null, 1606); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1605 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", 1606); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()"
")"); do { MOZ_CrashSequence(__null, 1606); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1606 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", 1606); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "GetScopeDataTrailingNames(bindings)[0].name() == TaggedParserAtomIndex::WellKnown::dot_privateBrand_()"
")"); do { MOZ_CrashSequence(__null, 1606); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
1607
1608 return Some(bindings);
1609}
1610
1611Maybe<ClassBodyScope::ParserData*> ParserBase::newClassBodyScopeData(
1612 ParseContext::Scope& scope) {
1613 return NewClassBodyScopeData(fc_, scope, stencilAlloc(), pc_);
1614}
1615
1616template <>
1617SyntaxParseHandler::LexicalScopeNodeResult
1618PerHandlerParser<SyntaxParseHandler>::finishLexicalScope(
1619 ParseContext::Scope& scope, Node body, ScopeKind kind) {
1620 if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) {
1621 return errorResult();
1622 }
1623
1624 return handler_.newLexicalScope(body);
1625}
1626
1627template <>
1628FullParseHandler::LexicalScopeNodeResult
1629PerHandlerParser<FullParseHandler>::finishLexicalScope(
1630 ParseContext::Scope& scope, ParseNode* body, ScopeKind kind) {
1631 if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) {
1632 return errorResult();
1633 }
1634
1635 Maybe<LexicalScope::ParserData*> bindings = newLexicalScopeData(scope);
1636 if (!bindings) {
1637 return errorResult();
1638 }
1639
1640 return handler_.newLexicalScope(*bindings, body, kind);
1641}
1642
1643template <>
1644SyntaxParseHandler::ClassBodyScopeNodeResult
1645PerHandlerParser<SyntaxParseHandler>::finishClassBodyScope(
1646 ParseContext::Scope& scope, ListNodeType body) {
1647 if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) {
1648 return errorResult();
1649 }
1650
1651 return handler_.newClassBodyScope(body);
1652}
1653
1654template <>
1655FullParseHandler::ClassBodyScopeNodeResult
1656PerHandlerParser<FullParseHandler>::finishClassBodyScope(
1657 ParseContext::Scope& scope, ListNode* body) {
1658 if (!propagateFreeNamesAndMarkClosedOverBindings(scope)) {
1659 return errorResult();
1660 }
1661
1662 Maybe<ClassBodyScope::ParserData*> bindings = newClassBodyScopeData(scope);
1663 if (!bindings) {
1664 return errorResult();
1665 }
1666
1667 return handler_.newClassBodyScope(*bindings, body);
1668}
1669
1670template <class ParseHandler>
1671bool PerHandlerParser<ParseHandler>::checkForUndefinedPrivateFields(
1672 EvalSharedContext* evalSc) {
1673 if (!this->compilationState_.isInitialStencil()) {
1674 // We're delazifying -- so we already checked private names during first
1675 // parse.
1676 return true;
1677 }
1678
1679 Vector<UnboundPrivateName, 8> unboundPrivateNames(fc_);
1680 if (!usedNames_.getUnboundPrivateNames(unboundPrivateNames)) {
1681 return false;
1682 }
1683
1684 // No unbound names, let's get out of here!
1685 if (unboundPrivateNames.empty()) {
1686 return true;
1687 }
1688
1689 // It is an early error if there's private name references unbound,
1690 // unless it's an eval, in which case we need to check the scope
1691 // chain.
1692 if (!evalSc) {
1693 // The unbound private names are sorted, so just grab the first one.
1694 UnboundPrivateName minimum = unboundPrivateNames[0];
1695 UniqueChars str = this->parserAtoms().toPrintableString(minimum.atom);
1696 if (!str) {
1697 ReportOutOfMemory(this->fc_);
1698 return false;
1699 }
1700
1701 errorAt(minimum.position.begin, JSMSG_MISSING_PRIVATE_DECL, str.get());
1702 return false;
1703 }
1704
1705 // It's important that the unbound private names are sorted, as we
1706 // want our errors to always be issued to the first textually.
1707 for (UnboundPrivateName unboundName : unboundPrivateNames) {
1708 // If the enclosingScope is non-syntactic, then we are in a
1709 // Debugger.Frame.prototype.eval call. In order to find the declared private
1710 // names, we must use the effective scope that was determined when creating
1711 // the scopeContext.
1712 if (!this->compilationState_.scopeContext
1713 .effectiveScopePrivateFieldCacheHas(unboundName.atom)) {
1714 UniqueChars str = this->parserAtoms().toPrintableString(unboundName.atom);
1715 if (!str) {
1716 ReportOutOfMemory(this->fc_);
1717 return false;
1718 }
1719 errorAt(unboundName.position.begin, JSMSG_MISSING_PRIVATE_DECL,
1720 str.get());
1721 return false;
1722 }
1723 }
1724
1725 return true;
1726}
1727
1728template <typename Unit>
1729FullParseHandler::LexicalScopeNodeResult
1730Parser<FullParseHandler, Unit>::evalBody(EvalSharedContext* evalsc) {
1731 SourceParseContext evalpc(this, evalsc, /* newDirectives = */ nullptr);
1732 if (!evalpc.init()) {
1733 return errorResult();
1734 }
1735
1736 ParseContext::VarScope varScope(this);
1737 if (!varScope.init(pc_)) {
1738 return errorResult();
1739 }
1740
1741 LexicalScopeNode* body;
1742 {
1743 // All evals have an implicit non-extensible lexical scope.
1744 ParseContext::Scope lexicalScope(this);
1745 if (!lexicalScope.init(pc_)) {
1746 return errorResult();
1747 }
1748
1749 ListNode* list = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
1750
1751 if (!checkStatementsEOF()) {
1752 return errorResult();
1753 }
1754
1755 // Private names not lexically defined must trigger a syntax error.
1756 if (!checkForUndefinedPrivateFields(evalsc)) {
1757 return errorResult();
1758 }
1759
1760 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(); })
;
1761 }
1762
1763#ifdef DEBUG1
1764 if (evalpc.superScopeNeedsHomeObject() &&
1765 !this->compilationState_.input.enclosingScope.isNull()) {
1766 // If superScopeNeedsHomeObject_ is set and we are an entry-point
1767 // ParseContext, then we must be emitting an eval script, and the
1768 // outer function must already be marked as needing a home object
1769 // since it contains an eval.
1770 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"
, 1773); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain"
") (" "Eval must have found an enclosing function box scope that "
"allows super.property" ")"); do { MOZ_CrashSequence(__null,
1773); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
1771 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"
, 1773); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain"
") (" "Eval must have found an enclosing function box scope that "
"allows super.property" ")"); do { MOZ_CrashSequence(__null,
1773); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
1772 "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"
, 1773); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain"
") (" "Eval must have found an enclosing function box scope that "
"allows super.property" ")"); do { MOZ_CrashSequence(__null,
1773); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
1773 "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"
, 1773); AnnotateMozCrashReason("MOZ_ASSERT" "(" "this->compilationState_.scopeContext.hasFunctionNeedsHomeObjectOnChain"
") (" "Eval must have found an enclosing function box scope that "
"allows super.property" ")"); do { MOZ_CrashSequence(__null,
1773); __attribute__((nomerge)) ::abort(); } while (false); }
} while (false)
;
1774 }
1775#endif
1776
1777 if (!CheckParseTree(this->fc_, alloc_, body)) {
1778 return errorResult();
1779 }
1780
1781 ParseNode* node = body;
1782 if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node,
1783 &handler_)) {
1784 return errorResult();
1785 }
1786 body = handler_.asLexicalScopeNode(node);
1787
1788 if (!this->setSourceMapInfo()) {
1789 return errorResult();
1790 }
1791
1792 if (pc_->sc()->strict()) {
1793 if (!propagateFreeNamesAndMarkClosedOverBindings(varScope)) {
1794 return errorResult();
1795 }
1796 } else {
1797 // For non-strict eval scripts, since all bindings are automatically
1798 // considered closed over, we don't need to call propagateFreeNames-
1799 // AndMarkClosedOverBindings. However, Annex B.3.3 functions still need to
1800 // be marked.
1801 if (!varScope.propagateAndMarkAnnexBFunctionBoxes(pc_, this)) {
1802 return errorResult();
1803 }
1804 }
1805
1806 Maybe<EvalScope::ParserData*> bindings = newEvalScopeData(pc_->varScope());
1807 if (!bindings) {
1808 return errorResult();
1809 }
1810 evalsc->bindings = *bindings;
1811
1812 return body;
1813}
1814
1815template <typename Unit>
1816FullParseHandler::ListNodeResult Parser<FullParseHandler, Unit>::globalBody(
1817 GlobalSharedContext* globalsc) {
1818 SourceParseContext globalpc(this, globalsc, /* newDirectives = */ nullptr);
1819 if (!globalpc.init()) {
1820 return errorResult();
1821 }
1822
1823 ParseContext::VarScope varScope(this);
1824 if (!varScope.init(pc_)) {
1825 return errorResult();
1826 }
1827
1828 ListNode* body = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
1829
1830 if (!checkStatementsEOF()) {
1831 return errorResult();
1832 }
1833
1834 if (!CheckParseTree(this->fc_, alloc_, body)) {
1835 return errorResult();
1836 }
1837
1838 if (!checkForUndefinedPrivateFields()) {
1839 return errorResult();
1840 }
1841
1842 ParseNode* node = body;
1843 if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node,
1844 &handler_)) {
1845 return errorResult();
1846 }
1847 body = &node->as<ListNode>();
1848
1849 if (!this->setSourceMapInfo()) {
1850 return errorResult();
1851 }
1852
1853 // For global scripts, whether bindings are closed over or not doesn't
1854 // matter, so no need to call propagateFreeNamesAndMarkClosedOver-
1855 // Bindings. However, Annex B.3.3 functions still need to be marked.
1856 if (!varScope.propagateAndMarkAnnexBFunctionBoxes(pc_, this)) {
1857 return errorResult();
1858 }
1859
1860 Maybe<GlobalScope::ParserData*> bindings =
1861 newGlobalScopeData(pc_->varScope());
1862 if (!bindings) {
1863 return errorResult();
1864 }
1865 globalsc->bindings = *bindings;
1866
1867 return body;
1868}
1869
1870template <typename Unit>
1871FullParseHandler::ModuleNodeResult Parser<FullParseHandler, Unit>::moduleBody(
1872 ModuleSharedContext* modulesc) {
1873 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", 1873); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence
(__null, 1873); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1874
1875 if (!fc_->checkCompilationCancellation()) {
1876 return errorResult();
1877 }
1878
1879 this->compilationState_.moduleMetadata =
1880 fc_->getAllocator()->template new_<StencilModuleMetadata>();
1881 if (!this->compilationState_.moduleMetadata) {
1882 return errorResult();
1883 }
1884
1885 SourceParseContext modulepc(this, modulesc, nullptr);
1886 if (!modulepc.init()) {
1887 return errorResult();
1888 }
1889
1890 ParseContext::VarScope varScope(this);
1891 if (!varScope.init(pc_)) {
1892 return errorResult();
1893 }
1894
1895 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(); })
;
1896
1897 AutoAwaitIsKeyword<FullParseHandler, Unit> awaitIsKeyword(
1898 this, AwaitIsModuleKeyword);
1899 ListNode* stmtList = MOZ_TRY(statementList(YieldIsName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(YieldIsName)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
1900
1901 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", 1901); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "stmtList->isKind(ParseNodeKind::StatementList)"
")"); do { MOZ_CrashSequence(__null, 1901); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1902 moduleNode->setBody(&stmtList->template as<ListNode>());
1903
1904 if (pc_->isAsync()) {
1905 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_generator_())) {
1906 return errorResult();
1907 }
1908
1909 if (!pc_->declareTopLevelDotGeneratorName()) {
1910 return errorResult();
1911 }
1912 }
1913
1914 TokenKind tt;
1915 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
1916 return errorResult();
1917 }
1918 if (tt != TokenKind::Eof) {
1919 error(JSMSG_GARBAGE_AFTER_INPUT, "module", TokenKindToDesc(tt));
1920 return errorResult();
1921 }
1922
1923 // Set the module to async if an await keyword was found at the top level.
1924 if (pc_->isAsync()) {
1925 pc_->sc()->asModuleContext()->builder.noteAsync(
1926 *this->compilationState_.moduleMetadata);
1927 }
1928
1929 // Generate the Import/Export tables and store in CompilationState.
1930 if (!modulesc->builder.buildTables(*this->compilationState_.moduleMetadata)) {
1931 return errorResult();
1932 }
1933
1934 // Check exported local bindings exist and mark them as closed over.
1935 StencilModuleMetadata& moduleMetadata =
1936 *this->compilationState_.moduleMetadata;
1937 for (auto entry : moduleMetadata.localExportEntries) {
1938 DeclaredNamePtr p = modulepc.varScope().lookupDeclaredName(entry.localName);
1939 if (!p) {
1940 UniqueChars str = this->parserAtoms().toPrintableString(entry.localName);
1941 if (!str) {
1942 ReportOutOfMemory(this->fc_);
1943 return errorResult();
1944 }
1945
1946 errorNoOffset(JSMSG_MISSING_EXPORT, str.get());
1947 return errorResult();
1948 }
1949
1950 p->value()->setClosedOver();
1951 }
1952
1953 // Reserve an environment slot for a "*namespace*" psuedo-binding and mark as
1954 // closed-over. We do not know until module linking if this will be used.
1955 if (!noteDeclaredName(
1956 TaggedParserAtomIndex::WellKnown::star_namespace_star_(),
1957 DeclarationKind::Const, pos())) {
1958 return errorResult();
1959 }
1960 modulepc.varScope()
1961 .lookupDeclaredName(
1962 TaggedParserAtomIndex::WellKnown::star_namespace_star_())
1963 ->value()
1964 ->setClosedOver();
1965
1966 // Reserve an environment slot for a "*deferred-namespace*" pseudo-binding
1967 // and mark as closed-over. We do not know until module linking if this will
1968 // be used.
1969 if (!noteDeclaredName(
1970 TaggedParserAtomIndex::WellKnown::star_deferred_namespace_star_(),
1971 DeclarationKind::Const, pos())) {
1972 return errorResult();
1973 }
1974 modulepc.varScope()
1975 .lookupDeclaredName(
1976 TaggedParserAtomIndex::WellKnown::star_deferred_namespace_star_())
1977 ->value()
1978 ->setClosedOver();
1979
1980 if (!CheckParseTree(this->fc_, alloc_, stmtList)) {
1981 return errorResult();
1982 }
1983
1984 ParseNode* node = stmtList;
1985 if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node,
1986 &handler_)) {
1987 return errorResult();
1988 }
1989 stmtList = &node->as<ListNode>();
1990
1991 if (!this->setSourceMapInfo()) {
1992 return errorResult();
1993 }
1994
1995 // Private names not lexically defined must trigger a syntax error.
1996 if (!checkForUndefinedPrivateFields()) {
1997 return errorResult();
1998 }
1999
2000 if (!propagateFreeNamesAndMarkClosedOverBindings(modulepc.varScope())) {
2001 return errorResult();
2002 }
2003
2004 Maybe<ModuleScope::ParserData*> bindings =
2005 newModuleScopeData(modulepc.varScope());
2006 if (!bindings) {
2007 return errorResult();
2008 }
2009
2010 modulesc->bindings = *bindings;
2011 return moduleNode;
2012}
2013
2014template <typename Unit>
2015SyntaxParseHandler::ModuleNodeResult
2016Parser<SyntaxParseHandler, Unit>::moduleBody(ModuleSharedContext* modulesc) {
2017 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", 2017); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 2017); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
2018 return errorResult();
2019}
2020
2021template <class ParseHandler>
2022typename ParseHandler::NameNodeResult
2023PerHandlerParser<ParseHandler>::newInternalDotName(TaggedParserAtomIndex name) {
2024 NameNodeType nameNode = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
2025 if (!noteUsedName(name)) {
2026 return errorResult();
2027 }
2028 return nameNode;
2029}
2030
2031template <class ParseHandler>
2032typename ParseHandler::NameNodeResult
2033PerHandlerParser<ParseHandler>::newThisName() {
2034 return newInternalDotName(TaggedParserAtomIndex::WellKnown::dot_this_());
2035}
2036
2037template <class ParseHandler>
2038typename ParseHandler::NameNodeResult
2039PerHandlerParser<ParseHandler>::newNewTargetName() {
2040 return newInternalDotName(TaggedParserAtomIndex::WellKnown::dot_newTarget_());
2041}
2042
2043template <class ParseHandler>
2044typename ParseHandler::NameNodeResult
2045PerHandlerParser<ParseHandler>::newDotGeneratorName() {
2046 return newInternalDotName(TaggedParserAtomIndex::WellKnown::dot_generator_());
2047}
2048
2049template <class ParseHandler>
2050bool PerHandlerParser<ParseHandler>::finishFunctionScopes(
2051 bool isStandaloneFunction) {
2052 FunctionBox* funbox = pc_->functionBox();
2053
2054 if (funbox->hasParameterExprs) {
2055 if (!propagateFreeNamesAndMarkClosedOverBindings(pc_->functionScope())) {
2056 return false;
2057 }
2058
2059 // Functions with parameter expressions utilize the FunctionScope for vars
2060 // generated by sloppy-direct-evals, as well as arguments (which are
2061 // lexicals bindings). If the function body has var bindings (or has a
2062 // sloppy-direct-eval that might), then an extra VarScope must be created
2063 // for them.
2064 if (VarScopeHasBindings(pc_) ||
2065 funbox->needsExtraBodyVarEnvironmentRegardlessOfBindings()) {
2066 funbox->setFunctionHasExtraBodyVarScope();
2067 }
2068 }
2069
2070 // See: JSFunction::needsCallObject()
2071 if (FunctionScopeHasClosedOverBindings(pc_) ||
2072 funbox->needsCallObjectRegardlessOfBindings()) {
2073 funbox->setNeedsFunctionEnvironmentObjects();
2074 }
2075
2076 if (funbox->isNamedLambda() && !isStandaloneFunction) {
2077 if (!propagateFreeNamesAndMarkClosedOverBindings(pc_->namedLambdaScope())) {
2078 return false;
2079 }
2080
2081 // See: JSFunction::needsNamedLambdaEnvironment()
2082 if (LexicalScopeHasClosedOverBindings(pc_, pc_->namedLambdaScope())) {
2083 funbox->setNeedsFunctionEnvironmentObjects();
2084 }
2085 }
2086
2087 return true;
2088}
2089
2090template <>
2091bool PerHandlerParser<FullParseHandler>::finishFunction(
2092 bool isStandaloneFunction /* = false */) {
2093 if (!finishFunctionScopes(isStandaloneFunction)) {
2094 return false;
2095 }
2096
2097 FunctionBox* funbox = pc_->functionBox();
2098 ScriptStencil& script = funbox->functionStencil();
2099
2100 if (funbox->isInterpreted()) {
2101 // BCE will need to generate bytecode for this.
2102 funbox->emitBytecode = true;
2103 this->compilationState_.nonLazyFunctionCount++;
2104 }
2105
2106 bool hasParameterExprs = funbox->hasParameterExprs;
2107
2108 if (hasParameterExprs) {
2109 Maybe<VarScope::ParserData*> bindings = newVarScopeData(pc_->varScope());
2110 if (!bindings) {
2111 return false;
2112 }
2113 funbox->setExtraVarScopeBindings(*bindings);
2114
2115 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", 2115); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "bool(*bindings) == VarScopeHasBindings(pc_)"
")"); do { MOZ_CrashSequence(__null, 2115); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2116 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", 2117); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "bool(*bindings) == funbox->functionHasExtraBodyVarScope()"
")"); do { MOZ_CrashSequence(__null, 2117); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
2117 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", 2117); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "bool(*bindings) == funbox->functionHasExtraBodyVarScope()"
")"); do { MOZ_CrashSequence(__null, 2117); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
2118 }
2119
2120 {
2121 Maybe<FunctionScope::ParserData*> bindings =
2122 newFunctionScopeData(pc_->functionScope(), hasParameterExprs);
2123 if (!bindings) {
2124 return false;
2125 }
2126 funbox->setFunctionScopeBindings(*bindings);
2127 }
2128
2129 if (funbox->isNamedLambda() && !isStandaloneFunction) {
2130 Maybe<LexicalScope::ParserData*> bindings =
2131 newLexicalScopeData(pc_->namedLambdaScope());
2132 if (!bindings) {
2133 return false;
2134 }
2135 funbox->setNamedLambdaBindings(*bindings);
2136 }
2137
2138 funbox->finishScriptFlags();
2139 funbox->copyFunctionFields(script);
2140
2141 if (this->compilationState_.isInitialStencil()) {
2142 ScriptStencilExtra& scriptExtra = funbox->functionExtraStencil();
2143 funbox->copyFunctionExtraFields(scriptExtra);
2144 funbox->copyScriptExtraFields(scriptExtra);
2145 }
2146
2147 return true;
2148}
2149
2150template <>
2151bool PerHandlerParser<SyntaxParseHandler>::finishFunction(
2152 bool isStandaloneFunction /* = false */) {
2153 // The BaseScript for a lazily parsed function needs to know its set of
2154 // free variables and inner functions so that when it is fully parsed, we
2155 // can skip over any already syntax parsed inner functions and still
2156 // retain correct scope information.
2157
2158 if (!finishFunctionScopes(isStandaloneFunction)) {
2159 return false;
2160 }
2161
2162 FunctionBox* funbox = pc_->functionBox();
2163 ScriptStencil& script = funbox->functionStencil();
2164
2165 funbox->finishScriptFlags();
2166 funbox->copyFunctionFields(script);
2167
2168 ScriptStencilExtra& scriptExtra = funbox->functionExtraStencil();
2169 funbox->copyFunctionExtraFields(scriptExtra);
2170 funbox->copyScriptExtraFields(scriptExtra);
2171
2172 // Elide nullptr sentinels from end of binding list. These are inserted for
2173 // each scope regardless of if any bindings are actually closed over.
2174 {
2175 AtomVector& closedOver = pc_->closedOverBindingsForLazy();
2176 while (!closedOver.empty() && !closedOver.back()) {
2177 closedOver.popBack();
2178 }
2179 }
2180
2181 // Check if we will overflow the `ngcthings` field later.
2182 mozilla::CheckedUint32 ngcthings =
2183 mozilla::CheckedUint32(pc_->innerFunctionIndexesForLazy.length()) +
2184 mozilla::CheckedUint32(pc_->closedOverBindingsForLazy().length());
2185 if (!ngcthings.isValid()) {
2186 ReportAllocationOverflow(fc_);
2187 return false;
2188 }
2189
2190 // If there are no script-things, we can return early without allocating.
2191 if (ngcthings.value() == 0) {
2192 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", 2192); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!script.hasGCThings()" ")"); do { MOZ_CrashSequence
(__null, 2192); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2193 return true;
2194 }
2195
2196 TaggedScriptThingIndex* cursor = nullptr;
2197 if (!this->compilationState_.allocateGCThingsUninitialized(
2198 fc_, funbox->index(), ngcthings.value(), &cursor)) {
2199 return false;
2200 }
2201
2202 // Copy inner-function and closed-over-binding info for the stencil. The order
2203 // is important here. We emit functions first, followed by the bindings info.
2204 // The bindings list uses nullptr as delimiter to separates the bindings per
2205 // scope.
2206 //
2207 // See: FullParseHandler::nextLazyInnerFunction(),
2208 // FullParseHandler::nextLazyClosedOverBinding()
2209 for (const ScriptIndex& index : pc_->innerFunctionIndexesForLazy) {
2210 void* raw = &(*cursor++);
2211 new (raw) TaggedScriptThingIndex(index);
2212 }
2213 for (auto binding : pc_->closedOverBindingsForLazy()) {
2214 void* raw = &(*cursor++);
2215 if (binding) {
2216 this->parserAtoms().markUsedByStencil(binding, ParserAtom::Atomize::Yes);
2217 new (raw) TaggedScriptThingIndex(binding);
2218 } else {
2219 new (raw) TaggedScriptThingIndex();
2220 }
2221 }
2222
2223 return true;
2224}
2225
2226static YieldHandling GetYieldHandling(GeneratorKind generatorKind) {
2227 if (generatorKind == GeneratorKind::NotGenerator) {
2228 return YieldIsName;
2229 }
2230 return YieldIsKeyword;
2231}
2232
2233static AwaitHandling GetAwaitHandling(FunctionAsyncKind asyncKind) {
2234 if (asyncKind == FunctionAsyncKind::SyncFunction) {
2235 return AwaitIsName;
2236 }
2237 return AwaitIsKeyword;
2238}
2239
2240static FunctionFlags InitialFunctionFlags(FunctionSyntaxKind kind,
2241 GeneratorKind generatorKind,
2242 FunctionAsyncKind asyncKind,
2243 bool isSelfHosting) {
2244 FunctionFlags flags = {};
2245
2246 switch (kind) {
2247 case FunctionSyntaxKind::Expression:
2248 flags = (generatorKind == GeneratorKind::NotGenerator &&
2249 asyncKind == FunctionAsyncKind::SyncFunction
2250 ? FunctionFlags::INTERPRETED_LAMBDA
2251 : FunctionFlags::INTERPRETED_LAMBDA_GENERATOR_OR_ASYNC);
2252 break;
2253 case FunctionSyntaxKind::Arrow:
2254 flags = FunctionFlags::INTERPRETED_LAMBDA_ARROW;
2255 break;
2256 case FunctionSyntaxKind::Method:
2257 case FunctionSyntaxKind::FieldInitializer:
2258 case FunctionSyntaxKind::StaticClassBlock:
2259 flags = FunctionFlags::INTERPRETED_METHOD;
2260 break;
2261 case FunctionSyntaxKind::ClassConstructor:
2262 case FunctionSyntaxKind::DerivedClassConstructor:
2263 flags = FunctionFlags::INTERPRETED_CLASS_CTOR;
2264 break;
2265 case FunctionSyntaxKind::Getter:
2266 flags = FunctionFlags::INTERPRETED_GETTER;
2267 break;
2268 case FunctionSyntaxKind::Setter:
2269 flags = FunctionFlags::INTERPRETED_SETTER;
2270 break;
2271 default:
2272 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", 2272); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == FunctionSyntaxKind::Statement" ")"
); do { MOZ_CrashSequence(__null, 2272); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2273 flags = (generatorKind == GeneratorKind::NotGenerator &&
2274 asyncKind == FunctionAsyncKind::SyncFunction
2275 ? FunctionFlags::INTERPRETED_NORMAL
2276 : FunctionFlags::INTERPRETED_GENERATOR_OR_ASYNC);
2277 }
2278
2279 if (isSelfHosting) {
2280 flags.setIsSelfHostedBuiltin();
2281 }
2282
2283 return flags;
2284}
2285
2286template <typename Unit>
2287FullParseHandler::FunctionNodeResult
2288Parser<FullParseHandler, Unit>::standaloneFunction(
2289 const Maybe<uint32_t>& parameterListEnd, FunctionSyntaxKind syntaxKind,
2290 GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
2291 Directives inheritedDirectives, Directives* newDirectives) {
2292 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", 2292); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence
(__null, 2292); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2293 // Skip prelude.
2294 TokenKind tt;
2295 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
2296 return errorResult();
2297 }
2298 if (asyncKind == FunctionAsyncKind::AsyncFunction) {
2299 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", 2299); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "tt == TokenKind::Async" ")"); do { MOZ_CrashSequence
(__null, 2299); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2300 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
2301 return errorResult();
2302 }
2303 }
2304 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", 2304); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "tt == TokenKind::Function" ")"); do { MOZ_CrashSequence
(__null, 2304); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2305
2306 if (!tokenStream.getToken(&tt)) {
2307 return errorResult();
2308 }
2309 if (generatorKind == GeneratorKind::Generator) {
2310 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", 2310); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "tt == TokenKind::Mul" ")"); do { MOZ_CrashSequence
(__null, 2310); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2311 if (!tokenStream.getToken(&tt)) {
2312 return errorResult();
2313 }
2314 }
2315
2316 // Skip function name, if present.
2317 TaggedParserAtomIndex explicitName;
2318 if (TokenKindIsPossibleIdentifierName(tt)) {
2319 explicitName = anyChars.currentName();
2320 } else {
2321 anyChars.ungetToken();
2322 }
2323
2324 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(); })
;
2325
2326 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(); })
;
2327 funNode->setBody(argsbody);
2328
2329 bool isSelfHosting = options().selfHostingMode;
2330 FunctionFlags flags =
2331 InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting);
2332 FunctionBox* funbox =
2333 newFunctionBox(funNode, explicitName, flags, /* toStringStart = */ 0,
2334 inheritedDirectives, generatorKind, asyncKind);
2335 if (!funbox) {
2336 return errorResult();
2337 }
2338
2339 // Function is not syntactically part of another script.
2340 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"
, 2340); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->index() == CompilationStencil::TopLevelIndex"
")"); do { MOZ_CrashSequence(__null, 2340); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2341
2342 funbox->initStandalone(this->compilationState_.scopeContext, syntaxKind);
2343
2344 SourceParseContext funpc(this, funbox, newDirectives);
2345 if (!funpc.init()) {
2346 return errorResult();
2347 }
2348
2349 YieldHandling yieldHandling = GetYieldHandling(generatorKind);
2350 AwaitHandling awaitHandling = GetAwaitHandling(asyncKind);
2351 AutoAwaitIsKeyword<FullParseHandler, Unit> awaitIsKeyword(this,
2352 awaitHandling);
2353 if (!functionFormalParametersAndBody(InAllowed, yieldHandling, &funNode,
2354 syntaxKind, parameterListEnd,
2355 /* isStandaloneFunction = */ true)) {
2356 return errorResult();
2357 }
2358
2359 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
2360 return errorResult();
2361 }
2362 if (tt != TokenKind::Eof) {
2363 error(JSMSG_GARBAGE_AFTER_INPUT, "function body", TokenKindToDesc(tt));
2364 return errorResult();
2365 }
2366
2367 if (!CheckParseTree(this->fc_, alloc_, funNode)) {
2368 return errorResult();
2369 }
2370
2371 ParseNode* node = funNode;
2372 if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node,
2373 &handler_)) {
2374 return errorResult();
2375 }
2376 funNode = &node->as<FunctionNode>();
2377
2378 if (!checkForUndefinedPrivateFields(nullptr)) {
2379 return errorResult();
2380 }
2381
2382 if (!this->setSourceMapInfo()) {
2383 return errorResult();
2384 }
2385
2386 return funNode;
2387}
2388
2389template <class ParseHandler, typename Unit>
2390typename ParseHandler::LexicalScopeNodeResult
2391GeneralParser<ParseHandler, Unit>::functionBody(InHandling inHandling,
2392 YieldHandling yieldHandling,
2393 FunctionSyntaxKind kind,
2394 FunctionBodyType type) {
2395 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", 2395); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence
(__null, 2395); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2396
2397#ifdef DEBUG1
2398 uint32_t startYieldOffset = pc_->lastYieldOffset;
2399#endif
2400
2401 Node body;
2402 if (type == StatementListBody) {
2403 bool inheritedStrict = pc_->sc()->strict();
2404 body = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
2405
2406 // When we transitioned from non-strict to strict mode, we need to
2407 // validate that all parameter names are valid strict mode names.
2408 if (!inheritedStrict && pc_->sc()->strict()) {
2409 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"
, 2411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()"
") (" "strict mode should only change when a 'use strict' directive "
"is present" ")"); do { MOZ_CrashSequence(__null, 2411); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
2410 "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"
, 2411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()"
") (" "strict mode should only change when a 'use strict' directive "
"is present" ")"); do { MOZ_CrashSequence(__null, 2411); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
2411 "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"
, 2411); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()"
") (" "strict mode should only change when a 'use strict' directive "
"is present" ")"); do { MOZ_CrashSequence(__null, 2411); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
2412 if (!hasValidSimpleStrictParameterNames()) {
2413 // Request that this function be reparsed as strict to report
2414 // the invalid parameter name at the correct source location.
2415 pc_->newDirectives->setStrict();
2416 return errorResult();
2417 }
2418 }
2419 } else {
2420 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", 2420); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "type == ExpressionBody" ")"); do { MOZ_CrashSequence
(__null, 2420); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2421
2422 // Async functions are implemented as generators, and generators are
2423 // assumed to be statement lists, to prepend initial `yield`.
2424 ListNodeType stmtList = null();
2425 if (pc_->isAsync()) {
2426 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(); })
;
2427 }
2428
2429 Node kid =
2430 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(); })
;
2431
2432 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(); })
;
2433
2434 if (pc_->isAsync()) {
2435 handler_.addStatementToList(stmtList, body);
2436 body = stmtList;
2437 }
2438 }
2439
2440 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", 2441); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->lastYieldOffset == startYieldOffset"
")"); do { MOZ_CrashSequence(__null, 2441); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
2441 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", 2441); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->lastYieldOffset == startYieldOffset"
")"); do { MOZ_CrashSequence(__null, 2441); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
2442 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", 2442); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind != FunctionSyntaxKind::Arrow" ")"); do
{ MOZ_CrashSequence(__null, 2442); __attribute__((nomerge)) ::
abort(); } while (false); } } while (false); } } while (false
)
;
2443 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"
, 2443); AnnotateMozCrashReason("MOZ_ASSERT" "(" "type == StatementListBody"
")"); do { MOZ_CrashSequence(__null, 2443); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
2444
2445 if (pc_->needsDotGeneratorName()) {
2446 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"
, 2446); AnnotateMozCrashReason("MOZ_ASSERT" "(" "type == StatementListBody"
")"); do { MOZ_CrashSequence(__null, 2446); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
2447 if (!pc_->declareDotGeneratorName()) {
2448 return errorResult();
2449 }
2450 if (pc_->isGenerator()) {
2451 NameNodeType generator = MOZ_TRY(newDotGeneratorName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newDotGeneratorName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
2452 if (!handler_.prependInitialYield(handler_.asListNode(body), generator)) {
2453 return errorResult();
2454 }
2455 }
2456 }
2457
2458 if (pc_->numberOfArgumentsNames > 0 || kind == FunctionSyntaxKind::Arrow) {
2459 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", 2459); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence
(__null, 2459); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2460 pc_->sc()->setIneligibleForArgumentsLength();
2461 }
2462
2463 // Declare the 'arguments', 'this', and 'new.target' bindings if necessary
2464 // before finishing up the scope so these special bindings get marked as
2465 // closed over if necessary. Arrow functions don't have these bindings.
2466 if (kind != FunctionSyntaxKind::Arrow) {
2467 bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings();
2468 if (!pc_->declareFunctionArgumentsObject(usedNames_,
2469 canSkipLazyClosedOverBindings)) {
2470 return errorResult();
2471 }
2472 if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) {
2473 return errorResult();
2474 }
2475 if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) {
2476 return errorResult();
2477 }
2478 }
2479
2480 return finishLexicalScope(pc_->varScope(), body, ScopeKind::FunctionLexical);
2481}
2482
2483template <class ParseHandler, typename Unit>
2484bool GeneralParser<ParseHandler, Unit>::matchOrInsertSemicolon(
2485 Modifier modifier /* = TokenStream::SlashIsRegExp */) {
2486 TokenKind tt = TokenKind::Eof;
2487 if (!tokenStream.peekTokenSameLine(&tt, modifier)) {
2488 return false;
2489 }
2490 if (tt != TokenKind::Eof && tt != TokenKind::Eol && tt != TokenKind::Semi &&
2491 tt != TokenKind::RightCurly) {
2492 /*
2493 * When current token is `await` and it's outside of async function,
2494 * it's possibly intended to be an await expression.
2495 *
2496 * await f();
2497 * ^
2498 * |
2499 * tried to insert semicolon here
2500 *
2501 * Detect this situation and throw an understandable error. Otherwise
2502 * we'd throw a confusing "unexpected token: (unexpected token)" error.
2503 */
2504 if (!pc_->isAsync() && anyChars.currentToken().type == TokenKind::Await) {
2505 error(JSMSG_AWAIT_OUTSIDE_ASYNC_OR_MODULE);
2506 return false;
2507 }
2508 if (!yieldExpressionsSupported() &&
2509 anyChars.currentToken().type == TokenKind::Yield) {
2510 error(JSMSG_YIELD_OUTSIDE_GENERATOR);
2511 return false;
2512 }
2513
2514 if (anyChars.currentToken().type == TokenKind::Using &&
2515 !this->pc_->isUsingSyntaxAllowed()) {
2516 error(JSMSG_USING_OUTSIDE_BLOCK_OR_MODULE);
2517 return false;
2518 }
2519
2520 /* Advance the scanner for proper error location reporting. */
2521 tokenStream.consumeKnownToken(tt, modifier);
2522 error(JSMSG_UNEXPECTED_TOKEN_NO_EXPECT, TokenKindToDesc(tt));
2523 return false;
2524 }
2525 bool matched;
2526 return tokenStream.matchToken(&matched, TokenKind::Semi, modifier);
2527}
2528
2529bool ParserBase::leaveInnerFunction(ParseContext* outerpc) {
2530 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", 2530); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_ != outerpc" ")"); do { MOZ_CrashSequence
(__null, 2530); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2531
2532 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", 2533); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "outerpc->functionBox()->index() < pc_->functionBox()->index()"
")"); do { MOZ_CrashSequence(__null, 2533); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
2533 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", 2533); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "outerpc->functionBox()->index() < pc_->functionBox()->index()"
")"); do { MOZ_CrashSequence(__null, 2533); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
2534
2535 // If the current function allows super.property but cannot have a home
2536 // object, i.e., it is an arrow function, we need to propagate the flag to
2537 // the outer ParseContext.
2538 if (pc_->superScopeNeedsHomeObject()) {
2539 if (!pc_->isArrowFunction()) {
2540 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", 2540); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->functionBox()->needsHomeObject()"
")"); do { MOZ_CrashSequence(__null, 2540); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2541 } else {
2542 outerpc->setSuperScopeNeedsHomeObject();
2543 }
2544 }
2545
2546 // Lazy functions inner to another lazy function need to be remembered by
2547 // the inner function so that if the outer function is eventually parsed
2548 // we do not need any further parsing or processing of the inner function.
2549 //
2550 // Append the inner function index here unconditionally; the vector is only
2551 // used if the Parser using outerpc is a syntax parsing. See
2552 // GeneralParser<SyntaxParseHandler>::finishFunction.
2553 if (!outerpc->innerFunctionIndexesForLazy.append(
2554 pc_->functionBox()->index())) {
2555 return false;
2556 }
2557
2558 PropagateTransitiveParseFlags(pc_->functionBox(), outerpc->sc());
2559
2560 return true;
2561}
2562
2563TaggedParserAtomIndex ParserBase::prefixAccessorName(
2564 PropertyType propType, TaggedParserAtomIndex propAtom) {
2565 StringBuilder prefixed(fc_);
2566 if (propType == PropertyType::Setter) {
2567 if (!prefixed.append("set ")) {
2568 return TaggedParserAtomIndex::null();
2569 }
2570 } else {
2571 if (!prefixed.append("get ")) {
2572 return TaggedParserAtomIndex::null();
2573 }
2574 }
2575 if (!prefixed.append(this->parserAtoms(), propAtom)) {
2576 return TaggedParserAtomIndex::null();
2577 }
2578 return prefixed.finishParserAtom(this->parserAtoms(), fc_);
2579}
2580
2581template <class ParseHandler, typename Unit>
2582void GeneralParser<ParseHandler, Unit>::setFunctionStartAtPosition(
2583 FunctionBox* funbox, TokenPos pos) const {
2584 uint32_t startLine;
2585 JS::LimitedColumnNumberOneOrigin startColumn;
2586 tokenStream.computeLineAndColumn(pos.begin, &startLine, &startColumn);
2587
2588 // NOTE: `Debugger::CallData::findScripts` relies on sourceStart and
2589 // lineno/column referring to the same location.
2590 funbox->setStart(pos.begin, startLine, startColumn);
2591}
2592
2593template <class ParseHandler, typename Unit>
2594void GeneralParser<ParseHandler, Unit>::setFunctionStartAtCurrentToken(
2595 FunctionBox* funbox) const {
2596 setFunctionStartAtPosition(funbox, anyChars.currentToken().pos);
2597}
2598
2599template <class ParseHandler, typename Unit>
2600bool GeneralParser<ParseHandler, Unit>::functionArguments(
2601 YieldHandling yieldHandling, FunctionSyntaxKind kind,
2602 FunctionNodeType funNode) {
2603 FunctionBox* funbox = pc_->functionBox();
2604
2605 // Modifier for the following tokens.
2606 // TokenStream::SlashIsDiv for the following cases:
2607 // async a => 1
2608 // ^
2609 //
2610 // (a) => 1
2611 // ^
2612 //
2613 // async (a) => 1
2614 // ^
2615 //
2616 // function f(a) {}
2617 // ^
2618 //
2619 // TokenStream::SlashIsRegExp for the following case:
2620 // a => 1
2621 // ^
2622 Modifier firstTokenModifier =
2623 kind != FunctionSyntaxKind::Arrow || funbox->isAsync()
2624 ? TokenStream::SlashIsDiv
2625 : TokenStream::SlashIsRegExp;
2626 TokenKind tt;
2627 if (!tokenStream.getToken(&tt, firstTokenModifier)) {
2628 return false;
2629 }
2630
2631 if (kind == FunctionSyntaxKind::Arrow && TokenKindIsPossibleIdentifier(tt)) {
2632 // Record the start of function source (for FunctionToString).
2633 setFunctionStartAtCurrentToken(funbox);
2634
2635 ParamsBodyNodeType argsbody;
2636 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)
;
2637 handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
2638
2639 TaggedParserAtomIndex name = bindingIdentifier(yieldHandling);
2640 if (!name) {
2641 return false;
2642 }
2643
2644 constexpr bool disallowDuplicateParams = true;
2645 bool duplicatedParam = false;
2646 if (!notePositionalFormalParameter(funNode, name, pos().begin,
2647 disallowDuplicateParams,
2648 &duplicatedParam)) {
2649 return false;
2650 }
2651 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", 2651); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!duplicatedParam" ")"); do { MOZ_CrashSequence
(__null, 2651); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
2652 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"
, 2652); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->positionalFormalParameterNames().length() == 1"
")"); do { MOZ_CrashSequence(__null, 2652); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2653
2654 funbox->setLength(1);
2655 funbox->setArgCount(1);
2656 return true;
2657 }
2658
2659 if (tt != TokenKind::LeftParen) {
2660 error(kind == FunctionSyntaxKind::Arrow ? JSMSG_BAD_ARROW_ARGS
2661 : JSMSG_PAREN_BEFORE_FORMAL);
2662 return false;
2663 }
2664
2665 // Record the start of function source (for FunctionToString).
2666 setFunctionStartAtCurrentToken(funbox);
2667
2668 ParamsBodyNodeType argsbody;
2669 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)
;
2670 handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
2671
2672 bool matched;
2673 if (!tokenStream.matchToken(&matched, TokenKind::RightParen,
2674 TokenStream::SlashIsRegExp)) {
2675 return false;
2676 }
2677 if (!matched) {
2678 bool hasRest = false;
2679 bool hasDefault = false;
2680 bool duplicatedParam = false;
2681 bool disallowDuplicateParams =
2682 kind == FunctionSyntaxKind::Arrow ||
2683 kind == FunctionSyntaxKind::Method ||
2684 kind == FunctionSyntaxKind::FieldInitializer ||
2685 kind == FunctionSyntaxKind::ClassConstructor;
2686 AtomVector& positionalFormals = pc_->positionalFormalParameterNames();
2687
2688 if (kind == FunctionSyntaxKind::Getter) {
2689 error(JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s");
2690 return false;
2691 }
2692
2693 while (true) {
2694 if (hasRest) {
2695 error(JSMSG_PARAMETER_AFTER_REST);
2696 return false;
2697 }
2698
2699 TokenKind tt;
2700 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
2701 return false;
2702 }
2703
2704 if (tt == TokenKind::TripleDot) {
2705 if (kind == FunctionSyntaxKind::Setter) {
2706 error(JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", "");
2707 return false;
2708 }
2709
2710 disallowDuplicateParams = true;
2711 if (duplicatedParam) {
2712 // Has duplicated args before the rest parameter.
2713 error(JSMSG_BAD_DUP_ARGS);
2714 return false;
2715 }
2716
2717 hasRest = true;
2718 funbox->setHasRest();
2719
2720 if (!tokenStream.getToken(&tt)) {
2721 return false;
2722 }
2723
2724 if (!TokenKindIsPossibleIdentifier(tt) &&
2725 tt != TokenKind::LeftBracket && tt != TokenKind::LeftCurly) {
2726 error(JSMSG_NO_REST_NAME);
2727 return false;
2728 }
2729 }
2730
2731 switch (tt) {
2732 case TokenKind::LeftBracket:
2733 case TokenKind::LeftCurly: {
2734 disallowDuplicateParams = true;
2735 if (duplicatedParam) {
2736 // Has duplicated args before the destructuring parameter.
2737 error(JSMSG_BAD_DUP_ARGS);
2738 return false;
2739 }
2740
2741 funbox->hasDestructuringArgs = true;
2742
2743 Node destruct;
2744 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)
2745 destruct,do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait
( DeclarationKind::FormalParameter, yieldHandling, tt)); if (
(__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) {
return (false); } (destruct) = parserTryVarTempResult_.unwrap
(); } while (0)
2746 destructuringDeclarationWithoutYieldOrAwait(do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait
( DeclarationKind::FormalParameter, yieldHandling, tt)); if (
(__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) {
return (false); } (destruct) = parserTryVarTempResult_.unwrap
(); } while (0)
2747 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)
2748 false)do { auto parserTryVarTempResult_ = (destructuringDeclarationWithoutYieldOrAwait
( DeclarationKind::FormalParameter, yieldHandling, tt)); if (
(__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0))) {
return (false); } (destruct) = parserTryVarTempResult_.unwrap
(); } while (0)
;
2749
2750 if (!noteDestructuredPositionalFormalParameter(funNode, destruct)) {
2751 return false;
2752 }
2753
2754 break;
2755 }
2756
2757 default: {
2758 if (!TokenKindIsPossibleIdentifier(tt)) {
2759 error(JSMSG_MISSING_FORMAL);
2760 return false;
2761 }
2762
2763 TaggedParserAtomIndex name = bindingIdentifier(yieldHandling);
2764 if (!name) {
2765 return false;
2766 }
2767
2768 if (!notePositionalFormalParameter(funNode, name, pos().begin,
2769 disallowDuplicateParams,
2770 &duplicatedParam)) {
2771 return false;
2772 }
2773 if (duplicatedParam) {
2774 funbox->hasDuplicateParameters = true;
2775 }
2776
2777 break;
2778 }
2779 }
2780
2781 if (positionalFormals.length() >= ARGNO_LIMIT) {
2782 error(JSMSG_TOO_MANY_FUN_ARGS);
2783 return false;
2784 }
2785
2786 bool matched;
2787 if (!tokenStream.matchToken(&matched, TokenKind::Assign,
2788 TokenStream::SlashIsRegExp)) {
2789 return false;
2790 }
2791 if (matched) {
2792 if (hasRest) {
2793 error(JSMSG_REST_WITH_DEFAULT);
2794 return false;
2795 }
2796 disallowDuplicateParams = true;
2797 if (duplicatedParam) {
2798 error(JSMSG_BAD_DUP_ARGS);
2799 return false;
2800 }
2801
2802 if (!hasDefault) {
2803 hasDefault = true;
2804
2805 // The Function.length property is the number of formals
2806 // before the first default argument.
2807 funbox->setLength(positionalFormals.length() - 1);
2808 }
2809 funbox->hasParameterExprs = true;
2810
2811 Node def_expr;
2812 MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (assignExprWithoutYieldOrAwait
(yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (def_expr) = parserTryVarTempResult_
.unwrap(); } while (0)
2813 def_expr, assignExprWithoutYieldOrAwait(yieldHandling), false)do { auto parserTryVarTempResult_ = (assignExprWithoutYieldOrAwait
(yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (def_expr) = parserTryVarTempResult_
.unwrap(); } while (0)
;
2814 if (!handler_.setLastFunctionFormalParameterDefault(funNode,
2815 def_expr)) {
2816 return false;
2817 }
2818 }
2819
2820 // Setter syntax uniquely requires exactly one argument.
2821 if (kind == FunctionSyntaxKind::Setter) {
2822 break;
2823 }
2824
2825 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
2826 TokenStream::SlashIsRegExp)) {
2827 return false;
2828 }
2829 if (!matched) {
2830 break;
2831 }
2832
2833 if (!hasRest) {
2834 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
2835 return false;
2836 }
2837 if (tt == TokenKind::RightParen) {
2838 break;
2839 }
2840 }
2841 }
2842
2843 TokenKind tt;
2844 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
2845 return false;
2846 }
2847 if (tt != TokenKind::RightParen) {
2848 if (kind == FunctionSyntaxKind::Setter) {
2849 error(JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", "");
2850 return false;
2851 }
2852
2853 error(JSMSG_PAREN_AFTER_FORMAL);
2854 return false;
2855 }
2856
2857 if (!hasDefault) {
2858 funbox->setLength(positionalFormals.length() - hasRest);
2859 }
2860
2861 funbox->setArgCount(positionalFormals.length());
2862 } else if (kind == FunctionSyntaxKind::Setter) {
2863 error(JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", "");
2864 return false;
2865 }
2866
2867 return true;
2868}
2869
2870template <typename Unit>
2871bool Parser<FullParseHandler, Unit>::skipLazyInnerFunction(
2872 FunctionNode* funNode, uint32_t toStringStart, bool tryAnnexB) {
2873 // When a lazily-parsed function is called, we only fully parse (and emit)
2874 // that function, not any of its nested children. The initial syntax-only
2875 // parse recorded the free variables of nested functions and their extents,
2876 // so we can skip over them after accounting for their free variables.
2877
2878 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", 2878); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isOutermostOfCurrentCompile()" ")"
); do { MOZ_CrashSequence(__null, 2878); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2879 handler_.nextLazyInnerFunction();
2880 const ScriptStencil& cachedData = handler_.cachedScriptData();
2881 const ScriptStencilExtra& cachedExtra = handler_.cachedScriptExtra();
2882 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", 2882); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "toStringStart == cachedExtra.extent.toStringStart"
")"); do { MOZ_CrashSequence(__null, 2882); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2883
2884 FunctionBox* funbox = newFunctionBox(funNode, cachedData, cachedExtra);
2885 if (!funbox) {
2886 return false;
2887 }
2888
2889 ScriptStencil& script = funbox->functionStencil();
2890 funbox->copyFunctionFields(script);
2891
2892 // If the inner lazy function is class constructor, connect it to the class
2893 // statement/expression we are parsing.
2894 if (funbox->isClassConstructor()) {
2895 auto classStmt =
2896 pc_->template findInnermostStatement<ParseContext::ClassStatement>();
2897 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"
, 2897); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!classStmt->constructorBox"
")"); do { MOZ_CrashSequence(__null, 2897); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
2898 classStmt->constructorBox = funbox;
2899 }
2900
2901 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", 2902); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->functionBox()->index() < funbox->index()"
")"); do { MOZ_CrashSequence(__null, 2902); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
2902 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", 2902); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->functionBox()->index() < funbox->index()"
")"); do { MOZ_CrashSequence(__null, 2902); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
2903
2904 PropagateTransitiveParseFlags(funbox, pc_->sc());
2905
2906 if (!tokenStream.advance(funbox->extent().sourceEnd)) {
2907 return false;
2908 }
2909
2910 // Append possible Annex B function box only upon successfully parsing.
2911 if (tryAnnexB &&
2912 !pc_->innermostScope()->addPossibleAnnexBFunctionBox(pc_, funbox)) {
2913 return false;
2914 }
2915
2916 return true;
2917}
2918
2919template <typename Unit>
2920bool Parser<SyntaxParseHandler, Unit>::skipLazyInnerFunction(
2921 FunctionNodeType funNode, uint32_t toStringStart, bool tryAnnexB) {
2922 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", 2922); AnnotateMozCrashReason
("MOZ_CRASH(" "Cannot skip lazy inner functions when syntax parsing"
")"); do { MOZ_CrashSequence(__null, 2922); __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
2923}
2924
2925template <class ParseHandler, typename Unit>
2926bool GeneralParser<ParseHandler, Unit>::skipLazyInnerFunction(
2927 FunctionNodeType funNode, uint32_t toStringStart, bool tryAnnexB) {
2928 return asFinalParser()->skipLazyInnerFunction(funNode, toStringStart,
2929 tryAnnexB);
2930}
2931
2932template <class ParseHandler, typename Unit>
2933bool GeneralParser<ParseHandler, Unit>::addExprAndGetNextTemplStrToken(
2934 YieldHandling yieldHandling, ListNodeType nodeList, TokenKind* ttp) {
2935 Node pn;
2936 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)
2937 false)do { auto parserTryVarTempResult_ = (expr(InAllowed, yieldHandling
, TripledotProhibited)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (pn) = parserTryVarTempResult_
.unwrap(); } while (0)
;
2938 handler_.addList(nodeList, pn);
2939
2940 TokenKind tt;
2941 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
2942 return false;
2943 }
2944 if (tt != TokenKind::RightCurly) {
2945 error(JSMSG_TEMPLSTR_UNTERM_EXPR);
2946 return false;
2947 }
2948
2949 return tokenStream.getTemplateToken(ttp);
2950}
2951
2952template <class ParseHandler, typename Unit>
2953bool GeneralParser<ParseHandler, Unit>::taggedTemplate(
2954 YieldHandling yieldHandling, ListNodeType tagArgsList, TokenKind tt) {
2955 CallSiteNodeType callSiteObjNode;
2956 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)
2957 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)
;
2958 handler_.addList(tagArgsList, callSiteObjNode);
2959
2960 pc_->sc()->setHasCallSiteObj();
2961
2962 while (true) {
2963 if (!appendToCallSiteObj(callSiteObjNode)) {
2964 return false;
2965 }
2966 if (tt != TokenKind::TemplateHead) {
2967 break;
2968 }
2969
2970 if (!addExprAndGetNextTemplStrToken(yieldHandling, tagArgsList, &tt)) {
2971 return false;
2972 }
2973 }
2974 handler_.setEndPosition(tagArgsList, callSiteObjNode);
2975 return true;
2976}
2977
2978template <class ParseHandler, typename Unit>
2979typename ParseHandler::ListNodeResult
2980GeneralParser<ParseHandler, Unit>::templateLiteral(
2981 YieldHandling yieldHandling) {
2982 NameNodeType literal = MOZ_TRY(noSubstitutionUntaggedTemplate())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(noSubstitutionUntaggedTemplate()); if ((__builtin_expect(!!(
mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
2983
2984 ListNodeType nodeList =
2985 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(); })
;
2986
2987 TokenKind tt;
2988 do {
2989 if (!addExprAndGetNextTemplStrToken(yieldHandling, nodeList, &tt)) {
2990 return errorResult();
2991 }
2992
2993 literal = MOZ_TRY(noSubstitutionUntaggedTemplate())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(noSubstitutionUntaggedTemplate()); if ((__builtin_expect(!!(
mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
2994
2995 handler_.addList(nodeList, literal);
2996 } while (tt == TokenKind::TemplateHead);
2997 return nodeList;
2998}
2999
3000template <class ParseHandler, typename Unit>
3001typename ParseHandler::FunctionNodeResult
3002GeneralParser<ParseHandler, Unit>::functionDefinition(
3003 FunctionNodeType funNode, uint32_t toStringStart, InHandling inHandling,
3004 YieldHandling yieldHandling, TaggedParserAtomIndex funName,
3005 FunctionSyntaxKind kind, GeneratorKind generatorKind,
3006 FunctionAsyncKind asyncKind, bool tryAnnexB /* = false */) {
3007 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",
3007); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funName" ")"
); do { MOZ_CrashSequence(__null, 3007); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
3008
3009 if (!this->fc_->checkCompilationCancellation()) {
3010 return errorResult();
3011 }
3012
3013 // If we see any inner function, note it on our current context. The bytecode
3014 // emitter may eliminate the function later, but we use a conservative
3015 // definition for consistency between lazy and full parsing.
3016 pc_->sc()->setHasInnerFunctions();
3017
3018 // When fully parsing a lazy script, we do not fully reparse its inner
3019 // functions, which are also lazy. Instead, their free variables and source
3020 // extents are recorded and may be skipped.
3021 if (handler_.reuseLazyInnerFunctions()) {
3022 if (!skipLazyInnerFunction(funNode, toStringStart, tryAnnexB)) {
3023 return errorResult();
3024 }
3025
3026 return funNode;
3027 }
3028
3029 bool isSelfHosting = options().selfHostingMode;
3030 FunctionFlags flags =
3031 InitialFunctionFlags(kind, generatorKind, asyncKind, isSelfHosting);
3032
3033 // Self-hosted functions with special function names require extended slots
3034 // for various purposes.
3035 bool forceExtended =
3036 isSelfHosting && funName &&
3037 this->parserAtoms().isExtendedUnclonedSelfHostedFunctionName(funName);
3038 if (forceExtended) {
3039 flags.setIsExtended();
3040 }
3041
3042 // Speculatively parse using the directives of the parent parsing context.
3043 // If a directive is encountered (e.g., "use strict") that changes how the
3044 // function should have been parsed, we backup and reparse with the new set
3045 // of directives.
3046 Directives directives(pc_);
3047 Directives newDirectives = directives;
3048
3049 Position start(tokenStream);
3050 auto startObj = this->compilationState_.getPosition();
3051
3052 // Parse the inner function. The following is a loop as we may attempt to
3053 // reparse a function due to failed syntax parsing and encountering new
3054 // "use foo" directives.
3055 while (true) {
3056 if (trySyntaxParseInnerFunction(&funNode, funName, flags, toStringStart,
3057 inHandling, yieldHandling, kind,
3058 generatorKind, asyncKind, tryAnnexB,
3059 directives, &newDirectives)) {
3060 break;
3061 }
3062
3063 // Return on error.
3064 if (anyChars.hadError() || directives == newDirectives) {
3065 return errorResult();
3066 }
3067
3068 // Assignment must be monotonic to prevent infinitely attempting to
3069 // reparse.
3070 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"
, 3070); AnnotateMozCrashReason("MOZ_ASSERT" "(" "newDirectives.strict()"
")"); do { MOZ_CrashSequence(__null, 3070); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
3071 directives = newDirectives;
3072
3073 // Rewind to retry parsing with new directives applied.
3074 tokenStream.rewind(start);
3075 this->compilationState_.rewind(startObj);
3076
3077 // functionFormalParametersAndBody may have already set body before failing.
3078 handler_.setFunctionFormalParametersAndBody(funNode, null());
3079 }
3080
3081 return funNode;
3082}
3083
3084template <typename Unit>
3085bool Parser<FullParseHandler, Unit>::advancePastSyntaxParsedFunction(
3086 SyntaxParser* syntaxParser) {
3087 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"
, 3087); AnnotateMozCrashReason("MOZ_ASSERT" "(" "getSyntaxParser() == syntaxParser"
")"); do { MOZ_CrashSequence(__null, 3087); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3088
3089 // Advance this parser over tokens processed by the syntax parser.
3090 Position currentSyntaxPosition(syntaxParser->tokenStream);
3091 if (!tokenStream.fastForward(currentSyntaxPosition, syntaxParser->anyChars)) {
3092 return false;
3093 }
3094
3095 anyChars.adoptState(syntaxParser->anyChars);
3096 tokenStream.adoptState(syntaxParser->tokenStream);
3097 return true;
3098}
3099
3100template <typename Unit>
3101bool Parser<FullParseHandler, Unit>::trySyntaxParseInnerFunction(
3102 FunctionNode** funNode, TaggedParserAtomIndex explicitName,
3103 FunctionFlags flags, uint32_t toStringStart, InHandling inHandling,
3104 YieldHandling yieldHandling, FunctionSyntaxKind kind,
3105 GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB,
3106 Directives inheritedDirectives, Directives* newDirectives) {
3107 // Try a syntax parse for this inner function.
3108 do {
3109 // If we're assuming this function is an IIFE, always perform a full
3110 // parse to avoid the overhead of a lazy syntax-only parse. Although
3111 // the prediction may be incorrect, IIFEs are common enough that it
3112 // pays off for lots of code.
3113 if ((*funNode)->isLikelyIIFE() &&
3114 generatorKind == GeneratorKind::NotGenerator &&
3115 asyncKind == FunctionAsyncKind::SyncFunction) {
3116 break;
3117 }
3118
3119 SyntaxParser* syntaxParser = getSyntaxParser();
3120 if (!syntaxParser) {
3121 break;
3122 }
3123
3124 UsedNameTracker::RewindToken token = usedNames_.getRewindToken();
3125 auto statePosition = this->compilationState_.getPosition();
3126
3127 // Move the syntax parser to the current position in the stream. In the
3128 // common case this seeks forward, but it'll also seek backward *at least*
3129 // when arrow functions appear inside arrow function argument defaults
3130 // (because we rewind to reparse arrow functions once we're certain they're
3131 // arrow functions):
3132 //
3133 // var x = (y = z => 2) => q;
3134 // // ^ we first seek to here to syntax-parse this function
3135 // // ^ then we seek back to here to syntax-parse the outer function
3136 Position currentPosition(tokenStream);
3137 if (!syntaxParser->tokenStream.seekTo(currentPosition, anyChars)) {
3138 return false;
3139 }
3140
3141 // Make a FunctionBox before we enter the syntax parser, because |pn|
3142 // still expects a FunctionBox to be attached to it during BCE, and
3143 // the syntax parser cannot attach one to it.
3144 FunctionBox* funbox =
3145 newFunctionBox(*funNode, explicitName, flags, toStringStart,
3146 inheritedDirectives, generatorKind, asyncKind);
3147 if (!funbox) {
3148 return false;
3149 }
3150 funbox->initWithEnclosingParseContext(pc_, kind);
3151
3152 auto syntaxNodeResult = syntaxParser->innerFunctionForFunctionBox(
3153 SyntaxParseHandler::Node::NodeGeneric, pc_, funbox, inHandling,
3154 yieldHandling, kind, newDirectives);
3155 if (syntaxNodeResult.isErr()) {
3156 if (syntaxParser->hadAbortedSyntaxParse()) {
3157 if (!fc_->checkCompilationCancellation()) {
3158 return false;
3159 }
3160
3161 // Try again with a full parse. UsedNameTracker needs to be
3162 // rewound to just before we tried the syntax parse for
3163 // correctness.
3164 syntaxParser->clearAbortedSyntaxParse();
3165 usedNames_.rewind(token);
3166 this->compilationState_.rewind(statePosition);
3167 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", 3167); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!fc_->hadErrors()" ")"); do { MOZ_CrashSequence
(__null, 3167); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3168 break;
3169 }
3170 return false;
3171 }
3172
3173 if (!advancePastSyntaxParsedFunction(syntaxParser)) {
3174 return false;
3175 }
3176
3177 // Update the end position of the parse node.
3178 (*funNode)->pn_pos.end = anyChars.currentToken().pos.end;
3179
3180 // Append possible Annex B function box only upon successfully parsing.
3181 if (tryAnnexB) {
3182 if (!pc_->innermostScope()->addPossibleAnnexBFunctionBox(pc_, funbox)) {
3183 return false;
3184 }
3185 }
3186
3187 return true;
3188 } while (false);
3189
3190 // We failed to do a syntax parse above, so do the full parse.
3191 FunctionNodeType innerFunc;
3192 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)
3193 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)
3194 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)
3195 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)
3196 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)
3197 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)
;
3198
3199 *funNode = innerFunc;
3200 return true;
3201}
3202
3203template <typename Unit>
3204bool Parser<SyntaxParseHandler, Unit>::trySyntaxParseInnerFunction(
3205 FunctionNodeType* funNode, TaggedParserAtomIndex explicitName,
3206 FunctionFlags flags, uint32_t toStringStart, InHandling inHandling,
3207 YieldHandling yieldHandling, FunctionSyntaxKind kind,
3208 GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB,
3209 Directives inheritedDirectives, Directives* newDirectives) {
3210 // This is already a syntax parser, so just parse the inner function.
3211 FunctionNodeType innerFunc;
3212 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)
3213 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)
3214 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)
3215 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)
3216 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)
3217 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)
;
3218
3219 *funNode = innerFunc;
3220 return true;
3221}
3222
3223template <class ParseHandler, typename Unit>
3224inline bool GeneralParser<ParseHandler, Unit>::trySyntaxParseInnerFunction(
3225 FunctionNodeType* funNode, TaggedParserAtomIndex explicitName,
3226 FunctionFlags flags, uint32_t toStringStart, InHandling inHandling,
3227 YieldHandling yieldHandling, FunctionSyntaxKind kind,
3228 GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB,
3229 Directives inheritedDirectives, Directives* newDirectives) {
3230 return asFinalParser()->trySyntaxParseInnerFunction(
3231 funNode, explicitName, flags, toStringStart, inHandling, yieldHandling,
3232 kind, generatorKind, asyncKind, tryAnnexB, inheritedDirectives,
3233 newDirectives);
3234}
3235
3236template <class ParseHandler, typename Unit>
3237typename ParseHandler::FunctionNodeResult
3238GeneralParser<ParseHandler, Unit>::innerFunctionForFunctionBox(
3239 FunctionNodeType funNode, ParseContext* outerpc, FunctionBox* funbox,
3240 InHandling inHandling, YieldHandling yieldHandling, FunctionSyntaxKind kind,
3241 Directives* newDirectives) {
3242 // Note that it is possible for outerpc != this->pc_, as we may be
3243 // attempting to syntax parse an inner function from an outer full
3244 // parser. In that case, outerpc is a SourceParseContext from the full parser
3245 // instead of the current top of the stack of the syntax parser.
3246
3247 // Push a new ParseContext.
3248 SourceParseContext funpc(this, funbox, newDirectives);
3249 if (!funpc.init()) {
3250 return errorResult();
3251 }
3252
3253 if (!functionFormalParametersAndBody(inHandling, yieldHandling, &funNode,
3254 kind)) {
3255 return errorResult();
3256 }
3257
3258 if (!leaveInnerFunction(outerpc)) {
3259 return errorResult();
3260 }
3261
3262 return funNode;
3263}
3264
3265template <class ParseHandler, typename Unit>
3266typename ParseHandler::FunctionNodeResult
3267GeneralParser<ParseHandler, Unit>::innerFunction(
3268 FunctionNodeType funNode, ParseContext* outerpc,
3269 TaggedParserAtomIndex explicitName, FunctionFlags flags,
3270 uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling,
3271 FunctionSyntaxKind kind, GeneratorKind generatorKind,
3272 FunctionAsyncKind asyncKind, bool tryAnnexB, Directives inheritedDirectives,
3273 Directives* newDirectives) {
3274 // Note that it is possible for outerpc != this->pc_, as we may be
3275 // attempting to syntax parse an inner function from an outer full
3276 // parser. In that case, outerpc is a SourceParseContext from the full parser
3277 // instead of the current top of the stack of the syntax parser.
3278
3279 FunctionBox* funbox =
3280 newFunctionBox(funNode, explicitName, flags, toStringStart,
3281 inheritedDirectives, generatorKind, asyncKind);
3282 if (!funbox) {
3283 return errorResult();
3284 }
3285 funbox->initWithEnclosingParseContext(outerpc, kind);
3286
3287 FunctionNodeType innerFunc =
3288 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(); })
3289 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(); })
;
3290
3291 // Append possible Annex B function box only upon successfully parsing.
3292 if (tryAnnexB) {
3293 if (!pc_->innermostScope()->addPossibleAnnexBFunctionBox(pc_, funbox)) {
3294 return errorResult();
3295 }
3296 }
3297
3298 return innerFunc;
3299}
3300
3301template <class ParseHandler, typename Unit>
3302bool GeneralParser<ParseHandler, Unit>::appendToCallSiteObj(
3303 CallSiteNodeType callSiteObj) {
3304 Node cookedNode;
3305 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)
;
3306
3307 auto atom = tokenStream.getRawTemplateStringAtom();
3308 if (!atom) {
3309 return false;
3310 }
3311 NameNodeType rawNode;
3312 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)
3313 false)do { auto parserTryVarTempResult_ = (handler_.newTemplateStringLiteral
(atom, pos())); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (rawNode) = parserTryVarTempResult_
.unwrap(); } while (0)
;
3314
3315 handler_.addToCallSiteObject(callSiteObj, rawNode, cookedNode);
3316 return true;
3317}
3318
3319template <typename Unit>
3320FullParseHandler::FunctionNodeResult
3321Parser<FullParseHandler, Unit>::standaloneLazyFunction(
3322 CompilationInput& input, uint32_t toStringStart, bool strict,
3323 GeneratorKind generatorKind, FunctionAsyncKind asyncKind) {
3324 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", 3324); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence
(__null, 3324); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
1
Assuming field 'checkOptionsCalled_' is true
2
Taking false branch
3
Loop condition is false. Exiting loop
3325
3326 FunctionSyntaxKind syntaxKind = input.functionSyntaxKind();
3327 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(); })
;
4
Taking false branch
3328
3329 TaggedParserAtomIndex displayAtom =
3330 this->getCompilationState().previousParseCache.displayAtom();
3331
3332 Directives directives(strict);
3333 FunctionBox* funbox =
3334 newFunctionBox(funNode, displayAtom, input.functionFlags(), toStringStart,
3335 directives, generatorKind, asyncKind);
3336 if (!funbox
4.1
'funbox' is non-null
) {
5
Taking false branch
3337 return errorResult();
3338 }
3339 const ScriptStencilExtra& funExtra =
3340 this->getCompilationState().previousParseCache.funExtra();
3341 funbox->initFromLazyFunction(
3342 funExtra, this->getCompilationState().scopeContext, syntaxKind);
3343 if (funbox->useMemberInitializers()) {
6
Assuming the condition is false
7
Taking false branch
3344 funbox->setMemberInitializers(funExtra.memberInitializers());
3345 }
3346
3347 Directives newDirectives = directives;
3348 SourceParseContext funpc(this, funbox, &newDirectives);
3349 if (!funpc.init()) {
8
Assuming the condition is false
3350 return errorResult();
3351 }
3352
3353 // Our tokenStream has no current token, so funNode's position is garbage.
3354 // Substitute the position of the first token in our source. If the
3355 // function is a not-async arrow, use TokenStream::SlashIsRegExp to keep
3356 // verifyConsistentModifier from complaining (we will use
3357 // TokenStream::SlashIsRegExp in functionArguments).
3358 Modifier modifier = (input.functionFlags().isArrow() &&
3359 asyncKind == FunctionAsyncKind::SyncFunction)
3360 ? TokenStream::SlashIsRegExp
3361 : TokenStream::SlashIsDiv;
3362 if (!tokenStream.peekTokenPos(&funNode->pn_pos, modifier)) {
9
Taking false branch
3363 return errorResult();
3364 }
3365
3366 YieldHandling yieldHandling = GetYieldHandling(generatorKind);
3367
3368 if (funbox->isSyntheticFunction()) {
10
Assuming the condition is true
11
Taking true branch
3369 // Currently default class constructors are the only synthetic function that
3370 // supports delazification.
3371 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"
, 3371); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isClassConstructor()"
")"); do { MOZ_CrashSequence(__null, 3371); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
12
Taking false branch
13
Loop condition is false. Exiting loop
3372 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", 3372); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "funbox->extent().toStringStart == funbox->extent().sourceStart"
")"); do { MOZ_CrashSequence(__null, 3372); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
14
Assuming field 'toStringStart' is equal to field 'sourceStart'
15
Taking false branch
3373
3374 HasHeritage hasHeritage = funbox->isDerivedClassConstructor()
16
Loop condition is false. Exiting loop
17
Assuming the condition is true
18
'?' condition is true
3375 ? HasHeritage::Yes
3376 : HasHeritage::No;
3377 TokenPos synthesizedBodyPos(funbox->extent().toStringStart,
3378 funbox->extent().toStringEnd);
3379
3380 // Reset pos() to the `class` keyword for predictable results.
3381 tokenStream.consumeKnownToken(TokenKind::Class);
3382
3383 if (!this->synthesizeConstructorBody(synthesizedBodyPos, hasHeritage,
19
Calling 'GeneralParser::synthesizeConstructorBody'
3384 funNode, funbox)) {
3385 return errorResult();
3386 }
3387 } else {
3388 if (!functionFormalParametersAndBody(InAllowed, yieldHandling, &funNode,
3389 syntaxKind)) {
3390 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", 3390); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "directives == newDirectives" ")"); do { MOZ_CrashSequence
(__null, 3390); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3391 return errorResult();
3392 }
3393 }
3394
3395 if (!CheckParseTree(this->fc_, alloc_, funNode)) {
3396 return errorResult();
3397 }
3398
3399 ParseNode* node = funNode;
3400 if (!FoldConstants(this->fc_, this->parserAtoms(), this->bigInts(), &node,
3401 &handler_)) {
3402 return errorResult();
3403 }
3404 funNode = &node->as<FunctionNode>();
3405
3406 return funNode;
3407}
3408
3409void ParserBase::setFunctionEndFromCurrentToken(FunctionBox* funbox) const {
3410 if (compilationState_.isInitialStencil()) {
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 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", 3412); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.currentToken().type < TokenKind::Limit"
")"); do { MOZ_CrashSequence(__null, 3412); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3413 funbox->setEnd(anyChars.currentToken().pos.end);
3414 } else {
3415 // If we're delazifying an arrow function with expression body and
3416 // the expression is also a function, we arrive here immediately after
3417 // skipping the function by Parser::skipLazyInnerFunction.
3418 //
3419 // a => b => c
3420 // ^
3421 // |
3422 // we're here
3423 //
3424 // In that case, the current token's type field is either Limit or
3425 // poisoned.
3426 // We shouldn't read the value if it's poisoned.
3427 // See TokenStreamSpecific<Unit, AnyCharsAccess>::advance and
3428 // mfbt/MemoryChecking.h for more details.
3429 //
3430 // Also, in delazification, the FunctionBox should already have the
3431 // correct extent, and we shouldn't overwrite it here.
3432 // See ScriptStencil variant of PerHandlerParser::newFunctionBox.
3433#if !defined(MOZ_ASAN) && !defined(MOZ_MSAN) && !defined(MOZ_VALGRIND)
3434 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", 3434); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.currentToken().type != TokenKind::Eof"
")"); do { MOZ_CrashSequence(__null, 3434); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3435#endif
3436 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", 3436); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "funbox->extent().sourceEnd == anyChars.currentToken().pos.end"
")"); do { MOZ_CrashSequence(__null, 3436); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3437 }
3438}
3439
3440template <class ParseHandler, typename Unit>
3441bool GeneralParser<ParseHandler, Unit>::functionFormalParametersAndBody(
3442 InHandling inHandling, YieldHandling yieldHandling,
3443 FunctionNodeType* funNode, FunctionSyntaxKind kind,
3444 const Maybe<uint32_t>& parameterListEnd /* = Nothing() */,
3445 bool isStandaloneFunction /* = false */) {
3446 // Given a properly initialized parse context, try to parse an actual
3447 // function without concern for conversion to strict mode, use of lazy
3448 // parsing and such.
3449
3450 FunctionBox* funbox = pc_->functionBox();
3451
3452 if (kind == FunctionSyntaxKind::ClassConstructor ||
3453 kind == FunctionSyntaxKind::DerivedClassConstructor) {
3454 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_initializers_())) {
3455 return false;
3456 }
3457#ifdef ENABLE_DECORATORS
3458 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::
3459 dot_instanceExtraInitializers_())) {
3460 return false;
3461 }
3462#endif
3463 }
3464
3465 // See below for an explanation why arrow function parameters and arrow
3466 // function bodies are parsed with different yield/await settings.
3467 {
3468 AwaitHandling awaitHandling =
3469 kind == FunctionSyntaxKind::StaticClassBlock ? AwaitIsDisallowed
3470 : (funbox->isAsync() ||
3471 (kind == FunctionSyntaxKind::Arrow && awaitIsKeyword()))
3472 ? AwaitIsKeyword
3473 : AwaitIsName;
3474 AutoAwaitIsKeyword<ParseHandler, Unit> awaitIsKeyword(this, awaitHandling);
3475 AutoInParametersOfAsyncFunction<ParseHandler, Unit> inParameters(
3476 this, funbox->isAsync());
3477 if (!functionArguments(yieldHandling, kind, *funNode)) {
3478 return false;
3479 }
3480 }
3481
3482 Maybe<ParseContext::VarScope> varScope;
3483 if (funbox->hasParameterExprs) {
3484 varScope.emplace(this);
3485 if (!varScope->init(pc_)) {
3486 return false;
3487 }
3488 } else {
3489 pc_->functionScope().useAsVarScope(pc_);
3490 }
3491
3492 if (kind == FunctionSyntaxKind::Arrow) {
3493 TokenKind tt;
3494 if (!tokenStream.peekTokenSameLine(&tt)) {
3495 return false;
3496 }
3497
3498 if (tt == TokenKind::Eol) {
3499 error(JSMSG_UNEXPECTED_TOKEN,
3500 "'=>' on the same line after an argument list",
3501 TokenKindToDesc(tt));
3502 return false;
3503 }
3504 if (tt != TokenKind::Arrow) {
3505 error(JSMSG_BAD_ARROW_ARGS);
3506 return false;
3507 }
3508 tokenStream.consumeKnownToken(TokenKind::Arrow);
3509 }
3510
3511 // When parsing something for new Function() we have to make sure to
3512 // only treat a certain part of the source as a parameter list.
3513 if (parameterListEnd.isSome() && parameterListEnd.value() != pos().begin) {
3514 error(JSMSG_UNEXPECTED_PARAMLIST_END);
3515 return false;
3516 }
3517
3518 // Parse the function body.
3519 FunctionBodyType bodyType = StatementListBody;
3520 TokenKind tt;
3521 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
3522 return false;
3523 }
3524 uint32_t openedPos = 0;
3525 if (tt != TokenKind::LeftCurly) {
3526 if (kind != FunctionSyntaxKind::Arrow) {
3527 error(JSMSG_CURLY_BEFORE_BODY);
3528 return false;
3529 }
3530
3531 anyChars.ungetToken();
3532 bodyType = ExpressionBody;
3533 funbox->setHasExprBody();
3534 } else {
3535 openedPos = pos().begin;
3536 }
3537
3538 // Arrow function parameters inherit yieldHandling from the enclosing
3539 // context, but the arrow body doesn't. E.g. in |(a = yield) => yield|,
3540 // |yield| in the parameters is either a name or keyword, depending on
3541 // whether the arrow function is enclosed in a generator function or not.
3542 // Whereas the |yield| in the function body is always parsed as a name.
3543 // The same goes when parsing |await| in arrow functions.
3544 YieldHandling bodyYieldHandling = GetYieldHandling(pc_->generatorKind());
3545 AwaitHandling bodyAwaitHandling = GetAwaitHandling(pc_->asyncKind());
3546 bool inheritedStrict = pc_->sc()->strict();
3547 LexicalScopeNodeType body;
3548 {
3549 AutoAwaitIsKeyword<ParseHandler, Unit> awaitIsKeyword(this,
3550 bodyAwaitHandling);
3551 AutoInParametersOfAsyncFunction<ParseHandler, Unit> inParameters(this,
3552 false);
3553 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)
3554 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)
3555 false)do { auto parserTryVarTempResult_ = (functionBody(inHandling,
bodyYieldHandling, kind, bodyType)); if ((__builtin_expect(!
!(parserTryVarTempResult_.isErr()), 0))) { return (false); } (
body) = parserTryVarTempResult_.unwrap(); } while (0)
;
3556 }
3557
3558 // Revalidate the function name when we transitioned to strict mode.
3559 if ((kind == FunctionSyntaxKind::Statement ||
3560 kind == FunctionSyntaxKind::Expression) &&
3561 funbox->explicitName() && !inheritedStrict && pc_->sc()->strict()) {
3562 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"
, 3564); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()"
") (" "strict mode should only change when a 'use strict' directive "
"is present" ")"); do { MOZ_CrashSequence(__null, 3564); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
3563 "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"
, 3564); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()"
") (" "strict mode should only change when a 'use strict' directive "
"is present" ")"); do { MOZ_CrashSequence(__null, 3564); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
3564 "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"
, 3564); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->sc()->hasExplicitUseStrict()"
") (" "strict mode should only change when a 'use strict' directive "
"is present" ")"); do { MOZ_CrashSequence(__null, 3564); __attribute__
((nomerge)) ::abort(); } while (false); } } while (false)
;
3565
3566 auto propertyName = funbox->explicitName();
3567 YieldHandling nameYieldHandling;
3568 if (kind == FunctionSyntaxKind::Expression) {
3569 // Named lambda has binding inside it.
3570 nameYieldHandling = bodyYieldHandling;
3571 } else {
3572 // Otherwise YieldHandling cannot be checked at this point
3573 // because of different context.
3574 // It should already be checked before this point.
3575 nameYieldHandling = YieldIsName;
3576 }
3577
3578 // We already use the correct await-handling at this point, therefore
3579 // we don't need call AutoAwaitIsKeyword here.
3580
3581 uint32_t nameOffset = handler_.getFunctionNameOffset(*funNode, anyChars);
3582 if (!checkBindingIdentifier(propertyName, nameOffset, nameYieldHandling)) {
3583 return false;
3584 }
3585 }
3586
3587 if (bodyType == StatementListBody) {
3588 // Cannot use mustMatchToken here because of internal compiler error on
3589 // gcc 6.4.0, with linux 64 SM hazard build.
3590 TokenKind actual;
3591 if (!tokenStream.getToken(&actual, TokenStream::SlashIsRegExp)) {
3592 return false;
3593 }
3594 if (actual != TokenKind::RightCurly) {
3595 reportMissingClosing(JSMSG_CURLY_AFTER_BODY, JSMSG_CURLY_OPENED,
3596 openedPos);
3597 return false;
3598 }
3599
3600 setFunctionEndFromCurrentToken(funbox);
3601 } else {
3602 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"
, 3602); AnnotateMozCrashReason("MOZ_ASSERT" "(" "kind == FunctionSyntaxKind::Arrow"
")"); do { MOZ_CrashSequence(__null, 3602); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3603
3604 if (anyChars.hadError()) {
3605 return false;
3606 }
3607
3608 setFunctionEndFromCurrentToken(funbox);
3609 }
3610
3611 if (IsMethodDefinitionKind(kind) && pc_->superScopeNeedsHomeObject()) {
3612 funbox->setNeedsHomeObject();
3613 }
3614
3615 if (!finishFunction(isStandaloneFunction)) {
3616 return false;
3617 }
3618
3619 handler_.setEndPosition(body, pos().begin);
3620 handler_.setEndPosition(*funNode, pos().end);
3621 handler_.setFunctionBody(*funNode, body);
3622
3623 return true;
3624}
3625
3626template <class ParseHandler, typename Unit>
3627typename ParseHandler::FunctionNodeResult
3628GeneralParser<ParseHandler, Unit>::functionStmt(uint32_t toStringStart,
3629 YieldHandling yieldHandling,
3630 DefaultHandling defaultHandling,
3631 FunctionAsyncKind asyncKind) {
3632 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", 3632); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)"
")"); do { MOZ_CrashSequence(__null, 3632); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3633
3634 // In sloppy mode, Annex B.3.2 allows labelled function declarations.
3635 // Otherwise it's a parse error.
3636 ParseContext::Statement* declaredInStmt = pc_->innermostStatement();
3637 if (declaredInStmt && declaredInStmt->kind() == StatementKind::Label) {
3638 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", 3639); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!pc_->sc()->strict()" ") (" "labeled functions shouldn't be parsed in strict mode"
")"); do { MOZ_CrashSequence(__null, 3639); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
3639 "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", 3639); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!pc_->sc()->strict()" ") (" "labeled functions shouldn't be parsed in strict mode"
")"); do { MOZ_CrashSequence(__null, 3639); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3640
3641 // Find the innermost non-label statement. Report an error if it's
3642 // unbraced: functions can't appear in it. Otherwise the statement
3643 // (or its absence) determines the scope the function's bound in.
3644 while (declaredInStmt && declaredInStmt->kind() == StatementKind::Label) {
3645 declaredInStmt = declaredInStmt->enclosing();
3646 }
3647
3648 if (declaredInStmt && !StatementKindIsBraced(declaredInStmt->kind())) {
3649 error(JSMSG_SLOPPY_FUNCTION_LABEL);
3650 return errorResult();
3651 }
3652 }
3653
3654 TokenKind tt;
3655 if (!tokenStream.getToken(&tt)) {
3656 return errorResult();
3657 }
3658
3659 GeneratorKind generatorKind = GeneratorKind::NotGenerator;
3660 if (tt == TokenKind::Mul) {
3661 generatorKind = GeneratorKind::Generator;
3662 if (!tokenStream.getToken(&tt)) {
3663 return errorResult();
3664 }
3665 }
3666
3667 TaggedParserAtomIndex name;
3668 if (TokenKindIsPossibleIdentifier(tt)) {
3669 name = bindingIdentifier(yieldHandling);
3670 if (!name) {
3671 return errorResult();
3672 }
3673 } else if (defaultHandling == AllowDefaultName) {
3674 name = TaggedParserAtomIndex::WellKnown::default_();
3675 anyChars.ungetToken();
3676 } else {
3677 /* Unnamed function expressions are forbidden in statement context. */
3678 error(JSMSG_UNNAMED_FUNCTION_STMT);
3679 return errorResult();
3680 }
3681
3682 if (name == TaggedParserAtomIndex::WellKnown::arguments()) {
3683 pc_->numberOfArgumentsNames++;
3684 }
3685
3686 // Note the declared name and check for early errors.
3687 DeclarationKind kind;
3688 if (declaredInStmt) {
3689 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", 3689); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "declaredInStmt->kind() != StatementKind::Label"
")"); do { MOZ_CrashSequence(__null, 3689); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3690 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", 3690); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "StatementKindIsBraced(declaredInStmt->kind())"
")"); do { MOZ_CrashSequence(__null, 3690); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3691
3692 kind =
3693 (!pc_->sc()->strict() && generatorKind == GeneratorKind::NotGenerator &&
3694 asyncKind == FunctionAsyncKind::SyncFunction)
3695 ? DeclarationKind::SloppyLexicalFunction
3696 : DeclarationKind::LexicalFunction;
3697 } else {
3698 kind = pc_->atModuleLevel() ? DeclarationKind::ModuleBodyLevelFunction
3699 : DeclarationKind::BodyLevelFunction;
3700 }
3701
3702 if (!noteDeclaredName(name, kind, pos())) {
3703 return errorResult();
3704 }
3705
3706 FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Statement;
3707 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(); })
;
3708
3709 // Under sloppy mode, try Annex B.3.3 semantics. If making an additional
3710 // 'var' binding of the same name does not throw an early error, do so.
3711 // This 'var' binding would be assigned the function object when its
3712 // declaration is reached, not at the start of the block.
3713 //
3714 // This semantics is implemented upon Scope exit in
3715 // Scope::propagateAndMarkAnnexBFunctionBoxes.
3716 bool tryAnnexB = kind == DeclarationKind::SloppyLexicalFunction;
3717
3718 YieldHandling newYieldHandling = GetYieldHandling(generatorKind);
3719 return functionDefinition(funNode, toStringStart, InAllowed, newYieldHandling,
3720 name, syntaxKind, generatorKind, asyncKind,
3721 tryAnnexB);
3722}
3723
3724template <class ParseHandler, typename Unit>
3725typename ParseHandler::FunctionNodeResult
3726GeneralParser<ParseHandler, Unit>::functionExpr(uint32_t toStringStart,
3727 InvokedPrediction invoked,
3728 FunctionAsyncKind asyncKind) {
3729 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", 3729); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)"
")"); do { MOZ_CrashSequence(__null, 3729); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
3730
3731 AutoAwaitIsKeyword<ParseHandler, Unit> awaitIsKeyword(
3732 this, GetAwaitHandling(asyncKind));
3733 GeneratorKind generatorKind = GeneratorKind::NotGenerator;
3734 TokenKind tt;
3735 if (!tokenStream.getToken(&tt)) {
3736 return errorResult();
3737 }
3738
3739 if (tt == TokenKind::Mul) {
3740 generatorKind = GeneratorKind::Generator;
3741 if (!tokenStream.getToken(&tt)) {
3742 return errorResult();
3743 }
3744 }
3745
3746 YieldHandling yieldHandling = GetYieldHandling(generatorKind);
3747
3748 TaggedParserAtomIndex name;
3749 if (TokenKindIsPossibleIdentifier(tt)) {
3750 name = bindingIdentifier(yieldHandling);
3751 if (!name) {
3752 return errorResult();
3753 }
3754 } else {
3755 anyChars.ungetToken();
3756 }
3757
3758 FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Expression;
3759 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(); })
;
3760
3761 if (invoked) {
3762 funNode = handler_.setLikelyIIFE(funNode);
3763 }
3764
3765 return functionDefinition(funNode, toStringStart, InAllowed, yieldHandling,
3766 name, syntaxKind, generatorKind, asyncKind);
3767}
3768
3769/*
3770 * Return true if this node, known to be an unparenthesized string literal
3771 * that never contain escape sequences, could be the string of a directive in a
3772 * Directive Prologue. Directive strings never contain escape sequences or line
3773 * continuations.
3774 */
3775static inline bool IsUseStrictDirective(const TokenPos& pos,
3776 TaggedParserAtomIndex atom) {
3777 // the length of "use strict", including quotation.
3778 static constexpr size_t useStrictLength = 12;
3779 return atom == TaggedParserAtomIndex::WellKnown::use_strict_() &&
3780 pos.begin + useStrictLength == pos.end;
3781}
3782
3783/*
3784 * Recognize Directive Prologue members and directives. Assuming |pn| is a
3785 * candidate for membership in a directive prologue, recognize directives and
3786 * set |pc_|'s flags accordingly. If |pn| is indeed part of a prologue, set its
3787 * |prologue| flag.
3788 *
3789 * Note that the following is a strict mode function:
3790 *
3791 * function foo() {
3792 * "blah" // inserted semi colon
3793 * "blurgh"
3794 * "use\x20loose"
3795 * "use strict"
3796 * }
3797 *
3798 * That is, even though "use\x20loose" can never be a directive, now or in the
3799 * future (because of the hex escape), the Directive Prologue extends through it
3800 * to the "use strict" statement, which is indeed a directive.
3801 */
3802template <class ParseHandler, typename Unit>
3803bool GeneralParser<ParseHandler, Unit>::maybeParseDirective(
3804 ListNodeType list, Node possibleDirective, bool* cont) {
3805 TokenPos directivePos;
3806 TaggedParserAtomIndex directive =
3807 handler_.isStringExprStatement(possibleDirective, &directivePos);
3808
3809 *cont = !!directive;
3810 if (!*cont) {
3811 return true;
3812 }
3813
3814 if (IsUseStrictDirective(directivePos, directive)) {
3815 // Functions with non-simple parameter lists (destructuring,
3816 // default or rest parameters) must not contain a "use strict"
3817 // directive.
3818 if (pc_->isFunctionBox()) {
3819 FunctionBox* funbox = pc_->functionBox();
3820 if (!funbox->hasSimpleParameterList()) {
3821 const char* parameterKind = funbox->hasDestructuringArgs
3822 ? "destructuring"
3823 : funbox->hasParameterExprs ? "default"
3824 : "rest";
3825 errorAt(directivePos.begin, JSMSG_STRICT_NON_SIMPLE_PARAMS,
3826 parameterKind);
3827 return false;
3828 }
3829 }
3830
3831 // We're going to be in strict mode. Note that this scope explicitly
3832 // had "use strict";
3833 pc_->sc()->setExplicitUseStrict();
3834 if (!pc_->sc()->strict()) {
3835 // Some strict mode violations can appear before a Use Strict Directive
3836 // is applied. (See the |DeprecatedContent| enum initializers.) These
3837 // violations can manifest in two ways.
3838 //
3839 // First, the violation can appear *before* the Use Strict Directive.
3840 // Numeric literals (and therefore octal literals) can only precede a
3841 // Use Strict Directive if this function's parameter list is not simple,
3842 // but we reported an error for non-simple parameter lists above, so
3843 // octal literals present no issue. But octal escapes and \8 and \9 can
3844 // appear in the directive prologue before a Use Strict Directive:
3845 //
3846 // function f()
3847 // {
3848 // "hell\157 world"; // octal escape
3849 // "\8"; "\9"; // NonOctalDecimalEscape
3850 // "use strict"; // retroactively makes all the above errors
3851 // }
3852 //
3853 // Second, the violation can appear *after* the Use Strict Directive but
3854 // *before* the directive is recognized as terminated. This only
3855 // happens when a directive is terminated by ASI, and the next token
3856 // contains a violation:
3857 //
3858 // function a()
3859 // {
3860 // "use strict" // ASI
3861 // 0755;
3862 // }
3863 // function b()
3864 // {
3865 // "use strict" // ASI
3866 // "hell\157 world";
3867 // }
3868 // function c()
3869 // {
3870 // "use strict" // ASI
3871 // "\8";
3872 // }
3873 //
3874 // We note such violations when tokenizing. Then, if a violation has
3875 // been observed at the time a "use strict" is applied, we report the
3876 // error.
3877 switch (anyChars.sawDeprecatedContent()) {
3878 case DeprecatedContent::None:
3879 break;
3880 case DeprecatedContent::OctalLiteral:
3881 error(JSMSG_DEPRECATED_OCTAL_LITERAL);
3882 return false;
3883 case DeprecatedContent::OctalEscape:
3884 error(JSMSG_DEPRECATED_OCTAL_ESCAPE);
3885 return false;
3886 case DeprecatedContent::EightOrNineEscape:
3887 error(JSMSG_DEPRECATED_EIGHT_OR_NINE_ESCAPE);
3888 return false;
3889 }
3890
3891 pc_->sc()->setStrictScript();
3892 }
3893 }
3894 return true;
3895}
3896
3897template <class ParseHandler, typename Unit>
3898typename ParseHandler::ListNodeResult
3899GeneralParser<ParseHandler, Unit>::statementList(YieldHandling yieldHandling) {
3900 AutoCheckRecursionLimit recursion(this->fc_);
3901 if (!recursion.check(this->fc_)) {
3902 return errorResult();
3903 }
3904
3905 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(); })
;
3906
3907 bool canHaveDirectives = pc_->atBodyLevel();
3908 if (canHaveDirectives) {
3909 // Clear flags for deprecated content that might have been seen in an
3910 // enclosing context.
3911 anyChars.clearSawDeprecatedContent();
3912 }
3913
3914 bool canHaveHashbangComment = pc_->atTopLevel();
3915 if (canHaveHashbangComment) {
3916 tokenStream.consumeOptionalHashbangComment();
3917 }
3918
3919 bool afterReturn = false;
3920 bool warnedAboutStatementsAfterReturn = false;
3921 uint32_t statementBegin = 0;
3922 for (;;) {
3923 TokenKind tt = TokenKind::Eof;
3924 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
3925 if (anyChars.isEOF()) {
3926 isUnexpectedEOF_ = true;
3927 }
3928 return errorResult();
3929 }
3930 if (tt == TokenKind::Eof || tt == TokenKind::RightCurly) {
3931 TokenPos pos;
3932 if (!tokenStream.peekTokenPos(&pos, TokenStream::SlashIsRegExp)) {
3933 return errorResult();
3934 }
3935 handler_.setListEndPosition(stmtList, pos);
3936 break;
3937 }
3938 if (afterReturn) {
3939 if (!tokenStream.peekOffset(&statementBegin,
3940 TokenStream::SlashIsRegExp)) {
3941 return errorResult();
3942 }
3943 }
3944 auto nextResult = statementListItem(yieldHandling, canHaveDirectives);
3945 if (nextResult.isErr()) {
3946 if (anyChars.isEOF()) {
3947 isUnexpectedEOF_ = true;
3948 }
3949 return errorResult();
3950 }
3951 Node next = nextResult.unwrap();
3952 if (!warnedAboutStatementsAfterReturn) {
3953 if (afterReturn) {
3954 if (!handler_.isStatementPermittedAfterReturnStatement(next)) {
3955 if (!warningAt(statementBegin, JSMSG_STMT_AFTER_RETURN)) {
3956 return errorResult();
3957 }
3958
3959 warnedAboutStatementsAfterReturn = true;
3960 }
3961 } else if (handler_.isReturnStatement(next)) {
3962 afterReturn = true;
3963 }
3964 }
3965
3966 if (canHaveDirectives) {
3967 if (!maybeParseDirective(stmtList, next, &canHaveDirectives)) {
3968 return errorResult();
3969 }
3970 }
3971
3972 handler_.addStatementToList(stmtList, next);
3973 }
3974
3975 return stmtList;
3976}
3977
3978template <class ParseHandler, typename Unit>
3979typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::condition(
3980 InHandling inHandling, YieldHandling yieldHandling) {
3981 if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_COND)) {
3982 return errorResult();
3983 }
3984
3985 Node pn =
3986 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(); })
;
3987
3988 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_COND)) {
3989 return errorResult();
3990 }
3991
3992 return pn;
3993}
3994
3995template <class ParseHandler, typename Unit>
3996bool GeneralParser<ParseHandler, Unit>::matchLabel(
3997 YieldHandling yieldHandling, TaggedParserAtomIndex* labelOut) {
3998 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", 3998); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "labelOut != nullptr" ")"); do { MOZ_CrashSequence
(__null, 3998); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
3999 TokenKind tt = TokenKind::Eof;
4000 if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) {
4001 return false;
4002 }
4003
4004 if (TokenKindIsPossibleIdentifier(tt)) {
4005 tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp);
4006
4007 *labelOut = labelIdentifier(yieldHandling);
4008 if (!*labelOut) {
4009 return false;
4010 }
4011 } else {
4012 *labelOut = TaggedParserAtomIndex::null();
4013 }
4014 return true;
4015}
4016
4017template <class ParseHandler, typename Unit>
4018GeneralParser<ParseHandler, Unit>::PossibleError::PossibleError(
4019 GeneralParser<ParseHandler, Unit>& parser)
4020 : parser_(parser) {}
4021
4022template <class ParseHandler, typename Unit>
4023typename GeneralParser<ParseHandler, Unit>::PossibleError::Error&
4024GeneralParser<ParseHandler, Unit>::PossibleError::error(ErrorKind kind) {
4025 if (kind == ErrorKind::Expression) {
4026 return exprError_;
4027 }
4028 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"
, 4028); AnnotateMozCrashReason("MOZ_ASSERT" "(" "kind == ErrorKind::Destructuring"
")"); do { MOZ_CrashSequence(__null, 4028); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4029 return destructuringError_;
4030}
4031
4032template <class ParseHandler, typename Unit>
4033void GeneralParser<ParseHandler, Unit>::PossibleError::setResolved(
4034 ErrorKind kind) {
4035 error(kind).state_ = ErrorState::None;
4036}
4037
4038template <class ParseHandler, typename Unit>
4039bool GeneralParser<ParseHandler, Unit>::PossibleError::hasError(
4040 ErrorKind kind) {
4041 return error(kind).state_ == ErrorState::Pending;
4042}
4043
4044template <class ParseHandler, typename Unit>
4045bool GeneralParser<ParseHandler,
4046 Unit>::PossibleError::hasPendingDestructuringError() {
4047 return hasError(ErrorKind::Destructuring);
4048}
4049
4050template <class ParseHandler, typename Unit>
4051void GeneralParser<ParseHandler, Unit>::PossibleError::setPending(
4052 ErrorKind kind, const TokenPos& pos, unsigned errorNumber) {
4053 // Don't overwrite a previously recorded error.
4054 if (hasError(kind)) {
4055 return;
4056 }
4057
4058 // If we report an error later, we'll do it from the position where we set
4059 // the state to pending.
4060 Error& err = error(kind);
4061 err.offset_ = pos.begin;
4062 err.errorNumber_ = errorNumber;
4063 err.state_ = ErrorState::Pending;
4064}
4065
4066template <class ParseHandler, typename Unit>
4067void GeneralParser<ParseHandler, Unit>::PossibleError::
4068 setPendingDestructuringErrorAt(const TokenPos& pos, unsigned errorNumber) {
4069 setPending(ErrorKind::Destructuring, pos, errorNumber);
4070}
4071
4072template <class ParseHandler, typename Unit>
4073void GeneralParser<ParseHandler, Unit>::PossibleError::
4074 setPendingExpressionErrorAt(const TokenPos& pos, unsigned errorNumber) {
4075 setPending(ErrorKind::Expression, pos, errorNumber);
4076}
4077
4078template <class ParseHandler, typename Unit>
4079bool GeneralParser<ParseHandler, Unit>::PossibleError::checkForError(
4080 ErrorKind kind) {
4081 if (!hasError(kind)) {
4082 return true;
4083 }
4084
4085 Error& err = error(kind);
4086 parser_.errorAt(err.offset_, err.errorNumber_);
4087 return false;
4088}
4089
4090template <class ParseHandler, typename Unit>
4091bool GeneralParser<ParseHandler,
4092 Unit>::PossibleError::checkForDestructuringErrorOrWarning() {
4093 // Clear pending expression error, because we're definitely not in an
4094 // expression context.
4095 setResolved(ErrorKind::Expression);
4096
4097 // Report any pending destructuring error.
4098 return checkForError(ErrorKind::Destructuring);
4099}
4100
4101template <class ParseHandler, typename Unit>
4102bool GeneralParser<ParseHandler,
4103 Unit>::PossibleError::checkForExpressionError() {
4104 // Clear pending destructuring error, because we're definitely not
4105 // in a destructuring context.
4106 setResolved(ErrorKind::Destructuring);
4107
4108 // Report any pending expression error.
4109 return checkForError(ErrorKind::Expression);
4110}
4111
4112template <class ParseHandler, typename Unit>
4113void GeneralParser<ParseHandler, Unit>::PossibleError::transferErrorTo(
4114 ErrorKind kind, PossibleError* other) {
4115 if (hasError(kind) && !other->hasError(kind)) {
4116 Error& err = error(kind);
4117 Error& otherErr = other->error(kind);
4118 otherErr.offset_ = err.offset_;
4119 otherErr.errorNumber_ = err.errorNumber_;
4120 otherErr.state_ = err.state_;
4121 }
4122}
4123
4124template <class ParseHandler, typename Unit>
4125void GeneralParser<ParseHandler, Unit>::PossibleError::transferErrorsTo(
4126 PossibleError* other) {
4127 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"
, 4127); AnnotateMozCrashReason("MOZ_ASSERT" "(" "other" ")")
; do { MOZ_CrashSequence(__null, 4127); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4128 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", 4128); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "this != other" ")"); do { MOZ_CrashSequence
(__null, 4128); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
4129 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"
, 4131); AnnotateMozCrashReason("MOZ_ASSERT" "(" "&parser_ == &other->parser_"
") (" "Can't transfer fields to an instance which belongs to a "
"different parser" ")"); do { MOZ_CrashSequence(__null, 4131
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
4130 "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"
, 4131); AnnotateMozCrashReason("MOZ_ASSERT" "(" "&parser_ == &other->parser_"
") (" "Can't transfer fields to an instance which belongs to a "
"different parser" ")"); do { MOZ_CrashSequence(__null, 4131
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
4131 "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"
, 4131); AnnotateMozCrashReason("MOZ_ASSERT" "(" "&parser_ == &other->parser_"
") (" "Can't transfer fields to an instance which belongs to a "
"different parser" ")"); do { MOZ_CrashSequence(__null, 4131
); __attribute__((nomerge)) ::abort(); } while (false); } } while
(false)
;
4132
4133 transferErrorTo(ErrorKind::Destructuring, other);
4134 transferErrorTo(ErrorKind::Expression, other);
4135}
4136
4137template <class ParseHandler, typename Unit>
4138typename ParseHandler::BinaryNodeResult
4139GeneralParser<ParseHandler, Unit>::bindingInitializer(
4140 Node lhs, DeclarationKind kind, YieldHandling yieldHandling) {
4141 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", 4141); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Assign)"
")"); do { MOZ_CrashSequence(__null, 4141); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4142
4143 if (kind == DeclarationKind::FormalParameter) {
4144 pc_->functionBox()->hasParameterExprs = true;
4145 }
4146
4147 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
(); })
;
4148
4149 BinaryNodeType assign =
4150 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(); })
;
4151
4152 return assign;
4153}
4154
4155template <class ParseHandler, typename Unit>
4156typename ParseHandler::NameNodeResult
4157GeneralParser<ParseHandler, Unit>::bindingIdentifier(
4158 DeclarationKind kind, YieldHandling yieldHandling) {
4159 TaggedParserAtomIndex name = bindingIdentifier(yieldHandling);
4160 if (!name) {
4161 return errorResult();
4162 }
4163
4164 NameNodeType binding = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
4165 if (!noteDeclaredName(name, kind, pos())) {
4166 return errorResult();
4167 }
4168
4169 return binding;
4170}
4171
4172template <class ParseHandler, typename Unit>
4173typename ParseHandler::NodeResult
4174GeneralParser<ParseHandler, Unit>::bindingIdentifierOrPattern(
4175 DeclarationKind kind, YieldHandling yieldHandling, TokenKind tt) {
4176 if (tt == TokenKind::LeftBracket) {
4177 return arrayBindingPattern(kind, yieldHandling);
4178 }
4179
4180 if (tt == TokenKind::LeftCurly) {
4181 return objectBindingPattern(kind, yieldHandling);
4182 }
4183
4184 if (!TokenKindIsPossibleIdentifierName(tt)) {
4185 error(JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt));
4186 return errorResult();
4187 }
4188
4189 return bindingIdentifier(kind, yieldHandling);
4190}
4191
4192template <class ParseHandler, typename Unit>
4193typename ParseHandler::ListNodeResult
4194GeneralParser<ParseHandler, Unit>::objectBindingPattern(
4195 DeclarationKind kind, YieldHandling yieldHandling) {
4196 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", 4196); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)"
")"); do { MOZ_CrashSequence(__null, 4196); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4197
4198 AutoCheckRecursionLimit recursion(this->fc_);
4199 if (!recursion.check(this->fc_)) {
4200 return errorResult();
4201 }
4202
4203 uint32_t begin = pos().begin;
4204 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(); })
;
4205
4206 Maybe<DeclarationKind> declKind = Some(kind);
4207 TaggedParserAtomIndex propAtom;
4208 for (;;) {
4209 TokenKind tt;
4210 if (!tokenStream.peekToken(&tt)) {
4211 return errorResult();
4212 }
4213 if (tt == TokenKind::RightCurly) {
4214 break;
4215 }
4216
4217 if (tt == TokenKind::TripleDot) {
4218 tokenStream.consumeKnownToken(TokenKind::TripleDot);
4219 uint32_t begin = pos().begin;
4220
4221 TokenKind tt;
4222 if (!tokenStream.getToken(&tt)) {
4223 return errorResult();
4224 }
4225
4226 if (!TokenKindIsPossibleIdentifierName(tt)) {
4227 error(JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt));
4228 return errorResult();
4229 }
4230
4231 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(); })
;
4232
4233 if (!handler_.addSpreadProperty(literal, begin, inner)) {
4234 return errorResult();
4235 }
4236 } else {
4237 TokenPos namePos = anyChars.nextToken().pos;
4238
4239 PropertyType propType;
4240 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(); })
4241 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(); })
4242 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(); })
;
4243
4244 if (propType == PropertyType::Normal) {
4245 // Handle e.g., |var {p: x} = o| and |var {p: x=0} = o|.
4246
4247 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
4248 return errorResult();
4249 }
4250
4251 Node binding =
4252 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(); })
;
4253
4254 bool hasInitializer;
4255 if (!tokenStream.matchToken(&hasInitializer, TokenKind::Assign,
4256 TokenStream::SlashIsRegExp)) {
4257 return errorResult();
4258 }
4259
4260 Node bindingExpr;
4261 if (hasInitializer) {
4262 bindingExpr =
4263 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(); })
;
4264 } else {
4265 bindingExpr = binding;
4266 }
4267
4268 if (!handler_.addPropertyDefinition(literal, propName, bindingExpr)) {
4269 return errorResult();
4270 }
4271 } else if (propType == PropertyType::Shorthand) {
4272 // Handle e.g., |var {x, y} = o| as destructuring shorthand
4273 // for |var {x: x, y: y} = o|.
4274 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", 4274); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(tt)" ")"
); do { MOZ_CrashSequence(__null, 4274); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4275
4276 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(); })
;
4277
4278 if (!handler_.addShorthand(literal, handler_.asNameNode(propName),
4279 binding)) {
4280 return errorResult();
4281 }
4282 } else if (propType == PropertyType::CoverInitializedName) {
4283 // Handle e.g., |var {x=1, y=2} = o| as destructuring
4284 // shorthand with default values.
4285 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", 4285); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(tt)" ")"
); do { MOZ_CrashSequence(__null, 4285); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4286
4287 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(); })
;
4288
4289 tokenStream.consumeKnownToken(TokenKind::Assign);
4290
4291 BinaryNodeType bindingExpr =
4292 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(); })
;
4293
4294 if (!handler_.addPropertyDefinition(literal, propName, bindingExpr)) {
4295 return errorResult();
4296 }
4297 } else {
4298 errorAt(namePos.begin, JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt));
4299 return errorResult();
4300 }
4301 }
4302
4303 bool matched;
4304 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
4305 TokenStream::SlashIsInvalid)) {
4306 return errorResult();
4307 }
4308 if (!matched) {
4309 break;
4310 }
4311 if (tt == TokenKind::TripleDot) {
4312 error(JSMSG_REST_WITH_COMMA);
4313 return errorResult();
4314 }
4315 }
4316
4317 if (!mustMatchToken(TokenKind::RightCurly, [this, begin](TokenKind actual) {
4318 this->reportMissingClosing(JSMSG_CURLY_AFTER_LIST, JSMSG_CURLY_OPENED,
4319 begin);
4320 })) {
4321 return errorResult();
4322 }
4323
4324 handler_.setEndPosition(literal, pos().end);
4325 return literal;
4326}
4327
4328template <class ParseHandler, typename Unit>
4329typename ParseHandler::ListNodeResult
4330GeneralParser<ParseHandler, Unit>::arrayBindingPattern(
4331 DeclarationKind kind, YieldHandling yieldHandling) {
4332 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", 4332); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket)"
")"); do { MOZ_CrashSequence(__null, 4332); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4333
4334 AutoCheckRecursionLimit recursion(this->fc_);
4335 if (!recursion.check(this->fc_)) {
4336 return errorResult();
4337 }
4338
4339 uint32_t begin = pos().begin;
4340 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(); })
;
4341
4342 uint32_t index = 0;
4343 for (;; index++) {
4344 if (index >= NativeObject::MAX_DENSE_ELEMENTS_COUNT) {
4345 error(JSMSG_ARRAY_INIT_TOO_BIG);
4346 return errorResult();
4347 }
4348
4349 TokenKind tt;
4350 if (!tokenStream.getToken(&tt)) {
4351 return errorResult();
4352 }
4353
4354 if (tt == TokenKind::RightBracket) {
4355 anyChars.ungetToken();
4356 break;
4357 }
4358
4359 if (tt == TokenKind::Comma) {
4360 if (!handler_.addElision(literal, pos())) {
4361 return errorResult();
4362 }
4363 } else if (tt == TokenKind::TripleDot) {
4364 uint32_t begin = pos().begin;
4365
4366 TokenKind tt;
4367 if (!tokenStream.getToken(&tt)) {
4368 return errorResult();
4369 }
4370
4371 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(); })
;
4372
4373 if (!handler_.addSpreadElement(literal, begin, inner)) {
4374 return errorResult();
4375 }
4376 } else {
4377 Node binding =
4378 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(); })
;
4379
4380 bool hasInitializer;
4381 if (!tokenStream.matchToken(&hasInitializer, TokenKind::Assign,
4382 TokenStream::SlashIsRegExp)) {
4383 return errorResult();
4384 }
4385
4386 Node element;
4387 if (hasInitializer) {
4388 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(); })
;
4389 } else {
4390 element = binding;
4391 }
4392
4393 handler_.addArrayElement(literal, element);
4394 }
4395
4396 if (tt != TokenKind::Comma) {
4397 // If we didn't already match TokenKind::Comma in above case.
4398 bool matched;
4399 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
4400 TokenStream::SlashIsRegExp)) {
4401 return errorResult();
4402 }
4403 if (!matched) {
4404 break;
4405 }
4406
4407 if (tt == TokenKind::TripleDot) {
4408 error(JSMSG_REST_WITH_COMMA);
4409 return errorResult();
4410 }
4411 }
4412 }
4413
4414 if (!mustMatchToken(TokenKind::RightBracket, [this, begin](TokenKind actual) {
4415 this->reportMissingClosing(JSMSG_BRACKET_AFTER_LIST,
4416 JSMSG_BRACKET_OPENED, begin);
4417 })) {
4418 return errorResult();
4419 }
4420
4421 handler_.setEndPosition(literal, pos().end);
4422 return literal;
4423}
4424
4425template <class ParseHandler, typename Unit>
4426typename ParseHandler::NodeResult
4427GeneralParser<ParseHandler, Unit>::destructuringDeclaration(
4428 DeclarationKind kind, YieldHandling yieldHandling, TokenKind tt) {
4429 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"
, 4429); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)"
")"); do { MOZ_CrashSequence(__null, 4429); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4430 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", 4430); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly"
")"); do { MOZ_CrashSequence(__null, 4430); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4431
4432 if (tt == TokenKind::LeftBracket) {
4433 return arrayBindingPattern(kind, yieldHandling);
4434 }
4435 return objectBindingPattern(kind, yieldHandling);
4436}
4437
4438template <class ParseHandler, typename Unit>
4439typename ParseHandler::NodeResult
4440GeneralParser<ParseHandler, Unit>::destructuringDeclarationWithoutYieldOrAwait(
4441 DeclarationKind kind, YieldHandling yieldHandling, TokenKind tt) {
4442 uint32_t startYieldOffset = pc_->lastYieldOffset;
4443 uint32_t startAwaitOffset = pc_->lastAwaitOffset;
4444
4445 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(); })
;
4446
4447 if (pc_->lastYieldOffset != startYieldOffset) {
4448 errorAt(pc_->lastYieldOffset, JSMSG_YIELD_IN_PARAMETER);
4449 return errorResult();
4450 }
4451 if (pc_->lastAwaitOffset != startAwaitOffset) {
4452 errorAt(pc_->lastAwaitOffset, JSMSG_AWAIT_IN_PARAMETER);
4453 return errorResult();
4454 }
4455 return res;
4456}
4457
4458template <class ParseHandler, typename Unit>
4459typename ParseHandler::LexicalScopeNodeResult
4460GeneralParser<ParseHandler, Unit>::blockStatement(YieldHandling yieldHandling,
4461 unsigned errorNumber) {
4462 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", 4462); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)"
")"); do { MOZ_CrashSequence(__null, 4462); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4463 uint32_t openedPos = pos().begin;
4464
4465 ParseContext::Statement stmt(pc_, StatementKind::Block);
4466 ParseContext::Scope scope(this);
4467 if (!scope.init(pc_)) {
4468 return errorResult();
4469 }
4470
4471 ListNodeType list = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
4472
4473 if (!mustMatchToken(TokenKind::RightCurly, [this, errorNumber,
4474 openedPos](TokenKind actual) {
4475 this->reportMissingClosing(errorNumber, JSMSG_CURLY_OPENED, openedPos);
4476 })) {
4477 return errorResult();
4478 }
4479
4480 return finishLexicalScope(scope, list);
4481}
4482
4483template <class ParseHandler, typename Unit>
4484typename ParseHandler::NodeResult
4485GeneralParser<ParseHandler, Unit>::expressionAfterForInOrOf(
4486 ParseNodeKind forHeadKind, YieldHandling yieldHandling) {
4487 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", 4488); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf"
")"); do { MOZ_CrashSequence(__null, 4488); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4488 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", 4488); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "forHeadKind == ParseNodeKind::ForIn || forHeadKind == ParseNodeKind::ForOf"
")"); do { MOZ_CrashSequence(__null, 4488); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4489 if (forHeadKind == ParseNodeKind::ForOf) {
4490 return assignExpr(InAllowed, yieldHandling, TripledotProhibited);
4491 }
4492
4493 return expr(InAllowed, yieldHandling, TripledotProhibited);
4494}
4495
4496template <class ParseHandler, typename Unit>
4497typename ParseHandler::NodeResult
4498GeneralParser<ParseHandler, Unit>::declarationPattern(
4499 DeclarationKind declKind, TokenKind tt, bool initialDeclaration,
4500 YieldHandling yieldHandling, ParseNodeKind* forHeadKind,
4501 Node* forInOrOfExpression) {
4502 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", 4503); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly)"
")"); do { MOZ_CrashSequence(__null, 4503); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4503 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", 4503); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket) || anyChars.isCurrentTokenType(TokenKind::LeftCurly)"
")"); do { MOZ_CrashSequence(__null, 4503); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4504
4505 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
(); })
;
4506
4507 if (initialDeclaration && forHeadKind) {
4508 bool isForIn, isForOf;
4509 if (!matchInOrOf(&isForIn, &isForOf)) {
4510 return errorResult();
4511 }
4512
4513 if (isForIn) {
4514 *forHeadKind = ParseNodeKind::ForIn;
4515 } else if (isForOf) {
4516 *forHeadKind = ParseNodeKind::ForOf;
4517 } else {
4518 *forHeadKind = ParseNodeKind::ForHead;
4519 }
4520
4521 if (*forHeadKind != ParseNodeKind::ForHead) {
4522 *forInOrOfExpression =
4523 MOZ_TRY(expressionAfterForInOrOf(*forHeadKind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(expressionAfterForInOrOf(*forHeadKind, yieldHandling)); if (
(__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return
mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap
(); })
;
4524
4525 return pattern;
4526 }
4527 }
4528
4529 if (!mustMatchToken(TokenKind::Assign, JSMSG_BAD_DESTRUCT_DECL)) {
4530 return errorResult();
4531 }
4532
4533 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(); })
4534 yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(forHeadKind ? InProhibited : InAllowed, yieldHandling
, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
4535
4536 return handler_.newAssignment(ParseNodeKind::AssignExpr, pattern, init);
4537}
4538
4539template <class ParseHandler, typename Unit>
4540typename ParseHandler::AssignmentNodeResult
4541GeneralParser<ParseHandler, Unit>::initializerInNameDeclaration(
4542 NameNodeType binding, DeclarationKind declKind, bool initialDeclaration,
4543 YieldHandling yieldHandling, ParseNodeKind* forHeadKind,
4544 Node* forInOrOfExpression) {
4545 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", 4545); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Assign)"
")"); do { MOZ_CrashSequence(__null, 4545); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4546
4547 uint32_t initializerOffset;
4548 if (!tokenStream.peekOffset(&initializerOffset, TokenStream::SlashIsRegExp)) {
4549 return errorResult();
4550 }
4551
4552 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(); })
4553 yieldHandling, TripledotProhibited))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(forHeadKind ? InProhibited : InAllowed, yieldHandling
, TripledotProhibited)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
4554
4555 if (forHeadKind && initialDeclaration) {
4556 bool isForIn, isForOf;
4557 if (!matchInOrOf(&isForIn, &isForOf)) {
4558 return errorResult();
4559 }
4560
4561 // An initialized declaration can't appear in a for-of:
4562 //
4563 // for (var/let/const x = ... of ...); // BAD
4564 if (isForOf) {
4565 errorAt(initializerOffset, JSMSG_OF_AFTER_FOR_LOOP_DECL);
4566 return errorResult();
4567 }
4568
4569 if (isForIn) {
4570 // Lexical declarations in for-in loops can't be initialized:
4571 //
4572 // for (let/const x = ... in ...); // BAD
4573 if (DeclarationKindIsLexical(declKind)) {
4574 errorAt(initializerOffset, JSMSG_IN_AFTER_LEXICAL_FOR_DECL);
4575 return errorResult();
4576 }
4577
4578 // This leaves only initialized for-in |var| declarations. ES6
4579 // forbids these; later ES un-forbids in non-strict mode code.
4580 *forHeadKind = ParseNodeKind::ForIn;
4581 if (!strictModeErrorAt(initializerOffset,
4582 JSMSG_INVALID_FOR_IN_DECL_WITH_INIT)) {
4583 return errorResult();
4584 }
4585
4586 *forInOrOfExpression = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(expressionAfterForInOrOf(ParseNodeKind::ForIn, yieldHandling
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
4587 expressionAfterForInOrOf(ParseNodeKind::ForIn, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(expressionAfterForInOrOf(ParseNodeKind::ForIn, yieldHandling
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
4588 } else {
4589 *forHeadKind = ParseNodeKind::ForHead;
4590 }
4591 }
4592
4593 return handler_.finishInitializerAssignment(binding, initializer);
4594}
4595
4596template <class ParseHandler, typename Unit>
4597typename ParseHandler::NodeResult
4598GeneralParser<ParseHandler, Unit>::declarationName(DeclarationKind declKind,
4599 TokenKind tt,
4600 bool initialDeclaration,
4601 YieldHandling yieldHandling,
4602 ParseNodeKind* forHeadKind,
4603 Node* forInOrOfExpression) {
4604 // Anything other than possible identifier is an error.
4605 if (!TokenKindIsPossibleIdentifier(tt)) {
4606 error(JSMSG_NO_VARIABLE_NAME, TokenKindToDesc(tt));
4607 return errorResult();
4608 }
4609
4610 TaggedParserAtomIndex name = bindingIdentifier(yieldHandling);
4611 if (!name) {
4612 return errorResult();
4613 }
4614
4615 NameNodeType binding = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
4616
4617 TokenPos namePos = pos();
4618
4619 // The '=' context after a variable name in a declaration is an opportunity
4620 // for ASI, and thus for the next token to start an ExpressionStatement:
4621 //
4622 // var foo // VariableDeclaration
4623 // /bar/g; // ExpressionStatement
4624 //
4625 // Therefore get the token here with SlashIsRegExp.
4626 bool matched;
4627 if (!tokenStream.matchToken(&matched, TokenKind::Assign,
4628 TokenStream::SlashIsRegExp)) {
4629 return errorResult();
4630 }
4631
4632 Node declaration;
4633 if (matched) {
4634 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(); })
4635 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(); })
4636 forInOrOfExpression))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(initializerInNameDeclaration( binding, declKind, initialDeclaration
, yieldHandling, forHeadKind, forInOrOfExpression)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
4637 } else {
4638 declaration = binding;
4639
4640 if (initialDeclaration && forHeadKind) {
4641 bool isForIn, isForOf;
4642 if (!matchInOrOf(&isForIn, &isForOf)) {
4643 return errorResult();
4644 }
4645
4646 if (isForIn) {
4647 *forHeadKind = ParseNodeKind::ForIn;
4648 if (declKind == DeclarationKind::Using ||
4649 declKind == DeclarationKind::AwaitUsing) {
4650 errorAt(namePos.begin, JSMSG_NO_IN_WITH_USING);
4651 return errorResult();
4652 }
4653 } else if (isForOf) {
4654 *forHeadKind = ParseNodeKind::ForOf;
4655 } else {
4656 *forHeadKind = ParseNodeKind::ForHead;
4657 }
4658 }
4659
4660 if (forHeadKind && *forHeadKind != ParseNodeKind::ForHead) {
4661 *forInOrOfExpression =
4662 MOZ_TRY(expressionAfterForInOrOf(*forHeadKind, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(expressionAfterForInOrOf(*forHeadKind, yieldHandling)); if (
(__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))) { return
mozTryVarTempResult.propagateErr(); } mozTryVarTempResult.unwrap
(); })
;
4663 } else {
4664 // Normal const declarations, and const declarations in for(;;)
4665 // heads, must be initialized.
4666 if (declKind == DeclarationKind::Const) {
4667 errorAt(namePos.begin, JSMSG_BAD_CONST_DECL);
4668 return errorResult();
4669 }
4670 if (declKind == DeclarationKind::Using ||
4671 declKind == DeclarationKind::AwaitUsing) {
4672 errorAt(namePos.begin, JSMSG_BAD_USING_DECL);
4673 return errorResult();
4674 }
4675 }
4676 }
4677
4678 // Note the declared name after knowing whether or not we are in a for-of
4679 // loop, due to special early error semantics in Annex B.3.5.
4680 if (!noteDeclaredName(name, declKind, namePos)) {
4681 return errorResult();
4682 }
4683
4684 return declaration;
4685}
4686
4687template <class ParseHandler, typename Unit>
4688typename ParseHandler::DeclarationListNodeResult
4689GeneralParser<ParseHandler, Unit>::declarationList(
4690 YieldHandling yieldHandling, ParseNodeKind kind,
4691 ParseNodeKind* forHeadKind /* = nullptr */,
4692 Node* forInOrOfExpression /* = nullptr */) {
4693 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", 4696); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl"
")"); do { MOZ_CrashSequence(__null, 4696); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4694 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", 4696); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl"
")"); do { MOZ_CrashSequence(__null, 4696); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4695 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", 4696); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl"
")"); do { MOZ_CrashSequence(__null, 4696); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4696 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", 4696); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == ParseNodeKind::VarStmt || kind == ParseNodeKind::LetDecl || kind == ParseNodeKind::ConstDecl || kind == ParseNodeKind::UsingDecl || kind == ParseNodeKind::AwaitUsingDecl"
")"); do { MOZ_CrashSequence(__null, 4696); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4697
4698 DeclarationKind declKind;
4699 switch (kind) {
4700 case ParseNodeKind::VarStmt:
4701 declKind = DeclarationKind::Var;
4702 break;
4703 case ParseNodeKind::ConstDecl:
4704 declKind = DeclarationKind::Const;
4705 break;
4706 case ParseNodeKind::LetDecl:
4707 declKind = DeclarationKind::Let;
4708 break;
4709 case ParseNodeKind::UsingDecl:
4710 declKind = DeclarationKind::Using;
4711 break;
4712 case ParseNodeKind::AwaitUsingDecl:
4713 declKind = DeclarationKind::AwaitUsing;
4714 break;
4715 default:
4716 MOZ_CRASH("Unknown declaration kind")do { do { } while (false); MOZ_ReportCrash("" "Unknown declaration kind"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 4716); AnnotateMozCrashReason
("MOZ_CRASH(" "Unknown declaration kind" ")"); do { MOZ_CrashSequence
(__null, 4716); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
4717 }
4718
4719 DeclarationListNodeType decl =
4720 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(); })
;
4721
4722 bool moreDeclarations;
4723 bool initialDeclaration = true;
4724 do {
4725 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"
, 4726); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*forHeadKind == ParseNodeKind::ForHead"
")"); do { MOZ_CrashSequence(__null, 4726); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
4726 *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"
, 4726); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*forHeadKind == ParseNodeKind::ForHead"
")"); do { MOZ_CrashSequence(__null, 4726); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
4727
4728 TokenKind tt;
4729 if (!tokenStream.getToken(&tt)) {
4730 return errorResult();
4731 }
4732
4733 Node binding;
4734 if (tt == TokenKind::LeftBracket || tt == TokenKind::LeftCurly) {
4735 if (declKind == DeclarationKind::Using ||
4736 declKind == DeclarationKind::AwaitUsing) {
4737 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", 4737); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!initialDeclaration" ")"); do { MOZ_CrashSequence
(__null, 4737); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
4738 error(JSMSG_NO_DESTRUCT_IN_USING);
4739 return errorResult();
4740 }
4741 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(); })
4742 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(); })
4743 forInOrOfExpression))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(declarationPattern(declKind, tt, initialDeclaration, yieldHandling
, forHeadKind, forInOrOfExpression)); if ((__builtin_expect(!
!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
4744 } else {
4745 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(); })
4746 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(); })
4747 forInOrOfExpression))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(declarationName(declKind, tt, initialDeclaration, yieldHandling
, forHeadKind, forInOrOfExpression)); if ((__builtin_expect(!
!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
4748 }
4749
4750 handler_.addList(decl, binding);
4751
4752 // If we have a for-in/of loop, the above call matches the entirety
4753 // of the loop head (up to the closing parenthesis).
4754 if (forHeadKind && *forHeadKind != ParseNodeKind::ForHead) {
4755 break;
4756 }
4757
4758 initialDeclaration = false;
4759
4760 if (!tokenStream.matchToken(&moreDeclarations, TokenKind::Comma,
4761 TokenStream::SlashIsRegExp)) {
4762 return errorResult();
4763 }
4764 } while (moreDeclarations);
4765
4766 return decl;
4767}
4768
4769template <class ParseHandler, typename Unit>
4770typename ParseHandler::DeclarationListNodeResult
4771GeneralParser<ParseHandler, Unit>::lexicalDeclaration(
4772 YieldHandling yieldHandling, DeclarationKind kind) {
4773 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", 4775); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing"
")"); do { MOZ_CrashSequence(__null, 4775); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4774 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", 4775); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing"
")"); do { MOZ_CrashSequence(__null, 4775); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
4775 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", 4775); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let || kind == DeclarationKind::Using || kind == DeclarationKind::AwaitUsing"
")"); do { MOZ_CrashSequence(__null, 4775); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4776
4777 if (options().selfHostingMode) {
4778 error(JSMSG_SELFHOSTED_LEXICAL);
4779 return errorResult();
4780 }
4781
4782 /*
4783 * Parse body-level lets without a new block object. ES6 specs
4784 * that an execution environment's initial lexical environment
4785 * is the VariableEnvironment, i.e., body-level lets are in
4786 * the same environment record as vars.
4787 *
4788 * However, they cannot be parsed exactly as vars, as ES6
4789 * requires that uninitialized lets throw ReferenceError on use.
4790 *
4791 * See 8.1.1.1.6 and the note in 13.2.1.
4792 */
4793 ParseNodeKind pnk;
4794 switch (kind) {
4795 case DeclarationKind::Const:
4796 pnk = ParseNodeKind::ConstDecl;
4797 break;
4798 case DeclarationKind::Using:
4799 pnk = ParseNodeKind::UsingDecl;
4800 break;
4801 case DeclarationKind::AwaitUsing:
4802 pnk = ParseNodeKind::AwaitUsingDecl;
4803 break;
4804 case DeclarationKind::Let:
4805 pnk = ParseNodeKind::LetDecl;
4806 break;
4807 default:
4808 MOZ_CRASH("unexpected node kind")do { do { } while (false); MOZ_ReportCrash("" "unexpected node kind"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 4808); AnnotateMozCrashReason
("MOZ_CRASH(" "unexpected node kind" ")"); do { MOZ_CrashSequence
(__null, 4808); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
4809 }
4810 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(); })
;
4811 if (!matchOrInsertSemicolon()) {
4812 return errorResult();
4813 }
4814
4815 return decl;
4816}
4817
4818template <class ParseHandler, typename Unit>
4819typename ParseHandler::NameNodeResult
4820GeneralParser<ParseHandler, Unit>::moduleExportName() {
4821 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", 4821); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::String"
")"); do { MOZ_CrashSequence(__null, 4821); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4822 TaggedParserAtomIndex name = anyChars.currentToken().atom();
4823 if (!this->parserAtoms().isModuleExportName(name)) {
4824 error(JSMSG_UNPAIRED_SURROGATE_EXPORT);
4825 return errorResult();
4826 }
4827 return handler_.newStringLiteral(name, pos());
4828}
4829
4830template <class ParseHandler, typename Unit>
4831bool GeneralParser<ParseHandler, Unit>::withClause(ListNodeType attributesSet) {
4832 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", 4832); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::With)"
")"); do { MOZ_CrashSequence(__null, 4832); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4833
4834 if (!abortIfSyntaxParser()) {
4835 return false;
4836 }
4837
4838 // https://tc39.es/ecma262/#prod-WithClause
4839 // WithClause:
4840 // with { }
4841 // with { WithEntries ,opt }
4842 if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_AFTER_WITH)) {
4843 return false;
4844 }
4845
4846 js::HashSet<TaggedParserAtomIndex, TaggedParserAtomIndexHasher,
4847 js::SystemAllocPolicy>
4848 usedAttributeKeys;
4849
4850 bool empty;
4851 if (!tokenStream.matchToken(&empty, TokenKind::RightCurly)) {
4852 return false;
4853 }
4854 if (empty) {
4855 // WithClause: with { }
4856 return true;
4857 }
4858
4859 // WithClause: with { WithEntries ,opt }
4860 // WithEntries:
4861 // AttributeKey : StringLiteral
4862 // AttributeKey : StringLiteral , WithEntries
4863 for (;;) {
4864 TokenKind token;
4865 if (!tokenStream.getToken(&token)) {
4866 return false;
4867 }
4868
4869 TaggedParserAtomIndex keyName;
4870 if (TokenKindIsPossibleIdentifierName(token)) {
4871 keyName = anyChars.currentName();
4872 } else if (token == TokenKind::String) {
4873 keyName = anyChars.currentToken().atom();
4874 } else {
4875 error(JSMSG_ATTRIBUTE_KEY_EXPECTED);
4876 return false;
4877 }
4878
4879 auto p = usedAttributeKeys.lookupForAdd(keyName);
4880 if (p) {
4881 UniqueChars str = this->parserAtoms().toPrintableString(keyName);
4882 if (!str) {
4883 ReportOutOfMemory(this->fc_);
4884 return false;
4885 }
4886 error(JSMSG_DUPLICATE_ATTRIBUTE_KEY, str.get());
4887 return false;
4888 }
4889 if (!usedAttributeKeys.add(p, keyName)) {
4890 ReportOutOfMemory(this->fc_);
4891 return false;
4892 }
4893
4894 NameNodeType keyNode;
4895 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)
;
4896
4897 if (!mustMatchToken(TokenKind::Colon, JSMSG_COLON_AFTER_ATTRIBUTE_KEY)) {
4898 return false;
4899 }
4900 if (!mustMatchToken(TokenKind::String, JSMSG_WITH_CLAUSE_STRING_LITERAL)) {
4901 return false;
4902 }
4903
4904 NameNodeType valueNode;
4905 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)
;
4906
4907 BinaryNodeType importAttributeNode;
4908 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)
4909 handler_.newImportAttribute(keyNode, valueNode),do { auto parserTryVarTempResult_ = (handler_.newImportAttribute
(keyNode, valueNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (importAttributeNode) = parserTryVarTempResult_
.unwrap(); } while (0)
4910 false)do { auto parserTryVarTempResult_ = (handler_.newImportAttribute
(keyNode, valueNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (importAttributeNode) = parserTryVarTempResult_
.unwrap(); } while (0)
;
4911 handler_.addList(attributesSet, importAttributeNode);
4912
4913 bool hasComma;
4914 if (!tokenStream.matchToken(&hasComma, TokenKind::Comma)) {
4915 return false;
4916 }
4917 if (!hasComma) {
4918 // No comma: end of WithEntries, expect closing '}'.
4919 break;
4920 }
4921 // The comma is either the optional trailing ',' in WithClause
4922 // (with { WithEntries ,opt }), or the ',' separator in WithEntries
4923 // (AttributeKey : StringLiteral , WithEntries).
4924 TokenKind next;
4925 if (!tokenStream.peekToken(&next)) {
4926 return false;
4927 }
4928 if (next == TokenKind::RightCurly) {
4929 // Optional trailing comma in WithClause — '}' consumed below.
4930 break;
4931 }
4932 // Comma was the WithEntries separator — another WithEntries must follow.
4933 }
4934
4935 return mustMatchToken(TokenKind::RightCurly,
4936 JSMSG_RC_AFTER_IMPORT_ATTRIBUTE_LIST);
4937}
4938
4939template <class ParseHandler, typename Unit>
4940bool GeneralParser<ParseHandler, Unit>::namedImports(
4941 ListNodeType importSpecSet) {
4942 if (!abortIfSyntaxParser()) {
4943 return false;
4944 }
4945
4946 while (true) {
4947 // Handle the forms |import {} from 'a'| and
4948 // |import { ..., } from 'a'| (where ... is non empty), by
4949 // escaping the loop early if the next token is }.
4950 TokenKind tt;
4951 if (!tokenStream.getToken(&tt)) {
4952 return false;
4953 }
4954
4955 if (tt == TokenKind::RightCurly) {
4956 break;
4957 }
4958
4959 TaggedParserAtomIndex importName;
4960 NameNodeType importNameNode = null();
4961 if (TokenKindIsPossibleIdentifierName(tt)) {
4962 importName = anyChars.currentName();
4963 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)
;
4964 } else if (tt == TokenKind::String) {
4965 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)
;
4966 } else {
4967 error(JSMSG_NO_IMPORT_NAME);
4968 return false;
4969 }
4970
4971 bool matched;
4972 if (!tokenStream.matchToken(&matched, TokenKind::As)) {
4973 return false;
4974 }
4975
4976 if (matched) {
4977 TokenKind afterAs;
4978 if (!tokenStream.getToken(&afterAs)) {
4979 return false;
4980 }
4981
4982 if (!TokenKindIsPossibleIdentifierName(afterAs)) {
4983 error(JSMSG_NO_BINDING_NAME);
4984 return false;
4985 }
4986 } else {
4987 // String export names can't refer to local bindings.
4988 if (tt == TokenKind::String) {
4989 error(JSMSG_AS_AFTER_STRING);
4990 return false;
4991 }
4992
4993 // Keywords cannot be bound to themselves, so an import name
4994 // that is a keyword is a syntax error if it is not followed
4995 // by the keyword 'as'.
4996 // See the ImportSpecifier production in ES6 section 15.2.2.
4997 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"
, 4997); AnnotateMozCrashReason("MOZ_ASSERT" "(" "importName"
")"); do { MOZ_CrashSequence(__null, 4997); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
4998 if (IsKeyword(importName)) {
4999 error(JSMSG_AS_AFTER_RESERVED_WORD, ReservedWordToCharZ(importName));
5000 return false;
5001 }
5002 }
5003
5004 TaggedParserAtomIndex bindingAtom = importedBinding();
5005 if (!bindingAtom) {
5006 return false;
5007 }
5008
5009 NameNodeType bindingName;
5010 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)
;
5011 if (!noteDeclaredName(bindingAtom, DeclarationKind::Import, pos())) {
5012 return false;
5013 }
5014
5015 BinaryNodeType importSpec;
5016 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)
5017 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)
;
5018
5019 handler_.addList(importSpecSet, importSpec);
5020
5021 TokenKind next;
5022 if (!tokenStream.getToken(&next)) {
5023 return false;
5024 }
5025
5026 if (next == TokenKind::RightCurly) {
5027 break;
5028 }
5029
5030 if (next != TokenKind::Comma) {
5031 error(JSMSG_RC_AFTER_IMPORT_SPEC_LIST);
5032 return false;
5033 }
5034 }
5035
5036 return true;
5037}
5038
5039template <class ParseHandler, typename Unit>
5040bool GeneralParser<ParseHandler, Unit>::namespaceImport(
5041 ListNodeType importSpecSet) {
5042 if (!abortIfSyntaxParser()) {
5043 return false;
5044 }
5045
5046 if (!mustMatchToken(TokenKind::As, JSMSG_AS_AFTER_IMPORT_STAR)) {
5047 return false;
5048 }
5049 uint32_t begin = pos().begin;
5050
5051 if (!mustMatchToken(TokenKindIsPossibleIdentifierName,
5052 JSMSG_NO_BINDING_NAME)) {
5053 return false;
5054 }
5055
5056 // Namespace imports are not indirect bindings but lexical
5057 // definitions that hold a module namespace object. They are treated
5058 // as const variables which are initialized during the
5059 // ModuleInstantiate step.
5060 TaggedParserAtomIndex bindingName = importedBinding();
5061 if (!bindingName) {
5062 return false;
5063 }
5064 NameNodeType bindingNameNode;
5065 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)
;
5066 if (!noteDeclaredName(bindingName, DeclarationKind::Const, pos())) {
5067 return false;
5068 }
5069
5070 // The namespace import name is currently required to live on the
5071 // environment.
5072 pc_->varScope().lookupDeclaredName(bindingName)->value()->setClosedOver();
5073
5074 UnaryNodeType importSpec;
5075 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)
5076 handler_.newImportNamespaceSpec(begin, bindingNameNode),do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec
(begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (importSpec) = parserTryVarTempResult_
.unwrap(); } while (0)
5077 false)do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec
(begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (importSpec) = parserTryVarTempResult_
.unwrap(); } while (0)
;
5078
5079 handler_.addList(importSpecSet, importSpec);
5080
5081 return true;
5082}
5083
5084template <class ParseHandler, typename Unit>
5085typename ParseHandler::BinaryNodeResult
5086GeneralParser<ParseHandler, Unit>::importDeclaration() {
5087 if (!abortIfSyntaxParser()) {
5088 return errorResult();
5089 }
5090
5091 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", 5091); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Import)"
")"); do { MOZ_CrashSequence(__null, 5091); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5092
5093 if (!pc_->atModuleLevel()) {
5094 error(JSMSG_IMPORT_DECL_AT_TOP_LEVEL);
5095 return errorResult();
5096 }
5097
5098 uint32_t begin = pos().begin;
5099 TokenKind tt;
5100 if (!tokenStream.getToken(&tt)) {
5101 return errorResult();
5102 }
5103
5104 TokenKind next = TokenKind::Eof;
5105 if (options().deferImportEval() && tt == TokenKind::Defer &&
5106 !tokenStream.peekToken(&next)) {
5107 return errorResult();
5108 }
5109
5110 ListNodeType importSpecSet =
5111 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
(); })
;
5112
5113 ImportPhase phase = ImportPhase::Evaluation;
5114 NameNodeType importSourceBinding = null();
5115 if (tt == TokenKind::String) {
5116 // import ModuleSpecifier;
5117 // Handle the form |import 'a'| by leaving the list empty. This is
5118 // equivalent to |import {} from 'a'|.
5119 handler_.setEndPosition(importSpecSet, pos().begin);
5120 } else if (options().deferImportEval() && tt == TokenKind::Defer &&
5121 next == TokenKind::Mul) {
5122 // import defer NameSpaceImport FromClause;
5123 phase = ImportPhase::Deferred;
5124 tokenStream.consumeKnownToken(TokenKind::Mul);
5125
5126 // Parse: as BindingIdentifier
5127 if (!mustMatchToken(TokenKind::As, JSMSG_AS_AFTER_IMPORT_STAR)) {
5128 return errorResult();
5129 }
5130 if (!mustMatchToken(TokenKindIsPossibleIdentifierName,
5131 JSMSG_NO_BINDING_NAME)) {
5132 return errorResult();
5133 }
5134
5135 uint32_t begin = pos().begin;
5136 TaggedParserAtomIndex bindingAtom = importedBinding();
5137 if (!bindingAtom) {
5138 return errorResult();
5139 }
5140
5141 NameNodeType bindingNameNode;
5142 MOZ_TRY_VAR_OR_RETURN(bindingNameNode, newName(bindingAtom), errorResult())do { auto parserTryVarTempResult_ = (newName(bindingAtom)); if
((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0)))
{ return (errorResult()); } (bindingNameNode) = parserTryVarTempResult_
.unwrap(); } while (0)
;
5143
5144 // Deferred namespace imports are not indirect bindings but lexical
5145 // definitions that hold a module namespace object, like regular namespace
5146 // imports. They are treated as const variables initialized at module link.
5147 if (!noteDeclaredName(bindingAtom, DeclarationKind::Const, pos())) {
5148 return errorResult();
5149 }
5150
5151 pc_->varScope().lookupDeclaredName(bindingAtom)->value()->setClosedOver();
5152
5153 // Add to importSpecSet like namespaceImport does
5154 UnaryNodeType importSpec;
5155 MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec
(begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (errorResult()); } (importSpec) = parserTryVarTempResult_
.unwrap(); } while (0)
5156 importSpec, handler_.newImportNamespaceSpec(begin, bindingNameNode),do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec
(begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (errorResult()); } (importSpec) = parserTryVarTempResult_
.unwrap(); } while (0)
5157 errorResult())do { auto parserTryVarTempResult_ = (handler_.newImportNamespaceSpec
(begin, bindingNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (errorResult()); } (importSpec) = parserTryVarTempResult_
.unwrap(); } while (0)
;
5158 handler_.addList(importSpecSet, importSpec);
5159
5160 if (!mustMatchToken(TokenKind::From, JSMSG_FROM_AFTER_IMPORT_CLAUSE)) {
5161 return errorResult();
5162 }
5163 if (!mustMatchToken(TokenKind::String, JSMSG_MODULE_SPEC_AFTER_FROM)) {
5164 return errorResult();
5165 }
5166 } else {
5167 // import ImportClause
5168 if (tt == TokenKind::LeftCurly) {
5169 if (!namedImports(importSpecSet)) {
5170 return errorResult();
5171 }
5172 } else if (tt == TokenKind::Mul) {
5173 if (!namespaceImport(importSpecSet)) {
5174 return errorResult();
5175 }
5176 } else if (TokenKindIsPossibleIdentifierName(tt)) {
5177 // `source` is a contextual keyword: |import source x from 'b'| is a
5178 // source phase import, but |import source from 'b'| imports the default
5179 // export under the binding name `source`. Disambiguate with lookahead
5180 // before committing to a phase, leaving `source` as the current token.
5181 if (options().sourcePhaseImports() && tt == TokenKind::Source) {
5182 if (!tokenStream.peekToken(&tt)) {
5183 return errorResult();
5184 }
5185 if (tt == TokenKind::From) {
5186 // |import source from ...| is a source phase import only if a second
5187 // `from` follows, as in |import source from from 'b'|.
5188 tokenStream.consumeKnownToken(TokenKind::From);
5189 if (!tokenStream.peekToken(&tt)) {
5190 return errorResult();
5191 }
5192 if (tt == TokenKind::From) {
5193 phase = ImportPhase::Source;
5194 }
5195 anyChars.ungetToken();
5196 } else if (tt != TokenKind::Comma) {
5197 // |import source <binding> from 'b'|
5198 phase = ImportPhase::Source;
5199 }
5200 }
5201
5202 if (phase == ImportPhase::Source) {
5203 // Handle the form |import source a from 'b'|.
5204 if (!tokenStream.getToken(&tt)) {
5205 return errorResult();
5206 }
5207
5208 if (!TokenKindIsPossibleIdentifierName(tt)) {
5209 error(JSMSG_DECLARATION_AFTER_IMPORT_SOURCE);
5210 return errorResult();
5211 }
5212
5213 TaggedParserAtomIndex bindingAtom = importedBinding();
5214 if (!bindingAtom) {
5215 return errorResult();
5216 }
5217
5218 importSourceBinding = MOZ_TRY(newName(bindingAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newName(bindingAtom)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5219
5220 // We handle import source like namespace imports.
5221 // It's not an indirect binding, but instead a lexical definition,
5222 // that's treated like a const variable.
5223 if (!noteDeclaredName(bindingAtom, DeclarationKind::Const, pos())) {
5224 return errorResult();
5225 }
5226
5227 // The source phase import name is currently required to live on the
5228 // environment.
5229 pc_->varScope()
5230 .lookupDeclaredName(bindingAtom)
5231 ->value()
5232 ->setClosedOver();
5233 } else {
5234 // Handle the form |import a from 'b'|, by adding a single import
5235 // specifier to the list, with 'default' as the import name and
5236 // 'a' as the binding name. This is equivalent to
5237 // |import { default as a } from 'b'|.
5238 NameNodeType importName =
5239 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
(); })
;
5240
5241 TaggedParserAtomIndex bindingAtom = importedBinding();
5242 if (!bindingAtom) {
5243 return errorResult();
5244 }
5245
5246 NameNodeType bindingName = MOZ_TRY(newName(bindingAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newName(bindingAtom)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5247
5248 if (!noteDeclaredName(bindingAtom, DeclarationKind::Import, pos())) {
5249 return errorResult();
5250 }
5251
5252 BinaryNodeType importSpec =
5253 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(); })
;
5254
5255 handler_.addList(importSpecSet, importSpec);
5256
5257 if (!tokenStream.peekToken(&tt)) {
5258 return errorResult();
5259 }
5260
5261 // ImportedDefaultBinding, NameSpaceImport
5262 // ImportedDefaultBinding, NamedImports
5263 if (tt == TokenKind::Comma) {
5264 tokenStream.consumeKnownToken(tt);
5265 if (!tokenStream.getToken(&tt)) {
5266 return errorResult();
5267 }
5268
5269 if (tt == TokenKind::LeftCurly) {
5270 if (!namedImports(importSpecSet)) {
5271 return errorResult();
5272 }
5273 } else if (tt == TokenKind::Mul) {
5274 if (!namespaceImport(importSpecSet)) {
5275 return errorResult();
5276 }
5277 } else {
5278 error(JSMSG_NAMED_IMPORTS_OR_NAMESPACE_IMPORT);
5279 return errorResult();
5280 }
5281 }
5282 }
5283 } else {
5284 error(JSMSG_DECLARATION_AFTER_IMPORT);
5285 return errorResult();
5286 }
5287
5288 if (!mustMatchToken(TokenKind::From, JSMSG_FROM_AFTER_IMPORT_CLAUSE)) {
5289 return errorResult();
5290 }
5291
5292 if (!mustMatchToken(TokenKind::String, JSMSG_MODULE_SPEC_AFTER_FROM)) {
5293 return errorResult();
5294 }
5295 }
5296
5297 NameNodeType moduleSpec = MOZ_TRY(stringLiteral())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(stringLiteral()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5298
5299 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
5300 return errorResult();
5301 }
5302
5303 Node importAttributeList;
5304 if (phase == ImportPhase::Source) {
5305 // Source phase imports do not support import attributes
5306 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(); })
;
5307 } else {
5308 ListNodeType attributeList =
5309 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(); })
;
5310
5311 if (tt == TokenKind::With) {
5312 tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp);
5313
5314 if (!withClause(attributeList)) {
5315 return errorResult();
5316 }
5317 }
5318
5319 importAttributeList = attributeList;
5320 }
5321
5322 if (!matchOrInsertSemicolon(TokenStream::SlashIsRegExp)) {
5323 return errorResult();
5324 }
5325
5326 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(); })
5327 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(); })
;
5328
5329 Node importClause;
5330 if (phase == ImportPhase::Source) {
5331 importClause = importSourceBinding;
5332 } else {
5333 importClause = importSpecSet;
5334 }
5335
5336 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(); })
5337 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(); })
;
5338 if (!processImport(node)) {
5339 return errorResult();
5340 }
5341
5342 return node;
5343}
5344
5345template <class ParseHandler, typename Unit>
5346inline typename ParseHandler::NodeResult
5347GeneralParser<ParseHandler, Unit>::importDeclarationOrImportExpr(
5348 YieldHandling yieldHandling) {
5349 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", 5349); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Import)"
")"); do { MOZ_CrashSequence(__null, 5349); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5350
5351 TokenKind tt;
5352 if (!tokenStream.peekToken(&tt)) {
5353 return errorResult();
5354 }
5355
5356 if (tt == TokenKind::Dot || tt == TokenKind::LeftParen) {
5357 return expressionStatement(yieldHandling);
5358 }
5359
5360 return importDeclaration();
5361}
5362
5363template <typename Unit>
5364bool Parser<FullParseHandler, Unit>::checkExportedName(
5365 TaggedParserAtomIndex exportName) {
5366 switch (pc_->sc()->asModuleContext()->builder.noteExportedName(exportName)) {
5367 case ModuleBuilder::NoteExportedNameResult::Success:
5368 return true;
5369 case ModuleBuilder::NoteExportedNameResult::OutOfMemory:
5370 return false;
5371 case ModuleBuilder::NoteExportedNameResult::AlreadyDeclared:
5372 break;
5373 }
5374
5375 UniqueChars str = this->parserAtoms().toPrintableString(exportName);
5376 if (!str) {
5377 ReportOutOfMemory(this->fc_);
5378 return false;
5379 }
5380
5381 error(JSMSG_DUPLICATE_EXPORT_NAME, str.get());
5382 return false;
5383}
5384
5385template <typename Unit>
5386inline bool Parser<SyntaxParseHandler, Unit>::checkExportedName(
5387 TaggedParserAtomIndex exportName) {
5388 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", 5388); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5388); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5389 return false;
5390}
5391
5392template <class ParseHandler, typename Unit>
5393inline bool GeneralParser<ParseHandler, Unit>::checkExportedName(
5394 TaggedParserAtomIndex exportName) {
5395 return asFinalParser()->checkExportedName(exportName);
5396}
5397
5398template <typename Unit>
5399bool Parser<FullParseHandler, Unit>::checkExportedNamesForArrayBinding(
5400 ListNode* array) {
5401 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", 5401); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "array->isKind(ParseNodeKind::ArrayExpr)"
")"); do { MOZ_CrashSequence(__null, 5401); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5402
5403 for (ParseNode* node : array->contents()) {
5404 if (node->isKind(ParseNodeKind::Elision)) {
5405 continue;
5406 }
5407
5408 ParseNode* binding;
5409 if (node->isKind(ParseNodeKind::Spread)) {
5410 binding = node->as<UnaryNode>().kid();
5411 } else if (node->isKind(ParseNodeKind::AssignExpr)) {
5412 binding = node->as<AssignmentNode>().left();
5413 } else {
5414 binding = node;
5415 }
5416
5417 if (!checkExportedNamesForDeclaration(binding)) {
5418 return false;
5419 }
5420 }
5421
5422 return true;
5423}
5424
5425template <typename Unit>
5426inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNamesForArrayBinding(
5427 ListNodeType array) {
5428 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", 5428); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5428); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5429 return false;
5430}
5431
5432template <class ParseHandler, typename Unit>
5433inline bool
5434GeneralParser<ParseHandler, Unit>::checkExportedNamesForArrayBinding(
5435 ListNodeType array) {
5436 return asFinalParser()->checkExportedNamesForArrayBinding(array);
5437}
5438
5439template <typename Unit>
5440bool Parser<FullParseHandler, Unit>::checkExportedNamesForObjectBinding(
5441 ListNode* obj) {
5442 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", 5442); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "obj->isKind(ParseNodeKind::ObjectExpr)"
")"); do { MOZ_CrashSequence(__null, 5442); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5443
5444 for (ParseNode* node : obj->contents()) {
5445 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", 5448); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)"
")"); do { MOZ_CrashSequence(__null, 5448); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
5446 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", 5448); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)"
")"); do { MOZ_CrashSequence(__null, 5448); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
5447 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", 5448); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)"
")"); do { MOZ_CrashSequence(__null, 5448); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
5448 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", 5448); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::MutateProto) || node->isKind(ParseNodeKind::PropertyDefinition) || node->isKind(ParseNodeKind::Shorthand) || node->isKind(ParseNodeKind::Spread)"
")"); do { MOZ_CrashSequence(__null, 5448); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5449
5450 ParseNode* target;
5451 if (node->isKind(ParseNodeKind::Spread)) {
5452 target = node->as<UnaryNode>().kid();
5453 } else {
5454 if (node->isKind(ParseNodeKind::MutateProto)) {
5455 target = node->as<UnaryNode>().kid();
5456 } else {
5457 target = node->as<BinaryNode>().right();
5458 }
5459
5460 if (target->isKind(ParseNodeKind::AssignExpr)) {
5461 target = target->as<AssignmentNode>().left();
5462 }
5463 }
5464
5465 if (!checkExportedNamesForDeclaration(target)) {
5466 return false;
5467 }
5468 }
5469
5470 return true;
5471}
5472
5473template <typename Unit>
5474inline bool Parser<SyntaxParseHandler,
5475 Unit>::checkExportedNamesForObjectBinding(ListNodeType obj) {
5476 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", 5476); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5476); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5477 return false;
5478}
5479
5480template <class ParseHandler, typename Unit>
5481inline bool
5482GeneralParser<ParseHandler, Unit>::checkExportedNamesForObjectBinding(
5483 ListNodeType obj) {
5484 return asFinalParser()->checkExportedNamesForObjectBinding(obj);
5485}
5486
5487template <typename Unit>
5488bool Parser<FullParseHandler, Unit>::checkExportedNamesForDeclaration(
5489 ParseNode* node) {
5490 if (node->isKind(ParseNodeKind::Name)) {
5491 if (!checkExportedName(node->as<NameNode>().atom())) {
5492 return false;
5493 }
5494 } else if (node->isKind(ParseNodeKind::ArrayExpr)) {
5495 if (!checkExportedNamesForArrayBinding(&node->as<ListNode>())) {
5496 return false;
5497 }
5498 } else {
5499 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", 5499); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "node->isKind(ParseNodeKind::ObjectExpr)"
")"); do { MOZ_CrashSequence(__null, 5499); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5500 if (!checkExportedNamesForObjectBinding(&node->as<ListNode>())) {
5501 return false;
5502 }
5503 }
5504
5505 return true;
5506}
5507
5508template <typename Unit>
5509inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNamesForDeclaration(
5510 Node node) {
5511 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", 5511); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5511); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5512 return false;
5513}
5514
5515template <class ParseHandler, typename Unit>
5516inline bool GeneralParser<ParseHandler, Unit>::checkExportedNamesForDeclaration(
5517 Node node) {
5518 return asFinalParser()->checkExportedNamesForDeclaration(node);
5519}
5520
5521template <typename Unit>
5522bool Parser<FullParseHandler, Unit>::checkExportedNamesForDeclarationList(
5523 DeclarationListNodeType node) {
5524 for (ParseNode* binding : node->contents()) {
5525 if (binding->isKind(ParseNodeKind::AssignExpr)) {
5526 binding = binding->as<AssignmentNode>().left();
5527 } else {
5528 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", 5528); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "binding->isKind(ParseNodeKind::Name)" ")"
); do { MOZ_CrashSequence(__null, 5528); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5529 }
5530
5531 if (!checkExportedNamesForDeclaration(binding)) {
5532 return false;
5533 }
5534 }
5535
5536 return true;
5537}
5538
5539template <typename Unit>
5540inline bool
5541Parser<SyntaxParseHandler, Unit>::checkExportedNamesForDeclarationList(
5542 DeclarationListNodeType node) {
5543 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", 5543); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5543); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5544 return false;
5545}
5546
5547template <class ParseHandler, typename Unit>
5548inline bool
5549GeneralParser<ParseHandler, Unit>::checkExportedNamesForDeclarationList(
5550 DeclarationListNodeType node) {
5551 return asFinalParser()->checkExportedNamesForDeclarationList(node);
5552}
5553
5554template <typename Unit>
5555inline bool Parser<FullParseHandler, Unit>::checkExportedNameForClause(
5556 NameNode* nameNode) {
5557 return checkExportedName(nameNode->atom());
5558}
5559
5560template <typename Unit>
5561inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNameForClause(
5562 NameNodeType nameNode) {
5563 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", 5563); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5563); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5564 return false;
5565}
5566
5567template <class ParseHandler, typename Unit>
5568inline bool GeneralParser<ParseHandler, Unit>::checkExportedNameForClause(
5569 NameNodeType nameNode) {
5570 return asFinalParser()->checkExportedNameForClause(nameNode);
5571}
5572
5573template <typename Unit>
5574bool Parser<FullParseHandler, Unit>::checkExportedNameForFunction(
5575 FunctionNode* funNode) {
5576 return checkExportedName(funNode->funbox()->explicitName());
5577}
5578
5579template <typename Unit>
5580inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNameForFunction(
5581 FunctionNodeType funNode) {
5582 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", 5582); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5582); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5583 return false;
5584}
5585
5586template <class ParseHandler, typename Unit>
5587inline bool GeneralParser<ParseHandler, Unit>::checkExportedNameForFunction(
5588 FunctionNodeType funNode) {
5589 return asFinalParser()->checkExportedNameForFunction(funNode);
5590}
5591
5592template <typename Unit>
5593bool Parser<FullParseHandler, Unit>::checkExportedNameForClass(
5594 ClassNode* classNode) {
5595 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", 5595); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "classNode->names()" ")"); do { MOZ_CrashSequence
(__null, 5595); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
5596 return checkExportedName(classNode->names()->innerBinding()->atom());
5597}
5598
5599template <typename Unit>
5600inline bool Parser<SyntaxParseHandler, Unit>::checkExportedNameForClass(
5601 ClassNodeType classNode) {
5602 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", 5602); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5602); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5603 return false;
5604}
5605
5606template <class ParseHandler, typename Unit>
5607inline bool GeneralParser<ParseHandler, Unit>::checkExportedNameForClass(
5608 ClassNodeType classNode) {
5609 return asFinalParser()->checkExportedNameForClass(classNode);
5610}
5611
5612template <>
5613inline bool PerHandlerParser<FullParseHandler>::processExport(ParseNode* node) {
5614 return pc_->sc()->asModuleContext()->builder.processExport(node);
5615}
5616
5617template <>
5618inline bool PerHandlerParser<SyntaxParseHandler>::processExport(Node node) {
5619 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", 5619); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5619); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5620 return false;
5621}
5622
5623template <>
5624inline bool PerHandlerParser<FullParseHandler>::processExportFrom(
5625 BinaryNodeType node) {
5626 return pc_->sc()->asModuleContext()->builder.processExportFrom(node);
5627}
5628
5629template <>
5630inline bool PerHandlerParser<SyntaxParseHandler>::processExportFrom(
5631 BinaryNodeType node) {
5632 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", 5632); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5632); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5633 return false;
5634}
5635
5636template <>
5637inline bool PerHandlerParser<FullParseHandler>::processImport(
5638 BinaryNodeType node) {
5639 return pc_->sc()->asModuleContext()->builder.processImport(node);
5640}
5641
5642template <>
5643inline bool PerHandlerParser<SyntaxParseHandler>::processImport(
5644 BinaryNodeType node) {
5645 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", 5645); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5645); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5646 return false;
5647}
5648
5649template <class ParseHandler, typename Unit>
5650typename ParseHandler::BinaryNodeResult
5651GeneralParser<ParseHandler, Unit>::exportFrom(uint32_t begin, Node specList) {
5652 if (!abortIfSyntaxParser()) {
5653 return errorResult();
5654 }
5655
5656 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", 5656); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::From)"
")"); do { MOZ_CrashSequence(__null, 5656); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5657
5658 if (!mustMatchToken(TokenKind::String, JSMSG_MODULE_SPEC_AFTER_FROM)) {
5659 return errorResult();
5660 }
5661
5662 NameNodeType moduleSpec = MOZ_TRY(stringLiteral())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(stringLiteral()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5663
5664 TokenKind tt;
5665 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
5666 return errorResult();
5667 }
5668
5669 uint32_t moduleSpecPos = pos().begin;
5670
5671 ListNodeType importAttributeList =
5672 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(); })
;
5673 if (tt == TokenKind::With) {
5674 tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp);
5675
5676 if (!withClause(importAttributeList)) {
5677 return errorResult();
5678 }
5679 }
5680
5681 if (!matchOrInsertSemicolon(TokenStream::SlashIsRegExp)) {
5682 return errorResult();
5683 }
5684
5685 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(); })
5686 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(); })
;
5687
5688 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(); })
5689 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(); })
;
5690
5691 if (!processExportFrom(node)) {
5692 return errorResult();
5693 }
5694
5695 return node;
5696}
5697
5698template <class ParseHandler, typename Unit>
5699typename ParseHandler::BinaryNodeResult
5700GeneralParser<ParseHandler, Unit>::exportBatch(uint32_t begin) {
5701 if (!abortIfSyntaxParser()) {
5702 return errorResult();
5703 }
5704
5705 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", 5705); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Mul)"
")"); do { MOZ_CrashSequence(__null, 5705); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5706 uint32_t beginExportSpec = pos().begin;
5707
5708 ListNodeType kid =
5709 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
(); })
;
5710
5711 bool foundAs;
5712 if (!tokenStream.matchToken(&foundAs, TokenKind::As)) {
5713 return errorResult();
5714 }
5715
5716 if (foundAs) {
5717 TokenKind tt;
5718 if (!tokenStream.getToken(&tt)) {
5719 return errorResult();
5720 }
5721
5722 NameNodeType exportName = null();
5723 if (TokenKindIsPossibleIdentifierName(tt)) {
5724 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(); })
;
5725 } else if (tt == TokenKind::String) {
5726 exportName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5727 } else {
5728 error(JSMSG_NO_EXPORT_NAME);
5729 return errorResult();
5730 }
5731
5732 if (!checkExportedNameForClause(exportName)) {
5733 return errorResult();
5734 }
5735
5736 UnaryNodeType exportSpec =
5737 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(); })
;
5738
5739 handler_.addList(kid, exportSpec);
5740 } else {
5741 // Handle the form |export *| by adding a special export batch
5742 // specifier to the list.
5743 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(); })
;
5744
5745 handler_.addList(kid, exportSpec);
5746 }
5747
5748 if (!mustMatchToken(TokenKind::From, JSMSG_FROM_AFTER_EXPORT_STAR)) {
5749 return errorResult();
5750 }
5751
5752 return exportFrom(begin, kid);
5753}
5754
5755template <typename Unit>
5756bool Parser<FullParseHandler, Unit>::checkLocalExportNames(ListNode* node) {
5757 // ES 2017 draft 15.2.3.1.
5758 for (ParseNode* next : node->contents()) {
5759 ParseNode* name = next->as<BinaryNode>().left();
5760
5761 if (name->isKind(ParseNodeKind::StringExpr)) {
5762 errorAt(name->pn_pos.begin, JSMSG_BAD_LOCAL_STRING_EXPORT);
5763 return false;
5764 }
5765
5766 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"
, 5766); AnnotateMozCrashReason("MOZ_ASSERT" "(" "name->isKind(ParseNodeKind::Name)"
")"); do { MOZ_CrashSequence(__null, 5766); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5767
5768 TaggedParserAtomIndex ident = name->as<NameNode>().atom();
5769 if (!checkLocalExportName(ident, name->pn_pos.begin)) {
5770 return false;
5771 }
5772 }
5773
5774 return true;
5775}
5776
5777template <typename Unit>
5778bool Parser<SyntaxParseHandler, Unit>::checkLocalExportNames(
5779 ListNodeType node) {
5780 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", 5780); AnnotateMozCrashReason
("MOZ_CRASH(" "!(abortIfSyntaxParser())" ")"); do { MOZ_CrashSequence
(__null, 5780); __attribute__((nomerge)) ::abort(); } while (
false); } while (false); } } while (false)
;
5781 return false;
5782}
5783
5784template <class ParseHandler, typename Unit>
5785inline bool GeneralParser<ParseHandler, Unit>::checkLocalExportNames(
5786 ListNodeType node) {
5787 return asFinalParser()->checkLocalExportNames(node);
5788}
5789
5790template <class ParseHandler, typename Unit>
5791typename ParseHandler::NodeResult
5792GeneralParser<ParseHandler, Unit>::exportClause(uint32_t begin) {
5793 if (!abortIfSyntaxParser()) {
5794 return errorResult();
5795 }
5796
5797 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", 5797); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)"
")"); do { MOZ_CrashSequence(__null, 5797); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5798
5799 ListNodeType kid =
5800 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
(); })
;
5801
5802 TokenKind tt;
5803 while (true) {
5804 // Handle the forms |export {}| and |export { ..., }| (where ... is non
5805 // empty), by escaping the loop early if the next token is }.
5806 if (!tokenStream.getToken(&tt)) {
5807 return errorResult();
5808 }
5809
5810 if (tt == TokenKind::RightCurly) {
5811 break;
5812 }
5813
5814 NameNodeType bindingName = null();
5815 if (TokenKindIsPossibleIdentifierName(tt)) {
5816 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(); })
;
5817 } else if (tt == TokenKind::String) {
5818 bindingName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5819 } else {
5820 error(JSMSG_NO_BINDING_NAME);
5821 return errorResult();
5822 }
5823
5824 bool foundAs;
5825 if (!tokenStream.matchToken(&foundAs, TokenKind::As)) {
5826 return errorResult();
5827 }
5828
5829 NameNodeType exportName = null();
5830 if (foundAs) {
5831 TokenKind tt;
5832 if (!tokenStream.getToken(&tt)) {
5833 return errorResult();
5834 }
5835
5836 if (TokenKindIsPossibleIdentifierName(tt)) {
5837 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(); })
;
5838 } else if (tt == TokenKind::String) {
5839 exportName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5840 } else {
5841 error(JSMSG_NO_EXPORT_NAME);
5842 return errorResult();
5843 }
5844 } else {
5845 if (tt != TokenKind::String) {
5846 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(); })
;
5847 } else {
5848 exportName = MOZ_TRY(moduleExportName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(moduleExportName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
5849 }
5850 }
5851
5852 if (!checkExportedNameForClause(exportName)) {
5853 return errorResult();
5854 }
5855
5856 BinaryNodeType exportSpec =
5857 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(); })
;
5858
5859 handler_.addList(kid, exportSpec);
5860
5861 TokenKind next;
5862 if (!tokenStream.getToken(&next)) {
5863 return errorResult();
5864 }
5865
5866 if (next == TokenKind::RightCurly) {
5867 break;
5868 }
5869
5870 if (next != TokenKind::Comma) {
5871 error(JSMSG_RC_AFTER_EXPORT_SPEC_LIST);
5872 return errorResult();
5873 }
5874 }
5875
5876 // Careful! If |from| follows, even on a new line, it must start a
5877 // FromClause:
5878 //
5879 // export { x }
5880 // from "foo"; // a single ExportDeclaration
5881 //
5882 // But if it doesn't, we might have an ASI opportunity in SlashIsRegExp
5883 // context:
5884 //
5885 // export { x } // ExportDeclaration, terminated by ASI
5886 // fro\u006D // ExpressionStatement, the name "from"
5887 //
5888 // In that case let matchOrInsertSemicolon sort out ASI or any necessary
5889 // error.
5890 bool matched;
5891 if (!tokenStream.matchToken(&matched, TokenKind::From,
5892 TokenStream::SlashIsRegExp)) {
5893 return errorResult();
5894 }
5895
5896 if (matched) {
5897 return exportFrom(begin, kid);
5898 }
5899
5900 if (!matchOrInsertSemicolon()) {
5901 return errorResult();
5902 }
5903
5904 if (!checkLocalExportNames(kid)) {
5905 return errorResult();
5906 }
5907
5908 UnaryNodeType node =
5909 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(); })
;
5910
5911 if (!processExport(node)) {
5912 return errorResult();
5913 }
5914
5915 return node;
5916}
5917
5918template <class ParseHandler, typename Unit>
5919typename ParseHandler::UnaryNodeResult
5920GeneralParser<ParseHandler, Unit>::exportVariableStatement(uint32_t begin) {
5921 if (!abortIfSyntaxParser()) {
5922 return errorResult();
5923 }
5924
5925 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", 5925); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Var)"
")"); do { MOZ_CrashSequence(__null, 5925); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5926
5927 DeclarationListNodeType kid =
5928 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
(); })
;
5929 if (!matchOrInsertSemicolon()) {
5930 return errorResult();
5931 }
5932 if (!checkExportedNamesForDeclarationList(kid)) {
5933 return errorResult();
5934 }
5935
5936 UnaryNodeType node =
5937 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(); })
;
5938
5939 if (!processExport(node)) {
5940 return errorResult();
5941 }
5942
5943 return node;
5944}
5945
5946template <class ParseHandler, typename Unit>
5947typename ParseHandler::UnaryNodeResult
5948GeneralParser<ParseHandler, Unit>::exportFunctionDeclaration(
5949 uint32_t begin, uint32_t toStringStart,
5950 FunctionAsyncKind asyncKind /* = SyncFunction */) {
5951 if (!abortIfSyntaxParser()) {
5952 return errorResult();
5953 }
5954
5955 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", 5955); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)"
")"); do { MOZ_CrashSequence(__null, 5955); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5956
5957 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(); })
5958 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(); })
;
5959
5960 if (!checkExportedNameForFunction(handler_.asFunctionNode(kid))) {
5961 return errorResult();
5962 }
5963
5964 UnaryNodeType node =
5965 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(); })
;
5966
5967 if (!processExport(node)) {
5968 return errorResult();
5969 }
5970
5971 return node;
5972}
5973
5974template <class ParseHandler, typename Unit>
5975typename ParseHandler::UnaryNodeResult
5976GeneralParser<ParseHandler, Unit>::exportClassDeclaration(uint32_t begin) {
5977 if (!abortIfSyntaxParser()) {
5978 return errorResult();
5979 }
5980
5981 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", 5981); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Class)"
")"); do { MOZ_CrashSequence(__null, 5981); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
5982
5983 ClassNodeType kid =
5984 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(); })
;
5985
5986 if (!checkExportedNameForClass(kid)) {
5987 return errorResult();
5988 }
5989
5990 UnaryNodeType node =
5991 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(); })
;
5992
5993 if (!processExport(node)) {
5994 return errorResult();
5995 }
5996
5997 return node;
5998}
5999
6000template <class ParseHandler, typename Unit>
6001typename ParseHandler::UnaryNodeResult
6002GeneralParser<ParseHandler, Unit>::exportLexicalDeclaration(
6003 uint32_t begin, DeclarationKind kind) {
6004 if (!abortIfSyntaxParser()) {
6005 return errorResult();
6006 }
6007
6008 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", 6008); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "kind == DeclarationKind::Const || kind == DeclarationKind::Let"
")"); do { MOZ_CrashSequence(__null, 6008); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6009 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"
, 6010); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Const)"
")"); do { MOZ_CrashSequence(__null, 6010); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
6010 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"
, 6010); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Const)"
")"); do { MOZ_CrashSequence(__null, 6010); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
6011 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"
, 6012); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Let)"
")"); do { MOZ_CrashSequence(__null, 6012); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
6012 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"
, 6012); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Let)"
")"); do { MOZ_CrashSequence(__null, 6012); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
6013
6014 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(); })
;
6015 if (!checkExportedNamesForDeclarationList(kid)) {
6016 return errorResult();
6017 }
6018
6019 UnaryNodeType node =
6020 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(); })
;
6021
6022 if (!processExport(node)) {
6023 return errorResult();
6024 }
6025
6026 return node;
6027}
6028
6029template <class ParseHandler, typename Unit>
6030typename ParseHandler::BinaryNodeResult
6031GeneralParser<ParseHandler, Unit>::exportDefaultFunctionDeclaration(
6032 uint32_t begin, uint32_t toStringStart,
6033 FunctionAsyncKind asyncKind /* = SyncFunction */) {
6034 if (!abortIfSyntaxParser()) {
6035 return errorResult();
6036 }
6037
6038 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", 6038); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Function)"
")"); do { MOZ_CrashSequence(__null, 6038); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6039
6040 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(); })
6041 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(); })
;
6042
6043 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(); })
6044 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(); })
;
6045
6046 if (!processExport(node)) {
6047 return errorResult();
6048 }
6049
6050 return node;
6051}
6052
6053template <class ParseHandler, typename Unit>
6054typename ParseHandler::BinaryNodeResult
6055GeneralParser<ParseHandler, Unit>::exportDefaultClassDeclaration(
6056 uint32_t begin) {
6057 if (!abortIfSyntaxParser()) {
6058 return errorResult();
6059 }
6060
6061 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", 6061); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Class)"
")"); do { MOZ_CrashSequence(__null, 6061); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6062
6063 ClassNodeType kid =
6064 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(); })
;
6065
6066 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(); })
6067 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(); })
;
6068
6069 if (!processExport(node)) {
6070 return errorResult();
6071 }
6072
6073 return node;
6074}
6075
6076template <class ParseHandler, typename Unit>
6077typename ParseHandler::BinaryNodeResult
6078GeneralParser<ParseHandler, Unit>::exportDefaultAssignExpr(uint32_t begin) {
6079 if (!abortIfSyntaxParser()) {
6080 return errorResult();
6081 }
6082
6083 TaggedParserAtomIndex name = TaggedParserAtomIndex::WellKnown::default_();
6084 NameNodeType nameNode = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
6085 if (!noteDeclaredName(name, DeclarationKind::Const, pos())) {
6086 return errorResult();
6087 }
6088
6089 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
(); })
;
6090
6091 if (!matchOrInsertSemicolon()) {
6092 return errorResult();
6093 }
6094
6095 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(); })
6096 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(); })
;
6097
6098 if (!processExport(node)) {
6099 return errorResult();
6100 }
6101
6102 return node;
6103}
6104
6105template <class ParseHandler, typename Unit>
6106typename ParseHandler::BinaryNodeResult
6107GeneralParser<ParseHandler, Unit>::exportDefault(uint32_t begin) {
6108 if (!abortIfSyntaxParser()) {
6109 return errorResult();
6110 }
6111
6112 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", 6112); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Default)"
")"); do { MOZ_CrashSequence(__null, 6112); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6113
6114 TokenKind tt;
6115 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
6116 return errorResult();
6117 }
6118
6119 if (!checkExportedName(TaggedParserAtomIndex::WellKnown::default_())) {
6120 return errorResult();
6121 }
6122
6123 switch (tt) {
6124 case TokenKind::Function:
6125 return exportDefaultFunctionDeclaration(begin, pos().begin);
6126
6127 case TokenKind::Async: {
6128 TokenKind nextSameLine = TokenKind::Eof;
6129 if (!tokenStream.peekTokenSameLine(&nextSameLine)) {
6130 return errorResult();
6131 }
6132
6133 if (nextSameLine == TokenKind::Function) {
6134 uint32_t toStringStart = pos().begin;
6135 tokenStream.consumeKnownToken(TokenKind::Function);
6136 return exportDefaultFunctionDeclaration(
6137 begin, toStringStart, FunctionAsyncKind::AsyncFunction);
6138 }
6139
6140 anyChars.ungetToken();
6141 return exportDefaultAssignExpr(begin);
6142 }
6143
6144 case TokenKind::Class:
6145 return exportDefaultClassDeclaration(begin);
6146
6147 default:
6148 anyChars.ungetToken();
6149 return exportDefaultAssignExpr(begin);
6150 }
6151}
6152
6153template <class ParseHandler, typename Unit>
6154typename ParseHandler::NodeResult
6155GeneralParser<ParseHandler, Unit>::exportDeclaration() {
6156 if (!abortIfSyntaxParser()) {
6157 return errorResult();
6158 }
6159
6160 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", 6160); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Export)"
")"); do { MOZ_CrashSequence(__null, 6160); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6161
6162 if (!pc_->atModuleLevel()) {
6163 error(JSMSG_EXPORT_DECL_AT_TOP_LEVEL);
6164 return errorResult();
6165 }
6166
6167 uint32_t begin = pos().begin;
6168
6169 TokenKind tt;
6170 if (!tokenStream.getToken(&tt)) {
6171 return errorResult();
6172 }
6173 switch (tt) {
6174 case TokenKind::Mul:
6175 return exportBatch(begin);
6176
6177 case TokenKind::LeftCurly:
6178 return exportClause(begin);
6179
6180 case TokenKind::Var:
6181 return exportVariableStatement(begin);
6182
6183 case TokenKind::Function:
6184 return exportFunctionDeclaration(begin, pos().begin);
6185
6186 case TokenKind::Async: {
6187 TokenKind nextSameLine = TokenKind::Eof;
6188 if (!tokenStream.peekTokenSameLine(&nextSameLine)) {
6189 return errorResult();
6190 }
6191
6192 if (nextSameLine == TokenKind::Function) {
6193 uint32_t toStringStart = pos().begin;
6194 tokenStream.consumeKnownToken(TokenKind::Function);
6195 return exportFunctionDeclaration(begin, toStringStart,
6196 FunctionAsyncKind::AsyncFunction);
6197 }
6198
6199 error(JSMSG_DECLARATION_AFTER_EXPORT);
6200 return errorResult();
6201 }
6202
6203 case TokenKind::Class:
6204 return exportClassDeclaration(begin);
6205
6206 case TokenKind::Const:
6207 return exportLexicalDeclaration(begin, DeclarationKind::Const);
6208
6209 case TokenKind::Let:
6210 return exportLexicalDeclaration(begin, DeclarationKind::Let);
6211
6212 case TokenKind::Default:
6213 return exportDefault(begin);
6214
6215 default:
6216 error(JSMSG_DECLARATION_AFTER_EXPORT);
6217 return errorResult();
6218 }
6219}
6220
6221template <class ParseHandler, typename Unit>
6222typename ParseHandler::UnaryNodeResult
6223GeneralParser<ParseHandler, Unit>::expressionStatement(
6224 YieldHandling yieldHandling, InvokedPrediction invoked) {
6225 anyChars.ungetToken();
6226 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(); })
6227 /* 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(); })
;
6228 if (!matchOrInsertSemicolon()) {
6229 return errorResult();
6230 }
6231 return handler_.newExprStatement(pnexpr, pos().end);
6232}
6233
6234template <class ParseHandler, typename Unit>
6235typename ParseHandler::NodeResult
6236GeneralParser<ParseHandler, Unit>::consequentOrAlternative(
6237 YieldHandling yieldHandling) {
6238 TokenKind next;
6239 if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) {
6240 return errorResult();
6241 }
6242
6243 // Annex B.3.4 says that unbraced FunctionDeclarations under if/else in
6244 // non-strict code act as if they were braced: |if (x) function f() {}|
6245 // parses as |if (x) { function f() {} }|.
6246 //
6247 // Careful! FunctionDeclaration doesn't include generators or async
6248 // functions.
6249 if (next == TokenKind::Function) {
6250 tokenStream.consumeKnownToken(next, TokenStream::SlashIsRegExp);
6251
6252 // Parser::statement would handle this, but as this function handles
6253 // every other error case, it seems best to handle this.
6254 if (pc_->sc()->strict()) {
6255 error(JSMSG_FORBIDDEN_AS_STATEMENT, "function declarations");
6256 return errorResult();
6257 }
6258
6259 TokenKind maybeStar;
6260 if (!tokenStream.peekToken(&maybeStar)) {
6261 return errorResult();
6262 }
6263
6264 if (maybeStar == TokenKind::Mul) {
6265 error(JSMSG_FORBIDDEN_AS_STATEMENT, "generator declarations");
6266 return errorResult();
6267 }
6268
6269 ParseContext::Statement stmt(pc_, StatementKind::Block);
6270 ParseContext::Scope scope(this);
6271 if (!scope.init(pc_)) {
6272 return errorResult();
6273 }
6274
6275 TokenPos funcPos = pos();
6276 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
(); })
;
6277
6278 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(); })
;
6279
6280 handler_.addStatementToList(block, fun);
6281 return finishLexicalScope(scope, block);
6282 }
6283
6284 return statement(yieldHandling);
6285}
6286
6287template <class ParseHandler, typename Unit>
6288typename ParseHandler::TernaryNodeResult
6289GeneralParser<ParseHandler, Unit>::ifStatement(YieldHandling yieldHandling) {
6290 Vector<Node, 4> condList(fc_), thenList(fc_);
6291 Vector<uint32_t, 4> posList(fc_);
6292 Node elseBranch;
6293
6294 ParseContext::Statement stmt(pc_, StatementKind::If);
6295
6296 while (true) {
6297 uint32_t begin = pos().begin;
6298
6299 /* An IF node has three kids: condition, then, and optional else. */
6300 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(); })
;
6301
6302 TokenKind tt;
6303 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
6304 return errorResult();
6305 }
6306
6307 Node thenBranch = MOZ_TRY(consequentOrAlternative(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(consequentOrAlternative(yieldHandling)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
6308
6309 if (!condList.append(cond) || !thenList.append(thenBranch) ||
6310 !posList.append(begin)) {
6311 return errorResult();
6312 }
6313
6314 bool matched;
6315 if (!tokenStream.matchToken(&matched, TokenKind::Else,
6316 TokenStream::SlashIsRegExp)) {
6317 return errorResult();
6318 }
6319 if (matched) {
6320 if (!tokenStream.matchToken(&matched, TokenKind::If,
6321 TokenStream::SlashIsRegExp)) {
6322 return errorResult();
6323 }
6324 if (matched) {
6325 continue;
6326 }
6327 elseBranch = MOZ_TRY(consequentOrAlternative(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(consequentOrAlternative(yieldHandling)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
6328 } else {
6329 elseBranch = null();
6330 }
6331 break;
6332 }
6333
6334 TernaryNodeType ifNode;
6335 for (int i = condList.length() - 1; i >= 0; i--) {
6336 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(); })
6337 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(); })
;
6338 elseBranch = ifNode;
6339 }
6340
6341 return ifNode;
6342}
6343
6344template <class ParseHandler, typename Unit>
6345typename ParseHandler::BinaryNodeResult
6346GeneralParser<ParseHandler, Unit>::doWhileStatement(
6347 YieldHandling yieldHandling) {
6348 uint32_t begin = pos().begin;
6349 ParseContext::Statement stmt(pc_, StatementKind::DoLoop);
6350 Node body = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
6351 if (!mustMatchToken(TokenKind::While, JSMSG_WHILE_AFTER_DO)) {
6352 return errorResult();
6353 }
6354 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(); })
;
6355
6356 // The semicolon after do-while is even more optional than most
6357 // semicolons in JS. Web compat required this by 2004:
6358 // http://bugzilla.mozilla.org/show_bug.cgi?id=238945
6359 // ES3 and ES5 disagreed, but ES6 conforms to Web reality:
6360 // https://bugs.ecmascript.org/show_bug.cgi?id=157
6361 // To parse |do {} while (true) false| correctly, use SlashIsRegExp.
6362 bool ignored;
6363 if (!tokenStream.matchToken(&ignored, TokenKind::Semi,
6364 TokenStream::SlashIsRegExp)) {
6365 return errorResult();
6366 }
6367 return handler_.newDoWhileStatement(body, cond, TokenPos(begin, pos().end));
6368}
6369
6370template <class ParseHandler, typename Unit>
6371typename ParseHandler::BinaryNodeResult
6372GeneralParser<ParseHandler, Unit>::whileStatement(YieldHandling yieldHandling) {
6373 uint32_t begin = pos().begin;
6374 ParseContext::Statement stmt(pc_, StatementKind::WhileLoop);
6375 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(); })
;
6376 Node body = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
6377 return handler_.newWhileStatement(begin, cond, body);
6378}
6379
6380template <class ParseHandler, typename Unit>
6381bool GeneralParser<ParseHandler, Unit>::matchInOrOf(bool* isForInp,
6382 bool* isForOfp) {
6383 TokenKind tt;
6384 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
6385 return false;
6386 }
6387
6388 *isForInp = tt == TokenKind::In;
6389 *isForOfp = tt == TokenKind::Of;
6390 if (!*isForInp && !*isForOfp) {
6391 anyChars.ungetToken();
6392 }
6393
6394 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"
, 6394); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*isForInp != *isForOfp"
")"); do { MOZ_CrashSequence(__null, 6394); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
6395 return true;
6396}
6397
6398template <class ParseHandler, typename Unit>
6399bool GeneralParser<ParseHandler, Unit>::forHeadStart(
6400 YieldHandling yieldHandling, IteratorKind iterKind,
6401 ParseNodeKind* forHeadKind, Node* forInitialPart,
6402 Maybe<ParseContext::Scope>& forLoopLexicalScope,
6403 Node* forInOrOfExpression) {
6404 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", 6404); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftParen)"
")"); do { MOZ_CrashSequence(__null, 6404); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6405
6406 TokenKind tt;
6407 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
6408 return false;
6409 }
6410
6411 // Super-duper easy case: |for (;| is a C-style for-loop with no init
6412 // component.
6413 if (tt == TokenKind::Semi) {
6414 *forInitialPart = null();
6415 *forHeadKind = ParseNodeKind::ForHead;
6416 return true;
6417 }
6418
6419 // Parsing after |for (var| is also relatively simple (from this method's
6420 // point of view). No block-related work complicates matters, so delegate
6421 // to Parser::declaration.
6422 if (tt == TokenKind::Var) {
6423 tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp);
6424
6425 // Pass null for block object because |var| declarations don't use one.
6426 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)
6427 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)
6428 forHeadKind, forInOrOfExpression),do { auto parserTryVarTempResult_ = (declarationList(yieldHandling
, ParseNodeKind::VarStmt, forHeadKind, forInOrOfExpression));
if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0
))) { return (false); } (*forInitialPart) = parserTryVarTempResult_
.unwrap(); } while (0)
6429 false)do { auto parserTryVarTempResult_ = (declarationList(yieldHandling
, ParseNodeKind::VarStmt, forHeadKind, forInOrOfExpression));
if ((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0
))) { return (false); } (*forInitialPart) = parserTryVarTempResult_
.unwrap(); } while (0)
;
6430 return true;
6431 }
6432
6433 // Otherwise we have a lexical declaration or an expression.
6434
6435 // For-in loop backwards compatibility requires that |let| starting a
6436 // for-loop that's not a (new to ES6) for-of loop, in non-strict mode code,
6437 // parse as an identifier. (|let| in for-of is always a declaration.)
6438 //
6439 // For-of loops can't start with the token sequence "async of", because that
6440 // leads to a shift-reduce conflict when parsing |for (async of => {};;)| or
6441 // |for (async of [])|.
6442 bool parsingLexicalDeclaration = false;
6443 bool letIsIdentifier = false;
6444 bool startsWithForOf = false;
6445
6446 if (tt == TokenKind::Const) {
6447 parsingLexicalDeclaration = true;
6448 tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp);
6449 } else if (tt == TokenKind::Await) {
6450 if (!pc_->isAsync()) {
6451 if (pc_->atModuleTopLevel()) {
6452 if (!options().topLevelAwait) {
6453 error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED);
6454 return false;
6455 }
6456 pc_->sc()->asModuleContext()->setIsAsync();
6457 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", 6457); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence
(__null, 6457); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
6458 }
6459 }
6460 if (pc_->isAsync()) {
6461 // Try finding evidence of a AwaitUsingDeclaration the syntax for which
6462 // would be:
6463 // await [no LineTerminator here] using [no LineTerminator here]
6464 // identifier
6465 tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp);
6466
6467 TokenKind nextTok = TokenKind::Eof;
6468 if (!tokenStream.peekTokenSameLine(&nextTok,
6469 TokenStream::SlashIsRegExp)) {
6470 return false;
6471 }
6472
6473 if (nextTok == TokenKind::Using) {
6474 tokenStream.consumeKnownToken(nextTok, TokenStream::SlashIsRegExp);
6475
6476 TokenKind nextTokIdent = TokenKind::Eof;
6477 if (!tokenStream.peekTokenSameLine(&nextTokIdent)) {
6478 return false;
6479 }
6480
6481 if (TokenKindIsPossibleIdentifier(nextTokIdent)) {
6482 parsingLexicalDeclaration = true;
6483 } else {
6484 anyChars.ungetToken(); // put back using token
6485 anyChars.ungetToken(); // put back await token
6486 }
6487 } else {
6488 anyChars.ungetToken(); // put back await token
6489 }
6490 }
6491 } else if (tt == TokenKind::Using) {
6492 tokenStream.consumeKnownToken(tt, TokenStream::SlashIsRegExp);
6493
6494 // Look ahead to find either a 'of' token or if not identifier
6495 TokenKind nextTok = TokenKind::Eof;
6496 if (!tokenStream.peekTokenSameLine(&nextTok)) {
6497 return false;
6498 }
6499
6500 if (!TokenKindIsPossibleIdentifier(nextTok)) {
6501 anyChars.ungetToken(); // we didnt find a valid case of using decl put
6502 // back the token
6503 } else if (nextTok == TokenKind::Of) {
6504 // "for (using of" can be a prefix of the following:
6505 // * "for (using of = 0;;) { ... }"
6506 // * "for (using of [1, 2, 3]) { ... }"
6507 //
6508 // If the "of" token is followed by the assignment token, the loop is
6509 // considered a C-style for-statement with a using declaration where
6510 // "of" is an identifier.
6511 // https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-for-statement&secAll=true
6512 //
6513 // If the "of" token is followed by anything else, this is a for-of
6514 // statement with the "using" being an identifier", and the token after
6515 // the "of" token being the first token of the iterated expression (thus
6516 // SlashIsRegExp is used as the modifier).
6517 // https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-for-in-and-for-of-statements&secAll=true
6518 tokenStream.consumeKnownToken(nextTok);
6519 TokenKind nextTokAssign;
6520 if (!tokenStream.peekToken(&nextTokAssign, TokenStream::SlashIsRegExp)) {
6521 return false;
6522 }
6523 if (nextTokAssign == TokenKind::Assign) {
6524 parsingLexicalDeclaration = true;
6525 anyChars.ungetToken(); // put back the assignment token
6526 } else {
6527 anyChars.ungetToken(); // put back the token after the "of" token
6528 anyChars.ungetToken(); // put back the of token
6529 }
6530 } else {
6531 parsingLexicalDeclaration = true;
6532 }
6533 } else if (tt == TokenKind::Let) {
6534 // We could have a {For,Lexical}Declaration, or we could have a
6535 // LeftHandSideExpression with lookahead restrictions so it's not
6536 // ambiguous with the former. Check for a continuation of the former
6537 // to decide which we have.
6538 tokenStream.consumeKnownToken(TokenKind::Let, TokenStream::SlashIsRegExp);
6539
6540 TokenKind next;
6541 if (!tokenStream.peekToken(&next)) {
6542 return false;
6543 }
6544
6545 parsingLexicalDeclaration = nextTokenContinuesLetDeclaration(next);
6546 if (!parsingLexicalDeclaration) {
6547 // If we end up here, we may have `for (let <reserved word> of/in ...`,
6548 // which is not valid.
6549 if (next != TokenKind::In && next != TokenKind::Of &&
6550 TokenKindIsReservedWord(next)) {
6551 tokenStream.consumeKnownToken(next);
6552 error(JSMSG_UNEXPECTED_TOKEN_NO_EXPECT, TokenKindToDesc(next));
6553 return false;
6554 }
6555
6556 anyChars.ungetToken();
6557 letIsIdentifier = true;
6558 }
6559 } else if (tt == TokenKind::Async && iterKind == IteratorKind::Sync) {
6560 tokenStream.consumeKnownToken(TokenKind::Async, TokenStream::SlashIsRegExp);
6561
6562 TokenKind next;
6563 if (!tokenStream.peekToken(&next)) {
6564 return false;
6565 }
6566
6567 if (next == TokenKind::Of) {
6568 startsWithForOf = true;
6569 }
6570 anyChars.ungetToken();
6571 }
6572
6573 if (parsingLexicalDeclaration) {
6574 if (options().selfHostingMode) {
6575 error(JSMSG_SELFHOSTED_LEXICAL);
6576 return false;
6577 }
6578
6579 forLoopLexicalScope.emplace(this);
6580 if (!forLoopLexicalScope->init(pc_)) {
6581 return false;
6582 }
6583
6584 // Push a temporary ForLoopLexicalHead Statement that allows for
6585 // lexical declarations, as they are usually allowed only in braced
6586 // statements.
6587 ParseContext::Statement forHeadStmt(pc_, StatementKind::ForLoopLexicalHead);
6588
6589 ParseNodeKind declKind;
6590 switch (tt) {
6591 case TokenKind::Const:
6592 declKind = ParseNodeKind::ConstDecl;
6593 break;
6594 case TokenKind::Using:
6595 declKind = ParseNodeKind::UsingDecl;
6596 break;
6597 case TokenKind::Await:
6598 declKind = ParseNodeKind::AwaitUsingDecl;
6599 break;
6600 case TokenKind::Let:
6601 declKind = ParseNodeKind::LetDecl;
6602 break;
6603 default:
6604 MOZ_CRASH("unexpected node kind")do { do { } while (false); MOZ_ReportCrash("" "unexpected node kind"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 6604); AnnotateMozCrashReason
("MOZ_CRASH(" "unexpected node kind" ")"); do { MOZ_CrashSequence
(__null, 6604); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
6605 }
6606
6607 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)
6608 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)
6609 forInOrOfExpression),do { auto parserTryVarTempResult_ = (declarationList(yieldHandling
, declKind, forHeadKind, forInOrOfExpression)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(*forInitialPart) = parserTryVarTempResult_.unwrap(); } while
(0)
6610 false)do { auto parserTryVarTempResult_ = (declarationList(yieldHandling
, declKind, forHeadKind, forInOrOfExpression)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(*forInitialPart) = parserTryVarTempResult_.unwrap(); } while
(0)
;
6611 return true;
6612 }
6613
6614 uint32_t exprOffset;
6615 if (!tokenStream.peekOffset(&exprOffset, TokenStream::SlashIsRegExp)) {
6616 return false;
6617 }
6618
6619 // Finally, handle for-loops that start with expressions. Pass
6620 // |InProhibited| so that |in| isn't parsed in a RelationalExpression as a
6621 // binary operator. |in| makes it a for-in loop, *not* an |in| expression.
6622 PossibleError possibleError(*this);
6623 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)
6624 *forInitialPart,do { auto parserTryVarTempResult_ = (expr(InProhibited, yieldHandling
, TripledotProhibited, &possibleError)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(*forInitialPart) = parserTryVarTempResult_.unwrap(); } while
(0)
6625 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)
6626 false)do { auto parserTryVarTempResult_ = (expr(InProhibited, yieldHandling
, TripledotProhibited, &possibleError)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(*forInitialPart) = parserTryVarTempResult_.unwrap(); } while
(0)
;
6627
6628 bool isForIn, isForOf;
6629 if (!matchInOrOf(&isForIn, &isForOf)) {
6630 return false;
6631 }
6632
6633 // If we don't encounter 'in'/'of', we have a for(;;) loop. We've handled
6634 // the init expression; the caller handles the rest.
6635 if (!isForIn && !isForOf) {
6636 if (!possibleError.checkForExpressionError()) {
6637 return false;
6638 }
6639
6640 *forHeadKind = ParseNodeKind::ForHead;
6641 return true;
6642 }
6643
6644 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", 6644); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "isForIn != isForOf" ")"); do { MOZ_CrashSequence
(__null, 6644); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
6645
6646 // In a for-of loop, 'let' that starts the loop head is a |let| keyword,
6647 // per the [lookahead ≠ let] restriction on the LeftHandSideExpression
6648 // variant of such loops. Expressions that start with |let| can't be used
6649 // here.
6650 //
6651 // var let = {};
6652 // for (let.prop of [1]) // BAD
6653 // break;
6654 //
6655 // See ES6 13.7.
6656 if (isForOf && letIsIdentifier) {
6657 errorAt(exprOffset, JSMSG_BAD_STARTING_FOROF_LHS, "let");
6658 return false;
6659 }
6660
6661 // In a for-of loop, the LeftHandSideExpression isn't allowed to be an
6662 // identifier named "async" per the [lookahead ≠ async of] restriction.
6663 if (isForOf && startsWithForOf) {
6664 errorAt(exprOffset, JSMSG_BAD_STARTING_FOROF_LHS, "async of");
6665 return false;
6666 }
6667
6668 *forHeadKind = isForIn ? ParseNodeKind::ForIn : ParseNodeKind::ForOf;
6669
6670 // Verify the left-hand side expression doesn't have a forbidden form.
6671 if (handler_.isUnparenthesizedDestructuringPattern(*forInitialPart)) {
6672 if (!possibleError.checkForDestructuringErrorOrWarning()) {
6673 return false;
6674 }
6675 } else if (handler_.isName(*forInitialPart)) {
6676 if (const char* chars = nameIsArgumentsOrEval(*forInitialPart)) {
6677 // |chars| is "arguments" or "eval" here.
6678 if (!strictModeErrorAt(exprOffset, JSMSG_BAD_STRICT_ASSIGN, chars)) {
6679 return false;
6680 }
6681 }
6682 } else if (handler_.isArgumentsLength(*forInitialPart)) {
6683 pc_->sc()->setIneligibleForArgumentsLength();
6684 } else if (handler_.isPropertyOrPrivateMemberAccess(*forInitialPart)) {
6685 // Permitted: no additional testing/fixup needed.
6686 } else if (handler_.isFunctionCall(*forInitialPart)) {
6687 if (!strictModeErrorAt(exprOffset, JSMSG_BAD_FOR_LEFTSIDE)) {
6688 return false;
6689 }
6690 } else {
6691 errorAt(exprOffset, JSMSG_BAD_FOR_LEFTSIDE);
6692 return false;
6693 }
6694
6695 if (!possibleError.checkForExpressionError()) {
6696 return false;
6697 }
6698
6699 // Finally, parse the iterated expression, making the for-loop's closing
6700 // ')' the next token.
6701 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)
6702 expressionAfterForInOrOf(*forHeadKind, yieldHandling),do { auto parserTryVarTempResult_ = (expressionAfterForInOrOf
(*forHeadKind, yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (*forInOrOfExpression) = parserTryVarTempResult_
.unwrap(); } while (0)
6703 false)do { auto parserTryVarTempResult_ = (expressionAfterForInOrOf
(*forHeadKind, yieldHandling)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (*forInOrOfExpression) = parserTryVarTempResult_
.unwrap(); } while (0)
;
6704 return true;
6705}
6706
6707template <class ParseHandler, typename Unit>
6708typename ParseHandler::NodeResult
6709GeneralParser<ParseHandler, Unit>::forStatement(YieldHandling yieldHandling) {
6710 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", 6710); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::For)"
")"); do { MOZ_CrashSequence(__null, 6710); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6711
6712 uint32_t begin = pos().begin;
6713
6714 ParseContext::Statement stmt(pc_, StatementKind::ForLoop);
6715
6716 IteratorKind iterKind = IteratorKind::Sync;
6717 unsigned iflags = 0;
6718
6719 if (pc_->isAsync() || pc_->sc()->isModuleContext()) {
6720 bool matched;
6721 if (!tokenStream.matchToken(&matched, TokenKind::Await)) {
6722 return errorResult();
6723 }
6724
6725 // If we come across a top level await here, mark the module as async.
6726 if (matched && pc_->sc()->isModuleContext() && !pc_->isAsync()) {
6727 if (!options().topLevelAwait) {
6728 error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED);
6729 return errorResult();
6730 }
6731 pc_->sc()->asModuleContext()->setIsAsync();
6732 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", 6732); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence
(__null, 6732); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
6733 }
6734
6735 if (matched) {
6736 iflags |= JSITER_FORAWAITOF0x80;
6737 iterKind = IteratorKind::Async;
6738 }
6739 }
6740
6741 if (!mustMatchToken(TokenKind::LeftParen, [this](TokenKind actual) {
6742 this->error((actual == TokenKind::Await && !this->pc_->isAsync())
6743 ? JSMSG_FOR_AWAIT_OUTSIDE_ASYNC
6744 : JSMSG_PAREN_AFTER_FOR);
6745 })) {
6746 return errorResult();
6747 }
6748
6749 // ParseNodeKind::ForHead, ParseNodeKind::ForIn, or
6750 // ParseNodeKind::ForOf depending on the loop type.
6751 ParseNodeKind headKind;
6752
6753 // |x| in either |for (x; ...; ...)| or |for (x in/of ...)|.
6754 Node startNode;
6755
6756 // The next two variables are used to implement `for (let/const ...)`.
6757 //
6758 // We generate an implicit block, wrapping the whole loop, to store loop
6759 // variables declared this way. Note that if the loop uses `for (var...)`
6760 // instead, those variables go on some existing enclosing scope, so no
6761 // implicit block scope is created.
6762 //
6763 // Both variables remain null/none if the loop is any other form.
6764
6765 // The static block scope for the implicit block scope.
6766 Maybe<ParseContext::Scope> forLoopLexicalScope;
6767
6768 // The expression being iterated over, for for-in/of loops only. Unused
6769 // for for(;;) loops.
6770 Node iteratedExpr;
6771
6772 // Parse the entirety of the loop-head for a for-in/of loop (so the next
6773 // token is the closing ')'):
6774 //
6775 // for (... in/of ...) ...
6776 // ^next token
6777 //
6778 // ...OR, parse up to the first ';' in a C-style for-loop:
6779 //
6780 // for (...; ...; ...) ...
6781 // ^next token
6782 //
6783 // In either case the subsequent token can be consistently accessed using
6784 // TokenStream::SlashIsDiv semantics.
6785 if (!forHeadStart(yieldHandling, iterKind, &headKind, &startNode,
6786 forLoopLexicalScope, &iteratedExpr)) {
6787 return errorResult();
6788 }
6789
6790 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", 6792); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead"
")"); do { MOZ_CrashSequence(__null, 6792); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6791 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", 6792); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead"
")"); do { MOZ_CrashSequence(__null, 6792); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6792 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", 6792); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf || headKind == ParseNodeKind::ForHead"
")"); do { MOZ_CrashSequence(__null, 6792); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6793
6794 if (iterKind == IteratorKind::Async && headKind != ParseNodeKind::ForOf) {
6795 errorAt(begin, JSMSG_FOR_AWAIT_NOT_OF);
6796 return errorResult();
6797 }
6798
6799 TernaryNodeType forHead;
6800 if (headKind == ParseNodeKind::ForHead) {
6801 Node init = startNode;
6802
6803 // Look for an operand: |for (;| means we might have already examined
6804 // this semicolon with that modifier.
6805 if (!mustMatchToken(TokenKind::Semi, JSMSG_SEMI_AFTER_FOR_INIT)) {
6806 return errorResult();
6807 }
6808
6809 TokenKind tt;
6810 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
6811 return errorResult();
6812 }
6813
6814 Node test;
6815 if (tt == TokenKind::Semi) {
6816 test = null();
6817 } else {
6818 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(); })
;
6819 }
6820
6821 if (!mustMatchToken(TokenKind::Semi, JSMSG_SEMI_AFTER_FOR_COND)) {
6822 return errorResult();
6823 }
6824
6825 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
6826 return errorResult();
6827 }
6828
6829 Node update;
6830 if (tt == TokenKind::RightParen) {
6831 update = null();
6832 } else {
6833 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(); })
;
6834 }
6835
6836 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_FOR_CTRL)) {
6837 return errorResult();
6838 }
6839
6840 TokenPos headPos(begin, pos().end);
6841 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(); })
;
6842 } else {
6843 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", 6844); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf"
")"); do { MOZ_CrashSequence(__null, 6844); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
6844 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", 6844); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "headKind == ParseNodeKind::ForIn || headKind == ParseNodeKind::ForOf"
")"); do { MOZ_CrashSequence(__null, 6844); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6845
6846 // |target| is the LeftHandSideExpression or declaration to which the
6847 // per-iteration value (an arbitrary value exposed by the iteration
6848 // protocol, or a string naming a property) is assigned.
6849 Node target = startNode;
6850
6851 // Parse the rest of the for-in/of head.
6852 if (headKind == ParseNodeKind::ForIn) {
6853 stmt.refineForKind(StatementKind::ForInLoop);
6854 } else {
6855 stmt.refineForKind(StatementKind::ForOfLoop);
6856 }
6857
6858 // Parser::declaration consumed everything up to the closing ')'. That
6859 // token follows an {Assignment,}Expression and so must be interpreted
6860 // as an operand to be consistent with normal expression tokenizing.
6861 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_FOR_CTRL)) {
6862 return errorResult();
6863 }
6864
6865 TokenPos headPos(begin, pos().end);
6866 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(); })
6867 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(); })
;
6868 }
6869
6870 Node body = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
6871
6872 ForNodeType forLoop =
6873 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
(); })
;
6874
6875 if (forLoopLexicalScope) {
6876 return finishLexicalScope(*forLoopLexicalScope, forLoop);
6877 }
6878
6879 return forLoop;
6880}
6881
6882template <class ParseHandler, typename Unit>
6883typename ParseHandler::SwitchStatementResult
6884GeneralParser<ParseHandler, Unit>::switchStatement(
6885 YieldHandling yieldHandling) {
6886 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", 6886); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Switch)"
")"); do { MOZ_CrashSequence(__null, 6886); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
6887 uint32_t begin = pos().begin;
6888
6889 if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_SWITCH)) {
6890 return errorResult();
6891 }
6892
6893 Node discriminant =
6894 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(); })
;
6895
6896 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_SWITCH)) {
6897 return errorResult();
6898 }
6899 if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_SWITCH)) {
6900 return errorResult();
6901 }
6902
6903 ParseContext::Statement stmt(pc_, StatementKind::Switch);
6904 ParseContext::Scope scope(this);
6905 if (!scope.init(pc_)) {
6906 return errorResult();
6907 }
6908
6909 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(); })
;
6910
6911 bool seenDefault = false;
6912 TokenKind tt;
6913 while (true) {
6914 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
6915 return errorResult();
6916 }
6917 if (tt == TokenKind::RightCurly) {
6918 break;
6919 }
6920 uint32_t caseBegin = pos().begin;
6921
6922 Node caseExpr;
6923 switch (tt) {
6924 case TokenKind::Default:
6925 if (seenDefault) {
6926 error(JSMSG_TOO_MANY_DEFAULTS);
6927 return errorResult();
6928 }
6929 seenDefault = true;
6930 caseExpr = null(); // The default case has pn_left == nullptr.
6931 break;
6932
6933 case TokenKind::Case:
6934 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(); })
;
6935 break;
6936
6937 default:
6938 error(JSMSG_BAD_SWITCH);
6939 return errorResult();
6940 }
6941
6942 if (!mustMatchToken(TokenKind::Colon, JSMSG_COLON_AFTER_CASE)) {
6943 return errorResult();
6944 }
6945
6946 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(); })
;
6947
6948 bool afterReturn = false;
6949 bool warnedAboutStatementsAfterReturn = false;
6950 uint32_t statementBegin = 0;
6951 while (true) {
6952 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
6953 return errorResult();
6954 }
6955 if (tt == TokenKind::RightCurly || tt == TokenKind::Case ||
6956 tt == TokenKind::Default) {
6957 break;
6958 }
6959 if (afterReturn) {
6960 if (!tokenStream.peekOffset(&statementBegin,
6961 TokenStream::SlashIsRegExp)) {
6962 return errorResult();
6963 }
6964 }
6965 Node stmt = MOZ_TRY(statementListItem(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementListItem(yieldHandling)); if ((__builtin_expect(!!(
mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
6966 if (!warnedAboutStatementsAfterReturn) {
6967 if (afterReturn) {
6968 if (!handler_.isStatementPermittedAfterReturnStatement(stmt)) {
6969 if (!warningAt(statementBegin, JSMSG_STMT_AFTER_RETURN)) {
6970 return errorResult();
6971 }
6972
6973 warnedAboutStatementsAfterReturn = true;
6974 }
6975 } else if (handler_.isReturnStatement(stmt)) {
6976 afterReturn = true;
6977 }
6978 }
6979 handler_.addStatementToList(body, stmt);
6980 }
6981
6982 CaseClauseType caseClause =
6983 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
(); })
;
6984 handler_.addCaseStatementToList(caseList, caseClause);
6985 }
6986
6987 LexicalScopeNodeType lexicalForCaseList =
6988 MOZ_TRY(finishLexicalScope(scope, caseList))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(finishLexicalScope(scope, caseList)); if ((__builtin_expect(
!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
6989
6990 handler_.setEndPosition(lexicalForCaseList, pos().end);
6991
6992 return handler_.newSwitchStatement(begin, discriminant, lexicalForCaseList,
6993 seenDefault);
6994}
6995
6996template <class ParseHandler, typename Unit>
6997typename ParseHandler::ContinueStatementResult
6998GeneralParser<ParseHandler, Unit>::continueStatement(
6999 YieldHandling yieldHandling) {
7000 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", 7000); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Continue)"
")"); do { MOZ_CrashSequence(__null, 7000); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7001 uint32_t begin = pos().begin;
7002
7003 TaggedParserAtomIndex label;
7004 if (!matchLabel(yieldHandling, &label)) {
7005 return errorResult();
7006 }
7007
7008 auto validity = pc_->checkContinueStatement(label);
7009 if (validity.isErr()) {
7010 switch (validity.unwrapErr()) {
7011 case ParseContext::ContinueStatementError::NotInALoop:
7012 errorAt(begin, JSMSG_BAD_CONTINUE);
7013 break;
7014 case ParseContext::ContinueStatementError::LabelNotFound:
7015 error(JSMSG_LABEL_NOT_FOUND);
7016 break;
7017 }
7018 return errorResult();
7019 }
7020
7021 if (!matchOrInsertSemicolon()) {
7022 return errorResult();
7023 }
7024
7025 return handler_.newContinueStatement(label, TokenPos(begin, pos().end));
7026}
7027
7028template <class ParseHandler, typename Unit>
7029typename ParseHandler::BreakStatementResult
7030GeneralParser<ParseHandler, Unit>::breakStatement(YieldHandling yieldHandling) {
7031 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", 7031); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Break)"
")"); do { MOZ_CrashSequence(__null, 7031); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7032 uint32_t begin = pos().begin;
7033
7034 TaggedParserAtomIndex label;
7035 if (!matchLabel(yieldHandling, &label)) {
7036 return errorResult();
7037 }
7038
7039 auto validity = pc_->checkBreakStatement(label);
7040 if (validity.isErr()) {
7041 switch (validity.unwrapErr()) {
7042 case ParseContext::BreakStatementError::ToughBreak:
7043 errorAt(begin, JSMSG_TOUGH_BREAK);
7044 return errorResult();
7045 case ParseContext::BreakStatementError::LabelNotFound:
7046 error(JSMSG_LABEL_NOT_FOUND);
7047 return errorResult();
7048 }
7049 }
7050
7051 if (!matchOrInsertSemicolon()) {
7052 return errorResult();
7053 }
7054
7055 return handler_.newBreakStatement(label, TokenPos(begin, pos().end));
7056}
7057
7058template <class ParseHandler, typename Unit>
7059typename ParseHandler::UnaryNodeResult
7060GeneralParser<ParseHandler, Unit>::returnStatement(
7061 YieldHandling yieldHandling) {
7062 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", 7062); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Return)"
")"); do { MOZ_CrashSequence(__null, 7062); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7063 uint32_t begin = pos().begin;
7064
7065 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", 7065); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence
(__null, 7065); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
7066
7067 // Parse an optional operand.
7068 //
7069 // This is ugly, but we don't want to require a semicolon.
7070 TokenKind tt = TokenKind::Eof;
7071 if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) {
7072 return errorResult();
7073 }
7074
7075 Node exprNode;
7076 switch (tt) {
7077 case TokenKind::Eol:
7078 case TokenKind::Eof:
7079 case TokenKind::Semi:
7080 case TokenKind::RightCurly:
7081 exprNode = null();
7082 break;
7083 default: {
7084 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(); })
;
7085 }
7086 }
7087
7088 if (!matchOrInsertSemicolon()) {
7089 return errorResult();
7090 }
7091
7092 return handler_.newReturnStatement(exprNode, TokenPos(begin, pos().end));
7093}
7094
7095template <class ParseHandler, typename Unit>
7096typename ParseHandler::UnaryNodeResult
7097GeneralParser<ParseHandler, Unit>::yieldExpression(InHandling inHandling) {
7098 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", 7098); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Yield)"
")"); do { MOZ_CrashSequence(__null, 7098); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7099 uint32_t begin = pos().begin;
7100
7101 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", 7101); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isGenerator()" ")"); do { MOZ_CrashSequence
(__null, 7101); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
7102 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", 7102); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isFunctionBox()" ")"); do { MOZ_CrashSequence
(__null, 7102); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
7103
7104 pc_->lastYieldOffset = begin;
7105
7106 Node exprNode;
7107 ParseNodeKind kind = ParseNodeKind::YieldExpr;
7108 TokenKind tt = TokenKind::Eof;
7109 if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) {
7110 return errorResult();
7111 }
7112 switch (tt) {
7113 // TokenKind::Eol is special; it implements the [no LineTerminator here]
7114 // quirk in the grammar.
7115 case TokenKind::Eol:
7116 // The rest of these make up the complete set of tokens that can
7117 // appear after any of the places where AssignmentExpression is used
7118 // throughout the grammar. Conveniently, none of them can also be the
7119 // start an expression.
7120 case TokenKind::Eof:
7121 case TokenKind::Semi:
7122 case TokenKind::RightCurly:
7123 case TokenKind::RightBracket:
7124 case TokenKind::RightParen:
7125 case TokenKind::Colon:
7126 case TokenKind::Comma:
7127 case TokenKind::In: // Annex B.3.6 `for (x = yield in y) ;`
7128 // No value.
7129 exprNode = null();
7130 break;
7131 case TokenKind::Mul:
7132 kind = ParseNodeKind::YieldStarExpr;
7133 tokenStream.consumeKnownToken(TokenKind::Mul, TokenStream::SlashIsRegExp);
7134 [[fallthrough]];
7135 default:
7136 exprNode =
7137 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(); })
;
7138 }
7139 if (kind == ParseNodeKind::YieldStarExpr) {
7140 return handler_.newYieldStarExpression(begin, exprNode);
7141 }
7142 return handler_.newYieldExpression(begin, exprNode);
7143}
7144
7145template <class ParseHandler, typename Unit>
7146typename ParseHandler::BinaryNodeResult
7147GeneralParser<ParseHandler, Unit>::withStatement(YieldHandling yieldHandling) {
7148 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", 7148); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::With)"
")"); do { MOZ_CrashSequence(__null, 7148); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7149 uint32_t begin = pos().begin;
7150
7151 if (pc_->sc()->strict()) {
7152 if (!strictModeError(JSMSG_STRICT_CODE_WITH)) {
7153 return errorResult();
7154 }
7155 }
7156
7157 if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_WITH)) {
7158 return errorResult();
7159 }
7160
7161 Node objectExpr =
7162 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(); })
;
7163
7164 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_WITH)) {
7165 return errorResult();
7166 }
7167
7168 Node innerBlock;
7169 {
7170 ParseContext::Statement stmt(pc_, StatementKind::With);
7171 innerBlock = MOZ_TRY(statement(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statement(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
7172 }
7173
7174 pc_->sc()->setBindingsAccessedDynamically();
7175
7176 return handler_.newWithStatement(begin, objectExpr, innerBlock);
7177}
7178
7179template <class ParseHandler, typename Unit>
7180typename ParseHandler::NodeResult
7181GeneralParser<ParseHandler, Unit>::labeledItem(YieldHandling yieldHandling) {
7182 TokenKind tt;
7183 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
7184 return errorResult();
7185 }
7186
7187 if (tt == TokenKind::Function) {
7188 TokenKind next;
7189 if (!tokenStream.peekToken(&next)) {
7190 return errorResult();
7191 }
7192
7193 // GeneratorDeclaration is only matched by HoistableDeclaration in
7194 // StatementListItem, so generators can't be inside labels.
7195 if (next == TokenKind::Mul) {
7196 error(JSMSG_GENERATOR_LABEL);
7197 return errorResult();
7198 }
7199
7200 // Per 13.13.1 it's a syntax error if LabelledItem: FunctionDeclaration
7201 // is ever matched. Per Annex B.3.2 that modifies this text, this
7202 // applies only to strict mode code.
7203 if (pc_->sc()->strict()) {
7204 error(JSMSG_FUNCTION_LABEL);
7205 return errorResult();
7206 }
7207
7208 return functionStmt(pos().begin, yieldHandling, NameRequired);
7209 }
7210
7211 anyChars.ungetToken();
7212 return statement(yieldHandling);
7213}
7214
7215template <class ParseHandler, typename Unit>
7216typename ParseHandler::LabeledStatementResult
7217GeneralParser<ParseHandler, Unit>::labeledStatement(
7218 YieldHandling yieldHandling) {
7219 TaggedParserAtomIndex label = labelIdentifier(yieldHandling);
7220 if (!label) {
7221 return errorResult();
7222 }
7223
7224 auto hasSameLabel = [&label](ParseContext::LabelStatement* stmt) {
7225 return stmt->label() == label;
7226 };
7227
7228 uint32_t begin = pos().begin;
7229
7230 if (pc_->template findInnermostStatement<ParseContext::LabelStatement>(
7231 hasSameLabel)) {
7232 errorAt(begin, JSMSG_DUPLICATE_LABEL);
7233 return errorResult();
7234 }
7235
7236 tokenStream.consumeKnownToken(TokenKind::Colon);
7237
7238 /* Push a label struct and parse the statement. */
7239 ParseContext::LabelStatement stmt(pc_, label);
7240 Node pn = MOZ_TRY(labeledItem(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(labeledItem(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
7241
7242 return handler_.newLabeledStatement(label, pn, begin);
7243}
7244
7245template <class ParseHandler, typename Unit>
7246typename ParseHandler::UnaryNodeResult
7247GeneralParser<ParseHandler, Unit>::throwStatement(YieldHandling yieldHandling) {
7248 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", 7248); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Throw)"
")"); do { MOZ_CrashSequence(__null, 7248); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7249 uint32_t begin = pos().begin;
7250
7251 /* ECMA-262 Edition 3 says 'throw [no LineTerminator here] Expr'. */
7252 TokenKind tt = TokenKind::Eof;
7253 if (!tokenStream.peekTokenSameLine(&tt, TokenStream::SlashIsRegExp)) {
7254 return errorResult();
7255 }
7256 if (tt == TokenKind::Eof || tt == TokenKind::Semi ||
7257 tt == TokenKind::RightCurly) {
7258 error(JSMSG_MISSING_EXPR_AFTER_THROW);
7259 return errorResult();
7260 }
7261 if (tt == TokenKind::Eol) {
7262 error(JSMSG_LINE_BREAK_AFTER_THROW);
7263 return errorResult();
7264 }
7265
7266 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(); })
;
7267
7268 if (!matchOrInsertSemicolon()) {
7269 return errorResult();
7270 }
7271
7272 return handler_.newThrowStatement(throwExpr, TokenPos(begin, pos().end));
7273}
7274
7275template <class ParseHandler, typename Unit>
7276typename ParseHandler::TernaryNodeResult
7277GeneralParser<ParseHandler, Unit>::tryStatement(YieldHandling yieldHandling) {
7278 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", 7278); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Try)"
")"); do { MOZ_CrashSequence(__null, 7278); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
7279 uint32_t begin = pos().begin;
7280
7281 /*
7282 * try nodes are ternary.
7283 * kid1 is the try statement
7284 * kid2 is the catch node list or null
7285 * kid3 is the finally statement
7286 *
7287 * catch nodes are binary.
7288 * left is the catch-name/pattern or null
7289 * right is the catch block
7290 *
7291 * catch lvalue nodes are either:
7292 * a single identifier
7293 * TokenKind::RightBracket for a destructuring left-hand side
7294 * TokenKind::RightCurly for a destructuring left-hand side
7295 *
7296 * finally nodes are TokenKind::LeftCurly statement lists.
7297 */
7298
7299 Node innerBlock;
7300 {
7301 if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_TRY)) {
7302 return errorResult();
7303 }
7304
7305 uint32_t openedPos = pos().begin;
7306
7307 ParseContext::Statement stmt(pc_, StatementKind::Try);
7308 ParseContext::Scope scope(this);
7309 if (!scope.init(pc_)) {
7310 return errorResult();
7311 }
7312
7313 innerBlock = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
7314
7315 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(); })
;
7316
7317 if (!mustMatchToken(
7318 TokenKind::RightCurly, [this, openedPos](TokenKind actual) {
7319 this->reportMissingClosing(JSMSG_CURLY_AFTER_TRY,
7320 JSMSG_CURLY_OPENED, openedPos);
7321 })) {
7322 return errorResult();
7323 }
7324 }
7325
7326 LexicalScopeNodeType catchScope = null();
7327 TokenKind tt;
7328 if (!tokenStream.getToken(&tt)) {
7329 return errorResult();
7330 }
7331 if (tt == TokenKind::Catch) {
7332 /*
7333 * Create a lexical scope node around the whole catch clause,
7334 * including the head.
7335 */
7336 ParseContext::Statement stmt(pc_, StatementKind::Catch);
7337 ParseContext::Scope scope(this);
7338 if (!scope.init(pc_)) {
7339 return errorResult();
7340 }
7341
7342 /*
7343 * Legal catch forms are:
7344 * catch (lhs) {
7345 * catch {
7346 * where lhs is a name or a destructuring left-hand side.
7347 */
7348 bool omittedBinding;
7349 if (!tokenStream.matchToken(&omittedBinding, TokenKind::LeftCurly)) {
7350 return errorResult();
7351 }
7352
7353 Node catchName;
7354 if (omittedBinding) {
7355 catchName = null();
7356 } else {
7357 if (!mustMatchToken(TokenKind::LeftParen, JSMSG_PAREN_BEFORE_CATCH)) {
7358 return errorResult();
7359 }
7360
7361 if (!tokenStream.getToken(&tt)) {
7362 return errorResult();
7363 }
7364 switch (tt) {
7365 case TokenKind::LeftBracket:
7366 case TokenKind::LeftCurly:
7367 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(); })
7368 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(); })
;
7369 break;
7370
7371 default: {
7372 if (!TokenKindIsPossibleIdentifierName(tt)) {
7373 error(JSMSG_CATCH_IDENTIFIER);
7374 return errorResult();
7375 }
7376
7377 catchName = MOZ_TRY(bindingIdentifier(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(bindingIdentifier( DeclarationKind::SimpleCatchParameter, yieldHandling
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
7378 DeclarationKind::SimpleCatchParameter, yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(bindingIdentifier( DeclarationKind::SimpleCatchParameter, yieldHandling
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
7379 break;
7380 }
7381 }
7382
7383 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_CATCH)) {
7384 return errorResult();
7385 }
7386
7387 if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_CATCH)) {
7388 return errorResult();
7389 }
7390 }
7391
7392 LexicalScopeNodeType catchBody =
7393 MOZ_TRY(catchBlockStatement(yieldHandling, scope))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(catchBlockStatement(yieldHandling, scope)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
7394
7395 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(); })
;
7396
7397 if (!handler_.setupCatchScope(catchScope, catchName, catchBody)) {
7398 return errorResult();
7399 }
7400 handler_.setEndPosition(catchScope, pos().end);
7401
7402 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
7403 return errorResult();
7404 }
7405 }
7406
7407 Node finallyBlock = null();
7408
7409 if (tt == TokenKind::Finally) {
7410 if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_FINALLY)) {
7411 return errorResult();
7412 }
7413
7414 uint32_t openedPos = pos().begin;
7415
7416 ParseContext::Statement stmt(pc_, StatementKind::Finally);
7417 ParseContext::Scope scope(this);
7418 if (!scope.init(pc_)) {
7419 return errorResult();
7420 }
7421
7422 finallyBlock = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
7423
7424 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(); })
;
7425
7426 if (!mustMatchToken(
7427 TokenKind::RightCurly, [this, openedPos](TokenKind actual) {
7428 this->reportMissingClosing(JSMSG_CURLY_AFTER_FINALLY,
7429 JSMSG_CURLY_OPENED, openedPos);
7430 })) {
7431 return errorResult();
7432 }
7433 } else {
7434 anyChars.ungetToken();
7435 }
7436 if (!catchScope && !finallyBlock) {
7437 error(JSMSG_CATCH_OR_FINALLY);
7438 return errorResult();
7439 }
7440
7441 return handler_.newTryStatement(begin, innerBlock, catchScope, finallyBlock);
7442}
7443
7444template <class ParseHandler, typename Unit>
7445typename ParseHandler::LexicalScopeNodeResult
7446GeneralParser<ParseHandler, Unit>::catchBlockStatement(
7447 YieldHandling yieldHandling, ParseContext::Scope& catchParamScope) {
7448 uint32_t openedPos = pos().begin;
7449
7450 ParseContext::Statement stmt(pc_, StatementKind::Block);
7451
7452 // ES 13.15.7 CatchClauseEvaluation
7453 //
7454 // Step 8 means that the body of a catch block always has an additional
7455 // lexical scope.
7456 ParseContext::Scope scope(this);
7457 if (!scope.init(pc_)) {
7458 return errorResult();
7459 }
7460
7461 // The catch parameter names cannot be redeclared inside the catch
7462 // block, so declare the name in the inner scope.
7463 if (!scope.addCatchParameters(pc_, catchParamScope)) {
7464 return errorResult();
7465 }
7466
7467 ListNodeType list = MOZ_TRY(statementList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(statementList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
7468
7469 if (!mustMatchToken(
7470 TokenKind::RightCurly, [this, openedPos](TokenKind actual) {
7471 this->reportMissingClosing(JSMSG_CURLY_AFTER_CATCH,
7472 JSMSG_CURLY_OPENED, openedPos);
7473 })) {
7474 return errorResult();
7475 }
7476
7477 // The catch parameter names are not bound in the body scope, so remove
7478 // them before generating bindings.
7479 scope.removeCatchParameters(pc_, catchParamScope);
7480 return finishLexicalScope(scope, list);
7481}
7482
7483template <class ParseHandler, typename Unit>
7484typename ParseHandler::DebuggerStatementResult
7485GeneralParser<ParseHandler, Unit>::debuggerStatement() {
7486 TokenPos p;
7487 p.begin = pos().begin;
7488 if (!matchOrInsertSemicolon()) {
7489 return errorResult();
7490 }
7491 p.end = pos().end;
7492
7493 return handler_.newDebuggerStatement(p);
7494}
7495
7496static AccessorType ToAccessorType(PropertyType propType) {
7497 switch (propType) {
7498 case PropertyType::Getter:
7499 return AccessorType::Getter;
7500 case PropertyType::Setter:
7501 return AccessorType::Setter;
7502 case PropertyType::Normal:
7503 case PropertyType::Method:
7504 case PropertyType::GeneratorMethod:
7505 case PropertyType::AsyncMethod:
7506 case PropertyType::AsyncGeneratorMethod:
7507 case PropertyType::Constructor:
7508 case PropertyType::DerivedConstructor:
7509 return AccessorType::None;
7510 default:
7511 MOZ_CRASH("unexpected property type")do { do { } while (false); MOZ_ReportCrash("" "unexpected property type"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 7511); AnnotateMozCrashReason
("MOZ_CRASH(" "unexpected property type" ")"); do { MOZ_CrashSequence
(__null, 7511); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
7512 }
7513}
7514
7515#ifdef ENABLE_DECORATORS
7516template <class ParseHandler, typename Unit>
7517typename ParseHandler::ListNodeResult
7518GeneralParser<ParseHandler, Unit>::decoratorList(YieldHandling yieldHandling) {
7519 ListNodeType decorators =
7520 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
(); })
;
7521
7522 // Build a decorator list element. At each entry point to this loop we have
7523 // already consumed the |@| token
7524 TokenKind tt;
7525 for (;;) {
7526 if (!tokenStream.getToken(&tt, TokenStream::SlashIsInvalid)) {
7527 return errorResult();
7528 }
7529
7530 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(); })
;
7531
7532 handler_.addList(decorators, decorator);
7533
7534 if (!tokenStream.getToken(&tt)) {
7535 return errorResult();
7536 }
7537 if (tt != TokenKind::At) {
7538 anyChars.ungetToken();
7539 break;
7540 }
7541 }
7542 return decorators;
7543}
7544#endif
7545
7546template <class ParseHandler, typename Unit>
7547bool GeneralParser<ParseHandler, Unit>::classMember(
7548 YieldHandling yieldHandling, const ParseContext::ClassStatement& classStmt,
7549 TaggedParserAtomIndex className, uint32_t classStartOffset,
7550 HasHeritage hasHeritage, ClassInitializedMembers& classInitializedMembers,
7551 ListNodeType& classMembers, bool* done) {
7552 *done = false;
7553
7554 TokenKind tt;
7555 if (!tokenStream.getToken(&tt, TokenStream::SlashIsInvalid)) {
7556 return false;
7557 }
7558 if (tt == TokenKind::RightCurly) {
7559 *done = true;
7560 return true;
7561 }
7562
7563 if (tt == TokenKind::Semi) {
7564 return true;
7565 }
7566
7567#ifdef ENABLE_DECORATORS
7568 ListNodeType decorators = null();
7569 if (tt == TokenKind::At) {
7570 if (fuzzingSafe) {
7571 error(JSMSG_DECORATOR_FUZZING_UNSAFE);
7572 return false;
7573 }
7574
7575 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)
;
7576
7577 if (!tokenStream.getToken(&tt, TokenStream::SlashIsInvalid)) {
7578 return false;
7579 }
7580 }
7581#endif
7582
7583 bool isStatic = false;
7584 if (tt == TokenKind::Static) {
7585 if (!tokenStream.peekToken(&tt)) {
7586 return false;
7587 }
7588
7589 if (tt == TokenKind::LeftCurly) {
7590 /* Parsing static class block: static { ... } */
7591 FunctionNodeType staticBlockBody;
7592 MOZ_TRY_VAR_OR_RETURN(staticBlockBody,do { auto parserTryVarTempResult_ = (staticClassBlock(classInitializedMembers
)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr())
, 0))) { return (false); } (staticBlockBody) = parserTryVarTempResult_
.unwrap(); } while (0)
7593 staticClassBlock(classInitializedMembers), false)do { auto parserTryVarTempResult_ = (staticClassBlock(classInitializedMembers
)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr())
, 0))) { return (false); } (staticBlockBody) = parserTryVarTempResult_
.unwrap(); } while (0)
;
7594
7595 StaticClassBlockType classBlock;
7596 MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (handler_.newStaticClassBlock
(staticBlockBody)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (classBlock) = parserTryVarTempResult_
.unwrap(); } while (0)
7597 classBlock, handler_.newStaticClassBlock(staticBlockBody), false)do { auto parserTryVarTempResult_ = (handler_.newStaticClassBlock
(staticBlockBody)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (classBlock) = parserTryVarTempResult_
.unwrap(); } while (0)
;
7598
7599 return handler_.addClassMemberDefinition(classMembers, classBlock);
7600 }
7601
7602 if (tt != TokenKind::LeftParen && tt != TokenKind::Assign &&
7603 tt != TokenKind::Semi && tt != TokenKind::RightCurly) {
7604 isStatic = true;
7605 } else {
7606 anyChars.ungetToken();
7607 }
7608 } else {
7609 anyChars.ungetToken();
7610 }
7611
7612 uint32_t propNameOffset;
7613 if (!tokenStream.peekOffset(&propNameOffset, TokenStream::SlashIsInvalid)) {
7614 return false;
7615 }
7616
7617 TaggedParserAtomIndex propAtom;
7618 PropertyType propType;
7619 Node propName;
7620 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)
7621 propName,do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling
, PropertyNameInClass, Nothing(), classMembers, &propType
, &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_
.unwrap(); } while (0)
7622 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)
7623 /* 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)
7624 &propAtom),do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling
, PropertyNameInClass, Nothing(), classMembers, &propType
, &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_
.unwrap(); } while (0)
7625 false)do { auto parserTryVarTempResult_ = (propertyOrMethodName(yieldHandling
, PropertyNameInClass, Nothing(), classMembers, &propType
, &propAtom)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (propName) = parserTryVarTempResult_
.unwrap(); } while (0)
;
7626
7627#ifdef ENABLE_DECORATORS
7628 if (!propAtom &&
7629 (decorators || propType == PropertyType::FieldWithAccessor)) {
7630 error(JSMSG_DECORATOR_COMPUTED_NYI);
7631 return false;
7632 }
7633#endif
7634
7635 if (propType == PropertyType::Field ||
7636 propType == PropertyType::FieldWithAccessor) {
7637 if (isStatic) {
7638 if (propAtom == TaggedParserAtomIndex::WellKnown::prototype()) {
7639 errorAt(propNameOffset, JSMSG_CLASS_STATIC_PROTO);
7640 return false;
7641 }
7642 }
7643
7644 if (propAtom == TaggedParserAtomIndex::WellKnown::constructor()) {
7645 errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF);
7646 return false;
7647 }
7648
7649 if (handler_.isPrivateName(propName)) {
7650 if (propAtom == TaggedParserAtomIndex::WellKnown::hash_constructor_()) {
7651 errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF);
7652 return false;
7653 }
7654
7655 auto privateName = propAtom;
7656 if (!noteDeclaredPrivateName(
7657 propName, privateName, propType,
7658 isStatic ? FieldPlacement::Static : FieldPlacement::Instance,
7659 pos())) {
7660 return false;
7661 }
7662 }
7663
7664#ifdef ENABLE_DECORATORS
7665 ClassMethodType accessorGetterNode = null();
7666 ClassMethodType accessorSetterNode = null();
7667 if (propType == PropertyType::FieldWithAccessor) {
7668 // Decorators Proposal
7669 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-runtime-semantics-classfielddefinitionevaluation
7670 //
7671 // FieldDefinition : accessor ClassElementName Initializeropt
7672 //
7673 // Step 1. Let name be the result of evaluating ClassElementName.
7674 // ...
7675 // Step 3. Let privateStateDesc be the string-concatenation of name
7676 // and " accessor storage".
7677 StringBuilder privateStateDesc(fc_);
7678 if (!privateStateDesc.append(this->parserAtoms(), propAtom)) {
7679 return false;
7680 }
7681 if (!privateStateDesc.append(" accessor storage")) {
7682 return false;
7683 }
7684 // Step 4. Let privateStateName be a new Private Name whose
7685 // [[Description]] value is privateStateDesc.
7686 TokenPos propNamePos(propNameOffset, pos().end);
7687 auto privateStateName =
7688 privateStateDesc.finishParserAtom(this->parserAtoms(), fc_);
7689 if (!noteDeclaredPrivateName(
7690 propName, privateStateName, propType,
7691 isStatic ? FieldPlacement::Static : FieldPlacement::Instance,
7692 propNamePos)) {
7693 return false;
7694 }
7695
7696 // Step 5. Let getter be MakeAutoAccessorGetter(homeObject, name,
7697 // privateStateName).
7698 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)
7699 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)
7700 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)
7701 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)
7702 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)
7703 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)
;
7704
7705 // If the accessor is not decorated or is a non-static private field,
7706 // add it to the class here. Otherwise, we'll handle this when the
7707 // decorators are called. We don't need to keep a reference to the node
7708 // after this except for non-static private accessors. Please see the
7709 // comment in the definition of ClassField for details.
7710 bool addAccessorImmediately =
7711 !decorators || (!isStatic && handler_.isPrivateName(propName));
7712 if (addAccessorImmediately) {
7713 if (!handler_.addClassMemberDefinition(classMembers,
7714 accessorGetterNode)) {
7715 return false;
7716 }
7717 if (!handler_.isPrivateName(propName)) {
7718 accessorGetterNode = null();
7719 }
7720 }
7721
7722 // Step 6. Let setter be MakeAutoAccessorSetter(homeObject, name,
7723 // privateStateName).
7724 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)
7725 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)
7726 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)
7727 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)
7728 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)
7729 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)
;
7730
7731 if (addAccessorImmediately) {
7732 if (!handler_.addClassMemberDefinition(classMembers,
7733 accessorSetterNode)) {
7734 return false;
7735 }
7736 if (!handler_.isPrivateName(propName)) {
7737 accessorSetterNode = null();
7738 }
7739 }
7740
7741 // Step 10. Return ClassElementDefinition Record { [[Key]]: name,
7742 // [[Kind]]: accessor, [[Get]]: getter, [[Set]]: setter,
7743 // [[BackingStorageKey]]: privateStateName, [[Initializers]]:
7744 // initializers, [[Decorators]]: empty }.
7745 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)
7746 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)
;
7747 propAtom = privateStateName;
7748 // We maintain `decorators` here to perform this step at the same time:
7749 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-static-semantics-classelementevaluation
7750 // 4. Set fieldDefinition.[[Decorators]] to decorators.
7751 }
7752#endif
7753 if (isStatic) {
7754 classInitializedMembers.staticFields++;
7755 } else {
7756 classInitializedMembers.instanceFields++;
7757#ifdef ENABLE_DECORATORS
7758 if (decorators) {
7759 classInitializedMembers.hasInstanceDecorators = true;
7760 }
7761#endif
7762 }
7763
7764 TokenPos propNamePos(propNameOffset, pos().end);
7765 FunctionNodeType initializer;
7766 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)
7767 initializer,do { auto parserTryVarTempResult_ = (fieldInitializerOpt(propNamePos
, propName, propAtom, classInitializedMembers, isStatic, hasHeritage
)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr())
, 0))) { return (false); } (initializer) = parserTryVarTempResult_
.unwrap(); } while (0)
7768 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)
7769 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)
7770 false)do { auto parserTryVarTempResult_ = (fieldInitializerOpt(propNamePos
, propName, propAtom, classInitializedMembers, isStatic, hasHeritage
)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr())
, 0))) { return (false); } (initializer) = parserTryVarTempResult_
.unwrap(); } while (0)
;
7771
7772 if (!matchOrInsertSemicolon(TokenStream::SlashIsInvalid)) {
7773 return false;
7774 }
7775
7776 ClassFieldType field;
7777 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)
7778 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)
7779 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)
7780#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)
7781 ,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)
7782 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)
7783#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)
7784 ),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)
7785 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)
;
7786
7787 return handler_.addClassMemberDefinition(classMembers, field);
7788 }
7789
7790 if (propType != PropertyType::Getter && propType != PropertyType::Setter &&
7791 propType != PropertyType::Method &&
7792 propType != PropertyType::GeneratorMethod &&
7793 propType != PropertyType::AsyncMethod &&
7794 propType != PropertyType::AsyncGeneratorMethod) {
7795 errorAt(propNameOffset, JSMSG_BAD_CLASS_MEMBER_DEF);
7796 return false;
7797 }
7798
7799 bool isConstructor =
7800 !isStatic && propAtom == TaggedParserAtomIndex::WellKnown::constructor();
7801 if (isConstructor) {
7802 if (propType != PropertyType::Method) {
7803 errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF);
7804 return false;
7805 }
7806 if (classStmt.constructorBox) {
7807 errorAt(propNameOffset, JSMSG_DUPLICATE_CONSTRUCTOR);
7808 return false;
7809 }
7810 propType = hasHeritage == HasHeritage::Yes
7811 ? PropertyType::DerivedConstructor
7812 : PropertyType::Constructor;
7813 } else if (isStatic &&
7814 propAtom == TaggedParserAtomIndex::WellKnown::prototype()) {
7815 errorAt(propNameOffset, JSMSG_CLASS_STATIC_PROTO);
7816 return false;
7817 }
7818
7819 TaggedParserAtomIndex funName;
7820 switch (propType) {
7821 case PropertyType::Getter:
7822 case PropertyType::Setter: {
7823 bool hasStaticName =
7824 !anyChars.isCurrentTokenType(TokenKind::RightBracket) && propAtom;
7825 if (hasStaticName) {
7826 funName = prefixAccessorName(propType, propAtom);
7827 if (!funName) {
7828 return false;
7829 }
7830 }
7831 break;
7832 }
7833 case PropertyType::Constructor:
7834 case PropertyType::DerivedConstructor:
7835 funName = className;
7836 break;
7837 default:
7838 if (!anyChars.isCurrentTokenType(TokenKind::RightBracket)) {
7839 funName = propAtom;
7840 }
7841 }
7842
7843 // When |super()| is invoked, we search for the nearest scope containing
7844 // |.initializers| to initialize the class fields. This set-up precludes
7845 // declaring |.initializers| in the class scope, because in some syntactic
7846 // contexts |super()| can appear nested in a class, while actually belonging
7847 // to an outer class definition.
7848 //
7849 // Example:
7850 // class Outer extends Base {
7851 // field = 1;
7852 // constructor() {
7853 // class Inner {
7854 // field = 2;
7855 //
7856 // // The super() call in the computed property name mustn't access
7857 // // Inner's |.initializers| array, but instead Outer's.
7858 // [super()]() {}
7859 // }
7860 // }
7861 // }
7862 Maybe<ParseContext::Scope> dotInitializersScope;
7863 if (isConstructor && !options().selfHostingMode) {
7864 dotInitializersScope.emplace(this);
7865 if (!dotInitializersScope->init(pc_)) {
7866 return false;
7867 }
7868
7869 if (!noteDeclaredName(TaggedParserAtomIndex::WellKnown::dot_initializers_(),
7870 DeclarationKind::Let, pos())) {
7871 return false;
7872 }
7873
7874#ifdef ENABLE_DECORATORS
7875 if (!noteDeclaredName(
7876 TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_(),
7877 DeclarationKind::Let, pos())) {
7878 return false;
7879 }
7880#endif
7881 }
7882
7883 // Calling toString on constructors need to return the source text for
7884 // the entire class. The end offset is unknown at this point in
7885 // parsing and will be amended when class parsing finishes below.
7886 FunctionNodeType funNode;
7887 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)
7888 funNode,do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor
? classStartOffset : propNameOffset, propType, funName)); if
((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0)))
{ return (false); } (funNode) = parserTryVarTempResult_.unwrap
(); } while (0)
7889 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)
7890 propType, funName),do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor
? classStartOffset : propNameOffset, propType, funName)); if
((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0)))
{ return (false); } (funNode) = parserTryVarTempResult_.unwrap
(); } while (0)
7891 false)do { auto parserTryVarTempResult_ = (methodDefinition(isConstructor
? classStartOffset : propNameOffset, propType, funName)); if
((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0)))
{ return (false); } (funNode) = parserTryVarTempResult_.unwrap
(); } while (0)
;
7892
7893 AccessorType atype = ToAccessorType(propType);
7894
7895 Maybe<FunctionNodeType> initializerIfPrivate = Nothing();
7896 if (handler_.isPrivateName(propName)) {
7897 if (propAtom == TaggedParserAtomIndex::WellKnown::hash_constructor_()) {
7898 // #constructor is an invalid private name.
7899 errorAt(propNameOffset, JSMSG_BAD_CONSTRUCTOR_DEF);
7900 return false;
7901 }
7902
7903 TaggedParserAtomIndex privateName = propAtom;
7904 if (!noteDeclaredPrivateName(
7905 propName, privateName, propType,
7906 isStatic ? FieldPlacement::Static : FieldPlacement::Instance,
7907 pos())) {
7908 return false;
7909 }
7910
7911 // Private non-static methods are stored in the class body environment.
7912 // Private non-static accessors are stamped onto every instance using
7913 // initializers. Private static methods are stamped onto the constructor
7914 // during class evaluation; see BytecodeEmitter::emitPropertyList.
7915 if (!isStatic) {
7916 if (atype == AccessorType::Getter || atype == AccessorType::Setter) {
7917 classInitializedMembers.privateAccessors++;
7918 TokenPos propNamePos(propNameOffset, pos().end);
7919 FunctionNodeType initializerNode;
7920 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)
7921 initializerNode,do { auto parserTryVarTempResult_ = (synthesizePrivateMethodInitializer
(propAtom, atype, propNamePos)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (initializerNode) = parserTryVarTempResult_
.unwrap(); } while (0)
7922 synthesizePrivateMethodInitializer(propAtom, atype, propNamePos),do { auto parserTryVarTempResult_ = (synthesizePrivateMethodInitializer
(propAtom, atype, propNamePos)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (initializerNode) = parserTryVarTempResult_
.unwrap(); } while (0)
7923 false)do { auto parserTryVarTempResult_ = (synthesizePrivateMethodInitializer
(propAtom, atype, propNamePos)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (initializerNode) = parserTryVarTempResult_
.unwrap(); } while (0)
;
7924 initializerIfPrivate = Some(initializerNode);
7925 } else {
7926 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", 7926); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "atype == AccessorType::None" ")"); do { MOZ_CrashSequence
(__null, 7926); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
7927 classInitializedMembers.privateMethods++;
7928 }
7929 }
7930 }
7931
7932#ifdef ENABLE_DECORATORS
7933 if (decorators) {
7934 classInitializedMembers.hasInstanceDecorators = true;
7935 }
7936#endif
7937
7938 Node method;
7939 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)
7940 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)
7941 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)
7942 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)
7943#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)
7944 ,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)
7945 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)
7946#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)
7947 ),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)
7948 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)
;
7949
7950 if (dotInitializersScope.isSome()) {
7951 MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (finishLexicalScope(*dotInitializersScope
, method)); if ((__builtin_expect(!!(parserTryVarTempResult_.
isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_
.unwrap(); } while (0)
7952 method, finishLexicalScope(*dotInitializersScope, method), false)do { auto parserTryVarTempResult_ = (finishLexicalScope(*dotInitializersScope
, method)); if ((__builtin_expect(!!(parserTryVarTempResult_.
isErr()), 0))) { return (false); } (method) = parserTryVarTempResult_
.unwrap(); } while (0)
;
7953 dotInitializersScope.reset();
7954 }
7955
7956 return handler_.addClassMemberDefinition(classMembers, method);
7957}
7958
7959template <class ParseHandler, typename Unit>
7960bool GeneralParser<ParseHandler, Unit>::finishClassConstructor(
7961 const ParseContext::ClassStatement& classStmt,
7962 TaggedParserAtomIndex className, HasHeritage hasHeritage,
7963 uint32_t classStartOffset, uint32_t classEndOffset,
7964 const ClassInitializedMembers& classInitializedMembers,
7965 ListNodeType& classMembers) {
7966 if (classStmt.constructorBox == nullptr) {
7967 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", 7967); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!options().selfHostingMode" ")"); do { MOZ_CrashSequence
(__null, 7967); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
7968 // Unconditionally create the scope here, because it's always the
7969 // constructor.
7970 ParseContext::Scope dotInitializersScope(this);
7971 if (!dotInitializersScope.init(pc_)) {
7972 return false;
7973 }
7974
7975 if (!noteDeclaredName(TaggedParserAtomIndex::WellKnown::dot_initializers_(),
7976 DeclarationKind::Let, pos())) {
7977 return false;
7978 }
7979
7980#ifdef ENABLE_DECORATORS
7981 if (!noteDeclaredName(
7982 TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_(),
7983 DeclarationKind::Let, pos(), ClosedOver::Yes)) {
7984 return false;
7985 }
7986#endif
7987
7988 // synthesizeConstructor assigns to classStmt.constructorBox
7989 TokenPos synthesizedBodyPos(classStartOffset, classEndOffset);
7990 FunctionNodeType synthesizedCtor;
7991 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)
7992 synthesizedCtor,do { auto parserTryVarTempResult_ = (synthesizeConstructor(className
, synthesizedBodyPos, hasHeritage)); if ((__builtin_expect(!!
(parserTryVarTempResult_.isErr()), 0))) { return (false); } (
synthesizedCtor) = parserTryVarTempResult_.unwrap(); } while (
0)
7993 synthesizeConstructor(className, synthesizedBodyPos, hasHeritage),do { auto parserTryVarTempResult_ = (synthesizeConstructor(className
, synthesizedBodyPos, hasHeritage)); if ((__builtin_expect(!!
(parserTryVarTempResult_.isErr()), 0))) { return (false); } (
synthesizedCtor) = parserTryVarTempResult_.unwrap(); } while (
0)
7994 false)do { auto parserTryVarTempResult_ = (synthesizeConstructor(className
, synthesizedBodyPos, hasHeritage)); if ((__builtin_expect(!!
(parserTryVarTempResult_.isErr()), 0))) { return (false); } (
synthesizedCtor) = parserTryVarTempResult_.unwrap(); } while (
0)
;
7995
7996 // Note: the *function* has the name of the class, but the *property*
7997 // containing the function has the name "constructor"
7998 Node constructorNameNode;
7999 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)
8000 constructorNameNode,do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName
( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if
((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0)))
{ return (false); } (constructorNameNode) = parserTryVarTempResult_
.unwrap(); } while (0)
8001 handler_.newObjectLiteralPropertyName(do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName
( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if
((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0)))
{ return (false); } (constructorNameNode) = parserTryVarTempResult_
.unwrap(); } while (0)
8002 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)
8003 false)do { auto parserTryVarTempResult_ = (handler_.newObjectLiteralPropertyName
( TaggedParserAtomIndex::WellKnown::constructor(), pos())); if
((__builtin_expect(!!(parserTryVarTempResult_.isErr()), 0)))
{ return (false); } (constructorNameNode) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8004 ClassMethodType method;
8005 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)
8006 handler_.newDefaultClassConstructor(do { auto parserTryVarTempResult_ = (handler_.newDefaultClassConstructor
( constructorNameNode, synthesizedCtor)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(method) = parserTryVarTempResult_.unwrap(); } while (0)
8007 constructorNameNode, synthesizedCtor),do { auto parserTryVarTempResult_ = (handler_.newDefaultClassConstructor
( constructorNameNode, synthesizedCtor)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(method) = parserTryVarTempResult_.unwrap(); } while (0)
8008 false)do { auto parserTryVarTempResult_ = (handler_.newDefaultClassConstructor
( constructorNameNode, synthesizedCtor)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(method) = parserTryVarTempResult_.unwrap(); } while (0)
;
8009 LexicalScopeNodeType scope;
8010 MOZ_TRY_VAR_OR_RETURN(do { auto parserTryVarTempResult_ = (finishLexicalScope(dotInitializersScope
, method)); if ((__builtin_expect(!!(parserTryVarTempResult_.
isErr()), 0))) { return (false); } (scope) = parserTryVarTempResult_
.unwrap(); } while (0)
8011 scope, finishLexicalScope(dotInitializersScope, method), false)do { auto parserTryVarTempResult_ = (finishLexicalScope(dotInitializersScope
, method)); if ((__builtin_expect(!!(parserTryVarTempResult_.
isErr()), 0))) { return (false); } (scope) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8012 if (!handler_.addClassMemberDefinition(classMembers, scope)) {
8013 return false;
8014 }
8015 }
8016
8017 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", 8017); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "classStmt.constructorBox" ")"); do { MOZ_CrashSequence
(__null, 8017); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
8018 FunctionBox* ctorbox = classStmt.constructorBox;
8019
8020 // Amend the toStringEnd offset for the constructor now that we've
8021 // finished parsing the class.
8022 ctorbox->setCtorToStringEnd(classEndOffset);
8023
8024 size_t numMemberInitializers = classInitializedMembers.privateAccessors +
8025 classInitializedMembers.instanceFields;
8026 bool hasPrivateBrand = classInitializedMembers.hasPrivateBrand();
8027 if (hasPrivateBrand || numMemberInitializers > 0) {
8028 // Now that we have full set of initializers, update the constructor.
8029 MemberInitializers initializers(
8030 hasPrivateBrand,
8031#ifdef ENABLE_DECORATORS
8032 classInitializedMembers.hasInstanceDecorators,
8033#endif
8034 numMemberInitializers);
8035 ctorbox->setMemberInitializers(initializers);
8036
8037 // Field initialization need access to `this`.
8038 ctorbox->setCtorFunctionHasThisBinding();
8039 }
8040
8041 return true;
8042}
8043
8044template <class ParseHandler, typename Unit>
8045typename ParseHandler::ClassNodeResult
8046GeneralParser<ParseHandler, Unit>::classDefinition(
8047 YieldHandling yieldHandling, ClassContext classContext,
8048 DefaultHandling defaultHandling) {
8049#ifdef ENABLE_DECORATORS
8050 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", 8051); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class)"
")"); do { MOZ_CrashSequence(__null, 8051); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
8051 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", 8051); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::At) || anyChars.isCurrentTokenType(TokenKind::Class)"
")"); do { MOZ_CrashSequence(__null, 8051); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8052
8053 ListNodeType decorators = null();
8054 FunctionNodeType addInitializerFunction = null();
8055 if (anyChars.isCurrentTokenType(TokenKind::At)) {
8056 if (fuzzingSafe) {
8057 error(JSMSG_DECORATOR_FUZZING_UNSAFE);
8058 return errorResult();
8059 }
8060
8061 decorators = MOZ_TRY(decoratorList(yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(decoratorList(yieldHandling)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
8062 TokenKind next;
8063 if (!tokenStream.getToken(&next)) {
8064 return errorResult();
8065 }
8066 if (next != TokenKind::Class) {
8067 error(JSMSG_CLASS_EXPECTED);
8068 return errorResult();
8069 }
8070 }
8071#else
8072 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", 8072); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Class)"
")"); do { MOZ_CrashSequence(__null, 8072); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8073#endif
8074
8075 uint32_t classStartOffset = pos().begin;
8076 bool savedStrictness = setLocalStrictMode(true);
8077
8078 // Classes are quite broken in self-hosted code.
8079 if (options().selfHostingMode) {
8080 error(JSMSG_SELFHOSTED_CLASS);
8081 return errorResult();
8082 }
8083
8084 TokenKind tt;
8085 if (!tokenStream.getToken(&tt)) {
8086 return errorResult();
8087 }
8088
8089 TaggedParserAtomIndex className;
8090 if (TokenKindIsPossibleIdentifier(tt)) {
8091 className = bindingIdentifier(yieldHandling);
8092 if (!className) {
8093 return errorResult();
8094 }
8095 } else if (classContext == ClassStatement) {
8096 if (defaultHandling == AllowDefaultName) {
8097 className = TaggedParserAtomIndex::WellKnown::default_();
8098 anyChars.ungetToken();
8099 } else {
8100 // Class statements must have a bound name
8101 error(JSMSG_UNNAMED_CLASS_STMT);
8102 return errorResult();
8103 }
8104 } else {
8105 // Make sure to put it back, whatever it was
8106 anyChars.ungetToken();
8107 }
8108
8109 // Because the binding definitions keep track of their blockId, we need to
8110 // create at least the inner binding later. Keep track of the name's
8111 // position in order to provide it for the nodes created later.
8112 TokenPos namePos = pos();
8113
8114 auto isClass = [](ParseContext::Statement* stmt) {
8115 return stmt->kind() == StatementKind::Class;
8116 };
8117
8118 bool isInClass = pc_->sc()->inClass() || pc_->findInnermostStatement(isClass);
8119
8120 // Push a ParseContext::ClassStatement to keep track of the constructor
8121 // funbox.
8122 ParseContext::ClassStatement classStmt(pc_);
8123
8124 NameNodeType innerName;
8125 Node nameNode = null();
8126 Node classHeritage = null();
8127 LexicalScopeNodeType classBlock = null();
8128 ClassBodyScopeNodeType classBodyBlock = null();
8129 uint32_t classEndOffset;
8130 {
8131 // A named class creates a new lexical scope with a const binding of the
8132 // class name for the "inner name".
8133 ParseContext::Statement innerScopeStmt(pc_, StatementKind::Block);
8134 ParseContext::Scope innerScope(this);
8135 if (!innerScope.init(pc_)) {
8136 return errorResult();
8137 }
8138
8139 bool hasHeritageBool;
8140 if (!tokenStream.matchToken(&hasHeritageBool, TokenKind::Extends)) {
8141 return errorResult();
8142 }
8143 HasHeritage hasHeritage =
8144 hasHeritageBool ? HasHeritage::Yes : HasHeritage::No;
8145 if (hasHeritage == HasHeritage::Yes) {
8146 if (!tokenStream.getToken(&tt)) {
8147 return errorResult();
8148 }
8149 classHeritage =
8150 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
(); })
;
8151 }
8152
8153 if (!mustMatchToken(TokenKind::LeftCurly, JSMSG_CURLY_BEFORE_CLASS)) {
8154 return errorResult();
8155 }
8156
8157 {
8158 ParseContext::Statement bodyScopeStmt(pc_, StatementKind::Block);
8159 ParseContext::Scope bodyScope(this);
8160 if (!bodyScope.init(pc_)) {
8161 return errorResult();
8162 }
8163
8164 ListNodeType classMembers =
8165 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(); })
;
8166
8167 ClassInitializedMembers classInitializedMembers{};
8168 for (;;) {
8169 bool done;
8170 if (!classMember(yieldHandling, classStmt, className, classStartOffset,
8171 hasHeritage, classInitializedMembers, classMembers,
8172 &done)) {
8173 return errorResult();
8174 }
8175 if (done) {
8176 break;
8177 }
8178 }
8179#ifdef ENABLE_DECORATORS
8180 if (classInitializedMembers.hasInstanceDecorators) {
8181 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(); })
8182 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(); })
8183 yieldHandling))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(synthesizeAddInitializerFunction( TaggedParserAtomIndex::WellKnown
::dot_instanceExtraInitializers_(), yieldHandling)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
8184 }
8185#endif
8186
8187 if (classInitializedMembers.privateMethods +
8188 classInitializedMembers.privateAccessors >
8189 0) {
8190 // We declare `.privateBrand` as ClosedOver because the constructor
8191 // always uses it, even a default constructor. We could equivalently
8192 // `noteUsedName` when parsing the constructor, except that at that
8193 // time, we don't necessarily know if the class has a private brand.
8194 if (!noteDeclaredName(
8195 TaggedParserAtomIndex::WellKnown::dot_privateBrand_(),
8196 DeclarationKind::Synthetic, namePos, ClosedOver::Yes)) {
8197 return errorResult();
8198 }
8199 }
8200
8201 if (classInitializedMembers.instanceFieldKeys > 0) {
8202 if (!noteDeclaredName(
8203 TaggedParserAtomIndex::WellKnown::dot_fieldKeys_(),
8204 DeclarationKind::Synthetic, namePos)) {
8205 return errorResult();
8206 }
8207 }
8208
8209 if (classInitializedMembers.staticFields > 0) {
8210 if (!noteDeclaredName(
8211 TaggedParserAtomIndex::WellKnown::dot_staticInitializers_(),
8212 DeclarationKind::Synthetic, namePos)) {
8213 return errorResult();
8214 }
8215 }
8216
8217 if (classInitializedMembers.staticFieldKeys > 0) {
8218 if (!noteDeclaredName(
8219 TaggedParserAtomIndex::WellKnown::dot_staticFieldKeys_(),
8220 DeclarationKind::Synthetic, namePos)) {
8221 return errorResult();
8222 }
8223 }
8224
8225 classEndOffset = pos().end;
8226 if (!finishClassConstructor(classStmt, className, hasHeritage,
8227 classStartOffset, classEndOffset,
8228 classInitializedMembers, classMembers)) {
8229 return errorResult();
8230 }
8231
8232 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(); })
;
8233
8234 // Pop the class body scope
8235 }
8236
8237 if (className) {
8238 // The inner name is immutable.
8239 if (!noteDeclaredName(className, DeclarationKind::Const, namePos)) {
8240 return errorResult();
8241 }
8242
8243 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(); })
;
8244 }
8245
8246 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(); })
;
8247
8248 // Pop the inner scope.
8249 }
8250
8251 if (className) {
8252 NameNodeType outerName = null();
8253 if (classContext == ClassStatement) {
8254 // The outer name is mutable.
8255 if (!noteDeclaredName(className, DeclarationKind::Class, namePos)) {
8256 return errorResult();
8257 }
8258
8259 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(); })
;
8260 }
8261
8262 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
(); })
;
8263 }
8264 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"
, 8264); AnnotateMozCrashReason("MOZ_CRASH(" "setLocalStrictMode(savedStrictness)"
")"); do { MOZ_CrashSequence(__null, 8264); __attribute__((nomerge
)) ::abort(); } while (false); } while (false); } } while (false
)
;
8265 // We're leaving a class definition that was not itself nested within a class
8266 if (!isInClass) {
8267 mozilla::Maybe<UnboundPrivateName> maybeUnboundName;
8268 if (!usedNames_.hasUnboundPrivateNames(fc_, maybeUnboundName)) {
8269 return errorResult();
8270 }
8271 if (maybeUnboundName) {
8272 UniqueChars str =
8273 this->parserAtoms().toPrintableString(maybeUnboundName->atom);
8274 if (!str) {
8275 ReportOutOfMemory(this->fc_);
8276 return errorResult();
8277 }
8278
8279 errorAt(maybeUnboundName->position.begin, JSMSG_MISSING_PRIVATE_DECL,
8280 str.get());
8281 return errorResult();
8282 }
8283 }
8284
8285 return handler_.newClass(nameNode, classHeritage, classBlock,
8286#ifdef ENABLE_DECORATORS
8287 decorators, addInitializerFunction,
8288#endif
8289 TokenPos(classStartOffset, classEndOffset));
8290}
8291
8292template <class ParseHandler, typename Unit>
8293typename ParseHandler::FunctionNodeResult
8294GeneralParser<ParseHandler, Unit>::synthesizeConstructor(
8295 TaggedParserAtomIndex className, TokenPos synthesizedBodyPos,
8296 HasHeritage hasHeritage) {
8297 FunctionSyntaxKind functionSyntaxKind =
8298 hasHeritage == HasHeritage::Yes
8299 ? FunctionSyntaxKind::DerivedClassConstructor
8300 : FunctionSyntaxKind::ClassConstructor;
8301
8302 bool isSelfHosting = options().selfHostingMode;
8303 FunctionFlags flags =
8304 InitialFunctionFlags(functionSyntaxKind, GeneratorKind::NotGenerator,
8305 FunctionAsyncKind::SyncFunction, isSelfHosting);
8306
8307 // Create the top-level field initializer node.
8308 FunctionNodeType funNode =
8309 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(); })
;
8310
8311 // If we see any inner function, note it on our current context. The bytecode
8312 // emitter may eliminate the function later, but we use a conservative
8313 // definition for consistency between lazy and full parsing.
8314 pc_->sc()->setHasInnerFunctions();
8315
8316 // When fully parsing a lazy script, we do not fully reparse its inner
8317 // functions, which are also lazy. Instead, their free variables and source
8318 // extents are recorded and may be skipped.
8319 if (handler_.reuseLazyInnerFunctions()) {
8320 if (!skipLazyInnerFunction(funNode, synthesizedBodyPos.begin,
8321 /* tryAnnexB = */ false)) {
8322 return errorResult();
8323 }
8324
8325 return funNode;
8326 }
8327
8328 // Create the FunctionBox and link it to the function object.
8329 Directives directives(true);
8330 FunctionBox* funbox = newFunctionBox(
8331 funNode, className, flags, synthesizedBodyPos.begin, directives,
8332 GeneratorKind::NotGenerator, FunctionAsyncKind::SyncFunction);
8333 if (!funbox) {
8334 return errorResult();
8335 }
8336 funbox->initWithEnclosingParseContext(pc_, functionSyntaxKind);
8337 setFunctionEndFromCurrentToken(funbox);
8338
8339 // Mark this function as being synthesized by the parser. This means special
8340 // handling in delazification will be used since we don't have typical
8341 // function syntax.
8342 funbox->setSyntheticFunction();
8343
8344 // Push a SourceParseContext on to the stack.
8345 ParseContext* outerpc = pc_;
8346 SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr);
8347 if (!funpc.init()) {
8348 return errorResult();
8349 }
8350
8351 if (!synthesizeConstructorBody(synthesizedBodyPos, hasHeritage, funNode,
8352 funbox)) {
8353 return errorResult();
8354 }
8355
8356 if (!leaveInnerFunction(outerpc)) {
8357 return errorResult();
8358 }
8359
8360 return funNode;
8361}
8362
8363template <class ParseHandler, typename Unit>
8364bool GeneralParser<ParseHandler, Unit>::synthesizeConstructorBody(
8365 TokenPos synthesizedBodyPos, HasHeritage hasHeritage,
8366 FunctionNodeType funNode, FunctionBox* funbox) {
8367 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"
, 8367); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isClassConstructor()"
")"); do { MOZ_CrashSequence(__null, 8367); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
20
Taking false branch
21
Loop condition is false. Exiting loop
8368
8369 // Create a ParamsBodyNode for the parameters + body (there are no
8370 // parameters).
8371 ParamsBodyNodeType argsbody;
8372 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)
22
Taking false branch
23
Loop condition is false. Exiting loop
8373 false)do { auto parserTryVarTempResult_ = (handler_.newParamsBody(synthesizedBodyPos
)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr())
, 0))) { return (false); } (argsbody) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8374 handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
8375 setFunctionStartAtPosition(funbox, synthesizedBodyPos);
8376
8377 if (hasHeritage
23.1
'hasHeritage' is equal to Yes
== HasHeritage::Yes) {
24
Taking true branch
8378 // Synthesize the equivalent to `function f(...args)`
8379 funbox->setHasRest();
8380 if (!notePositionalFormalParameter(
26
Calling 'GeneralParser::notePositionalFormalParameter'
8381 funNode, TaggedParserAtomIndex::WellKnown::dot_args_(),
8382 synthesizedBodyPos.begin,
8383 /* disallowDuplicateParams = */ false,
8384 /* duplicatedParam = */ nullptr)) {
25
Passing null pointer value via 5th parameter 'duplicatedParam'
8385 return false;
8386 }
8387 funbox->setArgCount(1);
8388 } else {
8389 funbox->setArgCount(0);
8390 }
8391
8392 pc_->functionScope().useAsVarScope(pc_);
8393
8394 ListNodeType stmtList;
8395 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)
8396 false)do { auto parserTryVarTempResult_ = (handler_.newStatementList
(synthesizedBodyPos)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (stmtList) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8397
8398 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_this_())) {
8399 return false;
8400 }
8401
8402 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_initializers_())) {
8403 return false;
8404 }
8405
8406#ifdef ENABLE_DECORATORS
8407 if (!noteUsedName(
8408 TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_())) {
8409 return false;
8410 }
8411#endif
8412
8413 if (hasHeritage == HasHeritage::Yes) {
8414 // |super()| implicitly reads |new.target|.
8415 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_newTarget_())) {
8416 return false;
8417 }
8418
8419 NameNodeType thisName;
8420 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)
;
8421
8422 UnaryNodeType superBase;
8423 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)
8424 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)
;
8425
8426 ListNodeType arguments;
8427 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)
8428 false)do { auto parserTryVarTempResult_ = (handler_.newArguments(synthesizedBodyPos
)); if ((__builtin_expect(!!(parserTryVarTempResult_.isErr())
, 0))) { return (false); } (arguments) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8429
8430 NameNodeType argsNameNode;
8431 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)
8432 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)
8433 synthesizedBodyPos),do { auto parserTryVarTempResult_ = (newName(TaggedParserAtomIndex
::WellKnown::dot_args_(), synthesizedBodyPos)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(argsNameNode) = parserTryVarTempResult_.unwrap(); } while (
0)
8434 false)do { auto parserTryVarTempResult_ = (newName(TaggedParserAtomIndex
::WellKnown::dot_args_(), synthesizedBodyPos)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(argsNameNode) = parserTryVarTempResult_.unwrap(); } while (
0)
;
8435 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_args_())) {
8436 return false;
8437 }
8438
8439 UnaryNodeType spreadArgs;
8440 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)
8441 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)
8442 false)do { auto parserTryVarTempResult_ = (handler_.newSpread(synthesizedBodyPos
.begin, argsNameNode)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (spreadArgs) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8443 handler_.addList(arguments, spreadArgs);
8444
8445 CallNodeType superCall;
8446 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)
8447 superCall,do { auto parserTryVarTempResult_ = (handler_.newSuperCall(superBase
, arguments, true)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (superCall) = parserTryVarTempResult_
.unwrap(); } while (0)
8448 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)
8449 false)do { auto parserTryVarTempResult_ = (handler_.newSuperCall(superBase
, arguments, true)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (superCall) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8450
8451 BinaryNodeType setThis;
8452 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)
8453 false)do { auto parserTryVarTempResult_ = (handler_.newSetThis(thisName
, superCall)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (setThis) = parserTryVarTempResult_
.unwrap(); } while (0)
;
8454
8455 UnaryNodeType exprStatement;
8456 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)
8457 exprStatement,do { auto parserTryVarTempResult_ = (handler_.newExprStatement
(setThis, synthesizedBodyPos.end)); if ((__builtin_expect(!!(
parserTryVarTempResult_.isErr()), 0))) { return (false); } (exprStatement
) = parserTryVarTempResult_.unwrap(); } while (0)
8458 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)
;
8459
8460 handler_.addStatementToList(stmtList, exprStatement);
8461 }
8462
8463 bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings();
8464 if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) {
8465 return false;
8466 }
8467 if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) {
8468 return false;
8469 }
8470
8471 LexicalScopeNodeType initializerBody;
8472 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)
8473 initializerBody,do { auto parserTryVarTempResult_ = (finishLexicalScope(pc_->
varScope(), stmtList, ScopeKind::FunctionLexical)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(initializerBody) = parserTryVarTempResult_.unwrap(); } while
(0)
8474 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)
8475 false)do { auto parserTryVarTempResult_ = (finishLexicalScope(pc_->
varScope(), stmtList, ScopeKind::FunctionLexical)); if ((__builtin_expect
(!!(parserTryVarTempResult_.isErr()), 0))) { return (false); }
(initializerBody) = parserTryVarTempResult_.unwrap(); } while
(0)
;
8476 handler_.setBeginPosition(initializerBody, stmtList);
8477 handler_.setEndPosition(initializerBody, stmtList);
8478
8479 handler_.setFunctionBody(funNode, initializerBody);
8480
8481 return finishFunction();
8482}
8483
8484template <class ParseHandler, typename Unit>
8485typename ParseHandler::FunctionNodeResult
8486GeneralParser<ParseHandler, Unit>::privateMethodInitializer(
8487 TokenPos propNamePos, TaggedParserAtomIndex propAtom,
8488 TaggedParserAtomIndex storedMethodAtom) {
8489 if (!abortIfSyntaxParser()) {
8490 return errorResult();
8491 }
8492
8493 // Synthesize an initializer function that the constructor can use to stamp a
8494 // private method onto an instance object.
8495 FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::FieldInitializer;
8496 FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction;
8497 GeneratorKind generatorKind = GeneratorKind::NotGenerator;
8498 bool isSelfHosting = options().selfHostingMode;
8499 FunctionFlags flags =
8500 InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting);
8501
8502 FunctionNodeType funNode =
8503 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(); })
;
8504
8505 Directives directives(true);
8506 FunctionBox* funbox =
8507 newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags,
8508 propNamePos.begin, directives, generatorKind, asyncKind);
8509 if (!funbox) {
8510 return errorResult();
8511 }
8512 funbox->initWithEnclosingParseContext(pc_, syntaxKind);
8513
8514 // Push a SourceParseContext on to the stack.
8515 ParseContext* outerpc = pc_;
8516 SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr);
8517 if (!funpc.init()) {
8518 return errorResult();
8519 }
8520 pc_->functionScope().useAsVarScope(pc_);
8521
8522 // Add empty parameter list.
8523 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(); })
;
8524 handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
8525 setFunctionStartAtCurrentToken(funbox);
8526 funbox->setArgCount(0);
8527
8528 // Note both the stored private method body and it's private name as being
8529 // used in the initializer. They will be emitted into the method body in the
8530 // BCE.
8531 if (!noteUsedName(storedMethodAtom)) {
8532 return errorResult();
8533 }
8534 MOZ_TRY(privateNameReference(propAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(privateNameReference(propAtom)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
8535
8536 // Unlike field initializers, private method initializers are not created with
8537 // a body of synthesized AST nodes. Instead, the body is left empty and the
8538 // initializer is synthesized at the bytecode level.
8539 // See BytecodeEmitter::emitPrivateMethodInitializer.
8540 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(); })
;
8541
8542 bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings();
8543 if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) {
8544 return errorResult();
8545 }
8546 if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) {
8547 return errorResult();
8548 }
8549
8550 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(); })
8551 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(); })
;
8552 handler_.setBeginPosition(initializerBody, stmtList);
8553 handler_.setEndPosition(initializerBody, stmtList);
8554 handler_.setFunctionBody(funNode, initializerBody);
8555
8556 // Set field-initializer lambda boundary to start at property name and end
8557 // after method body.
8558 setFunctionStartAtPosition(funbox, propNamePos);
8559 setFunctionEndFromCurrentToken(funbox);
8560
8561 if (!finishFunction()) {
8562 return errorResult();
8563 }
8564
8565 if (!leaveInnerFunction(outerpc)) {
8566 return errorResult();
8567 }
8568
8569 return funNode;
8570}
8571
8572template <class ParseHandler, typename Unit>
8573typename ParseHandler::FunctionNodeResult
8574GeneralParser<ParseHandler, Unit>::staticClassBlock(
8575 ClassInitializedMembers& classInitializedMembers) {
8576 // Both for getting-this-done, and because this will invariably be executed,
8577 // syntax parsing should be aborted.
8578 if (!abortIfSyntaxParser()) {
8579 return errorResult();
8580 }
8581
8582 FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::StaticClassBlock;
8583 FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction;
8584 GeneratorKind generatorKind = GeneratorKind::NotGenerator;
8585 bool isSelfHosting = options().selfHostingMode;
8586 FunctionFlags flags =
8587 InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting);
8588
8589 AutoAwaitIsKeyword awaitIsKeyword(this, AwaitHandling::AwaitIsDisallowed);
8590
8591 // Create the function node for the static class body.
8592 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(); })
;
8593
8594 // Create the FunctionBox and link it to the function object.
8595 Directives directives(true);
8596 FunctionBox* funbox =
8597 newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags, pos().begin,
8598 directives, generatorKind, asyncKind);
8599 if (!funbox) {
8600 return errorResult();
8601 }
8602 funbox->initWithEnclosingParseContext(pc_, syntaxKind);
8603 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"
, 8603); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isSyntheticFunction()"
")"); do { MOZ_CrashSequence(__null, 8603); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8604 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"
, 8604); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!funbox->allowSuperCall()"
")"); do { MOZ_CrashSequence(__null, 8604); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8605 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"
, 8605); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!funbox->allowArguments()"
")"); do { MOZ_CrashSequence(__null, 8605); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8606 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", 8606); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!funbox->allowReturn()" ")"); do { MOZ_CrashSequence
(__null, 8606); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
8607
8608 // Set start at `static` token.
8609 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", 8609); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Static)"
")"); do { MOZ_CrashSequence(__null, 8609); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8610 setFunctionStartAtCurrentToken(funbox);
8611
8612 // Push a SourceParseContext on to the stack.
8613 ParseContext* outerpc = pc_;
8614 SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr);
8615 if (!funpc.init()) {
8616 return errorResult();
8617 }
8618
8619 pc_->functionScope().useAsVarScope(pc_);
8620
8621 uint32_t start = pos().begin;
8622
8623 tokenStream.consumeKnownToken(TokenKind::LeftCurly);
8624
8625 // Static class blocks are code-generated as if they were static field
8626 // initializers, so we bump the staticFields count here, which ensures
8627 // .staticInitializers is noted as used.
8628 classInitializedMembers.staticFields++;
8629
8630 LexicalScopeNodeType body =
8631 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(); })
8632 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(); })
;
8633
8634 if (anyChars.isEOF()) {
8635 error(JSMSG_UNTERMINATED_STATIC_CLASS_BLOCK);
8636 return errorResult();
8637 }
8638
8639 tokenStream.consumeKnownToken(TokenKind::RightCurly,
8640 TokenStream::Modifier::SlashIsRegExp);
8641
8642 TokenPos wholeBodyPos(start, pos().end);
8643
8644 handler_.setEndPosition(funNode, wholeBodyPos.end);
8645 setFunctionEndFromCurrentToken(funbox);
8646
8647 // Create a ParamsBodyNode for the parameters + body (there are no
8648 // parameters).
8649 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(); })
;
8650
8651 handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
8652 funbox->setArgCount(0);
8653
8654 if (pc_->superScopeNeedsHomeObject()) {
8655 funbox->setNeedsHomeObject();
8656 }
8657
8658 handler_.setEndPosition(body, pos().begin);
8659 handler_.setEndPosition(funNode, pos().end);
8660 handler_.setFunctionBody(funNode, body);
8661
8662 if (!finishFunction()) {
8663 return errorResult();
8664 }
8665
8666 if (!leaveInnerFunction(outerpc)) {
8667 return errorResult();
8668 }
8669
8670 return funNode;
8671}
8672
8673template <class ParseHandler, typename Unit>
8674typename ParseHandler::FunctionNodeResult
8675GeneralParser<ParseHandler, Unit>::fieldInitializerOpt(
8676 TokenPos propNamePos, Node propName, TaggedParserAtomIndex propAtom,
8677 ClassInitializedMembers& classInitializedMembers, bool isStatic,
8678 HasHeritage hasHeritage) {
8679 if (!abortIfSyntaxParser()) {
8680 return errorResult();
8681 }
8682
8683 bool hasInitializer = false;
8684 if (!tokenStream.matchToken(&hasInitializer, TokenKind::Assign,
8685 TokenStream::SlashIsDiv)) {
8686 return errorResult();
8687 }
8688
8689 FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::FieldInitializer;
8690 FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction;
8691 GeneratorKind generatorKind = GeneratorKind::NotGenerator;
8692 bool isSelfHosting = options().selfHostingMode;
8693 FunctionFlags flags =
8694 InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting);
8695
8696 // Create the top-level field initializer node.
8697 FunctionNodeType funNode =
8698 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(); })
;
8699
8700 // Create the FunctionBox and link it to the function object.
8701 Directives directives(true);
8702 FunctionBox* funbox =
8703 newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags,
8704 propNamePos.begin, directives, generatorKind, asyncKind);
8705 if (!funbox) {
8706 return errorResult();
8707 }
8708 funbox->initWithEnclosingParseContext(pc_, syntaxKind);
8709 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"
, 8709); AnnotateMozCrashReason("MOZ_ASSERT" "(" "funbox->isSyntheticFunction()"
")"); do { MOZ_CrashSequence(__null, 8709); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8710
8711 // We can't use setFunctionStartAtCurrentToken because that uses pos().begin,
8712 // which is incorrect for fields without initializers (pos() points to the
8713 // field identifier)
8714 setFunctionStartAtPosition(funbox, propNamePos);
8715
8716 // Push a SourceParseContext on to the stack.
8717 ParseContext* outerpc = pc_;
8718 SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr);
8719 if (!funpc.init()) {
8720 return errorResult();
8721 }
8722
8723 pc_->functionScope().useAsVarScope(pc_);
8724
8725 Node initializerExpr;
8726 if (hasInitializer) {
8727 // Parse the expression for the field initializer.
8728 {
8729 AutoAwaitIsKeyword awaitHandling(this, AwaitIsName);
8730 initializerExpr =
8731 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
(); })
;
8732 }
8733
8734 handler_.checkAndSetIsDirectRHSAnonFunction(initializerExpr);
8735 } else {
8736 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(); })
;
8737 }
8738
8739 TokenPos wholeInitializerPos(propNamePos.begin, pos().end);
8740
8741 // Update the end position of the parse node.
8742 handler_.setEndPosition(funNode, wholeInitializerPos.end);
8743 setFunctionEndFromCurrentToken(funbox);
8744
8745 // Create a ParamsBodyNode for the parameters + body (there are no
8746 // parameters).
8747 ParamsBodyNodeType argsbody =
8748 MOZ_TRY(handler_.newParamsBody(wholeInitializerPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(handler_.newParamsBody(wholeInitializerPos)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
8749 handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
8750 funbox->setArgCount(0);
8751
8752 NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
8753
8754 // Build `this.field` expression.
8755 ThisLiteralType propAssignThis =
8756 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
(); })
;
8757
8758 Node propAssignFieldAccess;
8759 uint32_t indexValue;
8760 if (!propAtom) {
8761 // See BytecodeEmitter::emitCreateFieldKeys for an explanation of what
8762 // .fieldKeys means and its purpose.
8763 NameNodeType fieldKeysName;
8764 if (isStatic) {
8765 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(); })
8766 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(); })
;
8767 } else {
8768 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(); })
8769 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(); })
;
8770 }
8771 if (!fieldKeysName) {
8772 return errorResult();
8773 }
8774
8775 double fieldKeyIndex;
8776 if (isStatic) {
8777 fieldKeyIndex = classInitializedMembers.staticFieldKeys++;
8778 } else {
8779 fieldKeyIndex = classInitializedMembers.instanceFieldKeys++;
8780 }
8781 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(); })
8782 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(); })
;
8783
8784 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(); })
8785 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(); })
;
8786
8787 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(); })
8788 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(); })
;
8789 } else if (handler_.isPrivateName(propName)) {
8790 // It would be nice if we could tweak this here such that only if
8791 // HasHeritage::Yes we end up emitting CheckPrivateField, but otherwise we
8792 // emit InitElem -- this is an optimization to minimize HasOwn checks
8793 // in InitElem for classes without heritage.
8794 //
8795 // Further tweaking would be to ultimately only do CheckPrivateField for the
8796 // -first- field in a derived class, which would suffice to match the
8797 // semantic check.
8798
8799 NameNodeType privateNameNode = MOZ_TRY(privateNameReference(propAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(privateNameReference(propAtom)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
8800
8801 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(); })
8802 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(); })
;
8803 } else if (this->parserAtoms().isIndex(propAtom, &indexValue)) {
8804 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(); })
8805 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(); })
;
8806 } else {
8807 NameNodeType propAssignName =
8808 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
(); })
;
8809
8810 propAssignFieldAccess =
8811 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(); })
;
8812 }
8813
8814 // Synthesize an property init.
8815 BinaryNodeType initializerPropInit =
8816 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(); })
;
8817
8818 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(); })
8819 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(); })
;
8820
8821 ListNodeType statementList =
8822 MOZ_TRY(handler_.newStatementList(wholeInitializerPos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(handler_.newStatementList(wholeInitializerPos)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
8823 handler_.addStatementToList(statementList, exprStatement);
8824
8825 bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings();
8826 if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) {
8827 return errorResult();
8828 }
8829 if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) {
8830 return errorResult();
8831 }
8832
8833 // Set the function's body to the field assignment.
8834 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(); })
8835 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(); })
;
8836
8837 handler_.setFunctionBody(funNode, initializerBody);
8838
8839 if (pc_->superScopeNeedsHomeObject()) {
8840 funbox->setNeedsHomeObject();
8841 }
8842
8843 if (!finishFunction()) {
8844 return errorResult();
8845 }
8846
8847 if (!leaveInnerFunction(outerpc)) {
8848 return errorResult();
8849 }
8850
8851 return funNode;
8852}
8853
8854template <class ParseHandler, typename Unit>
8855typename ParseHandler::FunctionNodeResult
8856GeneralParser<ParseHandler, Unit>::synthesizePrivateMethodInitializer(
8857 TaggedParserAtomIndex propAtom, AccessorType accessorType,
8858 TokenPos propNamePos) {
8859 if (!abortIfSyntaxParser()) {
8860 return errorResult();
8861 }
8862
8863 // Synthesize a name for the lexical variable that will store the
8864 // accessor body.
8865 StringBuilder storedMethodName(fc_);
8866 if (!storedMethodName.append(this->parserAtoms(), propAtom)) {
8867 return errorResult();
8868 }
8869 if (!storedMethodName.append(
8870 accessorType == AccessorType::Getter ? ".getter" : ".setter")) {
8871 return errorResult();
8872 }
8873 auto storedMethodProp =
8874 storedMethodName.finishParserAtom(this->parserAtoms(), fc_);
8875 if (!storedMethodProp) {
8876 return errorResult();
8877 }
8878 if (!noteDeclaredName(storedMethodProp, DeclarationKind::Synthetic, pos())) {
8879 return errorResult();
8880 }
8881
8882 return privateMethodInitializer(propNamePos, propAtom, storedMethodProp);
8883}
8884
8885#ifdef ENABLE_DECORATORS
8886template <class ParseHandler, typename Unit>
8887typename ParseHandler::FunctionNodeResult
8888GeneralParser<ParseHandler, Unit>::synthesizeAddInitializerFunction(
8889 TaggedParserAtomIndex initializers, YieldHandling yieldHandling) {
8890 if (!abortIfSyntaxParser()) {
8891 return errorResult();
8892 }
8893
8894 // TODO: Add support for static and class extra initializers, see bug 1868220
8895 // and bug 1868221.
8896 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", 8898); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()"
")"); do { MOZ_CrashSequence(__null, 8898); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
8897 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", 8898); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()"
")"); do { MOZ_CrashSequence(__null, 8898); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
8898 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", 8898); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "initializers == TaggedParserAtomIndex::WellKnown::dot_instanceExtraInitializers_()"
")"); do { MOZ_CrashSequence(__null, 8898); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8899
8900 TokenPos propNamePos = pos();
8901
8902 // Synthesize an addInitializer function that can be used to append to
8903 // .initializers
8904 FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Statement;
8905 FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction;
8906 GeneratorKind generatorKind = GeneratorKind::NotGenerator;
8907 bool isSelfHosting = options().selfHostingMode;
8908 FunctionFlags flags =
8909 InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting);
8910
8911 FunctionNodeType funNode =
8912 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(); })
;
8913
8914 Directives directives(true);
8915 FunctionBox* funbox =
8916 newFunctionBox(funNode, TaggedParserAtomIndex::null(), flags,
8917 propNamePos.begin, directives, generatorKind, asyncKind);
8918 if (!funbox) {
8919 return errorResult();
8920 }
8921 funbox->initWithEnclosingParseContext(pc_, syntaxKind);
8922
8923 ParseContext* outerpc = pc_;
8924 SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr);
8925 if (!funpc.init()) {
8926 return errorResult();
8927 }
8928 pc_->functionScope().useAsVarScope(pc_);
8929
8930 // Takes a single parameter, `initializer`.
8931 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(); })
;
8932
8933 handler_.setFunctionFormalParametersAndBody(funNode, params);
8934
8935 constexpr bool disallowDuplicateParams = true;
8936 bool duplicatedParam = false;
8937 if (!notePositionalFormalParameter(
8938 funNode, TaggedParserAtomIndex::WellKnown::initializer(), pos().begin,
8939 disallowDuplicateParams, &duplicatedParam)) {
8940 return errorResult();
8941 }
8942 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", 8942); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!duplicatedParam" ")"); do { MOZ_CrashSequence
(__null, 8942); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
8943 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"
, 8943); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pc_->positionalFormalParameterNames().length() == 1"
")"); do { MOZ_CrashSequence(__null, 8943); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
8944
8945 funbox->setLength(1);
8946 funbox->setArgCount(1);
8947 setFunctionStartAtCurrentToken(funbox);
8948
8949 // Like private method initializers, the addInitializer method is not created
8950 // with a body of synthesized AST nodes. Instead, the body is left empty and
8951 // the initializer is synthesized at the bytecode level. See
8952 // DecoratorEmitter::emitCreateAddInitializerFunction.
8953 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(); })
;
8954
8955 if (!noteUsedName(initializers)) {
8956 return errorResult();
8957 }
8958
8959 bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings();
8960 if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) {
8961 return errorResult();
8962 }
8963 if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) {
8964 return errorResult();
8965 }
8966
8967 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(); })
8968 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(); })
;
8969 handler_.setBeginPosition(addInitializerBody, stmtList);
8970 handler_.setEndPosition(addInitializerBody, stmtList);
8971 handler_.setFunctionBody(funNode, addInitializerBody);
8972
8973 // Set field-initializer lambda boundary to start at property name and end
8974 // after method body.
8975 setFunctionStartAtPosition(funbox, propNamePos);
8976 setFunctionEndFromCurrentToken(funbox);
8977
8978 if (!finishFunction()) {
8979 return errorResult();
8980 }
8981
8982 if (!leaveInnerFunction(outerpc)) {
8983 return errorResult();
8984 }
8985
8986 return funNode;
8987}
8988
8989template <class ParseHandler, typename Unit>
8990typename ParseHandler::ClassMethodResult
8991GeneralParser<ParseHandler, Unit>::synthesizeAccessor(
8992 Node propName, TokenPos propNamePos, TaggedParserAtomIndex propAtom,
8993 TaggedParserAtomIndex privateStateNameAtom, bool isStatic,
8994 FunctionSyntaxKind syntaxKind,
8995 ClassInitializedMembers& classInitializedMembers) {
8996 // Decorators Proposal
8997 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter
8998 // The abstract operation MakeAutoAccessorGetter takes arguments homeObject
8999 // (an Object), name (a property key or Private Name), and privateStateName (a
9000 // Private Name) and returns a function object.
9001 //
9002 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter
9003 // The abstract operation MakeAutoAccessorSetter takes arguments homeObject
9004 // (an Object), name (a property key or Private Name), and privateStateName (a
9005 // Private Name) and returns a function object.
9006 if (!abortIfSyntaxParser()) {
9007 return errorResult();
9008 }
9009
9010 AccessorType accessorType = syntaxKind == FunctionSyntaxKind::Getter
9011 ? AccessorType::Getter
9012 : AccessorType::Setter;
9013
9014 mozilla::Maybe<FunctionNodeType> initializerIfPrivate = Nothing();
9015 if (!isStatic && handler_.isPrivateName(propName)) {
9016 classInitializedMembers.privateAccessors++;
9017 FunctionNodeType initializerNode =
9018 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(); })
9019 propNamePos))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(synthesizePrivateMethodInitializer(propAtom, accessorType, propNamePos
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
9020 initializerIfPrivate = Some(initializerNode);
9021 handler_.setPrivateNameKind(propName, PrivateNameKind::GetterSetter);
9022 }
9023
9024 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter
9025 // 2. Let getter be CreateBuiltinFunction(getterClosure, 0, "get", « »).
9026 //
9027 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter
9028 // 2. Let setter be CreateBuiltinFunction(setterClosure, 1, "set", « »).
9029 StringBuilder storedMethodName(fc_);
9030 if (!storedMethodName.append(accessorType == AccessorType::Getter ? "get"
9031 : "set")) {
9032 return errorResult();
9033 }
9034 TaggedParserAtomIndex funNameAtom =
9035 storedMethodName.finishParserAtom(this->parserAtoms(), fc_);
9036
9037 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(); })
9038 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(); })
;
9039
9040 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter
9041 // 3. Perform MakeMethod(getter, homeObject).
9042 // 4. Return getter.
9043 //
9044 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter
9045 // 3. Perform MakeMethod(setter, homeObject).
9046 // 4. Return setter.
9047 return handler_.newClassMethodDefinition(
9048 propName, funNode, accessorType, isStatic, initializerIfPrivate, null());
9049}
9050
9051template <class ParseHandler, typename Unit>
9052typename ParseHandler::FunctionNodeResult
9053GeneralParser<ParseHandler, Unit>::synthesizeAccessorBody(
9054 TaggedParserAtomIndex funNameAtom, TokenPos propNamePos,
9055 TaggedParserAtomIndex propNameAtom, FunctionSyntaxKind syntaxKind) {
9056 if (!abortIfSyntaxParser()) {
9057 return errorResult();
9058 }
9059
9060 FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction;
9061 GeneratorKind generatorKind = GeneratorKind::NotGenerator;
9062 bool isSelfHosting = options().selfHostingMode;
9063 FunctionFlags flags =
9064 InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting);
9065
9066 // Create the top-level function node.
9067 FunctionNodeType funNode =
9068 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(); })
;
9069
9070 // Create the FunctionBox and link it to the function object.
9071 Directives directives(true);
9072 FunctionBox* funbox =
9073 newFunctionBox(funNode, funNameAtom, flags, propNamePos.begin, directives,
9074 generatorKind, asyncKind);
9075 if (!funbox) {
9076 return errorResult();
9077 }
9078 funbox->initWithEnclosingParseContext(pc_, syntaxKind);
9079 funbox->setSyntheticFunction();
9080
9081 // Push a SourceParseContext on to the stack.
9082 ParseContext* outerpc = pc_;
9083 SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr);
9084 if (!funpc.init()) {
9085 return errorResult();
9086 }
9087
9088 pc_->functionScope().useAsVarScope(pc_);
9089
9090 // The function we synthesize is located at the field with the
9091 // accessor.
9092 setFunctionStartAtCurrentToken(funbox);
9093 setFunctionEndFromCurrentToken(funbox);
9094
9095 // Create a ListNode for the parameters + body
9096 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(); })
;
9097 handler_.setFunctionFormalParametersAndBody(funNode, paramsbody);
9098
9099 if (syntaxKind == FunctionSyntaxKind::Getter) {
9100 funbox->setArgCount(0);
9101 } else {
9102 funbox->setArgCount(1);
9103 }
9104
9105 // Build `this` expression to access the privateStateName for use in the
9106 // operations to create the getter and setter below.
9107 NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
9108
9109 ThisLiteralType propThis =
9110 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(); })
;
9111
9112 NameNodeType privateNameNode = MOZ_TRY(privateNameReference(propNameAtom))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(privateNameReference(propNameAtom)); if ((__builtin_expect(!
!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
9113
9114 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(); })
9115 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(); })
;
9116
9117 Node accessorBody;
9118 if (syntaxKind == FunctionSyntaxKind::Getter) {
9119 // Decorators Proposal
9120 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorgetter
9121 // 1. Let getterClosure be a new Abstract Closure with no parameters that
9122 // captures privateStateName and performs the following steps when called:
9123 // 1.a. Let o be the this value.
9124 // 1.b. Return ? PrivateGet(privateStateName, o).
9125 accessorBody =
9126 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
(); })
;
9127 } else {
9128 // Decorators Proposal
9129 // https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-makeautoaccessorsetter
9130 // The abstract operation MakeAutoAccessorSetter takes arguments homeObject
9131 // (an Object), name (a property key or Private Name), and privateStateName
9132 // (a Private Name) and returns a function object.
9133 // 1. Let setterClosure be a new Abstract Closure with parameters (value)
9134 // that captures privateStateName and performs the following steps when
9135 // called:
9136 // 1.a. Let o be the this value.
9137 if (!notePositionalFormalParameter(
9138 funNode, TaggedParserAtomIndex::WellKnown::value(),
9139 /* pos = */ 0, false,
9140 /* duplicatedParam = */ nullptr)) {
9141 return errorResult();
9142 }
9143
9144 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(); })
9145 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(); })
;
9146
9147 // 1.b. Perform ? PrivateSet(privateStateName, o, value).
9148 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(); })
9149 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(); })
;
9150
9151 accessorBody =
9152 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
(); })
;
9153
9154 // 1.c. Return undefined.
9155 }
9156
9157 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(); })
;
9158 handler_.addStatementToList(statementList, accessorBody);
9159
9160 bool canSkipLazyClosedOverBindings = handler_.reuseClosedOverBindings();
9161 if (!pc_->declareFunctionThis(usedNames_, canSkipLazyClosedOverBindings)) {
9162 return errorResult();
9163 }
9164 if (!pc_->declareNewTarget(usedNames_, canSkipLazyClosedOverBindings)) {
9165 return errorResult();
9166 }
9167
9168 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(); })
9169 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(); })
;
9170
9171 handler_.setFunctionBody(funNode, initializerBody);
9172
9173 if (pc_->superScopeNeedsHomeObject()) {
9174 funbox->setNeedsHomeObject();
9175 }
9176
9177 if (!finishFunction()) {
9178 return errorResult();
9179 }
9180
9181 if (!leaveInnerFunction(outerpc)) {
9182 return errorResult();
9183 }
9184
9185 return funNode;
9186}
9187
9188#endif
9189
9190bool ParserBase::nextTokenContinuesLetDeclaration(TokenKind next) {
9191 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", 9191); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Let)"
")"); do { MOZ_CrashSequence(__null, 9191); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9192 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"
, 9192); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.nextToken().type == next"
")"); do { MOZ_CrashSequence(__null, 9192); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9193
9194 TokenStreamShared::verifyConsistentModifier(TokenStreamShared::SlashIsDiv,
9195 anyChars.nextToken());
9196
9197 // Destructuring continues a let declaration.
9198 if (next == TokenKind::LeftBracket || next == TokenKind::LeftCurly) {
9199 return true;
9200 }
9201
9202 // A "let" edge case deserves special comment. Consider this:
9203 //
9204 // let // not an ASI opportunity
9205 // let;
9206 //
9207 // Static semantics in §13.3.1.1 turn a LexicalDeclaration that binds
9208 // "let" into an early error. Does this retroactively permit ASI so
9209 // that we should parse this as two ExpressionStatements? No. ASI
9210 // resolves during parsing. Static semantics only apply to the full
9211 // parse tree with ASI applied. No backsies!
9212
9213 // Otherwise a let declaration must have a name.
9214 return TokenKindIsPossibleIdentifier(next);
9215}
9216
9217template <class ParseHandler, typename Unit>
9218typename ParseHandler::DeclarationListNodeResult
9219GeneralParser<ParseHandler, Unit>::variableStatement(
9220 YieldHandling yieldHandling) {
9221 DeclarationListNodeType vars =
9222 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
(); })
;
9223 if (!matchOrInsertSemicolon()) {
9224 return errorResult();
9225 }
9226 return vars;
9227}
9228
9229template <class ParseHandler, typename Unit>
9230typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::statement(
9231 YieldHandling yieldHandling) {
9232 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", 9232); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence
(__null, 9232); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9233
9234 AutoCheckRecursionLimit recursion(this->fc_);
9235 if (!recursion.check(this->fc_)) {
9236 return errorResult();
9237 }
9238
9239 TokenKind tt;
9240 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
9241 return errorResult();
9242 }
9243
9244 switch (tt) {
9245 // BlockStatement[?Yield, ?Return]
9246 case TokenKind::LeftCurly:
9247 return blockStatement(yieldHandling);
9248
9249 // VariableStatement[?Yield]
9250 case TokenKind::Var:
9251 return variableStatement(yieldHandling);
9252
9253 // EmptyStatement
9254 case TokenKind::Semi:
9255 return handler_.newEmptyStatement(pos());
9256
9257 // ExpressionStatement[?Yield].
9258
9259 case TokenKind::Yield: {
9260 // Don't use a ternary operator here due to obscure linker issues
9261 // around using static consts in the arms of a ternary.
9262 Modifier modifier;
9263 if (yieldExpressionsSupported()) {
9264 modifier = TokenStream::SlashIsRegExp;
9265 } else {
9266 modifier = TokenStream::SlashIsDiv;
9267 }
9268
9269 TokenKind next;
9270 if (!tokenStream.peekToken(&next, modifier)) {
9271 return errorResult();
9272 }
9273
9274 if (next == TokenKind::Colon) {
9275 return labeledStatement(yieldHandling);
9276 }
9277
9278 return expressionStatement(yieldHandling);
9279 }
9280
9281 default: {
9282 // If we encounter an await in a module, and the module is not marked
9283 // as async, mark the module as async.
9284 if (tt == TokenKind::Await && !pc_->isAsync()) {
9285 if (pc_->atModuleTopLevel()) {
9286 if (!options().topLevelAwait) {
9287 error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED);
9288 return errorResult();
9289 }
9290 pc_->sc()->asModuleContext()->setIsAsync();
9291 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", 9291); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence
(__null, 9291); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9292 }
9293 }
9294
9295 // Avoid getting next token with SlashIsDiv.
9296 if (tt == TokenKind::Await && pc_->isAsync()) {
9297 return expressionStatement(yieldHandling);
9298 }
9299
9300 if (!TokenKindIsPossibleIdentifier(tt)) {
9301 return expressionStatement(yieldHandling);
9302 }
9303
9304 TokenKind next;
9305 if (!tokenStream.peekToken(&next)) {
9306 return errorResult();
9307 }
9308
9309 // |let| here can only be an Identifier, not a declaration. Give nicer
9310 // errors for declaration-looking typos.
9311 if (tt == TokenKind::Let) {
9312 bool forbiddenLetDeclaration = false;
9313
9314 if (next == TokenKind::LeftBracket) {
9315 // Enforce ExpressionStatement's 'let [' lookahead restriction.
9316 forbiddenLetDeclaration = true;
9317 } else if (next == TokenKind::LeftCurly ||
9318 TokenKindIsPossibleIdentifier(next)) {
9319 // 'let {' and 'let foo' aren't completely forbidden, if ASI
9320 // causes 'let' to be the entire Statement. But if they're
9321 // same-line, we can aggressively give a better error message.
9322 //
9323 // Note that this ignores 'yield' as TokenKind::Yield: we'll handle it
9324 // correctly but with a worse error message.
9325 TokenKind nextSameLine;
9326 if (!tokenStream.peekTokenSameLine(&nextSameLine)) {
9327 return errorResult();
9328 }
9329
9330 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", 9332); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol"
")"); do { MOZ_CrashSequence(__null, 9332); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
9331 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", 9332); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol"
")"); do { MOZ_CrashSequence(__null, 9332); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
9332 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", 9332); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(nextSameLine) || nextSameLine == TokenKind::LeftCurly || nextSameLine == TokenKind::Eol"
")"); do { MOZ_CrashSequence(__null, 9332); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9333
9334 forbiddenLetDeclaration = nextSameLine != TokenKind::Eol;
9335 }
9336
9337 if (forbiddenLetDeclaration) {
9338 error(JSMSG_FORBIDDEN_AS_STATEMENT, "lexical declarations");
9339 return errorResult();
9340 }
9341 } else if (tt == TokenKind::Async) {
9342 // Peek only on the same line: ExpressionStatement's lookahead
9343 // restriction is phrased as
9344 //
9345 // [lookahead ∉ { '{',
9346 // function,
9347 // async [no LineTerminator here] function,
9348 // class,
9349 // let '[' }]
9350 //
9351 // meaning that code like this is valid:
9352 //
9353 // if (true)
9354 // async // ASI opportunity
9355 // function clownshoes() {}
9356 TokenKind maybeFunction;
9357 if (!tokenStream.peekTokenSameLine(&maybeFunction)) {
9358 return errorResult();
9359 }
9360
9361 if (maybeFunction == TokenKind::Function) {
9362 error(JSMSG_FORBIDDEN_AS_STATEMENT, "async function declarations");
9363 return errorResult();
9364 }
9365
9366 // Otherwise this |async| begins an ExpressionStatement or is a
9367 // label name.
9368 }
9369
9370 // NOTE: It's unfortunately allowed to have a label named 'let' in
9371 // non-strict code. 💯
9372 if (next == TokenKind::Colon) {
9373 return labeledStatement(yieldHandling);
9374 }
9375
9376 return expressionStatement(yieldHandling);
9377 }
9378
9379 case TokenKind::New:
9380 return expressionStatement(yieldHandling, PredictInvoked);
9381
9382 // IfStatement[?Yield, ?Return]
9383 case TokenKind::If:
9384 return ifStatement(yieldHandling);
9385
9386 // BreakableStatement[?Yield, ?Return]
9387 //
9388 // BreakableStatement[Yield, Return]:
9389 // IterationStatement[?Yield, ?Return]
9390 // SwitchStatement[?Yield, ?Return]
9391 case TokenKind::Do:
9392 return doWhileStatement(yieldHandling);
9393
9394 case TokenKind::While:
9395 return whileStatement(yieldHandling);
9396
9397 case TokenKind::For:
9398 return forStatement(yieldHandling);
9399
9400 case TokenKind::Switch:
9401 return switchStatement(yieldHandling);
9402
9403 // ContinueStatement[?Yield]
9404 case TokenKind::Continue:
9405 return continueStatement(yieldHandling);
9406
9407 // BreakStatement[?Yield]
9408 case TokenKind::Break:
9409 return breakStatement(yieldHandling);
9410
9411 // [+Return] ReturnStatement[?Yield]
9412 case TokenKind::Return:
9413 // The Return parameter is only used here, and the effect is easily
9414 // detected this way, so don't bother passing around an extra parameter
9415 // everywhere.
9416 if (!pc_->allowReturn()) {
9417 error(JSMSG_BAD_RETURN_OR_YIELD, "return");
9418 return errorResult();
9419 }
9420 return returnStatement(yieldHandling);
9421
9422 // WithStatement[?Yield, ?Return]
9423 case TokenKind::With:
9424 return withStatement(yieldHandling);
9425
9426 // LabelledStatement[?Yield, ?Return]
9427 // This is really handled by default and TokenKind::Yield cases above.
9428
9429 // ThrowStatement[?Yield]
9430 case TokenKind::Throw:
9431 return throwStatement(yieldHandling);
9432
9433 // TryStatement[?Yield, ?Return]
9434 case TokenKind::Try:
9435 return tryStatement(yieldHandling);
9436
9437 // DebuggerStatement
9438 case TokenKind::Debugger:
9439 return debuggerStatement();
9440
9441 // |function| is forbidden by lookahead restriction (unless as child
9442 // statement of |if| or |else|, but Parser::consequentOrAlternative
9443 // handles that).
9444 case TokenKind::Function:
9445 error(JSMSG_FORBIDDEN_AS_STATEMENT, "function declarations");
9446 return errorResult();
9447
9448 // |class| is also forbidden by lookahead restriction.
9449 case TokenKind::Class:
9450 error(JSMSG_FORBIDDEN_AS_STATEMENT, "classes");
9451 return errorResult();
9452
9453 // ImportDeclaration (only inside modules)
9454 case TokenKind::Import:
9455 return importDeclarationOrImportExpr(yieldHandling);
9456
9457 // ExportDeclaration (only inside modules)
9458 case TokenKind::Export:
9459 return exportDeclaration();
9460
9461 // Miscellaneous error cases arguably better caught here than elsewhere.
9462
9463 case TokenKind::Catch:
9464 error(JSMSG_CATCH_WITHOUT_TRY);
9465 return errorResult();
9466
9467 case TokenKind::Finally:
9468 error(JSMSG_FINALLY_WITHOUT_TRY);
9469 return errorResult();
9470
9471 // NOTE: default case handled in the ExpressionStatement section.
9472 }
9473}
9474
9475template <class ParseHandler, typename Unit>
9476typename ParseHandler::NodeResult
9477GeneralParser<ParseHandler, Unit>::statementListItem(
9478 YieldHandling yieldHandling, bool canHaveDirectives /* = false */) {
9479 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", 9479); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "checkOptionsCalled_" ")"); do { MOZ_CrashSequence
(__null, 9479); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9480
9481 AutoCheckRecursionLimit recursion(this->fc_);
9482 if (!recursion.check(this->fc_)) {
9483 return errorResult();
9484 }
9485
9486 TokenKind tt;
9487 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
9488 return errorResult();
9489 }
9490
9491 switch (tt) {
9492 // BlockStatement[?Yield, ?Return]
9493 case TokenKind::LeftCurly:
9494 return blockStatement(yieldHandling);
9495
9496 // VariableStatement[?Yield]
9497 case TokenKind::Var:
9498 return variableStatement(yieldHandling);
9499
9500 // EmptyStatement
9501 case TokenKind::Semi:
9502 return handler_.newEmptyStatement(pos());
9503
9504 // ExpressionStatement[?Yield].
9505 //
9506 // These should probably be handled by a single ExpressionStatement
9507 // function in a default, not split up this way.
9508 case TokenKind::String:
9509 return expressionStatement(yieldHandling);
9510
9511 case TokenKind::Yield: {
9512 // Don't use a ternary operator here due to obscure linker issues
9513 // around using static consts in the arms of a ternary.
9514 Modifier modifier;
9515 if (yieldExpressionsSupported()) {
9516 modifier = TokenStream::SlashIsRegExp;
9517 } else {
9518 modifier = TokenStream::SlashIsDiv;
9519 }
9520
9521 TokenKind next;
9522 if (!tokenStream.peekToken(&next, modifier)) {
9523 return errorResult();
9524 }
9525
9526 if (next == TokenKind::Colon) {
9527 return labeledStatement(yieldHandling);
9528 }
9529
9530 return expressionStatement(yieldHandling);
9531 }
9532
9533 default: {
9534 // If we encounter an await in a module, and the module is not marked
9535 // as async, mark the module as async.
9536 if (tt == TokenKind::Await && !pc_->isAsync()) {
9537 if (pc_->atModuleTopLevel()) {
9538 if (!options().topLevelAwait) {
9539 error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED);
9540 return errorResult();
9541 }
9542 pc_->sc()->asModuleContext()->setIsAsync();
9543 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", 9543); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence
(__null, 9543); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9544 }
9545 }
9546
9547 if (tt == TokenKind::Await && pc_->isAsync()) {
9548 // Try finding evidence of a AwaitUsingDeclaration the syntax for which
9549 // would be:
9550 // await [no LineTerminator here] using [no LineTerminator here]
9551 // identifier
9552
9553 TokenKind nextTokUsing = TokenKind::Eof;
9554 // Scan with regex modifier because when its await expression, `/`
9555 // should be treated as a regexp.
9556 if (!tokenStream.peekTokenSameLine(&nextTokUsing,
9557 TokenStream::SlashIsRegExp)) {
9558 return errorResult();
9559 }
9560
9561 if (nextTokUsing == TokenKind::Using &&
9562 this->pc_->isUsingSyntaxAllowed()) {
9563 tokenStream.consumeKnownToken(nextTokUsing,
9564 TokenStream::SlashIsRegExp);
9565 TokenKind nextTokIdentifier = TokenKind::Eof;
9566 // Here we can use the Div modifier because if the next token is
9567 // using then a `/` as the next token can only be considered a
9568 // division.
9569 if (!tokenStream.peekTokenSameLine(&nextTokIdentifier)) {
9570 return errorResult();
9571 }
9572 if (TokenKindIsPossibleIdentifier(nextTokIdentifier)) {
9573 return lexicalDeclaration(yieldHandling,
9574 DeclarationKind::AwaitUsing);
9575 }
9576 anyChars.ungetToken(); // put back using.
9577 }
9578 return expressionStatement(yieldHandling);
9579 }
9580
9581 if (!TokenKindIsPossibleIdentifier(tt)) {
9582 return expressionStatement(yieldHandling);
9583 }
9584
9585 TokenKind next;
9586 if (!tokenStream.peekToken(&next)) {
9587 return errorResult();
9588 }
9589
9590 if (tt == TokenKind::Let && nextTokenContinuesLetDeclaration(next)) {
9591 return lexicalDeclaration(yieldHandling, DeclarationKind::Let);
9592 }
9593
9594 if (tt == TokenKind::Async) {
9595 TokenKind nextSameLine = TokenKind::Eof;
9596 if (!tokenStream.peekTokenSameLine(&nextSameLine)) {
9597 return errorResult();
9598 }
9599 if (nextSameLine == TokenKind::Function) {
9600 uint32_t toStringStart = pos().begin;
9601 tokenStream.consumeKnownToken(TokenKind::Function);
9602 return functionStmt(toStringStart, yieldHandling, NameRequired,
9603 FunctionAsyncKind::AsyncFunction);
9604 }
9605 }
9606
9607 if (next == TokenKind::Colon) {
9608 return labeledStatement(yieldHandling);
9609 }
9610
9611 return expressionStatement(yieldHandling);
9612 }
9613
9614 case TokenKind::New:
9615 return expressionStatement(yieldHandling, PredictInvoked);
9616
9617 // IfStatement[?Yield, ?Return]
9618 case TokenKind::If:
9619 return ifStatement(yieldHandling);
9620
9621 // BreakableStatement[?Yield, ?Return]
9622 //
9623 // BreakableStatement[Yield, Return]:
9624 // IterationStatement[?Yield, ?Return]
9625 // SwitchStatement[?Yield, ?Return]
9626 case TokenKind::Do:
9627 return doWhileStatement(yieldHandling);
9628
9629 case TokenKind::While:
9630 return whileStatement(yieldHandling);
9631
9632 case TokenKind::For:
9633 return forStatement(yieldHandling);
9634
9635 case TokenKind::Switch:
9636 return switchStatement(yieldHandling);
9637
9638 // ContinueStatement[?Yield]
9639 case TokenKind::Continue:
9640 return continueStatement(yieldHandling);
9641
9642 // BreakStatement[?Yield]
9643 case TokenKind::Break:
9644 return breakStatement(yieldHandling);
9645
9646 // [+Return] ReturnStatement[?Yield]
9647 case TokenKind::Return:
9648 // The Return parameter is only used here, and the effect is easily
9649 // detected this way, so don't bother passing around an extra parameter
9650 // everywhere.
9651 if (!pc_->allowReturn()) {
9652 error(JSMSG_BAD_RETURN_OR_YIELD, "return");
9653 return errorResult();
9654 }
9655 return returnStatement(yieldHandling);
9656
9657 // WithStatement[?Yield, ?Return]
9658 case TokenKind::With:
9659 return withStatement(yieldHandling);
9660
9661 // LabelledStatement[?Yield, ?Return]
9662 // This is really handled by default and TokenKind::Yield cases above.
9663
9664 // ThrowStatement[?Yield]
9665 case TokenKind::Throw:
9666 return throwStatement(yieldHandling);
9667
9668 // TryStatement[?Yield, ?Return]
9669 case TokenKind::Try:
9670 return tryStatement(yieldHandling);
9671
9672 // DebuggerStatement
9673 case TokenKind::Debugger:
9674 return debuggerStatement();
9675
9676 // Declaration[Yield]:
9677
9678 // HoistableDeclaration[?Yield, ~Default]
9679 case TokenKind::Function:
9680 return functionStmt(pos().begin, yieldHandling, NameRequired);
9681
9682 // DecoratorList[?Yield, ?Await] opt ClassDeclaration[?Yield, ~Default]
9683#ifdef ENABLE_DECORATORS
9684 case TokenKind::At:
9685 if (fuzzingSafe) {
9686 error(JSMSG_DECORATOR_FUZZING_UNSAFE);
9687 return errorResult();
9688 }
9689 return classDefinition(yieldHandling, ClassStatement, NameRequired);
9690#endif
9691
9692 case TokenKind::Class:
9693 return classDefinition(yieldHandling, ClassStatement, NameRequired);
9694
9695 // LexicalDeclaration[In, ?Yield]
9696 // LetOrConst BindingList[?In, ?Yield]
9697 case TokenKind::Const:
9698 // [In] is the default behavior, because for-loops specially parse
9699 // their heads to handle |in| in this situation.
9700 return lexicalDeclaration(yieldHandling, DeclarationKind::Const);
9701
9702 case TokenKind::Using: {
9703 TokenKind nextTok = TokenKind::Eol;
9704 if (!tokenStream.peekTokenSameLine(&nextTok)) {
9705 return errorResult();
9706 }
9707 if (!TokenKindIsPossibleIdentifier(nextTok) ||
9708 !this->pc_->isUsingSyntaxAllowed()) {
9709 if (!tokenStream.peekToken(&nextTok)) {
9710 return errorResult();
9711 }
9712 // labelled statement could be like using\n:\nexpr
9713 if (nextTok == TokenKind::Colon) {
9714 return labeledStatement(yieldHandling);
9715 }
9716 return expressionStatement(yieldHandling);
9717 }
9718 return lexicalDeclaration(yieldHandling, DeclarationKind::Using);
9719 }
9720
9721 // ImportDeclaration (only inside modules)
9722 case TokenKind::Import:
9723 return importDeclarationOrImportExpr(yieldHandling);
9724
9725 // ExportDeclaration (only inside modules)
9726 case TokenKind::Export:
9727 return exportDeclaration();
9728
9729 // Miscellaneous error cases arguably better caught here than elsewhere.
9730
9731 case TokenKind::Catch:
9732 error(JSMSG_CATCH_WITHOUT_TRY);
9733 return errorResult();
9734
9735 case TokenKind::Finally:
9736 error(JSMSG_FINALLY_WITHOUT_TRY);
9737 return errorResult();
9738
9739 // NOTE: default case handled in the ExpressionStatement section.
9740 }
9741}
9742
9743template <class ParseHandler, typename Unit>
9744typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::expr(
9745 InHandling inHandling, YieldHandling yieldHandling,
9746 TripledotHandling tripledotHandling,
9747 PossibleError* possibleError /* = nullptr */,
9748 InvokedPrediction invoked /* = PredictUninvoked */) {
9749 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(); })
9750 possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(inHandling, yieldHandling, tripledotHandling, possibleError
, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr
()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
9751
9752 bool matched;
9753 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
9754 TokenStream::SlashIsRegExp)) {
9755 return errorResult();
9756 }
9757 if (!matched) {
9758 return pn;
9759 }
9760
9761 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(); })
;
9762 while (true) {
9763 // Trailing comma before the closing parenthesis is valid in an arrow
9764 // function parameters list: `(a, b, ) => body`. Check if we are
9765 // directly under CoverParenthesizedExpressionAndArrowParameterList,
9766 // and the next two tokens are closing parenthesis and arrow. If all
9767 // are present allow the trailing comma.
9768 if (tripledotHandling == TripledotAllowed) {
9769 TokenKind tt;
9770 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
9771 return errorResult();
9772 }
9773
9774 if (tt == TokenKind::RightParen) {
9775 tokenStream.consumeKnownToken(TokenKind::RightParen,
9776 TokenStream::SlashIsRegExp);
9777
9778 if (!tokenStream.peekToken(&tt)) {
9779 return errorResult();
9780 }
9781 if (tt != TokenKind::Arrow) {
9782 error(JSMSG_UNEXPECTED_TOKEN, "expression",
9783 TokenKindToDesc(TokenKind::RightParen));
9784 return errorResult();
9785 }
9786
9787 anyChars.ungetToken(); // put back right paren
9788 break;
9789 }
9790 }
9791
9792 // Additional calls to assignExpr should not reuse the possibleError
9793 // which had been passed into the function. Otherwise we would lose
9794 // information needed to determine whether or not we're dealing with
9795 // a non-recoverable situation.
9796 PossibleError possibleErrorInner(*this);
9797 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(); })
9798 &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(inHandling, yieldHandling, tripledotHandling, &
possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
9799
9800 if (!possibleError) {
9801 // Report any pending expression error.
9802 if (!possibleErrorInner.checkForExpressionError()) {
9803 return errorResult();
9804 }
9805 } else {
9806 possibleErrorInner.transferErrorsTo(possibleError);
9807 }
9808
9809 handler_.addList(seq, pn);
9810
9811 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
9812 TokenStream::SlashIsRegExp)) {
9813 return errorResult();
9814 }
9815 if (!matched) {
9816 break;
9817 }
9818 }
9819 return seq;
9820}
9821
9822static ParseNodeKind BinaryOpTokenKindToParseNodeKind(TokenKind tok) {
9823 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", 9823); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsBinaryOp(tok)" ")"); do { MOZ_CrashSequence
(__null, 9823); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
9824 return ParseNodeKind(size_t(ParseNodeKind::BinOpFirst) +
9825 (size_t(tok) - size_t(TokenKind::BinOpFirst)));
9826}
9827
9828// This list must be kept in the same order in several places:
9829// - The binary operators in ParseNode.h ,
9830// - the binary operators in TokenKind.h
9831// - the JSOp code list in BytecodeEmitter.cpp
9832static const int PrecedenceTable[] = {
9833 1, /* ParseNodeKind::Coalesce */
9834 2, /* ParseNodeKind::Or */
9835 3, /* ParseNodeKind::And */
9836 4, /* ParseNodeKind::BitOr */
9837 5, /* ParseNodeKind::BitXor */
9838 6, /* ParseNodeKind::BitAnd */
9839 7, /* ParseNodeKind::StrictEq */
9840 7, /* ParseNodeKind::Eq */
9841 7, /* ParseNodeKind::StrictNe */
9842 7, /* ParseNodeKind::Ne */
9843 8, /* ParseNodeKind::Lt */
9844 8, /* ParseNodeKind::Le */
9845 8, /* ParseNodeKind::Gt */
9846 8, /* ParseNodeKind::Ge */
9847 8, /* ParseNodeKind::InstanceOf */
9848 8, /* ParseNodeKind::In */
9849 8, /* ParseNodeKind::PrivateIn */
9850 9, /* ParseNodeKind::Lsh */
9851 9, /* ParseNodeKind::Rsh */
9852 9, /* ParseNodeKind::Ursh */
9853 10, /* ParseNodeKind::Add */
9854 10, /* ParseNodeKind::Sub */
9855 11, /* ParseNodeKind::Star */
9856 11, /* ParseNodeKind::Div */
9857 11, /* ParseNodeKind::Mod */
9858 12 /* ParseNodeKind::Pow */
9859};
9860
9861static const int PRECEDENCE_CLASSES = 12;
9862
9863static int Precedence(ParseNodeKind pnk) {
9864 // Everything binds tighter than ParseNodeKind::Limit, because we want
9865 // to reduce all nodes to a single node when we reach a token that is not
9866 // another binary operator.
9867 if (pnk == ParseNodeKind::Limit) {
9868 return 0;
9869 }
9870
9871 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"
, 9871); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pnk >= ParseNodeKind::BinOpFirst"
")"); do { MOZ_CrashSequence(__null, 9871); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9872 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"
, 9872); AnnotateMozCrashReason("MOZ_ASSERT" "(" "pnk <= ParseNodeKind::BinOpLast"
")"); do { MOZ_CrashSequence(__null, 9872); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
9873 return PrecedenceTable[size_t(pnk) - size_t(ParseNodeKind::BinOpFirst)];
9874}
9875
9876enum class EnforcedParentheses : uint8_t { CoalesceExpr, AndOrExpr, None };
9877
9878template <class ParseHandler, typename Unit>
9879MOZ_ALWAYS_INLINEinline typename ParseHandler::NodeResult
9880GeneralParser<ParseHandler, Unit>::orExpr(InHandling inHandling,
9881 YieldHandling yieldHandling,
9882 TripledotHandling tripledotHandling,
9883 PossibleError* possibleError,
9884 InvokedPrediction invoked) {
9885 // Shift-reduce parser for the binary operator part of the JS expression
9886 // syntax.
9887
9888 // Conceptually there's just one stack, a stack of pairs (lhs, op).
9889 // It's implemented using two separate arrays, though.
9890 Node nodeStack[PRECEDENCE_CLASSES];
9891 ParseNodeKind kindStack[PRECEDENCE_CLASSES];
9892 int depth = 0;
9893 Node pn;
9894 EnforcedParentheses unparenthesizedExpression = EnforcedParentheses::None;
9895 for (;;) {
9896 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(); })
9897 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(); })
;
9898
9899 // If a binary operator follows, consume it and compute the
9900 // corresponding operator.
9901 TokenKind tok;
9902 if (!tokenStream.getToken(&tok)) {
9903 return errorResult();
9904 }
9905
9906 // Ensure that if we have a private name lhs we are legally constructing a
9907 // `#x in obj` expessions:
9908 if (handler_.isPrivateName(pn)) {
9909 if (tok != TokenKind::In || inHandling != InAllowed) {
9910 error(JSMSG_ILLEGAL_PRIVATE_NAME);
9911 return errorResult();
9912 }
9913 }
9914
9915 ParseNodeKind pnk;
9916 if (tok == TokenKind::In ? inHandling == InAllowed
9917 : TokenKindIsBinaryOp(tok)) {
9918 // We're definitely not in a destructuring context, so report any
9919 // pending expression error now.
9920 if (possibleError && !possibleError->checkForExpressionError()) {
9921 return errorResult();
9922 }
9923
9924 bool isErgonomicBrandCheck = false;
9925 switch (tok) {
9926 // Report an error for unary expressions on the LHS of **.
9927 case TokenKind::Pow:
9928 if (handler_.isUnparenthesizedUnaryExpression(pn)) {
9929 error(JSMSG_BAD_POW_LEFTSIDE);
9930 return errorResult();
9931 }
9932 break;
9933
9934 case TokenKind::Or:
9935 case TokenKind::And:
9936 // In the case that the `??` is on the left hand side of the
9937 // expression: Disallow Mixing of ?? and other logical operators (||
9938 // and &&) unless one expression is parenthesized
9939 if (unparenthesizedExpression == EnforcedParentheses::CoalesceExpr) {
9940 error(JSMSG_BAD_COALESCE_MIXING);
9941 return errorResult();
9942 }
9943 // If we have not detected a mixing error at this point, record that
9944 // we have an unparenthesized expression, in case we have one later.
9945 unparenthesizedExpression = EnforcedParentheses::AndOrExpr;
9946 break;
9947
9948 case TokenKind::Coalesce:
9949 if (unparenthesizedExpression == EnforcedParentheses::AndOrExpr) {
9950 error(JSMSG_BAD_COALESCE_MIXING);
9951 return errorResult();
9952 }
9953 // If we have not detected a mixing error at this point, record that
9954 // we have an unparenthesized expression, in case we have one later.
9955 unparenthesizedExpression = EnforcedParentheses::CoalesceExpr;
9956 break;
9957
9958 case TokenKind::In:
9959 // if the LHS is a private name, and the operator is In,
9960 // ensure we're construcing an ergonomic brand check of
9961 // '#x in y', rather than having a higher precedence operator
9962 // like + cause a different reduction, such as
9963 // 1 + #x in y.
9964 if (handler_.isPrivateName(pn)) {
9965 if (depth > 0 && Precedence(kindStack[depth - 1]) >=
9966 Precedence(ParseNodeKind::InExpr)) {
9967 error(JSMSG_INVALID_PRIVATE_NAME_PRECEDENCE);
9968 return errorResult();
9969 }
9970
9971 isErgonomicBrandCheck = true;
9972 }
9973 break;
9974
9975 default:
9976 // do nothing in other cases
9977 break;
9978 }
9979
9980 if (isErgonomicBrandCheck) {
9981 pnk = ParseNodeKind::PrivateInExpr;
9982 } else {
9983 pnk = BinaryOpTokenKindToParseNodeKind(tok);
9984 }
9985
9986 } else {
9987 tok = TokenKind::Eof;
9988 pnk = ParseNodeKind::Limit;
9989 }
9990
9991 // From this point on, destructuring defaults are definitely an error.
9992 possibleError = nullptr;
9993
9994 // If pnk has precedence less than or equal to another operator on the
9995 // stack, reduce. This combines nodes on the stack until we form the
9996 // actual lhs of pnk.
9997 //
9998 // The >= in this condition works because it is appendOrCreateList's
9999 // job to decide if the operator in question is left- or
10000 // right-associative, and build the corresponding tree.
10001 while (depth > 0 && Precedence(kindStack[depth - 1]) >= Precedence(pnk)) {
10002 depth--;
10003 ParseNodeKind combiningPnk = kindStack[depth];
10004 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(); })
10005 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(); })
;
10006 }
10007
10008 if (pnk == ParseNodeKind::Limit) {
10009 break;
10010 }
10011
10012 nodeStack[depth] = pn;
10013 kindStack[depth] = pnk;
10014 depth++;
10015 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"
, 10015); AnnotateMozCrashReason("MOZ_ASSERT" "(" "depth <= PRECEDENCE_CLASSES"
")"); do { MOZ_CrashSequence(__null, 10015); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10016 }
10017
10018 anyChars.ungetToken();
10019
10020 // Had the next token been a Div, we would have consumed it. So there's no
10021 // ambiguity if we later (after ASI) re-get this token with SlashIsRegExp.
10022 anyChars.allowGettingNextTokenWithSlashIsRegExp();
10023
10024 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"
, 10024); AnnotateMozCrashReason("MOZ_ASSERT" "(" "depth == 0"
")"); do { MOZ_CrashSequence(__null, 10024); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10025 return pn;
10026}
10027
10028template <class ParseHandler, typename Unit>
10029MOZ_ALWAYS_INLINEinline typename ParseHandler::NodeResult
10030GeneralParser<ParseHandler, Unit>::condExpr(InHandling inHandling,
10031 YieldHandling yieldHandling,
10032 TripledotHandling tripledotHandling,
10033 PossibleError* possibleError,
10034 InvokedPrediction invoked) {
10035 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(); })
10036 possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(orExpr(inHandling, yieldHandling, tripledotHandling, possibleError
, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr
()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
10037
10038 bool matched;
10039 if (!tokenStream.matchToken(&matched, TokenKind::Hook,
10040 TokenStream::SlashIsInvalid)) {
10041 return errorResult();
10042 }
10043 if (!matched) {
10044 return condition;
10045 }
10046
10047 Node thenExpr =
10048 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
(); })
;
10049
10050 if (!mustMatchToken(TokenKind::Colon, JSMSG_COLON_IN_COND)) {
10051 return errorResult();
10052 }
10053
10054 Node elseExpr =
10055 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(); })
;
10056
10057 return handler_.newConditional(condition, thenExpr, elseExpr);
10058}
10059
10060template <class ParseHandler, typename Unit>
10061typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::assignExpr(
10062 InHandling inHandling, YieldHandling yieldHandling,
10063 TripledotHandling tripledotHandling,
10064 PossibleError* possibleError /* = nullptr */,
10065 InvokedPrediction invoked /* = PredictUninvoked */) {
10066 AutoCheckRecursionLimit recursion(this->fc_);
10067 if (!recursion.check(this->fc_)) {
10068 return errorResult();
10069 }
10070
10071 // It's very common at this point to have a "detectably simple" expression,
10072 // i.e. a name/number/string token followed by one of the following tokens
10073 // that obviously isn't part of an expression: , ; : ) ] }
10074 //
10075 // (In Parsemark this happens 81.4% of the time; in code with large
10076 // numeric arrays, such as some Kraken benchmarks, it happens more often.)
10077 //
10078 // In such cases, we can avoid the full expression parsing route through
10079 // assignExpr(), condExpr(), orExpr(), unaryExpr(), memberExpr(), and
10080 // primaryExpr().
10081
10082 TokenKind firstToken;
10083 if (!tokenStream.getToken(&firstToken, TokenStream::SlashIsRegExp)) {
10084 return errorResult();
10085 }
10086
10087 TokenPos exprPos = pos();
10088
10089 bool endsExpr;
10090
10091 // This only handles identifiers that *never* have special meaning anywhere
10092 // in the language. Contextual keywords, reserved words in strict mode,
10093 // and other hard cases are handled outside this fast path.
10094 if (firstToken == TokenKind::Name) {
10095 if (!tokenStream.nextTokenEndsExpr(&endsExpr)) {
10096 return errorResult();
10097 }
10098 if (endsExpr) {
10099 TaggedParserAtomIndex name = identifierReference(yieldHandling);
10100 if (!name) {
10101 return errorResult();
10102 }
10103
10104 return identifierReference(name);
10105 }
10106 }
10107
10108 if (firstToken == TokenKind::Number) {
10109 if (!tokenStream.nextTokenEndsExpr(&endsExpr)) {
10110 return errorResult();
10111 }
10112 if (endsExpr) {
10113 return newNumber(anyChars.currentToken());
10114 }
10115 }
10116
10117 if (firstToken == TokenKind::String) {
10118 if (!tokenStream.nextTokenEndsExpr(&endsExpr)) {
10119 return errorResult();
10120 }
10121 if (endsExpr) {
10122 return stringLiteral();
10123 }
10124 }
10125
10126 if (firstToken == TokenKind::Yield && yieldExpressionsSupported()) {
10127 return yieldExpression(inHandling);
10128 }
10129
10130 bool maybeAsyncArrow = false;
10131 if (firstToken == TokenKind::Async) {
10132 TokenKind nextSameLine = TokenKind::Eof;
10133 if (!tokenStream.peekTokenSameLine(&nextSameLine)) {
10134 return errorResult();
10135 }
10136
10137 if (TokenKindIsPossibleIdentifier(nextSameLine)) {
10138 maybeAsyncArrow = true;
10139 }
10140 }
10141
10142 anyChars.ungetToken();
10143
10144 // Save the tokenizer state in case we find an arrow function and have to
10145 // rewind.
10146 Position start(tokenStream);
10147 auto ghostToken = this->compilationState_.getPosition();
10148
10149 PossibleError possibleErrorInner(*this);
10150 Node lhs;
10151 TokenKind tokenAfterLHS;
10152 bool isArrow;
10153 if (maybeAsyncArrow) {
10154 tokenStream.consumeKnownToken(TokenKind::Async, TokenStream::SlashIsRegExp);
10155
10156 TokenKind tokenAfterAsync;
10157 if (!tokenStream.getToken(&tokenAfterAsync)) {
10158 return errorResult();
10159 }
10160 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", 10160); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifier(tokenAfterAsync)"
")"); do { MOZ_CrashSequence(__null, 10160); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10161
10162 // Check yield validity here.
10163 TaggedParserAtomIndex name = bindingIdentifier(yieldHandling);
10164 if (!name) {
10165 return errorResult();
10166 }
10167
10168 if (!tokenStream.peekToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)) {
10169 return errorResult();
10170 }
10171
10172 isArrow = tokenAfterLHS == TokenKind::Arrow;
10173
10174 // |async [no LineTerminator] of| without being followed by => is only
10175 // possible in for-await-of loops, e.g. |for await (async of [])|. Pretend
10176 // the |async| token was parsed an identifier reference and then proceed
10177 // with the rest of this function.
10178 if (!isArrow) {
10179 anyChars.ungetToken(); // unget the binding identifier
10180
10181 // The next token is guaranteed to never be a Div (, because it's an
10182 // identifier), so it's okay to re-get the token with SlashIsRegExp.
10183 anyChars.allowGettingNextTokenWithSlashIsRegExp();
10184
10185 TaggedParserAtomIndex asyncName = identifierReference(yieldHandling);
10186 if (!asyncName) {
10187 return errorResult();
10188 }
10189
10190 lhs = MOZ_TRY(identifierReference(asyncName))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(identifierReference(asyncName)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10191 }
10192 } else {
10193 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(); })
10194 &possibleErrorInner, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(condExpr(inHandling, yieldHandling, tripledotHandling, &
possibleErrorInner, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10195
10196 // Use SlashIsRegExp here because the ConditionalExpression parsed above
10197 // could be the entirety of this AssignmentExpression, and then ASI
10198 // permits this token to be a regular expression.
10199 if (!tokenStream.peekToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)) {
10200 return errorResult();
10201 }
10202
10203 isArrow = tokenAfterLHS == TokenKind::Arrow;
10204 }
10205
10206 if (isArrow) {
10207 // Rewind to reparse as an arrow function.
10208 //
10209 // Note: We do not call CompilationState::rewind here because parsing
10210 // during delazification will see the same rewind and need the same sequence
10211 // of inner functions to skip over.
10212 // Instead, we mark inner functions as "ghost".
10213 //
10214 // See GHOST_FUNCTION in FunctionFlags.h for more details.
10215 tokenStream.rewind(start);
10216 this->compilationState_.markGhost(ghostToken);
10217
10218 TokenKind next;
10219 if (!tokenStream.getToken(&next, TokenStream::SlashIsRegExp)) {
10220 return errorResult();
10221 }
10222 TokenPos startPos = pos();
10223 uint32_t toStringStart = startPos.begin;
10224 anyChars.ungetToken();
10225
10226 FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction;
10227
10228 if (next == TokenKind::Async) {
10229 tokenStream.consumeKnownToken(next, TokenStream::SlashIsRegExp);
10230
10231 TokenKind nextSameLine = TokenKind::Eof;
10232 if (!tokenStream.peekTokenSameLine(&nextSameLine)) {
10233 return errorResult();
10234 }
10235
10236 // The AsyncArrowFunction production are
10237 // async [no LineTerminator here] AsyncArrowBindingIdentifier ...
10238 // async [no LineTerminator here] ArrowFormalParameters ...
10239 if (TokenKindIsPossibleIdentifier(nextSameLine) ||
10240 nextSameLine == TokenKind::LeftParen) {
10241 asyncKind = FunctionAsyncKind::AsyncFunction;
10242 } else {
10243 anyChars.ungetToken();
10244 }
10245 }
10246
10247 FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Arrow;
10248 FunctionNodeType funNode =
10249 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(); })
;
10250
10251 return functionDefinition(funNode, toStringStart, inHandling, yieldHandling,
10252 TaggedParserAtomIndex::null(), syntaxKind,
10253 GeneratorKind::NotGenerator, asyncKind);
10254 }
10255
10256 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", 10257); AnnotateMozCrashReason
("MOZ_CRASH(" "tokenStream.getToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)"
")"); do { MOZ_CrashSequence(__null, 10257); __attribute__((
nomerge)) ::abort(); } while (false); } while (false); } } while
(false)
10257 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", 10257); AnnotateMozCrashReason
("MOZ_CRASH(" "tokenStream.getToken(&tokenAfterLHS, TokenStream::SlashIsRegExp)"
")"); do { MOZ_CrashSequence(__null, 10257); __attribute__((
nomerge)) ::abort(); } while (false); } while (false); } } while
(false)
;
10258
10259 ParseNodeKind kind;
10260 switch (tokenAfterLHS) {
10261 case TokenKind::Assign:
10262 kind = ParseNodeKind::AssignExpr;
10263 break;
10264 case TokenKind::AddAssign:
10265 kind = ParseNodeKind::AddAssignExpr;
10266 break;
10267 case TokenKind::SubAssign:
10268 kind = ParseNodeKind::SubAssignExpr;
10269 break;
10270 case TokenKind::CoalesceAssign:
10271 kind = ParseNodeKind::CoalesceAssignExpr;
10272 break;
10273 case TokenKind::OrAssign:
10274 kind = ParseNodeKind::OrAssignExpr;
10275 break;
10276 case TokenKind::AndAssign:
10277 kind = ParseNodeKind::AndAssignExpr;
10278 break;
10279 case TokenKind::BitOrAssign:
10280 kind = ParseNodeKind::BitOrAssignExpr;
10281 break;
10282 case TokenKind::BitXorAssign:
10283 kind = ParseNodeKind::BitXorAssignExpr;
10284 break;
10285 case TokenKind::BitAndAssign:
10286 kind = ParseNodeKind::BitAndAssignExpr;
10287 break;
10288 case TokenKind::LshAssign:
10289 kind = ParseNodeKind::LshAssignExpr;
10290 break;
10291 case TokenKind::RshAssign:
10292 kind = ParseNodeKind::RshAssignExpr;
10293 break;
10294 case TokenKind::UrshAssign:
10295 kind = ParseNodeKind::UrshAssignExpr;
10296 break;
10297 case TokenKind::MulAssign:
10298 kind = ParseNodeKind::MulAssignExpr;
10299 break;
10300 case TokenKind::DivAssign:
10301 kind = ParseNodeKind::DivAssignExpr;
10302 break;
10303 case TokenKind::ModAssign:
10304 kind = ParseNodeKind::ModAssignExpr;
10305 break;
10306 case TokenKind::PowAssign:
10307 kind = ParseNodeKind::PowAssignExpr;
10308 break;
10309
10310 default:
10311 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"
, 10311); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!anyChars.isCurrentTokenAssignment()"
")"); do { MOZ_CrashSequence(__null, 10311); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10312 if (!possibleError) {
10313 if (!possibleErrorInner.checkForExpressionError()) {
10314 return errorResult();
10315 }
10316 } else {
10317 possibleErrorInner.transferErrorsTo(possibleError);
10318 }
10319
10320 anyChars.ungetToken();
10321 return lhs;
10322 }
10323
10324 // Verify the left-hand side expression doesn't have a forbidden form.
10325 if (handler_.isUnparenthesizedDestructuringPattern(lhs)) {
10326 if (kind != ParseNodeKind::AssignExpr) {
10327 error(JSMSG_BAD_DESTRUCT_ASS);
10328 return errorResult();
10329 }
10330
10331 if (!possibleErrorInner.checkForDestructuringErrorOrWarning()) {
10332 return errorResult();
10333 }
10334 } else if (handler_.isName(lhs)) {
10335 if (const char* chars = nameIsArgumentsOrEval(lhs)) {
10336 // |chars| is "arguments" or "eval" here.
10337 if (!strictModeErrorAt(exprPos.begin, JSMSG_BAD_STRICT_ASSIGN, chars)) {
10338 return errorResult();
10339 }
10340 }
10341 } else if (handler_.isArgumentsLength(lhs)) {
10342 pc_->sc()->setIneligibleForArgumentsLength();
10343 } else if (handler_.isPropertyOrPrivateMemberAccess(lhs)) {
10344 // Permitted: no additional testing/fixup needed.
10345 } else if (handler_.isFunctionCall(lhs)) {
10346 // We don't have to worry about backward compatibility issues with the new
10347 // compound assignment operators, so we always throw here. Also that way we
10348 // don't have to worry if |f() &&= expr| should always throw an error or
10349 // only if |f()| returns true.
10350 if (kind == ParseNodeKind::CoalesceAssignExpr ||
10351 kind == ParseNodeKind::OrAssignExpr ||
10352 kind == ParseNodeKind::AndAssignExpr) {
10353 errorAt(exprPos.begin, JSMSG_BAD_LEFTSIDE_OF_ASS);
10354 return errorResult();
10355 }
10356
10357 if (!strictModeErrorAt(exprPos.begin, JSMSG_BAD_LEFTSIDE_OF_ASS)) {
10358 return errorResult();
10359 }
10360
10361 if (possibleError) {
10362 possibleError->setPendingDestructuringErrorAt(exprPos,
10363 JSMSG_BAD_DESTRUCT_TARGET);
10364 }
10365 } else {
10366 errorAt(exprPos.begin, JSMSG_BAD_LEFTSIDE_OF_ASS);
10367 return errorResult();
10368 }
10369
10370 if (!possibleErrorInner.checkForExpressionError()) {
10371 return errorResult();
10372 }
10373
10374 Node rhs =
10375 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(); })
;
10376
10377 return handler_.newAssignment(kind, lhs, rhs);
10378}
10379
10380template <class ParseHandler>
10381const char* PerHandlerParser<ParseHandler>::nameIsArgumentsOrEval(Node node) {
10382 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"
, 10383); AnnotateMozCrashReason("MOZ_ASSERT" "(" "handler_.isName(node)"
") (" "must only call this function on known names" ")"); do
{ MOZ_CrashSequence(__null, 10383); __attribute__((nomerge))
::abort(); } while (false); } } while (false)
10383 "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"
, 10383); AnnotateMozCrashReason("MOZ_ASSERT" "(" "handler_.isName(node)"
") (" "must only call this function on known names" ")"); do
{ MOZ_CrashSequence(__null, 10383); __attribute__((nomerge))
::abort(); } while (false); } } while (false)
;
10384
10385 if (handler_.isEvalName(node)) {
10386 return "eval";
10387 }
10388 if (handler_.isArgumentsName(node)) {
10389 return "arguments";
10390 }
10391 return nullptr;
10392}
10393
10394template <class ParseHandler, typename Unit>
10395bool GeneralParser<ParseHandler, Unit>::checkIncDecOperand(
10396 Node operand, uint32_t operandOffset) {
10397 if (handler_.isName(operand)) {
10398 if (const char* chars = nameIsArgumentsOrEval(operand)) {
10399 if (!strictModeErrorAt(operandOffset, JSMSG_BAD_STRICT_ASSIGN, chars)) {
10400 return false;
10401 }
10402 }
10403 } else if (handler_.isArgumentsLength(operand)) {
10404 pc_->sc()->setIneligibleForArgumentsLength();
10405 } else if (handler_.isPropertyOrPrivateMemberAccess(operand)) {
10406 // Permitted: no additional testing/fixup needed.
10407 } else if (handler_.isFunctionCall(operand)) {
10408 // Assignment to function calls is forbidden in ES6. We're still
10409 // somewhat concerned about sites using this in dead code, so forbid it
10410 // only in strict mode code.
10411 if (!strictModeErrorAt(operandOffset, JSMSG_BAD_INCOP_OPERAND)) {
10412 return false;
10413 }
10414 } else {
10415 errorAt(operandOffset, JSMSG_BAD_INCOP_OPERAND);
10416 return false;
10417 }
10418 return true;
10419}
10420
10421template <class ParseHandler, typename Unit>
10422typename ParseHandler::UnaryNodeResult
10423GeneralParser<ParseHandler, Unit>::unaryOpExpr(YieldHandling yieldHandling,
10424 ParseNodeKind kind,
10425 uint32_t begin) {
10426 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(); })
;
10427 return handler_.newUnary(kind, begin, kid);
10428}
10429
10430template <class ParseHandler, typename Unit>
10431typename ParseHandler::NodeResult
10432GeneralParser<ParseHandler, Unit>::optionalExpr(
10433 YieldHandling yieldHandling, TripledotHandling tripledotHandling,
10434 TokenKind tt, PossibleError* possibleError /* = nullptr */,
10435 InvokedPrediction invoked /* = PredictUninvoked */) {
10436 AutoCheckRecursionLimit recursion(this->fc_);
10437 if (!recursion.check(this->fc_)) {
10438 return errorResult();
10439 }
10440
10441 uint32_t begin = pos().begin;
10442
10443 Node lhs =
10444 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(); })
10445 /* 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(); })
;
10446
10447 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsDiv)) {
10448 return errorResult();
10449 }
10450
10451 if (tt != TokenKind::OptionalChain) {
10452 return lhs;
10453 }
10454
10455 while (true) {
10456 if (!tokenStream.getToken(&tt)) {
10457 return errorResult();
10458 }
10459
10460 if (tt == TokenKind::Eof) {
10461 anyChars.ungetToken();
10462 break;
10463 }
10464
10465 Node nextMember;
10466 if (tt == TokenKind::OptionalChain) {
10467 if (!tokenStream.getToken(&tt)) {
10468 return errorResult();
10469 }
10470 if (TokenKindIsPossibleIdentifierName(tt)) {
10471 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(); })
;
10472 } else if (tt == TokenKind::PrivateName) {
10473 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(); })
;
10474 } else if (tt == TokenKind::LeftBracket) {
10475 nextMember = MOZ_TRY(__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberElemAccess(lhs, yieldHandling, OptionalKind::Optional)
); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0))
) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
10476 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(); })
;
10477 } else if (tt == TokenKind::LeftParen) {
10478 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(); })
10479 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(); })
;
10480 } else {
10481 error(JSMSG_NAME_AFTER_DOT);
10482 return errorResult();
10483 }
10484 } else if (tt == TokenKind::Dot) {
10485 if (!tokenStream.getToken(&tt)) {
10486 return errorResult();
10487 }
10488 if (TokenKindIsPossibleIdentifierName(tt)) {
10489 nextMember = MOZ_TRY(memberPropertyAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberPropertyAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10490 } else if (tt == TokenKind::PrivateName) {
10491 nextMember = MOZ_TRY(memberPrivateAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberPrivateAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10492 } else {
10493 error(JSMSG_NAME_AFTER_DOT);
10494 return errorResult();
10495 }
10496 } else if (tt == TokenKind::LeftBracket) {
10497 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(); })
;
10498 } else if (tt == TokenKind::LeftParen) {
10499 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(); })
;
10500 } else if (tt == TokenKind::TemplateHead ||
10501 tt == TokenKind::NoSubsTemplate) {
10502 error(JSMSG_BAD_OPTIONAL_TEMPLATE);
10503 return errorResult();
10504 } else {
10505 anyChars.ungetToken();
10506 break;
10507 }
10508
10509 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"
, 10509); AnnotateMozCrashReason("MOZ_ASSERT" "(" "nextMember"
")"); do { MOZ_CrashSequence(__null, 10509); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10510 lhs = nextMember;
10511 }
10512
10513 return handler_.newOptionalChain(begin, lhs);
10514}
10515
10516template <class ParseHandler, typename Unit>
10517typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::unaryExpr(
10518 YieldHandling yieldHandling, TripledotHandling tripledotHandling,
10519 PossibleError* possibleError /* = nullptr */,
10520 InvokedPrediction invoked /* = PredictUninvoked */,
10521 PrivateNameHandling privateNameHandling /* = PrivateNameProhibited */) {
10522 AutoCheckRecursionLimit recursion(this->fc_);
10523 if (!recursion.check(this->fc_)) {
10524 return errorResult();
10525 }
10526
10527 TokenKind tt;
10528 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
10529 return errorResult();
10530 }
10531 uint32_t begin = pos().begin;
10532 switch (tt) {
10533 case TokenKind::Void:
10534 return unaryOpExpr(yieldHandling, ParseNodeKind::VoidExpr, begin);
10535 case TokenKind::Not:
10536 return unaryOpExpr(yieldHandling, ParseNodeKind::NotExpr, begin);
10537 case TokenKind::BitNot:
10538 return unaryOpExpr(yieldHandling, ParseNodeKind::BitNotExpr, begin);
10539 case TokenKind::Add:
10540 return unaryOpExpr(yieldHandling, ParseNodeKind::PosExpr, begin);
10541 case TokenKind::Sub:
10542 return unaryOpExpr(yieldHandling, ParseNodeKind::NegExpr, begin);
10543
10544 case TokenKind::TypeOf: {
10545 // The |typeof| operator is specially parsed to distinguish its
10546 // application to a name, from its application to a non-name
10547 // expression:
10548 //
10549 // // Looks up the name, doesn't find it and so evaluates to
10550 // // "undefined".
10551 // assertEq(typeof nonExistentName, "undefined");
10552 //
10553 // // Evaluates expression, triggering a runtime ReferenceError for
10554 // // the undefined name.
10555 // typeof (1, nonExistentName);
10556 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(); })
;
10557
10558 return handler_.newTypeof(begin, kid);
10559 }
10560
10561 case TokenKind::Inc:
10562 case TokenKind::Dec: {
10563 TokenKind tt2;
10564 if (!tokenStream.getToken(&tt2, TokenStream::SlashIsRegExp)) {
10565 return errorResult();
10566 }
10567
10568 uint32_t operandOffset = pos().begin;
10569 Node operand =
10570 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
(); })
;
10571 if (!checkIncDecOperand(operand, operandOffset)) {
10572 return errorResult();
10573 }
10574 ParseNodeKind pnk = (tt == TokenKind::Inc)
10575 ? ParseNodeKind::PreIncrementExpr
10576 : ParseNodeKind::PreDecrementExpr;
10577 return handler_.newUpdate(pnk, begin, operand);
10578 }
10579 case TokenKind::PrivateName: {
10580 if (privateNameHandling == PrivateNameHandling::PrivateNameAllowed) {
10581 TaggedParserAtomIndex field = anyChars.currentName();
10582 return privateNameReference(field);
10583 }
10584 error(JSMSG_INVALID_PRIVATE_NAME_IN_UNARY_EXPR);
10585 return errorResult();
10586 }
10587
10588 case TokenKind::Delete: {
10589 uint32_t exprOffset;
10590 if (!tokenStream.peekOffset(&exprOffset, TokenStream::SlashIsRegExp)) {
10591 return errorResult();
10592 }
10593
10594 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(); })
;
10595
10596 // Per spec, deleting most unary expressions is valid -- it simply
10597 // returns true -- except for two cases:
10598 // 1. `var x; ...; delete x` is a syntax error in strict mode.
10599 // 2. Private fields cannot be deleted.
10600 if (handler_.isName(expr)) {
10601 if (!strictModeErrorAt(exprOffset, JSMSG_DEPRECATED_DELETE_OPERAND)) {
10602 return errorResult();
10603 }
10604
10605 pc_->sc()->setBindingsAccessedDynamically();
10606 }
10607
10608 if (handler_.isPrivateMemberAccess(expr)) {
10609 errorAt(exprOffset, JSMSG_PRIVATE_DELETE);
10610 return errorResult();
10611 }
10612
10613 if (handler_.isArgumentsLength(expr)) {
10614 pc_->sc()->setIneligibleForArgumentsLength();
10615 }
10616
10617 return handler_.newDelete(begin, expr);
10618 }
10619 case TokenKind::Await: {
10620 // If we encounter an await in a module, mark it as async.
10621 if (!pc_->isAsync() && pc_->sc()->isModule()) {
10622 if (!options().topLevelAwait) {
10623 error(JSMSG_TOP_LEVEL_AWAIT_NOT_SUPPORTED);
10624 return errorResult();
10625 }
10626 pc_->sc()->asModuleContext()->setIsAsync();
10627 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", 10627); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->isAsync()" ")"); do { MOZ_CrashSequence
(__null, 10627); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
10628 }
10629
10630 if (pc_->isAsync()) {
10631 if (inParametersOfAsyncFunction()) {
10632 error(JSMSG_AWAIT_IN_PARAMETER);
10633 return errorResult();
10634 }
10635 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(); })
10636 possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
10637 pc_->lastAwaitOffset = begin;
10638 return handler_.newAwaitExpression(begin, kid);
10639 }
10640 }
10641
10642 [[fallthrough]];
10643
10644 default: {
10645 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(); })
10646 possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(optionalExpr(yieldHandling, tripledotHandling, tt, possibleError
, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr
()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
10647
10648 /* Don't look across a newline boundary for a postfix incop. */
10649 if (!tokenStream.peekTokenSameLine(&tt)) {
10650 return errorResult();
10651 }
10652
10653 if (tt != TokenKind::Inc && tt != TokenKind::Dec) {
10654 return expr;
10655 }
10656
10657 tokenStream.consumeKnownToken(tt);
10658 if (!checkIncDecOperand(expr, begin)) {
10659 return errorResult();
10660 }
10661
10662 ParseNodeKind pnk = (tt == TokenKind::Inc)
10663 ? ParseNodeKind::PostIncrementExpr
10664 : ParseNodeKind::PostDecrementExpr;
10665 return handler_.newUpdate(pnk, begin, expr);
10666 }
10667 }
10668}
10669
10670template <class ParseHandler, typename Unit>
10671typename ParseHandler::NodeResult
10672GeneralParser<ParseHandler, Unit>::assignExprWithoutYieldOrAwait(
10673 YieldHandling yieldHandling) {
10674 uint32_t startYieldOffset = pc_->lastYieldOffset;
10675 uint32_t startAwaitOffset = pc_->lastAwaitOffset;
10676
10677 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
(); })
;
10678
10679 if (pc_->lastYieldOffset != startYieldOffset) {
10680 errorAt(pc_->lastYieldOffset, JSMSG_YIELD_IN_PARAMETER);
10681 return errorResult();
10682 }
10683 if (pc_->lastAwaitOffset != startAwaitOffset) {
10684 errorAt(pc_->lastAwaitOffset, JSMSG_AWAIT_IN_PARAMETER);
10685 return errorResult();
10686 }
10687 return res;
10688}
10689
10690template <class ParseHandler, typename Unit>
10691typename ParseHandler::ListNodeResult
10692GeneralParser<ParseHandler, Unit>::argumentList(
10693 YieldHandling yieldHandling, bool* isSpread,
10694 PossibleError* possibleError /* = nullptr */) {
10695 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(); })
;
10696
10697 bool matched;
10698 if (!tokenStream.matchToken(&matched, TokenKind::RightParen,
10699 TokenStream::SlashIsRegExp)) {
10700 return errorResult();
10701 }
10702 if (matched) {
10703 handler_.setEndPosition(argsList, pos().end);
10704 return argsList;
10705 }
10706
10707 while (true) {
10708 bool spread = false;
10709 uint32_t begin = 0;
10710 if (!tokenStream.matchToken(&matched, TokenKind::TripleDot,
10711 TokenStream::SlashIsRegExp)) {
10712 return errorResult();
10713 }
10714 if (matched) {
10715 spread = true;
10716 begin = pos().begin;
10717 *isSpread = true;
10718 }
10719
10720 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(); })
10721 TripledotProhibited, possibleError))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(InAllowed, yieldHandling, TripledotProhibited, possibleError
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
10722 if (spread) {
10723 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(); })
;
10724 }
10725
10726 handler_.addList(argsList, argNode);
10727
10728 bool matched;
10729 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
10730 TokenStream::SlashIsRegExp)) {
10731 return errorResult();
10732 }
10733 if (!matched) {
10734 break;
10735 }
10736
10737 TokenKind tt;
10738 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
10739 return errorResult();
10740 }
10741 if (tt == TokenKind::RightParen) {
10742 break;
10743 }
10744 }
10745
10746 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_ARGS)) {
10747 return errorResult();
10748 }
10749
10750 handler_.setEndPosition(argsList, pos().end);
10751 return argsList;
10752}
10753
10754bool ParserBase::checkAndMarkSuperScope() {
10755 if (!pc_->sc()->allowSuperProperty()) {
10756 return false;
10757 }
10758
10759 pc_->setSuperScopeNeedsHomeObject();
10760 return true;
10761}
10762
10763template <class ParseHandler, typename Unit>
10764bool GeneralParser<ParseHandler, Unit>::computeErrorMetadata(
10765 ErrorMetadata* err, const ErrorReportMixin::ErrorOffset& offset) const {
10766 if (offset.is<ErrorReportMixin::Current>()) {
10767 return tokenStream.computeErrorMetadata(err, AsVariant(pos().begin));
10768 }
10769 return tokenStream.computeErrorMetadata(err, offset);
10770}
10771
10772template <class ParseHandler, typename Unit>
10773typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::memberExpr(
10774 YieldHandling yieldHandling, TripledotHandling tripledotHandling,
10775 TokenKind tt, bool allowCallSyntax, PossibleError* possibleError,
10776 InvokedPrediction invoked) {
10777 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"
, 10777); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)"
")"); do { MOZ_CrashSequence(__null, 10777); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10778
10779 Node lhs;
10780
10781 AutoCheckRecursionLimit recursion(this->fc_);
10782 if (!recursion.check(this->fc_)) {
10783 return errorResult();
10784 }
10785
10786 /* Check for new expression first. */
10787 if (tt == TokenKind::New) {
10788 uint32_t newBegin = pos().begin;
10789 // Make sure this wasn't a |new.target| in disguise.
10790 NewTargetNodeType newTarget;
10791 if (!tryNewTarget(&newTarget)) {
10792 return errorResult();
10793 }
10794 if (newTarget) {
10795 lhs = newTarget;
10796 } else {
10797 // Gotten by tryNewTarget
10798 tt = anyChars.currentToken().type;
10799 Node ctorExpr =
10800 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(); })
10801 /* 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(); })
10802 /* 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(); })
;
10803
10804 // If we have encountered an optional chain, in the form of `new
10805 // ClassName?.()` then we need to throw, as this is disallowed by the
10806 // spec.
10807 bool optionalToken;
10808 if (!tokenStream.matchToken(&optionalToken, TokenKind::OptionalChain)) {
10809 return errorResult();
10810 }
10811 if (optionalToken) {
10812 errorAt(newBegin, JSMSG_BAD_NEW_OPTIONAL);
10813 return errorResult();
10814 }
10815
10816 bool matched;
10817 if (!tokenStream.matchToken(&matched, TokenKind::LeftParen)) {
10818 return errorResult();
10819 }
10820
10821 bool isSpread = false;
10822 ListNodeType args;
10823 if (matched) {
10824 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(); })
;
10825 } else {
10826 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(); })
;
10827 }
10828
10829 if (!args) {
10830 return errorResult();
10831 }
10832
10833 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(); })
10834 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(); })
;
10835 }
10836 } else if (tt == TokenKind::Super) {
10837 NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10838 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(); })
;
10839 } else if (tt == TokenKind::Import) {
10840 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(); })
;
10841 } else {
10842 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(); })
10843 possibleError, invoked))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(primaryExpr(yieldHandling, tripledotHandling, tt, possibleError
, invoked)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr
()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
10844 }
10845
10846 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"
, 10847); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Super)"
")"); do { MOZ_CrashSequence(__null, 10847); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
10847 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"
, 10847); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Super)"
")"); do { MOZ_CrashSequence(__null, 10847); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false); } } while
(false)
;
10848
10849 while (true) {
10850 if (!tokenStream.getToken(&tt)) {
10851 return errorResult();
10852 }
10853 if (tt == TokenKind::Eof) {
10854 anyChars.ungetToken();
10855 break;
10856 }
10857
10858 Node nextMember;
10859 if (tt == TokenKind::Dot) {
10860 if (!tokenStream.getToken(&tt)) {
10861 return errorResult();
10862 }
10863
10864 if (TokenKindIsPossibleIdentifierName(tt)) {
10865 nextMember = MOZ_TRY(memberPropertyAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberPropertyAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10866 } else if (tt == TokenKind::PrivateName) {
10867 nextMember = MOZ_TRY(memberPrivateAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberPrivateAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10868 } else {
10869 error(JSMSG_NAME_AFTER_DOT);
10870 return errorResult();
10871 }
10872 } else if (tt == TokenKind::LeftBracket) {
10873 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(); })
;
10874 } else if ((allowCallSyntax && tt == TokenKind::LeftParen) ||
10875 tt == TokenKind::TemplateHead ||
10876 tt == TokenKind::NoSubsTemplate) {
10877 if (handler_.isSuperBase(lhs)) {
10878 if (!pc_->sc()->allowSuperCall()) {
10879 error(JSMSG_BAD_SUPERCALL);
10880 return errorResult();
10881 }
10882
10883 if (tt != TokenKind::LeftParen) {
10884 error(JSMSG_BAD_SUPER);
10885 return errorResult();
10886 }
10887
10888 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(); })
;
10889
10890 if (!noteUsedName(
10891 TaggedParserAtomIndex::WellKnown::dot_initializers_())) {
10892 return errorResult();
10893 }
10894#ifdef ENABLE_DECORATORS
10895 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::
10896 dot_instanceExtraInitializers_())) {
10897 return errorResult();
10898 }
10899#endif
10900 } else {
10901 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(); })
;
10902 }
10903 } else {
10904 anyChars.ungetToken();
10905 if (handler_.isSuperBase(lhs)) {
10906 break;
10907 }
10908 return lhs;
10909 }
10910
10911 lhs = nextMember;
10912 }
10913
10914 if (handler_.isSuperBase(lhs)) {
10915 error(JSMSG_BAD_SUPER);
10916 return errorResult();
10917 }
10918
10919 return lhs;
10920}
10921
10922template <class ParseHandler, typename Unit>
10923typename ParseHandler::NodeResult
10924GeneralParser<ParseHandler, Unit>::decoratorExpr(YieldHandling yieldHandling,
10925 TokenKind tt) {
10926 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"
, 10926); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)"
")"); do { MOZ_CrashSequence(__null, 10926); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
10927
10928 AutoCheckRecursionLimit recursion(this->fc_);
10929 if (!recursion.check(this->fc_)) {
10930 return errorResult();
10931 }
10932
10933 if (tt == TokenKind::LeftParen) {
10934 // DecoratorParenthesizedExpression
10935 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(); })
10936 /* possibleError*/ nullptr))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(exprInParens(InAllowed, yieldHandling, TripledotAllowed, nullptr
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
10937 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_DECORATOR)) {
10938 return errorResult();
10939 }
10940
10941 return handler_.parenthesize(expr);
10942 }
10943
10944 if (!TokenKindIsPossibleIdentifier(tt)) {
10945 error(JSMSG_DECORATOR_NAME_EXPECTED);
10946 return errorResult();
10947 }
10948
10949 TaggedParserAtomIndex name = identifierReference(yieldHandling);
10950 if (!name) {
10951 return errorResult();
10952 }
10953
10954 Node lhs = MOZ_TRY(identifierReference(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(identifierReference(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10955
10956 while (true) {
10957 if (!tokenStream.getToken(&tt)) {
10958 return errorResult();
10959 }
10960 if (tt == TokenKind::Eof) {
10961 anyChars.ungetToken();
10962 break;
10963 }
10964
10965 Node nextMember;
10966 if (tt == TokenKind::Dot) {
10967 if (!tokenStream.getToken(&tt)) {
10968 return errorResult();
10969 }
10970
10971 if (TokenKindIsPossibleIdentifierName(tt)) {
10972 nextMember = MOZ_TRY(memberPropertyAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberPropertyAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10973 } else if (tt == TokenKind::PrivateName) {
10974 nextMember = MOZ_TRY(memberPrivateAccess(lhs))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberPrivateAccess(lhs)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
10975 } else {
10976 error(JSMSG_NAME_AFTER_DOT);
10977 return errorResult();
10978 }
10979 } else if (tt == TokenKind::LeftParen) {
10980 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(); })
10981 /* possibleError */ nullptr))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(memberCall(tt, lhs, yieldHandling, nullptr)); if ((__builtin_expect
(!!(mozTryVarTempResult.isErr()), 0))) { return mozTryVarTempResult
.propagateErr(); } mozTryVarTempResult.unwrap(); })
;
10982 lhs = nextMember;
10983 // This is a `DecoratorCallExpression` and it's defined at the top level
10984 // of `Decorator`, no other `DecoratorMemberExpression` is allowed to
10985 // follow after the arguments.
10986 break;
10987 } else {
10988 anyChars.ungetToken();
10989 break;
10990 }
10991
10992 lhs = nextMember;
10993 }
10994
10995 return lhs;
10996}
10997
10998template <class ParseHandler>
10999inline typename ParseHandler::NameNodeResult
11000PerHandlerParser<ParseHandler>::newName(TaggedParserAtomIndex name) {
11001 return newName(name, pos());
11002}
11003
11004template <class ParseHandler>
11005inline typename ParseHandler::NameNodeResult
11006PerHandlerParser<ParseHandler>::newName(TaggedParserAtomIndex name,
11007 TokenPos pos) {
11008 if (name == TaggedParserAtomIndex::WellKnown::arguments()) {
11009 this->pc_->numberOfArgumentsNames++;
11010 }
11011 return handler_.newName(name, pos);
11012}
11013
11014template <class ParseHandler>
11015inline typename ParseHandler::NameNodeResult
11016PerHandlerParser<ParseHandler>::newPrivateName(TaggedParserAtomIndex name) {
11017 return handler_.newPrivateName(name, pos());
11018}
11019
11020template <class ParseHandler, typename Unit>
11021typename ParseHandler::NodeResult
11022GeneralParser<ParseHandler, Unit>::memberPropertyAccess(
11023 Node lhs, OptionalKind optionalKind /* = OptionalKind::NonOptional */) {
11024 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", 11025); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(anyChars.currentToken().type) || anyChars.currentToken().type == TokenKind::PrivateName"
")"); do { MOZ_CrashSequence(__null, 11025); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
11025 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", 11025); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "TokenKindIsPossibleIdentifierName(anyChars.currentToken().type) || anyChars.currentToken().type == TokenKind::PrivateName"
")"); do { MOZ_CrashSequence(__null, 11025); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11026 TaggedParserAtomIndex field = anyChars.currentName();
11027 if (handler_.isSuperBase(lhs) && !checkAndMarkSuperScope()) {
11028 error(JSMSG_BAD_SUPERPROP, "property");
11029 return errorResult();
11030 }
11031
11032 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(); })
;
11033
11034 if (optionalKind == OptionalKind::Optional) {
11035 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", 11035); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!handler_.isSuperBase(lhs)" ")"); do { MOZ_CrashSequence
(__null, 11035); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
11036 return handler_.newOptionalPropertyAccess(lhs, name);
11037 }
11038
11039 if (handler_.isArgumentsName(lhs) && handler_.isLengthName(name)) {
11040 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", 11040); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "pc_->numberOfArgumentsNames > 0" ")"
); do { MOZ_CrashSequence(__null, 11040); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
11041 pc_->numberOfArgumentsNames--;
11042 // Resumed generators and async functions have numActualArgs == 0.
11043 // See e.g. InterpreterStack::createGeneratorResumeFrame and its call to
11044 // initCallFrame.
11045 if (pc_->isGeneratorOrAsync()) {
11046 pc_->sc()->setIneligibleForArgumentsLength();
11047 }
11048 return handler_.newArgumentsLength(lhs, name);
11049 }
11050
11051 return handler_.newPropertyAccess(lhs, name);
11052}
11053
11054template <class ParseHandler, typename Unit>
11055typename ParseHandler::NodeResult
11056GeneralParser<ParseHandler, Unit>::memberPrivateAccess(
11057 Node lhs, OptionalKind optionalKind /* = OptionalKind::NonOptional */) {
11058 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"
, 11058); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::PrivateName"
")"); do { MOZ_CrashSequence(__null, 11058); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11059
11060 TaggedParserAtomIndex field = anyChars.currentName();
11061 // Cannot access private fields on super.
11062 if (handler_.isSuperBase(lhs)) {
11063 error(JSMSG_BAD_SUPERPRIVATE);
11064 return errorResult();
11065 }
11066
11067 NameNodeType privateName = MOZ_TRY(privateNameReference(field))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(privateNameReference(field)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
11068
11069 if (optionalKind == OptionalKind::Optional) {
11070 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", 11070); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!handler_.isSuperBase(lhs)" ")"); do { MOZ_CrashSequence
(__null, 11070); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
11071 return handler_.newOptionalPrivateMemberAccess(lhs, privateName, pos().end);
11072 }
11073 return handler_.newPrivateMemberAccess(lhs, privateName, pos().end);
11074}
11075
11076template <class ParseHandler, typename Unit>
11077typename ParseHandler::NodeResult
11078GeneralParser<ParseHandler, Unit>::memberElemAccess(
11079 Node lhs, YieldHandling yieldHandling,
11080 OptionalKind optionalKind /* = OptionalKind::NonOptional */) {
11081 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"
, 11081); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::LeftBracket"
")"); do { MOZ_CrashSequence(__null, 11081); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11082 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(); })
;
11083
11084 if (!mustMatchToken(TokenKind::RightBracket, JSMSG_BRACKET_IN_INDEX)) {
11085 return errorResult();
11086 }
11087
11088 if (handler_.isSuperBase(lhs) && !checkAndMarkSuperScope()) {
11089 error(JSMSG_BAD_SUPERPROP, "member");
11090 return errorResult();
11091 }
11092 if (optionalKind == OptionalKind::Optional) {
11093 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", 11093); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!handler_.isSuperBase(lhs)" ")"); do { MOZ_CrashSequence
(__null, 11093); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
11094 return handler_.newOptionalPropertyByValue(lhs, propExpr, pos().end);
11095 }
11096 return handler_.newPropertyByValue(lhs, propExpr, pos().end);
11097}
11098
11099template <class ParseHandler, typename Unit>
11100typename ParseHandler::NodeResult
11101GeneralParser<ParseHandler, Unit>::memberSuperCall(
11102 Node lhs, YieldHandling yieldHandling) {
11103 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"
, 11103); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.currentToken().type == TokenKind::LeftParen"
")"); do { MOZ_CrashSequence(__null, 11103); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11104 // Despite the fact that it's impossible to have |super()| in a
11105 // generator, we still inherit the yieldHandling of the
11106 // memberExpression, per spec. Curious.
11107 bool isSpread = false;
11108 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(); })
;
11109
11110 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(); })
;
11111
11112 // |super()| implicitly reads |new.target|.
11113 if (!noteUsedName(TaggedParserAtomIndex::WellKnown::dot_newTarget_())) {
11114 return errorResult();
11115 }
11116
11117 NameNodeType thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
11118
11119 return handler_.newSetThis(thisName, superCall);
11120}
11121
11122template <class ParseHandler, typename Unit>
11123typename ParseHandler::NodeResult GeneralParser<ParseHandler, Unit>::memberCall(
11124 TokenKind tt, Node lhs, YieldHandling yieldHandling,
11125 PossibleError* possibleError /* = nullptr */,
11126 OptionalKind optionalKind /* = OptionalKind::NonOptional */) {
11127 if (options().selfHostingMode &&
11128 (handler_.isPropertyOrPrivateMemberAccess(lhs) ||
11129 handler_.isOptionalPropertyOrPrivateMemberAccess(lhs))) {
11130 error(JSMSG_SELFHOSTED_METHOD_CALL);
11131 return errorResult();
11132 }
11133
11134 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"
, 11136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate"
") (" "Unexpected token kind for member call" ")"); do { MOZ_CrashSequence
(__null, 11136); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
11135 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"
, 11136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate"
") (" "Unexpected token kind for member call" ")"); do { MOZ_CrashSequence
(__null, 11136); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
11136 "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"
, 11136); AnnotateMozCrashReason("MOZ_ASSERT" "(" "tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead || tt == TokenKind::NoSubsTemplate"
") (" "Unexpected token kind for member call" ")"); do { MOZ_CrashSequence
(__null, 11136); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
11137
11138 JSOp op = JSOp::Call;
11139 bool maybeAsyncArrow = false;
11140 if (tt == TokenKind::LeftParen && optionalKind == OptionalKind::NonOptional) {
11141 if (handler_.isAsyncKeyword(lhs)) {
11142 // |async (| can be the start of an async arrow
11143 // function, so we need to defer reporting possible
11144 // errors from destructuring syntax. To give better
11145 // error messages, we only allow the AsyncArrowHead
11146 // part of the CoverCallExpressionAndAsyncArrowHead
11147 // syntax when the initial name is "async".
11148 maybeAsyncArrow = true;
11149 } else if (handler_.isEvalName(lhs)) {
11150 // Select the right Eval op and flag pc_ as having a
11151 // direct eval.
11152 op = pc_->sc()->strict() ? JSOp::StrictEval : JSOp::Eval;
11153 pc_->sc()->setBindingsAccessedDynamically();
11154 pc_->sc()->setHasDirectEval();
11155
11156 // In non-strict mode code, direct calls to eval can
11157 // add variables to the call object.
11158 if (pc_->isFunctionBox() && !pc_->sc()->strict()) {
11159 pc_->functionBox()->setFunHasExtensibleScope();
11160 }
11161
11162 // If we're in a method, mark the method as requiring
11163 // support for 'super', since direct eval code can use
11164 // it. (If we're not in a method, that's fine, so
11165 // ignore the return value.)
11166 checkAndMarkSuperScope();
11167 }
11168 }
11169
11170 if (tt == TokenKind::LeftParen) {
11171 bool isSpread = false;
11172 PossibleError* asyncPossibleError =
11173 maybeAsyncArrow ? possibleError : nullptr;
11174 ListNodeType args =
11175 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(); })
;
11176 if (isSpread) {
11177 if (op == JSOp::Eval) {
11178 op = JSOp::SpreadEval;
11179 } else if (op == JSOp::StrictEval) {
11180 op = JSOp::StrictSpreadEval;
11181 } else {
11182 op = JSOp::SpreadCall;
11183 }
11184 }
11185
11186 if (optionalKind == OptionalKind::Optional) {
11187 return handler_.newOptionalCall(lhs, args, op);
11188 }
11189 return handler_.newCall(lhs, args, op);
11190 }
11191
11192 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(); })
;
11193
11194 if (!taggedTemplate(yieldHandling, args, tt)) {
11195 return errorResult();
11196 }
11197
11198 if (optionalKind == OptionalKind::Optional) {
11199 error(JSMSG_BAD_OPTIONAL_TEMPLATE);
11200 return errorResult();
11201 }
11202
11203 return handler_.newTaggedTemplate(lhs, args, op);
11204}
11205
11206template <class ParseHandler, typename Unit>
11207bool GeneralParser<ParseHandler, Unit>::checkLabelOrIdentifierReference(
11208 TaggedParserAtomIndex ident, uint32_t offset, YieldHandling yieldHandling,
11209 TokenKind hint /* = TokenKind::Limit */) {
11210 TokenKind tt;
11211 if (hint == TokenKind::Limit) {
11212 tt = ReservedWordTokenKind(ident);
11213 } else {
11214 // All non-reserved word kinds are folded into TokenKind::Limit in
11215 // ReservedWordTokenKind and the following code.
11216 if (hint == TokenKind::Name || hint == TokenKind::PrivateName) {
11217 hint = TokenKind::Limit;
11218 }
11219 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", 11220
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "hint == ReservedWordTokenKind(ident)"
") (" "hint doesn't match actual token kind" ")"); do { MOZ_CrashSequence
(__null, 11220); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
11220 "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", 11220
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "hint == ReservedWordTokenKind(ident)"
") (" "hint doesn't match actual token kind" ")"); do { MOZ_CrashSequence
(__null, 11220); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
11221 tt = hint;
11222 }
11223
11224 if (!pc_->sc()->allowArguments() &&
11225 ident == TaggedParserAtomIndex::WellKnown::arguments()) {
11226 error(JSMSG_BAD_ARGUMENTS);
11227 return false;
11228 }
11229
11230 if (tt == TokenKind::Limit) {
11231 // Either TokenKind::Name or TokenKind::PrivateName
11232 return true;
11233 }
11234 if (TokenKindIsContextualKeyword(tt)) {
11235 if (tt == TokenKind::Yield) {
11236 if (yieldHandling == YieldIsKeyword) {
11237 errorAt(offset, JSMSG_RESERVED_ID, "yield");
11238 return false;
11239 }
11240 if (pc_->sc()->strict()) {
11241 if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, "yield")) {
11242 return false;
11243 }
11244 }
11245 return true;
11246 }
11247 if (tt == TokenKind::Await) {
11248 if (awaitIsKeyword() || awaitIsDisallowed()) {
11249 errorAt(offset, JSMSG_RESERVED_ID, "await");
11250 return false;
11251 }
11252 return true;
11253 }
11254 if (pc_->sc()->strict()) {
11255 if (tt == TokenKind::Let) {
11256 if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, "let")) {
11257 return false;
11258 }
11259 return true;
11260 }
11261 if (tt == TokenKind::Static) {
11262 if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID, "static")) {
11263 return false;
11264 }
11265 return true;
11266 }
11267 }
11268 return true;
11269 }
11270 if (TokenKindIsStrictReservedWord(tt)) {
11271 if (pc_->sc()->strict()) {
11272 if (!strictModeErrorAt(offset, JSMSG_RESERVED_ID,
11273 ReservedWordToCharZ(tt))) {
11274 return false;
11275 }
11276 }
11277 return true;
11278 }
11279 if (TokenKindIsKeyword(tt) || TokenKindIsReservedWordLiteral(tt)) {
11280 errorAt(offset, JSMSG_INVALID_ID, ReservedWordToCharZ(tt));
11281 return false;
11282 }
11283 if (TokenKindIsFutureReservedWord(tt)) {
11284 errorAt(offset, JSMSG_RESERVED_ID, ReservedWordToCharZ(tt));
11285 return false;
11286 }
11287 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"
, 11287); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"MOZ_ASSERT_UNREACHABLE: " "Unexpected reserved word kind." ")"
); do { MOZ_CrashSequence(__null, 11287); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
11288 return false;
11289}
11290
11291template <class ParseHandler, typename Unit>
11292bool GeneralParser<ParseHandler, Unit>::checkBindingIdentifier(
11293 TaggedParserAtomIndex ident, uint32_t offset, YieldHandling yieldHandling,
11294 TokenKind hint /* = TokenKind::Limit */) {
11295 if (pc_->sc()->strict()) {
11296 if (ident == TaggedParserAtomIndex::WellKnown::arguments()) {
11297 if (!strictModeErrorAt(offset, JSMSG_BAD_STRICT_ASSIGN, "arguments")) {
11298 return false;
11299 }
11300 return true;
11301 }
11302
11303 if (ident == TaggedParserAtomIndex::WellKnown::eval()) {
11304 if (!strictModeErrorAt(offset, JSMSG_BAD_STRICT_ASSIGN, "eval")) {
11305 return false;
11306 }
11307 return true;
11308 }
11309 }
11310
11311 return checkLabelOrIdentifierReference(ident, offset, yieldHandling, hint);
11312}
11313
11314template <class ParseHandler, typename Unit>
11315TaggedParserAtomIndex
11316GeneralParser<ParseHandler, Unit>::labelOrIdentifierReference(
11317 YieldHandling yieldHandling) {
11318 // ES 2017 draft 12.1.1.
11319 // StringValue of IdentifierName normalizes any Unicode escape sequences
11320 // in IdentifierName hence such escapes cannot be used to write an
11321 // Identifier whose code point sequence is the same as a ReservedWord.
11322 //
11323 // Use const ParserName* instead of TokenKind to reflect the normalization.
11324
11325 // Unless the name contains escapes, we can reuse the current TokenKind
11326 // to determine if the name is a restricted identifier.
11327 TokenKind hint = !anyChars.currentNameHasEscapes(this->parserAtoms())
11328 ? anyChars.currentToken().type
11329 : TokenKind::Limit;
11330 TaggedParserAtomIndex ident = anyChars.currentName();
11331 if (!checkLabelOrIdentifierReference(ident, pos().begin, yieldHandling,
11332 hint)) {
11333 return TaggedParserAtomIndex::null();
11334 }
11335 return ident;
11336}
11337
11338template <class ParseHandler, typename Unit>
11339TaggedParserAtomIndex GeneralParser<ParseHandler, Unit>::bindingIdentifier(
11340 YieldHandling yieldHandling) {
11341 TokenKind hint = !anyChars.currentNameHasEscapes(this->parserAtoms())
11342 ? anyChars.currentToken().type
11343 : TokenKind::Limit;
11344 TaggedParserAtomIndex ident = anyChars.currentName();
11345 if (!checkBindingIdentifier(ident, pos().begin, yieldHandling, hint)) {
11346 return TaggedParserAtomIndex::null();
11347 }
11348 return ident;
11349}
11350
11351template <class ParseHandler>
11352typename ParseHandler::NameNodeResult
11353PerHandlerParser<ParseHandler>::identifierReference(
11354 TaggedParserAtomIndex name) {
11355 NameNodeType id = MOZ_TRY(newName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newName(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
11356
11357 if (!noteUsedName(name)) {
11358 return errorResult();
11359 }
11360
11361 return id;
11362}
11363
11364template <class ParseHandler>
11365typename ParseHandler::NameNodeResult
11366PerHandlerParser<ParseHandler>::privateNameReference(
11367 TaggedParserAtomIndex name) {
11368 NameNodeType id = MOZ_TRY(newPrivateName(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newPrivateName(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
11369
11370 if (!noteUsedName(name, NameVisibility::Private, Some(pos()))) {
11371 return errorResult();
11372 }
11373
11374 return id;
11375}
11376
11377template <class ParseHandler>
11378typename ParseHandler::NameNodeResult
11379PerHandlerParser<ParseHandler>::stringLiteral() {
11380 return handler_.newStringLiteral(anyChars.currentToken().atom(), pos());
11381}
11382
11383template <class ParseHandler>
11384typename ParseHandler::NodeResult
11385PerHandlerParser<ParseHandler>::noSubstitutionTaggedTemplate() {
11386 if (anyChars.hasInvalidTemplateEscape()) {
11387 anyChars.clearInvalidTemplateEscape();
11388 return handler_.newRawUndefinedLiteral(pos());
11389 }
11390
11391 return handler_.newTemplateStringLiteral(anyChars.currentToken().atom(),
11392 pos());
11393}
11394
11395template <class ParseHandler, typename Unit>
11396typename ParseHandler::NameNodeResult
11397GeneralParser<ParseHandler, Unit>::noSubstitutionUntaggedTemplate() {
11398 if (!tokenStream.checkForInvalidTemplateEscapeError()) {
11399 return errorResult();
11400 }
11401
11402 return handler_.newTemplateStringLiteral(anyChars.currentToken().atom(),
11403 pos());
11404}
11405
11406template <typename Unit>
11407FullParseHandler::RegExpLiteralResult
11408Parser<FullParseHandler, Unit>::newRegExp() {
11409 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", 11409); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!options().selfHostingMode" ")"); do { MOZ_CrashSequence
(__null, 11409); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
11410
11411 // Create the regexp and check its syntax.
11412 const auto& chars = tokenStream.getCharBuffer();
11413 mozilla::Range<const char16_t> range(chars.begin(), chars.length());
11414 RegExpFlags flags = anyChars.currentToken().regExpFlags();
11415
11416 uint32_t offset = anyChars.currentToken().pos.begin;
11417 uint32_t line;
11418 JS::LimitedColumnNumberOneOrigin column;
11419 tokenStream.computeLineAndColumn(offset, &line, &column);
11420
11421 if (!handler_.reuseRegexpSyntaxParse()) {
11422 // Verify that the Regexp will syntax parse when the time comes to
11423 // instantiate it. If we have already done a syntax parse, we can
11424 // skip this.
11425 if (!irregexp::CheckPatternSyntax(
11426 this->alloc_, this->fc_->stackLimit(), anyChars, range, flags,
11427 Some(line), Some(JS::ColumnNumberOneOrigin(column)))) {
11428 return errorResult();
11429 }
11430 }
11431
11432 auto atom =
11433 this->parserAtoms().internChar16(fc_, chars.begin(), chars.length());
11434 if (!atom) {
11435 return errorResult();
11436 }
11437 // RegExp patterm must be atomized.
11438 this->parserAtoms().markUsedByStencil(atom, ParserAtom::Atomize::Yes);
11439
11440 RegExpIndex index(this->compilationState_.regExpData.length());
11441 if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) {
11442 ReportAllocationOverflow(fc_);
11443 return errorResult();
11444 }
11445 if (!this->compilationState_.regExpData.emplaceBack(atom, flags)) {
11446 js::ReportOutOfMemory(this->fc_);
11447 return errorResult();
11448 }
11449
11450 return handler_.newRegExp(index, pos());
11451}
11452
11453template <typename Unit>
11454SyntaxParseHandler::RegExpLiteralResult
11455Parser<SyntaxParseHandler, Unit>::newRegExp() {
11456 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", 11456); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "!options().selfHostingMode" ")"); do { MOZ_CrashSequence
(__null, 11456); __attribute__((nomerge)) ::abort(); } while (
false); } } while (false)
;
11457
11458 // Only check the regexp's syntax, but don't create a regexp object.
11459 const auto& chars = tokenStream.getCharBuffer();
11460 RegExpFlags flags = anyChars.currentToken().regExpFlags();
11461
11462 uint32_t offset = anyChars.currentToken().pos.begin;
11463 uint32_t line;
11464 JS::LimitedColumnNumberOneOrigin column;
11465 tokenStream.computeLineAndColumn(offset, &line, &column);
11466
11467 mozilla::Range<const char16_t> source(chars.begin(), chars.length());
11468 if (!irregexp::CheckPatternSyntax(this->alloc_, this->fc_->stackLimit(),
11469 anyChars, source, flags, Some(line),
11470 Some(JS::ColumnNumberOneOrigin(column)))) {
11471 return errorResult();
11472 }
11473
11474 return handler_.newRegExp(SyntaxParseHandler::Node::NodeGeneric, pos());
11475}
11476
11477template <class ParseHandler, typename Unit>
11478typename ParseHandler::RegExpLiteralResult
11479GeneralParser<ParseHandler, Unit>::newRegExp() {
11480 return asFinalParser()->newRegExp();
11481}
11482
11483template <typename Unit>
11484FullParseHandler::BigIntLiteralResult
11485Parser<FullParseHandler, Unit>::newBigInt() {
11486 // The token's charBuffer contains the DecimalIntegerLiteral or
11487 // NonDecimalIntegerLiteral production, and as such does not include the
11488 // BigIntLiteralSuffix (the trailing "n"). Note that NonDecimalIntegerLiteral
11489 // productions start with 0[bBoOxX], indicating binary/octal/hex.
11490 const auto& chars = tokenStream.getCharBuffer();
11491 if (chars.length() > UINT32_MAX(4294967295U)) {
11492 ReportAllocationOverflow(fc_);
11493 return errorResult();
11494 }
11495
11496 BigIntIndex index(this->bigInts().length());
11497 if (uint32_t(index) >= TaggedScriptThingIndex::IndexLimit) {
11498 ReportAllocationOverflow(fc_);
11499 return errorResult();
11500 }
11501 if (!this->bigInts().emplaceBack()) {
11502 js::ReportOutOfMemory(this->fc_);
11503 return errorResult();
11504 }
11505
11506 if (!this->bigInts()[index].init(this->fc_, this->stencilAlloc(), chars)) {
11507 return errorResult();
11508 }
11509
11510 // Should the operations below fail, the buffer held by data will
11511 // be cleaned up by the CompilationState destructor.
11512 return handler_.newBigInt(index, pos());
11513}
11514
11515template <typename Unit>
11516SyntaxParseHandler::BigIntLiteralResult
11517Parser<SyntaxParseHandler, Unit>::newBigInt() {
11518 // The tokenizer has already checked the syntax of the bigint.
11519
11520 return handler_.newBigInt();
11521}
11522
11523template <class ParseHandler, typename Unit>
11524typename ParseHandler::BigIntLiteralResult
11525GeneralParser<ParseHandler, Unit>::newBigInt() {
11526 return asFinalParser()->newBigInt();
11527}
11528
11529// |exprPossibleError| is the PossibleError state within |expr|,
11530// |possibleError| is the surrounding PossibleError state.
11531template <class ParseHandler, typename Unit>
11532bool GeneralParser<ParseHandler, Unit>::checkDestructuringAssignmentTarget(
11533 Node expr, TokenPos exprPos, PossibleError* exprPossibleError,
11534 PossibleError* possibleError, TargetBehavior behavior) {
11535 // |arguments.length| is reported as a property access by the check below, so
11536 // the property-access early-return would otherwise swallow it before the
11537 // ArgumentsLength optimization is disabled. Mirror the
11538 // isArgumentsLength-first pattern used by assignExpr.
11539 if (handler_.isArgumentsLength(expr)) {
11540 pc_->sc()->setIneligibleForArgumentsLength();
11541 }
11542
11543 // Report any pending expression error if we're definitely not in a
11544 // destructuring context or the possible destructuring target is a
11545 // property accessor.
11546 if (!possibleError || handler_.isPropertyOrPrivateMemberAccess(expr)) {
11547 return exprPossibleError->checkForExpressionError();
11548 }
11549
11550 // |expr| may end up as a destructuring assignment target, so we need to
11551 // validate it's either a name or can be parsed as a nested destructuring
11552 // pattern. Property accessors are also valid assignment targets, but
11553 // those are already handled above.
11554
11555 exprPossibleError->transferErrorsTo(possibleError);
11556
11557 // Return early if a pending destructuring error is already present.
11558 if (possibleError->hasPendingDestructuringError()) {
11559 return true;
11560 }
11561
11562 if (handler_.isName(expr)) {
11563 checkDestructuringAssignmentName(handler_.asNameNode(expr), exprPos,
11564 possibleError);
11565 return true;
11566 }
11567
11568 if (handler_.isUnparenthesizedDestructuringPattern(expr)) {
11569 if (behavior == TargetBehavior::ForbidAssignmentPattern) {
11570 possibleError->setPendingDestructuringErrorAt(exprPos,
11571 JSMSG_BAD_DESTRUCT_TARGET);
11572 }
11573 return true;
11574 }
11575
11576 // Parentheses are forbidden around destructuring *patterns* (but allowed
11577 // around names). Use our nicer error message for parenthesized, nested
11578 // patterns if nested destructuring patterns are allowed.
11579 if (handler_.isParenthesizedDestructuringPattern(expr) &&
11580 behavior != TargetBehavior::ForbidAssignmentPattern) {
11581 possibleError->setPendingDestructuringErrorAt(exprPos,
11582 JSMSG_BAD_DESTRUCT_PARENS);
11583 } else {
11584 possibleError->setPendingDestructuringErrorAt(exprPos,
11585 JSMSG_BAD_DESTRUCT_TARGET);
11586 }
11587
11588 return true;
11589}
11590
11591template <class ParseHandler, typename Unit>
11592void GeneralParser<ParseHandler, Unit>::checkDestructuringAssignmentName(
11593 NameNodeType name, TokenPos namePos, PossibleError* possibleError) {
11594#ifdef DEBUG1
11595 // GCC 8.0.1 crashes if this is a one-liner.
11596 bool isName = handler_.isName(name);
11597 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"
, 11597); AnnotateMozCrashReason("MOZ_ASSERT" "(" "isName" ")"
); do { MOZ_CrashSequence(__null, 11597); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
11598#endif
11599
11600 // Return early if a pending destructuring error is already present.
11601 if (possibleError->hasPendingDestructuringError()) {
11602 return;
11603 }
11604
11605 if (handler_.isArgumentsLength(name)) {
11606 pc_->sc()->setIneligibleForArgumentsLength();
11607 }
11608
11609 if (pc_->sc()->strict()) {
11610 if (handler_.isArgumentsName(name)) {
11611 possibleError->setPendingDestructuringErrorAt(
11612 namePos, JSMSG_BAD_STRICT_ASSIGN_ARGUMENTS);
11613 return;
11614 }
11615 if (handler_.isEvalName(name)) {
11616 possibleError->setPendingDestructuringErrorAt(
11617 namePos, JSMSG_BAD_STRICT_ASSIGN_EVAL);
11618 return;
11619 }
11620 }
11621}
11622
11623template <class ParseHandler, typename Unit>
11624bool GeneralParser<ParseHandler, Unit>::checkDestructuringAssignmentElement(
11625 Node expr, TokenPos exprPos, PossibleError* exprPossibleError,
11626 PossibleError* possibleError) {
11627 // ES2018 draft rev 0719f44aab93215ed9a626b2f45bd34f36916834
11628 // 12.15.5 Destructuring Assignment
11629 //
11630 // AssignmentElement[Yield, Await]:
11631 // DestructuringAssignmentTarget[?Yield, ?Await]
11632 // DestructuringAssignmentTarget[?Yield, ?Await] Initializer[+In,
11633 // ?Yield,
11634 // ?Await]
11635
11636 // If |expr| is an assignment element with an initializer expression, its
11637 // destructuring assignment target was already validated in assignExpr().
11638 // Otherwise we need to check that |expr| is a valid destructuring target.
11639 if (handler_.isUnparenthesizedAssignment(expr)) {
11640 // Report any pending expression error if we're definitely not in a
11641 // destructuring context.
11642 if (!possibleError) {
11643 return exprPossibleError->checkForExpressionError();
11644 }
11645
11646 exprPossibleError->transferErrorsTo(possibleError);
11647 return true;
11648 }
11649 return checkDestructuringAssignmentTarget(expr, exprPos, exprPossibleError,
11650 possibleError);
11651}
11652
11653template <class ParseHandler, typename Unit>
11654typename ParseHandler::ListNodeResult
11655GeneralParser<ParseHandler, Unit>::arrayInitializer(
11656 YieldHandling yieldHandling, PossibleError* possibleError) {
11657 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", 11657); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket)"
")"); do { MOZ_CrashSequence(__null, 11657); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11658
11659 uint32_t begin = pos().begin;
11660 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(); })
;
11661
11662 TokenKind tt;
11663 if (!tokenStream.getToken(&tt, TokenStream::SlashIsRegExp)) {
11664 return errorResult();
11665 }
11666
11667 if (tt == TokenKind::RightBracket) {
11668 /*
11669 * Mark empty arrays as non-constant, since we cannot easily
11670 * determine their type.
11671 */
11672 handler_.setListHasNonConstInitializer(literal);
11673 } else {
11674 anyChars.ungetToken();
11675
11676 for (uint32_t index = 0;; index++) {
11677 if (index >= NativeObject::MAX_DENSE_ELEMENTS_COUNT) {
11678 error(JSMSG_ARRAY_INIT_TOO_BIG);
11679 return errorResult();
11680 }
11681
11682 TokenKind tt;
11683 if (!tokenStream.peekToken(&tt, TokenStream::SlashIsRegExp)) {
11684 return errorResult();
11685 }
11686 if (tt == TokenKind::RightBracket) {
11687 break;
11688 }
11689
11690 if (tt == TokenKind::Comma) {
11691 tokenStream.consumeKnownToken(TokenKind::Comma,
11692 TokenStream::SlashIsRegExp);
11693 if (!handler_.addElision(literal, pos())) {
11694 return errorResult();
11695 }
11696 continue;
11697 }
11698
11699 if (tt == TokenKind::TripleDot) {
11700 tokenStream.consumeKnownToken(TokenKind::TripleDot,
11701 TokenStream::SlashIsRegExp);
11702 uint32_t begin = pos().begin;
11703
11704 TokenPos innerPos;
11705 if (!tokenStream.peekTokenPos(&innerPos, TokenStream::SlashIsRegExp)) {
11706 return errorResult();
11707 }
11708
11709 PossibleError possibleErrorInner(*this);
11710 Node inner =
11711 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(); })
11712 &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(InAllowed, yieldHandling, TripledotProhibited, &
possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
11713 if (!checkDestructuringAssignmentTarget(
11714 inner, innerPos, &possibleErrorInner, possibleError)) {
11715 return errorResult();
11716 }
11717
11718 if (!handler_.addSpreadElement(literal, begin, inner)) {
11719 return errorResult();
11720 }
11721 } else {
11722 TokenPos elementPos;
11723 if (!tokenStream.peekTokenPos(&elementPos,
11724 TokenStream::SlashIsRegExp)) {
11725 return errorResult();
11726 }
11727
11728 PossibleError possibleErrorInner(*this);
11729 Node element =
11730 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(); })
11731 &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(InAllowed, yieldHandling, TripledotProhibited, &
possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
11732 if (!checkDestructuringAssignmentElement(
11733 element, elementPos, &possibleErrorInner, possibleError)) {
11734 return errorResult();
11735 }
11736 handler_.addArrayElement(literal, element);
11737 }
11738
11739 bool matched;
11740 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
11741 TokenStream::SlashIsRegExp)) {
11742 return errorResult();
11743 }
11744 if (!matched) {
11745 break;
11746 }
11747
11748 if (tt == TokenKind::TripleDot && possibleError) {
11749 possibleError->setPendingDestructuringErrorAt(pos(),
11750 JSMSG_REST_WITH_COMMA);
11751 }
11752 }
11753
11754 if (!mustMatchToken(
11755 TokenKind::RightBracket, [this, begin](TokenKind actual) {
11756 this->reportMissingClosing(JSMSG_BRACKET_AFTER_LIST,
11757 JSMSG_BRACKET_OPENED, begin);
11758 })) {
11759 return errorResult();
11760 }
11761 }
11762
11763 handler_.setEndPosition(literal, pos().end);
11764 return literal;
11765}
11766
11767template <class ParseHandler, typename Unit>
11768typename ParseHandler::NodeResult
11769GeneralParser<ParseHandler, Unit>::propertyName(
11770 YieldHandling yieldHandling, PropertyNameContext propertyNameContext,
11771 const Maybe<DeclarationKind>& maybeDecl, ListNodeType propList,
11772 TaggedParserAtomIndex* propAtomOut) {
11773 // PropertyName[Yield, Await]:
11774 // LiteralPropertyName
11775 // ComputedPropertyName[?Yield, ?Await]
11776 //
11777 // LiteralPropertyName:
11778 // IdentifierName
11779 // StringLiteral
11780 // NumericLiteral
11781 TokenKind ltok = anyChars.currentToken().type;
11782
11783 *propAtomOut = TaggedParserAtomIndex::null();
11784 switch (ltok) {
11785 case TokenKind::Number: {
11786 auto numAtom = NumberToParserAtom(fc_, this->parserAtoms(),
11787 anyChars.currentToken().number());
11788 if (!numAtom) {
11789 return errorResult();
11790 }
11791 *propAtomOut = numAtom;
11792 return newNumber(anyChars.currentToken());
11793 }
11794
11795 case TokenKind::BigInt: {
11796 Node biNode = MOZ_TRY(newBigInt())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newBigInt()); if ((__builtin_expect(!!(mozTryVarTempResult.isErr
()), 0))) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
11797 return handler_.newSyntheticComputedName(biNode, pos().begin, pos().end);
11798 }
11799 case TokenKind::String: {
11800 auto str = anyChars.currentToken().atom();
11801 *propAtomOut = str;
11802 uint32_t index;
11803 if (this->parserAtoms().isIndex(str, &index)) {
11804 return handler_.newNumber(index, NoDecimal, pos());
11805 }
11806 return stringLiteral();
11807 }
11808
11809 case TokenKind::LeftBracket:
11810 return computedPropertyName(yieldHandling, maybeDecl, propertyNameContext,
11811 propList);
11812
11813 case TokenKind::PrivateName: {
11814 if (propertyNameContext != PropertyNameContext::PropertyNameInClass) {
11815 error(JSMSG_ILLEGAL_PRIVATE_FIELD);
11816 return errorResult();
11817 }
11818
11819 TaggedParserAtomIndex propName = anyChars.currentName();
11820 *propAtomOut = propName;
11821 return privateNameReference(propName);
11822 }
11823
11824 default: {
11825 if (!TokenKindIsPossibleIdentifierName(ltok)) {
11826 error(JSMSG_UNEXPECTED_TOKEN, "property name", TokenKindToDesc(ltok));
11827 return errorResult();
11828 }
11829
11830 TaggedParserAtomIndex name = anyChars.currentName();
11831 *propAtomOut = name;
11832 return handler_.newObjectLiteralPropertyName(name, pos());
11833 }
11834 }
11835}
11836
11837// True if `kind` can be the first token of a PropertyName.
11838static bool TokenKindCanStartPropertyName(TokenKind tt) {
11839 return TokenKindIsPossibleIdentifierName(tt) || tt == TokenKind::String ||
11840 tt == TokenKind::Number || tt == TokenKind::LeftBracket ||
11841 tt == TokenKind::BigInt || tt == TokenKind::PrivateName;
11842}
11843
11844template <class ParseHandler, typename Unit>
11845typename ParseHandler::NodeResult
11846GeneralParser<ParseHandler, Unit>::propertyOrMethodName(
11847 YieldHandling yieldHandling, PropertyNameContext propertyNameContext,
11848 const Maybe<DeclarationKind>& maybeDecl, ListNodeType propList,
11849 PropertyType* propType, TaggedParserAtomIndex* propAtomOut) {
11850 // We're parsing an object literal, class, or destructuring pattern;
11851 // propertyNameContext tells which one. This method parses any of the
11852 // following, storing the corresponding PropertyType in `*propType` to tell
11853 // the caller what we parsed:
11854 //
11855 // async [no LineTerminator here] PropertyName
11856 // ==> PropertyType::AsyncMethod
11857 // async [no LineTerminator here] * PropertyName
11858 // ==> PropertyType::AsyncGeneratorMethod
11859 // * PropertyName ==> PropertyType::GeneratorMethod
11860 // get PropertyName ==> PropertyType::Getter
11861 // set PropertyName ==> PropertyType::Setter
11862 // accessor PropertyName ==> PropertyType::FieldWithAccessor
11863 // PropertyName : ==> PropertyType::Normal
11864 // PropertyName ==> see below
11865 //
11866 // In the last case, where there's not a `:` token to consume, we peek at
11867 // (but don't consume) the next token to decide how to set `*propType`.
11868 //
11869 // `,` or `}` ==> PropertyType::Shorthand
11870 // `(` ==> PropertyType::Method
11871 // `=`, not in a class ==> PropertyType::CoverInitializedName
11872 // '=', in a class ==> PropertyType::Field
11873 // any token, in a class ==> PropertyType::Field (ASI)
11874 //
11875 // The caller must check `*propType` and throw if whatever we parsed isn't
11876 // allowed here (for example, a getter in a destructuring pattern).
11877 //
11878 // This method does *not* match `static` (allowed in classes) or `...`
11879 // (allowed in object literals and patterns). The caller must take care of
11880 // those before calling this method.
11881
11882 TokenKind ltok;
11883 if (!tokenStream.getToken(&ltok, TokenStream::SlashIsInvalid)) {
11884 return errorResult();
11885 }
11886
11887 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", 11888
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ltok != TokenKind::RightCurly"
") (" "caller should have handled TokenKind::RightCurly" ")"
); do { MOZ_CrashSequence(__null, 11888); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
11888 "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", 11888
); AnnotateMozCrashReason("MOZ_ASSERT" "(" "ltok != TokenKind::RightCurly"
") (" "caller should have handled TokenKind::RightCurly" ")"
); do { MOZ_CrashSequence(__null, 11888); __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
11889
11890 // Accept `async` and/or `*`, indicating an async or generator method;
11891 // or `get` or `set` or `accessor`, indicating an accessor.
11892 bool isGenerator = false;
11893 bool isAsync = false;
11894 bool isGetter = false;
11895 bool isSetter = false;
11896#ifdef ENABLE_DECORATORS
11897 bool hasAccessor = false;
11898#endif
11899
11900 if (ltok == TokenKind::Async) {
11901 // `async` is also a PropertyName by itself (it's a conditional keyword),
11902 // so peek at the next token to see if we're really looking at a method.
11903 TokenKind tt = TokenKind::Eof;
11904 if (!tokenStream.peekTokenSameLine(&tt)) {
11905 return errorResult();
11906 }
11907 if (TokenKindCanStartPropertyName(tt) || tt == TokenKind::Mul) {
11908 isAsync = true;
11909 tokenStream.consumeKnownToken(tt);
11910 ltok = tt;
11911 }
11912 }
11913
11914 if (ltok == TokenKind::Mul) {
11915 isGenerator = true;
11916 if (!tokenStream.getToken(&ltok)) {
11917 return errorResult();
11918 }
11919 }
11920
11921 if (!isAsync && !isGenerator &&
11922 (ltok == TokenKind::Get || ltok == TokenKind::Set)) {
11923 // We have parsed |get| or |set|. Look for an accessor property
11924 // name next.
11925 TokenKind tt;
11926 if (!tokenStream.peekToken(&tt)) {
11927 return errorResult();
11928 }
11929 if (TokenKindCanStartPropertyName(tt)) {
11930 tokenStream.consumeKnownToken(tt);
11931 isGetter = (ltok == TokenKind::Get);
11932 isSetter = (ltok == TokenKind::Set);
11933 }
11934 }
11935
11936#ifdef ENABLE_DECORATORS
11937 if (!isGenerator && !isAsync && propertyNameContext == PropertyNameInClass &&
11938 ltok == TokenKind::Accessor) {
11939 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"
, 11939); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!isGetter && !isSetter"
")"); do { MOZ_CrashSequence(__null, 11939); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11940 TokenKind tt;
11941 if (!tokenStream.peekTokenSameLine(&tt)) {
11942 return errorResult();
11943 }
11944
11945 // The target rule is `accessor [no LineTerminator here]
11946 // ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt`
11947 if (TokenKindCanStartPropertyName(tt)) {
11948 tokenStream.consumeKnownToken(tt);
11949 if (fuzzingSafe) {
11950 error(JSMSG_DECORATOR_FUZZING_UNSAFE);
11951 return errorResult();
11952 }
11953 hasAccessor = true;
11954 }
11955 }
11956#endif
11957
11958 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(); })
11959 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(); })
;
11960
11961 // Grab the next token following the property/method name.
11962 // (If this isn't a colon, we're going to either put it back or throw.)
11963 TokenKind tt;
11964 if (!tokenStream.getToken(&tt)) {
11965 return errorResult();
11966 }
11967
11968 if (tt == TokenKind::Colon) {
11969 if (isGenerator || isAsync || isGetter || isSetter
11970#ifdef ENABLE_DECORATORS
11971 || hasAccessor
11972#endif
11973 ) {
11974 error(JSMSG_BAD_PROP_ID);
11975 return errorResult();
11976 }
11977 *propType = PropertyType::Normal;
11978 return propName;
11979 }
11980
11981 if (propertyNameContext != PropertyNameInClass &&
11982 TokenKindIsPossibleIdentifierName(ltok) &&
11983 (tt == TokenKind::Comma || tt == TokenKind::RightCurly ||
11984 tt == TokenKind::Assign)) {
11985#ifdef ENABLE_DECORATORS
11986 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"
, 11986); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!hasAccessor"
")"); do { MOZ_CrashSequence(__null, 11986); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
11987#endif
11988 if (isGenerator || isAsync || isGetter || isSetter) {
11989 error(JSMSG_BAD_PROP_ID);
11990 return errorResult();
11991 }
11992
11993 anyChars.ungetToken();
11994 *propType = tt == TokenKind::Assign ? PropertyType::CoverInitializedName
11995 : PropertyType::Shorthand;
11996 return propName;
11997 }
11998
11999 if (tt == TokenKind::LeftParen) {
12000 anyChars.ungetToken();
12001
12002#ifdef ENABLE_DECORATORS
12003 if (hasAccessor) {
12004 error(JSMSG_BAD_PROP_ID);
12005 return errorResult();
12006 }
12007#endif
12008
12009 if (isGenerator && isAsync) {
12010 *propType = PropertyType::AsyncGeneratorMethod;
12011 } else if (isGenerator) {
12012 *propType = PropertyType::GeneratorMethod;
12013 } else if (isAsync) {
12014 *propType = PropertyType::AsyncMethod;
12015 } else if (isGetter) {
12016 *propType = PropertyType::Getter;
12017 } else if (isSetter) {
12018 *propType = PropertyType::Setter;
12019 } else {
12020 *propType = PropertyType::Method;
12021 }
12022 return propName;
12023 }
12024
12025 if (propertyNameContext == PropertyNameInClass) {
12026 if (isGenerator || isAsync || isGetter || isSetter) {
12027 error(JSMSG_BAD_PROP_ID);
12028 return errorResult();
12029 }
12030 anyChars.ungetToken();
12031#ifdef ENABLE_DECORATORS
12032 if (!hasAccessor) {
12033 *propType = PropertyType::Field;
12034 } else {
12035 *propType = PropertyType::FieldWithAccessor;
12036 }
12037#else
12038 *propType = PropertyType::Field;
12039#endif
12040 return propName;
12041 }
12042
12043 error(JSMSG_COLON_AFTER_ID);
12044 return errorResult();
12045}
12046
12047template <class ParseHandler, typename Unit>
12048typename ParseHandler::UnaryNodeResult
12049GeneralParser<ParseHandler, Unit>::computedPropertyName(
12050 YieldHandling yieldHandling, const Maybe<DeclarationKind>& maybeDecl,
12051 PropertyNameContext propertyNameContext, ListNodeType literal) {
12052 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", 12052); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftBracket)"
")"); do { MOZ_CrashSequence(__null, 12052); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
12053
12054 uint32_t begin = pos().begin;
12055
12056 if (maybeDecl) {
12057 if (*maybeDecl == DeclarationKind::FormalParameter) {
12058 pc_->functionBox()->hasParameterExprs = true;
12059 }
12060 } else if (propertyNameContext ==
12061 PropertyNameContext::PropertyNameInLiteral) {
12062 handler_.setListHasNonConstInitializer(literal);
12063 }
12064
12065 Node assignNode =
12066 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
(); })
;
12067
12068 if (!mustMatchToken(TokenKind::RightBracket, JSMSG_COMP_PROP_UNTERM_EXPR)) {
12069 return errorResult();
12070 }
12071 return handler_.newComputedName(assignNode, begin, pos().end);
12072}
12073
12074template <class ParseHandler, typename Unit>
12075typename ParseHandler::ListNodeResult
12076GeneralParser<ParseHandler, Unit>::objectLiteral(YieldHandling yieldHandling,
12077 PossibleError* possibleError) {
12078 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", 12078); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftCurly)"
")"); do { MOZ_CrashSequence(__null, 12078); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
12079
12080 uint32_t openedPos = pos().begin;
12081
12082 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(); })
;
12083
12084 bool seenPrototypeMutation = false;
12085 bool seenCoverInitializedName = false;
12086 Maybe<DeclarationKind> declKind = Nothing();
12087 TaggedParserAtomIndex propAtom;
12088 for (;;) {
12089 TokenKind tt;
12090 if (!tokenStream.peekToken(&tt)) {
12091 return errorResult();
12092 }
12093 if (tt == TokenKind::RightCurly) {
12094 break;
12095 }
12096
12097 if (tt == TokenKind::TripleDot) {
12098 tokenStream.consumeKnownToken(TokenKind::TripleDot);
12099 uint32_t begin = pos().begin;
12100
12101 TokenPos innerPos;
12102 if (!tokenStream.peekTokenPos(&innerPos, TokenStream::SlashIsRegExp)) {
12103 return errorResult();
12104 }
12105
12106 PossibleError possibleErrorInner(*this);
12107 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(); })
12108 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(); })
;
12109 if (!checkDestructuringAssignmentTarget(
12110 inner, innerPos, &possibleErrorInner, possibleError,
12111 TargetBehavior::ForbidAssignmentPattern)) {
12112 return errorResult();
12113 }
12114 if (!handler_.addSpreadProperty(literal, begin, inner)) {
12115 return errorResult();
12116 }
12117 } else {
12118 TokenPos namePos = anyChars.nextToken().pos;
12119
12120 PropertyType propType;
12121 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(); })
12122 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(); })
12123 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(); })
;
12124
12125 if (propType == PropertyType::Normal) {
12126 TokenPos exprPos;
12127 if (!tokenStream.peekTokenPos(&exprPos, TokenStream::SlashIsRegExp)) {
12128 return errorResult();
12129 }
12130
12131 PossibleError possibleErrorInner(*this);
12132 Node propExpr =
12133 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(); })
12134 &possibleErrorInner))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(assignExpr(InAllowed, yieldHandling, TripledotProhibited, &
possibleErrorInner)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
12135
12136 if (!checkDestructuringAssignmentElement(
12137 propExpr, exprPos, &possibleErrorInner, possibleError)) {
12138 return errorResult();
12139 }
12140
12141 if (propAtom == TaggedParserAtomIndex::WellKnown::proto_()) {
12142 if (seenPrototypeMutation) {
12143 // Directly report the error when we're definitely not
12144 // in a destructuring context.
12145 if (!possibleError) {
12146 errorAt(namePos.begin, JSMSG_DUPLICATE_PROTO_PROPERTY);
12147 return errorResult();
12148 }
12149
12150 // Otherwise delay error reporting until we've
12151 // determined whether or not we're destructuring.
12152 possibleError->setPendingExpressionErrorAt(
12153 namePos, JSMSG_DUPLICATE_PROTO_PROPERTY);
12154 }
12155 seenPrototypeMutation = true;
12156
12157 // This occurs *only* if we observe PropertyType::Normal!
12158 // Only |__proto__: v| mutates [[Prototype]]. Getters,
12159 // setters, method/generator definitions, computed
12160 // property name versions of all of these, and shorthands
12161 // do not.
12162 if (!handler_.addPrototypeMutation(literal, namePos.begin,
12163 propExpr)) {
12164 return errorResult();
12165 }
12166 } else {
12167 BinaryNodeType propDef =
12168 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(); })
;
12169
12170 handler_.addPropertyDefinition(literal, propDef);
12171 }
12172 } else if (propType == PropertyType::Shorthand) {
12173 /*
12174 * Support, e.g., |({x, y} = o)| as destructuring shorthand
12175 * for |({x: x, y: y} = o)|, and |var o = {x, y}| as
12176 * initializer shorthand for |var o = {x: x, y: y}|.
12177 */
12178 TaggedParserAtomIndex name = identifierReference(yieldHandling);
12179 if (!name) {
12180 return errorResult();
12181 }
12182
12183 NameNodeType nameExpr = MOZ_TRY(identifierReference(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(identifierReference(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
12184
12185 if (possibleError) {
12186 checkDestructuringAssignmentName(nameExpr, namePos, possibleError);
12187 }
12188
12189 if (!handler_.addShorthand(literal, handler_.asNameNode(propName),
12190 nameExpr)) {
12191 return errorResult();
12192 }
12193 } else if (propType == PropertyType::CoverInitializedName) {
12194 /*
12195 * Support, e.g., |({x=1, y=2} = o)| as destructuring
12196 * shorthand with default values, as per ES6 12.14.5
12197 */
12198 TaggedParserAtomIndex name = identifierReference(yieldHandling);
12199 if (!name) {
12200 return errorResult();
12201 }
12202
12203 Node lhs = MOZ_TRY(identifierReference(name))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(identifierReference(name)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
12204
12205 tokenStream.consumeKnownToken(TokenKind::Assign);
12206
12207 if (!seenCoverInitializedName) {
12208 // "shorthand default" or "CoverInitializedName" syntax is
12209 // only valid in the case of destructuring.
12210 seenCoverInitializedName = true;
12211
12212 if (!possibleError) {
12213 // Destructuring defaults are definitely not allowed
12214 // in this object literal, because of something the
12215 // caller knows about the preceding code. For example,
12216 // maybe the preceding token is an operator:
12217 // |x + {y=z}|.
12218 error(JSMSG_COLON_AFTER_ID);
12219 return errorResult();
12220 }
12221
12222 // Here we set a pending error so that later in the parse,
12223 // once we've determined whether or not we're
12224 // destructuring, the error can be reported or ignored
12225 // appropriately.
12226 possibleError->setPendingExpressionErrorAt(pos(),
12227 JSMSG_COLON_AFTER_ID);
12228 }
12229
12230 if (const char* chars = nameIsArgumentsOrEval(lhs)) {
12231 // |chars| is "arguments" or "eval" here.
12232 if (!strictModeErrorAt(namePos.begin, JSMSG_BAD_STRICT_ASSIGN,
12233 chars)) {
12234 return errorResult();
12235 }
12236 }
12237
12238 if (handler_.isArgumentsLength(lhs)) {
12239 pc_->sc()->setIneligibleForArgumentsLength();
12240 }
12241
12242 Node rhs =
12243 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
(); })
;
12244
12245 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(); })
12246 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(); })
;
12247
12248 if (!handler_.addPropertyDefinition(literal, propName, propExpr)) {
12249 return errorResult();
12250 }
12251 } else {
12252 TaggedParserAtomIndex funName;
12253 bool hasStaticName =
12254 !anyChars.isCurrentTokenType(TokenKind::RightBracket) && propAtom;
12255 if (hasStaticName) {
12256 funName = propAtom;
12257
12258 if (propType == PropertyType::Getter ||
12259 propType == PropertyType::Setter) {
12260 funName = prefixAccessorName(propType, propAtom);
12261 if (!funName) {
12262 return errorResult();
12263 }
12264 }
12265 }
12266
12267 FunctionNodeType funNode =
12268 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(); })
;
12269
12270 AccessorType atype = ToAccessorType(propType);
12271 if (!handler_.addObjectMethodDefinition(literal, propName, funNode,
12272 atype)) {
12273 return errorResult();
12274 }
12275
12276 if (possibleError) {
12277 possibleError->setPendingDestructuringErrorAt(
12278 namePos, JSMSG_BAD_DESTRUCT_TARGET);
12279 }
12280 }
12281 }
12282
12283 bool matched;
12284 if (!tokenStream.matchToken(&matched, TokenKind::Comma,
12285 TokenStream::SlashIsInvalid)) {
12286 return errorResult();
12287 }
12288 if (!matched) {
12289 break;
12290 }
12291 if (tt == TokenKind::TripleDot && possibleError) {
12292 possibleError->setPendingDestructuringErrorAt(pos(),
12293 JSMSG_REST_WITH_COMMA);
12294 }
12295 }
12296
12297 if (!mustMatchToken(
12298 TokenKind::RightCurly, [this, openedPos](TokenKind actual) {
12299 this->reportMissingClosing(JSMSG_CURLY_AFTER_LIST,
12300 JSMSG_CURLY_OPENED, openedPos);
12301 })) {
12302 return errorResult();
12303 }
12304
12305 handler_.setEndPosition(literal, pos().end);
12306 return literal;
12307}
12308
12309template <class ParseHandler, typename Unit>
12310typename ParseHandler::FunctionNodeResult
12311GeneralParser<ParseHandler, Unit>::methodDefinition(
12312 uint32_t toStringStart, PropertyType propType,
12313 TaggedParserAtomIndex funName) {
12314 FunctionSyntaxKind syntaxKind;
12315 switch (propType) {
12316 case PropertyType::Getter:
12317 syntaxKind = FunctionSyntaxKind::Getter;
12318 break;
12319
12320 case PropertyType::Setter:
12321 syntaxKind = FunctionSyntaxKind::Setter;
12322 break;
12323
12324 case PropertyType::Method:
12325 case PropertyType::GeneratorMethod:
12326 case PropertyType::AsyncMethod:
12327 case PropertyType::AsyncGeneratorMethod:
12328 syntaxKind = FunctionSyntaxKind::Method;
12329 break;
12330
12331 case PropertyType::Constructor:
12332 syntaxKind = FunctionSyntaxKind::ClassConstructor;
12333 break;
12334
12335 case PropertyType::DerivedConstructor:
12336 syntaxKind = FunctionSyntaxKind::DerivedClassConstructor;
12337 break;
12338
12339 default:
12340 MOZ_CRASH("unexpected property type")do { do { } while (false); MOZ_ReportCrash("" "unexpected property type"
, "/root/firefox-clang/js/src/frontend/Parser.cpp", 12340); AnnotateMozCrashReason
("MOZ_CRASH(" "unexpected property type" ")"); do { MOZ_CrashSequence
(__null, 12340); __attribute__((nomerge)) ::abort(); } while (
false); } while (false)
;
12341 }
12342
12343 GeneratorKind generatorKind = (propType == PropertyType::GeneratorMethod ||
12344 propType == PropertyType::AsyncGeneratorMethod)
12345 ? GeneratorKind::Generator
12346 : GeneratorKind::NotGenerator;
12347
12348 FunctionAsyncKind asyncKind = (propType == PropertyType::AsyncMethod ||
12349 propType == PropertyType::AsyncGeneratorMethod)
12350 ? FunctionAsyncKind::AsyncFunction
12351 : FunctionAsyncKind::SyncFunction;
12352
12353 YieldHandling yieldHandling = GetYieldHandling(generatorKind);
12354
12355 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(); })
;
12356
12357 return functionDefinition(funNode, toStringStart, InAllowed, yieldHandling,
12358 funName, syntaxKind, generatorKind, asyncKind);
12359}
12360
12361template <class ParseHandler, typename Unit>
12362bool GeneralParser<ParseHandler, Unit>::tryNewTarget(
12363 NewTargetNodeType* newTarget) {
12364 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", 12364); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::New)"
")"); do { MOZ_CrashSequence(__null, 12364); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
12365
12366 *newTarget = null();
12367
12368 NullaryNodeType newHolder;
12369 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)
;
12370
12371 uint32_t begin = pos().begin;
12372
12373 // |new| expects to look for an operand, so we will honor that.
12374 TokenKind next;
12375 if (!tokenStream.getToken(&next, TokenStream::SlashIsRegExp)) {
12376 return false;
12377 }
12378
12379 // Don't unget the token, since lookahead cannot handle someone calling
12380 // getToken() with a different modifier. Callers should inspect
12381 // currentToken().
12382 if (next != TokenKind::Dot) {
12383 return true;
12384 }
12385
12386 if (!tokenStream.getToken(&next)) {
12387 return false;
12388 }
12389 if (next != TokenKind::Target) {
12390 error(JSMSG_UNEXPECTED_TOKEN, "target", TokenKindToDesc(next));
12391 return false;
12392 }
12393
12394 if (!pc_->sc()->allowNewTarget()) {
12395 errorAt(begin, JSMSG_BAD_NEWTARGET);
12396 return false;
12397 }
12398
12399 NullaryNodeType targetHolder;
12400 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)
;
12401
12402 NameNodeType newTargetName;
12403 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)
;
12404
12405 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)
12406 *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)
12407 false)do { auto parserTryVarTempResult_ = (handler_.newNewTarget(newHolder
, targetHolder, newTargetName)); if ((__builtin_expect(!!(parserTryVarTempResult_
.isErr()), 0))) { return (false); } (*newTarget) = parserTryVarTempResult_
.unwrap(); } while (0)
;
12408
12409 return true;
12410}
12411
12412template <class ParseHandler, typename Unit>
12413typename ParseHandler::BinaryNodeResult
12414GeneralParser<ParseHandler, Unit>::importExpr(YieldHandling yieldHandling,
12415 bool allowCallSyntax) {
12416 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", 12416); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::Import)"
")"); do { MOZ_CrashSequence(__null, 12416); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
12417
12418 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(); })
;
12419
12420 TokenKind next;
12421 if (!tokenStream.getToken(&next)) {
12422 return errorResult();
12423 }
12424
12425 ImportPhase phase = ImportPhase::Evaluation;
12426
12427 if (next == TokenKind::Dot) {
12428 if (!tokenStream.getToken(&next)) {
12429 return errorResult();
12430 }
12431 if (next == TokenKind::Meta) {
12432 if (parseGoal() != ParseGoal::Module) {
12433 errorAt(pos().begin, JSMSG_IMPORT_META_OUTSIDE_MODULE);
12434 return errorResult();
12435 }
12436
12437 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(); })
;
12438
12439 return handler_.newImportMeta(importHolder, metaHolder);
12440 }
12441
12442 if (options().sourcePhaseImports() && next == TokenKind::Source) {
12443 phase = ImportPhase::Source;
12444 } else if (options().deferImportEval() && next == TokenKind::Defer) {
12445 phase = ImportPhase::Deferred;
12446 } else {
12447 error(JSMSG_UNEXPECTED_TOKEN_NO_EXPECT, TokenKindToDesc(next));
12448 return errorResult();
12449 }
12450
12451 if (!tokenStream.getToken(&next)) {
12452 return errorResult();
12453 }
12454 }
12455
12456 if (next == TokenKind::LeftParen && allowCallSyntax) {
12457 Node arg =
12458 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
(); })
;
12459
12460 if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) {
12461 return errorResult();
12462 }
12463
12464 Node optionalArg;
12465 if (next == TokenKind::Comma
12466 // Unlike `import`, `import.source` does not have an optional parameter.
12467 && phase != ImportPhase::Source) {
12468 tokenStream.consumeKnownToken(TokenKind::Comma,
12469 TokenStream::SlashIsRegExp);
12470
12471 if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) {
12472 return errorResult();
12473 }
12474
12475 if (next != TokenKind::RightParen) {
12476 optionalArg =
12477 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
(); })
;
12478
12479 if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) {
12480 return errorResult();
12481 }
12482
12483 if (next == TokenKind::Comma) {
12484 tokenStream.consumeKnownToken(TokenKind::Comma,
12485 TokenStream::SlashIsRegExp);
12486 }
12487 } else {
12488 optionalArg =
12489 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
(); })
;
12490 }
12491 } else {
12492 optionalArg =
12493 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
(); })
;
12494 }
12495
12496 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_AFTER_ARGS)) {
12497 return errorResult();
12498 }
12499
12500 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(); })
;
12501
12502 return handler_.newCallImport(importHolder, spec, phase);
12503 }
12504
12505 error(JSMSG_UNEXPECTED_TOKEN_NO_EXPECT, TokenKindToDesc(next));
12506 return errorResult();
12507}
12508
12509template <class ParseHandler, typename Unit>
12510typename ParseHandler::NodeResult
12511GeneralParser<ParseHandler, Unit>::primaryExpr(
12512 YieldHandling yieldHandling, TripledotHandling tripledotHandling,
12513 TokenKind tt, PossibleError* possibleError, InvokedPrediction invoked) {
12514 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"
, 12514); AnnotateMozCrashReason("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(tt)"
")"); do { MOZ_CrashSequence(__null, 12514); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
12515 AutoCheckRecursionLimit recursion(this->fc_);
12516 if (!recursion.check(this->fc_)) {
12517 return errorResult();
12518 }
12519
12520 switch (tt) {
12521 case TokenKind::Function:
12522 return functionExpr(pos().begin, invoked,
12523 FunctionAsyncKind::SyncFunction);
12524
12525 case TokenKind::Class:
12526 return classDefinition(yieldHandling, ClassExpression, NameRequired);
12527
12528 case TokenKind::LeftBracket:
12529 return arrayInitializer(yieldHandling, possibleError);
12530
12531 case TokenKind::LeftCurly:
12532 return objectLiteral(yieldHandling, possibleError);
12533
12534#ifdef ENABLE_DECORATORS
12535 case TokenKind::At:
12536 if (fuzzingSafe) {
12537 error(JSMSG_DECORATOR_FUZZING_UNSAFE);
12538 return errorResult();
12539 }
12540
12541 return classDefinition(yieldHandling, ClassExpression, NameRequired);
12542#endif
12543
12544 case TokenKind::LeftParen: {
12545 TokenKind next;
12546 if (!tokenStream.peekToken(&next, TokenStream::SlashIsRegExp)) {
12547 return errorResult();
12548 }
12549
12550 if (next == TokenKind::RightParen) {
12551 // Not valid expression syntax, but this is valid in an arrow function
12552 // with no params: `() => body`.
12553 tokenStream.consumeKnownToken(TokenKind::RightParen,
12554 TokenStream::SlashIsRegExp);
12555
12556 if (!tokenStream.peekToken(&next)) {
12557 return errorResult();
12558 }
12559 if (next != TokenKind::Arrow) {
12560 error(JSMSG_UNEXPECTED_TOKEN, "expression",
12561 TokenKindToDesc(TokenKind::RightParen));
12562 return errorResult();
12563 }
12564
12565 // Now just return something that will allow parsing to continue.
12566 // It doesn't matter what; when we reach the =>, we will rewind and
12567 // reparse the whole arrow function. See Parser::assignExpr.
12568 return handler_.newNullLiteral(pos());
12569 }
12570
12571 // Pass |possibleError| to support destructuring in arrow parameters.
12572 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(); })
12573 TripledotAllowed, possibleError))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(exprInParens(InAllowed, yieldHandling, TripledotAllowed, possibleError
)); if ((__builtin_expect(!!(mozTryVarTempResult.isErr()), 0)
)) { return mozTryVarTempResult.propagateErr(); } mozTryVarTempResult
.unwrap(); })
;
12574 if (!mustMatchToken(TokenKind::RightParen, JSMSG_PAREN_IN_PAREN)) {
12575 return errorResult();
12576 }
12577 return handler_.parenthesize(expr);
12578 }
12579
12580 case TokenKind::TemplateHead:
12581 return templateLiteral(yieldHandling);
12582
12583 case TokenKind::NoSubsTemplate:
12584 return noSubstitutionUntaggedTemplate();
12585
12586 case TokenKind::String:
12587 return stringLiteral();
12588
12589 default: {
12590 if (!TokenKindIsPossibleIdentifier(tt)) {
12591 error(JSMSG_UNEXPECTED_TOKEN, "expression", TokenKindToDesc(tt));
12592 return errorResult();
12593 }
12594
12595 if (tt == TokenKind::Async) {
12596 TokenKind nextSameLine = TokenKind::Eof;
12597 if (!tokenStream.peekTokenSameLine(&nextSameLine)) {
12598 return errorResult();
12599 }
12600
12601 if (nextSameLine == TokenKind::Function) {
12602 uint32_t toStringStart = pos().begin;
12603 tokenStream.consumeKnownToken(TokenKind::Function);
12604 return functionExpr(toStringStart, PredictUninvoked,
12605 FunctionAsyncKind::AsyncFunction);
12606 }
12607 }
12608
12609 TaggedParserAtomIndex name = identifierReference(yieldHandling);
12610 if (!name) {
12611 return errorResult();
12612 }
12613
12614 return identifierReference(name);
12615 }
12616
12617 case TokenKind::RegExp:
12618 return newRegExp();
12619
12620 case TokenKind::Number:
12621 return newNumber(anyChars.currentToken());
12622
12623 case TokenKind::BigInt:
12624 return newBigInt();
12625
12626 case TokenKind::True:
12627 return handler_.newBooleanLiteral(true, pos());
12628 case TokenKind::False:
12629 return handler_.newBooleanLiteral(false, pos());
12630 case TokenKind::This: {
12631 NameNodeType thisName = null();
12632 if (pc_->sc()->hasFunctionThisBinding()) {
12633 thisName = MOZ_TRY(newThisName())__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(newThisName()); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
12634 }
12635 return handler_.newThisLiteral(pos(), thisName);
12636 }
12637 case TokenKind::Null:
12638 return handler_.newNullLiteral(pos());
12639
12640 case TokenKind::TripleDot: {
12641 // This isn't valid expression syntax, but it's valid in an arrow
12642 // function as a trailing rest param: `(a, b, ...rest) => body`. Check
12643 // if it's directly under
12644 // CoverParenthesizedExpressionAndArrowParameterList, and check for a
12645 // name, closing parenthesis, and arrow, and allow it only if all are
12646 // present.
12647 if (tripledotHandling != TripledotAllowed) {
12648 error(JSMSG_UNEXPECTED_TOKEN, "expression", TokenKindToDesc(tt));
12649 return errorResult();
12650 }
12651
12652 TokenKind next;
12653 if (!tokenStream.getToken(&next)) {
12654 return errorResult();
12655 }
12656
12657 if (next == TokenKind::LeftBracket || next == TokenKind::LeftCurly) {
12658 // Validate, but don't store the pattern right now. The whole arrow
12659 // function is reparsed in functionFormalParametersAndBody().
12660 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(); })
12661 yieldHandling, next))__extension__({ auto mozTryVarTempResult = ::mozilla::ToResult
(destructuringDeclaration(DeclarationKind::CoverArrowParameter
, yieldHandling, next)); if ((__builtin_expect(!!(mozTryVarTempResult
.isErr()), 0))) { return mozTryVarTempResult.propagateErr(); }
mozTryVarTempResult.unwrap(); })
;
12662 } else {
12663 // This doesn't check that the provided name is allowed, e.g. if
12664 // the enclosing code is strict mode code, any of "let", "yield",
12665 // or "arguments" should be prohibited. Argument-parsing code
12666 // handles that.
12667 if (!TokenKindIsPossibleIdentifier(next)) {
12668 error(JSMSG_UNEXPECTED_TOKEN, "rest argument name",
12669 TokenKindToDesc(next));
12670 return errorResult();
12671 }
12672 }
12673
12674 if (!tokenStream.getToken(&next)) {
12675 return errorResult();
12676 }
12677 if (next != TokenKind::RightParen) {
12678 error(JSMSG_UNEXPECTED_TOKEN, "closing parenthesis",
12679 TokenKindToDesc(next));
12680 return errorResult();
12681 }
12682
12683 if (!tokenStream.peekToken(&next)) {
12684 return errorResult();
12685 }
12686 if (next != TokenKind::Arrow) {
12687 // Advance the scanner for proper error location reporting.
12688 tokenStream.consumeKnownToken(next);
12689 error(JSMSG_UNEXPECTED_TOKEN, "'=>' after argument list",
12690 TokenKindToDesc(next));
12691 return errorResult();
12692 }
12693
12694 anyChars.ungetToken(); // put back right paren
12695
12696 // Return an arbitrary expression node. See case TokenKind::RightParen
12697 // above.
12698 return handler_.newNullLiteral(pos());
12699 }
12700 }
12701}
12702
12703template <class ParseHandler, typename Unit>
12704typename ParseHandler::NodeResult
12705GeneralParser<ParseHandler, Unit>::exprInParens(
12706 InHandling inHandling, YieldHandling yieldHandling,
12707 TripledotHandling tripledotHandling,
12708 PossibleError* possibleError /* = nullptr */) {
12709 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", 12709); AnnotateMozCrashReason
("MOZ_ASSERT" "(" "anyChars.isCurrentTokenType(TokenKind::LeftParen)"
")"); do { MOZ_CrashSequence(__null, 12709); __attribute__((
nomerge)) ::abort(); } while (false); } } while (false)
;
12710 return expr(inHandling, yieldHandling, tripledotHandling, possibleError,
12711 PredictInvoked);
12712}
12713
12714template class PerHandlerParser<FullParseHandler>;
12715template class PerHandlerParser<SyntaxParseHandler>;
12716template class GeneralParser<FullParseHandler, Utf8Unit>;
12717template class GeneralParser<SyntaxParseHandler, Utf8Unit>;
12718template class GeneralParser<FullParseHandler, char16_t>;
12719template class GeneralParser<SyntaxParseHandler, char16_t>;
12720template class Parser<FullParseHandler, Utf8Unit>;
12721template class Parser<SyntaxParseHandler, Utf8Unit>;
12722template class Parser<FullParseHandler, char16_t>;
12723template class Parser<SyntaxParseHandler, char16_t>;
12724
12725} // namespace js::frontend