-
-
Notifications
You must be signed in to change notification settings - Fork 567
/
Copy pathUuidPrototype.cs
44 lines (36 loc) · 1.41 KB
/
UuidPrototype.cs
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
using Jint.Native;
using Jint.Runtime;
using Jint.Runtime.Interop;
namespace Jint.Tests.Runtime.Domain
{
internal sealed class UuidPrototype : UuidInstance
{
private UuidPrototype(Engine engine) : base(engine)
{
}
private UuidInstance EnsureUuidInstance(JsValue thisObj)
{
return thisObj.TryCast<UuidInstance>(value =>
{
throw new JavaScriptException(Engine.TypeError, "Invalid Uuid");
});
}
private JsValue ToGuidString(JsValue thisObj, JsValue[] arguments) => EnsureUuidInstance(thisObj).PrimitiveValue.ToString();
private JsValue ValueOf(JsValue thisObj, JsValue[] arguments) => EnsureUuidInstance(thisObj).PrimitiveValue;
public static UuidPrototype CreatePrototypeObject(Engine engine, UuidConstructor ctor)
{
var obj = new UuidPrototype(engine)
{
PrimitiveValue = JsUuid.Empty,
_prototype = engine.Object.PrototypeObject,
};
obj.FastAddProperty("constructor", ctor, false, false, true);
return obj;
}
public void Configure()
{
FastAddProperty("toString", new ClrFunctionInstance(Engine, "toString", ToGuidString), true, false, true);
FastAddProperty("valueOf", new ClrFunctionInstance(Engine, "valueOf", ValueOf), true, false, true);
}
}
}