• 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_XFA_CFXJSE_VALUE_H_
8 #define FXJS_XFA_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 "core/fxcrt/unowned_ptr.h"
16 #include "v8/include/v8.h"
17 
18 class CFXJSE_Class;
19 class CFXJSE_HostObject;
20 
21 class CFXJSE_Value {
22  public:
23   explicit CFXJSE_Value(v8::Isolate* pIsolate);
24   ~CFXJSE_Value();
25 
26   bool IsEmpty() const;
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 ToBoolean() const;
37   float ToFloat() const;
38   double ToDouble() const;
39   int32_t ToInteger() const;
40   ByteString ToString() const;
ToWideString()41   WideString ToWideString() const {
42     return WideString::FromUTF8(ToString().AsStringView());
43   }
44   CFXJSE_HostObject* ToHostObject() const;
45 
46   void SetUndefined();
47   void SetNull();
48   void SetBoolean(bool bBoolean);
49   void SetInteger(int32_t nInteger);
50   void SetDouble(double dDouble);
51   void SetString(ByteStringView szString);
52   void SetFloat(float fFloat);
53 
54   void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass);
55   void ClearHostObject();
56 
57   void SetArray(const std::vector<std::unique_ptr<CFXJSE_Value>>& values);
58 
59   bool GetObjectProperty(ByteStringView szPropName, CFXJSE_Value* lpPropValue);
60   bool SetObjectProperty(ByteStringView szPropName, CFXJSE_Value* lpPropValue);
61   bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
62   bool DeleteObjectProperty(ByteStringView szPropName);
63   bool HasObjectOwnProperty(ByteStringView szPropName, bool bUseTypeGetter);
64   bool SetObjectOwnProperty(ByteStringView szPropName,
65                             CFXJSE_Value* lpPropValue);
66   bool SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
67 
GetIsolate()68   v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); }
DirectGetValue()69   const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; }
ForceSetValue(v8::Local<v8::Value> hValue)70   void ForceSetValue(v8::Local<v8::Value> hValue) {
71     m_hValue.Reset(GetIsolate(), hValue);
72   }
Assign(const CFXJSE_Value * lpValue)73   void Assign(const CFXJSE_Value* lpValue) {
74     ASSERT(lpValue);
75     if (lpValue) {
76       m_hValue.Reset(GetIsolate(), lpValue->m_hValue);
77     } else {
78       m_hValue.Reset();
79     }
80   }
81 
82  private:
83   CFXJSE_Value() = delete;
84   CFXJSE_Value(const CFXJSE_Value&) = delete;
85   CFXJSE_Value& operator=(const CFXJSE_Value&) = delete;
86 
87   UnownedPtr<v8::Isolate> const m_pIsolate;
88   v8::Global<v8::Value> m_hValue;
89 };
90 
91 #endif  // FXJS_XFA_CFXJSE_VALUE_H_
92