Reviewers: ulan,
Message:
ulan, ptal. This one is less complex than the previous ones.
Description:
Tests and fixes for (pre)parse errors related to future reserved words.
This contains the following fixes:
- PreParser was using an error "reserved_word" which doesn't exist in
messages.js. Changed it to "unexpected_reserved".
BUG=3126
LOG=N
[email protected]
Please review this at https://codereview.chromium.org/153793002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+49, -3 lines):
M src/preparser.cc
M test/cctest/test-parsing.cc
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index
21010ae6d2ca5360de77ffe2f7f0a130db7cafb7..b3a271a8c63f65edec7758dca1e23a6d37720d5b
100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -1497,7 +1497,7 @@ PreParser::Identifier
PreParser::ParseIdentifier(bool* ok) {
case Token::FUTURE_RESERVED_WORD: {
Scanner::Location location = scanner()->location();
ReportMessageAt(location.beg_pos, location.end_pos,
- "reserved_word", NULL);
+ "unexpected_reserved", NULL);
*ok = false;
return GetIdentifierSymbol();
}
@@ -1565,7 +1565,7 @@ void
PreParser::StrictModeIdentifierViolation(Scanner::Location location,
bool* ok) {
const char* type = eval_args_type;
if (identifier.IsFutureReserved()) {
- type = "reserved_word";
+ type = "unexpected_reserved";
} else if (identifier.IsFutureStrictReserved() || identifier.IsYield()) {
type = "unexpected_strict_reserved";
}
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index
e5cddbf46a00ca2358a71974dac966bdb497b4b3..63110743926514fb8485474ee8a4b04f79df059b
100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1383,6 +1383,9 @@ const char* strict_var_name_preparse
= "strict_var_name";
const char* strict_var_name_parse =
"SyntaxError: Variable name may not be eval or arguments in strict
mode";
+const char* unexpected_reserved_preparse = "unexpected_reserved";
+const char* unexpected_reserved_parse = "SyntaxError: Unexpected reserved
word";
+
const char* unexpected_strict_reserved_preparse
= "unexpected_strict_reserved";
const char* unexpected_strict_reserved_parse =
"SyntaxError: Unexpected strict mode reserved word";
@@ -1555,7 +1558,6 @@ TEST(ErrorsFutureStrictReservedWords) {
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
- const char* use_strict_prefix = "\"use strict\";\n";
int prefix_length = i::StrLength(use_strict_prefix);
ParseErrorTestCase test_cases[] = {
@@ -1640,3 +1642,47 @@ TEST(ErrorsFutureStrictReservedWords) {
scoped_test_cases[i].parse_error_message);
}
}
+
+
+TEST(ErrorsReservedWords) {
+ // Tests that both preparsing and parsing produce the right kind of
errors for
+ // using future reserved words as identifiers. These tests don't depend
on the
+ // strict mode.
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope handles(isolate);
+ v8::Local<v8::Context> context = v8::Context::New(isolate);
+ v8::Context::Scope context_scope(context);
+
+ ParseErrorTestCase test_cases[] = {
+ {"var super = 42;", 4, 9, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {"var foo, super;", 9, 14, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {"try { } catch (super) { }", 15, 20, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {"function super() { }", 9, 14, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {"function foo(super) { }", 13, 18, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {"function foo(bar, super) { }", 18, 23, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {"super = 1;", 0, 5, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {"++super;", 2, 7, unexpected_reserved_preparse,
unexpected_reserved_parse},
+ {"super++;", 0, 5, unexpected_reserved_preparse,
unexpected_reserved_parse},
+ {"function foo super", 13, 18, unexpected_reserved_preparse,
+ unexpected_reserved_parse},
+ {NULL, 0, 0, NULL, NULL}
+ };
+
+ for (int i = 0; test_cases[i].source; ++i) {
+ v8::Handle<v8::String> source =
+ v8::String::NewFromUtf8(isolate, test_cases[i].source);
+ VerifyPreParseAndParseErrorMessages(
+ source,
+ test_cases[i].error_location_beg,
+ test_cases[i].error_location_end,
+ test_cases[i].preparse_error_message,
+ test_cases[i].parse_error_message);
+ }
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.