forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostObjectUtil.h
More file actions
114 lines (93 loc) · 4.99 KB
/
HostObjectUtil.h
File metadata and controls
114 lines (93 loc) · 4.99 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
struct V8DocumentInfo;
//-----------------------------------------------------------------------------
// HostObjectUtil
//-----------------------------------------------------------------------------
struct HostObjectUtil final: StaticBase
{
static void* AddRef(void* pvObject);
static void Release(void* pvObject);
enum class Invocability : int32_t
{
// IMPORTANT: maintain bitwise equivalence with managed enum Invocability
None,
Delegate,
Dynamic,
DefaultProperty
};
static Invocability GetInvocability(void* pvObject);
static V8Value GetProperty(void* pvObject, const StdString& name, bool& isCacheable);
static void SetProperty(void* pvObject, const StdString& name, const V8Value& value);
static bool DeleteProperty(void* pvObject, const StdString& name);
static void GetPropertyNames(void* pvObject, std::vector<StdString>& names);
static V8Value GetProperty(void* pvObject, int32_t index);
static void SetProperty(void* pvObject, int32_t index, const V8Value& value);
static bool DeleteProperty(void* pvObject, int32_t index);
static void GetPropertyIndices(void* pvObject, std::vector<int32_t>& indices);
static V8Value Invoke(void* pvObject, bool asConstructor, size_t argCount, const V8Value* pArgs);
static V8Value InvokeMethod(void* pvObject, const StdString& name, size_t argCount, const V8Value* pArgs);
static V8Value GetEnumerator(void* pvObject);
static V8Value GetAsyncEnumerator(void* pvObject);
static void Dispose(void* pvObject);
static V8Value AsyncDispose(void* pvObject);
static void* CreateV8ObjectCache();
static void CacheV8Object(void* pvCache, void* pvObject, void* pvV8Object);
static void* GetCachedV8Object(void* pvCache, void* pvObject);
static void GetAllCachedV8Objects(void* pvCache, std::vector<void*>& v8ObjectPtrs);
static bool RemoveV8ObjectCacheEntry(void* pvCache, void* pvObject);
enum class DebugDirective
{
ConnectClient,
SendCommand,
DisconnectClient
};
using DebugCallback = std::function<void(DebugDirective directive, const StdString* pCommand)>;
static void* CreateDebugAgent(const StdString& name, const StdString& version, int32_t port, bool remote, DebugCallback&& callback);
static void SendDebugMessage(void* pvAgent, const StdString& content);
static void DestroyDebugAgent(void* pvAgent);
using NativeCallback = std::function<void()>;
static void QueueNativeCallback(NativeCallback&& callback);
static void* CreateNativeCallbackTimer(int32_t dueTime, int32_t period, NativeCallback&& callback);
static bool ChangeNativeCallbackTimer(void* pvTimer, int32_t dueTime, int32_t period);
static void DestroyNativeCallbackTimer(void* pvTimer);
static StdString LoadModule(const V8DocumentInfo& sourceDocumentInfo, const StdString& specifier, V8DocumentInfo& documentInfo, V8Value& exports);
static std::vector<std::pair<StdString, V8Value>> CreateModuleContext(const V8DocumentInfo& documentInfo);
static size_t GetMaxScriptCacheSize();
static size_t GetMaxModuleCacheSize();
};
//-----------------------------------------------------------------------------
// FastHostObjectUtil
//-----------------------------------------------------------------------------
struct FastHostObjectUtil final: StaticBase
{
enum class PropertyFlags : int32_t
{
// IMPORTANT: maintain bitwise equivalence with managed enum V8.FastProxy.V8FastHostPropertyFlags
None = 0,
Available = 0x00000001,
Cacheable = 0x00000002,
Enumerable = 0x00000004,
Writable = 0x00000008,
Deletable = 0x00000010
};
static V8Value GetProperty(void* pvObject, const StdString& name, bool& isCacheable);
static void SetProperty(void* pvObject, const StdString& name, const V8Value& value);
static PropertyFlags QueryProperty(void* pvObject, const StdString& name);
static bool DeleteProperty(void* pvObject, const StdString& name);
static void GetPropertyNames(void* pvObject, std::vector<StdString>& names);
static V8Value GetProperty(void* pvObject, int32_t index);
static void SetProperty(void* pvObject, int32_t index, const V8Value& value);
static PropertyFlags QueryProperty(void* pvObject, int32_t index);
static bool DeleteProperty(void* pvObject, int32_t index);
static void GetPropertyIndices(void* pvObject, std::vector<int32_t>& indices);
static V8Value Invoke(void* pvObject, bool asConstructor, size_t argCount, const V8Value* pArgs);
static V8Value GetEnumerator(void* pvObject);
static V8Value GetAsyncEnumerator(void* pvObject);
static void Dispose(void* pvObject);
static V8Value AsyncDispose(void* pvObject);
};