| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef SKY_ENGINE_BINDINGS_CORE_V8_EXCEPTIONMESSAGES_H_ | 31 #ifndef ExceptionMessages_h |
| 32 #define SKY_ENGINE_BINDINGS_CORE_V8_EXCEPTIONMESSAGES_H_ | 32 #define ExceptionMessages_h |
| 33 | 33 |
| 34 #include "sky/engine/wtf/MathExtras.h" | 34 #include "wtf/MathExtras.h" |
| 35 #include "sky/engine/wtf/text/StringBuilder.h" | 35 #include "wtf/text/StringBuilder.h" |
| 36 #include "sky/engine/wtf/text/WTFString.h" | 36 #include "wtf/text/WTFString.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 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, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 65 return formatFiniteNumber(number); | 65 return formatFiniteNumber(number); |
| 66 } | 66 } |
| 67 | 67 |
| 68 static String incorrectPropertyType(const String& property, const String& de
tail); | 68 static String incorrectPropertyType(const String& property, const String& de
tail); |
| 69 | 69 |
| 70 template <typename NumberType> | 70 template <typename NumberType> |
| 71 static String indexExceedsMaximumBound(const char* name, NumberType given, N
umberType bound) | 71 static String indexExceedsMaximumBound(const char* name, NumberType given, N
umberType bound) |
| 72 { | 72 { |
| 73 bool eq = given == bound; | 73 bool eq = given == bound; |
| 74 StringBuilder result; | 74 StringBuilder result; |
| 75 result.appendLiteral("The "); | 75 result.append("The "); |
| 76 result.append(name); | 76 result.append(name); |
| 77 result.appendLiteral(" provided ("); | 77 result.append(" provided ("); |
| 78 result.append(formatNumber(given)); | 78 result.append(formatNumber(given)); |
| 79 result.appendLiteral(") is greater than "); | 79 result.append(") is greater than "); |
| 80 result.append(eq ? "or equal to " : ""); | 80 result.append(eq ? "or equal to " : ""); |
| 81 result.appendLiteral("the maximum bound ("); | 81 result.append("the maximum bound ("); |
| 82 result.append(formatNumber(bound)); | 82 result.append(formatNumber(bound)); |
| 83 result.appendLiteral(")."); | 83 result.append(")."); |
| 84 return result.toString(); | 84 return result.toString(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 template <typename NumberType> | 87 template <typename NumberType> |
| 88 static String indexExceedsMinimumBound(const char* name, NumberType given, N
umberType bound) | 88 static String indexExceedsMinimumBound(const char* name, NumberType given, N
umberType bound) |
| 89 { | 89 { |
| 90 bool eq = given == bound; | 90 bool eq = given == bound; |
| 91 StringBuilder result; | 91 StringBuilder result; |
| 92 result.appendLiteral("The "); | 92 result.append("The "); |
| 93 result.append(name); | 93 result.append(name); |
| 94 result.appendLiteral(" provided ("); | 94 result.append(" provided ("); |
| 95 result.append(formatNumber(given)); | 95 result.append(formatNumber(given)); |
| 96 result.appendLiteral(") is less than "); | 96 result.append(") is less than "); |
| 97 result.append(eq ? "or equal to " : ""); | 97 result.append(eq ? "or equal to " : ""); |
| 98 result.appendLiteral("the minimum bound ("); | 98 result.append("the minimum bound ("); |
| 99 result.append(formatNumber(bound)); | 99 result.append(formatNumber(bound)); |
| 100 result.appendLiteral(")."); | 100 result.append(")."); |
| 101 return result.toString(); | 101 return result.toString(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 template <typename NumberType> | 104 template <typename NumberType> |
| 105 static String indexOutsideRange(const char* name, NumberType given, NumberTy
pe lowerBound, BoundType lowerType, NumberType upperBound, BoundType upperType) | 105 static String indexOutsideRange(const char* name, NumberType given, NumberTy
pe lowerBound, BoundType lowerType, NumberType upperBound, BoundType upperType) |
| 106 { | 106 { |
| 107 StringBuilder result; | 107 StringBuilder result; |
| 108 result.appendLiteral("The "); | 108 result.append("The "); |
| 109 result.append(name); | 109 result.append(name); |
| 110 result.appendLiteral(" provided ("); | 110 result.append(" provided ("); |
| 111 result.append(formatNumber(given)); | 111 result.append(formatNumber(given)); |
| 112 result.appendLiteral(") is outside the range "); | 112 result.append(") is outside the range "); |
| 113 result.append(lowerType == ExclusiveBound ? '(' : '['); | 113 result.append(lowerType == ExclusiveBound ? '(' : '['); |
| 114 result.append(formatNumber(lowerBound)); | 114 result.append(formatNumber(lowerBound)); |
| 115 result.appendLiteral(", "); | 115 result.append(", "); |
| 116 result.append(formatNumber(upperBound)); | 116 result.append(formatNumber(upperBound)); |
| 117 result.append(upperType == ExclusiveBound ? ')' : ']'); | 117 result.append(upperType == ExclusiveBound ? ')' : ']'); |
| 118 result.append('.'); | 118 result.append('.'); |
| 119 return result.toString(); | 119 return result.toString(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 static String invalidArity(const char* expected, unsigned provided); | 122 static String invalidArity(const char* expected, unsigned provided); |
| 123 | 123 |
| 124 // If > 0, the argument index that failed type check (1-indexed.) | 124 // If > 0, the argument index that failed type check (1-indexed.) |
| 125 // If == 0, a (non-argument) value (e.g., a setter) failed the same check. | 125 // If == 0, a (non-argument) value (e.g., a setter) failed the same check. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 static String ordinalNumber(int number); | 156 static String ordinalNumber(int number); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 template <> String ExceptionMessages::formatNumber<float>(float number); | 159 template <> String ExceptionMessages::formatNumber<float>(float number); |
| 160 template <> String ExceptionMessages::formatNumber<double>(double number); | 160 template <> String ExceptionMessages::formatNumber<double>(double number); |
| 161 | 161 |
| 162 } // namespace blink | 162 } // namespace blink |
| 163 | 163 |
| 164 #endif // SKY_ENGINE_BINDINGS_CORE_V8_EXCEPTIONMESSAGES_H_ | 164 #endif // ExceptionMessages_h |
| OLD | NEW |