OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef FXJS_CFXJSE_VALUE_H_ | 7 #ifndef FXJS_CFXJSE_VALUE_H_ |
8 #define FXJS_CFXJSE_VALUE_H_ | 8 #define FXJS_CFXJSE_VALUE_H_ |
9 | 9 |
10 #include "core/fxcrt/fx_string.h" | 10 #include "core/fxcrt/fx_string.h" |
11 #include "core/fxcrt/fx_system.h" | 11 #include "core/fxcrt/fx_system.h" |
12 #include "fxjs/cfxjse_isolatetracker.h" | 12 #include "fxjs/cfxjse_isolatetracker.h" |
13 #include "fxjs/cfxjse_runtimedata.h" | 13 #include "fxjs/cfxjse_runtimedata.h" |
14 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
15 | 15 |
16 class CFXJSE_Class; | 16 class CFXJSE_Class; |
17 class CFXJSE_HostObject; | 17 class CFXJSE_HostObject; |
18 | 18 |
19 class CFXJSE_Value { | 19 class CFXJSE_Value { |
20 public: | 20 public: |
21 explicit CFXJSE_Value(v8::Isolate* pIsolate); | 21 explicit CFXJSE_Value(v8::Isolate* pIsolate); |
22 ~CFXJSE_Value(); | 22 ~CFXJSE_Value(); |
23 | 23 |
24 FX_BOOL IsUndefined() const; | 24 bool IsUndefined() const; |
25 FX_BOOL IsNull() const; | 25 bool IsNull() const; |
26 FX_BOOL IsBoolean() const; | 26 bool IsBoolean() const; |
27 FX_BOOL IsString() const; | 27 bool IsString() const; |
28 FX_BOOL IsNumber() const; | 28 bool IsNumber() const; |
29 FX_BOOL IsInteger() const; | 29 bool IsInteger() const; |
30 FX_BOOL IsObject() const; | 30 bool IsObject() const; |
31 FX_BOOL IsArray() const; | 31 bool IsArray() const; |
32 FX_BOOL IsFunction() const; | 32 bool IsFunction() const; |
33 FX_BOOL IsDate() const; | 33 bool IsDate() const; |
34 FX_BOOL ToBoolean() const; | 34 bool ToBoolean() const; |
35 FX_FLOAT ToFloat() const; | 35 FX_FLOAT ToFloat() const; |
36 double ToDouble() const; | 36 double ToDouble() const; |
37 int32_t ToInteger() const; | 37 int32_t ToInteger() const; |
38 CFX_ByteString ToString() const; | 38 CFX_ByteString ToString() const; |
39 CFX_WideString ToWideString() const { | 39 CFX_WideString ToWideString() const { |
40 return CFX_WideString::FromUTF8(ToString().AsStringC()); | 40 return CFX_WideString::FromUTF8(ToString().AsStringC()); |
41 } | 41 } |
42 CFXJSE_HostObject* ToHostObject(CFXJSE_Class* lpClass) const; | 42 CFXJSE_HostObject* ToHostObject(CFXJSE_Class* lpClass) const; |
43 | 43 |
44 void SetUndefined(); | 44 void SetUndefined(); |
45 void SetNull(); | 45 void SetNull(); |
46 void SetBoolean(FX_BOOL bBoolean); | 46 void SetBoolean(bool bBoolean); |
47 void SetInteger(int32_t nInteger); | 47 void SetInteger(int32_t nInteger); |
48 void SetDouble(double dDouble); | 48 void SetDouble(double dDouble); |
49 void SetString(const CFX_ByteStringC& szString); | 49 void SetString(const CFX_ByteStringC& szString); |
50 void SetFloat(FX_FLOAT fFloat); | 50 void SetFloat(FX_FLOAT fFloat); |
51 void SetJSObject(); | 51 void SetJSObject(); |
52 | 52 |
53 void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass); | 53 void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass); |
54 void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* lpClass); | 54 void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* lpClass); |
55 void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues); | 55 void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues); |
56 void SetDate(double dDouble); | 56 void SetDate(double dDouble); |
57 | 57 |
58 FX_BOOL GetObjectProperty(const CFX_ByteStringC& szPropName, | 58 bool GetObjectProperty(const CFX_ByteStringC& szPropName, |
| 59 CFXJSE_Value* lpPropValue); |
| 60 bool SetObjectProperty(const CFX_ByteStringC& szPropName, |
| 61 CFXJSE_Value* lpPropValue); |
| 62 bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); |
| 63 bool SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); |
| 64 bool DeleteObjectProperty(const CFX_ByteStringC& szPropName); |
| 65 bool HasObjectOwnProperty(const CFX_ByteStringC& szPropName, |
| 66 bool bUseTypeGetter); |
| 67 bool SetObjectOwnProperty(const CFX_ByteStringC& szPropName, |
59 CFXJSE_Value* lpPropValue); | 68 CFXJSE_Value* lpPropValue); |
60 FX_BOOL SetObjectProperty(const CFX_ByteStringC& szPropName, | 69 bool SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis); |
61 CFXJSE_Value* lpPropValue); | 70 bool Call(CFXJSE_Value* lpReceiver, |
62 FX_BOOL GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); | 71 CFXJSE_Value* lpRetValue, |
63 FX_BOOL SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); | 72 uint32_t nArgCount, |
64 FX_BOOL DeleteObjectProperty(const CFX_ByteStringC& szPropName); | 73 CFXJSE_Value** lpArgs); |
65 FX_BOOL HasObjectOwnProperty(const CFX_ByteStringC& szPropName, | |
66 FX_BOOL bUseTypeGetter); | |
67 FX_BOOL SetObjectOwnProperty(const CFX_ByteStringC& szPropName, | |
68 CFXJSE_Value* lpPropValue); | |
69 FX_BOOL SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis); | |
70 FX_BOOL Call(CFXJSE_Value* lpReceiver, | |
71 CFXJSE_Value* lpRetValue, | |
72 uint32_t nArgCount, | |
73 CFXJSE_Value** lpArgs); | |
74 | 74 |
75 v8::Isolate* GetIsolate() const { return m_pIsolate; } | 75 v8::Isolate* GetIsolate() const { return m_pIsolate; } |
76 const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; } | 76 const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; } |
77 void ForceSetValue(v8::Local<v8::Value> hValue) { | 77 void ForceSetValue(v8::Local<v8::Value> hValue) { |
78 m_hValue.Reset(m_pIsolate, hValue); | 78 m_hValue.Reset(m_pIsolate, hValue); |
79 } | 79 } |
80 void Assign(const CFXJSE_Value* lpValue) { | 80 void Assign(const CFXJSE_Value* lpValue) { |
81 ASSERT(lpValue); | 81 ASSERT(lpValue); |
82 if (lpValue) { | 82 if (lpValue) { |
83 m_hValue.Reset(m_pIsolate, lpValue->m_hValue); | 83 m_hValue.Reset(m_pIsolate, lpValue->m_hValue); |
84 } else { | 84 } else { |
85 m_hValue.Reset(); | 85 m_hValue.Reset(); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 friend class CFXJSE_Class; | 90 friend class CFXJSE_Class; |
91 friend class CFXJSE_Context; | 91 friend class CFXJSE_Context; |
92 | 92 |
93 CFXJSE_Value(); | 93 CFXJSE_Value(); |
94 CFXJSE_Value(const CFXJSE_Value&); | 94 CFXJSE_Value(const CFXJSE_Value&); |
95 CFXJSE_Value& operator=(const CFXJSE_Value&); | 95 CFXJSE_Value& operator=(const CFXJSE_Value&); |
96 | 96 |
97 v8::Isolate* m_pIsolate; | 97 v8::Isolate* m_pIsolate; |
98 v8::Global<v8::Value> m_hValue; | 98 v8::Global<v8::Value> m_hValue; |
99 }; | 99 }; |
100 | 100 |
101 #endif // FXJS_CFXJSE_VALUE_H_ | 101 #endif // FXJS_CFXJSE_VALUE_H_ |
OLD | NEW |