1 // Copyright 2017 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fxjs/js_resources.h"
8 
JSGetStringFromID(JSMessage msg)9 WideString JSGetStringFromID(JSMessage msg) {
10   switch (msg) {
11     case JSMessage::kAlert:
12       return L"Alert";
13     case JSMessage::kParamError:
14       return L"Incorrect number of parameters passed to function.";
15     case JSMessage::kInvalidInputError:
16       return L"The input value is invalid.";
17     case JSMessage::kParamTooLongError:
18       return L"The input value is too long.";
19     case JSMessage::kParseDateError:
20       return L"The input value can't be parsed as a valid date/time (%s).";
21     case JSMessage::kRangeBetweenError:
22       return L"The input value must be greater than or equal to %s"
23              L" and less than or equal to %s.";
24     case JSMessage::kRangeGreaterError:
25       return L"The input value must be greater than or equal to %s.";
26     case JSMessage::kRangeLessError:
27       return L"The input value must be less than or equal to %s.";
28     case JSMessage::kNotSupportedError:
29       return L"Operation not supported.";
30     case JSMessage::kBusyError:
31       return L"System is busy.";
32     case JSMessage::kDuplicateEventError:
33       return L"Duplicate formfield event found.";
34     case JSMessage::kRunSuccess:
35       return L"Script ran successfully.";
36     case JSMessage::kSecondParamNotDateError:
37       return L"The second parameter can't be converted to a Date.";
38     case JSMessage::kSecondParamInvalidDateError:
39       return L"The second parameter is an invalid Date!";
40     case JSMessage::kGlobalNotFoundError:
41       return L"Global value not found.";
42     case JSMessage::kReadOnlyError:
43       return L"Cannot assign to readonly property.";
44     case JSMessage::kTypeError:
45       return L"Incorrect parameter type.";
46     case JSMessage::kValueError:
47       return L"Incorrect parameter value.";
48     case JSMessage::kPermissionError:
49       return L"Permission denied.";
50     case JSMessage::kBadObjectError:
51       return L"Object no longer exists.";
52     case JSMessage::kTooManyOccurances:
53       return L"Too many occurances";
54   }
55   NOTREACHED();
56   return L"";
57 }
58 
JSFormatErrorString(const char * class_name,const char * property_name,const WideString & details)59 WideString JSFormatErrorString(const char* class_name,
60                                const char* property_name,
61                                const WideString& details) {
62   WideString result = WideString::FromLocal(class_name);
63   if (property_name) {
64     result += L".";
65     result += WideString::FromLocal(property_name);
66   }
67   result += L": ";
68   result += details;
69   return result;
70 }
71