• 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 <string>
11 #include <vector>
12 
13 #include "fxjs/JS_Define.h"
14 
15 // Return values for ParseDataType() below.
16 #define UTIL_INT 0
17 #define UTIL_DOUBLE 1
18 #define UTIL_STRING 2
19 
20 class util : public CJS_EmbedObj {
21  public:
22   explicit util(CJS_Object* pJSObject);
23   ~util() override;
24 
25   CJS_Return printd(CJS_Runtime* pRuntime,
26                     const std::vector<v8::Local<v8::Value>>& params);
27   CJS_Return printf(CJS_Runtime* pRuntime,
28                     const std::vector<v8::Local<v8::Value>>& params);
29   CJS_Return printx(CJS_Runtime* pRuntime,
30                     const std::vector<v8::Local<v8::Value>>& params);
31   CJS_Return scand(CJS_Runtime* pRuntime,
32                    const std::vector<v8::Local<v8::Value>>& params);
33   CJS_Return byteToChar(CJS_Runtime* pRuntime,
34                         const std::vector<v8::Local<v8::Value>>& params);
35 
36   static WideString printx(const WideString& cFormat,
37                            const WideString& cSource);
38 
39  private:
40   friend class CJS_Util_ParseDataType_Test;
41 
42   static int ParseDataType(std::wstring* sFormat);
43 };
44 
45 class CJS_Util : public CJS_Object {
46  public:
47   static void DefineJSObjects(CFXJS_Engine* pEngine);
48 
CJS_Util(v8::Local<v8::Object> pObject)49   explicit CJS_Util(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
~CJS_Util()50   ~CJS_Util() override {}
51 
52   JS_STATIC_METHOD(printd, util);
53   JS_STATIC_METHOD(printf, util);
54   JS_STATIC_METHOD(printx, util);
55   JS_STATIC_METHOD(scand, util);
56   JS_STATIC_METHOD(byteToChar, util);
57 
58  private:
59   static int ObjDefnID;
60   static const JSMethodSpec MethodSpecs[];
61 };
62 
63 #endif  // FXJS_CJS_UTIL_H_
64