| 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 FPDFSDK_JAVASCRIPT_JS_VALUE_H_ | 7 #ifndef FPDFSDK_JAVASCRIPT_JS_VALUE_H_ |
| 8 #define FPDFSDK_JAVASCRIPT_JS_VALUE_H_ | 8 #define FPDFSDK_JAVASCRIPT_JS_VALUE_H_ |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "core/fxcrt/include/fx_basic.h" | 12 #include "core/fxcrt/include/fx_basic.h" |
| 13 #include "fxjs/include/fxjs_v8.h" | 13 #include "fxjs/include/fxjs_v8.h" |
| 14 | 14 |
| 15 class CJS_Array; | 15 class CJS_Array; |
| 16 class CJS_Date; | 16 class CJS_Date; |
| 17 class CJS_Document; | 17 class CJS_Document; |
| 18 class CJS_Object; | 18 class CJS_Object; |
| 19 class CJS_Runtime; | 19 class CJS_Runtime; |
| 20 | 20 |
| 21 class CJS_Value { | 21 class CJS_Value { |
| 22 public: | 22 public: |
| 23 enum Type { | 23 enum Type { |
| 24 VT_unknown, | 24 VT_unknown, |
| 25 VT_string, | 25 VT_string, |
| 26 VT_number, | 26 VT_number, |
| 27 VT_boolean, | 27 VT_boolean, |
| 28 VT_date, | 28 VT_date, |
| 29 VT_object, | 29 VT_object, |
| 30 VT_fxobject, | |
| 31 VT_null, | 30 VT_null, |
| 32 VT_undefined | 31 VT_undefined |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 CJS_Value(CJS_Runtime* pRuntime); | 34 CJS_Value(CJS_Runtime* pRuntime); |
| 36 CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue, Type t); | 35 CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue); |
| 37 CJS_Value(CJS_Runtime* pRuntime, const int& iValue); | 36 CJS_Value(CJS_Runtime* pRuntime, const int& iValue); |
| 38 CJS_Value(CJS_Runtime* pRuntime, const double& dValue); | 37 CJS_Value(CJS_Runtime* pRuntime, const double& dValue); |
| 39 CJS_Value(CJS_Runtime* pRuntime, const float& fValue); | 38 CJS_Value(CJS_Runtime* pRuntime, const float& fValue); |
| 40 CJS_Value(CJS_Runtime* pRuntime, const bool& bValue); | 39 CJS_Value(CJS_Runtime* pRuntime, const bool& bValue); |
| 41 CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Object>); | 40 CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Object>); |
| 42 CJS_Value(CJS_Runtime* pRuntime, CJS_Object*); | 41 CJS_Value(CJS_Runtime* pRuntime, CJS_Object*); |
| 43 CJS_Value(CJS_Runtime* pRuntime, CJS_Document*); | 42 CJS_Value(CJS_Runtime* pRuntime, CJS_Document*); |
| 44 CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr); | 43 CJS_Value(CJS_Runtime* pRuntime, const FX_CHAR* pStr); |
| 45 CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr); | 44 CJS_Value(CJS_Runtime* pRuntime, const FX_WCHAR* pWstr); |
| 46 CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array); | 45 CJS_Value(CJS_Runtime* pRuntime, CJS_Array& array); |
| 47 | 46 |
| 48 ~CJS_Value(); | 47 ~CJS_Value(); |
| 49 CJS_Value(const CJS_Value& other); | 48 CJS_Value(const CJS_Value& other); |
| 50 | 49 |
| 51 void SetNull(); | 50 void SetNull(); |
| 52 void Attach(v8::Local<v8::Value> pValue, Type t); | 51 void Attach(v8::Local<v8::Value> pValue); |
| 53 void Attach(CJS_Value* pValue); | 52 void Attach(CJS_Value* pValue); |
| 54 void Detach(); | 53 void Detach(); |
| 55 | 54 |
| 56 Type GetType() const; | 55 static Type GetValueType(v8::Local<v8::Value> value); |
| 56 Type GetType() const { return GetValueType(m_pValue); } |
| 57 int ToInt() const; | 57 int ToInt() const; |
| 58 bool ToBool() const; | 58 bool ToBool() const; |
| 59 double ToDouble() const; | 59 double ToDouble() const; |
| 60 float ToFloat() const; | 60 float ToFloat() const; |
| 61 CJS_Object* ToCJSObject() const; | 61 CJS_Object* ToCJSObject() const; |
| 62 CFX_WideString ToCFXWideString() const; | 62 CFX_WideString ToCFXWideString() const; |
| 63 CFX_ByteString ToCFXByteString() const; | 63 CFX_ByteString ToCFXByteString() const; |
| 64 v8::Local<v8::Object> ToV8Object() const; | 64 v8::Local<v8::Object> ToV8Object() const; |
| 65 v8::Local<v8::Array> ToV8Array() const; | 65 v8::Local<v8::Array> ToV8Array() const; |
| 66 v8::Local<v8::Value> ToV8Value() const; | 66 v8::Local<v8::Value> ToV8Value() const; |
| 67 | 67 |
| 68 // Replace the current |m_pValue| with a v8::Number if possible | 68 // Replace the current |m_pValue| with a v8::Number if possible |
| 69 // to make one from the current |m_pValue|, updating |m_eType| | 69 // to make one from the current |m_pValue|. |
| 70 // as appropriate to indicate the result. | |
| 71 void MaybeCoerceToNumber(); | 70 void MaybeCoerceToNumber(); |
| 72 | 71 |
| 73 void operator=(int iValue); | 72 void operator=(int iValue); |
| 74 void operator=(bool bValue); | 73 void operator=(bool bValue); |
| 75 void operator=(double val); | 74 void operator=(double val); |
| 76 void operator=(float val); | 75 void operator=(float val); |
| 77 void operator=(CJS_Object* val); | 76 void operator=(CJS_Object* val); |
| 78 void operator=(CJS_Document* val); | 77 void operator=(CJS_Document* val); |
| 79 void operator=(v8::Local<v8::Object> val); | 78 void operator=(v8::Local<v8::Object> val); |
| 80 void operator=(CJS_Array& val); | 79 void operator=(CJS_Array& val); |
| 81 void operator=(CJS_Date& val); | 80 void operator=(CJS_Date& val); |
| 82 void operator=(const FX_WCHAR* pWstr); | 81 void operator=(const FX_WCHAR* pWstr); |
| 83 void operator=(const FX_CHAR* pStr); | 82 void operator=(const FX_CHAR* pStr); |
| 84 void operator=(CJS_Value value); | 83 void operator=(CJS_Value value); |
| 85 | 84 |
| 86 FX_BOOL IsArrayObject() const; | 85 FX_BOOL IsArrayObject() const; |
| 87 FX_BOOL IsDateObject() const; | 86 FX_BOOL IsDateObject() const; |
| 88 FX_BOOL ConvertToArray(CJS_Array&) const; | 87 FX_BOOL ConvertToArray(CJS_Array&) const; |
| 89 FX_BOOL ConvertToDate(CJS_Date&) const; | 88 FX_BOOL ConvertToDate(CJS_Date&) const; |
| 90 | 89 |
| 91 CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; } | 90 CJS_Runtime* GetJSRuntime() const { return m_pJSRuntime; } |
| 92 | 91 |
| 93 protected: | 92 protected: |
| 94 Type m_eType; | |
| 95 v8::Local<v8::Value> m_pValue; | 93 v8::Local<v8::Value> m_pValue; |
| 96 CJS_Runtime* m_pJSRuntime; | 94 CJS_Runtime* m_pJSRuntime; |
| 97 }; | 95 }; |
| 98 | 96 |
| 99 class CJS_PropValue : public CJS_Value { | 97 class CJS_PropValue : public CJS_Value { |
| 100 public: | 98 public: |
| 101 CJS_PropValue(const CJS_Value&); | 99 CJS_PropValue(const CJS_Value&); |
| 102 CJS_PropValue(CJS_Runtime* pRuntime); | 100 CJS_PropValue(CJS_Runtime* pRuntime); |
| 103 ~CJS_PropValue(); | 101 ~CJS_PropValue(); |
| 104 | 102 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // names as wchar_t string literals corresponding to each positional argument. | 221 // names as wchar_t string literals corresponding to each positional argument. |
| 224 // The result will always contain |nKeywords| value, with unspecified ones | 222 // The result will always contain |nKeywords| value, with unspecified ones |
| 225 // being set to type VT_unknown. | 223 // being set to type VT_unknown. |
| 226 std::vector<CJS_Value> JS_ExpandKeywordParams( | 224 std::vector<CJS_Value> JS_ExpandKeywordParams( |
| 227 CJS_Runtime* pRuntime, | 225 CJS_Runtime* pRuntime, |
| 228 const std::vector<CJS_Value>& originals, | 226 const std::vector<CJS_Value>& originals, |
| 229 size_t nKeywords, | 227 size_t nKeywords, |
| 230 ...); | 228 ...); |
| 231 | 229 |
| 232 #endif // FPDFSDK_JAVASCRIPT_JS_VALUE_H_ | 230 #endif // FPDFSDK_JAVASCRIPT_JS_VALUE_H_ |
| OLD | NEW |