Commit f3f0b272 authored by yangguo's avatar yangguo Committed by Commit bot

Migrate error messages, part 11.

R=mvstanton@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28423}
parent 323ced9e
......@@ -7230,7 +7230,7 @@ String::Value::~Value() {
{ \
i::HandleScope scope(isolate); \
i::Handle<i::String> message = Utils::OpenHandle(*raw_message); \
error = *isolate->factory()->New##NAME(message); \
error = *isolate->factory()->NewError("$" #NAME, message); \
} \
i::Handle<i::Object> result(error, isolate); \
return Utils::ToLocal(result); \
......
......@@ -1076,52 +1076,6 @@ Handle<HeapNumber> Factory::NewHeapNumber(double value,
}
Handle<Object> Factory::NewTypeError(Handle<String> message) {
return NewError("$TypeError", message);
}
Handle<Object> Factory::NewRangeError(Handle<String> message) {
return NewError("$RangeError", message);
}
Handle<Object> Factory::NewSyntaxError(const char* message,
Handle<JSArray> args) {
return NewError("MakeSyntaxError", message, args);
}
Handle<Object> Factory::NewSyntaxError(Handle<String> message) {
return NewError("$SyntaxError", message);
}
Handle<Object> Factory::NewReferenceError(const char* message,
Handle<JSArray> args) {
return NewError("MakeReferenceError", message, args);
}
Handle<Object> Factory::NewReferenceError(Handle<String> message) {
return NewError("$ReferenceError", message);
}
Handle<Object> Factory::NewError(const char* maker, const char* message,
Vector<Handle<Object> > args) {
// Instantiate a closeable HandleScope for EscapeFrom.
v8::EscapableHandleScope scope(reinterpret_cast<v8::Isolate*>(isolate()));
Handle<FixedArray> array = NewFixedArray(args.length());
for (int i = 0; i < args.length(); i++) {
array->set(i, *args[i]);
}
Handle<JSArray> object = NewJSArrayWithElements(array);
Handle<Object> result = NewError(maker, message, object);
return result.EscapeFrom(&scope);
}
Handle<Object> Factory::NewError(const char* maker,
MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
......@@ -1169,6 +1123,13 @@ Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index,
}
Handle<Object> Factory::NewSyntaxError(MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2) {
return NewError("MakeSyntaxError", template_index, arg0, arg1, arg2);
}
Handle<Object> Factory::NewReferenceError(
MessageTemplate::Template template_index, Handle<Object> arg0,
Handle<Object> arg1, Handle<Object> arg2) {
......@@ -1257,11 +1218,6 @@ Handle<Object> Factory::NewError(const char* maker, const char* message,
}
Handle<Object> Factory::NewError(Handle<String> message) {
return NewError("$Error", message);
}
Handle<Object> Factory::NewError(const char* constructor,
Handle<String> message) {
Handle<String> constr = InternalizeUtf8String(constructor);
......
......@@ -540,27 +540,13 @@ class Factory final {
Handle<Object> NewError(const char* maker, const char* message,
Handle<JSArray> args);
Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
Handle<Object> NewError(const char* maker, const char* message,
Vector<Handle<Object> > args);
Handle<Object> NewError(const char* message, Vector<Handle<Object> > args);
Handle<Object> NewError(Handle<String> message);
Handle<Object> NewError(const char* constructor, Handle<String> message);
Handle<Object> NewTypeError(Handle<String> message);
Handle<Object> NewRangeError(Handle<String> message);
Handle<Object> NewInvalidStringLengthError() {
return NewRangeError(MessageTemplate::kInvalidStringLength);
}
Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
Handle<Object> NewSyntaxError(Handle<String> message);
Handle<Object> NewReferenceError(const char* message, Handle<JSArray> args);
Handle<Object> NewReferenceError(Handle<String> message);
Handle<Object> NewError(const char* maker,
MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
......@@ -576,6 +562,11 @@ class Factory final {
Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>());
Handle<Object> NewSyntaxError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>());
Handle<Object> NewReferenceError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(),
......
......@@ -744,16 +744,9 @@ static inline AccessCheckInfo* GetAccessCheckInfo(Isolate* isolate,
}
static void ThrowAccessCheckError(Isolate* isolate) {
Handle<String> message =
isolate->factory()->InternalizeUtf8String("no access");
isolate->ScheduleThrow(*isolate->factory()->NewTypeError(message));
}
void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver) {
if (!thread_local_top()->failed_access_check_callback_) {
return ThrowAccessCheckError(this);
return ScheduleThrow(*factory()->NewTypeError(MessageTemplate::kNoAccess));
}
DCHECK(receiver->IsAccessCheckNeeded());
......@@ -766,7 +759,8 @@ void Isolate::ReportFailedAccessCheck(Handle<JSObject> receiver) {
AccessCheckInfo* access_check_info = GetAccessCheckInfo(this, receiver);
if (!access_check_info) {
AllowHeapAllocation doesnt_matter_anymore;
return ThrowAccessCheckError(this);
return ScheduleThrow(
*factory()->NewTypeError(MessageTemplate::kNoAccess));
}
data = handle(access_check_info->data(), this);
}
......
......@@ -213,14 +213,13 @@ MaybeHandle<Object> JsonParser<seq_one_byte>::ParseJson() {
if (isolate_->has_pending_exception()) return Handle<Object>::null();
// Parse failed. Current character is the unexpected token.
const char* message;
Factory* factory = this->factory();
Handle<JSArray> array;
MessageTemplate::Template message;
Handle<String> argument;
switch (c0_) {
case kEndOfString:
message = "unexpected_eos";
array = factory->NewJSArray(0);
message = MessageTemplate::kUnexpectedEOS;
break;
case '-':
case '0':
......@@ -233,26 +232,21 @@ MaybeHandle<Object> JsonParser<seq_one_byte>::ParseJson() {
case '7':
case '8':
case '9':
message = "unexpected_token_number";
array = factory->NewJSArray(0);
message = MessageTemplate::kUnexpectedTokenNumber;
break;
case '"':
message = "unexpected_token_string";
array = factory->NewJSArray(0);
message = MessageTemplate::kUnexpectedTokenString;
break;
default:
message = "unexpected_token";
Handle<Object> name = factory->LookupSingleCharacterStringFromCode(c0_);
Handle<FixedArray> element = factory->NewFixedArray(1);
element->set(0, *name);
array = factory->NewJSArrayWithElements(element);
message = MessageTemplate::kUnexpectedToken;
argument = factory->LookupSingleCharacterStringFromCode(c0_);
break;
}
MessageLocation location(factory->NewScript(source_),
position_,
position_ + 1);
Handle<Object> error = factory->NewSyntaxError(message, array);
Handle<Object> error = factory->NewSyntaxError(message, argument);
return isolate()->template Throw<Object>(error, &location);
}
return result;
......
......@@ -12,6 +12,7 @@
#include "src/factory.h"
#include "src/jsregexp-inl.h"
#include "src/jsregexp.h"
#include "src/messages.h"
#include "src/ostreams.h"
#include "src/parser.h"
#include "src/regexp-macro-assembler.h"
......@@ -62,18 +63,17 @@ MaybeHandle<Object> RegExpImpl::CreateRegExpLiteral(
MUST_USE_RESULT
static inline MaybeHandle<Object> ThrowRegExpException(
Handle<JSRegExp> re,
Handle<String> pattern,
Handle<String> error_text,
const char* message) {
Handle<JSRegExp> re, Handle<String> pattern, Handle<String> error_text) {
Isolate* isolate = re->GetIsolate();
Factory* factory = isolate->factory();
Handle<FixedArray> elements = factory->NewFixedArray(2);
elements->set(0, *pattern);
elements->set(1, *error_text);
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> regexp_err;
THROW_NEW_ERROR(isolate, NewSyntaxError(message, array), Object);
THROW_NEW_ERROR(isolate, NewSyntaxError(MessageTemplate::kMalformedRegExp,
pattern, error_text),
Object);
}
inline void ThrowRegExpException(Handle<JSRegExp> re,
Handle<String> error_text) {
USE(ThrowRegExpException(re, Handle<String>(re->Pattern()), error_text));
}
......@@ -159,10 +159,7 @@ MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
flags.is_multiline(), flags.is_unicode(),
&parse_result)) {
// Throw an exception if we fail to parse the pattern.
return ThrowRegExpException(re,
pattern,
parse_result.error,
"malformed_regexp");
return ThrowRegExpException(re, pattern, parse_result.error);
}
bool has_been_compiled = false;
......@@ -352,19 +349,6 @@ bool RegExpImpl::EnsureCompiledIrregexp(Handle<JSRegExp> re,
}
static void CreateRegExpErrorObjectAndThrow(Handle<JSRegExp> re,
Handle<String> error_message,
Isolate* isolate) {
Factory* factory = isolate->factory();
Handle<FixedArray> elements = factory->NewFixedArray(2);
elements->set(0, re->Pattern());
elements->set(1, *error_message);
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> error = factory->NewSyntaxError("malformed_regexp", array);
isolate->Throw(*error);
}
bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
Handle<String> sample_subject,
bool is_one_byte) {
......@@ -391,7 +375,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
Object* error_string = re->DataAt(JSRegExp::saved_code_index(is_one_byte));
DCHECK(error_string->IsString());
Handle<String> error_message(String::cast(error_string));
CreateRegExpErrorObjectAndThrow(re, error_message, isolate);
ThrowRegExpException(re, error_message);
return false;
}
......@@ -405,10 +389,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
flags.is_unicode(), &compile_data)) {
// Throw an exception if we fail to parse the pattern.
// THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once.
USE(ThrowRegExpException(re,
pattern,
compile_data.error,
"malformed_regexp"));
USE(ThrowRegExpException(re, pattern, compile_data.error));
return false;
}
RegExpEngine::CompilationResult result = RegExpEngine::Compile(
......@@ -419,7 +400,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
// Unable to compile regexp.
Handle<String> error_message = isolate->factory()->NewStringFromUtf8(
CStrVector(result.error_message)).ToHandleChecked();
CreateRegExpErrorObjectAndThrow(re, error_message, isolate);
ThrowRegExpException(re, error_message);
return false;
}
......
......@@ -170,6 +170,7 @@ class CallSite {
T(MethodInvokedOnNullOrUndefined, \
"Method invoked on undefined or null value.") \
T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
T(NoAccess, "no access") \
T(NonExtensibleProto, "% is not extensible") \
T(NonObjectPropertyLoad, "Cannot read property '%' of %") \
T(NonObjectPropertyStore, "Cannot set property '%' of %") \
......@@ -228,6 +229,8 @@ class CallSite {
T(RedefineExternalArray, \
"Cannot redefine a property of an object with external array elements") \
T(ReduceNoInitial, "Reduce of empty array with no initial value") \
T(RegExpFlags, \
"Cannot supply flags when constructing one RegExp from another") \
T(ReinitializeIntl, "Trying to re-initialize % object.") \
T(ResolvedOptionsCalledOnNonObject, \
"resolvedOptions method called on a non-object or on a object that is " \
......@@ -246,6 +249,7 @@ class CallSite {
T(StrongArity, \
"In strong mode, calling a function with too few arguments is deprecated") \
T(StrongImplicitCast, "In strong mode, implicit conversions are deprecated") \
T(SymbolKeyFor, "% is not a symbol") \
T(SymbolToPrimitive, \
"Cannot convert a Symbol wrapper object to a primitive value") \
T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
......@@ -275,6 +279,8 @@ class CallSite {
T(InvalidDataViewLength, "Invalid data view length") \
T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
T(InvalidLanguageTag, "Invalid language tag: %") \
T(InvalidWeakMapKey, "Invalid value used as weak map key") \
T(InvalidWeakSetValue, "Invalid value used in weak set") \
T(InvalidStringLength, "Invalid string length") \
T(InvalidTimeValue, "Invalid time value") \
T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
......@@ -292,7 +298,13 @@ class CallSite {
T(UnsupportedTimeZone, "Unsupported time zone specified %") \
T(ValueOutOfRange, "Value % out of range for % options property %") \
/* SyntaxError */ \
T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \
T(MalformedRegExp, "Invalid regular expression: /%/: %") \
T(ParenthesisInArgString, "Function arg string contains parenthesis") \
T(UnexpectedEOS, "Unexpected end of input") \
T(UnexpectedToken, "Unexpected token %") \
T(UnexpectedTokenNumber, "Unexpected number") \
T(UnexpectedTokenString, "Unexpected string") \
/* EvalError */ \
T(CodeGenFromStrings, "%") \
/* URIError */ \
......
......@@ -64,13 +64,11 @@ var kMessages = {
unexpected_strict_reserved: ["Unexpected strict mode reserved word"],
unexpected_eos: ["Unexpected end of input"],
unexpected_template_string: ["Unexpected template string"],
malformed_regexp: ["Invalid regular expression: /", "%0", "/: ", "%1"],
malformed_regexp_flags: ["Invalid regular expression flags"],
unterminated_regexp: ["Invalid regular expression: missing /"],
unterminated_template: ["Unterminated template literal"],
unterminated_template_expr: ["Missing } in template expression"],
unterminated_arg_list: ["missing ) after argument list"],
regexp_flags: ["Cannot supply flags when constructing one RegExp from another"],
multiple_defaults_in_switch: ["More than one default clause in switch statement"],
newline_after_throw: ["Illegal newline after throw"],
label_redeclaration: ["Label '", "%0", "' has already been declared"],
......@@ -82,9 +80,6 @@ var kMessages = {
non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1"],
value_and_accessor: ["Invalid property. A property cannot both have accessors and be writable or have a value, ", "%0"],
proto_object_or_null: ["Object prototype may only be an Object or null: ", "%0"],
invalid_weakmap_key: ["Invalid value used as weak map key"],
invalid_weakset_value: ["Invalid value used in weak set"],
not_a_symbol: ["%0", " is not a symbol"],
// ReferenceError
invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"],
invalid_lhs_in_for: ["Invalid left-hand side in for-loop"],
......@@ -93,8 +88,6 @@ var kMessages = {
// SyntaxError
not_isvar: ["builtin %IS_VAR: not a variable"],
single_function_literal: ["Single function literal required"],
invalid_regexp_flags: ["Invalid flags supplied to RegExp constructor '", "%0", "'"],
invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"],
illegal_break: ["Illegal break statement"],
illegal_continue: ["Illegal continue statement"],
illegal_return: ["Illegal return statement"],
......
......@@ -36,10 +36,10 @@ void PendingCompilationErrorHandler::ThrowPendingError(Isolate* isolate,
switch (error_type_) {
case kReferenceError:
error = factory->NewReferenceError(message_, array);
error = factory->NewError("MakeReferenceError", message_, array);
break;
case kSyntaxError:
error = factory->NewSyntaxError(message_, array);
error = factory->NewError("MakeSyntaxError", message_, array);
break;
}
......
......@@ -48,9 +48,7 @@ $regexpLastMatchInfoOverride = null;
function DoConstructRegExp(object, pattern, flags) {
// RegExp : Called as constructor; see ECMA-262, section 15.10.4.
if (IS_REGEXP(pattern)) {
if (!IS_UNDEFINED(flags)) {
throw MakeTypeError('regexp_flags', []);
}
if (!IS_UNDEFINED(flags)) throw MakeTypeError(kRegExpFlags);
flags = (pattern.global ? 'g' : '')
+ (pattern.ignoreCase ? 'i' : '')
+ (pattern.multiline ? 'm' : '');
......
......@@ -210,7 +210,7 @@ COMPARE_STRONG = function COMPARE_STRONG(x, ncr) {
if (IS_STRING(this) && IS_STRING(x)) return %_StringCompare(this, x);
if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberCompare(this, x, ncr);
throw %MakeTypeError('strong_implicit_cast');
throw %MakeTypeError(kStrongImplicitCast);
}
......
......@@ -7,6 +7,7 @@
#include "src/arguments.h"
#include "src/jsregexp-inl.h"
#include "src/jsregexp.h"
#include "src/messages.h"
#include "src/runtime/runtime-utils.h"
#include "src/string-builder.h"
#include "src/string-search.h"
......@@ -912,11 +913,9 @@ RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) {
bool success = false;
JSRegExp::Flags flags = RegExpFlagsFromString(flags_string, &success);
if (!success) {
Handle<FixedArray> element = factory->NewFixedArray(1);
element->set(0, *flags_string);
Handle<JSArray> args = factory->NewJSArrayWithElements(element);
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewSyntaxError("invalid_regexp_flags", args));
isolate,
NewSyntaxError(MessageTemplate::kInvalidRegExpFlags, flags_string));
}
Handle<String> escaped_source;
......
......@@ -62,7 +62,7 @@ function SymbolFor(key) {
function SymbolKeyFor(symbol) {
if (!IS_SYMBOL(symbol)) throw MakeTypeError("not_a_symbol", [symbol]);
if (!IS_SYMBOL(symbol)) throw MakeTypeError(kSymbolKeyFor, symbol);
return %SymbolRegistry().keyFor[symbol];
}
......
......@@ -52,9 +52,7 @@ function WeakMapSet(key, value) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakMap.prototype.set', this);
}
if (!IS_SPEC_OBJECT(key)) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
if (!IS_SPEC_OBJECT(key)) throw MakeTypeError(kInvalidWeakMapKey);
return %WeakCollectionSet(this, key, value);
}
......@@ -124,9 +122,7 @@ function WeakSetAdd(value) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakSet.prototype.add', this);
}
if (!IS_SPEC_OBJECT(value)) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
}
if (!IS_SPEC_OBJECT(value)) throw MakeTypeError(kInvalidWeakSetValue);
return %WeakCollectionSet(this, value, true);
}
......
......@@ -353,15 +353,47 @@ test(function() {
}, "Reflect.construct: Arguments list has wrong type", TypeError);
//=== SyntaxError ===
// === SyntaxError ===
// kInvalidRegExpFlags
test(function() {
/a/x.test("a");
}, "Invalid flags supplied to RegExp constructor 'x'", SyntaxError);
// kMalformedRegExp
test(function() {
/(/.test("a");
}, "Invalid regular expression: /(/: Unterminated group", SyntaxError);
// kParenthesisInArgString
test(function() {
new Function(")", "");
}, "Function arg string contains parenthesis", SyntaxError);
// kUnexpectedEOS
test(function() {
JSON.parse("{")
}, "Unexpected end of input", SyntaxError);
// kUnexpectedToken
test(function() {
JSON.parse("/")
}, "Unexpected token /", SyntaxError);
// kUnexpectedTokenNumber
test(function() {
JSON.parse("{ 1")
}, "Unexpected number", SyntaxError);
// kUnexpectedTokenString
test(function() {
JSON.parse('"""')
}, "Unexpected string", SyntaxError);
// === ReferenceError ===
// kNotDefined
test(function() {
"use strict";
o;
......
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