Migrate error messages, part 6. (string.js and date.js)
authoryangguo <yangguo@chromium.org>
Thu, 30 Apr 2015 16:22:00 +0000 (09:22 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 30 Apr 2015 16:22:05 +0000 (16:22 +0000)
R=mvstanton@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28180}

src/date.js
src/messages.h
src/messages.js
src/string.js
test/mjsunit/messages.js

index 577957d..4bf5340 100644 (file)
@@ -691,7 +691,7 @@ function PadInt(n, digits) {
 // ECMA 262 - 15.9.5.43
 function DateToISOString() {
   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_string;
   if (year >= 0 && year <= 9999) {
index f031496..feb25f9 100644 (file)
@@ -131,8 +131,10 @@ class CallSite {
   T(CannotConvertToPrimitive, "Cannot convert object to primitive value")      \
   T(DateType, "this is not a Date object.")                                    \
   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(GeneratorRunning, "Generator is already running")                          \
   T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %")  \
   T(InstanceofFunctionExpected,                                                \
     "Expecting a function in instanceof check, but got %")                     \
@@ -189,8 +191,11 @@ class CallSite {
   T(ArrayLengthOutOfRange, "defineProperty() array length out of range")       \
   T(DateRange, "Provided date is not in valid range.")                         \
   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(InvalidLanguageTag, "Invalid language tag: %")                             \
+  T(InvalidTimeValue, "Invalid time value")                                    \
   T(LocaleMatcher, "Illegal value for localeMatcher:%")                        \
   T(NormalizationForm, "The normalization form should be one of %.")           \
   T(NumberFormatRange, "% argument must be between 0 and 20")                  \
index 9b2c440..71a1325 100644 (file)
@@ -110,7 +110,6 @@ var kMessages = {
   not_a_promise:                 ["%0", " is not a promise"],
   resolver_not_a_function:       ["Promise resolver ", "%0", " is not a function"],
   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_value_not_an_object:  ["Iterator value ", "%0", " is not an entry object"],
   // RangeError
@@ -128,10 +127,6 @@ var kMessages = {
   invalid_data_view_length:      ["Invalid data view length"],
   invalid_data_view_accessor_offset:
                                  ["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
   invalid_lhs_in_assignment:     ["Invalid left-hand side in assignment"],
   invalid_lhs_in_for:            ["Invalid left-hand side in for-loop"],
index 9f7755b..fa57b9a 100644 (file)
@@ -936,9 +936,7 @@ function StringRepeat(count) {
   var n = ToInteger(count);
   // The maximum string length is stored in a smi, so a longer repeat
   // must result in a range error.
-  if (n < 0 || n > %_MaxSmi()) {
-    throw MakeRangeError("invalid_count_value", []);
-  }
+  if (n < 0 || n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue);
 
   var r = "";
   while (true) {
@@ -957,8 +955,7 @@ function StringStartsWith(searchString /* position */) {  // length == 1
   var s = TO_STRING_INLINE(this);
 
   if (IS_REGEXP(searchString)) {
-    throw MakeTypeError("first_argument_not_regexp",
-                        ["String.prototype.startsWith"]);
+    throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.startsWith");
   }
 
   var ss = TO_STRING_INLINE(searchString);
@@ -986,8 +983,7 @@ function StringEndsWith(searchString /* position */) {  // length == 1
   var s = TO_STRING_INLINE(this);
 
   if (IS_REGEXP(searchString)) {
-    throw MakeTypeError("first_argument_not_regexp",
-                        ["String.prototype.endsWith"]);
+    throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith");
   }
 
   var ss = TO_STRING_INLINE(searchString);
@@ -1018,8 +1014,7 @@ function StringIncludes(searchString /* position */) {  // length == 1
   var s = TO_STRING_INLINE(this);
 
   if (IS_REGEXP(searchString)) {
-    throw MakeTypeError("first_argument_not_regexp",
-                        ["String.prototype.includes"]);
+    throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes");
   }
 
   var ss = TO_STRING_INLINE(searchString);
@@ -1074,7 +1069,7 @@ function StringFromCodePoint(_) {  // length = 1
       code = ToNumber(code);
     }
     if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) {
-      throw MakeRangeError("invalid_code_point", [code]);
+      throw MakeRangeError(kInvalidCodePoint, code);
     }
     if (code <= 0xFFFF) {
       result += %_StringCharFromCode(code);
index 4b6915d..20a9361 100644 (file)
@@ -79,6 +79,17 @@ test(function() {
   Object.defineProperty(o, "x", { value: 1 });
 }, "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
 test(function() {
   var iter;
@@ -87,11 +98,6 @@ test(function() {
   iter.next();
 }, "Generator is already running", TypeError);
 
-// kFunctionBind
-test(function() {
-  Function.prototype.bind.call(1);
-}, "Bind must be called on a function", TypeError);
-
 // kIncompatibleMethodReceiver
 test(function() {
   RegExp.prototype.compile.call(RegExp.prototype);
@@ -259,6 +265,16 @@ test(function() {
   Object.defineProperty([], "length", { value: 1E100 });
 }, "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
 test(function() {
   "".normalize("ABC");
@@ -266,11 +282,11 @@ test(function() {
 
 // kNumberFormatRange
 test(function() {
-Number(1).toFixed(100);
+  Number(1).toFixed(100);
 }, "toFixed() digits argument must be between 0 and 20", RangeError);
 
 test(function() {
-Number(1).toExponential(100);
+  Number(1).toExponential(100);
 }, "toExponential() argument must be between 0 and 20", RangeError);
 
 // kStackOverflow