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
87 lines (68 loc) · 3.75 KB
/
HostObjectUtil.h
File metadata and controls
87 lines (68 loc) · 3.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
struct V8DocumentInfo;
//-----------------------------------------------------------------------------
// IHostObjectUtil
//-----------------------------------------------------------------------------
struct IHostObjectUtil
{
virtual void* AddRef(void* pvObject) = 0;
virtual void Release(void* pvObject) = 0;
virtual V8Value GetProperty(void* pvObject, const StdString& name) = 0;
virtual V8Value GetProperty(void* pvObject, const StdString& name, bool& isCacheable) = 0;
virtual void SetProperty(void* pvObject, const StdString& name, const V8Value& value) = 0;
virtual bool DeleteProperty(void* pvObject, const StdString& name) = 0;
virtual void GetPropertyNames(void* pvObject, std::vector<StdString>& names) = 0;
virtual V8Value GetProperty(void* pvObject, int32_t index) = 0;
virtual void SetProperty(void* pvObject, int32_t index, const V8Value& value) = 0;
virtual bool DeleteProperty(void* pvObject, int32_t index) = 0;
virtual void GetPropertyIndices(void* pvObject, std::vector<int32_t>& indices) = 0;
virtual V8Value Invoke(void* pvObject, bool asConstructor, const std::vector<V8Value>& args) = 0;
virtual V8Value InvokeMethod(void* pvObject, const StdString& name, const std::vector<V8Value>& args) = 0;
enum class Invocability : int32_t
{
// IMPORTANT: maintain bitwise equivalence with managed enum Invocability
None,
Delegate,
Dynamic,
DefaultProperty
};
virtual Invocability GetInvocability(void* pvObject) = 0;
virtual V8Value GetEnumerator(void* pvObject) = 0;
virtual V8Value GetAsyncEnumerator(void* pvObject) = 0;
virtual void* CreateV8ObjectCache() = 0;
virtual void CacheV8Object(void* pvCache, void* pvObject, void* pvV8Object) = 0;
virtual void* GetCachedV8Object(void* pvCache, void* pvObject) = 0;
virtual void GetAllCachedV8Objects(void* pvCache, std::vector<void*>& v8ObjectPtrs) = 0;
virtual bool RemoveV8ObjectCacheEntry(void* pvCache, void* pvObject) = 0;
enum class DebugDirective
{
ConnectClient,
SendCommand,
DisconnectClient
};
using DebugCallback = std::function<void(DebugDirective directive, const StdString* pCommand)>;
virtual void* CreateDebugAgent(const StdString& name, const StdString& version, int32_t port, bool remote, DebugCallback&& callback) = 0;
virtual void SendDebugMessage(void* pvAgent, const StdString& content) = 0;
virtual void DestroyDebugAgent(void* pvAgent) = 0;
using NativeCallback = std::function<void()>;
virtual void QueueNativeCallback(NativeCallback&& callback) = 0;
virtual void* CreateNativeCallbackTimer(int32_t dueTime, int32_t period, NativeCallback&& callback) = 0;
virtual bool ChangeNativeCallbackTimer(void* pvTimer, int32_t dueTime, int32_t period) = 0;
virtual void DestroyNativeCallbackTimer(void* pvTimer) = 0;
virtual StdString LoadModule(const V8DocumentInfo& sourceDocumentInfo, const StdString& specifier, V8DocumentInfo& documentInfo) = 0;
virtual std::vector<std::pair<StdString, V8Value>> CreateModuleContext(const V8DocumentInfo& documentInfo) = 0;
virtual size_t GetMaxScriptCacheSize() = 0;
virtual size_t GetMaxModuleCacheSize() = 0;
};
//-----------------------------------------------------------------------------
// HostObjectUtil
//-----------------------------------------------------------------------------
struct HostObjectUtil final: StaticBase
{
static IHostObjectUtil& GetInstance() noexcept;
};