Пример #1
0
 private static bool IsValidReference(object value, out SharedObjectHandle handle)
 {
     if (value is Enum p1)
     {
         handle = RuntimeRealm.GetSharedObjectHandle(p1);
         return(true);
     }
     handle = default;
     return(false);
 }
Пример #2
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);
        }