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 {
Scanner::Location MessageLocation() const;
bool IsReferenceError() const;
const char* BuildMessage() const;
Vector<const char*> BuildArgs() const;
const char* BuildArg() const;
int function_count() {
int functions_size =
......@@ -515,14 +515,14 @@ class ParserTraits {
// Reporting errors.
void ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<const char*> args,
const char* arg,
bool is_reference_error = false);
void ReportMessage(const char* message,
Vector<Handle<String> > args,
MaybeHandle<String> arg,
bool is_reference_error = false);
void ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<Handle<String> > args,
MaybeHandle<String> arg,
bool is_reference_error = false);
// "null" return type creators.
......
......@@ -35,31 +35,22 @@ namespace internal {
void PreParserTraits::ReportMessageAt(Scanner::Location location,
const char* message,
Vector<const char*> args,
const char* arg,
bool is_reference_error) {
ReportMessageAt(location.beg_pos,
location.end_pos,
message,
args.length() > 0 ? args[0] : NULL,
arg,
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,
int end_pos,
const char* type,
const char* name_opt,
const char* message,
const char* arg,
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);
}
......@@ -294,8 +285,7 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) {
if (strict_mode() == STRICT) {
PreParserTraits::ReportMessageAt(start_location.beg_pos,
end_location.end_pos,
"strict_function",
NULL);
"strict_function");
*ok = false;
return Statement::Default();
} else {
......
......@@ -348,16 +348,15 @@ class ParserBase : public Traits {
bool is_generator() const { return function_state_->is_generator(); }
// 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) {
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,
bool is_reference_error = false) {
Traits::ReportMessageAt(location, message, Vector<const char*>::empty(),
is_reference_error);
Traits::ReportMessageAt(location, message, NULL, is_reference_error);
}
void ReportUnexpectedToken(Token::Value token);
......@@ -968,16 +967,12 @@ class PreParserTraits {
// Reporting errors.
void ReportMessageAt(Scanner::Location location,
const char* message,
Vector<const char*> args,
bool is_reference_error = false);
void ReportMessageAt(Scanner::Location location,
const char* type,
const char* name_opt,
const char* arg = NULL,
bool is_reference_error = false);
void ReportMessageAt(int start_pos,
int end_pos,
const char* type,
const char* name_opt,
const char* message,
const char* arg = NULL,
bool is_reference_error = false);
// "null" return type creators.
......@@ -1240,7 +1235,7 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
const char* name = Token::String(token);
ASSERT(name != NULL);
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(
int pos = peek_position();
if (!scanner()->ScanRegExpPattern(seen_equal)) {
Next();
ReportMessage("unterminated_regexp", Vector<const char*>::empty());
ReportMessage("unterminated_regexp");
*ok = false;
return Traits::EmptyExpression();
}
......@@ -1864,7 +1859,7 @@ ParserBase<Traits>::ParseUnaryExpression(bool* ok) {
// "delete identifier" is a syntax error in strict mode.
if (op == Token::DELETE && strict_mode() == STRICT &&
this->IsIdentifier(expression)) {
ReportMessage("strict_delete", Vector<const char*>::empty());
ReportMessage("strict_delete");
*ok = false;
return this->EmptyExpression();
}
......
......@@ -1147,12 +1147,12 @@ i::Handle<i::String> FormatMessage(i::ScriptData* data) {
const char* message = data->BuildMessage();
i::Handle<i::String> format = v8::Utils::OpenHandle(
*v8::String::NewFromUtf8(CcTest::isolate(), message));
i::Vector<const char*> args = data->BuildArgs();
i::Handle<i::JSArray> args_array = factory->NewJSArray(args.length());
for (int i = 0; i < args.length(); i++) {
const char* arg = data->BuildArg();
i::Handle<i::JSArray> args_array = factory->NewJSArray(arg == NULL ? 0 : 1);
if (arg != NULL) {
i::JSArray::SetElement(
args_array, i, v8::Utils::OpenHandle(*v8::String::NewFromUtf8(
CcTest::isolate(), args[i])),
args_array, 0, v8::Utils::OpenHandle(*v8::String::NewFromUtf8(
CcTest::isolate(), arg)),
NONE, i::SLOPPY).Check();
}
i::Handle<i::JSObject> builtins(isolate->js_builtins_object());
......@@ -1162,11 +1162,8 @@ i::Handle<i::String> FormatMessage(i::ScriptData* data) {
i::Handle<i::Object> result = i::Execution::Call(
isolate, format_fun, builtins, 2, arg_handles).ToHandleChecked();
CHECK(result->IsString());
for (int i = 0; i < args.length(); i++) {
i::DeleteArray(args[i]);
}
i::DeleteArray(args.start());
i::DeleteArray(message);
i::DeleteArray(arg);
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