Skip to content

Commit 7fa07eb

Browse files
Added HostItemFlags.DirectAccess.
1 parent 4d6048f commit 7fa07eb

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

ClearScript/HostItemFlags.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ public enum HostItemFlags
9090
/// Specifies that the host resource's dynamic members are not to be exposed. This option
9191
/// applies only to objects that implement <see cref="IDynamicMetaObjectProvider"/>.
9292
/// </summary>
93-
HideDynamicMembers = 0x00000004
93+
HideDynamicMembers = 0x00000004,
94+
95+
/// <summary>
96+
/// Specifies that the script engine is to be given direct access to the exposed object if
97+
/// possible. This option, when supported, suppresses marshaling and hands off the object
98+
/// for script access without the host's involvement. It is currently supported only for
99+
/// COM objects exposed in Windows Script engines.
100+
/// </summary>
101+
DirectAccess = 0x00000008
94102
}
95103
}

ClearScript/Windows/WindowsScriptEngine.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,18 @@ internal override void AddHostItem(string itemName, HostItemFlags flags, object
406406

407407
ScriptInvoke(() =>
408408
{
409-
var marshaledItem = MarshalToScript(item, flags);
410-
if (!(marshaledItem is HostItem))
409+
object marshaledItem;
410+
if (flags.HasFlag(HostItemFlags.DirectAccess) && item.GetType().IsCOMObject)
411411
{
412-
throw new InvalidOperationException("Invalid host item");
412+
marshaledItem = item;
413+
}
414+
else
415+
{
416+
marshaledItem = MarshalToScript(item, flags);
417+
if (!(marshaledItem is HostItem))
418+
{
419+
throw new InvalidOperationException("Invalid host item");
420+
}
413421
}
414422

415423
var oldItem = ((IDictionary)hostItemMap)[itemName];

0 commit comments

Comments
 (0)