dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 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 | |
Tom Sepez | 70e5214 | 2018-12-13 20:07:50 +0000 | [diff] [blame] | 7 | #ifndef FXJS_XFA_CFXJSE_VALUE_H_ |
| 8 | #define FXJS_XFA_CFXJSE_VALUE_H_ |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | 76a44de | 2017-01-11 08:58:35 -0500 | [diff] [blame] | 10 | #include <memory> |
| 11 | #include <vector> |
| 12 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 13 | #include "core/fxcrt/fx_string.h" |
| 14 | #include "core/fxcrt/fx_system.h" |
Tom Sepez | 98b356a | 2018-07-16 21:35:06 +0000 | [diff] [blame] | 15 | #include "core/fxcrt/unowned_ptr.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 16 | #include "v8/include/v8.h" |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 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 | |
Tom Sepez | 4761770 | 2019-01-23 21:55:41 +0000 | [diff] [blame] | 26 | bool IsEmpty() const; |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 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; |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 36 | bool ToBoolean() const; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 37 | float ToFloat() const; |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 38 | double ToDouble() const; |
| 39 | int32_t ToInteger() const; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 40 | ByteString ToString() const; |
| 41 | WideString ToWideString() const { |
| 42 | return WideString::FromUTF8(ToString().AsStringView()); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 43 | } |
Tom Sepez | 4c35848 | 2018-07-23 20:41:04 +0000 | [diff] [blame] | 44 | CFXJSE_HostObject* ToHostObject() const; |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 45 | |
| 46 | void SetUndefined(); |
| 47 | void SetNull(); |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 48 | void SetBoolean(bool bBoolean); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 49 | void SetInteger(int32_t nInteger); |
| 50 | void SetDouble(double dDouble); |
Tom Sepez | c839ac7 | 2018-12-14 20:34:11 +0000 | [diff] [blame] | 51 | void SetString(ByteStringView szString); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 52 | void SetFloat(float fFloat); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 53 | |
Tom Sepez | 7e4877f | 2019-04-05 21:32:36 +0000 | [diff] [blame] | 54 | void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass); |
| 55 | void ClearHostObject(); |
| 56 | |
Dan Sinclair | 76a44de | 2017-01-11 08:58:35 -0500 | [diff] [blame] | 57 | void SetArray(const std::vector<std::unique_ptr<CFXJSE_Value>>& values); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 58 | |
Tom Sepez | c839ac7 | 2018-12-14 20:34:11 +0000 | [diff] [blame] | 59 | bool GetObjectProperty(ByteStringView szPropName, CFXJSE_Value* lpPropValue); |
| 60 | bool SetObjectProperty(ByteStringView szPropName, CFXJSE_Value* lpPropValue); |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 61 | bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); |
Tom Sepez | c839ac7 | 2018-12-14 20:34:11 +0000 | [diff] [blame] | 62 | bool DeleteObjectProperty(ByteStringView szPropName); |
| 63 | bool HasObjectOwnProperty(ByteStringView szPropName, bool bUseTypeGetter); |
| 64 | bool SetObjectOwnProperty(ByteStringView szPropName, |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 65 | CFXJSE_Value* lpPropValue); |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 66 | bool SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 67 | |
Tom Sepez | 98b356a | 2018-07-16 21:35:06 +0000 | [diff] [blame] | 68 | v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); } |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 69 | const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; } |
| 70 | void ForceSetValue(v8::Local<v8::Value> hValue) { |
Tom Sepez | 98b356a | 2018-07-16 21:35:06 +0000 | [diff] [blame] | 71 | m_hValue.Reset(GetIsolate(), hValue); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 72 | } |
| 73 | void Assign(const CFXJSE_Value* lpValue) { |
| 74 | ASSERT(lpValue); |
| 75 | if (lpValue) { |
Tom Sepez | 98b356a | 2018-07-16 21:35:06 +0000 | [diff] [blame] | 76 | m_hValue.Reset(GetIsolate(), lpValue->m_hValue); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 77 | } else { |
| 78 | m_hValue.Reset(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | private: |
Lei Zhang | da379c7 | 2018-08-28 23:12:22 +0000 | [diff] [blame] | 83 | CFXJSE_Value() = delete; |
| 84 | CFXJSE_Value(const CFXJSE_Value&) = delete; |
| 85 | CFXJSE_Value& operator=(const CFXJSE_Value&) = delete; |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 86 | |
Lei Zhang | da379c7 | 2018-08-28 23:12:22 +0000 | [diff] [blame] | 87 | UnownedPtr<v8::Isolate> const m_pIsolate; |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 88 | v8::Global<v8::Value> m_hValue; |
| 89 | }; |
| 90 | |
Tom Sepez | 70e5214 | 2018-12-13 20:07:50 +0000 | [diff] [blame] | 91 | #endif // FXJS_XFA_CFXJSE_VALUE_H_ |