Reviewers: mvstanton,

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

[email protected]

Please review this at https://codereview.chromium.org/1116953002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+35, -22 lines):
  M src/date.js
  M src/messages.h
  M src/messages.js
  M src/string.js
  M test/mjsunit/messages.js


Index: src/date.js
diff --git a/src/date.js b/src/date.js
index 11cf4e91e79b3a007182e3615232cfee87b3394b..81246cfd91d0995b86d548c609367ba31fdff51d 100644
--- a/src/date.js
+++ b/src/date.js
@@ -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: src/messages.h
diff --git a/src/messages.h b/src/messages.h
index f031496000c2de911813543eb3446cca465195ea..feb25f93d8183701b2bdcc439f929f624c31d383 100644
--- a/src/messages.h
+++ b/src/messages.h
@@ -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: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index b81215ebe9b794ed5926b3a64ea56b29389c1e8c..bc2f5186d07acabd3335abd7d9cacb4e28664693 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -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
@@ -130,8 +129,6 @@ var kMessages = {
["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: src/string.js
diff --git a/src/string.js b/src/string.js
index 87823d92644abc6c59b1b314c8b410ad199e0229..14350732b66131c1bc271c2a35f5bb5e3167a5f2 100644
--- a/src/string.js
+++ b/src/string.js
@@ -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: test/mjsunit/messages.js
diff --git a/test/mjsunit/messages.js b/test/mjsunit/messages.js
index 4b6915d6407add40209d5b2d52c22716d7cf21c1..20a93615094eb8af84688c8c16fb1b2e8272c665 100644
--- a/test/mjsunit/messages.js
+++ b/test/mjsunit/messages.js
@@ -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


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to