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 String& type, const String& detail)
41 return "Failed to construct '" + type + (!detail.isEmpty() ? String("': " + detail) : String("'"));
44 String ExceptionMessages::failedToExecute(const String& method, const String& type, const String& detail)
46 return "Failed to execute '" + method + "' on '" + type + (!detail.isEmpty() ? String("': " + detail) : String("'"));
49 String ExceptionMessages::failedToGet(const String& property, const String& type, const String& detail)
51 return "Failed to read the '" + property + "' property from '" + type + "': " + detail;
54 String ExceptionMessages::failedToSet(const String& property, const String& type, const String& detail)
56 return "Failed to set the '" + property + "' property on '" + type + "': " + detail;
59 String ExceptionMessages::failedToDelete(const String& property, const String& type, const String& detail)
61 return "Failed to delete the '" + property + "' property from '" + type + "': " + detail;
64 String ExceptionMessages::incorrectPropertyType(const String& property, const String& detail)
66 return "The '" + property + "' property " + detail;
69 String ExceptionMessages::incorrectArgumentType(int argumentIndex, const String& detail)
71 return "The " + ordinalNumber(argumentIndex) + " argument " + detail;
74 String ExceptionMessages::notAnArrayTypeArgumentOrValue(int argumentIndex)
77 if (argumentIndex) // method argument
78 kind = ordinalNumber(argumentIndex) + " argument";
79 else // value, e.g. attribute setter
80 kind = "value provided";
81 return "The " + kind + " is neither an array, nor does it have indexed properties.";
84 String ExceptionMessages::notASequenceTypeProperty(const String& propertyName)
86 return "'" + propertyName + "' property is neither an array, nor does it have indexed properties.";
89 String ExceptionMessages::notEnoughArguments(unsigned expected, unsigned provided)
91 return String::number(expected) + " argument" + (expected > 1 ? "s" : "") + " required, but only " + String::number(provided) + " present.";
94 String ExceptionMessages::notAFiniteNumber(double value, const char* name)
96 ASSERT(!std::isfinite(value));
97 return String::format("The %s is %s.", name, std::isinf(value) ? "infinite" : "not a number");
100 String ExceptionMessages::notAFiniteNumber(const Decimal& value, const char* name)
102 ASSERT(!value.isFinite());
103 return String::format("The %s is %s.", name, value.isInfinity() ? "infinite" : "not a number");
106 String ExceptionMessages::ordinalNumber(int number)
109 switch (number % 10) {
111 if (number % 100 != 11)
115 if (number % 100 != 12)
119 if (number % 100 != 13)
123 return String::number(number) + suffix;
126 String ExceptionMessages::readOnly(const char* detail)
128 DEFINE_STATIC_LOCAL(String, readOnly, ("This object is read-only."));
129 return detail ? String::format("This object is read-only, because %s.", detail) : readOnly;
132 String ExceptionMessages::indexExceedsMaximumBound(const char* name, unsigned given, unsigned bound)
134 bool eq = given == bound;
135 return String::format("The %s provided (%u) is greater than %sthe maximum bound (%u).", name, given, eq ? "or equal to " : "", bound);
138 } // namespace WebCore