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

Migrate error messages, part 6. (string.js and date.js)

R=mvstanton@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28180}
parent d18dd375
...@@ -691,7 +691,7 @@ function PadInt(n, digits) { ...@@ -691,7 +691,7 @@ function PadInt(n, digits) {
// ECMA 262 - 15.9.5.43 // ECMA 262 - 15.9.5.43
function DateToISOString() { function DateToISOString() {
var t = UTC_DATE_VALUE(this); var t = UTC_DATE_VALUE(this);
if (NUMBER_IS_NAN(t)) throw MakeRangeError("invalid_time_value", []); if (NUMBER_IS_NAN(t)) throw MakeRangeError(kInvalidTimeValue);
var year = this.getUTCFullYear(); var year = this.getUTCFullYear();
var year_string; var year_string;
if (year >= 0 && year <= 9999) { if (year >= 0 && year <= 9999) {
......
...@@ -131,8 +131,10 @@ class CallSite { ...@@ -131,8 +131,10 @@ class CallSite {
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \ T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
T(DateType, "this is not a Date object.") \ T(DateType, "this is not a Date object.") \
T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \ T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \
T(GeneratorRunning, "Generator is already running") \ T(FirstArgumentNotRegExp, \
"First argument to % must not be a regular expression") \
T(FunctionBind, "Bind must be called on a function") \ T(FunctionBind, "Bind must be called on a function") \
T(GeneratorRunning, "Generator is already running") \
T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \ T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
T(InstanceofFunctionExpected, \ T(InstanceofFunctionExpected, \
"Expecting a function in instanceof check, but got %") \ "Expecting a function in instanceof check, but got %") \
...@@ -189,8 +191,11 @@ class CallSite { ...@@ -189,8 +191,11 @@ class CallSite {
T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \ T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \
T(DateRange, "Provided date is not in valid range.") \ T(DateRange, "Provided date is not in valid range.") \
T(ExpectedLocation, "Expected Area/Location for time zone, got %") \ T(ExpectedLocation, "Expected Area/Location for time zone, got %") \
T(InvalidCodePoint, "Invalid code point %") \
T(InvalidCountValue, "Invalid count value") \
T(InvalidCurrencyCode, "Invalid currency code: %") \ T(InvalidCurrencyCode, "Invalid currency code: %") \
T(InvalidLanguageTag, "Invalid language tag: %") \ T(InvalidLanguageTag, "Invalid language tag: %") \
T(InvalidTimeValue, "Invalid time value") \
T(LocaleMatcher, "Illegal value for localeMatcher:%") \ T(LocaleMatcher, "Illegal value for localeMatcher:%") \
T(NormalizationForm, "The normalization form should be one of %.") \ T(NormalizationForm, "The normalization form should be one of %.") \
T(NumberFormatRange, "% argument must be between 0 and 20") \ T(NumberFormatRange, "% argument must be between 0 and 20") \
......
...@@ -110,7 +110,6 @@ var kMessages = { ...@@ -110,7 +110,6 @@ var kMessages = {
not_a_promise: ["%0", " is not a promise"], not_a_promise: ["%0", " is not a promise"],
resolver_not_a_function: ["Promise resolver ", "%0", " is not a function"], resolver_not_a_function: ["Promise resolver ", "%0", " is not a function"],
promise_cyclic: ["Chaining cycle detected for promise ", "%0"], promise_cyclic: ["Chaining cycle detected for promise ", "%0"],
first_argument_not_regexp: ["First argument to ", "%0", " must not be a regular expression"],
iterator_result_not_an_object: ["Iterator result ", "%0", " is not an object"], iterator_result_not_an_object: ["Iterator result ", "%0", " is not an object"],
iterator_value_not_an_object: ["Iterator value ", "%0", " is not an entry object"], iterator_value_not_an_object: ["Iterator value ", "%0", " is not an entry object"],
// RangeError // RangeError
...@@ -128,10 +127,6 @@ var kMessages = { ...@@ -128,10 +127,6 @@ var kMessages = {
invalid_data_view_length: ["Invalid data view length"], invalid_data_view_length: ["Invalid data view length"],
invalid_data_view_accessor_offset: invalid_data_view_accessor_offset:
["Offset is outside the bounds of the DataView"], ["Offset is outside the bounds of the DataView"],
invalid_time_value: ["Invalid time value"],
invalid_count_value: ["Invalid count value"],
invalid_code_point: ["Invalid code point ", "%0"],
// 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"],
......
...@@ -936,9 +936,7 @@ function StringRepeat(count) { ...@@ -936,9 +936,7 @@ function StringRepeat(count) {
var n = ToInteger(count); var n = ToInteger(count);
// The maximum string length is stored in a smi, so a longer repeat // The maximum string length is stored in a smi, so a longer repeat
// must result in a range error. // must result in a range error.
if (n < 0 || n > %_MaxSmi()) { if (n < 0 || n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue);
throw MakeRangeError("invalid_count_value", []);
}
var r = ""; var r = "";
while (true) { while (true) {
...@@ -957,8 +955,7 @@ function StringStartsWith(searchString /* position */) { // length == 1 ...@@ -957,8 +955,7 @@ function StringStartsWith(searchString /* position */) { // length == 1
var s = TO_STRING_INLINE(this); var s = TO_STRING_INLINE(this);
if (IS_REGEXP(searchString)) { if (IS_REGEXP(searchString)) {
throw MakeTypeError("first_argument_not_regexp", throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.startsWith");
["String.prototype.startsWith"]);
} }
var ss = TO_STRING_INLINE(searchString); var ss = TO_STRING_INLINE(searchString);
...@@ -986,8 +983,7 @@ function StringEndsWith(searchString /* position */) { // length == 1 ...@@ -986,8 +983,7 @@ function StringEndsWith(searchString /* position */) { // length == 1
var s = TO_STRING_INLINE(this); var s = TO_STRING_INLINE(this);
if (IS_REGEXP(searchString)) { if (IS_REGEXP(searchString)) {
throw MakeTypeError("first_argument_not_regexp", throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith");
["String.prototype.endsWith"]);
} }
var ss = TO_STRING_INLINE(searchString); var ss = TO_STRING_INLINE(searchString);
...@@ -1018,8 +1014,7 @@ function StringIncludes(searchString /* position */) { // length == 1 ...@@ -1018,8 +1014,7 @@ function StringIncludes(searchString /* position */) { // length == 1
var s = TO_STRING_INLINE(this); var s = TO_STRING_INLINE(this);
if (IS_REGEXP(searchString)) { if (IS_REGEXP(searchString)) {
throw MakeTypeError("first_argument_not_regexp", throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes");
["String.prototype.includes"]);
} }
var ss = TO_STRING_INLINE(searchString); var ss = TO_STRING_INLINE(searchString);
...@@ -1074,7 +1069,7 @@ function StringFromCodePoint(_) { // length = 1 ...@@ -1074,7 +1069,7 @@ function StringFromCodePoint(_) { // length = 1
code = ToNumber(code); code = ToNumber(code);
} }
if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) {
throw MakeRangeError("invalid_code_point", [code]); throw MakeRangeError(kInvalidCodePoint, code);
} }
if (code <= 0xFFFF) { if (code <= 0xFFFF) {
result += %_StringCharFromCode(code); result += %_StringCharFromCode(code);
......
...@@ -79,6 +79,17 @@ test(function() { ...@@ -79,6 +79,17 @@ test(function() {
Object.defineProperty(o, "x", { value: 1 }); Object.defineProperty(o, "x", { value: 1 });
}, "Cannot define property:x, object is not extensible.", TypeError); }, "Cannot define property:x, object is not extensible.", TypeError);
// kFirstArgumentNotRegExp
test(function() {
"a".startsWith(/a/);
}, "First argument to String.prototype.startsWith " +
"must not be a regular expression", TypeError);
// kFunctionBind
test(function() {
Function.prototype.bind.call(1);
}, "Bind must be called on a function", TypeError);
// kGeneratorRunning // kGeneratorRunning
test(function() { test(function() {
var iter; var iter;
...@@ -87,11 +98,6 @@ test(function() { ...@@ -87,11 +98,6 @@ test(function() {
iter.next(); iter.next();
}, "Generator is already running", TypeError); }, "Generator is already running", TypeError);
// kFunctionBind
test(function() {
Function.prototype.bind.call(1);
}, "Bind must be called on a function", TypeError);
// kIncompatibleMethodReceiver // kIncompatibleMethodReceiver
test(function() { test(function() {
RegExp.prototype.compile.call(RegExp.prototype); RegExp.prototype.compile.call(RegExp.prototype);
...@@ -259,6 +265,16 @@ test(function() { ...@@ -259,6 +265,16 @@ test(function() {
Object.defineProperty([], "length", { value: 1E100 }); Object.defineProperty([], "length", { value: 1E100 });
}, "defineProperty() array length out of range", RangeError); }, "defineProperty() array length out of range", RangeError);
// kInvalidCodePoint
test(function() {
String.fromCodePoint(-1);
}, "Invalid code point -1", RangeError);
// kInvalidCountValue
test(function() {
"a".repeat(-1);
}, "Invalid count value", RangeError);
// kNormalizationForm // kNormalizationForm
test(function() { test(function() {
"".normalize("ABC"); "".normalize("ABC");
...@@ -266,11 +282,11 @@ test(function() { ...@@ -266,11 +282,11 @@ test(function() {
// kNumberFormatRange // kNumberFormatRange
test(function() { test(function() {
Number(1).toFixed(100); Number(1).toFixed(100);
}, "toFixed() digits argument must be between 0 and 20", RangeError); }, "toFixed() digits argument must be between 0 and 20", RangeError);
test(function() { test(function() {
Number(1).toExponential(100); Number(1).toExponential(100);
}, "toExponential() argument must be between 0 and 20", RangeError); }, "toExponential() argument must be between 0 and 20", RangeError);
// kStackOverflow // kStackOverflow
......
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