public override Value Evaluate() { var current = Regions.Current; current.CreateAndSet(data.Name, data); foreach (var(key, i) in data.Constructors) { Value value; if (i == 0) { value = new Constructor(data.Name, key, new Value[0]); } else { value = new ConstructorProxy(data.Name, key); } if (!current.ContainsMessage(key)) { current.CreateAndSet(key, value); } } return(null); }
private static void AddToProxy(this ConstructorInfo[] constructors, WrapperObject target, IDictionary <String, BaseProxy> proxies, INameSelector selector) { if (constructors.Length > 0) { var name = selector.Select(proxies.Keys, constructors[0]); proxies[name] = new ConstructorProxy(target, constructors); } }
public JSObject GetConstructor(Type type) { JSObject constructor = null; if (!_proxies.TryGetValue(type, out constructor)) { lock (_proxies) { JSObject dynamicProxy = null; if (type.GetTypeInfo().ContainsGenericParameters) { constructor = GetGenericTypeSelector(new[] { type }); } else { var indexerSupport = IndexersSupport == IndexersSupport.ForceEnable || (IndexersSupport == IndexersSupport.WithAttributeOnly && type.GetTypeInfo().IsDefined(typeof(UseIndexersAttribute), false)); var staticProxy = new StaticProxy(this, type, indexerSupport); if (type.GetTypeInfo().IsAbstract) { _proxies[type] = staticProxy; return(staticProxy); } JSObject parentPrototype = null; var pa = type.GetTypeInfo().GetCustomAttributes(typeof(PrototypeAttribute), true).ToArray(); if (pa.Length != 0 && (pa[0] as PrototypeAttribute).PrototypeType != type) { var parentType = (pa[0] as PrototypeAttribute).PrototypeType; parentPrototype = (GetConstructor(parentType) as Function).prototype as JSObject; if ((pa[0] as PrototypeAttribute).Replace && parentType.IsAssignableFrom(type)) { dynamicProxy = parentPrototype; } else { dynamicProxy = new PrototypeProxy(this, type, indexerSupport) { _objectPrototype = parentPrototype }; } } else { dynamicProxy = new PrototypeProxy(this, type, indexerSupport); } if (type == typeof(JSObject)) { constructor = new ObjectConstructor(this, staticProxy, dynamicProxy); } else { constructor = new ConstructorProxy(this, staticProxy, dynamicProxy); } if (type.GetTypeInfo().IsDefined(typeof(ImmutableAttribute), false)) { dynamicProxy._attributes |= JSValueAttributesInternal.Immutable; } constructor._attributes = dynamicProxy._attributes; dynamicProxy._attributes |= JSValueAttributesInternal.DoNotDelete | JSValueAttributesInternal.DoNotEnumerate | JSValueAttributesInternal.NonConfigurable | JSValueAttributesInternal.ReadOnly; if (dynamicProxy != parentPrototype && type != typeof(ConstructorProxy)) { dynamicProxy._fields["constructor"] = constructor; } } _proxies[type] = constructor; if (dynamicProxy != null && typeof(JSValue).IsAssignableFrom(type)) { if (dynamicProxy._objectPrototype == null) { dynamicProxy._objectPrototype = _globalPrototype ?? JSValue.@null; } var fake = (dynamicProxy as PrototypeProxy).PrototypeInstance; } } } return(constructor); }