Beispiel #1
0
        public NativeRuntimeFunction(string name, MethodInfo method, bool containUseStrict, WellKnownObject proto)
            : base(proto)
        {
            Guard.ArgumentNotNull(method, "method");
            this.method = method;

            Type runtimeObjectType = null;

            if (method.HasAttribute(out IntrinsicConstructorAttribute attribute))
            {
                constraint        = attribute.Constraint;
                containUseStrict  = true;
                runtimeObjectType = attribute.ObjectType;
                if (attribute.Prototype is Enum protoEnum)
                {
                    defaultProto = RuntimeRealm.GetSharedObjectHandle(protoEnum);
                }
            }
            else if (method.HasAttribute(out IntrinsicMemberAttribute a2))
            {
                constraint       = NativeRuntimeFunctionConstraint.DenyConstruct;
                containUseStrict = true;
                if (name == null)
                {
                    name = a2.Name;
                }
            }
            else
            {
                SetPrototypeInternal(new EcmaObject());
            }
            if (name == null)
            {
                name = "";
            }
            this.Source = "function " + name + "() { [native code] }";
            InitProperty(name, GetFuncLength(method), containUseStrict);
            constructThisValue = runtimeObjectType == null || runtimeObjectType == typeof(EcmaObject) ? createFromConstructorDefault : createFromConstructor.MakeGenericMethod(runtimeObjectType);
        }
Beispiel #2
0
 public IntrinsicConstructorAttribute(NativeRuntimeFunctionConstraint constraint)
     : this()
 {
     this.Constraint = constraint;
 }