• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fxjs/js_resources.h"
8 
9 #include "third_party/base/notreached.h"
10 
JSGetStringFromID(JSMessage msg)11 WideString JSGetStringFromID(JSMessage msg) {
12   const char* msg_string = "";
13   switch (msg) {
14     case JSMessage::kAlert:
15       msg_string = "Alert";
16       break;
17     case JSMessage::kParamError:
18       msg_string = "Incorrect number of parameters passed to function.";
19       break;
20     case JSMessage::kInvalidInputError:
21       msg_string = "The input value is invalid.";
22       break;
23     case JSMessage::kParamTooLongError:
24       msg_string = "The input value is too long.";
25       break;
26     case JSMessage::kParseDateError:
27       msg_string =
28           "The input value can't be parsed as a valid date/time (%ls).";
29       break;
30     case JSMessage::kRangeBetweenError:
31       msg_string =
32           "The input value must be greater than or equal to %ls"
33           " and less than or equal to %ls.";
34       break;
35     case JSMessage::kRangeGreaterError:
36       msg_string = "The input value must be greater than or equal to %ls.";
37       break;
38     case JSMessage::kRangeLessError:
39       msg_string = "The input value must be less than or equal to %ls.";
40       break;
41     case JSMessage::kNotSupportedError:
42       msg_string = "Operation not supported.";
43       break;
44     case JSMessage::kBusyError:
45       msg_string = "System is busy.";
46       break;
47     case JSMessage::kDuplicateEventError:
48       msg_string = "Duplicate formfield event found.";
49       break;
50     case JSMessage::kSecondParamNotDateError:
51       msg_string = "The second parameter can't be converted to a Date.";
52       break;
53     case JSMessage::kSecondParamInvalidDateError:
54       msg_string = "The second parameter is an invalid Date.";
55       break;
56     case JSMessage::kGlobalNotFoundError:
57       msg_string = "Global value not found.";
58       break;
59     case JSMessage::kReadOnlyError:
60       msg_string = "Cannot assign to readonly property.";
61       break;
62     case JSMessage::kTypeError:
63       msg_string = "Incorrect parameter type.";
64       break;
65     case JSMessage::kValueError:
66       msg_string = "Incorrect parameter value.";
67       break;
68     case JSMessage::kPermissionError:
69       msg_string = "Permission denied.";
70       break;
71     case JSMessage::kBadObjectError:
72       msg_string = "Object no longer exists.";
73       break;
74     case JSMessage::kObjectTypeError:
75       msg_string = "Object is of the wrong type.";
76       break;
77     case JSMessage::kUnknownProperty:
78       msg_string = "Unknown property.";
79       break;
80     case JSMessage::kInvalidSetError:
81       msg_string = "Set not possible, invalid or unknown.";
82       break;
83     case JSMessage::kUserGestureRequiredError:
84       msg_string = "User gesture required.";
85       break;
86     case JSMessage::kTooManyOccurrences:
87       msg_string = "Too many occurrences.";
88       break;
89     case JSMessage::kUnknownMethod:
90       msg_string = "Unknown method.";
91       break;
92     case JSMessage::kWouldBeCyclic:
93       msg_string = "Operation would create a cycle.";
94       break;
95     default:
96       NOTREACHED();
97       break;
98   }
99   return WideString::FromASCII(msg_string);
100 }
101 
JSFormatErrorString(const char * class_name,const char * property_name,const WideString & details)102 WideString JSFormatErrorString(const char* class_name,
103                                const char* property_name,
104                                const WideString& details) {
105   WideString result = WideString::FromUTF8(class_name);
106   if (property_name) {
107     result += L".";
108     result += WideString::FromUTF8(property_name);
109   }
110   result += L": ";
111   result += details;
112   return result;
113 }
114