文档介绍:: .
JSJSJS e.
source->TryFlatten();
// Scanner scanner_初始化
(source, JAVASCRIPT);
// Compute the parsing mode.
mode_ = FLAG_lazy ? PARSE_LAZILY: PARSE_EAGERLY;if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
Scope::Type type =
in_global_context
? Scope::GLOBAL_SCOPE
: Scope::EVAL_SCOPE;
Handle<String> no_name = factory()->EmptySymbol();
FunctionLiteral* result = NULL;
//这里 top_scope_还为 NULL
{
//生成一个新的 class Scope 其 parent 为 NULL
Scope* scope = factory()->NewScope(top_scope_, type, inside_with());
// LexicalScope 的构造函数里将 class parser 的 top_scope_指针指向刚生成 scope
LexicalScope lexical_scope(this, scope);
TemporaryScope temp_scope(this);
ZoneListWrapper<Statement> body(16);
bool ok = true;
//对于最上层 top scope,其结束标志是 Token::EOS
ParseSourceElements(&body, Token::EOS, &ok);
if (ok) {
result = NEW(FunctionLiteral(
no_name,
top_scope_,
(),
(),
(),
(),
(),
0,
0,
source->length(),
false));
} else if (scanner().stack_overflow()) {
Top::StackOverflow();
}
}
if (result == NULL) ();
return result;
}//对于一个 js 函数的分析
FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
int function_token_position,
FunctionLiteralType type,
bool* ok) {
seen_loop_stmt_ = false;
bool is_named = !();
Handle<String> name = is_named ? var_na