-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the
EmbedHostType
method (embeds a host type to script code)
- Loading branch information
Showing
24 changed files
with
1,356 additions
and
689 deletions.
There are no files selected for viewing
456 changes: 397 additions & 59 deletions
456
src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs
Large diffs are not rendered by default.
Oops, something went wrong.
494 changes: 0 additions & 494 deletions
494
src/MsieJavaScriptEngine/ActiveScript/ActiveScriptSiteWrapper.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace MsieJavaScriptEngine.Constants | ||
{ | ||
/// <summary> | ||
/// Special member names | ||
/// </summary> | ||
internal static class SpecialMemberName | ||
{ | ||
public const string Default = "[DISPID=0]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
namespace MsieJavaScriptEngine | ||
{ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
/// <summary> | ||
/// Base class of item, that implements <see cref="IReflect"/> interface | ||
/// </summary> | ||
internal abstract class HostItemBase : IReflect | ||
{ | ||
/// <summary> | ||
/// Target type | ||
/// </summary> | ||
protected readonly Type _type; | ||
|
||
/// <summary> | ||
/// Target object | ||
/// </summary> | ||
protected readonly object _target; | ||
|
||
/// <summary> | ||
/// JavaScript engine mode | ||
/// </summary> | ||
protected readonly JsEngineMode _engineMode; | ||
|
||
/// <summary> | ||
/// List of fields | ||
/// </summary> | ||
private readonly FieldInfo[] _fields; | ||
|
||
/// <summary> | ||
/// List of properties | ||
/// </summary> | ||
private readonly PropertyInfo[] _properties; | ||
|
||
/// <summary> | ||
/// List of methods | ||
/// </summary> | ||
private readonly MethodInfo[] _methods; | ||
|
||
/// <summary> | ||
/// Gets a target object | ||
/// </summary> | ||
public object Target | ||
{ | ||
get { return _target; } | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Constructs an instance of the wrapper for item, that implements <see cref="IReflect"/> interface | ||
/// </summary> | ||
/// <param name="type">Target type</param> | ||
/// <param name="target">Target object</param> | ||
/// <param name="engineMode">JavaScript engine mode</param> | ||
/// <param name="instance">Flag for whether to allow access to members of the instance</param> | ||
protected HostItemBase(Type type, object target, JsEngineMode engineMode, bool instance) | ||
{ | ||
_type = type; | ||
_target = target; | ||
_engineMode = engineMode; | ||
|
||
BindingFlags bindingFlags = BindingFlags.Public; | ||
if (instance) | ||
{ | ||
bindingFlags |= BindingFlags.Instance; | ||
} | ||
else | ||
{ | ||
bindingFlags |= BindingFlags.Static; | ||
} | ||
|
||
_fields = _type.GetFields(bindingFlags); | ||
_properties = _type.GetProperties(bindingFlags); | ||
_methods = _type.GetMethods(bindingFlags); | ||
} | ||
|
||
|
||
protected abstract object InnerInvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, | ||
object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters); | ||
|
||
protected object InvokeStandardMember(string name, BindingFlags invokeAttr, Binder binder, object target, | ||
object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) | ||
{ | ||
BindingFlags processedInvokeAttr = invokeAttr; | ||
if ((processedInvokeAttr.HasFlag(BindingFlags.GetProperty) | ||
|| processedInvokeAttr.HasFlag(BindingFlags.PutDispProperty)) | ||
&& !_properties.Any(p => p.Name == name) | ||
&& _fields.Any(p => p.Name == name)) | ||
{ | ||
if (processedInvokeAttr.HasFlag(BindingFlags.GetProperty)) | ||
{ | ||
processedInvokeAttr &= ~BindingFlags.GetProperty; | ||
processedInvokeAttr |= BindingFlags.GetField; | ||
} | ||
else if (processedInvokeAttr.HasFlag(BindingFlags.PutDispProperty)) | ||
{ | ||
processedInvokeAttr &= ~BindingFlags.PutDispProperty; | ||
processedInvokeAttr |= BindingFlags.SetField; | ||
} | ||
} | ||
|
||
object result = _type.InvokeMember(name, processedInvokeAttr, binder, target, | ||
args, modifiers, culture, namedParameters); | ||
|
||
return result; | ||
} | ||
|
||
#region IReflect implementation | ||
|
||
Type IReflect.UnderlyingSystemType | ||
{ | ||
get { throw new NotImplementedException(); } | ||
} | ||
|
||
|
||
FieldInfo IReflect.GetField(string name, BindingFlags bindingAttr) | ||
{ | ||
FieldInfo field = _fields.SingleOrDefault(f => f.Name == name); | ||
|
||
return field; | ||
} | ||
|
||
FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) | ||
{ | ||
return _fields; | ||
} | ||
|
||
MemberInfo[] IReflect.GetMember(string name, BindingFlags bindingAttr) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
MethodInfo IReflect.GetMethod(string name, BindingFlags bindingAttr) | ||
{ | ||
MethodInfo method = _methods.SingleOrDefault(m => m.Name == name); | ||
|
||
return method; | ||
} | ||
|
||
MethodInfo IReflect.GetMethod(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) | ||
{ | ||
return _methods; | ||
} | ||
|
||
PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) | ||
{ | ||
return _properties; | ||
} | ||
|
||
PropertyInfo IReflect.GetProperty(string name, BindingFlags bindingAttr) | ||
{ | ||
PropertyInfo property = _properties.SingleOrDefault(p => p.Name == name); | ||
|
||
return property; | ||
} | ||
|
||
PropertyInfo IReflect.GetProperty(string name, BindingFlags bindingAttr, Binder binder, | ||
Type returnType, Type[] types, ParameterModifier[] modifiers) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
object IReflect.InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, | ||
object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) | ||
{ | ||
return InnerInvokeMember(name, invokeAttr, binder,target, args, modifiers, culture, namedParameters); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.