forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathV8FastHostFunction.cs
More file actions
143 lines (126 loc) · 6.75 KB
/
Copy pathV8FastHostFunction.cs
File metadata and controls
143 lines (126 loc) · 6.75 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
namespace Microsoft.ClearScript.V8.FastProxy
{
/// <summary>
/// Provides an implementation of <c><see cref="IV8FastHostFunction"/></c> with a private configuration.
/// </summary>
public sealed class V8FastHostFunction : V8FastHostFunctionOperations<V8FastHostFunction>, IV8FastHostFunction
{
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance.
/// </summary>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(V8FastHostFunctionInvoker invoker)
: this(0, invoker)
{
}
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance with the specified name.
/// </summary>
/// <param name="name">The function name.</param>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(string name, V8FastHostFunctionInvoker invoker)
: this(name, 0, invoker)
{
}
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance with the specified required argument count.
/// </summary>
/// <param name="requiredArgCount">The required argument count for the function.</param>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(int requiredArgCount, V8FastHostFunctionInvoker invoker)
: this(requiredArgCount, null, invoker)
{
}
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance with the specified configuration callback.
/// </summary>
/// <param name="configurator">A callback for preparing the configuration associated with the instance.</param>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(V8FastHostObjectConfigurator<V8FastHostFunction> configurator, V8FastHostFunctionInvoker invoker)
: this(0, configurator, invoker)
{
}
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance with the specified name and required argument count.
/// </summary>
/// <param name="name">The function name.</param>
/// <param name="requiredArgCount">The required argument count for the function.</param>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(string name, int requiredArgCount, V8FastHostFunctionInvoker invoker)
: this(name, requiredArgCount, null, invoker)
{
}
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance with the specified name and configuration callback.
/// </summary>
/// <param name="name">The function name.</param>
/// <param name="configurator">A callback for preparing the configuration associated with the instance.</param>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(string name, V8FastHostObjectConfigurator<V8FastHostFunction> configurator, V8FastHostFunctionInvoker invoker)
: this(name, 0, configurator, invoker)
{
}
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance with the specified required argument count and configuration callback.
/// </summary>
/// <param name="requiredArgCount">The required argument count for the function.</param>
/// <param name="configurator">A callback for preparing the configuration associated with the instance.</param>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(int requiredArgCount, V8FastHostObjectConfigurator<V8FastHostFunction> configurator, V8FastHostFunctionInvoker invoker)
: this(null, requiredArgCount, configurator, invoker)
{
}
/// <summary>
/// Initializes a new <c><see cref="V8FastHostFunction"/></c> instance with the specified name, required argument count, and configuration callback.
/// </summary>
/// <param name="name">The function name.</param>
/// <param name="requiredArgCount">The required argument count for the function.</param>
/// <param name="configurator">A callback for preparing the configuration associated with the instance.</param>
/// <param name="invoker">The function invocation callback.</param>
public V8FastHostFunction(string name, int requiredArgCount, V8FastHostObjectConfigurator<V8FastHostFunction> configurator, V8FastHostFunctionInvoker invoker)
: base(name, requiredArgCount, configurator, invoker)
{
}
/// <summary>
/// Verifies that a fast host function was invoked as a function and not as a constructor.
/// </summary>
/// <param name="asConstructor"><c>True</c> if the function was invoked as a constructor, <c>false</c> otherwise.</param>
/// <remarks>
/// This is a simple utility method that checks <paramref name="asConstructor"/> and throws
/// an exception if it is <c>true</c>. It is intended for use within fast host function
/// invocation callbacks.
/// </remarks>
public static void VerifyFunctionCall(bool asConstructor)
{
if (asConstructor)
{
throw new NotSupportedException("The function does not support constructor invocation");
}
}
/// <summary>
/// Verifies that a fast host function was invoked as a constructor and not as a function.
/// </summary>
/// <param name="asConstructor"><c>True</c> if the function was invoked as a constructor, <c>false</c> otherwise.</param>
/// <remarks>
/// This is a simple utility method that checks <paramref name="asConstructor"/> and throws
/// an exception if it is <c>false</c>. It is intended for use within fast host function
/// invocation callbacks.
/// </remarks>
public static void VerifyConstructorCall(bool asConstructor)
{
if (!asConstructor)
{
throw new NotSupportedException("The function requires constructor invocation");
}
}
#region IV8FastHostFunction implementation
IV8FastHostFunctionOperations IV8FastHostFunction.Operations => this;
#endregion
#region IV8FastHostObject implementation
IV8FastHostObjectOperations IV8FastHostObject.Operations => this;
#endregion
}
}