-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathV8ObjectHolderImpl.cpp
159 lines (117 loc) · 5.38 KB
/
V8ObjectHolderImpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#include "ClearScriptV8Native.h"
//-----------------------------------------------------------------------------
// V8ObjectHolderImpl implementation
//-----------------------------------------------------------------------------
V8ObjectHolderImpl::V8ObjectHolderImpl(const SharedPtr<V8WeakContextBinding>& spBinding, void* pvObject, int32_t identityHash, const SharedPtr<V8SharedObjectInfo>& spSharedObjectInfo):
m_spBinding(spBinding),
m_pvObject(pvObject),
m_IdentityHash(identityHash),
m_spSharedObjectInfo(spSharedObjectInfo)
{
}
//-----------------------------------------------------------------------------
V8ObjectHolderImpl* V8ObjectHolderImpl::Clone() const
{
return new V8ObjectHolderImpl(m_spBinding, m_spBinding->GetIsolateImpl()->AddRefV8Object(m_pvObject), m_IdentityHash, m_spSharedObjectInfo);
}
//-----------------------------------------------------------------------------
bool V8ObjectHolderImpl::IsSameIsolate(const SharedPtr<V8IsolateImpl>& spThat) const
{
SharedPtr<V8IsolateImpl> spIsolateImpl;
if (m_spBinding->TryGetIsolateImpl(spIsolateImpl))
{
return spIsolateImpl == spThat;
}
return false;
}
//-----------------------------------------------------------------------------
void* V8ObjectHolderImpl::GetObject() const
{
return m_pvObject;
}
//-----------------------------------------------------------------------------
int32_t V8ObjectHolderImpl::GetIdentityHash() const
{
return m_IdentityHash;
}
//-----------------------------------------------------------------------------
const SharedPtr<V8SharedObjectInfo>& V8ObjectHolderImpl::GetSharedObjectInfo() const
{
return m_spSharedObjectInfo;
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHolderImpl::GetProperty(const StdString& name) const
{
return m_spBinding->GetContextImpl()->GetV8ObjectProperty(m_pvObject, name);
}
//-----------------------------------------------------------------------------
bool V8ObjectHolderImpl::TryGetProperty(const StdString& name, V8Value& value) const
{
return m_spBinding->GetContextImpl()->TryGetV8ObjectProperty(m_pvObject, name, value);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::SetProperty(const StdString& name, const V8Value& value) const
{
m_spBinding->GetContextImpl()->SetV8ObjectProperty(m_pvObject, name, value);
}
//-----------------------------------------------------------------------------
bool V8ObjectHolderImpl::DeleteProperty(const StdString& name) const
{
return m_spBinding->GetContextImpl()->DeleteV8ObjectProperty(m_pvObject, name);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::GetPropertyNames(bool includeIndices, std::vector<StdString>& names) const
{
m_spBinding->GetContextImpl()->GetV8ObjectPropertyNames(m_pvObject, includeIndices, names);
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHolderImpl::GetProperty(int index) const
{
return m_spBinding->GetContextImpl()->GetV8ObjectProperty(m_pvObject, index);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::SetProperty(int index, const V8Value& value) const
{
m_spBinding->GetContextImpl()->SetV8ObjectProperty(m_pvObject, index, value);
}
//-----------------------------------------------------------------------------
bool V8ObjectHolderImpl::DeleteProperty(int index) const
{
return m_spBinding->GetContextImpl()->DeleteV8ObjectProperty(m_pvObject, index);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::GetPropertyIndices(std::vector<int>& indices) const
{
m_spBinding->GetContextImpl()->GetV8ObjectPropertyIndices(m_pvObject, indices);
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHolderImpl::Invoke(bool asConstructor, const std::vector<V8Value>& args) const
{
return m_spBinding->GetContextImpl()->InvokeV8Object(m_pvObject, asConstructor, args);
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHolderImpl::InvokeMethod(const StdString& name, const std::vector<V8Value>& args) const
{
return m_spBinding->GetContextImpl()->InvokeV8ObjectMethod(m_pvObject, name, args);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::GetArrayBufferOrViewInfo(V8Value& arrayBuffer, size_t& offset, size_t& size, size_t& length) const
{
m_spBinding->GetContextImpl()->GetV8ObjectArrayBufferOrViewInfo(m_pvObject, arrayBuffer, offset, size, length);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::InvokeWithArrayBufferOrViewData(V8ObjectHelpers::ArrayBufferOrViewDataCallback* pCallback, void* pvArg) const
{
m_spBinding->GetContextImpl()->InvokeWithV8ObjectArrayBufferOrViewData(m_pvObject, pCallback, pvArg);
}
//-----------------------------------------------------------------------------
V8ObjectHolderImpl::~V8ObjectHolderImpl()
{
SharedPtr<V8IsolateImpl> spIsolateImpl;
if (m_spBinding->TryGetIsolateImpl(spIsolateImpl))
{
spIsolateImpl->ReleaseV8Object(m_pvObject);
}
}