|
@@ -1,4 +1,5 @@
|
|
using System;
|
|
using System;
|
|
|
|
+using System.Globalization;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
using Jint.Native;
|
|
using Jint.Native;
|
|
@@ -13,7 +14,7 @@ namespace Jint.Runtime.Interop
|
|
/// a new <see cref="NamespaceReference"/> as it assumes that the property is a deeper
|
|
/// a new <see cref="NamespaceReference"/> as it assumes that the property is a deeper
|
|
/// level of the current namespace
|
|
/// level of the current namespace
|
|
/// </summary>
|
|
/// </summary>
|
|
- public class NamespaceReference : ObjectInstance
|
|
|
|
|
|
+ public class NamespaceReference : ObjectInstance, ICallable
|
|
{
|
|
{
|
|
private readonly string _path;
|
|
private readonly string _path;
|
|
|
|
|
|
@@ -42,37 +43,69 @@ namespace Jint.Runtime.Interop
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public JsValue Call(JsValue thisObject, JsValue[] arguments)
|
|
|
|
+ {
|
|
|
|
+ // direct calls on a NamespaceReference constructor object is creating a generic type
|
|
|
|
+ var genericTypes = new Type[arguments.Length];
|
|
|
|
+ for (int i = 0; i < arguments.Length; i++)
|
|
|
|
+ {
|
|
|
|
+ var genericTypeReference = arguments.At(i);
|
|
|
|
+ if (genericTypeReference == Undefined.Instance || !genericTypeReference.IsObject() || genericTypeReference.AsObject().Class != "TypeReference")
|
|
|
|
+ {
|
|
|
|
+ throw new JavaScriptException(Engine.TypeError, "Invalid generic type parameter");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ genericTypes[i] = arguments.At(0).As<TypeReference>().Type;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var typeReference = GetPath(_path + "`" + arguments.Length.ToString(CultureInfo.InvariantCulture)).As<TypeReference>();
|
|
|
|
+
|
|
|
|
+ if (typeReference == null)
|
|
|
|
+ {
|
|
|
|
+ return Undefined.Instance;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var genericType = typeReference.Type.MakeGenericType(genericTypes);
|
|
|
|
+
|
|
|
|
+ return TypeReference.CreateTypeReference(Engine, genericType);
|
|
|
|
+ }
|
|
|
|
+
|
|
public override JsValue Get(string propertyName)
|
|
public override JsValue Get(string propertyName)
|
|
{
|
|
{
|
|
var newPath = _path + "." + propertyName;
|
|
var newPath = _path + "." + propertyName;
|
|
|
|
|
|
|
|
+ return GetPath(newPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JsValue GetPath(string path)
|
|
|
|
+ {
|
|
Type type;
|
|
Type type;
|
|
|
|
|
|
- if (Engine.TypeCache.TryGetValue(newPath, out type))
|
|
|
|
|
|
+ if (Engine.TypeCache.TryGetValue(path, out type))
|
|
{
|
|
{
|
|
if (type == null)
|
|
if (type == null)
|
|
{
|
|
{
|
|
- return new NamespaceReference(Engine, newPath);
|
|
|
|
|
|
+ return new NamespaceReference(Engine, path);
|
|
}
|
|
}
|
|
|
|
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
}
|
|
}
|
|
|
|
|
|
// search for type in mscorlib
|
|
// search for type in mscorlib
|
|
- type = Type.GetType(newPath);
|
|
|
|
|
|
+ type = Type.GetType(path);
|
|
if (type != null)
|
|
if (type != null)
|
|
{
|
|
{
|
|
- Engine.TypeCache.Add(newPath, type);
|
|
|
|
|
|
+ Engine.TypeCache.Add(path, type);
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
}
|
|
}
|
|
|
|
|
|
// search in loaded assemblies
|
|
// search in loaded assemblies
|
|
- foreach (var assembly in new [] { Assembly.GetCallingAssembly(), Assembly.GetExecutingAssembly() }.Distinct())
|
|
|
|
|
|
+ foreach (var assembly in new[] { Assembly.GetCallingAssembly(), Assembly.GetExecutingAssembly() }.Distinct())
|
|
{
|
|
{
|
|
- type = assembly.GetType(newPath);
|
|
|
|
|
|
+ type = assembly.GetType(path);
|
|
if (type != null)
|
|
if (type != null)
|
|
{
|
|
{
|
|
- Engine.TypeCache.Add(newPath, type);
|
|
|
|
|
|
+ Engine.TypeCache.Add(path, type);
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -80,18 +113,18 @@ namespace Jint.Runtime.Interop
|
|
// search in lookup asemblies
|
|
// search in lookup asemblies
|
|
foreach (var assembly in Engine.Options.GetLookupAssemblies())
|
|
foreach (var assembly in Engine.Options.GetLookupAssemblies())
|
|
{
|
|
{
|
|
- type = assembly.GetType(newPath);
|
|
|
|
|
|
+ type = assembly.GetType(path);
|
|
if (type != null)
|
|
if (type != null)
|
|
{
|
|
{
|
|
- Engine.TypeCache.Add(newPath, type);
|
|
|
|
|
|
+ Engine.TypeCache.Add(path, type);
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
return TypeReference.CreateTypeReference(Engine, type);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// the new path doesn't represent a known class, thus return a new namespace instance
|
|
// the new path doesn't represent a known class, thus return a new namespace instance
|
|
|
|
|
|
- Engine.TypeCache.Add(newPath, null);
|
|
|
|
- return new NamespaceReference(Engine, newPath);
|
|
|
|
|
|
+ Engine.TypeCache.Add(path, null);
|
|
|
|
+ return new NamespaceReference(Engine, path);
|
|
}
|
|
}
|
|
|
|
|
|
public override PropertyDescriptor GetOwnProperty(string propertyName)
|
|
public override PropertyDescriptor GetOwnProperty(string propertyName)
|