Line data Source code
1 : // Copyright 2012 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_PARSING_PARSER_H_
6 : #define V8_PARSING_PARSER_H_
7 :
8 : #include "src/ast/ast.h"
9 : #include "src/ast/scopes.h"
10 : #include "src/base/compiler-specific.h"
11 : #include "src/globals.h"
12 : #include "src/parsing/parser-base.h"
13 : #include "src/parsing/parsing.h"
14 : #include "src/parsing/preparse-data-format.h"
15 : #include "src/parsing/preparse-data.h"
16 : #include "src/parsing/preparser.h"
17 : #include "src/pending-compilation-error-handler.h"
18 : #include "src/utils.h"
19 :
20 : namespace v8 {
21 :
22 : class ScriptCompiler;
23 :
24 : namespace internal {
25 :
26 : class ParseInfo;
27 : class ScriptData;
28 : class ParserTarget;
29 : class ParserTargetScope;
30 : class PreParsedScopeData;
31 :
32 : class FunctionEntry BASE_EMBEDDED {
33 : public:
34 : enum {
35 : kStartPositionIndex,
36 : kEndPositionIndex,
37 : kNumParametersIndex,
38 : kFlagsIndex,
39 : kNumInnerFunctionsIndex,
40 : kSize
41 : };
42 :
43 : explicit FunctionEntry(Vector<unsigned> backing)
44 : : backing_(backing) { }
45 :
46 : FunctionEntry() : backing_() { }
47 :
48 : class LanguageModeField : public BitField<LanguageMode, 0, 1> {};
49 : class UsesSuperPropertyField
50 : : public BitField<bool, LanguageModeField::kNext, 1> {};
51 :
52 : static uint32_t EncodeFlags(LanguageMode language_mode,
53 : bool uses_super_property) {
54 : return LanguageModeField::encode(language_mode) |
55 204 : UsesSuperPropertyField::encode(uses_super_property);
56 : }
57 :
58 : int start_pos() const { return backing_[kStartPositionIndex]; }
59 480 : int end_pos() const { return backing_[kEndPositionIndex]; }
60 120 : int num_parameters() const { return backing_[kNumParametersIndex]; }
61 : LanguageMode language_mode() const {
62 120 : return LanguageModeField::decode(backing_[kFlagsIndex]);
63 : }
64 : bool uses_super_property() const {
65 120 : return UsesSuperPropertyField::decode(backing_[kFlagsIndex]);
66 : }
67 120 : int num_inner_functions() const { return backing_[kNumInnerFunctionsIndex]; }
68 :
69 126 : bool is_valid() const { return !backing_.is_empty(); }
70 :
71 : private:
72 : Vector<unsigned> backing_;
73 : };
74 :
75 :
76 : // Wrapper around ScriptData to provide parser-specific functionality.
77 : class ParseData {
78 : public:
79 72 : static ParseData* FromCachedData(ScriptData* cached_data) {
80 72 : ParseData* pd = new ParseData(cached_data);
81 72 : if (pd->IsSane()) return pd;
82 : cached_data->Reject();
83 6 : delete pd;
84 6 : return NULL;
85 : }
86 :
87 : void Initialize();
88 : FunctionEntry GetFunctionEntry(int start);
89 : int FunctionCount();
90 :
91 : unsigned* Data() { // Writable data as unsigned int array.
92 414 : return reinterpret_cast<unsigned*>(const_cast<byte*>(script_data_->data()));
93 : }
94 :
95 : void Reject() { script_data_->Reject(); }
96 :
97 : bool rejected() const { return script_data_->rejected(); }
98 :
99 : private:
100 72 : explicit ParseData(ScriptData* script_data) : script_data_(script_data) {}
101 :
102 : bool IsSane();
103 : unsigned Magic();
104 : unsigned Version();
105 : int FunctionsSize();
106 : int Length() const {
107 : // Script data length is already checked to be a multiple of unsigned size.
108 324 : return script_data_->length() / sizeof(unsigned);
109 : }
110 :
111 : ScriptData* script_data_;
112 : int function_index_;
113 :
114 : DISALLOW_COPY_AND_ASSIGN(ParseData);
115 : };
116 :
117 : // ----------------------------------------------------------------------------
118 : // JAVASCRIPT PARSING
119 :
120 : class Parser;
121 :
122 :
123 : struct ParserFormalParameters : FormalParametersBase {
124 : struct Parameter : public ZoneObject {
125 9965353 : Parameter(const AstRawString* name, Expression* pattern,
126 : Expression* initializer, int position,
127 : int initializer_end_position, bool is_rest)
128 : : name(name),
129 : pattern(pattern),
130 : initializer(initializer),
131 : position(position),
132 : initializer_end_position(initializer_end_position),
133 9965353 : is_rest(is_rest) {}
134 : const AstRawString* name;
135 : Expression* pattern;
136 : Expression* initializer;
137 : int position;
138 : int initializer_end_position;
139 : bool is_rest;
140 : Parameter* next_parameter = nullptr;
141 93522 : bool is_simple() const {
142 187044 : return pattern->IsVariableProxy() && initializer == nullptr && !is_rest;
143 : }
144 :
145 : Parameter** next() { return &next_parameter; }
146 : Parameter* const* next() const { return &next_parameter; }
147 : };
148 :
149 : explicit ParserFormalParameters(DeclarationScope* scope)
150 : : FormalParametersBase(scope) {}
151 : ThreadedList<Parameter> params;
152 : };
153 :
154 : template <>
155 : struct ParserTypes<Parser> {
156 : typedef ParserBase<Parser> Base;
157 : typedef Parser Impl;
158 :
159 : typedef v8::internal::Variable Variable;
160 :
161 : // Return types for traversing functions.
162 : typedef const AstRawString* Identifier;
163 : typedef v8::internal::Expression* Expression;
164 : typedef v8::internal::FunctionLiteral* FunctionLiteral;
165 : typedef ObjectLiteral::Property* ObjectLiteralProperty;
166 : typedef ClassLiteral::Property* ClassLiteralProperty;
167 : typedef v8::internal::Suspend* Suspend;
168 : typedef ZoneList<v8::internal::Expression*>* ExpressionList;
169 : typedef ZoneList<ObjectLiteral::Property*>* ObjectPropertyList;
170 : typedef ZoneList<ClassLiteral::Property*>* ClassPropertyList;
171 : typedef ParserFormalParameters FormalParameters;
172 : typedef v8::internal::Statement* Statement;
173 : typedef ZoneList<v8::internal::Statement*>* StatementList;
174 : typedef v8::internal::Block* Block;
175 : typedef v8::internal::BreakableStatement* BreakableStatement;
176 : typedef v8::internal::IterationStatement* IterationStatement;
177 :
178 : // For constructing objects returned by the traversing functions.
179 : typedef AstNodeFactory Factory;
180 :
181 : typedef ParserTarget Target;
182 : typedef ParserTargetScope TargetScope;
183 : };
184 :
185 : class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
186 : public:
187 : explicit Parser(ParseInfo* info);
188 7135467 : ~Parser() {
189 3973343 : delete reusable_preparser_;
190 3567736 : reusable_preparser_ = NULL;
191 3567736 : delete cached_parse_data_;
192 3567731 : cached_parse_data_ = NULL;
193 3567737 : }
194 :
195 : static bool IsPreParser() { return false; }
196 :
197 : void ParseOnBackground(ParseInfo* info);
198 :
199 : // Deserialize the scope chain prior to parsing in which the script is going
200 : // to be executed. If the script is a top-level script, or the scope chain
201 : // consists of only a native context, maybe_outer_scope_info should be an
202 : // empty handle.
203 : //
204 : // This only deserializes the scope chain, but doesn't connect the scopes to
205 : // their corresponding scope infos. Therefore, looking up variables in the
206 : // deserialized scopes is not possible.
207 : void DeserializeScopeChain(ParseInfo* info,
208 : MaybeHandle<ScopeInfo> maybe_outer_scope_info);
209 :
210 : // Handle errors detected during parsing
211 : void ReportErrors(Isolate* isolate, Handle<Script> script);
212 : // Move statistics to Isolate
213 : void UpdateStatistics(Isolate* isolate, Handle<Script> script);
214 : void HandleSourceURLComments(Isolate* isolate, Handle<Script> script);
215 :
216 : private:
217 : friend class ParserBase<Parser>;
218 : friend class v8::internal::ExpressionClassifier<ParserTypes<Parser>>;
219 : friend bool v8::internal::parsing::ParseProgram(ParseInfo*, Isolate*, bool);
220 : friend bool v8::internal::parsing::ParseFunction(ParseInfo*, Isolate*, bool);
221 :
222 : bool AllowsLazyParsingWithoutUnresolvedVariables() const {
223 : return scope()->AllowsLazyParsingWithoutUnresolvedVariables(
224 8107044 : original_scope_);
225 : }
226 :
227 : bool parse_lazily() const { return mode_ == PARSE_LAZILY; }
228 : enum Mode { PARSE_LAZILY, PARSE_EAGERLY };
229 :
230 : class ParsingModeScope BASE_EMBEDDED {
231 : public:
232 : ParsingModeScope(Parser* parser, Mode mode)
233 9723399 : : parser_(parser), old_mode_(parser->mode_) {
234 9723399 : parser_->mode_ = mode;
235 : }
236 9723395 : ~ParsingModeScope() { parser_->mode_ = old_mode_; }
237 :
238 : private:
239 : Parser* parser_;
240 : Mode old_mode_;
241 : };
242 :
243 : // Runtime encoding of different completion modes.
244 : enum CompletionKind {
245 : kNormalCompletion,
246 : kThrowCompletion,
247 : kAbruptCompletion
248 : };
249 :
250 201417 : Variable* NewTemporary(const AstRawString* name) {
251 1452103 : return scope()->NewTemporary(name);
252 : }
253 :
254 : void PrepareGeneratorVariables();
255 :
256 : // Limit the allowed number of local variables in a function. The hard limit
257 : // is that offsets computed by FullCodeGenerator::StackOperand and similar
258 : // functions are ints, and they should not overflow. In addition, accessing
259 : // local variables creates user-controlled constants in the generated code,
260 : // and we don't want too much user-controlled memory inside the code (this was
261 : // the reason why this limit was introduced in the first place; see
262 : // https://codereview.chromium.org/7003030/ ).
263 : static const int kMaxNumFunctionLocals = 4194303; // 2^22-1
264 :
265 : // Returns NULL if parsing failed.
266 : FunctionLiteral* ParseProgram(Isolate* isolate, ParseInfo* info);
267 :
268 : FunctionLiteral* ParseFunction(Isolate* isolate, ParseInfo* info);
269 : FunctionLiteral* DoParseFunction(ParseInfo* info);
270 :
271 : // Called by ParseProgram after setting up the scanner.
272 : FunctionLiteral* DoParseProgram(ParseInfo* info);
273 :
274 : void SetCachedData(ParseInfo* info);
275 :
276 : ScriptCompiler::CompileOptions compile_options() const {
277 : return compile_options_;
278 : }
279 : bool consume_cached_parse_data() const {
280 : return compile_options_ == ScriptCompiler::kConsumeParserCache;
281 : }
282 : bool produce_cached_parse_data() const {
283 : return compile_options_ == ScriptCompiler::kProduceParserCache;
284 : }
285 :
286 2818332 : PreParser* reusable_preparser() {
287 2818332 : if (reusable_preparser_ == NULL) {
288 : reusable_preparser_ =
289 4461677 : new PreParser(zone(), &scanner_, stack_limit_, ast_value_factory(),
290 : &pending_error_handler_, runtime_call_stats_,
291 405607 : preparsed_scope_data_, parsing_on_main_thread_);
292 : #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
293 : SET_ALLOW(natives);
294 : SET_ALLOW(tailcalls);
295 : SET_ALLOW(harmony_do_expressions);
296 : SET_ALLOW(harmony_function_sent);
297 : SET_ALLOW(harmony_trailing_commas);
298 : SET_ALLOW(harmony_class_fields);
299 : SET_ALLOW(harmony_object_rest_spread);
300 : SET_ALLOW(harmony_dynamic_import);
301 : SET_ALLOW(harmony_async_iteration);
302 : SET_ALLOW(harmony_template_escapes);
303 : #undef SET_ALLOW
304 : }
305 2818332 : return reusable_preparser_;
306 : }
307 :
308 : void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok);
309 : Statement* ParseModuleItem(bool* ok);
310 : const AstRawString* ParseModuleSpecifier(bool* ok);
311 : void ParseImportDeclaration(bool* ok);
312 : Statement* ParseExportDeclaration(bool* ok);
313 : Statement* ParseExportDefault(bool* ok);
314 : void ParseExportClause(ZoneList<const AstRawString*>* export_names,
315 : ZoneList<Scanner::Location>* export_locations,
316 : ZoneList<const AstRawString*>* local_names,
317 : Scanner::Location* reserved_loc, bool* ok);
318 : struct NamedImport : public ZoneObject {
319 : const AstRawString* import_name;
320 : const AstRawString* local_name;
321 : const Scanner::Location location;
322 : NamedImport(const AstRawString* import_name, const AstRawString* local_name,
323 : Scanner::Location location)
324 : : import_name(import_name),
325 : local_name(local_name),
326 773 : location(location) {}
327 : };
328 : ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok);
329 : Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result,
330 : ZoneList<const AstRawString*>* names,
331 : bool* ok);
332 : void DeclareAndInitializeVariables(
333 : Block* block, const DeclarationDescriptor* declaration_descriptor,
334 : const DeclarationParsingResult::Declaration* declaration,
335 : ZoneList<const AstRawString*>* names, bool* ok);
336 : ZoneList<const AstRawString*>* DeclareLabel(
337 : ZoneList<const AstRawString*>* labels, VariableProxy* expr, bool* ok);
338 : bool ContainsLabel(ZoneList<const AstRawString*>* labels,
339 : const AstRawString* label);
340 : Expression* RewriteReturn(Expression* return_value, int pos);
341 : Statement* RewriteSwitchStatement(Expression* tag,
342 : SwitchStatement* switch_statement,
343 : ZoneList<CaseClause*>* cases, Scope* scope);
344 : void RewriteCatchPattern(CatchInfo* catch_info, bool* ok);
345 : void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok);
346 : Statement* RewriteTryStatement(Block* try_block, Block* catch_block,
347 : Block* finally_block,
348 : const CatchInfo& catch_info, int pos);
349 :
350 : void ParseAndRewriteGeneratorFunctionBody(int pos, FunctionKind kind,
351 : ZoneList<Statement*>* body,
352 : bool* ok);
353 : void CreateFunctionNameAssignment(const AstRawString* function_name, int pos,
354 : FunctionLiteral::FunctionType function_type,
355 : DeclarationScope* function_scope,
356 : ZoneList<Statement*>* result, int index);
357 :
358 : Statement* DeclareFunction(const AstRawString* variable_name,
359 : FunctionLiteral* function, VariableMode mode,
360 : int pos, bool is_sloppy_block_function,
361 : ZoneList<const AstRawString*>* names, bool* ok);
362 : V8_INLINE Statement* DeclareClass(const AstRawString* variable_name,
363 : Expression* value,
364 : ZoneList<const AstRawString*>* names,
365 : int class_token_pos, int end_pos, bool* ok);
366 : V8_INLINE void DeclareClassVariable(const AstRawString* name,
367 : ClassInfo* class_info,
368 : int class_token_pos, bool* ok);
369 : V8_INLINE void DeclareClassProperty(const AstRawString* class_name,
370 : ClassLiteralProperty* property,
371 : ClassLiteralProperty::Kind kind,
372 : bool is_static, bool is_constructor,
373 : ClassInfo* class_info, bool* ok);
374 : V8_INLINE Expression* RewriteClassLiteral(const AstRawString* name,
375 : ClassInfo* class_info, int pos,
376 : bool* ok);
377 : V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos,
378 : bool* ok);
379 :
380 : V8_INLINE Block* IgnoreCompletion(Statement* statement);
381 :
382 : V8_INLINE Scope* NewHiddenCatchScopeWithParent(Scope* parent);
383 :
384 : class PatternRewriter final : public AstVisitor<PatternRewriter> {
385 : public:
386 : static void DeclareAndInitializeVariables(
387 : Parser* parser, Block* block,
388 : const DeclarationDescriptor* declaration_descriptor,
389 : const DeclarationParsingResult::Declaration* declaration,
390 : ZoneList<const AstRawString*>* names, bool* ok);
391 :
392 : static void RewriteDestructuringAssignment(Parser* parser,
393 : RewritableExpression* expr,
394 : Scope* Scope);
395 :
396 : static Expression* RewriteDestructuringAssignment(Parser* parser,
397 : Assignment* assignment,
398 : Scope* scope);
399 :
400 : private:
401 : PatternRewriter() {}
402 :
403 : #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node);
404 : // Visiting functions for AST nodes make this an AstVisitor.
405 : AST_NODE_LIST(DECLARE_VISIT)
406 : #undef DECLARE_VISIT
407 :
408 : enum PatternContext {
409 : BINDING,
410 : INITIALIZER,
411 : ASSIGNMENT,
412 : ASSIGNMENT_INITIALIZER
413 : };
414 :
415 : PatternContext context() const { return context_; }
416 573334 : void set_context(PatternContext context) { context_ = context; }
417 :
418 : void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
419 413320 : Expression* old_value = current_value_;
420 14836984 : current_value_ = value;
421 14836984 : recursion_level_++;
422 14836984 : Visit(pattern);
423 413320 : recursion_level_--;
424 413320 : current_value_ = old_value;
425 : }
426 :
427 : void VisitObjectLiteral(ObjectLiteral* node, Variable** temp_var);
428 : void VisitArrayLiteral(ArrayLiteral* node, Variable** temp_var);
429 :
430 : bool IsBindingContext() const {
431 : return context_ == BINDING || context_ == INITIALIZER;
432 : }
433 : bool IsInitializerContext() const { return context_ != ASSIGNMENT; }
434 : bool IsAssignmentContext() const {
435 14599300 : return context_ == ASSIGNMENT || context_ == ASSIGNMENT_INITIALIZER;
436 : }
437 : bool IsSubPattern() const { return recursion_level_ > 1; }
438 : PatternContext SetAssignmentContextIfNeeded(Expression* node);
439 : PatternContext SetInitializerContextIfNeeded(Expression* node);
440 :
441 : bool DeclaresParameterContainingSloppyEval() const;
442 : void RewriteParameterScopes(Expression* expr);
443 :
444 : Variable* CreateTempVar(Expression* value = nullptr);
445 :
446 : AstNodeFactory* factory() const { return parser_->factory(); }
447 : AstValueFactory* ast_value_factory() const {
448 929669 : return parser_->ast_value_factory();
449 : }
450 15505987 : Zone* zone() const { return parser_->zone(); }
451 : Scope* scope() const { return scope_; }
452 :
453 : Scope* scope_;
454 : Parser* parser_;
455 : PatternContext context_;
456 : Expression* pattern_;
457 : int initializer_position_;
458 : Block* block_;
459 : const DeclarationDescriptor* descriptor_;
460 : ZoneList<const AstRawString*>* names_;
461 : Expression* current_value_;
462 : int recursion_level_;
463 : bool* ok_;
464 :
465 29680562 : DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW()
466 : };
467 :
468 : // [if (IteratorType == kAsync)]
469 : // !%_IsJSReceiver(result = Await(iterator.next()) &&
470 : // %ThrowIteratorResultNotAnObject(result)
471 : // [else]
472 : // !%_IsJSReceiver(result = iterator.next()) &&
473 : // %ThrowIteratorResultNotAnObject(result)
474 : // [endif]
475 : Expression* BuildIteratorNextResult(Expression* iterator, Variable* result,
476 : IteratorType type, int pos);
477 :
478 : // Initialize the components of a for-in / for-of statement.
479 : Statement* InitializeForEachStatement(ForEachStatement* stmt,
480 : Expression* each, Expression* subject,
481 : Statement* body, int each_keyword_pos);
482 : Statement* InitializeForOfStatement(ForOfStatement* stmt, Expression* each,
483 : Expression* iterable, Statement* body,
484 : bool finalize, IteratorType type,
485 : int next_result_pos = kNoSourcePosition);
486 :
487 : Block* RewriteForVarInLegacy(const ForInfo& for_info);
488 : void DesugarBindingInForEachStatement(ForInfo* for_info, Block** body_block,
489 : Expression** each_variable, bool* ok);
490 : Block* CreateForEachStatementTDZ(Block* init_block, const ForInfo& for_info,
491 : bool* ok);
492 :
493 : Statement* DesugarLexicalBindingsInForStatement(
494 : ForStatement* loop, Statement* init, Expression* cond, Statement* next,
495 : Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok);
496 :
497 : Expression* RewriteDoExpression(Block* body, int pos, bool* ok);
498 :
499 : FunctionLiteral* ParseFunctionLiteral(
500 : const AstRawString* name, Scanner::Location function_name_location,
501 : FunctionNameValidity function_name_validity, FunctionKind kind,
502 : int function_token_position, FunctionLiteral::FunctionType type,
503 : LanguageMode language_mode, bool* ok);
504 :
505 : // Get odd-ball literals.
506 : Literal* GetLiteralUndefined(int position);
507 :
508 : // Check if the scope has conflicting var/let declarations from different
509 : // scopes. This covers for example
510 : //
511 : // function f() { { { var x; } let x; } }
512 : // function g() { { var x; let x; } }
513 : //
514 : // The var declarations are hoisted to the function scope, but originate from
515 : // a scope where the name has also been let bound or the var declaration is
516 : // hoisted over such a scope.
517 : void CheckConflictingVarDeclarations(Scope* scope, bool* ok);
518 :
519 : // Insert initializer statements for var-bindings shadowing parameter bindings
520 : // from a non-simple parameter list.
521 : void InsertShadowingVarBindingInitializers(Block* block);
522 :
523 : // Implement sloppy block-scoped functions, ES2015 Annex B 3.3
524 : void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope);
525 :
526 : VariableProxy* NewUnresolved(const AstRawString* name, int begin_pos,
527 : VariableKind kind = NORMAL_VARIABLE);
528 : VariableProxy* NewUnresolved(const AstRawString* name);
529 : Variable* Declare(Declaration* declaration,
530 : DeclarationDescriptor::Kind declaration_kind,
531 : VariableMode mode, InitializationFlag init, bool* ok,
532 : Scope* declaration_scope = nullptr,
533 : int var_end_pos = kNoSourcePosition);
534 : Declaration* DeclareVariable(const AstRawString* name, VariableMode mode,
535 : int pos, bool* ok);
536 : Declaration* DeclareVariable(const AstRawString* name, VariableMode mode,
537 : InitializationFlag init, int pos, bool* ok);
538 :
539 : bool TargetStackContainsLabel(const AstRawString* label);
540 : BreakableStatement* LookupBreakTarget(const AstRawString* label, bool* ok);
541 : IterationStatement* LookupContinueTarget(const AstRawString* label, bool* ok);
542 :
543 : Statement* BuildAssertIsCoercible(Variable* var);
544 :
545 : // Factory methods.
546 : FunctionLiteral* DefaultConstructor(const AstRawString* name, bool call_super,
547 : int pos, int end_pos);
548 :
549 : // Skip over a lazy function, either using cached data if we have it, or
550 : // by parsing the function with PreParser. Consumes the ending }.
551 : // If may_abort == true, the (pre-)parser may decide to abort skipping
552 : // in order to force the function to be eagerly parsed, after all.
553 : LazyParsingResult SkipFunction(FunctionKind kind,
554 : DeclarationScope* function_scope,
555 : int* num_parameters, bool is_inner_function,
556 : bool may_abort, bool* ok);
557 :
558 : Block* BuildParameterInitializationBlock(
559 : const ParserFormalParameters& parameters, bool* ok);
560 : Block* BuildRejectPromiseOnException(Block* block);
561 :
562 : ZoneList<Statement*>* ParseFunction(
563 : const AstRawString* function_name, int pos, FunctionKind kind,
564 : FunctionLiteral::FunctionType function_type,
565 : DeclarationScope* function_scope, int* num_parameters,
566 : int* function_length, bool* has_duplicate_parameters,
567 : int* expected_property_count, bool* ok);
568 :
569 : void ThrowPendingError(Isolate* isolate, Handle<Script> script);
570 :
571 : class TemplateLiteral : public ZoneObject {
572 : public:
573 40750 : TemplateLiteral(Zone* zone, int pos)
574 40750 : : cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {}
575 :
576 : const ZoneList<Expression*>* cooked() const { return &cooked_; }
577 : const ZoneList<Expression*>* raw() const { return &raw_; }
578 : const ZoneList<Expression*>* expressions() const { return &expressions_; }
579 : int position() const { return pos_; }
580 :
581 70792 : void AddTemplateSpan(Literal* cooked, Literal* raw, int end, Zone* zone) {
582 : DCHECK_NOT_NULL(cooked);
583 : DCHECK_NOT_NULL(raw);
584 : cooked_.Add(cooked, zone);
585 : raw_.Add(raw, zone);
586 70792 : }
587 :
588 : void AddExpression(Expression* expression, Zone* zone) {
589 : DCHECK_NOT_NULL(expression);
590 : expressions_.Add(expression, zone);
591 : }
592 :
593 : private:
594 : ZoneList<Expression*> cooked_;
595 : ZoneList<Expression*> raw_;
596 : ZoneList<Expression*> expressions_;
597 : int pos_;
598 : };
599 :
600 : typedef TemplateLiteral* TemplateLiteralState;
601 :
602 : TemplateLiteralState OpenTemplateLiteral(int pos);
603 : // "should_cook" means that the span can be "cooked": in tagged template
604 : // literals, both the raw and "cooked" representations are available to user
605 : // code ("cooked" meaning that escape sequences are converted to their
606 : // interpreted values). With the --harmony-template-escapes flag, invalid
607 : // escape sequences cause the cooked span to be represented by undefined,
608 : // instead of being a syntax error.
609 : // "tail" indicates that this span is the last in the literal.
610 : void AddTemplateSpan(TemplateLiteralState* state, bool should_cook,
611 : bool tail);
612 : void AddTemplateExpression(TemplateLiteralState* state,
613 : Expression* expression);
614 : Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
615 : Expression* tag);
616 : uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
617 :
618 : ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list);
619 : Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args,
620 : int pos, Call::PossiblyEval is_possibly_eval);
621 : Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args,
622 : int pos);
623 : Expression* RewriteSuperCall(Expression* call_expression);
624 :
625 : void SetLanguageMode(Scope* scope, LanguageMode mode);
626 : void SetAsmModule();
627 :
628 : V8_INLINE void MarkCollectedTailCallExpressions();
629 : V8_INLINE void MarkTailPosition(Expression* expression);
630 :
631 : // Rewrite all DestructuringAssignments in the current FunctionState.
632 : V8_INLINE void RewriteDestructuringAssignments();
633 :
634 : V8_INLINE Expression* RewriteExponentiation(Expression* left,
635 : Expression* right, int pos);
636 : V8_INLINE Expression* RewriteAssignExponentiation(Expression* left,
637 : Expression* right, int pos);
638 :
639 : friend class NonPatternRewriter;
640 : V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
641 :
642 : // Rewrite expressions that are not used as patterns
643 : V8_INLINE void RewriteNonPattern(bool* ok);
644 :
645 : V8_INLINE void QueueDestructuringAssignmentForRewriting(
646 : Expression* assignment);
647 : V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok);
648 :
649 : friend class InitializerRewriter;
650 : void RewriteParameterInitializer(Expression* expr, Scope* scope);
651 :
652 : Expression* BuildInitialYield(int pos, FunctionKind kind);
653 : Assignment* BuildCreateJSGeneratorObject(int pos, FunctionKind kind);
654 : Expression* BuildResolvePromise(Expression* value, int pos);
655 : Expression* BuildRejectPromise(Expression* value, int pos);
656 : Variable* PromiseVariable();
657 : Variable* AsyncGeneratorAwaitVariable();
658 :
659 : // Generic AST generator for throwing errors from compiled code.
660 : Expression* NewThrowError(Runtime::FunctionId function_id,
661 : MessageTemplate::Template message,
662 : const AstRawString* arg, int pos);
663 :
664 : void FinalizeIteratorUse(Scope* use_scope, Variable* completion,
665 : Expression* condition, Variable* iter,
666 : Block* iterator_use, Block* result,
667 : IteratorType type);
668 :
669 : Statement* FinalizeForOfStatement(ForOfStatement* loop, Variable* completion,
670 : IteratorType type, int pos);
671 : void BuildIteratorClose(ZoneList<Statement*>* statements, Variable* iterator,
672 : Variable* input, Variable* output, IteratorType type);
673 : void BuildIteratorCloseForCompletion(Scope* scope,
674 : ZoneList<Statement*>* statements,
675 : Variable* iterator,
676 : Expression* completion,
677 : IteratorType type);
678 : Statement* CheckCallable(Variable* var, Expression* error, int pos);
679 :
680 : V8_INLINE Expression* RewriteAwaitExpression(Expression* value, int pos);
681 : V8_INLINE void PrepareAsyncFunctionBody(ZoneList<Statement*>* body,
682 : FunctionKind kind, int pos);
683 : V8_INLINE void RewriteAsyncFunctionBody(ZoneList<Statement*>* body,
684 : Block* block,
685 : Expression* return_value, bool* ok);
686 :
687 : Expression* RewriteYieldStar(Expression* generator, Expression* expression,
688 : int pos);
689 :
690 : void AddArrowFunctionFormalParameters(ParserFormalParameters* parameters,
691 : Expression* params, int end_pos,
692 : bool* ok);
693 : void SetFunctionName(Expression* value, const AstRawString* name);
694 :
695 : // Helper functions for recursive descent.
696 : V8_INLINE bool IsEval(const AstRawString* identifier) const {
697 107438565 : return identifier == ast_value_factory()->eval_string();
698 : }
699 :
700 : V8_INLINE bool IsArguments(const AstRawString* identifier) const {
701 101175328 : return identifier == ast_value_factory()->arguments_string();
702 : }
703 :
704 : V8_INLINE bool IsEvalOrArguments(const AstRawString* identifier) const {
705 202751707 : return IsEval(identifier) || IsArguments(identifier);
706 : }
707 :
708 : V8_INLINE bool IsUndefined(const AstRawString* identifier) const {
709 : return identifier == ast_value_factory()->undefined_string();
710 : }
711 :
712 : // Returns true if the expression is of type "this.foo".
713 : V8_INLINE static bool IsThisProperty(Expression* expression) {
714 : DCHECK(expression != NULL);
715 11489961 : Property* property = expression->AsProperty();
716 27751908 : return property != NULL && property->obj()->IsVariableProxy() &&
717 9775410 : property->obj()->AsVariableProxy()->is_this();
718 : }
719 :
720 : // This returns true if the expression is an indentifier (wrapped
721 : // inside a variable proxy). We exclude the case of 'this', which
722 : // has been converted to a variable proxy.
723 : V8_INLINE static bool IsIdentifier(Expression* expression) {
724 : DCHECK_NOT_NULL(expression);
725 210536904 : VariableProxy* operand = expression->AsVariableProxy();
726 283592387 : return operand != nullptr && !operand->is_this() &&
727 70542920 : !operand->is_new_target();
728 : }
729 :
730 : V8_INLINE static const AstRawString* AsIdentifier(Expression* expression) {
731 : DCHECK(IsIdentifier(expression));
732 35066415 : return expression->AsVariableProxy()->raw_name();
733 : }
734 :
735 : V8_INLINE VariableProxy* AsIdentifierExpression(Expression* expression) {
736 25158 : return expression->AsVariableProxy();
737 : }
738 :
739 : V8_INLINE bool IsPrototype(const AstRawString* identifier) const {
740 : return identifier == ast_value_factory()->prototype_string();
741 : }
742 :
743 : V8_INLINE bool IsConstructor(const AstRawString* identifier) const {
744 315580 : return identifier == ast_value_factory()->constructor_string();
745 : }
746 :
747 : V8_INLINE bool IsName(const AstRawString* identifier) const {
748 18108 : return identifier == ast_value_factory()->name_string();
749 : }
750 :
751 : V8_INLINE static bool IsBoilerplateProperty(
752 : ObjectLiteral::Property* property) {
753 4917800 : return ObjectLiteral::IsBoilerplateProperty(property);
754 : }
755 :
756 : V8_INLINE bool IsNative(Expression* expr) const {
757 : DCHECK_NOT_NULL(expr);
758 8982 : return expr->IsVariableProxy() &&
759 2994 : expr->AsVariableProxy()->raw_name() ==
760 2994 : ast_value_factory()->native_string();
761 : }
762 :
763 : V8_INLINE static bool IsArrayIndex(const AstRawString* string,
764 : uint32_t* index) {
765 1899163 : return string->AsArrayIndex(index);
766 : }
767 :
768 : V8_INLINE bool IsUseStrictDirective(Statement* statement) const {
769 2153570 : return IsStringLiteral(statement, ast_value_factory()->use_strict_string());
770 : }
771 :
772 : V8_INLINE bool IsUseAsmDirective(Statement* statement) const {
773 1853351 : return IsStringLiteral(statement, ast_value_factory()->use_asm_string());
774 : }
775 :
776 : // Returns true if the statement is an expression statement containing
777 : // a single string literal. If a second argument is given, the literal
778 : // is also compared with it and the result is true only if they are equal.
779 : V8_INLINE bool IsStringLiteral(Statement* statement,
780 : const AstRawString* arg = nullptr) const {
781 8002740 : ExpressionStatement* e_stat = statement->AsExpressionStatement();
782 5849170 : if (e_stat == nullptr) return false;
783 15664021 : Literal* literal = e_stat->expression()->AsLiteral();
784 11673596 : if (literal == nullptr || !literal->raw_value()->IsString()) return false;
785 7980850 : return arg == nullptr || literal->raw_value()->AsString() == arg;
786 : }
787 :
788 14041 : V8_INLINE static Expression* GetPropertyValue(LiteralProperty* property) {
789 14041 : return property->value();
790 : }
791 :
792 : V8_INLINE void GetDefaultStrings(
793 : const AstRawString** default_string,
794 : const AstRawString** star_default_star_string) {
795 84 : *default_string = ast_value_factory()->default_string();
796 84 : *star_default_star_string = ast_value_factory()->star_default_star_string();
797 : }
798 :
799 : // Functions for encapsulating the differences between parsing and preparsing;
800 : // operations interleaved with the recursive descent.
801 : V8_INLINE void PushLiteralName(const AstRawString* id) {
802 : DCHECK_NOT_NULL(fni_);
803 25557524 : fni_->PushLiteralName(id);
804 : }
805 :
806 : V8_INLINE void PushVariableName(const AstRawString* id) {
807 : DCHECK_NOT_NULL(fni_);
808 14178488 : fni_->PushVariableName(id);
809 : }
810 :
811 : V8_INLINE void PushPropertyName(Expression* expression) {
812 : DCHECK_NOT_NULL(fni_);
813 4882644 : if (expression->IsPropertyName()) {
814 163330 : fni_->PushLiteralName(expression->AsLiteral()->AsRawPropertyName());
815 : } else {
816 4800980 : fni_->PushLiteralName(ast_value_factory()->anonymous_function_string());
817 : }
818 : }
819 :
820 : V8_INLINE void PushEnclosingName(const AstRawString* name) {
821 : DCHECK_NOT_NULL(fni_);
822 1823883 : fni_->PushEnclosingName(name);
823 : }
824 :
825 : V8_INLINE void AddFunctionForNameInference(FunctionLiteral* func_to_infer) {
826 : DCHECK_NOT_NULL(fni_);
827 736472 : fni_->AddFunction(func_to_infer);
828 : }
829 :
830 : V8_INLINE void InferFunctionName() {
831 : DCHECK_NOT_NULL(fni_);
832 350663 : fni_->Infer();
833 : }
834 :
835 : // If we assign a function literal to a property we pretenure the
836 : // literal so it can be added as a constant function property.
837 : V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
838 : Expression* left, Expression* right) {
839 : DCHECK(left != NULL);
840 16828449 : if (left->IsProperty() && right->IsFunctionLiteral()) {
841 3732050 : right->AsFunctionLiteral()->set_pretenure();
842 : }
843 : }
844 :
845 : // Determine if the expression is a variable proxy and mark it as being used
846 : // in an assignment or with a increment/decrement operator.
847 : V8_INLINE static void MarkExpressionAsAssigned(Expression* expression) {
848 : DCHECK_NOT_NULL(expression);
849 23684202 : if (expression->IsVariableProxy()) {
850 5119472 : expression->AsVariableProxy()->set_is_assigned();
851 : }
852 : }
853 :
854 : // Returns true if we have a binary expression between two numeric
855 : // literals. In that case, *x will be changed to an expression which is the
856 : // computed value.
857 : bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y,
858 : Token::Value op, int pos);
859 :
860 : // Rewrites the following types of unary expressions:
861 : // not <literal> -> true / false
862 : // + <numeric literal> -> <numeric literal>
863 : // - <numeric literal> -> <numeric literal with value negated>
864 : // ! <literal> -> true / false
865 : // The following rewriting rules enable the collection of type feedback
866 : // without any special stub and the multiplication is removed later in
867 : // Crankshaft's canonicalization pass.
868 : // + foo -> foo * 1
869 : // - foo -> foo * (-1)
870 : // ~ foo -> foo ^(~0)
871 : Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
872 : int pos);
873 :
874 : Expression* BuildIteratorResult(Expression* value, bool done);
875 :
876 : // Generate AST node that throws a ReferenceError with the given type.
877 : V8_INLINE Expression* NewThrowReferenceError(
878 : MessageTemplate::Template message, int pos) {
879 : return NewThrowError(Runtime::kNewReferenceError, message,
880 1544 : ast_value_factory()->empty_string(), pos);
881 : }
882 :
883 : // Generate AST node that throws a SyntaxError with the given
884 : // type. The first argument may be null (in the handle sense) in
885 : // which case no arguments are passed to the constructor.
886 : V8_INLINE Expression* NewThrowSyntaxError(MessageTemplate::Template message,
887 : const AstRawString* arg, int pos) {
888 : return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
889 : }
890 :
891 : // Generate AST node that throws a TypeError with the given
892 : // type. Both arguments must be non-null (in the handle sense).
893 : V8_INLINE Expression* NewThrowTypeError(MessageTemplate::Template message,
894 : const AstRawString* arg, int pos) {
895 379838 : return NewThrowError(Runtime::kNewTypeError, message, arg, pos);
896 : }
897 :
898 : // Reporting errors.
899 : V8_INLINE void ReportMessageAt(Scanner::Location source_location,
900 : MessageTemplate::Template message,
901 : const char* arg = NULL,
902 : ParseErrorType error_type = kSyntaxError) {
903 230110 : if (stack_overflow()) {
904 : // Suppress the error message (syntax error or such) in the presence of a
905 : // stack overflow. The isolate allows only one pending exception at at
906 : // time
907 : // and we want to report the stack overflow later.
908 : return;
909 : }
910 : pending_error_handler_.ReportMessageAt(source_location.beg_pos,
911 : source_location.end_pos, message,
912 220183 : arg, error_type);
913 : }
914 :
915 : V8_INLINE void ReportMessageAt(Scanner::Location source_location,
916 : MessageTemplate::Template message,
917 : const AstRawString* arg,
918 : ParseErrorType error_type = kSyntaxError) {
919 118244 : if (stack_overflow()) {
920 : // Suppress the error message (syntax error or such) in the presence of a
921 : // stack overflow. The isolate allows only one pending exception at at
922 : // time
923 : // and we want to report the stack overflow later.
924 : return;
925 : }
926 : pending_error_handler_.ReportMessageAt(source_location.beg_pos,
927 : source_location.end_pos, message,
928 118244 : arg, error_type);
929 : }
930 :
931 : // "null" return type creators.
932 : V8_INLINE static const AstRawString* EmptyIdentifier() { return nullptr; }
933 : V8_INLINE static bool IsEmptyIdentifier(const AstRawString* name) {
934 : return name == nullptr;
935 : }
936 : V8_INLINE static Expression* EmptyExpression() { return nullptr; }
937 : V8_INLINE static Literal* EmptyLiteral() { return nullptr; }
938 : V8_INLINE static ObjectLiteralProperty* EmptyObjectLiteralProperty() {
939 : return nullptr;
940 : }
941 : V8_INLINE static ClassLiteralProperty* EmptyClassLiteralProperty() {
942 : return nullptr;
943 : }
944 : V8_INLINE static FunctionLiteral* EmptyFunctionLiteral() { return nullptr; }
945 : V8_INLINE static Block* NullBlock() { return nullptr; }
946 :
947 : V8_INLINE static bool IsEmptyExpression(Expression* expr) {
948 : return expr == nullptr;
949 : }
950 :
951 : // Used in error return values.
952 : V8_INLINE static ZoneList<Expression*>* NullExpressionList() {
953 : return nullptr;
954 : }
955 : V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) {
956 : return exprs == nullptr;
957 : }
958 : V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; }
959 : V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) {
960 : return stmts == nullptr;
961 : }
962 : V8_INLINE static Statement* NullStatement() { return nullptr; }
963 : V8_INLINE bool IsNullStatement(Statement* stmt) { return stmt == nullptr; }
964 : V8_INLINE bool IsEmptyStatement(Statement* stmt) {
965 : DCHECK_NOT_NULL(stmt);
966 44804040 : return stmt->IsEmpty();
967 : }
968 :
969 : // Non-NULL empty string.
970 : V8_INLINE const AstRawString* EmptyIdentifierString() const {
971 652117 : return ast_value_factory()->empty_string();
972 : }
973 :
974 : // Odd-ball literal creators.
975 : V8_INLINE Literal* GetLiteralTheHole(int position) {
976 1437236 : return factory()->NewTheHoleLiteral(kNoSourcePosition);
977 : }
978 :
979 : // Producing data during the recursive descent.
980 : V8_INLINE const AstRawString* GetSymbol() const {
981 120523093 : const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory());
982 : DCHECK(result != NULL);
983 : return result;
984 : }
985 :
986 : V8_INLINE const AstRawString* GetNextSymbol() const {
987 98348 : return scanner()->NextSymbol(ast_value_factory());
988 : }
989 :
990 : V8_INLINE const AstRawString* GetNumberAsSymbol() const {
991 817419 : double double_value = scanner()->DoubleValue();
992 : char array[100];
993 817419 : const char* string = DoubleToCString(double_value, ArrayVector(array));
994 817419 : return ast_value_factory()->GetOneByteString(string);
995 : }
996 :
997 : V8_INLINE Expression* ThisExpression(int pos = kNoSourcePosition) {
998 : return NewUnresolved(ast_value_factory()->this_string(), pos,
999 5832676 : THIS_VARIABLE);
1000 : }
1001 :
1002 : Expression* NewSuperPropertyReference(int pos);
1003 : Expression* NewSuperCallReference(int pos);
1004 : Expression* NewTargetExpression(int pos);
1005 : Expression* FunctionSentExpression(int pos);
1006 :
1007 : Literal* ExpressionFromLiteral(Token::Value token, int pos);
1008 :
1009 : V8_INLINE Expression* ExpressionFromIdentifier(
1010 : const AstRawString* name, int start_position,
1011 : InferName infer = InferName::kYes) {
1012 : if (infer == InferName::kYes) {
1013 80853505 : fni_->PushVariableName(name);
1014 : }
1015 80853673 : return NewUnresolved(name, start_position);
1016 : }
1017 :
1018 : V8_INLINE Expression* ExpressionFromString(int pos) {
1019 : const AstRawString* symbol = GetSymbol();
1020 9798761 : fni_->PushLiteralName(symbol);
1021 9798762 : return factory()->NewStringLiteral(symbol, pos);
1022 : }
1023 :
1024 : V8_INLINE ZoneList<Expression*>* NewExpressionList(int size) const {
1025 15536651 : return new (zone()) ZoneList<Expression*>(size, zone());
1026 : }
1027 : V8_INLINE ZoneList<ObjectLiteral::Property*>* NewObjectPropertyList(
1028 : int size) const {
1029 1619654 : return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone());
1030 : }
1031 : V8_INLINE ZoneList<ClassLiteral::Property*>* NewClassPropertyList(
1032 : int size) const {
1033 105813 : return new (zone()) ZoneList<ClassLiteral::Property*>(size, zone());
1034 : }
1035 : V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const {
1036 1156594 : return new (zone()) ZoneList<Statement*>(size, zone());
1037 : }
1038 : V8_INLINE ZoneList<CaseClause*>* NewCaseClauseList(int size) const {
1039 89755 : return new (zone()) ZoneList<CaseClause*>(size, zone());
1040 : }
1041 :
1042 : V8_INLINE Expression* NewV8Intrinsic(const AstRawString* name,
1043 : ZoneList<Expression*>* args, int pos,
1044 : bool* ok);
1045 :
1046 : V8_INLINE Statement* NewThrowStatement(Expression* exception, int pos) {
1047 : return factory()->NewExpressionStatement(
1048 378107 : factory()->NewThrow(exception, pos), pos);
1049 : }
1050 :
1051 : V8_INLINE void AddParameterInitializationBlock(
1052 : const ParserFormalParameters& parameters, ZoneList<Statement*>* body,
1053 : bool is_async, bool* ok) {
1054 474921 : if (parameters.is_simple) return;
1055 1846 : auto* init_block = BuildParameterInitializationBlock(parameters, ok);
1056 1846 : if (!*ok) return;
1057 1756 : if (is_async) {
1058 168 : init_block = BuildRejectPromiseOnException(init_block);
1059 : }
1060 1756 : if (init_block != nullptr) body->Add(init_block, zone());
1061 : }
1062 :
1063 : V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
1064 : Expression* pattern,
1065 : Expression* initializer,
1066 : int initializer_end_position,
1067 : bool is_rest) {
1068 9965354 : parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest);
1069 10287275 : bool has_simple_name = pattern->IsVariableProxy() && initializer == nullptr;
1070 : const AstRawString* name = has_simple_name
1071 : ? pattern->AsVariableProxy()->raw_name()
1072 19876357 : : ast_value_factory()->empty_string();
1073 9965353 : auto parameter = new (parameters->scope->zone())
1074 : ParserFormalParameters::Parameter(name, pattern, initializer,
1075 9965353 : scanner()->location().beg_pos,
1076 19930706 : initializer_end_position, is_rest);
1077 :
1078 9965353 : parameters->params.Add(parameter);
1079 : }
1080 :
1081 : V8_INLINE void DeclareFormalParameters(
1082 : DeclarationScope* scope,
1083 : const ThreadedList<ParserFormalParameters::Parameter>& parameters) {
1084 15553569 : bool is_simple = classifier()->is_simple_parameter_list();
1085 6464432 : if (!is_simple) scope->SetHasNonSimpleParameters();
1086 15437177 : for (auto parameter : parameters) {
1087 8972744 : bool is_duplicate = false;
1088 8972744 : bool is_optional = parameter->initializer != nullptr;
1089 : // If the parameter list is simple, declare the parameters normally with
1090 : // their names. If the parameter list is not simple, declare a temporary
1091 : // for each parameter - the corresponding named variable is declared by
1092 : // BuildParamerterInitializationBlock.
1093 : scope->DeclareParameter(
1094 106738 : is_simple ? parameter->name : ast_value_factory()->empty_string(),
1095 : is_simple ? VAR : TEMPORARY, is_optional, parameter->is_rest,
1096 18052226 : &is_duplicate, ast_value_factory(), parameter->position);
1097 8982254 : if (is_duplicate &&
1098 : classifier()->is_valid_formal_parameter_list_without_duplicates()) {
1099 : classifier()->RecordDuplicateFormalParameterError(
1100 146 : scanner()->location());
1101 : }
1102 : }
1103 : }
1104 :
1105 : void DeclareArrowFunctionFormalParameters(ParserFormalParameters* parameters,
1106 : Expression* params,
1107 : const Scanner::Location& params_loc,
1108 : Scanner::Location* duplicate_loc,
1109 : bool* ok);
1110 :
1111 : V8_INLINE Expression* NoTemplateTag() { return NULL; }
1112 : V8_INLINE static bool IsTaggedTemplate(const Expression* tag) {
1113 : return tag != NULL;
1114 : }
1115 :
1116 : Expression* ExpressionListToExpression(ZoneList<Expression*>* args);
1117 :
1118 : void AddAccessorPrefixToFunctionName(bool is_get, FunctionLiteral* function,
1119 : const AstRawString* name);
1120 :
1121 : void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
1122 : const AstRawString* name);
1123 :
1124 : void SetFunctionNameFromIdentifierRef(Expression* value,
1125 : Expression* identifier);
1126 :
1127 : V8_INLINE ZoneList<typename ExpressionClassifier::Error>*
1128 : GetReportedErrorList() const {
1129 230899984 : return function_state_->GetReportedErrorList();
1130 : }
1131 :
1132 : V8_INLINE ZoneList<Expression*>* GetNonPatternList() const {
1133 230899875 : return function_state_->non_patterns_to_rewrite();
1134 : }
1135 :
1136 : V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) {
1137 1544 : ++use_counts_[feature];
1138 : }
1139 :
1140 : // Returns true iff we're parsing the first function literal during
1141 : // CreateDynamicFunction().
1142 : V8_INLINE bool ParsingDynamicFunctionDeclaration() const {
1143 : return parameters_end_pos_ != kNoSourcePosition;
1144 : }
1145 :
1146 : // Parser's private field members.
1147 : friend class DiscardableZoneScope; // Uses reusable_preparser_.
1148 : // FIXME(marja): Make reusable_preparser_ always use its own temp Zone (call
1149 : // DeleteAll after each function), so this won't be needed.
1150 :
1151 : Scanner scanner_;
1152 : PreParser* reusable_preparser_;
1153 : Mode mode_;
1154 :
1155 : friend class ParserTarget;
1156 : friend class ParserTargetScope;
1157 : ParserTarget* target_stack_; // for break, continue statements
1158 :
1159 : ScriptCompiler::CompileOptions compile_options_;
1160 : ParseData* cached_parse_data_;
1161 :
1162 : PendingCompilationErrorHandler pending_error_handler_;
1163 :
1164 : // Other information which will be stored in Parser and moved to Isolate after
1165 : // parsing.
1166 : int use_counts_[v8::Isolate::kUseCounterFeatureCount];
1167 : int total_preparse_skipped_;
1168 : bool allow_lazy_;
1169 : bool temp_zoned_;
1170 : ParserLogger* log_;
1171 :
1172 : // If not kNoSourcePosition, indicates that the first function literal
1173 : // encountered is a dynamic function, see CreateDynamicFunction(). This field
1174 : // indicates the correct position of the ')' that closes the parameter list.
1175 : // After that ')' is encountered, this field is reset to kNoSourcePosition.
1176 : int parameters_end_pos_;
1177 : };
1178 :
1179 : // ----------------------------------------------------------------------------
1180 : // Target is a support class to facilitate manipulation of the
1181 : // Parser's target_stack_ (the stack of potential 'break' and
1182 : // 'continue' statement targets). Upon construction, a new target is
1183 : // added; it is removed upon destruction.
1184 :
1185 : class ParserTarget BASE_EMBEDDED {
1186 : public:
1187 : ParserTarget(ParserBase<Parser>* parser, BreakableStatement* statement)
1188 : : variable_(&parser->impl()->target_stack_),
1189 : statement_(statement),
1190 7028297 : previous_(parser->impl()->target_stack_) {
1191 7028297 : parser->impl()->target_stack_ = this;
1192 : }
1193 :
1194 7028306 : ~ParserTarget() { *variable_ = previous_; }
1195 :
1196 : ParserTarget* previous() { return previous_; }
1197 : BreakableStatement* statement() { return statement_; }
1198 :
1199 : private:
1200 : ParserTarget** variable_;
1201 : BreakableStatement* statement_;
1202 : ParserTarget* previous_;
1203 : };
1204 :
1205 : class ParserTargetScope BASE_EMBEDDED {
1206 : public:
1207 : explicit ParserTargetScope(ParserBase<Parser>* parser)
1208 : : variable_(&parser->impl()->target_stack_),
1209 8527085 : previous_(parser->impl()->target_stack_) {
1210 8527085 : parser->impl()->target_stack_ = nullptr;
1211 : }
1212 :
1213 8527130 : ~ParserTargetScope() { *variable_ = previous_; }
1214 :
1215 : private:
1216 : ParserTarget** variable_;
1217 : ParserTarget* previous_;
1218 : };
1219 :
1220 : } // namespace internal
1221 : } // namespace v8
1222 :
1223 : #endif // V8_PARSING_PARSER_H_
|