blob: 31b751da1e8640529c19c7aa3eec19199b38b319 [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;
41 CFX_ByteString ToString() const;
42 CFX_WideString ToWideString() const {
43 return CFX_WideString::FromUTF8(ToString().AsStringC());
44 }
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);
52 void SetString(const CFX_ByteStringC& 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
tsepez304bb912016-11-03 06:10:26 -070061 bool GetObjectProperty(const CFX_ByteStringC& szPropName,
62 CFXJSE_Value* lpPropValue);
63 bool SetObjectProperty(const CFX_ByteStringC& szPropName,
64 CFXJSE_Value* lpPropValue);
65 bool GetObjectPropertyByIdx(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
66 bool SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
67 bool DeleteObjectProperty(const CFX_ByteStringC& szPropName);
68 bool HasObjectOwnProperty(const CFX_ByteStringC& szPropName,
69 bool bUseTypeGetter);
70 bool SetObjectOwnProperty(const CFX_ByteStringC& 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_