• 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   float ToFloat() const;
39   double ToDouble() const;
40   int32_t ToInteger() const;
41   ByteString ToString() const;
ToWideString()42   WideString ToWideString() const {
43     return WideString::FromUTF8(ToString().AsStringView());
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 ByteStringView& szString);
53   void SetFloat(float fFloat);
54 
55   void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass);
56   void SetArray(const std::vector<std::unique_ptr<CFXJSE_Value>>& values);
57   void SetDate(double dDouble);
58 
59   bool GetObjectProperty(const ByteStringView& szPropName,
60                          CFXJSE_Value* lpPropValue);
61   bool SetObjectProperty(const ByteStringView& szPropName,
62                          CFXJSE_Value* lpPropValue);
63   bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
64   bool SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
65   bool DeleteObjectProperty(const ByteStringView& szPropName);
66   bool HasObjectOwnProperty(const ByteStringView& szPropName,
67                             bool bUseTypeGetter);
68   bool SetObjectOwnProperty(const ByteStringView& szPropName,
69                             CFXJSE_Value* lpPropValue);
70   bool SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
71 
GetIsolate()72   v8::Isolate* GetIsolate() const { return m_pIsolate; }
DirectGetValue()73   const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; }
ForceSetValue(v8::Local<v8::Value> hValue)74   void ForceSetValue(v8::Local<v8::Value> hValue) {
75     m_hValue.Reset(m_pIsolate, hValue);
76   }
Assign(const CFXJSE_Value * lpValue)77   void Assign(const CFXJSE_Value* lpValue) {
78     ASSERT(lpValue);
79     if (lpValue) {
80       m_hValue.Reset(m_pIsolate, lpValue->m_hValue);
81     } else {
82       m_hValue.Reset();
83     }
84   }
85 
86  private:
87   friend class CFXJSE_Class;
88   friend class CFXJSE_Context;
89 
90   CFXJSE_Value();
91   CFXJSE_Value(const CFXJSE_Value&);
92   CFXJSE_Value& operator=(const CFXJSE_Value&);
93 
94   v8::Isolate* m_pIsolate;
95   v8::Global<v8::Value> m_hValue;
96 };
97 
98 #endif  // FXJS_CFXJSE_VALUE_H_
99