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