| OLD | NEW |
| (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 #include "sky/engine/config.h" |
| 6 #include "sky/engine/bindings2/exception_messages.h" |
| 7 |
| 8 #include "sky/engine/platform/Decimal.h" |
| 9 #include "sky/engine/wtf/MathExtras.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 String ExceptionMessages::failedToConstruct(const char* type, |
| 14 const String& detail) { |
| 15 return "Failed to construct '" + String(type) + |
| 16 (!detail.isEmpty() ? String("': " + detail) : String("'")); |
| 17 } |
| 18 |
| 19 String ExceptionMessages::failedToEnumerate(const char* type, |
| 20 const String& detail) { |
| 21 return "Failed to enumerate the properties of '" + String(type) + |
| 22 (!detail.isEmpty() ? String("': " + detail) : String("'")); |
| 23 } |
| 24 |
| 25 String ExceptionMessages::failedToExecute(const char* method, |
| 26 const char* type, |
| 27 const String& detail) { |
| 28 return "Failed to execute '" + String(method) + "' on '" + String(type) + |
| 29 (!detail.isEmpty() ? String("': " + detail) : String("'")); |
| 30 } |
| 31 |
| 32 String ExceptionMessages::failedToGet(const char* property, |
| 33 const char* type, |
| 34 const String& detail) { |
| 35 return "Failed to read the '" + String(property) + "' property from '" + |
| 36 String(type) + "': " + detail; |
| 37 } |
| 38 |
| 39 String ExceptionMessages::failedToSet(const char* property, |
| 40 const char* type, |
| 41 const String& detail) { |
| 42 return "Failed to set the '" + String(property) + "' property on '" + |
| 43 String(type) + "': " + detail; |
| 44 } |
| 45 |
| 46 String ExceptionMessages::failedToDelete(const char* property, |
| 47 const char* type, |
| 48 const String& detail) { |
| 49 return "Failed to delete the '" + String(property) + "' property from '" + |
| 50 String(type) + "': " + detail; |
| 51 } |
| 52 |
| 53 String ExceptionMessages::failedToGetIndexed(const char* type, |
| 54 const String& detail) { |
| 55 return "Failed to read an indexed property from '" + String(type) + "': " + |
| 56 detail; |
| 57 } |
| 58 |
| 59 String ExceptionMessages::failedToSetIndexed(const char* type, |
| 60 const String& detail) { |
| 61 return "Failed to set an indexed property on '" + String(type) + "': " + |
| 62 detail; |
| 63 } |
| 64 |
| 65 String ExceptionMessages::failedToDeleteIndexed(const char* type, |
| 66 const String& detail) { |
| 67 return "Failed to delete an indexed property from '" + String(type) + "': " + |
| 68 detail; |
| 69 } |
| 70 |
| 71 String ExceptionMessages::constructorNotCallableAsFunction(const char* type) { |
| 72 return failedToConstruct(type, |
| 73 "Please use the 'new' operator, this DOM object " |
| 74 "constructor cannot be called as a function."); |
| 75 } |
| 76 |
| 77 String ExceptionMessages::incorrectPropertyType(const String& property, |
| 78 const String& detail) { |
| 79 return "The '" + property + "' property " + detail; |
| 80 } |
| 81 |
| 82 String ExceptionMessages::invalidArity(const char* expected, |
| 83 unsigned provided) { |
| 84 return "Valid arities are: " + String(expected) + ", but " + |
| 85 String::number(provided) + " arguments provided."; |
| 86 } |
| 87 |
| 88 String ExceptionMessages::argumentNullOrIncorrectType( |
| 89 int argumentIndex, |
| 90 const String& expectedType) { |
| 91 return "The " + ordinalNumber(argumentIndex) + |
| 92 " argument provided is either null, or an invalid " + expectedType + |
| 93 " object."; |
| 94 } |
| 95 |
| 96 String ExceptionMessages::notAnArrayTypeArgumentOrValue(int argumentIndex) { |
| 97 String kind; |
| 98 if (argumentIndex) // method argument |
| 99 kind = ordinalNumber(argumentIndex) + " argument"; |
| 100 else // value, e.g. attribute setter |
| 101 kind = "value provided"; |
| 102 return "The " + kind + |
| 103 " is neither an array, nor does it have indexed properties."; |
| 104 } |
| 105 |
| 106 String ExceptionMessages::notASequenceTypeProperty(const String& propertyName) { |
| 107 return "'" + propertyName + |
| 108 "' property is neither an array, nor does it have indexed properties."; |
| 109 } |
| 110 |
| 111 String ExceptionMessages::notEnoughArguments(unsigned expected, |
| 112 unsigned provided) { |
| 113 return String::number(expected) + " argument" + (expected > 1 ? "s" : "") + |
| 114 " required, but only " + String::number(provided) + " present."; |
| 115 } |
| 116 |
| 117 String ExceptionMessages::notAFiniteNumber(double value, const char* name) { |
| 118 ASSERT(!std::isfinite(value)); |
| 119 return String::format("The %s is %s.", name, |
| 120 std::isinf(value) ? "infinite" : "not a number"); |
| 121 } |
| 122 |
| 123 String ExceptionMessages::notAFiniteNumber(const Decimal& value, |
| 124 const char* name) { |
| 125 ASSERT(!value.isFinite()); |
| 126 return String::format("The %s is %s.", name, |
| 127 value.isInfinity() ? "infinite" : "not a number"); |
| 128 } |
| 129 |
| 130 String ExceptionMessages::ordinalNumber(int number) { |
| 131 String suffix("th"); |
| 132 switch (number % 10) { |
| 133 case 1: |
| 134 if (number % 100 != 11) |
| 135 suffix = "st"; |
| 136 break; |
| 137 case 2: |
| 138 if (number % 100 != 12) |
| 139 suffix = "nd"; |
| 140 break; |
| 141 case 3: |
| 142 if (number % 100 != 13) |
| 143 suffix = "rd"; |
| 144 break; |
| 145 } |
| 146 return String::number(number) + suffix; |
| 147 } |
| 148 |
| 149 String ExceptionMessages::readOnly(const char* detail) { |
| 150 DEFINE_STATIC_LOCAL(String, readOnly, ("This object is read-only.")); |
| 151 return detail |
| 152 ? String::format("This object is read-only, because %s.", detail) |
| 153 : readOnly; |
| 154 } |
| 155 |
| 156 template <> |
| 157 String ExceptionMessages::formatNumber<float>(float number) { |
| 158 return formatPotentiallyNonFiniteNumber(number); |
| 159 } |
| 160 |
| 161 template <> |
| 162 String ExceptionMessages::formatNumber<double>(double number) { |
| 163 return formatPotentiallyNonFiniteNumber(number); |
| 164 } |
| 165 |
| 166 } // namespace blink |
| OLD | NEW |