Commit 11b8551f authored by marja@chromium.org's avatar marja@chromium.org

Parser / PreParser: Simplify error message arguments.

In some places, we pretended that there can be multiple arguments, though in
practice there was only one. In other places (most importantly, PreParser), we
only handled one argument. (This means that we were not able to produce a
multi-argument error inside a lazy function anyway.)

This CL makes it clear that there is ever only one argument.

R=ulan@chromium.org
BUG=

Review URL: https://codereview.chromium.org/273653002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21324 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fb5492d6
This diff is collapsed.
...@@ -89,7 +89,7 @@ class ScriptData { ...@@ -89,7 +89,7 @@ class ScriptData {
Scanner::Location MessageLocation() const; Scanner::Location MessageLocation() const;
bool IsReferenceError() const; bool IsReferenceError() const;
const char* BuildMessage() const; const char* BuildMessage() const;
Vector<const char*> BuildArgs() const; const char* BuildArg() const;
int function_count() { int function_count() {
int functions_size = int functions_size =
...@@ -515,14 +515,14 @@ class ParserTraits { ...@@ -515,14 +515,14 @@ class ParserTraits {
// Reporting errors. // Reporting errors.
void ReportMessageAt(Scanner::Location source_location, void ReportMessageAt(Scanner::Location source_location,
const char* message, const char* message,
Vector<const char*> args, const char* arg,
bool is_reference_error = false); bool is_reference_error = false);
void ReportMessage(const char* message, void ReportMessage(const char* message,
Vector<Handle<String> > args, MaybeHandle<String> arg,
bool is_reference_error = false); bool is_reference_error = false);
void ReportMessageAt(Scanner::Location source_location, void ReportMessageAt(Scanner::Location source_location,
const char* message, const char* message,
Vector<Handle<String> > args, MaybeHandle<String> arg,
bool is_reference_error = false); bool is_reference_error = false);
// "null" return type creators. // "null" return type creators.
......
...@@ -35,31 +35,22 @@ namespace internal { ...@@ -35,31 +35,22 @@ namespace internal {
void PreParserTraits::ReportMessageAt(Scanner::Location location, void PreParserTraits::ReportMessageAt(Scanner::Location location,
const char* message, const char* message,
Vector<const char*> args, const char* arg,
bool is_reference_error) { bool is_reference_error) {
ReportMessageAt(location.beg_pos, ReportMessageAt(location.beg_pos,
location.end_pos, location.end_pos,
message, message,
args.length() > 0 ? args[0] : NULL, arg,
is_reference_error); is_reference_error);
} }
void PreParserTraits::ReportMessageAt(Scanner::Location location,
const char* type,
const char* name_opt,
bool is_reference_error) {
pre_parser_->log_->LogMessage(location.beg_pos, location.end_pos, type,
name_opt, is_reference_error);
}
void PreParserTraits::ReportMessageAt(int start_pos, void PreParserTraits::ReportMessageAt(int start_pos,
int end_pos, int end_pos,
const char* type, const char* message,
const char* name_opt, const char* arg,
bool is_reference_error) { bool is_reference_error) {
pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt, pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg,
is_reference_error); is_reference_error);
} }
...@@ -294,8 +285,7 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) { ...@@ -294,8 +285,7 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) {
if (strict_mode() == STRICT) { if (strict_mode() == STRICT) {
PreParserTraits::ReportMessageAt(start_location.beg_pos, PreParserTraits::ReportMessageAt(start_location.beg_pos,
end_location.end_pos, end_location.end_pos,
"strict_function", "strict_function");
NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} else { } else {
......
...@@ -348,16 +348,15 @@ class ParserBase : public Traits { ...@@ -348,16 +348,15 @@ class ParserBase : public Traits {
bool is_generator() const { return function_state_->is_generator(); } bool is_generator() const { return function_state_->is_generator(); }
// Report syntax errors. // Report syntax errors.
void ReportMessage(const char* message, Vector<const char*> args, void ReportMessage(const char* message, const char* arg = NULL,
bool is_reference_error = false) { bool is_reference_error = false) {
Scanner::Location source_location = scanner()->location(); Scanner::Location source_location = scanner()->location();
Traits::ReportMessageAt(source_location, message, args, is_reference_error); Traits::ReportMessageAt(source_location, message, arg, is_reference_error);
} }
void ReportMessageAt(Scanner::Location location, const char* message, void ReportMessageAt(Scanner::Location location, const char* message,
bool is_reference_error = false) { bool is_reference_error = false) {
Traits::ReportMessageAt(location, message, Vector<const char*>::empty(), Traits::ReportMessageAt(location, message, NULL, is_reference_error);
is_reference_error);
} }
void ReportUnexpectedToken(Token::Value token); void ReportUnexpectedToken(Token::Value token);
...@@ -968,16 +967,12 @@ class PreParserTraits { ...@@ -968,16 +967,12 @@ class PreParserTraits {
// Reporting errors. // Reporting errors.
void ReportMessageAt(Scanner::Location location, void ReportMessageAt(Scanner::Location location,
const char* message, const char* message,
Vector<const char*> args, const char* arg = NULL,
bool is_reference_error = false);
void ReportMessageAt(Scanner::Location location,
const char* type,
const char* name_opt,
bool is_reference_error = false); bool is_reference_error = false);
void ReportMessageAt(int start_pos, void ReportMessageAt(int start_pos,
int end_pos, int end_pos,
const char* type, const char* message,
const char* name_opt, const char* arg = NULL,
bool is_reference_error = false); bool is_reference_error = false);
// "null" return type creators. // "null" return type creators.
...@@ -1240,7 +1235,7 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { ...@@ -1240,7 +1235,7 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
const char* name = Token::String(token); const char* name = Token::String(token);
ASSERT(name != NULL); ASSERT(name != NULL);
Traits::ReportMessageAt( Traits::ReportMessageAt(
source_location, "unexpected_token", Vector<const char*>(&name, 1)); source_location, "unexpected_token", name);
} }
} }
...@@ -1321,7 +1316,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( ...@@ -1321,7 +1316,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral(
int pos = peek_position(); int pos = peek_position();
if (!scanner()->ScanRegExpPattern(seen_equal)) { if (!scanner()->ScanRegExpPattern(seen_equal)) {
Next(); Next();
ReportMessage("unterminated_regexp", Vector<const char*>::empty()); ReportMessage("unterminated_regexp");
*ok = false; *ok = false;
return Traits::EmptyExpression(); return Traits::EmptyExpression();
} }
...@@ -1864,7 +1859,7 @@ ParserBase<Traits>::ParseUnaryExpression(bool* ok) { ...@@ -1864,7 +1859,7 @@ ParserBase<Traits>::ParseUnaryExpression(bool* ok) {
// "delete identifier" is a syntax error in strict mode. // "delete identifier" is a syntax error in strict mode.
if (op == Token::DELETE && strict_mode() == STRICT && if (op == Token::DELETE && strict_mode() == STRICT &&
this->IsIdentifier(expression)) { this->IsIdentifier(expression)) {
ReportMessage("strict_delete", Vector<const char*>::empty()); ReportMessage("strict_delete");
*ok = false; *ok = false;
return this->EmptyExpression(); return this->EmptyExpression();
} }
......
...@@ -1147,12 +1147,12 @@ i::Handle<i::String> FormatMessage(i::ScriptData* data) { ...@@ -1147,12 +1147,12 @@ i::Handle<i::String> FormatMessage(i::ScriptData* data) {
const char* message = data->BuildMessage(); const char* message = data->BuildMessage();
i::Handle<i::String> format = v8::Utils::OpenHandle( i::Handle<i::String> format = v8::Utils::OpenHandle(
*v8::String::NewFromUtf8(CcTest::isolate(), message)); *v8::String::NewFromUtf8(CcTest::isolate(), message));
i::Vector<const char*> args = data->BuildArgs(); const char* arg = data->BuildArg();
i::Handle<i::JSArray> args_array = factory->NewJSArray(args.length()); i::Handle<i::JSArray> args_array = factory->NewJSArray(arg == NULL ? 0 : 1);
for (int i = 0; i < args.length(); i++) { if (arg != NULL) {
i::JSArray::SetElement( i::JSArray::SetElement(
args_array, i, v8::Utils::OpenHandle(*v8::String::NewFromUtf8( args_array, 0, v8::Utils::OpenHandle(*v8::String::NewFromUtf8(
CcTest::isolate(), args[i])), CcTest::isolate(), arg)),
NONE, i::SLOPPY).Check(); NONE, i::SLOPPY).Check();
} }
i::Handle<i::JSObject> builtins(isolate->js_builtins_object()); i::Handle<i::JSObject> builtins(isolate->js_builtins_object());
...@@ -1162,11 +1162,8 @@ i::Handle<i::String> FormatMessage(i::ScriptData* data) { ...@@ -1162,11 +1162,8 @@ i::Handle<i::String> FormatMessage(i::ScriptData* data) {
i::Handle<i::Object> result = i::Execution::Call( i::Handle<i::Object> result = i::Execution::Call(
isolate, format_fun, builtins, 2, arg_handles).ToHandleChecked(); isolate, format_fun, builtins, 2, arg_handles).ToHandleChecked();
CHECK(result->IsString()); CHECK(result->IsString());
for (int i = 0; i < args.length(); i++) {
i::DeleteArray(args[i]);
}
i::DeleteArray(args.start());
i::DeleteArray(message); i::DeleteArray(message);
i::DeleteArray(arg);
return i::Handle<i::String>::cast(result); return i::Handle<i::String>::cast(result);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment