xref: /aosp_15_r20/external/pdfium/fxjs/xfa/cfxjse_value.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2014 The PDFium Authors
2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file.
4*3ac0a46fSAndroid Build Coastguard Worker 
5*3ac0a46fSAndroid Build Coastguard Worker // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6*3ac0a46fSAndroid Build Coastguard Worker 
7*3ac0a46fSAndroid Build Coastguard Worker #ifndef FXJS_XFA_CFXJSE_VALUE_H_
8*3ac0a46fSAndroid Build Coastguard Worker #define FXJS_XFA_CFXJSE_VALUE_H_
9*3ac0a46fSAndroid Build Coastguard Worker 
10*3ac0a46fSAndroid Build Coastguard Worker #include <stdint.h>
11*3ac0a46fSAndroid Build Coastguard Worker 
12*3ac0a46fSAndroid Build Coastguard Worker #include <memory>
13*3ac0a46fSAndroid Build Coastguard Worker #include <vector>
14*3ac0a46fSAndroid Build Coastguard Worker 
15*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/fx_string.h"
16*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/unowned_ptr.h"
17*3ac0a46fSAndroid Build Coastguard Worker #include "third_party/base/check.h"
18*3ac0a46fSAndroid Build Coastguard Worker #include "v8/include/v8-forward.h"
19*3ac0a46fSAndroid Build Coastguard Worker #include "v8/include/v8-persistent-handle.h"
20*3ac0a46fSAndroid Build Coastguard Worker 
21*3ac0a46fSAndroid Build Coastguard Worker class CFXJSE_Class;
22*3ac0a46fSAndroid Build Coastguard Worker class CFXJSE_HostObject;
23*3ac0a46fSAndroid Build Coastguard Worker 
24*3ac0a46fSAndroid Build Coastguard Worker class CFXJSE_Value {
25*3ac0a46fSAndroid Build Coastguard Worker  public:
26*3ac0a46fSAndroid Build Coastguard Worker   CFXJSE_Value();
27*3ac0a46fSAndroid Build Coastguard Worker   CFXJSE_Value(v8::Isolate* pIsolate, v8::Local<v8::Value> value);
28*3ac0a46fSAndroid Build Coastguard Worker   ~CFXJSE_Value();
29*3ac0a46fSAndroid Build Coastguard Worker 
30*3ac0a46fSAndroid Build Coastguard Worker   bool IsEmpty() const;
31*3ac0a46fSAndroid Build Coastguard Worker   bool IsUndefined(v8::Isolate* pIsolate) const;
32*3ac0a46fSAndroid Build Coastguard Worker   bool IsNull(v8::Isolate* pIsolate) const;
33*3ac0a46fSAndroid Build Coastguard Worker   bool IsBoolean(v8::Isolate* pIsolate) const;
34*3ac0a46fSAndroid Build Coastguard Worker   bool IsString(v8::Isolate* pIsolate) const;
35*3ac0a46fSAndroid Build Coastguard Worker   bool IsNumber(v8::Isolate* pIsolate) const;
36*3ac0a46fSAndroid Build Coastguard Worker   bool IsInteger(v8::Isolate* pIsolate) const;
37*3ac0a46fSAndroid Build Coastguard Worker   bool IsObject(v8::Isolate* pIsolate) const;
38*3ac0a46fSAndroid Build Coastguard Worker   bool IsArray(v8::Isolate* pIsolate) const;
39*3ac0a46fSAndroid Build Coastguard Worker   bool IsFunction(v8::Isolate* pIsolate) const;
40*3ac0a46fSAndroid Build Coastguard Worker   bool ToBoolean(v8::Isolate* pIsolate) const;
41*3ac0a46fSAndroid Build Coastguard Worker   float ToFloat(v8::Isolate* pIsolate) const;
42*3ac0a46fSAndroid Build Coastguard Worker   double ToDouble(v8::Isolate* pIsolate) const;
43*3ac0a46fSAndroid Build Coastguard Worker   int32_t ToInteger(v8::Isolate* pIsolate) const;
44*3ac0a46fSAndroid Build Coastguard Worker   ByteString ToString(v8::Isolate* pIsolate) const;
ToWideString(v8::Isolate * pIsolate)45*3ac0a46fSAndroid Build Coastguard Worker   WideString ToWideString(v8::Isolate* pIsolate) const {
46*3ac0a46fSAndroid Build Coastguard Worker     return WideString::FromUTF8(ToString(pIsolate).AsStringView());
47*3ac0a46fSAndroid Build Coastguard Worker   }
48*3ac0a46fSAndroid Build Coastguard Worker   CFXJSE_HostObject* ToHostObject(v8::Isolate* pIsolate) const;
49*3ac0a46fSAndroid Build Coastguard Worker 
50*3ac0a46fSAndroid Build Coastguard Worker   void SetUndefined(v8::Isolate* pIsolate);
51*3ac0a46fSAndroid Build Coastguard Worker   void SetNull(v8::Isolate* pIsolate);
52*3ac0a46fSAndroid Build Coastguard Worker   void SetBoolean(v8::Isolate* pIsolate, bool bBoolean);
53*3ac0a46fSAndroid Build Coastguard Worker   void SetInteger(v8::Isolate* pIsolate, int32_t nInteger);
54*3ac0a46fSAndroid Build Coastguard Worker   void SetDouble(v8::Isolate* pIsolate, double dDouble);
55*3ac0a46fSAndroid Build Coastguard Worker   void SetString(v8::Isolate* pIsolate, ByteStringView szString);
56*3ac0a46fSAndroid Build Coastguard Worker   void SetFloat(v8::Isolate* pIsolate, float fFloat);
57*3ac0a46fSAndroid Build Coastguard Worker 
58*3ac0a46fSAndroid Build Coastguard Worker   void SetHostObject(v8::Isolate* pIsolate,
59*3ac0a46fSAndroid Build Coastguard Worker                      CFXJSE_HostObject* pObject,
60*3ac0a46fSAndroid Build Coastguard Worker                      CFXJSE_Class* pClass);
61*3ac0a46fSAndroid Build Coastguard Worker 
62*3ac0a46fSAndroid Build Coastguard Worker   void SetArray(v8::Isolate* pIsolate,
63*3ac0a46fSAndroid Build Coastguard Worker                 const std::vector<std::unique_ptr<CFXJSE_Value>>& values);
64*3ac0a46fSAndroid Build Coastguard Worker 
65*3ac0a46fSAndroid Build Coastguard Worker   bool GetObjectProperty(v8::Isolate* pIsolate,
66*3ac0a46fSAndroid Build Coastguard Worker                          ByteStringView szPropName,
67*3ac0a46fSAndroid Build Coastguard Worker                          CFXJSE_Value* pPropValue);
68*3ac0a46fSAndroid Build Coastguard Worker   bool SetObjectProperty(v8::Isolate* pIsolate,
69*3ac0a46fSAndroid Build Coastguard Worker                          ByteStringView szPropName,
70*3ac0a46fSAndroid Build Coastguard Worker                          CFXJSE_Value* pPropValue);
71*3ac0a46fSAndroid Build Coastguard Worker   bool GetObjectPropertyByIdx(v8::Isolate* pIsolate,
72*3ac0a46fSAndroid Build Coastguard Worker                               uint32_t uPropIdx,
73*3ac0a46fSAndroid Build Coastguard Worker                               CFXJSE_Value* pPropValue);
74*3ac0a46fSAndroid Build Coastguard Worker   void DeleteObjectProperty(v8::Isolate* pIsolate, ByteStringView szPropName);
75*3ac0a46fSAndroid Build Coastguard Worker   bool SetObjectOwnProperty(v8::Isolate* pIsolate,
76*3ac0a46fSAndroid Build Coastguard Worker                             ByteStringView szPropName,
77*3ac0a46fSAndroid Build Coastguard Worker                             CFXJSE_Value* pPropValue);
78*3ac0a46fSAndroid Build Coastguard Worker 
79*3ac0a46fSAndroid Build Coastguard Worker   // Return empty local on error.
80*3ac0a46fSAndroid Build Coastguard Worker   static v8::Local<v8::Function> NewBoundFunction(
81*3ac0a46fSAndroid Build Coastguard Worker       v8::Isolate* pIsolate,
82*3ac0a46fSAndroid Build Coastguard Worker       v8::Local<v8::Function> hOldFunction,
83*3ac0a46fSAndroid Build Coastguard Worker       v8::Local<v8::Object> lpNewThis);
84*3ac0a46fSAndroid Build Coastguard Worker 
85*3ac0a46fSAndroid Build Coastguard Worker   v8::Local<v8::Value> GetValue(v8::Isolate* pIsolate) const;
DirectGetValue()86*3ac0a46fSAndroid Build Coastguard Worker   const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; }
ForceSetValue(v8::Isolate * pIsolate,v8::Local<v8::Value> hValue)87*3ac0a46fSAndroid Build Coastguard Worker   void ForceSetValue(v8::Isolate* pIsolate, v8::Local<v8::Value> hValue) {
88*3ac0a46fSAndroid Build Coastguard Worker     m_hValue.Reset(pIsolate, hValue);
89*3ac0a46fSAndroid Build Coastguard Worker   }
90*3ac0a46fSAndroid Build Coastguard Worker 
91*3ac0a46fSAndroid Build Coastguard Worker  private:
92*3ac0a46fSAndroid Build Coastguard Worker   CFXJSE_Value(const CFXJSE_Value&) = delete;
93*3ac0a46fSAndroid Build Coastguard Worker   CFXJSE_Value& operator=(const CFXJSE_Value&) = delete;
94*3ac0a46fSAndroid Build Coastguard Worker 
95*3ac0a46fSAndroid Build Coastguard Worker   v8::Global<v8::Value> m_hValue;
96*3ac0a46fSAndroid Build Coastguard Worker };
97*3ac0a46fSAndroid Build Coastguard Worker 
98*3ac0a46fSAndroid Build Coastguard Worker #endif  // FXJS_XFA_CFXJSE_VALUE_H_
99