forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathV8ObjectImpl.cs
More file actions
186 lines (153 loc) · 6.64 KB
/
Copy pathV8ObjectImpl.cs
File metadata and controls
186 lines (153 loc) · 6.64 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
namespace Microsoft.ClearScript.V8.SplitProxy
{
internal sealed class V8ObjectImpl : IV8Object
{
private V8EntityHolder holder;
public V8Object.Handle Handle => (V8Object.Handle)holder.Handle;
public V8ObjectImpl(V8Object.Handle hObject, V8Value.Subtype subtype, V8Value.Flags flags)
{
holder = new V8EntityHolder("V8 object", () => hObject);
Subtype = subtype;
Flags = flags;
}
public V8Value.Subtype Subtype { get; }
public V8Value.Flags Flags { get; }
#region IV8Object implementation
public object GetProperty(string name)
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_GetNamedProperty(Handle, name));
}
public void SetProperty(string name, object value)
{
V8SplitProxyNative.Invoke(instance => instance.V8Object_SetNamedProperty(Handle, name, value));
}
public bool DeleteProperty(string name)
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_DeleteNamedProperty(Handle, name));
}
public string[] GetPropertyNames()
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_GetPropertyNames(Handle));
}
public object GetProperty(int index)
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_GetIndexedProperty(Handle, index));
}
public void SetProperty(int index, object value)
{
V8SplitProxyNative.Invoke(instance => instance.V8Object_SetIndexedProperty(Handle, index, value));
}
public bool DeleteProperty(int index)
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_DeleteIndexedProperty(Handle, index));
}
public int[] GetPropertyIndices()
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_GetPropertyIndices(Handle));
}
public object Invoke(bool asConstructor, object[] args)
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_Invoke(Handle, asConstructor, args));
}
public object InvokeMethod(string name, object[] args)
{
return V8SplitProxyNative.Invoke(instance => instance.V8Object_InvokeMethod(Handle, name, args));
}
public bool IsPromise => Subtype == V8Value.Subtype.Promise;
public bool IsArray => Subtype == V8Value.Subtype.Array;
public bool IsShared => Flags.HasFlag(V8Value.Flags.Shared);
public bool IsArrayBufferOrView
{
get
{
switch (Subtype)
{
case V8Value.Subtype.ArrayBuffer:
case V8Value.Subtype.DataView:
case V8Value.Subtype.Uint8Array:
case V8Value.Subtype.Uint8ClampedArray:
case V8Value.Subtype.Int8Array:
case V8Value.Subtype.Uint16Array:
case V8Value.Subtype.Int16Array:
case V8Value.Subtype.Uint32Array:
case V8Value.Subtype.Int32Array:
case V8Value.Subtype.BigUint64Array:
case V8Value.Subtype.BigInt64Array:
case V8Value.Subtype.Float32Array:
case V8Value.Subtype.Float64Array:
return true;
default:
return false;
}
}
}
public V8ArrayBufferOrViewKind GetArrayBufferOrViewKind()
{
var kind = V8ArrayBufferOrViewKind.None;
if (Subtype == V8Value.Subtype.ArrayBuffer)
kind = V8ArrayBufferOrViewKind.ArrayBuffer;
else if (Subtype == V8Value.Subtype.DataView)
kind = V8ArrayBufferOrViewKind.DataView;
else if (Subtype == V8Value.Subtype.Uint8Array)
kind = V8ArrayBufferOrViewKind.Uint8Array;
else if (Subtype == V8Value.Subtype.Uint8ClampedArray)
kind = V8ArrayBufferOrViewKind.Uint8ClampedArray;
else if (Subtype == V8Value.Subtype.Int8Array)
kind = V8ArrayBufferOrViewKind.Int8Array;
else if (Subtype == V8Value.Subtype.Uint16Array)
kind = V8ArrayBufferOrViewKind.Uint16Array;
else if (Subtype == V8Value.Subtype.Int16Array)
kind = V8ArrayBufferOrViewKind.Int16Array;
else if (Subtype == V8Value.Subtype.Uint32Array)
kind = V8ArrayBufferOrViewKind.Uint32Array;
else if (Subtype == V8Value.Subtype.Int32Array)
kind = V8ArrayBufferOrViewKind.Int32Array;
else if (Subtype == V8Value.Subtype.BigUint64Array)
kind = V8ArrayBufferOrViewKind.BigUint64Array;
else if (Subtype == V8Value.Subtype.BigInt64Array)
kind = V8ArrayBufferOrViewKind.BigInt64Array;
else if (Subtype == V8Value.Subtype.Float32Array)
kind = V8ArrayBufferOrViewKind.Float32Array;
else if (Subtype == V8Value.Subtype.Float64Array)
kind = V8ArrayBufferOrViewKind.Float64Array;
return kind;
}
public V8ArrayBufferOrViewInfo GetArrayBufferOrViewInfo()
{
var kind = GetArrayBufferOrViewKind();
if (kind != V8ArrayBufferOrViewKind.None)
{
IV8Object arrayBuffer = null;
var offset = 0UL;
var size = 0UL;
var length = 0UL;
V8SplitProxyNative.Invoke(instance => instance.V8Object_GetArrayBufferOrViewInfo(Handle, out arrayBuffer, out offset, out size, out length));
return new V8ArrayBufferOrViewInfo(kind, arrayBuffer, offset, size, length);
}
return null;
}
public void InvokeWithArrayBufferOrViewData(Action<IntPtr> action)
{
using (var actionScope = V8ProxyHelpers.CreateAddRefHostObjectScope(action))
{
var pAction = actionScope.Value;
V8SplitProxyNative.Invoke(instance => instance.V8Object_InvokeWithArrayBufferOrViewData(Handle, pAction));
}
}
#endregion
#region disposal / finalization
public void Dispose()
{
holder.ReleaseEntity();
GC.KeepAlive(this);
}
~V8ObjectImpl()
{
V8EntityHolder.Destroy(ref holder);
}
#endregion
}
}