Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index 42d094938657541fa00a4ae2d14fe31a43e9e456..fd0dd2913eacd62897b64fa7af4b54461a773bdb 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -326,9 +326,7 @@ unsigned* ScriptData::ReadAddress(int position) const { |
Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { |
- ASSERT(ast_value_factory_); |
- Scope* result = |
- new (zone()) Scope(parent, scope_type, ast_value_factory_, zone()); |
+ Scope* result = new(zone()) Scope(parent, scope_type, zone()); |
result->Initialize(); |
return result; |
} |
@@ -401,9 +399,10 @@ class TargetScope BASE_EMBEDDED { |
// ---------------------------------------------------------------------------- |
// Implementation of Parser |
-bool ParserTraits::IsEvalOrArguments(const AstString* identifier) const { |
- return identifier == parser_->ast_value_factory_->eval_string() || |
- identifier == parser_->ast_value_factory_->arguments_string(); |
+bool ParserTraits::IsEvalOrArguments(Handle<String> identifier) const { |
+ Factory* factory = parser_->isolate()->factory(); |
+ return identifier.is_identical_to(factory->eval_string()) |
+ || identifier.is_identical_to(factory->arguments_string()); |
} |
@@ -425,10 +424,10 @@ bool ParserTraits::IsIdentifier(Expression* expression) { |
void ParserTraits::PushPropertyName(FuncNameInferrer* fni, |
Expression* expression) { |
if (expression->IsPropertyName()) { |
- fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); |
+ fni->PushLiteralName(expression->AsLiteral()->AsPropertyName()); |
} else { |
fni->PushLiteralName( |
- parser_->ast_value_factory_->anonymous_function_string()); |
+ parser_->isolate()->factory()->anonymous_function_string()); |
} |
} |
@@ -447,7 +446,7 @@ void ParserTraits::CheckPossibleEvalCall(Expression* expression, |
Scope* scope) { |
VariableProxy* callee = expression->AsVariableProxy(); |
if (callee != NULL && |
- callee->raw_name() == parser_->ast_value_factory_->eval_string()) { |
+ callee->IsVariable(parser_->isolate()->factory()->eval_string())) { |
scope->DeclarationScope()->RecordEvalCall(); |
} |
} |
@@ -465,10 +464,10 @@ Expression* ParserTraits::MarkExpressionAsLValue(Expression* expression) { |
bool ParserTraits::ShortcutNumericLiteralBinaryExpression( |
Expression** x, Expression* y, Token::Value op, int pos, |
AstNodeFactory<AstConstructionVisitor>* factory) { |
- if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() && |
- y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { |
- double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); |
- double y_val = y->AsLiteral()->raw_value()->AsNumber(); |
+ if ((*x)->AsLiteral() && (*x)->AsLiteral()->value()->IsNumber() && |
+ y->AsLiteral() && y->AsLiteral()->value()->IsNumber()) { |
+ double x_val = (*x)->AsLiteral()->value()->Number(); |
+ double y_val = y->AsLiteral()->value()->Number(); |
switch (op) { |
case Token::ADD: |
*x = factory->NewNumberLiteral(x_val + y_val, pos); |
@@ -527,14 +526,16 @@ Expression* ParserTraits::BuildUnaryExpression( |
AstNodeFactory<AstConstructionVisitor>* factory) { |
ASSERT(expression != NULL); |
if (expression->IsLiteral()) { |
- const AstValue* literal = expression->AsLiteral()->raw_value(); |
+ Handle<Object> literal = expression->AsLiteral()->value(); |
if (op == Token::NOT) { |
// Convert the literal to a boolean condition and negate it. |
bool condition = literal->BooleanValue(); |
- return factory->NewBooleanLiteral(!condition, pos); |
+ Handle<Object> result = |
+ parser_->isolate()->factory()->ToBoolean(!condition); |
+ return factory->NewLiteral(result, pos); |
} else if (literal->IsNumber()) { |
// Compute some expressions involving only number literals. |
- double value = literal->AsNumber(); |
+ double value = literal->Number(); |
switch (op) { |
case Token::ADD: |
return expression; |
@@ -568,41 +569,51 @@ Expression* ParserTraits::BuildUnaryExpression( |
Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) { |
return NewThrowError( |
- parser_->ast_value_factory_->make_reference_error_string(), message, NULL, |
- pos); |
+ parser_->isolate()->factory()->MakeReferenceError_string(), |
+ message, HandleVector<Object>(NULL, 0), pos); |
} |
Expression* ParserTraits::NewThrowSyntaxError( |
- const char* message, const AstString* arg, int pos) { |
- return NewThrowError(parser_->ast_value_factory_->make_syntax_error_string(), |
- message, arg, pos); |
+ const char* message, Handle<Object> arg, int pos) { |
+ int argc = arg.is_null() ? 0 : 1; |
+ Vector< Handle<Object> > arguments = HandleVector<Object>(&arg, argc); |
+ return NewThrowError( |
+ parser_->isolate()->factory()->MakeSyntaxError_string(), |
+ message, arguments, pos); |
} |
Expression* ParserTraits::NewThrowTypeError( |
- const char* message, const AstString* arg, int pos) { |
- return NewThrowError(parser_->ast_value_factory_->make_type_error_string(), |
- message, arg, pos); |
+ const char* message, Handle<Object> arg, int pos) { |
+ int argc = arg.is_null() ? 0 : 1; |
+ Vector< Handle<Object> > arguments = HandleVector<Object>(&arg, argc); |
+ return NewThrowError( |
+ parser_->isolate()->factory()->MakeTypeError_string(), |
+ message, arguments, pos); |
} |
Expression* ParserTraits::NewThrowError( |
- const AstString* constructor, const char* message, |
- const AstString* arg, int pos) { |
+ Handle<String> constructor, const char* message, |
+ Vector<Handle<Object> > arguments, int pos) { |
Zone* zone = parser_->zone(); |
- int argc = arg != NULL ? 1 : 0; |
- const AstString* type = |
- parser_->ast_value_factory_->GetOneByteString(Vector<const uint8_t>( |
- reinterpret_cast<const uint8_t*>(message), StrLength(message))); |
- ZoneList<const AstString*>* array = |
- new (zone) ZoneList<const AstString*>(argc, zone); |
- if (arg != NULL) { |
- array->Add(arg, zone); |
- } |
- ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone); |
- args->Add(parser_->factory()->NewStringLiteral(type, pos), zone); |
- args->Add(parser_->factory()->NewStringListLiteral(array, pos), zone); |
+ Factory* factory = parser_->isolate()->factory(); |
+ int argc = arguments.length(); |
+ Handle<FixedArray> elements = factory->NewFixedArray(argc, TENURED); |
+ for (int i = 0; i < argc; i++) { |
+ Handle<Object> element = arguments[i]; |
+ if (!element.is_null()) { |
+ elements->set(i, *element); |
+ } |
+ } |
+ Handle<JSArray> array = |
+ factory->NewJSArrayWithElements(elements, FAST_ELEMENTS, TENURED); |
+ |
+ ZoneList<Expression*>* args = new(zone) ZoneList<Expression*>(2, zone); |
+ Handle<String> type = factory->InternalizeUtf8String(message); |
+ args->Add(parser_->factory()->NewLiteral(type, pos), zone); |
+ args->Add(parser_->factory()->NewLiteral(array, pos), zone); |
CallRuntime* call_constructor = |
parser_->factory()->NewCallRuntime(constructor, NULL, args, pos); |
return parser_->factory()->NewThrow(call_constructor, pos); |
@@ -623,21 +634,13 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
parser_->pending_error_location_ = source_location; |
parser_->pending_error_message_ = message; |
parser_->pending_error_char_arg_ = arg; |
- parser_->pending_error_arg_ = NULL; |
+ parser_->pending_error_arg_ = Handle<String>(); |
parser_->pending_error_is_reference_error_ = is_reference_error; |
} |
void ParserTraits::ReportMessage(const char* message, |
- const char* arg, |
- bool is_reference_error) { |
- Scanner::Location source_location = parser_->scanner()->location(); |
- ReportMessageAt(source_location, message, arg, is_reference_error); |
-} |
- |
- |
-void ParserTraits::ReportMessage(const char* message, |
- const AstString* arg, |
+ MaybeHandle<String> arg, |
bool is_reference_error) { |
Scanner::Location source_location = parser_->scanner()->location(); |
ReportMessageAt(source_location, message, arg, is_reference_error); |
@@ -646,7 +649,7 @@ void ParserTraits::ReportMessage(const char* message, |
void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
const char* message, |
- const AstString* arg, |
+ MaybeHandle<String> arg, |
bool is_reference_error) { |
if (parser_->stack_overflow()) { |
// Suppress the error message (syntax error or such) in the presence of a |
@@ -663,16 +666,17 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
} |
-const AstString* ParserTraits::GetSymbol(Scanner* scanner) { |
- const AstString* result = |
- parser_->scanner()->CurrentSymbol(parser_->ast_value_factory_); |
- ASSERT(result != NULL); |
+Handle<String> ParserTraits::GetSymbol(Scanner* scanner) { |
+ Handle<String> result = |
+ parser_->scanner()->AllocateInternalizedString(parser_->isolate()); |
+ ASSERT(!result.is_null()); |
return result; |
} |
-const AstString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
- return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); |
+Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, |
+ PretenureFlag tenured) { |
+ return scanner->AllocateNextLiteralString(parser_->isolate(), tenured); |
} |
@@ -687,13 +691,14 @@ Literal* ParserTraits::ExpressionFromLiteral( |
Token::Value token, int pos, |
Scanner* scanner, |
AstNodeFactory<AstConstructionVisitor>* factory) { |
+ Factory* isolate_factory = parser_->isolate()->factory(); |
switch (token) { |
case Token::NULL_LITERAL: |
- return factory->NewNullLiteral(pos); |
+ return factory->NewLiteral(isolate_factory->null_value(), pos); |
case Token::TRUE_LITERAL: |
- return factory->NewBooleanLiteral(true, pos); |
+ return factory->NewLiteral(isolate_factory->true_value(), pos); |
case Token::FALSE_LITERAL: |
- return factory->NewBooleanLiteral(false, pos); |
+ return factory->NewLiteral(isolate_factory->false_value(), pos); |
case Token::NUMBER: { |
double value = scanner->DoubleValue(); |
return factory->NewNumberLiteral(value, pos); |
@@ -706,13 +711,13 @@ Literal* ParserTraits::ExpressionFromLiteral( |
Expression* ParserTraits::ExpressionFromIdentifier( |
- const AstString* name, int pos, Scope* scope, |
+ Handle<String> name, int pos, Scope* scope, |
AstNodeFactory<AstConstructionVisitor>* factory) { |
if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
// The name may refer to a module instance object, so its type is unknown. |
#ifdef DEBUG |
if (FLAG_print_interface_details) |
- PrintF("# Variable %.*s ", name->length(), name->raw_data()); |
+ PrintF("# Variable %s ", name->ToAsciiArray()); |
#endif |
Interface* interface = Interface::NewUnknown(parser_->zone()); |
return scope->NewUnresolved(factory, name, interface, pos); |
@@ -722,15 +727,16 @@ Expression* ParserTraits::ExpressionFromIdentifier( |
Expression* ParserTraits::ExpressionFromString( |
int pos, Scanner* scanner, |
AstNodeFactory<AstConstructionVisitor>* factory) { |
- const AstString* symbol = GetSymbol(scanner); |
+ Handle<String> symbol = GetSymbol(scanner); |
if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
- return factory->NewStringLiteral(symbol, pos); |
+ return factory->NewLiteral(symbol, pos); |
} |
Literal* ParserTraits::GetLiteralTheHole( |
int position, AstNodeFactory<AstConstructionVisitor>* factory) { |
- return factory->NewTheHoleLiteral(RelocInfo::kNoPosition); |
+ return factory->NewLiteral(parser_->isolate()->factory()->the_hole_value(), |
+ RelocInfo::kNoPosition); |
} |
@@ -740,7 +746,7 @@ Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { |
FunctionLiteral* ParserTraits::ParseFunctionLiteral( |
- const AstString* name, |
+ Handle<String> name, |
Scanner::Location function_name_location, |
bool name_is_strict_reserved, |
bool is_generator, |
@@ -770,11 +776,9 @@ Parser::Parser(CompilationInfo* info) |
target_stack_(NULL), |
cached_data_(NULL), |
cached_data_mode_(NO_CACHED_DATA), |
- ast_value_factory_(NULL), |
info_(info), |
has_pending_error_(false), |
pending_error_message_(NULL), |
- pending_error_arg_(NULL), |
pending_error_char_arg_(NULL) { |
ASSERT(!script_.is_null()); |
isolate_->set_ast_node_id(0); |
@@ -798,7 +802,7 @@ FunctionLiteral* Parser::ParseProgram() { |
if (FLAG_trace_parse) { |
timer.Start(); |
} |
- fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); |
+ fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
// Initialize parser state. |
CompleteParserRecorder recorder; |
@@ -853,16 +857,13 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, |
ASSERT(scope_ == NULL); |
ASSERT(target_stack_ == NULL); |
+ Handle<String> no_name = isolate()->factory()->empty_string(); |
+ |
FunctionLiteral* result = NULL; |
{ Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
info->SetGlobalScope(scope); |
if (!info->context().is_null()) { |
scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); |
- // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
- // means the Parser cannot operate independent of the V8 heap. Tell the |
- // string table to internalize strings and values right after they're |
- // created. |
- ast_value_factory_->Internalize(isolate()); |
} |
original_scope_ = scope; |
if (info->is_eval()) { |
@@ -885,8 +886,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, |
ParsingModeScope parsing_mode(this, mode); |
// Enters 'scope'. |
- FunctionState function_state(&function_state_, &scope_, scope, zone(), |
- ast_value_factory_); |
+ FunctionState function_state(&function_state_, &scope_, scope, zone()); |
scope_->SetStrictMode(info->strict_mode()); |
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
@@ -911,11 +911,9 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, |
} |
} |
- ast_value_factory_->Internalize(isolate()); |
if (ok) { |
result = factory()->NewFunctionLiteral( |
- ast_value_factory_->empty_string(), |
- ast_value_factory_, |
+ no_name, |
scope_, |
body, |
function_state.materialized_literal_count(), |
@@ -987,10 +985,8 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { |
ASSERT(target_stack_ == NULL); |
Handle<String> name(String::cast(shared_info->name())); |
- ASSERT(ast_value_factory_); |
- fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); |
- const AstString* raw_name = ast_value_factory_->GetString(name); |
- fni_->PushEnclosingName(raw_name); |
+ fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
+ fni_->PushEnclosingName(name); |
ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
@@ -1006,8 +1002,7 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { |
zone()); |
} |
original_scope_ = scope; |
- FunctionState function_state(&function_state_, &scope_, scope, zone(), |
- ast_value_factory_); |
+ FunctionState function_state(&function_state_, &scope_, scope, zone()); |
ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
ASSERT(info()->strict_mode() == shared_info->strict_mode()); |
scope->SetStrictMode(shared_info->strict_mode()); |
@@ -1017,7 +1012,7 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { |
: FunctionLiteral::NAMED_EXPRESSION) |
: FunctionLiteral::DECLARATION; |
bool ok = true; |
- result = ParseFunctionLiteral(raw_name, |
+ result = ParseFunctionLiteral(name, |
Scanner::Location::invalid(), |
false, // Strict mode name already checked. |
shared_info->is_generator(), |
@@ -1032,7 +1027,6 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { |
// Make sure the target stack is empty. |
ASSERT(target_stack_ == NULL); |
- ast_value_factory_->Internalize(isolate()); |
if (result == NULL) { |
if (stack_overflow()) { |
isolate()->StackOverflow(); |
@@ -1088,12 +1082,15 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
// Still processing directive prologue? |
if ((e_stat = stat->AsExpressionStatement()) != NULL && |
(literal = e_stat->expression()->AsLiteral()) != NULL && |
- literal->raw_value()->IsString()) { |
+ literal->value()->IsString()) { |
+ Handle<String> directive = Handle<String>::cast(literal->value()); |
+ |
// Check "use strict" directive (ES5 14.1). |
if (strict_mode() == SLOPPY && |
- literal->raw_value()->AsString() == |
- ast_value_factory_->use_strict_string() && |
- token_loc.end_pos - token_loc.beg_pos == 12) { |
+ String::Equals(isolate()->factory()->use_strict_string(), |
+ directive) && |
+ token_loc.end_pos - token_loc.beg_pos == |
+ isolate()->heap()->use_strict_string()->length() + 2) { |
// TODO(mstarzinger): Global strict eval calls, need their own scope |
// as specified in ES5 10.4.2(3). The correct fix would be to always |
// add this scope in DoParseProgram(), but that requires adaptations |
@@ -1124,7 +1121,7 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
} |
-Statement* Parser::ParseModuleElement(ZoneList<const AstString*>* labels, |
+Statement* Parser::ParseModuleElement(ZoneStringList* labels, |
bool* ok) { |
// (Ecma 262 5th Edition, clause 14): |
// SourceElement: |
@@ -1158,9 +1155,10 @@ Statement* Parser::ParseModuleElement(ZoneList<const AstString*>* labels, |
!scanner()->HasAnyLineTerminatorBeforeNext() && |
stmt != NULL) { |
ExpressionStatement* estmt = stmt->AsExpressionStatement(); |
- if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL && |
- estmt->expression()->AsVariableProxy()->raw_name() == |
- ast_value_factory_->module_string() && |
+ if (estmt != NULL && |
+ estmt->expression()->AsVariableProxy() != NULL && |
+ String::Equals(isolate()->factory()->module_string(), |
+ estmt->expression()->AsVariableProxy()->name()) && |
!scanner()->literal_contains_escapes()) { |
return ParseModuleDeclaration(NULL, ok); |
} |
@@ -1171,17 +1169,16 @@ Statement* Parser::ParseModuleElement(ZoneList<const AstString*>* labels, |
} |
-Statement* Parser::ParseModuleDeclaration(ZoneList<const AstString*>* names, |
- bool* ok) { |
+Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { |
// ModuleDeclaration: |
// 'module' Identifier Module |
int pos = peek_position(); |
- const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
+ Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
#ifdef DEBUG |
if (FLAG_print_interface_details) |
- PrintF("# Module %.*s ", name->length(), name->raw_data()); |
+ PrintF("# Module %s...\n", name->ToAsciiArray()); |
#endif |
Module* module = ParseModule(CHECK_OK); |
@@ -1192,9 +1189,10 @@ Statement* Parser::ParseModuleDeclaration(ZoneList<const AstString*>* names, |
#ifdef DEBUG |
if (FLAG_print_interface_details) |
- PrintF("# Module %.*s ", name->length(), name->raw_data()); |
+ PrintF("# Module %s.\n", name->ToAsciiArray()); |
+ |
if (FLAG_print_interfaces) { |
- PrintF("module %.*s: ", name->length(), name->raw_data()); |
+ PrintF("module %s : ", name->ToAsciiArray()); |
module->interface()->Print(); |
} |
#endif |
@@ -1295,17 +1293,17 @@ Module* Parser::ParseModulePath(bool* ok) { |
int pos = peek_position(); |
Module* result = ParseModuleVariable(CHECK_OK); |
while (Check(Token::PERIOD)) { |
- const AstString* name = ParseIdentifierName(CHECK_OK); |
+ Handle<String> name = ParseIdentifierName(CHECK_OK); |
#ifdef DEBUG |
if (FLAG_print_interface_details) |
- PrintF("# Path .%.*s ", name->length(), name->raw_data()); |
+ PrintF("# Path .%s ", name->ToAsciiArray()); |
#endif |
Module* member = factory()->NewModulePath(result, name, pos); |
result->interface()->Add(name, member->interface(), zone(), ok); |
if (!*ok) { |
#ifdef DEBUG |
if (FLAG_print_interfaces) { |
- PrintF("PATH TYPE ERROR at '%.*s'\n", name->length(), name->raw_data()); |
+ PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray()); |
PrintF("result: "); |
result->interface()->Print(); |
PrintF("member: "); |
@@ -1327,10 +1325,10 @@ Module* Parser::ParseModuleVariable(bool* ok) { |
// Identifier |
int pos = peek_position(); |
- const AstString* name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
+ Handle<String> name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
#ifdef DEBUG |
if (FLAG_print_interface_details) |
- PrintF("# Module variable %.*s ", name->length(), name->raw_data()); |
+ PrintF("# Module variable %s ", name->ToAsciiArray()); |
#endif |
VariableProxy* proxy = scope_->NewUnresolved( |
factory(), name, Interface::NewModule(zone()), |
@@ -1346,7 +1344,7 @@ Module* Parser::ParseModuleUrl(bool* ok) { |
int pos = peek_position(); |
Expect(Token::STRING, CHECK_OK); |
- const AstString* symbol = GetSymbol(scanner()); |
+ Handle<String> symbol = GetSymbol(); |
// TODO(ES6): Request JS resource from environment... |
@@ -1390,9 +1388,9 @@ Block* Parser::ParseImportDeclaration(bool* ok) { |
int pos = peek_position(); |
Expect(Token::IMPORT, CHECK_OK); |
- ZoneList<const AstString*> names(1, zone()); |
+ ZoneStringList names(1, zone()); |
- const AstString* name = ParseIdentifierName(CHECK_OK); |
+ Handle<String> name = ParseIdentifierName(CHECK_OK); |
names.Add(name, zone()); |
while (peek() == Token::COMMA) { |
Consume(Token::COMMA); |
@@ -1410,15 +1408,14 @@ Block* Parser::ParseImportDeclaration(bool* ok) { |
for (int i = 0; i < names.length(); ++i) { |
#ifdef DEBUG |
if (FLAG_print_interface_details) |
- PrintF("# Import %.*s ", name->length(), name->raw_data()); |
+ PrintF("# Import %s ", names[i]->ToAsciiArray()); |
#endif |
Interface* interface = Interface::NewUnknown(zone()); |
module->interface()->Add(names[i], interface, zone(), ok); |
if (!*ok) { |
#ifdef DEBUG |
if (FLAG_print_interfaces) { |
- PrintF("IMPORT TYPE ERROR at '%.*s'\n", name->length(), |
- name->raw_data()); |
+ PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray()); |
PrintF("module: "); |
module->interface()->Print(); |
} |
@@ -1449,14 +1446,14 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { |
Expect(Token::EXPORT, CHECK_OK); |
Statement* result = NULL; |
- ZoneList<const AstString*> names(1, zone()); |
+ ZoneStringList names(1, zone()); |
switch (peek()) { |
case Token::IDENTIFIER: { |
int pos = position(); |
- const AstString* name = |
+ Handle<String> name = |
ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
// Handle 'module' as a context-sensitive keyword. |
- if (name != ast_value_factory_->module_string()) { |
+ if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) { |
names.Add(name, zone()); |
while (peek() == Token::COMMA) { |
Consume(Token::COMMA); |
@@ -1492,7 +1489,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { |
for (int i = 0; i < names.length(); ++i) { |
#ifdef DEBUG |
if (FLAG_print_interface_details) |
- PrintF("# Export %.*s ", names[i]->length(), names[i]->raw_data()); |
+ PrintF("# Export %s ", names[i]->ToAsciiArray()); |
#endif |
Interface* inner = Interface::NewUnknown(zone()); |
interface->Add(names[i], inner, zone(), CHECK_OK); |
@@ -1512,7 +1509,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { |
} |
-Statement* Parser::ParseBlockElement(ZoneList<const AstString*>* labels, |
+Statement* Parser::ParseBlockElement(ZoneStringList* labels, |
bool* ok) { |
// (Ecma 262 5th Edition, clause 14): |
// SourceElement: |
@@ -1537,8 +1534,7 @@ Statement* Parser::ParseBlockElement(ZoneList<const AstString*>* labels, |
} |
-Statement* Parser::ParseStatement(ZoneList<const AstString*>* labels, |
- bool* ok) { |
+Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { |
// Statement :: |
// Block |
// VariableStatement |
@@ -1648,8 +1644,8 @@ Statement* Parser::ParseStatement(ZoneList<const AstString*>* labels, |
} |
-VariableProxy* Parser::NewUnresolved(const AstString* name, VariableMode mode, |
- Interface* interface) { |
+VariableProxy* Parser::NewUnresolved( |
+ Handle<String> name, VariableMode mode, Interface* interface) { |
// If we are inside a function, a declaration of a var/const variable is a |
// truly local variable, and the scope of the variable is always the function |
// scope. |
@@ -1662,8 +1658,7 @@ VariableProxy* Parser::NewUnresolved(const AstString* name, VariableMode mode, |
void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
VariableProxy* proxy = declaration->proxy(); |
- ASSERT(proxy->raw_name() != NULL); |
- const AstString* name = proxy->raw_name(); |
+ Handle<String> name = proxy->name(); |
VariableMode mode = declaration->mode(); |
Scope* declaration_scope = DeclarationScope(mode); |
Variable* var = NULL; |
@@ -1791,10 +1786,8 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { |
if (FLAG_harmony_modules) { |
bool ok; |
#ifdef DEBUG |
- if (FLAG_print_interface_details) { |
- PrintF("# Declare %.*s ", var->raw_name()->length(), |
- var->raw_name()->raw_data()); |
- } |
+ if (FLAG_print_interface_details) |
+ PrintF("# Declare %s\n", var->name()->ToAsciiArray()); |
#endif |
proxy->interface()->Unify(var->interface(), zone(), &ok); |
if (!ok) { |
@@ -1822,7 +1815,7 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { |
int pos = peek_position(); |
Expect(Token::FUNCTION, CHECK_OK); |
// Allow "eval" or "arguments" for backward compatibility. |
- const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
+ Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
Expect(Token::LPAREN, CHECK_OK); |
bool done = (peek() == Token::RPAREN); |
while (!done) { |
@@ -1857,8 +1850,7 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { |
} |
-Statement* Parser::ParseFunctionDeclaration(ZoneList<const AstString*>* names, |
- bool* ok) { |
+Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { |
// FunctionDeclaration :: |
// 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
// GeneratorDeclaration :: |
@@ -1868,7 +1860,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneList<const AstString*>* names, |
int pos = position(); |
bool is_generator = allow_generators() && Check(Token::MUL); |
bool is_strict_reserved = false; |
- const AstString* name = ParseIdentifierOrStrictReservedWord( |
+ Handle<String> name = ParseIdentifierOrStrictReservedWord( |
&is_strict_reserved, CHECK_OK); |
FunctionLiteral* fun = ParseFunctionLiteral(name, |
scanner()->location(), |
@@ -1895,7 +1887,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneList<const AstString*>* names, |
} |
-Block* Parser::ParseBlock(ZoneList<const AstString*>* labels, bool* ok) { |
+Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { |
if (allow_harmony_scoping() && strict_mode() == STRICT) { |
return ParseScopedBlock(labels, ok); |
} |
@@ -1922,7 +1914,7 @@ Block* Parser::ParseBlock(ZoneList<const AstString*>* labels, bool* ok) { |
} |
-Block* Parser::ParseScopedBlock(ZoneList<const AstString*>* labels, bool* ok) { |
+Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { |
// The harmony mode uses block elements instead of statements. |
// |
// Block :: |
@@ -1957,12 +1949,12 @@ Block* Parser::ParseScopedBlock(ZoneList<const AstString*>* labels, bool* ok) { |
Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, |
- ZoneList<const AstString*>* names, |
+ ZoneStringList* names, |
bool* ok) { |
// VariableStatement :: |
// VariableDeclarations ';' |
- const AstString* ignore; |
+ Handle<String> ignore; |
Block* result = |
ParseVariableDeclarations(var_context, NULL, names, &ignore, CHECK_OK); |
ExpectSemicolon(CHECK_OK); |
@@ -1978,8 +1970,8 @@ Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, |
Block* Parser::ParseVariableDeclarations( |
VariableDeclarationContext var_context, |
VariableDeclarationProperties* decl_props, |
- ZoneList<const AstString*>* names, |
- const AstString** out, |
+ ZoneStringList* names, |
+ Handle<String>* out, |
bool* ok) { |
// VariableDeclarations :: |
// ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[','] |
@@ -2087,7 +2079,7 @@ Block* Parser::ParseVariableDeclarations( |
// Create new block with one expected declaration. |
Block* block = factory()->NewBlock(NULL, 1, true, pos); |
int nvars = 0; // the number of variables declared |
- const AstString* name = NULL; |
+ Handle<String> name; |
do { |
if (fni_ != NULL) fni_->Enter(); |
@@ -2206,7 +2198,7 @@ Block* Parser::ParseVariableDeclarations( |
ZoneList<Expression*>* arguments = |
new(zone()) ZoneList<Expression*>(3, zone()); |
// We have at least 1 parameter. |
- arguments->Add(factory()->NewStringLiteral(name, pos), zone()); |
+ arguments->Add(factory()->NewLiteral(name, pos), zone()); |
CallRuntime* initialize; |
if (is_const) { |
@@ -2218,7 +2210,7 @@ Block* Parser::ParseVariableDeclarations( |
// Note that the function does different things depending on |
// the number of arguments (1 or 2). |
initialize = factory()->NewCallRuntime( |
- ast_value_factory_->initialize_const_global_string(), |
+ isolate()->factory()->InitializeConstGlobal_string(), |
Runtime::FunctionForId(Runtime::kHiddenInitializeConstGlobal), |
arguments, pos); |
} else { |
@@ -2241,7 +2233,7 @@ Block* Parser::ParseVariableDeclarations( |
// Note that the function does different things depending on |
// the number of arguments (2 or 3). |
initialize = factory()->NewCallRuntime( |
- ast_value_factory_->initialize_var_global_string(), |
+ isolate()->factory()->InitializeVarGlobal_string(), |
Runtime::FunctionForId(Runtime::kInitializeVarGlobal), |
arguments, pos); |
} |
@@ -2297,12 +2289,11 @@ Block* Parser::ParseVariableDeclarations( |
} |
-static bool ContainsLabel(ZoneList<const AstString*>* labels, |
- const AstString* label) { |
- ASSERT(label != NULL); |
+static bool ContainsLabel(ZoneStringList* labels, Handle<String> label) { |
+ ASSERT(!label.is_null()); |
if (labels != NULL) { |
for (int i = labels->length(); i-- > 0; ) { |
- if (labels->at(i) == label) { |
+ if (labels->at(i).is_identical_to(label)) { |
return true; |
} |
} |
@@ -2311,8 +2302,8 @@ static bool ContainsLabel(ZoneList<const AstString*>* labels, |
} |
-Statement* Parser::ParseExpressionOrLabelledStatement( |
- ZoneList<const AstString*>* labels, bool* ok) { |
+Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, |
+ bool* ok) { |
// ExpressionStatement | LabelledStatement :: |
// Expression ';' |
// Identifier ':' Statement |
@@ -2325,7 +2316,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement( |
// Expression is a single identifier, and not, e.g., a parenthesized |
// identifier. |
VariableProxy* var = expr->AsVariableProxy(); |
- const AstString* label = var->raw_name(); |
+ Handle<String> label = var->name(); |
// TODO(1240780): We don't check for redeclaration of labels |
// during preparsing since keeping track of the set of active |
// labels requires nontrivial changes to the way scopes are |
@@ -2337,7 +2328,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement( |
return NULL; |
} |
if (labels == NULL) { |
- labels = new(zone()) ZoneList<const AstString*>(4, zone()); |
+ labels = new(zone()) ZoneStringList(4, zone()); |
} |
labels->Add(label, zone()); |
// Remove the "ghost" variable that turned out to be a label |
@@ -2356,8 +2347,8 @@ Statement* Parser::ParseExpressionOrLabelledStatement( |
!scanner()->HasAnyLineTerminatorBeforeNext() && |
expr != NULL && |
expr->AsVariableProxy() != NULL && |
- expr->AsVariableProxy()->raw_name() == |
- ast_value_factory_->native_string() && |
+ String::Equals(isolate()->factory()->native_string(), |
+ expr->AsVariableProxy()->name()) && |
!scanner()->literal_contains_escapes()) { |
return ParseNativeDeclaration(ok); |
} |
@@ -2368,8 +2359,8 @@ Statement* Parser::ParseExpressionOrLabelledStatement( |
peek() != Token::IDENTIFIER || |
scanner()->HasAnyLineTerminatorBeforeNext() || |
expr->AsVariableProxy() == NULL || |
- expr->AsVariableProxy()->raw_name() != |
- ast_value_factory_->module_string() || |
+ !String::Equals(isolate()->factory()->module_string(), |
+ expr->AsVariableProxy()->name()) || |
scanner()->literal_contains_escapes()) { |
ExpectSemicolon(CHECK_OK); |
} |
@@ -2377,8 +2368,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement( |
} |
-IfStatement* Parser::ParseIfStatement(ZoneList<const AstString*>* labels, |
- bool* ok) { |
+IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { |
// IfStatement :: |
// 'if' '(' Expression ')' Statement ('else' Statement)? |
@@ -2406,18 +2396,19 @@ Statement* Parser::ParseContinueStatement(bool* ok) { |
int pos = peek_position(); |
Expect(Token::CONTINUE, CHECK_OK); |
- const AstString* label = NULL; |
+ Handle<String> label = Handle<String>::null(); |
Token::Value tok = peek(); |
if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
// ECMA allows "eval" or "arguments" as labels even in strict mode. |
label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
} |
- IterationStatement* target = LookupContinueTarget(label, CHECK_OK); |
+ IterationStatement* target = NULL; |
+ target = LookupContinueTarget(label, CHECK_OK); |
if (target == NULL) { |
// Illegal continue statement. |
const char* message = "illegal_continue"; |
- if (label != NULL) { |
+ if (!label.is_null()) { |
message = "unknown_label"; |
} |
ParserTraits::ReportMessage(message, label); |
@@ -2429,14 +2420,13 @@ Statement* Parser::ParseContinueStatement(bool* ok) { |
} |
-Statement* Parser::ParseBreakStatement(ZoneList<const AstString*>* labels, |
- bool* ok) { |
+Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { |
// BreakStatement :: |
// 'break' Identifier? ';' |
int pos = peek_position(); |
Expect(Token::BREAK, CHECK_OK); |
- const AstString* label = NULL; |
+ Handle<String> label; |
Token::Value tok = peek(); |
if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
@@ -2445,7 +2435,7 @@ Statement* Parser::ParseBreakStatement(ZoneList<const AstString*>* labels, |
} |
// Parse labeled break statements that target themselves into |
// empty statements, e.g. 'l1: l2: l3: break l2;' |
- if (label != NULL && ContainsLabel(labels, label)) { |
+ if (!label.is_null() && ContainsLabel(labels, label)) { |
ExpectSemicolon(CHECK_OK); |
return factory()->NewEmptyStatement(pos); |
} |
@@ -2454,7 +2444,7 @@ Statement* Parser::ParseBreakStatement(ZoneList<const AstString*>* labels, |
if (target == NULL) { |
// Illegal break statement. |
const char* message = "illegal_break"; |
- if (label != NULL) { |
+ if (!label.is_null()) { |
message = "unknown_label"; |
} |
ParserTraits::ReportMessage(message, label); |
@@ -2508,8 +2498,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { |
} |
-Statement* Parser::ParseWithStatement(ZoneList<const AstString*>* labels, |
- bool* ok) { |
+Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { |
// WithStatement :: |
// 'with' '(' Expression ')' Statement |
@@ -2571,8 +2560,8 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { |
} |
-SwitchStatement* Parser::ParseSwitchStatement( |
- ZoneList<const AstString*>* labels, bool* ok) { |
+SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, |
+ bool* ok) { |
// SwitchStatement :: |
// 'switch' '(' Expression ')' '{' CaseClause* '}' |
@@ -2655,7 +2644,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { |
Scope* catch_scope = NULL; |
Variable* catch_variable = NULL; |
Block* catch_block = NULL; |
- const AstString* name = NULL; |
+ Handle<String> name; |
if (tok == Token::CATCH) { |
Consume(Token::CATCH); |
@@ -2725,8 +2714,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { |
} |
-DoWhileStatement* Parser::ParseDoWhileStatement( |
- ZoneList<const AstString*>* labels, bool* ok) { |
+DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, |
+ bool* ok) { |
// DoStatement :: |
// 'do' Statement 'while' '(' Expression ')' ';' |
@@ -2753,8 +2742,7 @@ DoWhileStatement* Parser::ParseDoWhileStatement( |
} |
-WhileStatement* Parser::ParseWhileStatement(ZoneList<const AstString*>* labels, |
- bool* ok) { |
+WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { |
// WhileStatement :: |
// 'while' '(' Expression ')' Statement |
@@ -2793,12 +2781,13 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
ForOfStatement* for_of = stmt->AsForOfStatement(); |
if (for_of != NULL) { |
+ Factory* heap_factory = isolate()->factory(); |
Variable* iterable = scope_->DeclarationScope()->NewTemporary( |
- ast_value_factory_->dot_iterable_string()); |
+ heap_factory->dot_iterable_string()); |
Variable* iterator = scope_->DeclarationScope()->NewTemporary( |
- ast_value_factory_->dot_iterator_string()); |
+ heap_factory->dot_iterator_string()); |
Variable* result = scope_->DeclarationScope()->NewTemporary( |
- ast_value_factory_->dot_result_string()); |
+ heap_factory->dot_result_string()); |
Expression* assign_iterable; |
Expression* assign_iterator; |
@@ -2816,8 +2805,10 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
// var iterator = iterable[Symbol.iterator](); |
{ |
Expression* iterable_proxy = factory()->NewVariableProxy(iterable); |
- Expression* iterator_symbol_literal = |
- factory()->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition); |
+ Handle<Symbol> iterator_symbol( |
+ isolate()->native_context()->iterator_symbol(), isolate()); |
+ Expression* iterator_symbol_literal = factory()->NewLiteral( |
+ iterator_symbol, RelocInfo::kNoPosition); |
// FIXME(wingo): Unhappily, it will be a common error that the RHS of a |
// for-of doesn't have a Symbol.iterator property. We should do better |
// than informing the user that "undefined is not a function". |
@@ -2836,8 +2827,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
// var result = iterator.next(); |
{ |
Expression* iterator_proxy = factory()->NewVariableProxy(iterator); |
- Expression* next_literal = factory()->NewStringLiteral( |
- ast_value_factory_->next_string(), RelocInfo::kNoPosition); |
+ Expression* next_literal = factory()->NewLiteral( |
+ heap_factory->next_string(), RelocInfo::kNoPosition); |
Expression* next_property = factory()->NewProperty( |
iterator_proxy, next_literal, RelocInfo::kNoPosition); |
ZoneList<Expression*>* next_arguments = |
@@ -2851,8 +2842,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
// result.done |
{ |
- Expression* done_literal = factory()->NewStringLiteral( |
- ast_value_factory_->done_string(), RelocInfo::kNoPosition); |
+ Expression* done_literal = factory()->NewLiteral( |
+ heap_factory->done_string(), RelocInfo::kNoPosition); |
Expression* result_proxy = factory()->NewVariableProxy(result); |
result_done = factory()->NewProperty( |
result_proxy, done_literal, RelocInfo::kNoPosition); |
@@ -2860,8 +2851,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
// each = result.value |
{ |
- Expression* value_literal = factory()->NewStringLiteral( |
- ast_value_factory_->value_string(), RelocInfo::kNoPosition); |
+ Expression* value_literal = factory()->NewLiteral( |
+ heap_factory->value_string(), RelocInfo::kNoPosition); |
Expression* result_proxy = factory()->NewVariableProxy(result); |
Expression* result_value = factory()->NewProperty( |
result_proxy, value_literal, RelocInfo::kNoPosition); |
@@ -2882,9 +2873,9 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, |
Statement* Parser::DesugarLetBindingsInForStatement( |
- Scope* inner_scope, ZoneList<const AstString*>* names, |
- ForStatement* loop, Statement* init, Expression* cond, Statement* next, |
- Statement* body, bool* ok) { |
+ Scope* inner_scope, ZoneStringList* names, ForStatement* loop, |
+ Statement* init, Expression* cond, Statement* next, Statement* body, |
+ bool* ok) { |
// ES6 13.6.3.4 specifies that on each loop iteration the let variables are |
// copied into a new environment. After copying, the "next" statement of the |
// loop is executed to update the loop variables. The loop condition is |
@@ -2925,7 +2916,10 @@ Statement* Parser::DesugarLetBindingsInForStatement( |
RelocInfo::kNoPosition); |
outer_block->AddStatement(init, zone()); |
- const AstString* temp_name = ast_value_factory_->dot_for_string(); |
+ Handle<String> temp_name = isolate()->factory()->dot_for_string(); |
+ Handle<Smi> smi0 = handle(Smi::FromInt(0), isolate()); |
+ Handle<Smi> smi1 = handle(Smi::FromInt(1), isolate()); |
+ |
// For each let variable x: |
// make statement: temp_x = x. |
@@ -2946,7 +2940,7 @@ Statement* Parser::DesugarLetBindingsInForStatement( |
// Make statement: flag = 1. |
{ |
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
- Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
+ Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); |
Assignment* assignment = factory()->NewAssignment( |
Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); |
Statement* assignment_statement = factory()->NewExpressionStatement( |
@@ -2986,7 +2980,7 @@ Statement* Parser::DesugarLetBindingsInForStatement( |
Expression* compare = NULL; |
// Make compare expresion: flag == 1. |
{ |
- Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
+ Expression* const1 = factory()->NewLiteral(smi1, RelocInfo::kNoPosition); |
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
compare = factory()->NewCompareOperation( |
Token::EQ, flag_proxy, const1, pos); |
@@ -2995,7 +2989,7 @@ Statement* Parser::DesugarLetBindingsInForStatement( |
// Make statement: flag = 0. |
{ |
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
- Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); |
+ Expression* const0 = factory()->NewLiteral(smi0, RelocInfo::kNoPosition); |
Assignment* assignment = factory()->NewAssignment( |
Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition); |
clear_flag = factory()->NewExpressionStatement(assignment, pos); |
@@ -3009,7 +3003,7 @@ Statement* Parser::DesugarLetBindingsInForStatement( |
// Make statement: if (cond) { } else { break; }. |
{ |
Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
- BreakableStatement* t = LookupBreakTarget(NULL, CHECK_OK); |
+ BreakableStatement* t = LookupBreakTarget(Handle<String>(), CHECK_OK); |
Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition); |
Statement* if_not_cond_break = factory()->NewIfStatement( |
cond, empty, stop, cond->position()); |
@@ -3040,14 +3034,13 @@ Statement* Parser::DesugarLetBindingsInForStatement( |
} |
-Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels, |
- bool* ok) { |
+Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { |
// ForStatement :: |
// 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
int pos = peek_position(); |
Statement* init = NULL; |
- ZoneList<const AstString*> let_bindings(1, zone()); |
+ ZoneStringList let_bindings(1, zone()); |
// Create an in-between scope for let-bound iteration variables. |
Scope* saved_scope = scope_; |
@@ -3060,7 +3053,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels, |
if (peek() != Token::SEMICOLON) { |
if (peek() == Token::VAR || peek() == Token::CONST) { |
bool is_const = peek() == Token::CONST; |
- const AstString* name = NULL; |
+ Handle<String> name; |
VariableDeclarationProperties decl_props = kHasNoInitializers; |
Block* variable_statement = |
ParseVariableDeclarations(kForStatement, &decl_props, NULL, &name, |
@@ -3068,7 +3061,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels, |
bool accept_OF = decl_props == kHasNoInitializers; |
ForEachStatement::VisitMode mode; |
- if (name != NULL && CheckInOrOf(accept_OF, &mode)) { |
+ if (!name.is_null() && CheckInOrOf(accept_OF, &mode)) { |
Interface* interface = |
is_const ? Interface::NewConst() : Interface::NewValue(); |
ForEachStatement* loop = |
@@ -3096,12 +3089,12 @@ Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels, |
init = variable_statement; |
} |
} else if (peek() == Token::LET) { |
- const AstString* name = NULL; |
+ Handle<String> name; |
VariableDeclarationProperties decl_props = kHasNoInitializers; |
Block* variable_statement = |
- ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings, |
- &name, CHECK_OK); |
- bool accept_IN = name != NULL && decl_props != kHasInitializers; |
+ ParseVariableDeclarations(kForStatement, &decl_props, &let_bindings, |
+ &name, CHECK_OK); |
+ bool accept_IN = !name.is_null() && decl_props != kHasInitializers; |
bool accept_OF = decl_props == kHasNoInitializers; |
ForEachStatement::VisitMode mode; |
@@ -3121,8 +3114,14 @@ Statement* Parser::ParseForStatement(ZoneList<const AstString*>* labels, |
// TODO(keuchel): Move the temporary variable to the block scope, after |
// implementing stack allocated block scoped variables. |
- Variable* temp = scope_->DeclarationScope()->NewTemporary( |
- ast_value_factory_->dot_for_string()); |
+ Factory* heap_factory = isolate()->factory(); |
+ Handle<String> tempstr; |
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
+ isolate(), tempstr, |
+ heap_factory->NewConsString(heap_factory->dot_for_string(), name), |
+ 0); |
+ Handle<String> tempname = heap_factory->InternalizeString(tempstr); |
+ Variable* temp = scope_->DeclarationScope()->NewTemporary(tempname); |
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
ForEachStatement* loop = |
factory()->NewForEachStatement(mode, labels, pos); |
@@ -3253,7 +3252,7 @@ DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { |
} |
-void Parser::ReportInvalidCachedData(const AstString* name, bool* ok) { |
+void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) { |
ParserTraits::ReportMessage("invalid_cached_data_function", name); |
*ok = false; |
} |
@@ -3303,7 +3302,7 @@ Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
FunctionLiteral* Parser::ParseFunctionLiteral( |
- const AstString* function_name, |
+ Handle<String> function_name, |
Scanner::Location function_name_location, |
bool name_is_strict_reserved, |
bool is_generator, |
@@ -3326,11 +3325,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
// Anonymous functions were passed either the empty symbol or a null |
// handle as the function name. Remember if we were passed a non-empty |
// handle to decide whether to invoke function name inference. |
- bool should_infer_name = function_name == NULL; |
+ bool should_infer_name = function_name.is_null(); |
// We want a non-null handle as the function name. |
if (should_infer_name) { |
- function_name = ast_value_factory_->empty_string(); |
+ function_name = isolate()->factory()->empty_string(); |
} |
int num_parameters = 0; |
@@ -3382,9 +3381,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
AstProperties ast_properties; |
BailoutReason dont_optimize_reason = kNoReason; |
// Parse function body. |
- { |
- FunctionState function_state(&function_state_, &scope_, scope, zone(), |
- ast_value_factory_); |
+ { FunctionState function_state(&function_state_, &scope_, scope, zone()); |
scope_->SetScopeName(function_name); |
if (is_generator) { |
@@ -3397,7 +3394,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
// in a temporary variable, a definition that is used by "yield" |
// expressions. This also marks the FunctionState as a generator. |
Variable* temp = scope_->DeclarationScope()->NewTemporary( |
- ast_value_factory_->dot_generator_object_string()); |
+ isolate()->factory()->dot_generator_object_string()); |
function_state.set_generator_object_variable(temp); |
} |
@@ -3418,7 +3415,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
arity_restriction != FunctionLiteral::SETTER_ARITY); |
while (!done) { |
bool is_strict_reserved = false; |
- const AstString* param_name = |
+ Handle<String> param_name = |
ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
// Store locations for possible future error reports. |
@@ -3463,7 +3460,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
VariableMode fvar_mode = |
allow_harmony_scoping() && strict_mode() == STRICT ? CONST |
: CONST_LEGACY; |
- ASSERT(function_name != NULL); |
fvar = new(zone()) Variable(scope_, |
function_name, fvar_mode, true /* is valid LHS */, |
Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); |
@@ -3567,7 +3563,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
: FunctionLiteral::kNotGenerator; |
FunctionLiteral* function_literal = |
factory()->NewFunctionLiteral(function_name, |
- ast_value_factory_, |
scope, |
body, |
materialized_literal_count, |
@@ -3589,7 +3584,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( |
} |
-void Parser::SkipLazyFunctionBody(const AstString* function_name, |
+void Parser::SkipLazyFunctionBody(Handle<String> function_name, |
int* materialized_literal_count, |
int* expected_property_count, |
bool* ok) { |
@@ -3668,7 +3663,7 @@ void Parser::SkipLazyFunctionBody(const AstString* function_name, |
ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
- const AstString* function_name, int pos, Variable* fvar, |
+ Handle<String> function_name, int pos, Variable* fvar, |
Token::Value fvar_init_op, bool is_generator, bool* ok) { |
// Everything inside an eagerly parsed function will be parsed eagerly |
// (see comment above). |
@@ -3691,7 +3686,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
ZoneList<Expression*>* arguments = |
new(zone()) ZoneList<Expression*>(0, zone()); |
CallRuntime* allocation = factory()->NewCallRuntime( |
- ast_value_factory_->empty_string(), |
+ isolate()->factory()->empty_string(), |
Runtime::FunctionForId(Runtime::kHiddenCreateJSGeneratorObject), |
arguments, pos); |
VariableProxy* init_proxy = factory()->NewVariableProxy( |
@@ -3711,10 +3706,10 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
if (is_generator) { |
VariableProxy* get_proxy = factory()->NewVariableProxy( |
function_state_->generator_object_variable()); |
- Expression* undefined = |
- factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); |
- Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL, |
- RelocInfo::kNoPosition); |
+ Expression *undefined = factory()->NewLiteral( |
+ isolate()->factory()->undefined_value(), RelocInfo::kNoPosition); |
+ Yield* yield = factory()->NewYield( |
+ get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); |
body->Add(factory()->NewExpressionStatement( |
yield, RelocInfo::kNoPosition), zone()); |
} |
@@ -3758,7 +3753,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { |
int pos = peek_position(); |
Expect(Token::MOD, CHECK_OK); |
// Allow "eval" or "arguments" for backward compatibility. |
- const AstString* name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
+ Handle<String> name = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
ZoneList<Expression*>* args = ParseArguments(CHECK_OK); |
if (extension_ != NULL) { |
@@ -3767,7 +3762,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { |
scope_->DeclarationScope()->ForceEagerCompilation(); |
} |
- const Runtime::Function* function = Runtime::FunctionForName(name->string()); |
+ const Runtime::Function* function = Runtime::FunctionForName(name); |
// Check for built-in IS_VAR macro. |
if (function != NULL && |
@@ -3795,7 +3790,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { |
} |
// Check that the function is defined if it's an inline runtime call. |
- if (function == NULL && name->FirstCharacter() == '_') { |
+ if (function == NULL && name->Get(0) == '_') { |
ParserTraits::ReportMessage("not_defined", name); |
*ok = false; |
return NULL; |
@@ -3807,7 +3802,8 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { |
Literal* Parser::GetLiteralUndefined(int position) { |
- return factory()->NewUndefinedLiteral(position); |
+ return factory()->NewLiteral( |
+ isolate()->factory()->undefined_value(), position); |
} |
@@ -3816,7 +3812,7 @@ void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { |
if (decl != NULL) { |
// In harmony mode we treat conflicting variable bindinds as early |
// errors. See ES5 16 for a definition of early errors. |
- const AstString* name = decl->proxy()->raw_name(); |
+ Handle<String> name = decl->proxy()->name(); |
int position = decl->proxy()->position(); |
Scanner::Location location = position == RelocInfo::kNoPosition |
? Scanner::Location::invalid() |
@@ -3831,7 +3827,7 @@ void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { |
// Parser support |
-bool Parser::TargetStackContainsLabel(const AstString* label) { |
+bool Parser::TargetStackContainsLabel(Handle<String> label) { |
for (Target* t = target_stack_; t != NULL; t = t->previous()) { |
BreakableStatement* stat = t->node()->AsBreakableStatement(); |
if (stat != NULL && ContainsLabel(stat->labels(), label)) |
@@ -3841,9 +3837,8 @@ bool Parser::TargetStackContainsLabel(const AstString* label) { |
} |
-BreakableStatement* Parser::LookupBreakTarget(const AstString* label, |
- bool* ok) { |
- bool anonymous = label == NULL; |
+BreakableStatement* Parser::LookupBreakTarget(Handle<String> label, bool* ok) { |
+ bool anonymous = label.is_null(); |
for (Target* t = target_stack_; t != NULL; t = t->previous()) { |
BreakableStatement* stat = t->node()->AsBreakableStatement(); |
if (stat == NULL) continue; |
@@ -3857,9 +3852,9 @@ BreakableStatement* Parser::LookupBreakTarget(const AstString* label, |
} |
-IterationStatement* Parser::LookupContinueTarget(const AstString* label, |
+IterationStatement* Parser::LookupContinueTarget(Handle<String> label, |
bool* ok) { |
- bool anonymous = label == NULL; |
+ bool anonymous = label.is_null(); |
for (Target* t = target_stack_; t != NULL; t = t->previous()) { |
IterationStatement* stat = t->node()->AsIterationStatement(); |
if (stat == NULL) continue; |
@@ -3886,18 +3881,16 @@ void Parser::RegisterTargetUse(Label* target, Target* stop) { |
void Parser::ThrowPendingError() { |
- ASSERT(ast_value_factory_->IsInternalized()); |
if (has_pending_error_) { |
MessageLocation location(script_, |
pending_error_location_.beg_pos, |
pending_error_location_.end_pos); |
Factory* factory = isolate()->factory(); |
bool has_arg = |
- pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; |
+ !pending_error_arg_.is_null() || pending_error_char_arg_ != NULL; |
Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); |
- if (pending_error_arg_ != NULL) { |
- Handle<String> arg_string = pending_error_arg_->string(); |
- elements->set(0, *arg_string); |
+ if (!pending_error_arg_.is_null()) { |
+ elements->set(0, *(pending_error_arg_.ToHandleChecked())); |
} else if (pending_error_char_arg_ != NULL) { |
Handle<String> arg_string = |
factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) |
@@ -4811,17 +4804,6 @@ bool RegExpParser::ParseRegExp(FlatStringReader* input, |
bool Parser::Parse() { |
ASSERT(info()->function() == NULL); |
FunctionLiteral* result = NULL; |
- ast_value_factory_ = info()->ast_value_factory(); |
- if (ast_value_factory_ == NULL) { |
- ast_value_factory_ = new AstValueFactory(zone()); |
- } |
- if (allow_natives_syntax() || extension_ != NULL) { |
- // If intrinsics are allowed, the Parser cannot operate independent of the |
- // V8 heap because of Rumtime. Tell the string table to internalize strings |
- // and values right after they're created. |
- ast_value_factory_->Internalize(isolate()); |
- } |
- |
if (info()->is_lazy()) { |
ASSERT(!info()->is_eval()); |
if (info()->shared_info()->is_function()) { |
@@ -4847,12 +4829,6 @@ bool Parser::Parse() { |
} |
} |
info()->SetFunction(result); |
- ASSERT(ast_value_factory_->IsInternalized()); |
- // info takes ownership of ast_value_factory_. |
- if (info()->ast_value_factory() == NULL) { |
- info()->SetAstValueFactory(ast_value_factory_); |
- } |
- ast_value_factory_ = NULL; |
return (result != NULL); |
} |