Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: Source/bindings/v8/ExceptionMessages.h

Issue 211333004: Tidy up error reporting for calling-constructor-as-function. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: re-use failedToConstruct() in constructorNotCallableAsFunction(). Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 28 matching lines...) Expand all
39 39
40 class Decimal; 40 class Decimal;
41 41
42 class ExceptionMessages { 42 class ExceptionMessages {
43 public: 43 public:
44 enum BoundType { 44 enum BoundType {
45 InclusiveBound, 45 InclusiveBound,
46 ExclusiveBound, 46 ExclusiveBound,
47 }; 47 };
48 48
49 static String failedToConstruct(const String& type, const String& detail = S tring()); 49 static String argumentNullOrIncorrectType(int argumentIndex, const String& e xpectedType);
50 static String failedToEnumerate(const String& type, const String& detail = S tring()); 50 static String constructorNotCallableAsFunction(const String& type);
51 static String failedToExecute(const String& method, const String& type, cons t String& detail = String()); 51
52 static String failedToConstruct(const String& type, const String& detail);
53 static String failedToEnumerate(const String& type, const String& detail);
54 static String failedToExecute(const String& method, const String& type, cons t String& detail);
52 static String failedToGet(const String& property, const String& type, const String& detail); 55 static String failedToGet(const String& property, const String& type, const String& detail);
53 static String failedToSet(const String& property, const String& type, const String& detail); 56 static String failedToSet(const String& property, const String& type, const String& detail);
54 static String failedToDelete(const String& property, const String& type, con st String& detail); 57 static String failedToDelete(const String& property, const String& type, con st String& detail);
55 static String failedToGetIndexed(const String& type, const String& detail); 58 static String failedToGetIndexed(const String& type, const String& detail);
56 static String failedToSetIndexed(const String& type, const String& detail); 59 static String failedToSetIndexed(const String& type, const String& detail);
57 static String failedToDeleteIndexed(const String& type, const String& detail ); 60 static String failedToDeleteIndexed(const String& type, const String& detail );
58 61
62 template <typename NumType>
63 static String formatNumber(NumType number)
64 {
65 return formatFiniteNumber(number);
66 }
67
59 static String incorrectPropertyType(const String& property, const String& de tail); 68 static String incorrectPropertyType(const String& property, const String& de tail);
60 69
61 static String argumentNullOrIncorrectType(int argumentIndex, const String& e xpectedType);
62
63 // If > 0, the argument index that failed type check (1-indexed.)
64 // If == 0, a (non-argument) value (e.g., a setter) failed the same check.
65 static String notAnArrayTypeArgumentOrValue(int argumentIndex);
66 static String notASequenceTypeProperty(const String& propertyName);
67 static String notAFiniteNumber(double value, const char* name = "value provi ded");
68 static String notAFiniteNumber(const Decimal& value, const char* name = "val ue provided");
69
70 static String notEnoughArguments(unsigned expected, unsigned providedleastNu mMandatoryParams);
71
72 static String readOnly(const char* detail = 0);
73
74 template <typename NumberType> 70 template <typename NumberType>
75 static String indexExceedsMaximumBound(const char* name, NumberType given, N umberType bound) 71 static String indexExceedsMaximumBound(const char* name, NumberType given, N umberType bound)
76 { 72 {
77 bool eq = given == bound; 73 bool eq = given == bound;
78 StringBuilder result; 74 StringBuilder result;
79 result.append("The "); 75 result.append("The ");
80 result.append(name); 76 result.append(name);
81 result.append(" provided ("); 77 result.append(" provided (");
82 result.append(formatNumber(given)); 78 result.append(formatNumber(given));
83 result.append(") is greater than "); 79 result.append(") is greater than ");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 result.append(") is outside the range "); 112 result.append(") is outside the range ");
117 result.append(lowerType == ExclusiveBound ? '(' : '['); 113 result.append(lowerType == ExclusiveBound ? '(' : '[');
118 result.append(formatNumber(lowerBound)); 114 result.append(formatNumber(lowerBound));
119 result.append(", "); 115 result.append(", ");
120 result.append(formatNumber(upperBound)); 116 result.append(formatNumber(upperBound));
121 result.append(upperType == ExclusiveBound ? ')' : ']'); 117 result.append(upperType == ExclusiveBound ? ')' : ']');
122 result.append('.'); 118 result.append('.');
123 return result.toString(); 119 return result.toString();
124 } 120 }
125 121
126 template <typename NumType> 122 // If > 0, the argument index that failed type check (1-indexed.)
127 static String formatNumber(NumType number) 123 // If == 0, a (non-argument) value (e.g., a setter) failed the same check.
128 { 124 static String notAnArrayTypeArgumentOrValue(int argumentIndex);
129 return formatFiniteNumber(number); 125 static String notASequenceTypeProperty(const String& propertyName);
130 } 126 static String notAFiniteNumber(double value, const char* name = "value provi ded");
127 static String notAFiniteNumber(const Decimal& value, const char* name = "val ue provided");
128
129 static String notEnoughArguments(unsigned expected, unsigned providedleastNu mMandatoryParams);
130
131 static String readOnly(const char* detail = 0);
131 132
132 private: 133 private:
133 static String ordinalNumber(int number);
134
135
136 template <typename NumType> 134 template <typename NumType>
137 static String formatFiniteNumber(NumType number) 135 static String formatFiniteNumber(NumType number)
138 { 136 {
139 if (number > 1e20 || number < -1e20) 137 if (number > 1e20 || number < -1e20)
140 return String::format("%e", 1.0*number); 138 return String::format("%e", 1.0*number);
141 return String::number(number); 139 return String::number(number);
142 } 140 }
143 141
144 template <typename NumType> 142 template <typename NumType>
145 static String formatPotentiallyNonFiniteNumber(NumType number) 143 static String formatPotentiallyNonFiniteNumber(NumType number)
146 { 144 {
147 if (std::isnan(number)) 145 if (std::isnan(number))
148 return "NaN"; 146 return "NaN";
149 if (std::isinf(number)) 147 if (std::isinf(number))
150 return number > 0 ? "Infinity" : "-Infinity"; 148 return number > 0 ? "Infinity" : "-Infinity";
151 if (number > 1e20 || number < -1e20) 149 if (number > 1e20 || number < -1e20)
152 return String::format("%e", number); 150 return String::format("%e", number);
153 return String::number(number); 151 return String::number(number);
154 } 152 }
153
154 static String ordinalNumber(int number);
155 }; 155 };
156 156
157 template <> String ExceptionMessages::formatNumber<float>(float number); 157 template <> String ExceptionMessages::formatNumber<float>(float number);
158 template <> String ExceptionMessages::formatNumber<double>(double number); 158 template <> String ExceptionMessages::formatNumber<double>(double number);
159 159
160 } // namespace WebCore 160 } // namespace WebCore
161 161
162 #endif // ExceptionMessages_h 162 #endif // ExceptionMessages_h
OLDNEW
« no previous file with comments | « Source/bindings/tests/results/V8TestTypedefs.cpp ('k') | Source/bindings/v8/ExceptionMessages.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698