Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: src/parser.cc

Issue 273653002: Parser / PreParser: Simplify error message arguments. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "api.h" 7 #include "api.h"
8 #include "ast.h" 8 #include "ast.h"
9 #include "bootstrapper.h" 9 #include "bootstrapper.h"
10 #include "char-predicates-inl.h" 10 #include "char-predicates-inl.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return Read(PreparseDataConstants::kIsReferenceErrorPos); 293 return Read(PreparseDataConstants::kIsReferenceErrorPos);
294 } 294 }
295 295
296 296
297 const char* ScriptData::BuildMessage() const { 297 const char* ScriptData::BuildMessage() const {
298 unsigned* start = ReadAddress(PreparseDataConstants::kMessageTextPos); 298 unsigned* start = ReadAddress(PreparseDataConstants::kMessageTextPos);
299 return ReadString(start, NULL); 299 return ReadString(start, NULL);
300 } 300 }
301 301
302 302
303 Vector<const char*> ScriptData::BuildArgs() const { 303 const char* ScriptData::BuildArg() const {
304 int arg_count = Read(PreparseDataConstants::kMessageArgCountPos); 304 int arg_count = Read(PreparseDataConstants::kMessageArgCountPos);
305 const char** array = NewArray<const char*>(arg_count); 305 ASSERT(arg_count == 0 || arg_count == 1);
306 if (arg_count == 0) {
307 return NULL;
308 }
306 // Position after text found by skipping past length field and 309 // Position after text found by skipping past length field and
307 // length field content words. 310 // length field content words.
308 int pos = PreparseDataConstants::kMessageTextPos + 1 311 int pos = PreparseDataConstants::kMessageTextPos + 1
309 + Read(PreparseDataConstants::kMessageTextPos); 312 + Read(PreparseDataConstants::kMessageTextPos);
310 for (int i = 0; i < arg_count; i++) { 313 int count = 0;
311 int count = 0; 314 return ReadString(ReadAddress(pos), &count);
312 array[i] = ReadString(ReadAddress(pos), &count);
313 pos += count + 1;
314 }
315 return Vector<const char*>(array, arg_count);
316 } 315 }
317 316
318 317
319 unsigned ScriptData::Read(int position) const { 318 unsigned ScriptData::Read(int position) const {
320 return store_[PreparseDataConstants::kHeaderSize + position]; 319 return store_[PreparseDataConstants::kHeaderSize + position];
321 } 320 }
322 321
323 322
324 unsigned* ScriptData::ReadAddress(int position) const { 323 unsigned* ScriptData::ReadAddress(int position) const {
325 return &store_[PreparseDataConstants::kHeaderSize + position]; 324 return &store_[PreparseDataConstants::kHeaderSize + position];
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 args->Add(parser_->factory()->NewLiteral(type, pos), zone); 615 args->Add(parser_->factory()->NewLiteral(type, pos), zone);
617 args->Add(parser_->factory()->NewLiteral(array, pos), zone); 616 args->Add(parser_->factory()->NewLiteral(array, pos), zone);
618 CallRuntime* call_constructor = 617 CallRuntime* call_constructor =
619 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos); 618 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos);
620 return parser_->factory()->NewThrow(call_constructor, pos); 619 return parser_->factory()->NewThrow(call_constructor, pos);
621 } 620 }
622 621
623 622
624 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 623 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
625 const char* message, 624 const char* message,
626 Vector<const char*> args, 625 const char* arg,
627 bool is_reference_error) { 626 bool is_reference_error) {
628 if (parser_->stack_overflow()) { 627 if (parser_->stack_overflow()) {
629 // Suppress the error message (syntax error or such) in the presence of a 628 // Suppress the error message (syntax error or such) in the presence of a
630 // stack overflow. The isolate allows only one pending exception at at time 629 // stack overflow. The isolate allows only one pending exception at at time
631 // and we want to report the stack overflow later. 630 // and we want to report the stack overflow later.
632 return; 631 return;
633 } 632 }
634 MessageLocation location(parser_->script_, 633 MessageLocation location(parser_->script_,
635 source_location.beg_pos, 634 source_location.beg_pos,
636 source_location.end_pos); 635 source_location.end_pos);
637 Factory* factory = parser_->isolate()->factory(); 636 Factory* factory = parser_->isolate()->factory();
638 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); 637 Handle<FixedArray> elements = factory->NewFixedArray(arg == NULL ? 0 : 1);
639 for (int i = 0; i < args.length(); i++) { 638 if (arg != NULL) {
640 Handle<String> arg_string = 639 Handle<String> arg_string =
641 factory->NewStringFromUtf8(CStrVector(args[i])).ToHandleChecked(); 640 factory->NewStringFromUtf8(CStrVector(arg)).ToHandleChecked();
642 elements->set(i, *arg_string); 641 elements->set(0, *arg_string);
643 } 642 }
644 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); 643 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
645 Handle<Object> result = is_reference_error 644 Handle<Object> result = is_reference_error
646 ? factory->NewReferenceError(message, array) 645 ? factory->NewReferenceError(message, array)
647 : factory->NewSyntaxError(message, array); 646 : factory->NewSyntaxError(message, array);
648 parser_->isolate()->Throw(*result, &location); 647 parser_->isolate()->Throw(*result, &location);
649 } 648 }
650 649
651 650
652 void ParserTraits::ReportMessage(const char* message, 651 void ParserTraits::ReportMessage(const char* message,
653 Vector<Handle<String> > args, 652 MaybeHandle<String> arg,
654 bool is_reference_error) { 653 bool is_reference_error) {
655 Scanner::Location source_location = parser_->scanner()->location(); 654 Scanner::Location source_location = parser_->scanner()->location();
656 ReportMessageAt(source_location, message, args, is_reference_error); 655 ReportMessageAt(source_location, message, arg, is_reference_error);
657 } 656 }
658 657
659 658
660 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 659 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
661 const char* message, 660 const char* message,
662 Vector<Handle<String> > args, 661 MaybeHandle<String> arg,
663 bool is_reference_error) { 662 bool is_reference_error) {
664 if (parser_->stack_overflow()) { 663 if (parser_->stack_overflow()) {
665 // Suppress the error message (syntax error or such) in the presence of a 664 // Suppress the error message (syntax error or such) in the presence of a
666 // stack overflow. The isolate allows only one pending exception at at time 665 // stack overflow. The isolate allows only one pending exception at at time
667 // and we want to report the stack overflow later. 666 // and we want to report the stack overflow later.
668 return; 667 return;
669 } 668 }
670 MessageLocation location(parser_->script_, 669 MessageLocation location(parser_->script_,
671 source_location.beg_pos, 670 source_location.beg_pos,
672 source_location.end_pos); 671 source_location.end_pos);
673 Factory* factory = parser_->isolate()->factory(); 672 Factory* factory = parser_->isolate()->factory();
674 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); 673 Handle<FixedArray> elements = factory->NewFixedArray(arg.is_null() ? 0 : 1);
675 for (int i = 0; i < args.length(); i++) { 674 if (!arg.is_null()) {
676 elements->set(i, *args[i]); 675 elements->set(0, *(arg.ToHandleChecked()));
677 } 676 }
678 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); 677 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
679 Handle<Object> result = is_reference_error 678 Handle<Object> result = is_reference_error
680 ? factory->NewReferenceError(message, array) 679 ? factory->NewReferenceError(message, array)
681 : factory->NewSyntaxError(message, array); 680 : factory->NewSyntaxError(message, array);
682 parser_->isolate()->Throw(*result, &location); 681 parser_->isolate()->Throw(*result, &location);
683 } 682 }
684 683
685 684
686 Handle<String> ParserTraits::GetSymbol(Scanner* scanner) { 685 Handle<String> ParserTraits::GetSymbol(Scanner* scanner) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 910
912 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { 911 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
913 CheckConflictingVarDeclarations(scope_, &ok); 912 CheckConflictingVarDeclarations(scope_, &ok);
914 } 913 }
915 914
916 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 915 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
917 if (body->length() != 1 || 916 if (body->length() != 1 ||
918 !body->at(0)->IsExpressionStatement() || 917 !body->at(0)->IsExpressionStatement() ||
919 !body->at(0)->AsExpressionStatement()-> 918 !body->at(0)->AsExpressionStatement()->
920 expression()->IsFunctionLiteral()) { 919 expression()->IsFunctionLiteral()) {
921 ReportMessage("single_function_literal", Vector<const char*>::empty()); 920 ReportMessage("single_function_literal");
922 ok = false; 921 ok = false;
923 } 922 }
924 } 923 }
925 924
926 if (ok) { 925 if (ok) {
927 result = factory()->NewFunctionLiteral( 926 result = factory()->NewFunctionLiteral(
928 no_name, 927 no_name,
929 scope_, 928 scope_,
930 body, 929 body,
931 function_state.materialized_literal_count(), 930 function_state.materialized_literal_count(),
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1268
1270 Expect(Token::RBRACE, CHECK_OK); 1269 Expect(Token::RBRACE, CHECK_OK);
1271 scope->set_end_position(scanner()->location().end_pos); 1270 scope->set_end_position(scanner()->location().end_pos);
1272 body->set_scope(scope); 1271 body->set_scope(scope);
1273 1272
1274 // Check that all exports are bound. 1273 // Check that all exports are bound.
1275 Interface* interface = scope->interface(); 1274 Interface* interface = scope->interface();
1276 for (Interface::Iterator it = interface->iterator(); 1275 for (Interface::Iterator it = interface->iterator();
1277 !it.done(); it.Advance()) { 1276 !it.done(); it.Advance()) {
1278 if (scope->LocalLookup(it.name()) == NULL) { 1277 if (scope->LocalLookup(it.name()) == NULL) {
1279 Handle<String> name(it.name()); 1278 ParserTraits::ReportMessage("module_export_undefined", it.name());
1280 ParserTraits::ReportMessage("module_export_undefined",
1281 Vector<Handle<String> >(&name, 1));
1282 *ok = false; 1279 *ok = false;
1283 return NULL; 1280 return NULL;
1284 } 1281 }
1285 } 1282 }
1286 1283
1287 interface->MakeModule(ok); 1284 interface->MakeModule(ok);
1288 ASSERT(*ok); 1285 ASSERT(*ok);
1289 interface->Freeze(ok); 1286 interface->Freeze(ok);
1290 ASSERT(*ok); 1287 ASSERT(*ok);
1291 return factory()->NewModuleLiteral(body, interface, pos); 1288 return factory()->NewModuleLiteral(body, interface, pos);
(...skipping 18 matching lines...) Expand all
1310 if (!*ok) { 1307 if (!*ok) {
1311 #ifdef DEBUG 1308 #ifdef DEBUG
1312 if (FLAG_print_interfaces) { 1309 if (FLAG_print_interfaces) {
1313 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray()); 1310 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray());
1314 PrintF("result: "); 1311 PrintF("result: ");
1315 result->interface()->Print(); 1312 result->interface()->Print();
1316 PrintF("member: "); 1313 PrintF("member: ");
1317 member->interface()->Print(); 1314 member->interface()->Print();
1318 } 1315 }
1319 #endif 1316 #endif
1320 ParserTraits::ReportMessage("invalid_module_path", 1317 ParserTraits::ReportMessage("invalid_module_path", name);
1321 Vector<Handle<String> >(&name, 1));
1322 return NULL; 1318 return NULL;
1323 } 1319 }
1324 result = member; 1320 result = member;
1325 } 1321 }
1326 1322
1327 return result; 1323 return result;
1328 } 1324 }
1329 1325
1330 1326
1331 Module* Parser::ParseModuleVariable(bool* ok) { 1327 Module* Parser::ParseModuleVariable(bool* ok) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 Interface* interface = Interface::NewUnknown(zone()); 1417 Interface* interface = Interface::NewUnknown(zone());
1422 module->interface()->Add(names[i], interface, zone(), ok); 1418 module->interface()->Add(names[i], interface, zone(), ok);
1423 if (!*ok) { 1419 if (!*ok) {
1424 #ifdef DEBUG 1420 #ifdef DEBUG
1425 if (FLAG_print_interfaces) { 1421 if (FLAG_print_interfaces) {
1426 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray()); 1422 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray());
1427 PrintF("module: "); 1423 PrintF("module: ");
1428 module->interface()->Print(); 1424 module->interface()->Print();
1429 } 1425 }
1430 #endif 1426 #endif
1431 ParserTraits::ReportMessage("invalid_module_path", 1427 ParserTraits::ReportMessage("invalid_module_path", name);
1432 Vector<Handle<String> >(&name, 1));
1433 return NULL; 1428 return NULL;
1434 } 1429 }
1435 VariableProxy* proxy = NewUnresolved(names[i], LET, interface); 1430 VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
1436 Declaration* declaration = 1431 Declaration* declaration =
1437 factory()->NewImportDeclaration(proxy, module, scope_, pos); 1432 factory()->NewImportDeclaration(proxy, module, scope_, pos);
1438 Declare(declaration, true, CHECK_OK); 1433 Declare(declaration, true, CHECK_OK);
1439 } 1434 }
1440 1435
1441 return block; 1436 return block;
1442 } 1437 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 // the special case 1705 // the special case
1711 // 1706 //
1712 // function () { let x; { var x; } } 1707 // function () { let x; { var x; } }
1713 // 1708 //
1714 // because the var declaration is hoisted to the function scope where 'x' 1709 // because the var declaration is hoisted to the function scope where 'x'
1715 // is already bound. 1710 // is already bound.
1716 ASSERT(IsDeclaredVariableMode(var->mode())); 1711 ASSERT(IsDeclaredVariableMode(var->mode()));
1717 if (allow_harmony_scoping() && strict_mode() == STRICT) { 1712 if (allow_harmony_scoping() && strict_mode() == STRICT) {
1718 // In harmony we treat re-declarations as early errors. See 1713 // In harmony we treat re-declarations as early errors. See
1719 // ES5 16 for a definition of early errors. 1714 // ES5 16 for a definition of early errors.
1720 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); 1715 ParserTraits::ReportMessage("var_redeclaration", name);
1721 const char* elms[1] = { c_string.get() };
1722 Vector<const char*> args(elms, 1);
1723 ReportMessage("var_redeclaration", args);
1724 *ok = false; 1716 *ok = false;
1725 return; 1717 return;
1726 } 1718 }
1727 Expression* expression = NewThrowTypeError( 1719 Expression* expression = NewThrowTypeError(
1728 "var_redeclaration", name, declaration->position()); 1720 "var_redeclaration", name, declaration->position());
1729 declaration_scope->SetIllegalRedeclaration(expression); 1721 declaration_scope->SetIllegalRedeclaration(expression);
1730 } 1722 }
1731 } 1723 }
1732 1724
1733 // We add a declaration node for every declaration. The compiler 1725 // We add a declaration node for every declaration. The compiler
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 if (!ok) { 1797 if (!ok) {
1806 #ifdef DEBUG 1798 #ifdef DEBUG
1807 if (FLAG_print_interfaces) { 1799 if (FLAG_print_interfaces) {
1808 PrintF("DECLARE TYPE ERROR\n"); 1800 PrintF("DECLARE TYPE ERROR\n");
1809 PrintF("proxy: "); 1801 PrintF("proxy: ");
1810 proxy->interface()->Print(); 1802 proxy->interface()->Print();
1811 PrintF("var: "); 1803 PrintF("var: ");
1812 var->interface()->Print(); 1804 var->interface()->Print();
1813 } 1805 }
1814 #endif 1806 #endif
1815 ParserTraits::ReportMessage("module_type_error", 1807 ParserTraits::ReportMessage("module_type_error", name);
1816 Vector<Handle<String> >(&name, 1));
1817 } 1808 }
1818 } 1809 }
1819 } 1810 }
1820 } 1811 }
1821 1812
1822 1813
1823 // Language extension which is only enabled for source files loaded 1814 // Language extension which is only enabled for source files loaded
1824 // through the API's extension mechanism. A native function 1815 // through the API's extension mechanism. A native function
1825 // declaration is resolved by looking up the function through a 1816 // declaration is resolved by looking up the function through a
1826 // callback provided by the extension. 1817 // callback provided by the extension.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 switch (strict_mode()) { 2016 switch (strict_mode()) {
2026 case SLOPPY: 2017 case SLOPPY:
2027 mode = CONST_LEGACY; 2018 mode = CONST_LEGACY;
2028 init_op = Token::INIT_CONST_LEGACY; 2019 init_op = Token::INIT_CONST_LEGACY;
2029 break; 2020 break;
2030 case STRICT: 2021 case STRICT:
2031 if (allow_harmony_scoping()) { 2022 if (allow_harmony_scoping()) {
2032 if (var_context == kStatement) { 2023 if (var_context == kStatement) {
2033 // In strict mode 'const' declarations are only allowed in source 2024 // In strict mode 'const' declarations are only allowed in source
2034 // element positions. 2025 // element positions.
2035 ReportMessage("unprotected_const", Vector<const char*>::empty()); 2026 ReportMessage("unprotected_const");
2036 *ok = false; 2027 *ok = false;
2037 return NULL; 2028 return NULL;
2038 } 2029 }
2039 mode = CONST; 2030 mode = CONST;
2040 init_op = Token::INIT_CONST; 2031 init_op = Token::INIT_CONST;
2041 } else { 2032 } else {
2042 ReportMessage("strict_const", Vector<const char*>::empty()); 2033 ReportMessage("strict_const");
2043 *ok = false; 2034 *ok = false;
2044 return NULL; 2035 return NULL;
2045 } 2036 }
2046 } 2037 }
2047 is_const = true; 2038 is_const = true;
2048 needs_init = true; 2039 needs_init = true;
2049 } else if (peek() == Token::LET) { 2040 } else if (peek() == Token::LET) {
2050 // ES6 Draft Rev4 section 12.2.1: 2041 // ES6 Draft Rev4 section 12.2.1:
2051 // 2042 //
2052 // LetDeclaration : let LetBindingList ; 2043 // LetDeclaration : let LetBindingList ;
2053 // 2044 //
2054 // * It is a Syntax Error if the code that matches this production is not 2045 // * It is a Syntax Error if the code that matches this production is not
2055 // contained in extended code. 2046 // contained in extended code.
2056 // 2047 //
2057 // TODO(rossberg): make 'let' a legal identifier in sloppy mode. 2048 // TODO(rossberg): make 'let' a legal identifier in sloppy mode.
2058 if (!allow_harmony_scoping() || strict_mode() == SLOPPY) { 2049 if (!allow_harmony_scoping() || strict_mode() == SLOPPY) {
2059 ReportMessage("illegal_let", Vector<const char*>::empty()); 2050 ReportMessage("illegal_let");
2060 *ok = false; 2051 *ok = false;
2061 return NULL; 2052 return NULL;
2062 } 2053 }
2063 Consume(Token::LET); 2054 Consume(Token::LET);
2064 if (var_context == kStatement) { 2055 if (var_context == kStatement) {
2065 // Let declarations are only allowed in source element positions. 2056 // Let declarations are only allowed in source element positions.
2066 ReportMessage("unprotected_let", Vector<const char*>::empty()); 2057 ReportMessage("unprotected_let");
2067 *ok = false; 2058 *ok = false;
2068 return NULL; 2059 return NULL;
2069 } 2060 }
2070 mode = LET; 2061 mode = LET;
2071 needs_init = true; 2062 needs_init = true;
2072 init_op = Token::INIT_LET; 2063 init_op = Token::INIT_LET;
2073 } else { 2064 } else {
2074 UNREACHABLE(); // by current callers 2065 UNREACHABLE(); // by current callers
2075 } 2066 }
2076 2067
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 // Expression is a single identifier, and not, e.g., a parenthesized 2317 // Expression is a single identifier, and not, e.g., a parenthesized
2327 // identifier. 2318 // identifier.
2328 VariableProxy* var = expr->AsVariableProxy(); 2319 VariableProxy* var = expr->AsVariableProxy();
2329 Handle<String> label = var->name(); 2320 Handle<String> label = var->name();
2330 // TODO(1240780): We don't check for redeclaration of labels 2321 // TODO(1240780): We don't check for redeclaration of labels
2331 // during preparsing since keeping track of the set of active 2322 // during preparsing since keeping track of the set of active
2332 // labels requires nontrivial changes to the way scopes are 2323 // labels requires nontrivial changes to the way scopes are
2333 // structured. However, these are probably changes we want to 2324 // structured. However, these are probably changes we want to
2334 // make later anyway so we should go back and fix this then. 2325 // make later anyway so we should go back and fix this then.
2335 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 2326 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
2336 SmartArrayPointer<char> c_string = label->ToCString(DISALLOW_NULLS); 2327 ParserTraits::ReportMessage("label_redeclaration", label);
2337 const char* elms[1] = { c_string.get() };
2338 Vector<const char*> args(elms, 1);
2339 ReportMessage("label_redeclaration", args);
2340 *ok = false; 2328 *ok = false;
2341 return NULL; 2329 return NULL;
2342 } 2330 }
2343 if (labels == NULL) { 2331 if (labels == NULL) {
2344 labels = new(zone()) ZoneStringList(4, zone()); 2332 labels = new(zone()) ZoneStringList(4, zone());
2345 } 2333 }
2346 labels->Add(label, zone()); 2334 labels->Add(label, zone());
2347 // Remove the "ghost" variable that turned out to be a label 2335 // Remove the "ghost" variable that turned out to be a label
2348 // from the top scope. This way, we don't try to resolve it 2336 // from the top scope. This way, we don't try to resolve it
2349 // during the scope processing. 2337 // during the scope processing.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2402 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2415 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2403 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2416 // ECMA allows "eval" or "arguments" as labels even in strict mode. 2404 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2417 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 2405 label = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
2418 } 2406 }
2419 IterationStatement* target = NULL; 2407 IterationStatement* target = NULL;
2420 target = LookupContinueTarget(label, CHECK_OK); 2408 target = LookupContinueTarget(label, CHECK_OK);
2421 if (target == NULL) { 2409 if (target == NULL) {
2422 // Illegal continue statement. 2410 // Illegal continue statement.
2423 const char* message = "illegal_continue"; 2411 const char* message = "illegal_continue";
2424 Vector<Handle<String> > args;
2425 if (!label.is_null()) { 2412 if (!label.is_null()) {
2426 message = "unknown_label"; 2413 message = "unknown_label";
2427 args = Vector<Handle<String> >(&label, 1);
2428 } 2414 }
2429 ParserTraits::ReportMessageAt(scanner()->location(), message, args); 2415 ParserTraits::ReportMessageAt(scanner()->location(), message, label);
2430 *ok = false; 2416 *ok = false;
2431 return NULL; 2417 return NULL;
2432 } 2418 }
2433 ExpectSemicolon(CHECK_OK); 2419 ExpectSemicolon(CHECK_OK);
2434 return factory()->NewContinueStatement(target, pos); 2420 return factory()->NewContinueStatement(target, pos);
2435 } 2421 }
2436 2422
2437 2423
2438 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 2424 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
2439 // BreakStatement :: 2425 // BreakStatement ::
(...skipping 12 matching lines...) Expand all
2452 // empty statements, e.g. 'l1: l2: l3: break l2;' 2438 // empty statements, e.g. 'l1: l2: l3: break l2;'
2453 if (!label.is_null() && ContainsLabel(labels, label)) { 2439 if (!label.is_null() && ContainsLabel(labels, label)) {
2454 ExpectSemicolon(CHECK_OK); 2440 ExpectSemicolon(CHECK_OK);
2455 return factory()->NewEmptyStatement(pos); 2441 return factory()->NewEmptyStatement(pos);
2456 } 2442 }
2457 BreakableStatement* target = NULL; 2443 BreakableStatement* target = NULL;
2458 target = LookupBreakTarget(label, CHECK_OK); 2444 target = LookupBreakTarget(label, CHECK_OK);
2459 if (target == NULL) { 2445 if (target == NULL) {
2460 // Illegal break statement. 2446 // Illegal break statement.
2461 const char* message = "illegal_break"; 2447 const char* message = "illegal_break";
2462 Vector<Handle<String> > args;
2463 if (!label.is_null()) { 2448 if (!label.is_null()) {
2464 message = "unknown_label"; 2449 message = "unknown_label";
2465 args = Vector<Handle<String> >(&label, 1);
2466 } 2450 }
2467 ParserTraits::ReportMessageAt(scanner()->location(), message, args); 2451 ParserTraits::ReportMessageAt(scanner()->location(), message, label);
2468 *ok = false; 2452 *ok = false;
2469 return NULL; 2453 return NULL;
2470 } 2454 }
2471 ExpectSemicolon(CHECK_OK); 2455 ExpectSemicolon(CHECK_OK);
2472 return factory()->NewBreakStatement(target, pos); 2456 return factory()->NewBreakStatement(target, pos);
2473 } 2457 }
2474 2458
2475 2459
2476 Statement* Parser::ParseReturnStatement(bool* ok) { 2460 Statement* Parser::ParseReturnStatement(bool* ok) {
2477 // ReturnStatement :: 2461 // ReturnStatement ::
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 2500
2517 2501
2518 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 2502 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
2519 // WithStatement :: 2503 // WithStatement ::
2520 // 'with' '(' Expression ')' Statement 2504 // 'with' '(' Expression ')' Statement
2521 2505
2522 Expect(Token::WITH, CHECK_OK); 2506 Expect(Token::WITH, CHECK_OK);
2523 int pos = position(); 2507 int pos = position();
2524 2508
2525 if (strict_mode() == STRICT) { 2509 if (strict_mode() == STRICT) {
2526 ReportMessage("strict_mode_with", Vector<const char*>::empty()); 2510 ReportMessage("strict_mode_with");
2527 *ok = false; 2511 *ok = false;
2528 return NULL; 2512 return NULL;
2529 } 2513 }
2530 2514
2531 Expect(Token::LPAREN, CHECK_OK); 2515 Expect(Token::LPAREN, CHECK_OK);
2532 Expression* expr = ParseExpression(true, CHECK_OK); 2516 Expression* expr = ParseExpression(true, CHECK_OK);
2533 Expect(Token::RPAREN, CHECK_OK); 2517 Expect(Token::RPAREN, CHECK_OK);
2534 2518
2535 scope_->DeclarationScope()->RecordWithStatement(); 2519 scope_->DeclarationScope()->RecordWithStatement();
2536 Scope* with_scope = NewScope(scope_, WITH_SCOPE); 2520 Scope* with_scope = NewScope(scope_, WITH_SCOPE);
(...skipping 12 matching lines...) Expand all
2549 // 'case' Expression ':' Statement* 2533 // 'case' Expression ':' Statement*
2550 // 'default' ':' Statement* 2534 // 'default' ':' Statement*
2551 2535
2552 Expression* label = NULL; // NULL expression indicates default case 2536 Expression* label = NULL; // NULL expression indicates default case
2553 if (peek() == Token::CASE) { 2537 if (peek() == Token::CASE) {
2554 Expect(Token::CASE, CHECK_OK); 2538 Expect(Token::CASE, CHECK_OK);
2555 label = ParseExpression(true, CHECK_OK); 2539 label = ParseExpression(true, CHECK_OK);
2556 } else { 2540 } else {
2557 Expect(Token::DEFAULT, CHECK_OK); 2541 Expect(Token::DEFAULT, CHECK_OK);
2558 if (*default_seen_ptr) { 2542 if (*default_seen_ptr) {
2559 ReportMessage("multiple_defaults_in_switch", 2543 ReportMessage("multiple_defaults_in_switch");
2560 Vector<const char*>::empty());
2561 *ok = false; 2544 *ok = false;
2562 return NULL; 2545 return NULL;
2563 } 2546 }
2564 *default_seen_ptr = true; 2547 *default_seen_ptr = true;
2565 } 2548 }
2566 Expect(Token::COLON, CHECK_OK); 2549 Expect(Token::COLON, CHECK_OK);
2567 int pos = position(); 2550 int pos = position();
2568 ZoneList<Statement*>* statements = 2551 ZoneList<Statement*>* statements =
2569 new(zone()) ZoneList<Statement*>(5, zone()); 2552 new(zone()) ZoneList<Statement*>(5, zone());
2570 while (peek() != Token::CASE && 2553 while (peek() != Token::CASE &&
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2606 } 2589 }
2607 2590
2608 2591
2609 Statement* Parser::ParseThrowStatement(bool* ok) { 2592 Statement* Parser::ParseThrowStatement(bool* ok) {
2610 // ThrowStatement :: 2593 // ThrowStatement ::
2611 // 'throw' Expression ';' 2594 // 'throw' Expression ';'
2612 2595
2613 Expect(Token::THROW, CHECK_OK); 2596 Expect(Token::THROW, CHECK_OK);
2614 int pos = position(); 2597 int pos = position();
2615 if (scanner()->HasAnyLineTerminatorBeforeNext()) { 2598 if (scanner()->HasAnyLineTerminatorBeforeNext()) {
2616 ReportMessage("newline_after_throw", Vector<const char*>::empty()); 2599 ReportMessage("newline_after_throw");
2617 *ok = false; 2600 *ok = false;
2618 return NULL; 2601 return NULL;
2619 } 2602 }
2620 Expression* exception = ParseExpression(true, CHECK_OK); 2603 Expression* exception = ParseExpression(true, CHECK_OK);
2621 ExpectSemicolon(CHECK_OK); 2604 ExpectSemicolon(CHECK_OK);
2622 2605
2623 return factory()->NewExpressionStatement( 2606 return factory()->NewExpressionStatement(
2624 factory()->NewThrow(exception, pos), pos); 2607 factory()->NewThrow(exception, pos), pos);
2625 } 2608 }
2626 2609
(...skipping 15 matching lines...) Expand all
2642 2625
2643 TargetCollector try_collector(zone()); 2626 TargetCollector try_collector(zone());
2644 Block* try_block; 2627 Block* try_block;
2645 2628
2646 { Target target(&this->target_stack_, &try_collector); 2629 { Target target(&this->target_stack_, &try_collector);
2647 try_block = ParseBlock(NULL, CHECK_OK); 2630 try_block = ParseBlock(NULL, CHECK_OK);
2648 } 2631 }
2649 2632
2650 Token::Value tok = peek(); 2633 Token::Value tok = peek();
2651 if (tok != Token::CATCH && tok != Token::FINALLY) { 2634 if (tok != Token::CATCH && tok != Token::FINALLY) {
2652 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); 2635 ReportMessage("no_catch_or_finally");
2653 *ok = false; 2636 *ok = false;
2654 return NULL; 2637 return NULL;
2655 } 2638 }
2656 2639
2657 // If we can break out from the catch block and there is a finally block, 2640 // If we can break out from the catch block and there is a finally block,
2658 // then we will need to collect escaping targets from the catch 2641 // then we will need to collect escaping targets from the catch
2659 // block. Since we don't know yet if there will be a finally block, we 2642 // block. Since we don't know yet if there will be a finally block, we
2660 // always collect the targets. 2643 // always collect the targets.
2661 TargetCollector catch_collector(zone()); 2644 TargetCollector catch_collector(zone());
2662 Scope* catch_scope = NULL; 2645 Scope* catch_scope = NULL;
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
3072 // 'debugger' ';' 3055 // 'debugger' ';'
3073 3056
3074 int pos = peek_position(); 3057 int pos = peek_position();
3075 Expect(Token::DEBUGGER, CHECK_OK); 3058 Expect(Token::DEBUGGER, CHECK_OK);
3076 ExpectSemicolon(CHECK_OK); 3059 ExpectSemicolon(CHECK_OK);
3077 return factory()->NewDebuggerStatement(pos); 3060 return factory()->NewDebuggerStatement(pos);
3078 } 3061 }
3079 3062
3080 3063
3081 void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) { 3064 void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) {
3082 SmartArrayPointer<char> name_string = name->ToCString(DISALLOW_NULLS); 3065 ParserTraits::ReportMessage("invalid_cached_data_function", name);
3083 const char* element[1] = { name_string.get() };
3084 ReportMessage("invalid_cached_data_function",
3085 Vector<const char*>(element, 1));
3086 *ok = false; 3066 *ok = false;
3087 } 3067 }
3088 3068
3089 3069
3090 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 3070 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
3091 if (expression->AsLiteral() != NULL) return true; 3071 if (expression->AsLiteral() != NULL) return true;
3092 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); 3072 MaterializedLiteral* lit = expression->AsMaterializedLiteral();
3093 return lit != NULL && lit->is_simple(); 3073 return lit != NULL && lit->is_simple();
3094 } 3074 }
3095 3075
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
3445 SingletonLogger logger; 3425 SingletonLogger logger;
3446 PreParser::PreParseResult result = 3426 PreParser::PreParseResult result =
3447 ParseLazyFunctionBodyWithPreParser(&logger); 3427 ParseLazyFunctionBodyWithPreParser(&logger);
3448 if (result == PreParser::kPreParseStackOverflow) { 3428 if (result == PreParser::kPreParseStackOverflow) {
3449 // Propagate stack overflow. 3429 // Propagate stack overflow.
3450 set_stack_overflow(); 3430 set_stack_overflow();
3451 *ok = false; 3431 *ok = false;
3452 return; 3432 return;
3453 } 3433 }
3454 if (logger.has_error()) { 3434 if (logger.has_error()) {
3455 const char* arg = logger.argument_opt();
3456 Vector<const char*> args;
3457 if (arg != NULL) {
3458 args = Vector<const char*>(&arg, 1);
3459 }
3460 ParserTraits::ReportMessageAt( 3435 ParserTraits::ReportMessageAt(
3461 Scanner::Location(logger.start(), logger.end()), 3436 Scanner::Location(logger.start(), logger.end()),
3462 logger.message(), args, logger.is_reference_error()); 3437 logger.message(), logger.argument_opt(), logger.is_reference_error());
3463 *ok = false; 3438 *ok = false;
3464 return; 3439 return;
3465 } 3440 }
3466 scope_->set_end_position(logger.end()); 3441 scope_->set_end_position(logger.end());
3467 Expect(Token::RBRACE, ok); 3442 Expect(Token::RBRACE, ok);
3468 if (!*ok) { 3443 if (!*ok) {
3469 return; 3444 return;
3470 } 3445 }
3471 isolate()->counters()->total_preparse_skipped()->Increment( 3446 isolate()->counters()->total_preparse_skipped()->Increment(
3472 scope_->end_position() - function_block_pos); 3447 scope_->end_position() - function_block_pos);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
3591 // Check for built-in IS_VAR macro. 3566 // Check for built-in IS_VAR macro.
3592 if (function != NULL && 3567 if (function != NULL &&
3593 function->intrinsic_type == Runtime::RUNTIME && 3568 function->intrinsic_type == Runtime::RUNTIME &&
3594 function->function_id == Runtime::kIS_VAR) { 3569 function->function_id == Runtime::kIS_VAR) {
3595 // %IS_VAR(x) evaluates to x if x is a variable, 3570 // %IS_VAR(x) evaluates to x if x is a variable,
3596 // leads to a parse error otherwise. Could be implemented as an 3571 // leads to a parse error otherwise. Could be implemented as an
3597 // inline function %_IS_VAR(x) to eliminate this special case. 3572 // inline function %_IS_VAR(x) to eliminate this special case.
3598 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) { 3573 if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) {
3599 return args->at(0); 3574 return args->at(0);
3600 } else { 3575 } else {
3601 ReportMessage("not_isvar", Vector<const char*>::empty()); 3576 ReportMessage("not_isvar");
3602 *ok = false; 3577 *ok = false;
3603 return NULL; 3578 return NULL;
3604 } 3579 }
3605 } 3580 }
3606 3581
3607 // Check that the expected number of arguments are being passed. 3582 // Check that the expected number of arguments are being passed.
3608 if (function != NULL && 3583 if (function != NULL &&
3609 function->nargs != -1 && 3584 function->nargs != -1 &&
3610 function->nargs != args->length()) { 3585 function->nargs != args->length()) {
3611 ReportMessage("illegal_access", Vector<const char*>::empty()); 3586 ReportMessage("illegal_access");
3612 *ok = false; 3587 *ok = false;
3613 return NULL; 3588 return NULL;
3614 } 3589 }
3615 3590
3616 // Check that the function is defined if it's an inline runtime call. 3591 // Check that the function is defined if it's an inline runtime call.
3617 if (function == NULL && name->Get(0) == '_') { 3592 if (function == NULL && name->Get(0) == '_') {
3618 ParserTraits::ReportMessage("not_defined", 3593 ParserTraits::ReportMessage("not_defined", name);
3619 Vector<Handle<String> >(&name, 1));
3620 *ok = false; 3594 *ok = false;
3621 return NULL; 3595 return NULL;
3622 } 3596 }
3623 3597
3624 // We have a valid intrinsics call or a call to a builtin. 3598 // We have a valid intrinsics call or a call to a builtin.
3625 return factory()->NewCallRuntime(name, function, args, pos); 3599 return factory()->NewCallRuntime(name, function, args, pos);
3626 } 3600 }
3627 3601
3628 3602
3629 Literal* Parser::GetLiteralUndefined(int position) { 3603 Literal* Parser::GetLiteralUndefined(int position) {
3630 return factory()->NewLiteral( 3604 return factory()->NewLiteral(
3631 isolate()->factory()->undefined_value(), position); 3605 isolate()->factory()->undefined_value(), position);
3632 } 3606 }
3633 3607
3634 3608
3635 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { 3609 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
3636 Declaration* decl = scope->CheckConflictingVarDeclarations(); 3610 Declaration* decl = scope->CheckConflictingVarDeclarations();
3637 if (decl != NULL) { 3611 if (decl != NULL) {
3638 // In harmony mode we treat conflicting variable bindinds as early 3612 // In harmony mode we treat conflicting variable bindinds as early
3639 // errors. See ES5 16 for a definition of early errors. 3613 // errors. See ES5 16 for a definition of early errors.
3640 Handle<String> name = decl->proxy()->name(); 3614 Handle<String> name = decl->proxy()->name();
3641 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS);
3642 const char* elms[1] = { c_string.get() };
3643 Vector<const char*> args(elms, 1);
3644 int position = decl->proxy()->position(); 3615 int position = decl->proxy()->position();
3645 Scanner::Location location = position == RelocInfo::kNoPosition 3616 Scanner::Location location = position == RelocInfo::kNoPosition
3646 ? Scanner::Location::invalid() 3617 ? Scanner::Location::invalid()
3647 : Scanner::Location(position, position + 1); 3618 : Scanner::Location(position, position + 1);
3648 ParserTraits::ReportMessageAt(location, "var_redeclaration", args); 3619 ParserTraits::ReportMessageAt(location, "var_redeclaration", name);
3649 *ok = false; 3620 *ok = false;
3650 } 3621 }
3651 } 3622 }
3652 3623
3653 3624
3654 // ---------------------------------------------------------------------------- 3625 // ----------------------------------------------------------------------------
3655 // Parser support 3626 // Parser support
3656 3627
3657 3628
3658 bool Parser::TargetStackContainsLabel(Handle<String> label) { 3629 bool Parser::TargetStackContainsLabel(Handle<String> label) {
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
4613 } else { 4584 } else {
4614 result = ParseProgram(); 4585 result = ParseProgram();
4615 } 4586 }
4616 } else { 4587 } else {
4617 SetCachedData(info()->cached_data(), info()->cached_data_mode()); 4588 SetCachedData(info()->cached_data(), info()->cached_data_mode());
4618 if (info()->cached_data_mode() == CONSUME_CACHED_DATA && 4589 if (info()->cached_data_mode() == CONSUME_CACHED_DATA &&
4619 (*info()->cached_data())->has_error()) { 4590 (*info()->cached_data())->has_error()) {
4620 ScriptData* cached_data = *(info()->cached_data()); 4591 ScriptData* cached_data = *(info()->cached_data());
4621 Scanner::Location loc = cached_data->MessageLocation(); 4592 Scanner::Location loc = cached_data->MessageLocation();
4622 const char* message = cached_data->BuildMessage(); 4593 const char* message = cached_data->BuildMessage();
4623 Vector<const char*> args = cached_data->BuildArgs(); 4594 const char* arg = cached_data->BuildArg();
4624 ParserTraits::ReportMessageAt(loc, message, args, 4595 ParserTraits::ReportMessageAt(loc, message, arg,
4625 cached_data->IsReferenceError()); 4596 cached_data->IsReferenceError());
4626 DeleteArray(message); 4597 DeleteArray(message);
4627 for (int i = 0; i < args.length(); i++) { 4598 DeleteArray(arg);
4628 DeleteArray(args[i]);
4629 }
4630 DeleteArray(args.start());
4631 ASSERT(info()->isolate()->has_pending_exception()); 4599 ASSERT(info()->isolate()->has_pending_exception());
4632 } else { 4600 } else {
4633 result = ParseProgram(); 4601 result = ParseProgram();
4634 } 4602 }
4635 } 4603 }
4636 info()->SetFunction(result); 4604 info()->SetFunction(result);
4637 return (result != NULL); 4605 return (result != NULL);
4638 } 4606 }
4639 4607
4640 } } // namespace v8::internal 4608 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698