1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "allocation.h"
33 #include "preparse-data-format.h"
34 #include "preparse-data.h"
36 #include "preparser.h"
41 class CompilationInfo;
42 class FuncNameInferrer;
47 template <typename T> class ZoneListWrapper;
50 class FunctionEntry BASE_EMBEDDED {
61 explicit FunctionEntry(Vector<unsigned> backing)
62 : backing_(backing) { }
64 FunctionEntry() : backing_() { }
66 int start_pos() { return backing_[kStartPositionIndex]; }
67 int end_pos() { return backing_[kEndPositionIndex]; }
68 int literal_count() { return backing_[kLiteralCountIndex]; }
69 int property_count() { return backing_[kPropertyCountIndex]; }
70 LanguageMode language_mode() {
71 ASSERT(backing_[kLanguageModeIndex] == CLASSIC_MODE ||
72 backing_[kLanguageModeIndex] == STRICT_MODE ||
73 backing_[kLanguageModeIndex] == EXTENDED_MODE);
74 return static_cast<LanguageMode>(backing_[kLanguageModeIndex]);
77 bool is_valid() { return !backing_.is_empty(); }
80 Vector<unsigned> backing_;
84 class ScriptDataImpl : public ScriptData {
86 explicit ScriptDataImpl(Vector<unsigned> store)
90 // Create an empty ScriptDataImpl that is guaranteed to not satisfy
92 ScriptDataImpl() : owns_store_(false) { }
94 virtual ~ScriptDataImpl();
96 virtual const char* Data();
97 virtual bool HasError();
100 void ReadNextSymbolPosition();
102 FunctionEntry GetFunctionEntry(int start);
103 int GetSymbolIdentifier();
106 Scanner::Location MessageLocation();
107 const char* BuildMessage();
108 Vector<const char*> BuildArgs();
111 return (store_.length() > PreparseDataConstants::kHeaderSize)
112 ? store_[PreparseDataConstants::kSymbolCountOffset]
115 // The following functions should only be called if SanityCheck has
117 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; }
118 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; }
119 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; }
122 Vector<unsigned> store_;
123 unsigned char* symbol_data_;
124 unsigned char* symbol_data_end_;
128 unsigned Read(int position);
129 unsigned* ReadAddress(int position);
130 // Reads a number from the current symbols
131 int ReadNumber(byte** source);
133 ScriptDataImpl(const char* backing_store, int length)
134 : store_(reinterpret_cast<unsigned*>(const_cast<char*>(backing_store)),
135 length / static_cast<int>(sizeof(unsigned))),
137 ASSERT_EQ(0, static_cast<int>(
138 reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned)));
141 // Read strings written by ParserRecorder::WriteString.
142 static const char* ReadString(unsigned* start, int* chars);
144 friend class ScriptData;
150 // Pre-parse a character stream and return full preparse data.
152 // This interface is here instead of in preparser.h because it instantiates a
153 // preparser recorder object that is suited to the parser's purposes. Also,
154 // the preparser doesn't know about ScriptDataImpl.
155 static ScriptDataImpl* PreParse(Isolate* isolate,
156 Utf16CharacterStream* source);
160 // ----------------------------------------------------------------------------
163 // A BufferedZoneList is an automatically growing list, just like (and backed
164 // by) a ZoneList, that is optimized for the case of adding and removing
165 // a single element. The last element added is stored outside the backing list,
166 // and if no more than one element is ever added, the ZoneList isn't even
168 // Elements must not be NULL pointers.
169 template <typename T, int initial_size>
170 class BufferedZoneList {
172 BufferedZoneList() : list_(NULL), last_(NULL) {}
174 // Adds element at end of list. This element is buffered and can
175 // be read using last() or removed using RemoveLast until a new Add or until
176 // RemoveLast or GetList has been called.
177 void Add(T* value, Zone* zone) {
180 list_ = new(zone) ZoneList<T*>(initial_size, zone);
182 list_->Add(last_, zone);
188 ASSERT(last_ != NULL);
193 ASSERT(last_ != NULL);
195 if ((list_ != NULL) && (list_->length() > 0))
196 last_ = list_->RemoveLast();
203 ASSERT((0 <= i) && (i < length()));
208 if (i == list_->length()) {
209 ASSERT(last_ != NULL);
223 int length = (list_ == NULL) ? 0 : list_->length();
224 return length + ((last_ == NULL) ? 0 : 1);
227 ZoneList<T*>* GetList(Zone* zone) {
229 list_ = new(zone) ZoneList<T*>(initial_size, zone);
232 list_->Add(last_, zone);
244 // Accumulates RegExp atoms and assertions into lists of terms and alternatives.
245 class RegExpBuilder: public ZoneObject {
247 explicit RegExpBuilder(Zone* zone);
248 void AddCharacter(uc16 character);
249 // "Adds" an empty expression. Does nothing except consume a
250 // following quantifier
252 void AddAtom(RegExpTree* tree);
253 void AddAssertion(RegExpTree* tree);
254 void NewAlternative(); // '|'
255 void AddQuantifierToAtom(
256 int min, int max, RegExpQuantifier::QuantifierType type);
257 RegExpTree* ToRegExp();
260 void FlushCharacters();
263 Zone* zone() const { return zone_; }
267 ZoneList<uc16>* characters_;
268 BufferedZoneList<RegExpTree, 2> terms_;
269 BufferedZoneList<RegExpTree, 2> text_;
270 BufferedZoneList<RegExpTree, 2> alternatives_;
272 enum {ADD_NONE, ADD_CHAR, ADD_TERM, ADD_ASSERT, ADD_ATOM} last_added_;
273 #define LAST(x) last_added_ = x;
280 class RegExpParser BASE_EMBEDDED {
282 RegExpParser(FlatStringReader* in,
283 Handle<String>* error,
287 static bool ParseRegExp(FlatStringReader* input,
289 RegExpCompileData* result,
292 RegExpTree* ParsePattern();
293 RegExpTree* ParseDisjunction();
294 RegExpTree* ParseGroup();
295 RegExpTree* ParseCharacterClass();
297 // Parses a {...,...} quantifier and stores the range in the given
299 bool ParseIntervalQuantifier(int* min_out, int* max_out);
301 // Parses and returns a single escaped character. The character
302 // must not be 'b' or 'B' since they are usually handle specially.
303 uc32 ParseClassCharacterEscape();
305 // Checks whether the following is a length-digit hexadecimal number,
306 // and sets the value if it is.
307 bool ParseHexEscape(int length, uc32* value);
309 uc32 ParseOctalLiteral();
311 // Tries to parse the input as a back reference. If successful it
312 // stores the result in the output parameter and returns true. If
313 // it fails it will push back the characters read so the same characters
315 bool ParseBackReferenceIndex(int* index_out);
317 CharacterRange ParseClassAtom(uc16* char_class);
318 RegExpTree* ReportError(Vector<const char> message);
320 void Advance(int dist);
323 // Reports whether the pattern might be used as a literal search string.
324 // Only use if the result of the parse is a single atom node.
326 bool contains_anchor() { return contains_anchor_; }
327 void set_contains_anchor() { contains_anchor_ = true; }
328 int captures_started() { return captures_ == NULL ? 0 : captures_->length(); }
329 int position() { return next_pos_ - 1; }
330 bool failed() { return failed_; }
332 static const int kMaxCaptures = 1 << 16;
333 static const uc32 kEndMarker = (1 << 21);
336 enum SubexpressionType {
338 CAPTURE, // All positive values represent captures.
344 class RegExpParserState : public ZoneObject {
346 RegExpParserState(RegExpParserState* previous_state,
347 SubexpressionType group_type,
348 int disjunction_capture_index,
350 : previous_state_(previous_state),
351 builder_(new(zone) RegExpBuilder(zone)),
352 group_type_(group_type),
353 disjunction_capture_index_(disjunction_capture_index) {}
354 // Parser state of containing expression, if any.
355 RegExpParserState* previous_state() { return previous_state_; }
356 bool IsSubexpression() { return previous_state_ != NULL; }
357 // RegExpBuilder building this regexp's AST.
358 RegExpBuilder* builder() { return builder_; }
359 // Type of regexp being parsed (parenthesized group or entire regexp).
360 SubexpressionType group_type() { return group_type_; }
361 // Index in captures array of first capture in this sub-expression, if any.
362 // Also the capture index of this sub-expression itself, if group_type
364 int capture_index() { return disjunction_capture_index_; }
367 // Linked list implementation of stack of states.
368 RegExpParserState* previous_state_;
369 // Builder for the stored disjunction.
370 RegExpBuilder* builder_;
371 // Stored disjunction type (capture, look-ahead or grouping), if any.
372 SubexpressionType group_type_;
373 // Stored disjunction's capture index (if any).
374 int disjunction_capture_index_;
377 Isolate* isolate() { return isolate_; }
378 Zone* zone() const { return zone_; }
380 uc32 current() { return current_; }
381 bool has_more() { return has_more_; }
382 bool has_next() { return next_pos_ < in()->length(); }
384 FlatStringReader* in() { return in_; }
385 void ScanForCaptures();
389 Handle<String>* error_;
390 ZoneList<RegExpCapture*>* captures_;
391 FlatStringReader* in_;
394 // The capture count is only valid after we have scanned for captures.
399 bool contains_anchor_;
400 bool is_scanned_for_captures_;
404 // ----------------------------------------------------------------------------
405 // JAVASCRIPT PARSING
407 // Forward declaration.
408 class SingletonLogger;
410 class Parser : public ParserBase {
412 explicit Parser(CompilationInfo* info);
414 delete reusable_preparser_;
415 reusable_preparser_ = NULL;
418 // Parses the source code represented by the compilation info and sets its
419 // function literal. Returns false (and deallocates any allocated AST
420 // nodes) if parsing failed.
421 static bool Parse(CompilationInfo* info,
422 bool allow_lazy = false) {
424 parser.set_allow_lazy(allow_lazy);
425 return parser.Parse();
430 static const int kMaxNumFunctionLocals = 131071; // 2^17-1
437 enum VariableDeclarationContext {
444 // If a list of variable declarations includes any initializers.
445 enum VariableDeclarationProperties {
452 class FunctionState BASE_EMBEDDED {
454 FunctionState(Parser* parser, Scope* scope);
457 int NextMaterializedLiteralIndex() {
458 return next_materialized_literal_index_++;
460 int materialized_literal_count() {
461 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize;
464 int NextHandlerIndex() { return next_handler_index_++; }
465 int handler_count() { return next_handler_index_; }
467 void AddProperty() { expected_property_count_++; }
468 int expected_property_count() { return expected_property_count_; }
470 void set_generator_object_variable(Variable *variable) {
471 ASSERT(variable != NULL);
472 ASSERT(!is_generator());
473 generator_object_variable_ = variable;
475 Variable* generator_object_variable() const {
476 return generator_object_variable_;
478 bool is_generator() const {
479 return generator_object_variable_ != NULL;
482 AstNodeFactory<AstConstructionVisitor>* factory() { return &factory_; }
485 // Used to assign an index to each literal that needs materialization in
486 // the function. Includes regexp literals, and boilerplate for object and
488 int next_materialized_literal_index_;
490 // Used to assign a per-function index to try and catch handlers.
491 int next_handler_index_;
493 // Properties count estimation.
494 int expected_property_count_;
496 // For generators, the variable that holds the generator object. This
497 // variable is used by yield expressions and return statements. NULL
498 // indicates that this function is not a generator.
499 Variable* generator_object_variable_;
502 FunctionState* outer_function_state_;
504 int saved_ast_node_id_;
505 AstNodeFactory<AstConstructionVisitor> factory_;
508 class ParsingModeScope BASE_EMBEDDED {
510 ParsingModeScope(Parser* parser, Mode mode)
512 old_mode_(parser->mode()) {
513 parser_->mode_ = mode;
515 ~ParsingModeScope() {
516 parser_->mode_ = old_mode_;
524 virtual bool is_classic_mode() {
525 return top_scope_->is_classic_mode();
528 // Returns NULL if parsing failed.
529 FunctionLiteral* ParseProgram();
531 FunctionLiteral* ParseLazy();
532 FunctionLiteral* ParseLazy(Utf16CharacterStream* source);
534 Isolate* isolate() { return isolate_; }
535 Zone* zone() const { return zone_; }
536 CompilationInfo* info() const { return info_; }
538 // Called by ParseProgram after setting up the scanner.
539 FunctionLiteral* DoParseProgram(CompilationInfo* info,
540 Handle<String> source);
542 // Report syntax error
543 void ReportInvalidPreparseData(Handle<String> name, bool* ok);
544 void ReportMessage(const char* message, Vector<const char*> args);
545 void ReportMessage(const char* message, Vector<Handle<String> > args);
546 void ReportMessageAt(Scanner::Location location, const char* type) {
547 ReportMessageAt(location, type, Vector<const char*>::empty());
549 void ReportMessageAt(Scanner::Location loc,
551 Vector<const char*> args);
552 void ReportMessageAt(Scanner::Location loc,
554 Vector<Handle<String> > args);
556 void set_pre_parse_data(ScriptDataImpl *data) {
557 pre_parse_data_ = data;
558 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone());
561 bool inside_with() const { return top_scope_->inside_with(); }
562 Scanner& scanner() { return scanner_; }
563 Mode mode() const { return mode_; }
564 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
565 bool is_extended_mode() {
566 ASSERT(top_scope_ != NULL);
567 return top_scope_->is_extended_mode();
569 Scope* DeclarationScope(VariableMode mode) {
570 return IsLexicalVariableMode(mode)
571 ? top_scope_ : top_scope_->DeclarationScope();
574 // Check if the given string is 'eval' or 'arguments'.
575 bool IsEvalOrArguments(Handle<String> string);
577 // All ParseXXX functions take as the last argument an *ok parameter
578 // which is set to false if parsing failed; it is unchanged otherwise.
579 // By making the 'exception handling' explicit, we are forced to check
580 // for failure at the call sites.
581 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token,
582 bool is_eval, bool is_global, bool* ok);
583 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok);
584 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok);
585 Module* ParseModule(bool* ok);
586 Module* ParseModuleLiteral(bool* ok);
587 Module* ParseModulePath(bool* ok);
588 Module* ParseModuleVariable(bool* ok);
589 Module* ParseModuleUrl(bool* ok);
590 Module* ParseModuleSpecifier(bool* ok);
591 Block* ParseImportDeclaration(bool* ok);
592 Statement* ParseExportDeclaration(bool* ok);
593 Statement* ParseBlockElement(ZoneStringList* labels, bool* ok);
594 Statement* ParseStatement(ZoneStringList* labels, bool* ok);
595 Statement* ParseFunctionDeclaration(ZoneStringList* names, bool* ok);
596 Statement* ParseNativeDeclaration(bool* ok);
597 Block* ParseBlock(ZoneStringList* labels, bool* ok);
598 Block* ParseVariableStatement(VariableDeclarationContext var_context,
599 ZoneStringList* names,
601 Block* ParseVariableDeclarations(VariableDeclarationContext var_context,
602 VariableDeclarationProperties* decl_props,
603 ZoneStringList* names,
606 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels,
608 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok);
609 Statement* ParseContinueStatement(bool* ok);
610 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok);
611 Statement* ParseReturnStatement(bool* ok);
612 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok);
613 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok);
614 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok);
615 DoWhileStatement* ParseDoWhileStatement(ZoneStringList* labels, bool* ok);
616 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok);
617 Statement* ParseForStatement(ZoneStringList* labels, bool* ok);
618 Statement* ParseThrowStatement(bool* ok);
619 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value);
620 TryStatement* ParseTryStatement(bool* ok);
621 DebuggerStatement* ParseDebuggerStatement(bool* ok);
623 // Support for hamony block scoped bindings.
624 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);
626 Expression* ParseExpression(bool accept_IN, bool* ok);
627 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok);
628 Expression* ParseYieldExpression(bool* ok);
629 Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
630 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
631 Expression* ParseUnaryExpression(bool* ok);
632 Expression* ParsePostfixExpression(bool* ok);
633 Expression* ParseLeftHandSideExpression(bool* ok);
634 Expression* ParseNewExpression(bool* ok);
635 Expression* ParseMemberExpression(bool* ok);
636 Expression* ParseNewPrefix(PositionStack* stack, bool* ok);
637 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack,
639 Expression* ParsePrimaryExpression(bool* ok);
640 Expression* ParseArrayLiteral(bool* ok);
641 Expression* ParseObjectLiteral(bool* ok);
642 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok);
644 // Initialize the components of a for-in / for-of statement.
645 void InitializeForEachStatement(ForEachStatement* stmt,
650 ZoneList<Expression*>* ParseArguments(bool* ok);
651 FunctionLiteral* ParseFunctionLiteral(
653 Scanner::Location function_name_location,
654 bool name_is_strict_reserved,
656 int function_token_position,
657 FunctionLiteral::FunctionType type,
660 // Magical syntax support.
661 Expression* ParseV8Intrinsic(bool* ok);
663 bool is_generator() const { return current_function_state_->is_generator(); }
665 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
667 Handle<String> LiteralString(PretenureFlag tenured) {
668 if (scanner().is_literal_ascii()) {
669 return isolate_->factory()->NewStringFromAscii(
670 scanner().literal_ascii_string(), tenured);
672 return isolate_->factory()->NewStringFromTwoByte(
673 scanner().literal_utf16_string(), tenured);
677 Handle<String> NextLiteralString(PretenureFlag tenured) {
678 if (scanner().is_next_literal_ascii()) {
679 return isolate_->factory()->NewStringFromAscii(
680 scanner().next_literal_ascii_string(), tenured);
682 return isolate_->factory()->NewStringFromTwoByte(
683 scanner().next_literal_utf16_string(), tenured);
687 Handle<String> GetSymbol();
689 // Get odd-ball literals.
690 Literal* GetLiteralUndefined(int position);
691 Literal* GetLiteralTheHole(int position);
693 Handle<String> ParseIdentifier(AllowEvalOrArgumentsAsIdentifier, bool* ok);
694 Handle<String> ParseIdentifierOrStrictReservedWord(
695 bool* is_strict_reserved, bool* ok);
696 Handle<String> ParseIdentifierName(bool* ok);
697 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get,
701 // Determine if the expression is a variable proxy and mark it as being used
702 // in an assignment or with a increment/decrement operator. This is currently
703 // used on for the statically checking assignments to harmony const bindings.
704 void MarkAsLValue(Expression* expression);
706 // Strict mode validation of LValue expressions
707 void CheckStrictModeLValue(Expression* expression,
710 // For harmony block scoping mode: Check if the scope has conflicting var/let
711 // declarations from different scopes. It covers for example
713 // function f() { { { var x; } let x; } }
714 // function g() { { var x; let x; } }
716 // The var declarations are hoisted to the function scope, but originate from
717 // a scope where the name has also been let bound or the var declaration is
718 // hoisted over such a scope.
719 void CheckConflictingVarDeclarations(Scope* scope, bool* ok);
722 VariableProxy* NewUnresolved(Handle<String> name,
724 Interface* interface);
725 void Declare(Declaration* declaration, bool resolve, bool* ok);
727 bool TargetStackContainsLabel(Handle<String> label);
728 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok);
729 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok);
731 void RegisterTargetUse(Label* target, Target* stop);
735 Scope* NewScope(Scope* parent, ScopeType type);
737 Handle<String> LookupSymbol(int symbol_id);
739 Handle<String> LookupCachedSymbol(int symbol_id);
741 // Generate AST node that throw a ReferenceError with the given type.
742 Expression* NewThrowReferenceError(Handle<String> type);
744 // Generate AST node that throw a SyntaxError with the given
745 // type. The first argument may be null (in the handle sense) in
746 // which case no arguments are passed to the constructor.
747 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first);
749 // Generate AST node that throw a TypeError with the given
750 // type. Both arguments must be non-null (in the handle sense).
751 Expression* NewThrowTypeError(Handle<String> type,
752 Handle<Object> first,
753 Handle<Object> second);
755 // Generic AST generator for throwing errors from compiled code.
756 Expression* NewThrowError(Handle<String> constructor,
758 Vector< Handle<Object> > arguments);
760 PreParser::PreParseResult LazyParseFunctionLiteral(
761 SingletonLogger* logger);
763 AstNodeFactory<AstConstructionVisitor>* factory() {
764 return current_function_state_->factory();
768 ZoneList<Handle<String> > symbol_cache_;
770 Handle<Script> script_;
772 PreParser* reusable_preparser_;
774 Scope* original_scope_; // for ES5 function declarations in sloppy eval
775 FunctionState* current_function_state_;
776 Target* target_stack_; // for break, continue statements
777 v8::Extension* extension_;
778 ScriptDataImpl* pre_parse_data_;
779 FuncNameInferrer* fni_;
782 // If true, the next (and immediately following) function literal is
783 // preceded by a parenthesis.
784 // Heuristically that means that the function will be called immediately,
785 // so never lazily compile it.
786 bool parenthesized_function_;
789 CompilationInfo* info_;
790 friend class BlockState;
791 friend class FunctionState;
795 // Support for handling complex values (array and object literals) that
796 // can be fully handled at compile time.
797 class CompileTimeValue: public AllStatic {
800 OBJECT_LITERAL_FAST_ELEMENTS,
801 OBJECT_LITERAL_SLOW_ELEMENTS,
805 static bool IsCompileTimeValue(Expression* expression);
807 // Get the value as a compile time value.
808 static Handle<FixedArray> GetValue(Isolate* isolate, Expression* expression);
810 // Get the type of a compile time value returned by GetValue().
811 static LiteralType GetLiteralType(Handle<FixedArray> value);
813 // Get the elements array of a compile time value returned by GetValue().
814 static Handle<FixedArray> GetElements(Handle<FixedArray> value);
817 static const int kLiteralTypeSlot = 0;
818 static const int kElementsSlot = 1;
820 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
823 } } // namespace v8::internal
825 #endif // V8_PARSER_H_