forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathV8FastArg.cs
More file actions
373 lines (328 loc) · 20.3 KB
/
Copy pathV8FastArg.cs
File metadata and controls
373 lines (328 loc) · 20.3 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Numerics;
using Microsoft.ClearScript.V8.SplitProxy;
namespace Microsoft.ClearScript.V8.FastProxy
{
/// <summary>
/// Represents an argument passed to a fast host object from script code.
/// </summary>
public readonly ref struct V8FastArg
{
private readonly V8Value.FastArg.Ptr pArg;
private readonly V8FastArgKind kind;
private readonly object obj;
internal V8FastArg(V8ScriptEngine engine, V8Value.FastArg.Ptr pArg, V8FastArgKind kind)
{
this.pArg = pArg;
this.kind = kind;
obj = V8FastArgImpl.InitializeObject(engine, pArg.AsRef());
}
/// <summary>
/// Determines whether the argument is <see href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy">falsy</see>.
/// </summary>
public bool IsFalsy => V8FastArgImpl.IsFalsy(pArg.AsRef(), obj);
/// <summary>
/// Determines whether the argument is <see href="https://developer.mozilla.org/en-US/docs/Glossary/Truthy">truthy</see>.
/// </summary>
public bool IsTruthy => V8FastArgImpl.IsTruthy(pArg.AsRef(), obj);
/// <summary>
/// Determines whether the argument is <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</see></c>.
/// </summary>
public bool IsUndefined => V8FastArgImpl.IsUndefined(pArg.AsRef(), obj);
/// <summary>
/// Determines whether the argument is <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null">null</see></c>.
/// </summary>
public bool IsNull => V8FastArgImpl.IsNull(pArg.AsRef(), obj);
/// <summary>
/// Gets the <c><see cref="bool"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="bool"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out bool value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="char"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="char"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out char value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="sbyte"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="sbyte"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out sbyte value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="byte"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="byte"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out byte value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="short"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="short"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out short value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="ushort"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="ushort"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out ushort value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="int"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="int"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out int value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="uint"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="uint"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out uint value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="long"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="long"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out long value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="ulong"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="ulong"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out ulong value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="float"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="float"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out float value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="double"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="double"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out double value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="decimal"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="decimal"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out decimal value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the string value of the argument if possible.
/// </summary>
/// <param name="value">On return, the string value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out string value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the string value of the argument as a <c><see href="https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1">ReadOnlySpan<char></see></c> if possible.
/// </summary>
/// <param name="value">On return, the string value of the argument as a <c><see href="https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1">ReadOnlySpan<char></see></c> if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out ReadOnlySpan<char> value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="DateTime"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="DateTime"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out DateTime value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="BigInteger"/></c> value of the argument if possible.
/// </summary>
/// <param name="value">On return, the <c><see cref="BigInteger"/></c> value of the argument if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet(out BigInteger value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets a nullable value of the given underlying type from the argument if possible.
/// </summary>
/// <typeparam name="T">The underlying type of the nullable value to get.</typeparam>
/// <param name="value">On return, a nullable value of underlying type <typeparamref name="T"/> if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet<T>(out T? value) where T : struct => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets a value of the given type from the argument if possible.
/// </summary>
/// <typeparam name="T">The type of value to get.</typeparam>
/// <param name="value">On return, a value of type <typeparamref name="T"/> if the operation succeeded.</param>
/// <returns><c>True</c> if the operation succeeded, <c>false</c> otherwise.</returns>
public bool TryGet<T>(out T value) => V8FastArgImpl.TryGet(pArg.AsRef(), obj, out value);
/// <summary>
/// Gets the <c><see cref="bool"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="bool"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public bool GetBoolean(string name = null) => V8FastArgImpl.GetBoolean(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="char"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="char"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public char GetChar(string name = null) => V8FastArgImpl.GetChar(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="sbyte"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="sbyte"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public sbyte GetSByte(string name = null) => V8FastArgImpl.GetSByte(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="byte"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="byte"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public byte GetByte(string name = null) => V8FastArgImpl.GetByte(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="short"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="short"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public short GetInt16(string name = null) => V8FastArgImpl.GetInt16(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="ushort"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="ushort"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public ushort GetUInt16(string name = null) => V8FastArgImpl.GetUInt16(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="int"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="int"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public int GetInt32(string name = null) => V8FastArgImpl.GetInt32(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="uint"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="uint"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public uint GetUInt32(string name = null) => V8FastArgImpl.GetUInt32(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="long"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="long"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public long GetInt64(string name = null) => V8FastArgImpl.GetInt64(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="ulong"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="ulong"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public ulong GetUInt64(string name = null) => V8FastArgImpl.GetUInt64(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="float"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="float"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public float GetSingle(string name = null) => V8FastArgImpl.GetSingle(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="double"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="double"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public double GetDouble(string name = null) => V8FastArgImpl.GetDouble(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="decimal"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="decimal"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public decimal GetDecimal(string name = null) => V8FastArgImpl.GetDecimal(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the string value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The string value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public string GetString(string name = null) => V8FastArgImpl.GetString(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the string value of the argument as a <c><see href="https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1">ReadOnlySpan<char></see></c>.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The string value of the argument as a <c><see href="https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1">ReadOnlySpan<char></see></c>.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public ReadOnlySpan<char> GetCharSpan(string name = null) => V8FastArgImpl.GetCharSpan(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="DateTime"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="DateTime"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public DateTime GetDateTime(string name = null) => V8FastArgImpl.GetDateTime(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets the <c><see cref="BigInteger"/></c> value of the argument.
/// </summary>
/// <param name="name">An optional argument or property name.</param>
/// <returns>The <c><see cref="BigInteger"/></c> value of the argument.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public BigInteger GetBigInteger(string name = null) => V8FastArgImpl.GetBigInteger(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets a nullable value of the given underlying type from the argument.
/// </summary>
/// <typeparam name="T">The underlying type of the nullable value to get.</typeparam>
/// <param name="name">An optional argument or property name.</param>
/// <returns>A nullable value of underlying type <typeparamref name="T"/>.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public T? GetNullable<T>(string name = null) where T : struct => V8FastArgImpl.GetNullable<T>(pArg.AsRef(), obj, kind, name);
/// <summary>
/// Gets a value of the given type from the argument.
/// </summary>
/// <typeparam name="T">The type of value to get.</typeparam>
/// <param name="name">An optional argument or property name.</param>
/// <returns>A value of type <typeparamref name="T"/>.</returns>
/// <remarks>
/// This method throws an exception if the operation fails.
/// </remarks>
public T Get<T>(string name = null) => V8FastArgImpl.Get<T>(pArg.AsRef(), obj, kind, name);
}
}