}
-Vector<const char*> ScriptData::BuildArgs() const {
+const char* ScriptData::BuildArg() const {
int arg_count = Read(PreparseDataConstants::kMessageArgCountPos);
- const char** array = NewArray<const char*>(arg_count);
+ ASSERT(arg_count == 0 || arg_count == 1);
+ if (arg_count == 0) {
+ return NULL;
+ }
// Position after text found by skipping past length field and
// length field content words.
int pos = PreparseDataConstants::kMessageTextPos + 1
+ Read(PreparseDataConstants::kMessageTextPos);
- for (int i = 0; i < arg_count; i++) {
- int count = 0;
- array[i] = ReadString(ReadAddress(pos), &count);
- pos += count + 1;
- }
- return Vector<const char*>(array, arg_count);
+ int count = 0;
+ return ReadString(ReadAddress(pos), &count);
}
void ParserTraits::ReportMessageAt(Scanner::Location source_location,
const char* message,
- Vector<const char*> args,
+ const char* arg,
bool is_reference_error) {
if (parser_->stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
source_location.beg_pos,
source_location.end_pos);
Factory* factory = parser_->isolate()->factory();
- Handle<FixedArray> elements = factory->NewFixedArray(args.length());
- for (int i = 0; i < args.length(); i++) {
+ Handle<FixedArray> elements = factory->NewFixedArray(arg == NULL ? 0 : 1);
+ if (arg != NULL) {
Handle<String> arg_string =
- factory->NewStringFromUtf8(CStrVector(args[i])).ToHandleChecked();
- elements->set(i, *arg_string);
+ factory->NewStringFromUtf8(CStrVector(arg)).ToHandleChecked();
+ elements->set(0, *arg_string);
}
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> result = is_reference_error
void ParserTraits::ReportMessage(const char* message,
- Vector<Handle<String> > args,
+ MaybeHandle<String> arg,
bool is_reference_error) {
Scanner::Location source_location = parser_->scanner()->location();
- ReportMessageAt(source_location, message, args, is_reference_error);
+ ReportMessageAt(source_location, message, arg, is_reference_error);
}
void ParserTraits::ReportMessageAt(Scanner::Location source_location,
const char* message,
- Vector<Handle<String> > args,
+ MaybeHandle<String> arg,
bool is_reference_error) {
if (parser_->stack_overflow()) {
// Suppress the error message (syntax error or such) in the presence of a
source_location.beg_pos,
source_location.end_pos);
Factory* factory = parser_->isolate()->factory();
- Handle<FixedArray> elements = factory->NewFixedArray(args.length());
- for (int i = 0; i < args.length(); i++) {
- elements->set(i, *args[i]);
+ Handle<FixedArray> elements = factory->NewFixedArray(arg.is_null() ? 0 : 1);
+ if (!arg.is_null()) {
+ elements->set(0, *(arg.ToHandleChecked()));
}
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> result = is_reference_error
!body->at(0)->IsExpressionStatement() ||
!body->at(0)->AsExpressionStatement()->
expression()->IsFunctionLiteral()) {
- ReportMessage("single_function_literal", Vector<const char*>::empty());
+ ReportMessage("single_function_literal");
ok = false;
}
}
for (Interface::Iterator it = interface->iterator();
!it.done(); it.Advance()) {
if (scope->LocalLookup(it.name()) == NULL) {
- Handle<String> name(it.name());
- ParserTraits::ReportMessage("module_export_undefined",
- Vector<Handle<String> >(&name, 1));
+ ParserTraits::ReportMessage("module_export_undefined", it.name());
*ok = false;
return NULL;
}
member->interface()->Print();
}
#endif
- ParserTraits::ReportMessage("invalid_module_path",
- Vector<Handle<String> >(&name, 1));
+ ParserTraits::ReportMessage("invalid_module_path", name);
return NULL;
}
result = member;
module->interface()->Print();
}
#endif
- ParserTraits::ReportMessage("invalid_module_path",
- Vector<Handle<String> >(&name, 1));
+ ParserTraits::ReportMessage("invalid_module_path", name);
return NULL;
}
VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
if (allow_harmony_scoping() && strict_mode() == STRICT) {
// In harmony we treat re-declarations as early errors. See
// ES5 16 for a definition of early errors.
- SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS);
- const char* elms[1] = { c_string.get() };
- Vector<const char*> args(elms, 1);
- ReportMessage("var_redeclaration", args);
+ ParserTraits::ReportMessage("var_redeclaration", name);
*ok = false;
return;
}
var->interface()->Print();
}
#endif
- ParserTraits::ReportMessage("module_type_error",
- Vector<Handle<String> >(&name, 1));
+ ParserTraits::ReportMessage("module_type_error", name);
}
}
}
if (var_context == kStatement) {
// In strict mode 'const' declarations are only allowed in source
// element positions.
- ReportMessage("unprotected_const", Vector<const char*>::empty());
+ ReportMessage("unprotected_const");
*ok = false;
return NULL;
}
mode = CONST;
init_op = Token::INIT_CONST;
} else {
- ReportMessage("strict_const", Vector<const char*>::empty());
+ ReportMessage("strict_const");
*ok = false;
return NULL;
}
//
// TODO(rossberg): make 'let' a legal identifier in sloppy mode.
if (!allow_harmony_scoping() || strict_mode() == SLOPPY) {
- ReportMessage("illegal_let", Vector<const char*>::empty());
+ ReportMessage("illegal_let");
*ok = false;
return NULL;
}
Consume(Token::LET);
if (var_context == kStatement) {
// Let declarations are only allowed in source element positions.
- ReportMessage("unprotected_let", Vector<const char*>::empty());
+ ReportMessage("unprotected_let");
*ok = false;
return NULL;
}
// structured. However, these are probably changes we want to
// make later anyway so we should go back and fix this then.
if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
- SmartArrayPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
- const char* elms[1] = { c_string.get() };
- Vector<const char*> args(elms, 1);
- ReportMessage("label_redeclaration", args);
+ ParserTraits::ReportMessage("label_redeclaration", label);
*ok = false;
return NULL;
}
if (target == NULL) {
// Illegal continue statement.
const char* message = "illegal_continue";
- Vector<Handle<String> > args;
if (!label.is_null()) {
message = "unknown_label";
- args = Vector<Handle<String> >(&label, 1);
}
- ParserTraits::ReportMessageAt(scanner()->location(), message, args);
+ ParserTraits::ReportMessageAt(scanner()->location(), message, label);
*ok = false;
return NULL;
}
if (target == NULL) {
// Illegal break statement.
const char* message = "illegal_break";
- Vector<Handle<String> > args;
if (!label.is_null()) {
message = "unknown_label";
- args = Vector<Handle<String> >(&label, 1);
}
- ParserTraits::ReportMessageAt(scanner()->location(), message, args);
+ ParserTraits::ReportMessageAt(scanner()->location(), message, label);
*ok = false;
return NULL;
}
int pos = position();
if (strict_mode() == STRICT) {
- ReportMessage("strict_mode_with", Vector<const char*>::empty());
+ ReportMessage("strict_mode_with");
*ok = false;
return NULL;
}
} else {
Expect(Token::DEFAULT, CHECK_OK);
if (*default_seen_ptr) {
- ReportMessage("multiple_defaults_in_switch",
- Vector<const char*>::empty());
+ ReportMessage("multiple_defaults_in_switch");
*ok = false;
return NULL;
}
Expect(Token::THROW, CHECK_OK);
int pos = position();
if (scanner()->HasAnyLineTerminatorBeforeNext()) {
- ReportMessage("newline_after_throw", Vector<const char*>::empty());
+ ReportMessage("newline_after_throw");
*ok = false;
return NULL;
}
Token::Value tok = peek();
if (tok != Token::CATCH && tok != Token::FINALLY) {
- ReportMessage("no_catch_or_finally", Vector<const char*>::empty());
+ ReportMessage("no_catch_or_finally");
*ok = false;
return NULL;
}
void Parser::ReportInvalidCachedData(Handle<String> name, bool* ok) {
- SmartArrayPointer<char> name_string = name->ToCString(DISALLOW_NULLS);
- const char* element[1] = { name_string.get() };
- ReportMessage("invalid_cached_data_function",
- Vector<const char*>(element, 1));
+ ParserTraits::ReportMessage("invalid_cached_data_function", name);
*ok = false;
}
return;
}
if (logger.has_error()) {
- const char* arg = logger.argument_opt();
- Vector<const char*> args;
- if (arg != NULL) {
- args = Vector<const char*>(&arg, 1);
- }
ParserTraits::ReportMessageAt(
Scanner::Location(logger.start(), logger.end()),
- logger.message(), args, logger.is_reference_error());
+ logger.message(), logger.argument_opt(), logger.is_reference_error());
*ok = false;
return;
}
if (args->length() == 1 && args->at(0)->AsVariableProxy() != NULL) {
return args->at(0);
} else {
- ReportMessage("not_isvar", Vector<const char*>::empty());
+ ReportMessage("not_isvar");
*ok = false;
return NULL;
}
if (function != NULL &&
function->nargs != -1 &&
function->nargs != args->length()) {
- ReportMessage("illegal_access", Vector<const char*>::empty());
+ ReportMessage("illegal_access");
*ok = false;
return NULL;
}
// Check that the function is defined if it's an inline runtime call.
if (function == NULL && name->Get(0) == '_') {
- ParserTraits::ReportMessage("not_defined",
- Vector<Handle<String> >(&name, 1));
+ ParserTraits::ReportMessage("not_defined", name);
*ok = false;
return NULL;
}
// In harmony mode we treat conflicting variable bindinds as early
// errors. See ES5 16 for a definition of early errors.
Handle<String> name = decl->proxy()->name();
- SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS);
- const char* elms[1] = { c_string.get() };
- Vector<const char*> args(elms, 1);
int position = decl->proxy()->position();
Scanner::Location location = position == RelocInfo::kNoPosition
? Scanner::Location::invalid()
: Scanner::Location(position, position + 1);
- ParserTraits::ReportMessageAt(location, "var_redeclaration", args);
+ ParserTraits::ReportMessageAt(location, "var_redeclaration", name);
*ok = false;
}
}
ScriptData* cached_data = *(info()->cached_data());
Scanner::Location loc = cached_data->MessageLocation();
const char* message = cached_data->BuildMessage();
- Vector<const char*> args = cached_data->BuildArgs();
- ParserTraits::ReportMessageAt(loc, message, args,
+ const char* arg = cached_data->BuildArg();
+ ParserTraits::ReportMessageAt(loc, message, arg,
cached_data->IsReferenceError());
DeleteArray(message);
- for (int i = 0; i < args.length(); i++) {
- DeleteArray(args[i]);
- }
- DeleteArray(args.start());
+ DeleteArray(arg);
ASSERT(info()->isolate()->has_pending_exception());
} else {
result = ParseProgram();
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);
// 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.
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);
}
}
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();
}
// "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();
}