• 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_CFXJSE_VALUE_H_
8 #define FXJS_CFXJSE_VALUE_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_string.h"
14 #include "core/fxcrt/fx_system.h"
15 #include "fxjs/cfxjse_isolatetracker.h"
16 #include "fxjs/cfxjse_runtimedata.h"
17 #include "v8/include/v8.h"
18 
19 class CFXJSE_Class;
20 class CFXJSE_HostObject;
21 
22 class CFXJSE_Value {
23  public:
24   explicit CFXJSE_Value(v8::Isolate* pIsolate);
25   ~CFXJSE_Value();
26 
27   bool IsUndefined() const;
28   bool IsNull() const;
29   bool IsBoolean() const;
30   bool IsString() const;
31   bool IsNumber() const;
32   bool IsInteger() const;
33   bool IsObject() const;
34   bool IsArray() const;
35   bool IsFunction() const;
36   bool IsDate() const;
37   bool ToBoolean() const;
38   FX_FLOAT ToFloat() const;
39   double ToDouble() const;
40   int32_t ToInteger() const;
41   CFX_ByteString ToString() const;
ToWideString()42   CFX_WideString ToWideString() const {
43     return CFX_WideString::FromUTF8(ToString().AsStringC());
44   }
45   CFXJSE_HostObject* ToHostObject(CFXJSE_Class* lpClass) const;
46 
47   void SetUndefined();
48   void SetNull();
49   void SetBoolean(bool bBoolean);
50   void SetInteger(int32_t nInteger);
51   void SetDouble(double dDouble);
52   void SetString(const CFX_ByteStringC& szString);
53   void SetFloat(FX_FLOAT fFloat);
54   void SetJSObject();
55 
56   void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass);
57   void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* lpClass);
58   void SetArray(const std::vector<std::unique_ptr<CFXJSE_Value>>& values);
59   void SetDate(double dDouble);
60 
61   bool GetObjectProperty(const CFX_ByteStringC& szPropName,
62                          CFXJSE_Value* lpPropValue);
63   bool SetObjectProperty(const CFX_ByteStringC& szPropName,
64                          CFXJSE_Value* lpPropValue);
65   bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
66   bool SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
67   bool DeleteObjectProperty(const CFX_ByteStringC& szPropName);
68   bool HasObjectOwnProperty(const CFX_ByteStringC& szPropName,
69                             bool bUseTypeGetter);
70   bool SetObjectOwnProperty(const CFX_ByteStringC& szPropName,
71                             CFXJSE_Value* lpPropValue);
72   bool SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
73   bool Call(CFXJSE_Value* lpReceiver,
74             CFXJSE_Value* lpRetValue,
75             uint32_t nArgCount,
76             CFXJSE_Value** lpArgs);
77 
GetIsolate()78   v8::Isolate* GetIsolate() const { return m_pIsolate; }
DirectGetValue()79   const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; }
ForceSetValue(v8::Local<v8::Value> hValue)80   void ForceSetValue(v8::Local<v8::Value> hValue) {
81     m_hValue.Reset(m_pIsolate, hValue);
82   }
Assign(const CFXJSE_Value * lpValue)83   void Assign(const CFXJSE_Value* lpValue) {
84     ASSERT(lpValue);
85     if (lpValue) {
86       m_hValue.Reset(m_pIsolate, lpValue->m_hValue);
87     } else {
88       m_hValue.Reset();
89     }
90   }
91 
92  private:
93   friend class CFXJSE_Class;
94   friend class CFXJSE_Context;
95 
96   CFXJSE_Value();
97   CFXJSE_Value(const CFXJSE_Value&);
98   CFXJSE_Value& operator=(const CFXJSE_Value&);
99 
100   v8::Isolate* m_pIsolate;
101   v8::Global<v8::Value> m_hValue;
102 };
103 
104 #endif  // FXJS_CFXJSE_VALUE_H_
105