blob: f506857965ed9bce13fa5f237945e3068738124d [file] [log] [blame]
dsinclair08fea802016-07-12 10:37:52 -07001// 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
dsinclair43554682016-09-29 17:29:48 -07007#ifndef FXJS_CFXJSE_VALUE_H_
8#define FXJS_CFXJSE_VALUE_H_
dsinclair08fea802016-07-12 10:37:52 -07009
Dan Sinclair76a44de2017-01-11 08:58:35 -050010#include <memory>
11#include <vector>
12
dsinclaira52ab742016-09-29 13:59:29 -070013#include "core/fxcrt/fx_string.h"
14#include "core/fxcrt/fx_system.h"
dsinclair08fea802016-07-12 10:37:52 -070015#include "fxjs/cfxjse_isolatetracker.h"
16#include "fxjs/cfxjse_runtimedata.h"
dsinclair43554682016-09-29 17:29:48 -070017#include "v8/include/v8.h"
dsinclair08fea802016-07-12 10:37:52 -070018
19class CFXJSE_Class;
20class CFXJSE_HostObject;
21
22class CFXJSE_Value {
23 public:
24 explicit CFXJSE_Value(v8::Isolate* pIsolate);
25 ~CFXJSE_Value();
26
tsepez304bb912016-11-03 06:10:26 -070027 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 Sinclair05df0752017-03-14 14:43:42 -040038 float ToFloat() const;
dsinclair08fea802016-07-12 10:37:52 -070039 double ToDouble() const;
40 int32_t ToInteger() const;
Ryan Harrison275e2602017-09-18 14:23:18 -040041 ByteString ToString() const;
42 WideString ToWideString() const {
43 return WideString::FromUTF8(ToString().AsStringView());
dsinclair08fea802016-07-12 10:37:52 -070044 }
45 CFXJSE_HostObject* ToHostObject(CFXJSE_Class* lpClass) const;
46
47 void SetUndefined();
48 void SetNull();
tsepez304bb912016-11-03 06:10:26 -070049 void SetBoolean(bool bBoolean);
dsinclair08fea802016-07-12 10:37:52 -070050 void SetInteger(int32_t nInteger);
51 void SetDouble(double dDouble);
Ryan Harrison275e2602017-09-18 14:23:18 -040052 void SetString(const ByteStringView& szString);
Dan Sinclair05df0752017-03-14 14:43:42 -040053 void SetFloat(float fFloat);
dsinclair08fea802016-07-12 10:37:52 -070054 void SetJSObject();
55
56 void SetObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* pClass);
57 void SetHostObject(CFXJSE_HostObject* lpObject, CFXJSE_Class* lpClass);
Dan Sinclair76a44de2017-01-11 08:58:35 -050058 void SetArray(const std::vector<std::unique_ptr<CFXJSE_Value>>& values);
dsinclair08fea802016-07-12 10:37:52 -070059 void SetDate(double dDouble);
60
Ryan Harrison275e2602017-09-18 14:23:18 -040061 bool GetObjectProperty(const ByteStringView& szPropName,
tsepez304bb912016-11-03 06:10:26 -070062 CFXJSE_Value* lpPropValue);
Ryan Harrison275e2602017-09-18 14:23:18 -040063 bool SetObjectProperty(const ByteStringView& szPropName,
tsepez304bb912016-11-03 06:10:26 -070064 CFXJSE_Value* lpPropValue);
65 bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
66 bool SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
Ryan Harrison275e2602017-09-18 14:23:18 -040067 bool DeleteObjectProperty(const ByteStringView& szPropName);
68 bool HasObjectOwnProperty(const ByteStringView& szPropName,
tsepez304bb912016-11-03 06:10:26 -070069 bool bUseTypeGetter);
Ryan Harrison275e2602017-09-18 14:23:18 -040070 bool SetObjectOwnProperty(const ByteStringView& szPropName,
dsinclair08fea802016-07-12 10:37:52 -070071 CFXJSE_Value* lpPropValue);
tsepez304bb912016-11-03 06:10:26 -070072 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);
dsinclair08fea802016-07-12 10:37:52 -070077
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
dsinclair43554682016-09-29 17:29:48 -0700104#endif // FXJS_CFXJSE_VALUE_H_