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 | |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 7 | #ifndef FXJS_CFXJSE_VALUE_H_ |
| 8 | #define FXJS_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" |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 15 | #include "fxjs/cfxjse_isolatetracker.h" |
| 16 | #include "fxjs/cfxjse_runtimedata.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 17 | #include "v8/include/v8.h" |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 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 | |
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; |
| 36 | bool IsDate() const; |
| 37 | bool ToBoolean() const; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 38 | float ToFloat() const; |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 39 | double ToDouble() const; |
| 40 | int32_t ToInteger() const; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 41 | ByteString ToString() const; |
| 42 | WideString ToWideString() const { |
| 43 | return WideString::FromUTF8(ToString().AsStringView()); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 44 | } |
| 45 | CFXJSE_HostObject* ToHostObject(CFXJSE_Class* lpClass) const; |
| 46 | |
| 47 | void SetUndefined(); |
| 48 | void SetNull(); |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 49 | void SetBoolean(bool bBoolean); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 50 | void SetInteger(int32_t nInteger); |
| 51 | void SetDouble(double dDouble); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 52 | void SetString(const ByteStringView& szString); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 53 | void SetFloat(float fFloat); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 54 | void SetJSObject(); |
| 55 | |
| 56 | void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass); |
| 57 | void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* lpClass); |
Dan Sinclair | 76a44de | 2017-01-11 08:58:35 -0500 | [diff] [blame] | 58 | void SetArray(const std::vector<std::unique_ptr<CFXJSE_Value>>& values); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 59 | void SetDate(double dDouble); |
| 60 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 61 | bool GetObjectProperty(const ByteStringView& szPropName, |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 62 | CFXJSE_Value* lpPropValue); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 63 | bool SetObjectProperty(const ByteStringView& szPropName, |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 64 | CFXJSE_Value* lpPropValue); |
| 65 | bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); |
| 66 | bool SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 67 | bool DeleteObjectProperty(const ByteStringView& szPropName); |
| 68 | bool HasObjectOwnProperty(const ByteStringView& szPropName, |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 69 | bool bUseTypeGetter); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 70 | bool SetObjectOwnProperty(const ByteStringView& szPropName, |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 71 | CFXJSE_Value* lpPropValue); |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 72 | bool SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis); |
| 73 | bool Call(CFXJSE_Value* lpReceiver, |
| 74 | CFXJSE_Value* lpRetValue, |
| 75 | uint32_t nArgCount, |
| 76 | CFXJSE_Value** lpArgs); |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 77 | |
| 78 | v8::Isolate* GetIsolate() const { return m_pIsolate; } |
| 79 | const v8::Global<v8::Value>& DirectGetValue() const { return m_hValue; } |
| 80 | void ForceSetValue(v8::Local<v8::Value> hValue) { |
| 81 | m_hValue.Reset(m_pIsolate, hValue); |
| 82 | } |
| 83 | void Assign(const CFXJSE_Value* lpValue) { |
| 84 | ASSERT(lpValue); |
| 85 | if (lpValue) { |
| 86 | m_hValue.Reset(m_pIsolate, lpValue->m_hValue); |
| 87 | } else { |
| 88 | m_hValue.Reset(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | private: |
| 93 | friend class CFXJSE_Class; |
| 94 | friend class CFXJSE_Context; |
| 95 | |
| 96 | CFXJSE_Value(); |
| 97 | CFXJSE_Value(const CFXJSE_Value&); |
| 98 | CFXJSE_Value& operator=(const CFXJSE_Value&); |
| 99 | |
| 100 | v8::Isolate* m_pIsolate; |
| 101 | v8::Global<v8::Value> m_hValue; |
| 102 | }; |
| 103 | |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 104 | #endif // FXJS_CFXJSE_VALUE_H_ |