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

Side by Side Diff: sky/engine/bindings2/exception_messages.h

Issue 918333002: Add the c++ code part of bindings2/ (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Updated per earlier reviews Created 5 years, 10 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
« no previous file with comments | « sky/engine/bindings2/dart_event_listener.cc ('k') | sky/engine/bindings2/exception_messages.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SKY_ENGINE_BINDINGS2_EXCEPTIONMESSAGES_H_
6 #define SKY_ENGINE_BINDINGS2_EXCEPTIONMESSAGES_H_
7
8 #include "sky/engine/wtf/MathExtras.h"
9 #include "sky/engine/wtf/text/StringBuilder.h"
10 #include "sky/engine/wtf/text/WTFString.h"
11
12 namespace blink {
13
14 class Decimal;
15
16 class ExceptionMessages {
17 public:
18 enum BoundType {
19 InclusiveBound,
20 ExclusiveBound,
21 };
22
23 static String argumentNullOrIncorrectType(int argumentIndex,
24 const String& expectedType);
25 static String constructorNotCallableAsFunction(const char* type);
26
27 static String failedToConstruct(const char* type, const String& detail);
28 static String failedToEnumerate(const char* type, const String& detail);
29 static String failedToExecute(const char* method,
30 const char* type,
31 const String& detail);
32 static String failedToGet(const char* property,
33 const char* type,
34 const String& detail);
35 static String failedToSet(const char* property,
36 const char* type,
37 const String& detail);
38 static String failedToDelete(const char* property,
39 const char* type,
40 const String& detail);
41 static String failedToGetIndexed(const char* type, const String& detail);
42 static String failedToSetIndexed(const char* type, const String& detail);
43 static String failedToDeleteIndexed(const char* type, const String& detail);
44
45 template <typename NumType>
46 static String formatNumber(NumType number) {
47 return formatFiniteNumber(number);
48 }
49
50 static String incorrectPropertyType(const String& property,
51 const String& detail);
52
53 template <typename NumberType>
54 static String indexExceedsMaximumBound(const char* name,
55 NumberType given,
56 NumberType bound) {
57 bool eq = given == bound;
58 StringBuilder result;
59 result.appendLiteral("The ");
60 result.append(name);
61 result.appendLiteral(" provided (");
62 result.append(formatNumber(given));
63 result.appendLiteral(") is greater than ");
64 result.append(eq ? "or equal to " : "");
65 result.appendLiteral("the maximum bound (");
66 result.append(formatNumber(bound));
67 result.appendLiteral(").");
68 return result.toString();
69 }
70
71 template <typename NumberType>
72 static String indexExceedsMinimumBound(const char* name,
73 NumberType given,
74 NumberType bound) {
75 bool eq = given == bound;
76 StringBuilder result;
77 result.appendLiteral("The ");
78 result.append(name);
79 result.appendLiteral(" provided (");
80 result.append(formatNumber(given));
81 result.appendLiteral(") is less than ");
82 result.append(eq ? "or equal to " : "");
83 result.appendLiteral("the minimum bound (");
84 result.append(formatNumber(bound));
85 result.appendLiteral(").");
86 return result.toString();
87 }
88
89 template <typename NumberType>
90 static String indexOutsideRange(const char* name,
91 NumberType given,
92 NumberType lowerBound,
93 BoundType lowerType,
94 NumberType upperBound,
95 BoundType upperType) {
96 StringBuilder result;
97 result.appendLiteral("The ");
98 result.append(name);
99 result.appendLiteral(" provided (");
100 result.append(formatNumber(given));
101 result.appendLiteral(") is outside the range ");
102 result.append(lowerType == ExclusiveBound ? '(' : '[');
103 result.append(formatNumber(lowerBound));
104 result.appendLiteral(", ");
105 result.append(formatNumber(upperBound));
106 result.append(upperType == ExclusiveBound ? ')' : ']');
107 result.append('.');
108 return result.toString();
109 }
110
111 static String invalidArity(const char* expected, unsigned provided);
112
113 // If > 0, the argument index that failed type check (1-indexed.)
114 // If == 0, a (non-argument) value (e.g., a setter) failed the same check.
115 static String notAnArrayTypeArgumentOrValue(int argumentIndex);
116 static String notASequenceTypeProperty(const String& propertyName);
117 static String notAFiniteNumber(double value,
118 const char* name = "value provided");
119 static String notAFiniteNumber(const Decimal& value,
120 const char* name = "value provided");
121
122 static String notEnoughArguments(unsigned expected, unsigned provided);
123
124 static String readOnly(const char* detail = 0);
125
126 private:
127 template <typename NumType>
128 static String formatFiniteNumber(NumType number) {
129 if (number > 1e20 || number < -1e20)
130 return String::format("%e", 1.0 * number);
131 return String::number(number);
132 }
133
134 template <typename NumType>
135 static String formatPotentiallyNonFiniteNumber(NumType number) {
136 if (std::isnan(number))
137 return "NaN";
138 if (std::isinf(number))
139 return number > 0 ? "Infinity" : "-Infinity";
140 if (number > 1e20 || number < -1e20)
141 return String::format("%e", number);
142 return String::number(number);
143 }
144
145 static String ordinalNumber(int number);
146 };
147
148 template <>
149 String ExceptionMessages::formatNumber<float>(float number);
150 template <>
151 String ExceptionMessages::formatNumber<double>(double number);
152
153 } // namespace blink
154
155 #endif // SKY_ENGINE_BINDINGS2_EXCEPTIONMESSAGES_H_
OLDNEW
« no previous file with comments | « sky/engine/bindings2/dart_event_listener.cc ('k') | sky/engine/bindings2/exception_messages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698