2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
32 #include "bindings/v8/ExceptionMessages.h"
34 #include "platform/Decimal.h"
35 #include "wtf/MathExtras.h"
39 String ExceptionMessages::failedToConstruct(const char* type, const String& detail)
41 return "Failed to construct '" + String(type) + (!detail.isEmpty() ? String("': " + detail) : String("'"));
44 String ExceptionMessages::failedToEnumerate(const char* type, const String& detail)
46 return "Failed to enumerate the properties of '" + String(type) + (!detail.isEmpty() ? String("': " + detail) : String("'"));
49 String ExceptionMessages::failedToExecute(const char* method, const char* type, const String& detail)
51 return "Failed to execute '" + String(method) + "' on '" + String(type) + (!detail.isEmpty() ? String("': " + detail) : String("'"));
54 String ExceptionMessages::failedToGet(const char* property, const char* type, const String& detail)
56 return "Failed to read the '" + String(property) + "' property from '" + String(type) + "': " + detail;
59 String ExceptionMessages::failedToSet(const char* property, const char* type, const String& detail)
61 return "Failed to set the '" + String(property) + "' property on '" + String(type) + "': " + detail;
64 String ExceptionMessages::failedToDelete(const char* property, const char* type, const String& detail)
66 return "Failed to delete the '" + String(property) + "' property from '" + String(type) + "': " + detail;
69 String ExceptionMessages::failedToGetIndexed(const char* type, const String& detail)
71 return "Failed to read an indexed property from '" + String(type) + "': " + detail;
74 String ExceptionMessages::failedToSetIndexed(const char* type, const String& detail)
76 return "Failed to set an indexed property on '" + String(type) + "': " + detail;
79 String ExceptionMessages::failedToDeleteIndexed(const char* type, const String& detail)
81 return "Failed to delete an indexed property from '" + String(type) + "': " + detail;
84 String ExceptionMessages::constructorNotCallableAsFunction(const char* type)
86 return failedToConstruct(type, "Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
89 String ExceptionMessages::incorrectPropertyType(const String& property, const String& detail)
91 return "The '" + property + "' property " + detail;
94 String ExceptionMessages::invalidArity(const char* expected, unsigned provided)
96 return "Valid arities are: " + String(expected) + ", but " + String::number(provided) + " arguments provided.";
99 String ExceptionMessages::argumentNullOrIncorrectType(int argumentIndex, const String& expectedType)
101 return "The " + ordinalNumber(argumentIndex) + " argument provided is either null, or an invalid " + expectedType + " object.";
104 String ExceptionMessages::notAnArrayTypeArgumentOrValue(int argumentIndex)
107 if (argumentIndex) // method argument
108 kind = ordinalNumber(argumentIndex) + " argument";
109 else // value, e.g. attribute setter
110 kind = "value provided";
111 return "The " + kind + " is neither an array, nor does it have indexed properties.";
114 String ExceptionMessages::notASequenceTypeProperty(const String& propertyName)
116 return "'" + propertyName + "' property is neither an array, nor does it have indexed properties.";
119 String ExceptionMessages::notEnoughArguments(unsigned expected, unsigned provided)
121 return String::number(expected) + " argument" + (expected > 1 ? "s" : "") + " required, but only " + String::number(provided) + " present.";
124 String ExceptionMessages::notAFiniteNumber(double value, const char* name)
126 ASSERT(!std::isfinite(value));
127 return String::format("The %s is %s.", name, std::isinf(value) ? "infinite" : "not a number");
130 String ExceptionMessages::notAFiniteNumber(const Decimal& value, const char* name)
132 ASSERT(!value.isFinite());
133 return String::format("The %s is %s.", name, value.isInfinity() ? "infinite" : "not a number");
136 String ExceptionMessages::ordinalNumber(int number)
139 switch (number % 10) {
141 if (number % 100 != 11)
145 if (number % 100 != 12)
149 if (number % 100 != 13)
153 return String::number(number) + suffix;
156 String ExceptionMessages::readOnly(const char* detail)
158 DEFINE_STATIC_LOCAL(String, readOnly, ("This object is read-only."));
159 return detail ? String::format("This object is read-only, because %s.", detail) : readOnly;
163 String ExceptionMessages::formatNumber<float>(float number)
165 return formatPotentiallyNonFiniteNumber(number);
169 String ExceptionMessages::formatNumber<double>(double number)
171 return formatPotentiallyNonFiniteNumber(number);
174 } // namespace WebCore