• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 #ifndef FXJS_CJS_UTIL_H_
8 #define FXJS_CJS_UTIL_H_
9 
10 #include <vector>
11 
12 #include "core/fxcrt/widestring.h"
13 #include "fxjs/cjs_object.h"
14 #include "fxjs/js_define.h"
15 
16 // Return values for ParseDataType() below.
17 #define UTIL_INT 0
18 #define UTIL_DOUBLE 1
19 #define UTIL_STRING 2
20 
21 class CJS_Util final : public CJS_Object {
22  public:
23   static int GetObjDefnID();
24   static void DefineJSObjects(CFXJS_Engine* pEngine);
25 
26   CJS_Util(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
27   ~CJS_Util() override;
28 
29   // Ensure that |sFormat| contains at most one well-understood printf
30   // formatting directive which is safe to use with a single argument, and
31   // return the type of argument expected, or -1 otherwise. If -1 is returned,
32   // it is NOT safe to use |sFormat| with printf() and it must be copied
33   // byte-by-byte.
34   //
35   // Exposed for testing.
36   static int ParseDataType(WideString* sFormat);
37 
38   // Exposed for testing.
39   static WideString StringPrintx(const WideString& cFormat,
40                                  const WideString& cSource);
41 
42   JS_STATIC_METHOD(printd, CJS_Util)
43   JS_STATIC_METHOD(printf, CJS_Util)
44   JS_STATIC_METHOD(printx, CJS_Util)
45   JS_STATIC_METHOD(scand, CJS_Util)
46   JS_STATIC_METHOD(byteToChar, CJS_Util)
47 
48  private:
49   static int ObjDefnID;
50   static const char kName[];
51   static const JSMethodSpec MethodSpecs[];
52 
53   CJS_Result printd(CJS_Runtime* pRuntime,
54                     const std::vector<v8::Local<v8::Value>>& params);
55   CJS_Result printf(CJS_Runtime* pRuntime,
56                     const std::vector<v8::Local<v8::Value>>& params);
57   CJS_Result printx(CJS_Runtime* pRuntime,
58                     const std::vector<v8::Local<v8::Value>>& params);
59   CJS_Result scand(CJS_Runtime* pRuntime,
60                    const std::vector<v8::Local<v8::Value>>& params);
61   CJS_Result byteToChar(CJS_Runtime* pRuntime,
62                         const std::vector<v8::Local<v8::Value>>& params);
63 };
64 
65 #endif  // FXJS_CJS_UTIL_H_
66