forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmbeddedItem.cs
More file actions
119 lines (101 loc) · 2.66 KB
/
EmbeddedItem.cs
File metadata and controls
119 lines (101 loc) · 2.66 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
using System;
using System.Collections.Generic;
using JavaScriptEngineSwitcher.Core.Utilities;
namespace JavaScriptEngineSwitcher.ChakraCore.JsRt.Embedding
{
/// <summary>
/// Embedded item
/// </summary>
internal abstract class EmbeddedItem : IDisposable
{
/// <summary>
/// Host type
/// </summary>
private Type _hostType;
/// <summary>
/// Instance of host type
/// </summary>
private object _hostObject;
/// <summary>
/// JavaScript value created from an host item
/// </summary>
private readonly JsValue _scriptValue;
/// <summary>
/// List of native functions, that used to access to members of host item
/// </summary>
private IList<JsNativeFunction> _nativeFunctions;
/// <summary>
/// Flag indicating whether this object is disposed
/// </summary>
private readonly InterlockedStatedFlag _disposedFlag = new InterlockedStatedFlag();
/// <summary>
/// Gets a host type
/// </summary>
public Type HostType
{
get { return _hostType; }
}
/// <summary>
/// Gets a instance of host type
/// </summary>
public object HostObject
{
get { return _hostObject; }
}
/// <summary>
/// Gets a JavaScript value created from an host item
/// </summary>
public JsValue ScriptValue
{
get { return _scriptValue; }
}
/// <summary>
/// Gets a list of native functions, that used to access to members of host item
/// </summary>
public IList<JsNativeFunction> NativeFunctions
{
get { return _nativeFunctions; }
}
/// <summary>
/// Gets a value that indicates if the host item is an instance
/// </summary>
public abstract bool IsInstance
{
get;
}
/// <summary>
/// Constructs an instance of the embedded item
/// </summary>
/// <param name="hostType">Host type</param>
/// <param name="hostObject">Instance of host type</param>
/// <param name="scriptValue">JavaScript value created from an host item</param>
/// <param name="nativeFunctions">List of native functions, that used to access to members of host item</param>
protected EmbeddedItem(Type hostType, object hostObject, JsValue scriptValue,
IList<JsNativeFunction> nativeFunctions)
{
_hostType = hostType;
_hostObject = hostObject;
_scriptValue = scriptValue;
_nativeFunctions = nativeFunctions;
}
#region IDisposable implementation
/// <summary>
/// Disposes the embedded item
/// </summary>
public void Dispose()
{
if (_disposedFlag.Set())
{
_hostType = null;
_hostObject = null;
IList<JsNativeFunction> nativeFunctions = _nativeFunctions;
if (nativeFunctions != null)
{
nativeFunctions.Clear();
_nativeFunctions = null;
}
}
}
#endregion
}
}