FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScriptV8/HostObjectUtil.cpp at master · aTiKhan/ClearScript · GitHub
aTiKhan
/
ClearScript
Public
forked from
ClearFoundry/ClearScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ClearScript
/
ClearScriptV8
/
HostObjectUtil.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
455 lines (345 loc) · 16.1 KB
Breadcrumbs
ClearScript
/
ClearScriptV8
/
HostObjectUtil.cpp
Copy path
File metadata and controls
455 lines (345 loc) · 16.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
//
Copyright (c) Microsoft Corporation. All rights reserved.
//
Licensed under the MIT license.
#
include
"
ClearScriptV8Native.h
"
//
-----------------------------------------------------------------------------
//
HostObjectUtil implementation
//
-----------------------------------------------------------------------------
void
*
HostObjectUtil::AddRef
(
void
* pvObject)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(
void
*, AddRefHostObject, pvObject);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::Release
(
void
* pvObject)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID_NOTHROW
(ReleaseHostObject, pvObject);
}
//
-----------------------------------------------------------------------------
HostObjectUtil::Invocability
HostObjectUtil::GetInvocability
(
void
* pvObject)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE
(Invocability, GetHostObjectInvocability, pvObject);
}
//
-----------------------------------------------------------------------------
V8Value
HostObjectUtil::GetProperty
(
void
* pvObject,
const
StdString& name,
bool
& isCacheable)
{
V8Value
value
(V8Value::Nonexistent);
StdBool tempIsCacheable;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetHostObjectNamedProperty, pvObject, name, value, tempIsCacheable);
isCacheable = (tempIsCacheable !=
0
);
return
value;
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::SetProperty
(
void
* pvObject,
const
StdString& name,
const
V8Value& value)
{
V8Value::Decoded decodedValue;
value.
Decode
(decodedValue);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(SetHostObjectNamedProperty, pvObject, name, decodedValue);
}
//
-----------------------------------------------------------------------------
bool
HostObjectUtil::DeleteProperty
(
void
* pvObject,
const
StdString& name)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE
(StdBool, DeleteHostObjectNamedProperty, pvObject, name);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::GetPropertyNames
(
void
* pvObject, std::vector<StdString>& names)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetHostObjectPropertyNames, pvObject, names);
}
//
-----------------------------------------------------------------------------
V8Value
HostObjectUtil::GetProperty
(
void
* pvObject,
int32_t
index)
{
V8Value
value
(V8Value::Nonexistent);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetHostObjectIndexedProperty, pvObject, index, value);
return
value;
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::SetProperty
(
void
* pvObject,
int32_t
index,
const
V8Value& value)
{
V8Value::Decoded decodedValue;
value.
Decode
(decodedValue);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(SetHostObjectIndexedProperty, pvObject, index, decodedValue);
}
//
-----------------------------------------------------------------------------
bool
HostObjectUtil::DeleteProperty
(
void
* pvObject,
int32_t
index)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE
(StdBool, DeleteHostObjectIndexedProperty, pvObject, index);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::GetPropertyIndices
(
void
* pvObject, std::vector<
int32_t
>& indices)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetHostObjectPropertyIndices, pvObject, indices);
}
//
-----------------------------------------------------------------------------
V8Value
HostObjectUtil::Invoke
(
void
* pvObject,
bool
asConstructor,
size_t
argCount,
const
V8Value* pArgs)
{
V8Value
result
(V8Value::Nonexistent);
if
(argCount <
1
)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeHostObject, pvObject, asConstructor,
0
,
nullptr
, result);
}
else
if
(argCount <= Constants::MaxInlineArgCount)
{
V8Value::Decoded decodedArgs[argCount];
for
(
size_t
index =
0
; index < argCount; index++)
{
pArgs[index].
Decode
(decodedArgs[index]);
}
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeHostObject, pvObject, asConstructor,
static_cast
<
int32_t
>(argCount), decodedArgs, result);
}
else
{
auto
upDecodedArgs = std::make_unique<V8Value::Decoded[]>(argCount);
auto
pDecodedArgs = upDecodedArgs.
get
();
for
(
size_t
index =
0
; index < argCount; index++)
{
pArgs[index].
Decode
(pDecodedArgs[index]);
}
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeHostObject, pvObject, asConstructor,
static_cast
<
int32_t
>(argCount), pDecodedArgs, result);
}
return
result;
}
//
-----------------------------------------------------------------------------
V8Value
HostObjectUtil::InvokeMethod
(
void
* pvObject,
const
StdString& name,
size_t
argCount,
const
V8Value* pArgs)
{
V8Value
result
(V8Value::Nonexistent);
if
(argCount <
1
)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeHostObjectMethod, pvObject, name,
0
,
nullptr
, result);
}
else
if
(argCount <= Constants::MaxInlineArgCount)
{
V8Value::Decoded decodedArgs[argCount];
for
(
size_t
index =
0
; index < argCount; index++)
{
pArgs[index].
Decode
(decodedArgs[index]);
}
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeHostObjectMethod, pvObject, name,
static_cast
<
int32_t
>(argCount), decodedArgs, result);
}
else
{
auto
upDecodedArgs = std::make_unique<V8Value::Decoded[]>(argCount);
auto
pDecodedArgs = upDecodedArgs.
get
();
for
(
size_t
index =
0
; index < argCount; index++)
{
pArgs[index].
Decode
(pDecodedArgs[index]);
}
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeHostObjectMethod, pvObject, name,
static_cast
<
int32_t
>(argCount), pDecodedArgs, result);
}
return
result;
}
//
-----------------------------------------------------------------------------
V8Value
HostObjectUtil::GetEnumerator
(
void
* pvObject)
{
V8Value
result
(V8Value::Nonexistent);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetHostObjectEnumerator, pvObject, result);
return
result;
}
//
-----------------------------------------------------------------------------
V8Value
HostObjectUtil::GetAsyncEnumerator
(
void
* pvObject)
{
V8Value
result
(V8Value::Nonexistent);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetHostObjectAsyncEnumerator, pvObject, result);
return
result;
}
//
-----------------------------------------------------------------------------
void
*
HostObjectUtil::CreateV8ObjectCache
()
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(
void
*, CreateV8ObjectCache);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::CacheV8Object
(
void
* pvCache,
void
* pvObject,
void
* pvV8Object)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID_NOTHROW
(CacheV8Object, pvCache, pvObject, pvV8Object);
}
//
-----------------------------------------------------------------------------
void
*
HostObjectUtil::GetCachedV8Object
(
void
* pvCache,
void
* pvObject)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(
void
*, GetCachedV8Object, pvCache, pvObject);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::GetAllCachedV8Objects
(
void
* pvCache, std::vector<
void
*>& v8ObjectPtrs)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID_NOTHROW
(GetAllCachedV8Objects, pvCache, v8ObjectPtrs);
}
//
-----------------------------------------------------------------------------
bool
HostObjectUtil::RemoveV8ObjectCacheEntry
(
void
* pvCache,
void
* pvObject)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(StdBool, RemoveV8ObjectCacheEntry, pvCache, pvObject);
}
//
-----------------------------------------------------------------------------
void
*
HostObjectUtil::CreateDebugAgent
(
const
StdString& name,
const
StdString& version,
int32_t
port,
bool
remote, DebugCallback&& callback)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(
void
*, CreateDebugAgent, name, version, port, remote,
new
V8DebugCallbackHandle
(
new
DebugCallback
(
std::move
(callback))));
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::SendDebugMessage
(
void
* pvAgent,
const
StdString& content)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID_NOTHROW
(SendDebugMessage, pvAgent, content);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::DestroyDebugAgent
(
void
* pvAgent)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID_NOTHROW
(DestroyDebugAgent, pvAgent);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::QueueNativeCallback
(NativeCallback&& callback)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID_NOTHROW
(QueueNativeCallback,
new
NativeCallbackHandle
(
new
NativeCallback
(
std::move
(callback))));
}
//
-----------------------------------------------------------------------------
void
*
HostObjectUtil::CreateNativeCallbackTimer
(
int32_t
dueTime,
int32_t
period, NativeCallback&& callback)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(
void
*, CreateNativeCallbackTimer, dueTime, period,
new
NativeCallbackHandle
(
new
NativeCallback
(
std::move
(callback))));
}
//
-----------------------------------------------------------------------------
bool
HostObjectUtil::ChangeNativeCallbackTimer
(
void
* pvTimer,
int32_t
dueTime,
int32_t
period)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(StdBool, ChangeNativeCallbackTimer, pvTimer, dueTime, period);
}
//
-----------------------------------------------------------------------------
void
HostObjectUtil::DestroyNativeCallbackTimer
(
void
* pvTimer)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID_NOTHROW
(DestroyNativeCallbackTimer, pvTimer);
}
//
-----------------------------------------------------------------------------
StdString
HostObjectUtil::LoadModule
(
const
V8DocumentInfo& sourceDocumentInfo,
const
StdString& specifier, V8DocumentInfo& documentInfo, V8Value& exports)
{
StdString resourceName;
StdString sourceMapUrl;
uint64_t
uniqueId;
DocumentKind documentKind;
StdString code;
void
* pvDocumentInfo;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(LoadModule, sourceDocumentInfo.
GetDocumentInfo
(), specifier, resourceName, sourceMapUrl, uniqueId, documentKind, code, pvDocumentInfo, exports);
documentInfo =
V8DocumentInfo
(
std::move
(resourceName),
std::move
(sourceMapUrl), uniqueId, documentKind, pvDocumentInfo);
return
code;
}
//
-----------------------------------------------------------------------------
std::vector<std::pair<StdString, V8Value>>
HostObjectUtil::CreateModuleContext
(
const
V8DocumentInfo& documentInfo)
{
std::vector<StdString> names;
std::vector<V8Value> values;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(CreateModuleContext, documentInfo.
GetDocumentInfo
(), names, values);
auto
count =
std::min
(names.
size
(), values.
size
());
std::vector<std::pair<StdString, V8Value>> context;
context.
reserve
(count);
for
(
size_t
index =
0
; index < count; index++)
{
context.
emplace_back
(names[index], values[index]);
}
return
context;
}
//
-----------------------------------------------------------------------------
size_t
HostObjectUtil::GetMaxScriptCacheSize
()
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(
int32_t
, GetMaxScriptCacheSize);
}
//
-----------------------------------------------------------------------------
size_t
HostObjectUtil::GetMaxModuleCacheSize
()
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE_NOTHROW
(
int32_t
, GetMaxModuleCacheSize);
}
//
-----------------------------------------------------------------------------
//
FastHostObjectUtil implementation
//
-----------------------------------------------------------------------------
V8Value
FastHostObjectUtil::GetProperty
(
void
* pvObject,
const
StdString& name,
bool
& isCacheable)
{
V8Value::FastResult value;
StdBool tempIsCacheable;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetFastHostObjectNamedProperty, pvObject, name, value, tempIsCacheable);
isCacheable = (tempIsCacheable !=
0
);
return
V8Value
(value);
}
//
-----------------------------------------------------------------------------
void
FastHostObjectUtil::SetProperty
(
void
* pvObject,
const
StdString& name,
const
V8Value& value)
{
V8Value::FastArg fastValue;
value.
Decode
(fastValue);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(SetFastHostObjectNamedProperty, pvObject, name, fastValue);
}
//
-----------------------------------------------------------------------------
FastHostObjectUtil::PropertyFlags
FastHostObjectUtil::QueryProperty
(
void
* pvObject,
const
StdString& name)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE
(PropertyFlags, QueryFastHostObjectNamedProperty, pvObject, name);
}
//
-----------------------------------------------------------------------------
bool
FastHostObjectUtil::DeleteProperty
(
void
* pvObject,
const
StdString& name)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE
(StdBool, DeleteFastHostObjectNamedProperty, pvObject, name);
}
//
-----------------------------------------------------------------------------
void
FastHostObjectUtil::GetPropertyNames
(
void
* pvObject, std::vector<StdString>& names)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetFastHostObjectPropertyNames, pvObject, names);
}
//
-----------------------------------------------------------------------------
V8Value
FastHostObjectUtil::GetProperty
(
void
* pvObject,
int32_t
index)
{
V8Value::FastResult value;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetFastHostObjectIndexedProperty, pvObject, index, value);
return
V8Value
(value);
}
//
-----------------------------------------------------------------------------
void
FastHostObjectUtil::SetProperty
(
void
* pvObject,
int32_t
index,
const
V8Value& value)
{
V8Value::FastArg fastValue;
value.
Decode
(fastValue);
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(SetFastHostObjectIndexedProperty, pvObject, index, fastValue);
}
//
-----------------------------------------------------------------------------
FastHostObjectUtil::PropertyFlags
FastHostObjectUtil::QueryProperty
(
void
* pvObject,
int32_t
index)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE
(PropertyFlags, QueryFastHostObjectIndexedProperty, pvObject, index);
}
//
-----------------------------------------------------------------------------
bool
FastHostObjectUtil::DeleteProperty
(
void
* pvObject,
int32_t
index)
{
return
V8_SPLIT_PROXY_MANAGED_INVOKE
(StdBool, DeleteFastHostObjectIndexedProperty, pvObject, index);
}
//
-----------------------------------------------------------------------------
void
FastHostObjectUtil::GetPropertyIndices
(
void
* pvObject, std::vector<
int32_t
>& indices)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetFastHostObjectPropertyIndices, pvObject, indices);
}
//
-----------------------------------------------------------------------------
V8Value
FastHostObjectUtil::Invoke
(
void
* pvObject,
bool
asConstructor,
size_t
argCount,
const
V8Value* pArgs)
{
V8Value::FastResult result;
if
(argCount <
1
)
{
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeFastHostObject, pvObject, asConstructor,
0
,
nullptr
, result);
}
else
if
(argCount <= Constants::MaxInlineArgCount)
{
V8Value::FastArg fastArgs[argCount];
for
(
size_t
index =
0
; index < argCount; index++)
{
pArgs[index].
Decode
(fastArgs[index]);
}
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeFastHostObject, pvObject, asConstructor,
static_cast
<
int32_t
>(argCount), fastArgs, result);
}
else
{
auto
upFastArgs = std::make_unique<V8Value::FastArg[]>(argCount);
auto
pFastArgs = upFastArgs.
get
();
for
(
size_t
index =
0
; index < argCount; index++)
{
pArgs[index].
Decode
(pFastArgs[index]);
}
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(InvokeFastHostObject, pvObject, asConstructor,
static_cast
<
int32_t
>(argCount), pFastArgs, result);
}
return
V8Value
(result);
}
//
-----------------------------------------------------------------------------
V8Value
FastHostObjectUtil::GetEnumerator
(
void
* pvObject)
{
V8Value::FastResult result;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetFastHostObjectEnumerator, pvObject, result);
return
V8Value
(result);
}
//
-----------------------------------------------------------------------------
V8Value
FastHostObjectUtil::GetAsyncEnumerator
(
void
* pvObject)
{
V8Value::FastResult result;
V8_SPLIT_PROXY_MANAGED_INVOKE_VOID
(GetFastHostObjectAsyncEnumerator, pvObject, result);
return
V8Value
(result);
}
Back
|
FazBrowse Home
|
New Git URL