typedef Variable GeneratorVariable;
typedef v8::internal::Zone Zone;
- class Checkpoint BASE_EMBEDDED {
- public:
- template <typename Parser>
- explicit Checkpoint(Parser* parser) {
- isolate_ = parser->zone()->isolate();
- saved_ast_node_id_ = isolate_->ast_node_id();
- }
-
- void Restore() { isolate_->set_ast_node_id(saved_ast_node_id_); }
-
- private:
- Isolate* isolate_;
- int saved_ast_node_id_;
- };
-
typedef v8::internal::AstProperties AstProperties;
typedef Vector<VariableProxy*> ParameterIdentifierVector;
typedef v8::internal::Expression* Expression;
typedef Yield* YieldExpression;
typedef v8::internal::FunctionLiteral* FunctionLiteral;
+ typedef v8::internal::ClassLiteral* ClassLiteral;
typedef v8::internal::Literal* Literal;
typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef AstNodeFactory<AstConstructionVisitor> Factory;
};
+ class Checkpoint;
+
explicit ParserTraits(Parser* parser) : parser_(parser) {}
// Custom operations executed when FunctionStates are created and destructed.
- template<typename FunctionState>
- static void SetUpFunctionState(FunctionState* function_state, Zone* zone) {
- Isolate* isolate = zone->isolate();
- function_state->saved_ast_node_id_ = isolate->ast_node_id();
- isolate->set_ast_node_id(BailoutId::FirstUsable().ToInt());
+ template <typename FunctionState>
+ static void SetUpFunctionState(FunctionState* function_state) {
+ function_state->saved_id_gen_ = *function_state->ast_node_id_gen_;
+ *function_state->ast_node_id_gen_ =
+ AstNode::IdGen(BailoutId::FirstUsable().ToInt());
}
- template<typename FunctionState>
- static void TearDownFunctionState(FunctionState* function_state, Zone* zone) {
+ template <typename FunctionState>
+ static void TearDownFunctionState(FunctionState* function_state) {
if (function_state->outer_function_state_ != NULL) {
- zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_);
+ *function_state->ast_node_id_gen_ = function_state->saved_id_gen_;
}
}
static bool IsIdentifier(Expression* expression);
+ bool IsPrototype(const AstRawString* identifier) const;
+
+ bool IsConstructor(const AstRawString* identifier) const;
+
static const AstRawString* AsIdentifier(Expression* expression) {
DCHECK(IsIdentifier(expression));
return expression->AsVariableProxy()->raw_name();
}
static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
- Scope* scope, Expression* value, bool* has_function) {
+ Scope* scope, ObjectLiteralProperty* property, bool* has_function) {
+ Expression* value = property->value();
if (scope->DeclarationScope()->is_global_scope() &&
value->AsFunctionLiteral() != NULL) {
*has_function = true;
static Literal* EmptyLiteral() {
return NULL;
}
+ static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; }
+ static FunctionLiteral* EmptyFunctionLiteral() { return NULL; }
// Used in error return values.
static ZoneList<Expression*>* NullExpressionList() {
// Producing data during the recursive descent.
const AstRawString* GetSymbol(Scanner* scanner);
const AstRawString* GetNextSymbol(Scanner* scanner);
+ const AstRawString* GetNumberAsSymbol(Scanner* scanner);
Expression* ThisExpression(Scope* scope,
AstNodeFactory<AstConstructionVisitor>* factory,
int pos = RelocInfo::kNoPosition);
+ Expression* SuperReference(Scope* scope,
+ AstNodeFactory<AstConstructionVisitor>* factory,
+ int pos = RelocInfo::kNoPosition);
+ Expression* ClassLiteral(const AstRawString* name, Expression* extends,
+ Expression* constructor,
+ ZoneList<ObjectLiteral::Property*>* properties,
+ int pos,
+ AstNodeFactory<AstConstructionVisitor>* factory);
+
Literal* ExpressionFromLiteral(
Token::Value token, int pos, Scanner* scanner,
AstNodeFactory<AstConstructionVisitor>* factory);
// Temporary glue; these functions will move to ParserBase.
Expression* ParseV8Intrinsic(bool* ok);
FunctionLiteral* ParseFunctionLiteral(
- const AstRawString* name,
- Scanner::Location function_name_location,
- bool name_is_strict_reserved,
- bool is_generator,
- int function_token_position,
- FunctionLiteral::FunctionType type,
- FunctionLiteral::ArityRestriction arity_restriction,
- bool* ok);
+ const AstRawString* name, Scanner::Location function_name_location,
+ bool name_is_strict_reserved, FunctionKind kind,
+ int function_token_position, FunctionLiteral::FunctionType type,
+ FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
V8_INLINE void SkipLazyFunctionBody(const AstRawString* name,
int* materialized_literal_count,
int* expected_property_count, bool* ok);
class Parser : public ParserBase<ParserTraits> {
public:
- explicit Parser(CompilationInfo* info);
+ // Note that the hash seed in ParseInfo must be the hash seed from the
+ // Isolate's heap, otherwise the heap will be in an inconsistent state once
+ // the strings created by the Parser are internalized.
+ struct ParseInfo {
+ uintptr_t stack_limit;
+ uint32_t hash_seed;
+ UnicodeCache* unicode_cache;
+ };
+
+ Parser(CompilationInfo* info, ParseInfo* parse_info);
~Parser() {
delete reusable_preparser_;
reusable_preparser_ = NULL;
// nodes) if parsing failed.
static bool Parse(CompilationInfo* info,
bool allow_lazy = false) {
- Parser parser(info);
+ ParseInfo parse_info = {info->isolate()->stack_guard()->real_climit(),
+ info->isolate()->heap()->HashSeed(),
+ info->isolate()->unicode_cache()};
+ Parser parser(info, &parse_info);
parser.set_allow_lazy(allow_lazy);
- return parser.Parse();
+ if (parser.Parse()) {
+ info->SetStrictMode(info->function()->strict_mode());
+ return true;
+ }
+ return false;
}
bool Parse();
+ void ParseOnBackground();
+
+ // Handle errors detected during parsing, move statistics to Isolate,
+ // internalize strings (move them to the heap).
+ void Internalize();
private:
friend class ParserTraits;
FunctionLiteral* ParseLazy();
FunctionLiteral* ParseLazy(Utf16CharacterStream* source);
- Isolate* isolate() { return isolate_; }
+ Isolate* isolate() { return info_->isolate(); }
CompilationInfo* info() const { return info_; }
+ Handle<Script> script() const { return info_->script(); }
+ AstValueFactory* ast_value_factory() const {
+ return info_->ast_value_factory();
+ }
// Called by ParseProgram after setting up the scanner.
- FunctionLiteral* DoParseProgram(CompilationInfo* info,
- Handle<String> source);
+ FunctionLiteral* DoParseProgram(CompilationInfo* info, Scope** scope,
+ Scope** ad_hoc_eval_scope);
void SetCachedData();
// By making the 'exception handling' explicit, we are forced to check
// for failure at the call sites.
void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token,
- bool is_eval, bool is_global, bool* ok);
+ bool is_eval, bool is_global,
+ Scope** ad_hoc_eval_scope, bool* ok);
Statement* ParseModuleElement(ZoneList<const AstRawString*>* labels,
bool* ok);
Statement* ParseModuleDeclaration(ZoneList<const AstRawString*>* names,
Statement* ParseStatement(ZoneList<const AstRawString*>* labels, bool* ok);
Statement* ParseFunctionDeclaration(ZoneList<const AstRawString*>* names,
bool* ok);
+ Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
+ bool* ok);
Statement* ParseNativeDeclaration(bool* ok);
Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok);
Block* ParseVariableStatement(VariableDeclarationContext var_context,
Statement* body, bool* ok);
FunctionLiteral* ParseFunctionLiteral(
- const AstRawString* name,
- Scanner::Location function_name_location,
- bool name_is_strict_reserved,
- bool is_generator,
- int function_token_position,
- FunctionLiteral::FunctionType type,
- FunctionLiteral::ArityRestriction arity_restriction,
- bool* ok);
+ const AstRawString* name, Scanner::Location function_name_location,
+ bool name_is_strict_reserved, FunctionKind kind,
+ int function_token_position, FunctionLiteral::FunctionType type,
+ FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
// Magical syntax support.
Expression* ParseV8Intrinsic(bool* ok);
void ThrowPendingError();
- void InternalizeUseCounts();
-
- Isolate* isolate_;
-
- Handle<Script> script_;
Scanner scanner_;
PreParser* reusable_preparser_;
Scope* original_scope_; // for ES5 function declarations in sloppy eval
Target* target_stack_; // for break, continue statements
ParseData* cached_parse_data_;
- AstValueFactory* ast_value_factory_;
CompilationInfo* info_;
const char* pending_error_char_arg_;
bool pending_error_is_reference_error_;
+ // Other information which will be stored in Parser and moved to Isolate after
+ // parsing.
int use_counts_[v8::Isolate::kUseCounterFeatureCount];
+ int total_preparse_skipped_;
+ HistogramTimer* pre_parse_timer_;
};
const AstRawString* ParserTraits::EmptyIdentifierString() {
- return parser_->ast_value_factory_->empty_string();
+ return parser_->ast_value_factory()->empty_string();
}
AstValueFactory* ParserTraits::ast_value_factory() {
- return parser_->ast_value_factory_;
+ return parser_->ast_value_factory();
}