Migrate error messages, part 7.
authoryangguo <yangguo@chromium.org>
Tue, 5 May 2015 07:57:37 +0000 (00:57 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 5 May 2015 07:57:36 +0000 (07:57 +0000)
R=mvstanton@chromium.org

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

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

13 files changed:
src/arraybuffer.js
src/collection.js
src/harmony-array.js
src/harmony-regexp.js
src/harmony-typedarray.js
src/messages.h
src/messages.js
src/object-observe.js
src/runtime/runtime-internal.cc
src/runtime/runtime-typedarray.cc
src/typedarray.js
src/weak-collection.js
test/mjsunit/messages.js

index 2a6ef80..bfd8693 100644 (file)
@@ -18,7 +18,7 @@ function ArrayBufferConstructor(length) { // length = 1
     var byteLength = ToPositiveInteger(length, 'invalid_array_buffer_length');
     %ArrayBufferInitialize(this, byteLength);
   } else {
-    throw MakeTypeError('constructor_not_function', ["ArrayBuffer"]);
+    throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer");
   }
 }
 
index 206aaa7..04a4d94 100644 (file)
@@ -91,7 +91,7 @@ function GetHash(key) {
 
 function SetConstructor(iterable) {
   if (!%_IsConstructCall()) {
-    throw MakeTypeError('constructor_not_function', ['Set']);
+    throw MakeTypeError(kConstructorNotFunction, "Set");
   }
 
   %_SetInitialize(this);
@@ -254,7 +254,7 @@ InstallFunctions(GlobalSet.prototype, DONT_ENUM, [
 
 function MapConstructor(iterable) {
   if (!%_IsConstructCall()) {
-    throw MakeTypeError('constructor_not_function', ['Map']);
+    throw MakeTypeError(kConstructorNotFunction, "Map");
   }
 
   %_MapInitialize(this);
@@ -267,7 +267,7 @@ function MapConstructor(iterable) {
 
     for (var nextItem of iterable) {
       if (!IS_SPEC_OBJECT(nextItem)) {
-        throw MakeTypeError('iterator_value_not_an_object', [nextItem]);
+        throw MakeTypeError(kIteratorValueNotAnObject, nextItem);
       }
       %_CallFunction(this, nextItem[0], nextItem[1], adder);
     }
index b24caff..63c0d43 100644 (file)
@@ -213,7 +213,7 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
       var next = iterator.next();
 
       if (!IS_OBJECT(next)) {
-        throw MakeTypeError("iterator_result_not_an_object", [next]);
+        throw MakeTypeError(kIteratorResultNotAnObject, next);
       }
 
       if (next.done) {
index c90eb80..f8e721f 100644 (file)
@@ -16,8 +16,7 @@ var GlobalRegExp = global.RegExp;
 // + https://bugs.ecmascript.org/show_bug.cgi?id=3423
 function RegExpGetFlags() {
   if (!IS_SPEC_OBJECT(this)) {
-    throw MakeTypeError('flags_getter_non_object',
-                        [%ToString(this)]);
+    throw MakeTypeError(kFlagsGetterNonObject, %ToString(this));
   }
   var result = '';
   if (this.global) result += 'g';
index 7fc01cb..168481b 100644 (file)
@@ -28,9 +28,7 @@ macro TYPED_ARRAY_HARMONY_ADDITIONS(ARRAY_ID, NAME, ELEMENT_SIZE)
 
 // ES6 draft 08-24-14, section 22.2.3.12
 function NAMEForEach(f /* thisArg */) {  // length == 1
-  if (!%IsTypedArray(this)) {
-    throw MakeTypeError('not_typed_array', []);
-  }
+  if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
   if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
 
   var length = %_TypedArrayGetLength(this);
index feb25f9..7c7b26f 100644 (file)
@@ -127,12 +127,15 @@ class CallSite {
   T(CalledNonCallable, "% is not a function")                                  \
   T(CalledOnNonObject, "% called on non-object")                               \
   T(CalledOnNullOrUndefined, "% called on null or undefined")                  \
-  T(CurrencyCode, "Currency code is required with currency style.")            \
   T(CannotConvertToPrimitive, "Cannot convert object to primitive value")      \
+  T(ConstructorNotFunction, "Constructor % requires 'new'")                    \
+  T(CurrencyCode, "Currency code is required with currency style.")            \
   T(DateType, "this is not a Date object.")                                    \
   T(DefineDisallowed, "Cannot define property:%, object is not extensible.")   \
   T(FirstArgumentNotRegExp,                                                    \
     "First argument to % must not be a regular expression")                    \
+  T(FlagsGetterNonObject,                                                      \
+    "RegExp.prototype.flags getter called on non-object %")                    \
   T(FunctionBind, "Bind must be called on a function")                         \
   T(GeneratorRunning, "Generator is already running")                          \
   T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %")  \
@@ -141,6 +144,8 @@ class CallSite {
   T(InstanceofNonobjectProto,                                                  \
     "Function has non-object prototype '%' in instanceof check")               \
   T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %")   \
+  T(IteratorResultNotAnObject, "Iterator result % is not an object")           \
+  T(IteratorValueNotAnObject, "Iterator value % is not an entry object")       \
   T(LanguageID, "Language ID should be string or object.")                     \
   T(MethodCalledOnWrongObject,                                                 \
     "Method % called on a non-object or on a wrong type of object.")           \
@@ -151,12 +156,25 @@ class CallSite {
   T(NotConstructor, "% is not a constructor")                                  \
   T(NotGeneric, "% is not generic")                                            \
   T(NotIterable, "% is not iterable")                                          \
+  T(NotTypedArray, "this is not a typed array.")                               \
   T(ObjectGetterExpectingFunction,                                             \
     "Object.prototype.__defineGetter__: Expecting function")                   \
   T(ObjectGetterCallable, "Getter must be a function: %")                      \
   T(ObjectSetterExpectingFunction,                                             \
     "Object.prototype.__defineSetter__: Expecting function")                   \
   T(ObjectSetterCallable, "Setter must be a function: %")                      \
+  T(ObserveCallbackFrozen,                                                     \
+    "Object.observe cannot deliver to a frozen function object")               \
+  T(ObserveGlobalProxy, "% cannot be called on the global proxy object")       \
+  T(ObserveInvalidAccept,                                                      \
+    "Third argument to Object.observe must be an array of strings.")           \
+  T(ObserveNonFunction, "Object.% cannot deliver to non-function")             \
+  T(ObserveNonObject, "Object.% cannot % non-object")                          \
+  T(ObserveNotifyNonNotifier, "notify called on non-notifier object")          \
+  T(ObservePerformNonFunction, "Cannot perform non-function")                  \
+  T(ObservePerformNonString, "Invalid non-string changeType")                  \
+  T(ObserveTypeNonString,                                                      \
+    "Invalid changeRecord with non-string 'type' property")                    \
   T(OrdinaryFunctionCalledAsConstructor,                                       \
     "Function object that's not a constructor was created with new")           \
   T(PropertyDescObject, "Property description must be an object: %")           \
index 4d400f2..dd8caf3 100644 (file)
@@ -82,7 +82,6 @@ var kMessages = {
   non_object_property_store:     ["Cannot set property '", "%0", "' of ", "%1"],
   illegal_invocation:            ["Illegal invocation"],
   no_setter_in_callback:         ["Cannot set property ", "%0", " of ", "%1", " which has only a getter"],
-  flags_getter_non_object:       ["RegExp.prototype.flags getter called on non-object ", "%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"],
   non_extensible_proto:          ["%0", " is not extensible"],
@@ -93,25 +92,12 @@ var kMessages = {
   invalid_weakmap_key:           ["Invalid value used as weak map key"],
   invalid_weakset_value:         ["Invalid value used in weak set"],
   not_date_object:               ["this is not a Date object."],
-  observe_non_object:            ["Object.", "%0", " cannot ", "%0", " non-object"],
-  observe_non_function:          ["Object.", "%0", " cannot deliver to non-function"],
-  observe_callback_frozen:       ["Object.observe cannot deliver to a frozen function object"],
-  observe_invalid_accept:        ["Third argument to Object.observe must be an array of strings."],
-  observe_type_non_string:       ["Invalid changeRecord with non-string 'type' property"],
-  observe_perform_non_string:    ["Invalid non-string changeType"],
-  observe_perform_non_function:  ["Cannot perform non-function"],
-  observe_notify_non_notifier:   ["notify called on non-notifier object"],
-  observe_global_proxy:          ["%0", " cannot be called on the global proxy object"],
-  not_typed_array:               ["this is not a typed array."],
   invalid_argument:              ["invalid_argument"],
   data_view_not_array_buffer:    ["First argument to DataView constructor must be an ArrayBuffer"],
-  constructor_not_function:      ["Constructor ", "%0", " requires 'new'"],
   not_a_symbol:                  ["%0", " is not a symbol"],
   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"],
-  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
   invalid_array_length:          ["Invalid array length"],
   invalid_array_buffer_length:   ["Invalid array buffer length"],
index 11562cb..a9eb1e0 100644 (file)
@@ -315,8 +315,7 @@ function ConvertAcceptListToTypeMap(arg) {
   if (IS_UNDEFINED(arg))
     return arg;
 
-  if (!IS_SPEC_OBJECT(arg))
-    throw MakeTypeError("observe_invalid_accept");
+  if (!IS_SPEC_OBJECT(arg)) throw MakeTypeError(kObserveInvalidAccept);
 
   var len = ToInteger(arg.length);
   if (len < 0) len = 0;
@@ -372,13 +371,13 @@ function CallbackInfoNormalize(callback) {
 
 function ObjectObserve(object, callback, acceptList) {
   if (!IS_SPEC_OBJECT(object))
-    throw MakeTypeError("observe_non_object", ["observe"]);
+    throw MakeTypeError(kObserveNonObject, "observe", "observe");
   if (%IsJSGlobalProxy(object))
-    throw MakeTypeError("observe_global_proxy", ["observe"]);
+    throw MakeTypeError(kObserveGlobalProxy, "observe");
   if (!IS_SPEC_FUNCTION(callback))
-    throw MakeTypeError("observe_non_function", ["observe"]);
+    throw MakeTypeError(kObserveNonFunction, "observe");
   if (ObjectIsFrozen(callback))
-    throw MakeTypeError("observe_callback_frozen");
+    throw MakeTypeError(kObserveCallbackFrozen);
 
   var objectObserveFn = %GetObjectContextObjectObserve(object);
   return objectObserveFn(object, callback, acceptList);
@@ -395,11 +394,11 @@ function NativeObjectObserve(object, callback, acceptList) {
 
 function ObjectUnobserve(object, callback) {
   if (!IS_SPEC_OBJECT(object))
-    throw MakeTypeError("observe_non_object", ["unobserve"]);
+    throw MakeTypeError(kObserveNonObject, "unobserve", "unobserve");
   if (%IsJSGlobalProxy(object))
-    throw MakeTypeError("observe_global_proxy", ["unobserve"]);
+    throw MakeTypeError(kObserveGlobalProxy, "unobserve");
   if (!IS_SPEC_FUNCTION(callback))
-    throw MakeTypeError("observe_non_function", ["unobserve"]);
+    throw MakeTypeError(kObserveNonFunction, "unobserve");
 
   var objectInfo = ObjectInfoGet(object);
   if (IS_UNDEFINED(objectInfo))
@@ -558,9 +557,9 @@ function ObjectNotifierNotify(changeRecord) {
 
   var objectInfo = ObjectInfoGetFromNotifier(this);
   if (IS_UNDEFINED(objectInfo))
-    throw MakeTypeError("observe_notify_non_notifier");
+    throw MakeTypeError(kObserveNotifyNonNotifier);
   if (!IS_STRING(changeRecord.type))
-    throw MakeTypeError("observe_type_non_string");
+    throw MakeTypeError(kObserveTypeNonString);
 
   ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord);
 }
@@ -572,11 +571,11 @@ function ObjectNotifierPerformChange(changeType, changeFn) {
 
   var objectInfo = ObjectInfoGetFromNotifier(this);
   if (IS_UNDEFINED(objectInfo))
-    throw MakeTypeError("observe_notify_non_notifier");
+    throw MakeTypeError(kObserveNotifyNonNotifier);
   if (!IS_STRING(changeType))
-    throw MakeTypeError("observe_perform_non_string");
+    throw MakeTypeError(kObservePerformNonString);
   if (!IS_SPEC_FUNCTION(changeFn))
-    throw MakeTypeError("observe_perform_non_function");
+    throw MakeTypeError(kObservePerformNonFunction);
 
   var performChangeFn = %GetObjectContextNotifierPerformChange(objectInfo);
   performChangeFn(objectInfo, changeType, changeFn);
@@ -600,9 +599,9 @@ function NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) {
 
 function ObjectGetNotifier(object) {
   if (!IS_SPEC_OBJECT(object))
-    throw MakeTypeError("observe_non_object", ["getNotifier"]);
+    throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier");
   if (%IsJSGlobalProxy(object))
-    throw MakeTypeError("observe_global_proxy", ["getNotifier"]);
+    throw MakeTypeError(kObserveGlobalProxy, "getNotifier");
 
   if (ObjectIsFrozen(object)) return null;
 
@@ -644,7 +643,7 @@ function CallbackDeliverPending(callback) {
 
 function ObjectDeliverChangeRecords(callback) {
   if (!IS_SPEC_FUNCTION(callback))
-    throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]);
+    throw MakeTypeError(kObserveNonFunction, "deliverChangeRecords");
 
   while (CallbackDeliverPending(callback)) {}
 }
index 343d24f..f17c4f6 100644 (file)
@@ -66,7 +66,7 @@ RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) {
   CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
   THROW_NEW_ERROR_RETURN_FAILURE(
       isolate,
-      NewTypeError("iterator_result_not_an_object", HandleVector(&value, 1)));
+      NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value));
 }
 
 
index 93ff56d..2692956 100644 (file)
@@ -5,6 +5,7 @@
 #include "src/v8.h"
 
 #include "src/arguments.h"
+#include "src/messages.h"
 #include "src/runtime/runtime.h"
 #include "src/runtime/runtime-utils.h"
 
@@ -399,8 +400,7 @@ RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) {
   DCHECK(args.length() == 3);
   if (!args[0]->IsJSTypedArray()) {
     THROW_NEW_ERROR_RETURN_FAILURE(
-        isolate,
-        NewTypeError("not_typed_array", HandleVector<Object>(NULL, 0)));
+        isolate, NewTypeError(MessageTemplate::kNotTypedArray));
   }
 
   if (!args[1]->IsJSTypedArray())
index 4e3b938..c9c6056 100644 (file)
@@ -113,7 +113,7 @@ function NAMEConstructor(arg1, arg2, arg3) {
       NAMEConstructByArrayLike(this, arg1);
     }
   } else {
-    throw MakeTypeError("constructor_not_function", ["NAME"])
+    throw MakeTypeError(kConstructorNotFunction, "NAME")
   }
 }
 
index 02804af..ccb2c35 100644 (file)
@@ -17,7 +17,7 @@ var GlobalWeakSet = global.WeakSet;
 
 function WeakMapConstructor(iterable) {
   if (!%_IsConstructCall()) {
-    throw MakeTypeError('constructor_not_function', ['WeakMap']);
+    throw MakeTypeError(kConstructorNotFunction, "WeakMap");
   }
 
   %WeakCollectionInitialize(this);
@@ -29,7 +29,7 @@ function WeakMapConstructor(iterable) {
     }
     for (var nextItem of iterable) {
       if (!IS_SPEC_OBJECT(nextItem)) {
-        throw MakeTypeError('iterator_value_not_an_object', [nextItem]);
+        throw MakeTypeError(kIteratorValueNotAnObject, nextItem);
       }
       %_CallFunction(this, nextItem[0], nextItem[1], adder);
     }
@@ -102,7 +102,7 @@ InstallFunctions(GlobalWeakMap.prototype, DONT_ENUM, [
 
 function WeakSetConstructor(iterable) {
   if (!%_IsConstructCall()) {
-    throw MakeTypeError('constructor_not_function', ['WeakSet']);
+    throw MakeTypeError(kConstructorNotFunction, "WeakSet");
   }
 
   %WeakCollectionInitialize(this);
index 20a9361..3eae74c 100644 (file)
@@ -2,7 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --stack-size=100 --harmony --harmony-reflect
+// Flags: --stack-size=100 --harmony --harmony-reflect --harmony-arrays
+// Flags: --harmony-regexps
 
 function test(f, expected, type) {
   try {
@@ -66,6 +67,11 @@ test(function() {
   [].join(Object(Symbol(1)));
 }, "Cannot convert object to primitive value", TypeError);
 
+// kConstructorNotFunction
+test(function() {
+  Uint16Array(1);
+}, "Constructor Uint16Array requires 'new'", TypeError);
+
 // kDateType
 test(function() {
   Date.prototype.setYear.call({}, 1);
@@ -85,6 +91,11 @@ test(function() {
 }, "First argument to String.prototype.startsWith " +
    "must not be a regular expression", TypeError);
 
+// kFlagsGetterNonObject
+test(function() {
+  Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get.call(1);
+}, "RegExp.prototype.flags getter called on non-object 1", TypeError);
+
 // kFunctionBind
 test(function() {
   Function.prototype.bind.call(1);
@@ -122,6 +133,18 @@ test(function() {
   1 in 1;
 }, "Cannot use 'in' operator to search for '1' in 1", TypeError);
 
+// kIteratorResultNotAnObject
+test(function() {
+  var obj = {};
+  obj[Symbol.iterator] = function() { return { next: function() { return 1 }}};
+  Array.from(obj);
+}, "Iterator result 1 is not an object", TypeError);
+
+// kIteratorValueNotAnObject
+test(function() {
+  new Map([1]);
+}, "Iterator value 1 is not an entry object", TypeError);
+
 // kNotConstructor
 test(function() {
   new Symbol();
@@ -156,6 +179,11 @@ test(function() {
   Function.prototype.toString.call(1);
 }, "Function.prototype.toString is not generic", TypeError);
 
+// kNotTypedArray
+test(function() {
+  Uint16Array.prototype.forEach.call(1);
+}, "this is not a typed array.", TypeError);
+
 // kObjectGetterExpectingFunction
 test(function() {
   ({}).__defineGetter__("x", 0);