private ReflectedNativeObjectPrototype(ISharedObjectContainer container, Type type, bool defaultHideMembers) : base(WellKnownObject.ObjectPrototype) { PropertyInfo[] properties = type.GetProperties(); bool showAttributedOnly = defaultHideMembers || properties.Any(v => v.HasAttribute(out IntrinsicMemberAttribute _)); foreach (PropertyInfo property in properties) { IntrinsicMemberAttribute attribute; property.HasAttribute(out attribute); if (!showAttributedOnly || attribute != null) { string propertyName = attribute != null ? attribute.Name : property.Name; DefineOwnPropertyNoChecked(propertyName, new EcmaPropertyDescriptor( property.GetGetMethod() != null ? container.Add(new NativeRuntimeFunction(propertyName, property.GetGetMethod())).ToValue() : EcmaValue.Undefined, property.GetSetMethod() != null ? container.Add(new NativeRuntimeFunction(propertyName, property.GetSetMethod())).ToValue() : EcmaValue.Undefined, EcmaPropertyAttributes.DefaultDataProperty)); } } foreach (MethodInfo method in type.GetMethods()) { if (method.HasAttribute(out IntrinsicMemberAttribute attribute)) { string methodName = attribute.Name ?? method.Name; DefineOwnPropertyNoChecked(methodName, new EcmaPropertyDescriptor(container.Add(new NativeRuntimeFunction(methodName, method)).ToValue(), EcmaPropertyAttributes.DefaultMethodProperty)); } } DefineOwnPropertyNoChecked(WellKnownProperty.Constructor, new EcmaPropertyDescriptor(container.Add(new Constructor(type.Name)).ToValue(), EcmaPropertyAttributes.Configurable | EcmaPropertyAttributes.Writable)); }
internal void Init(RuntimeRealm.SharedObjectContainer container, RuntimeObject[] moduleObjects) { this.Container = container; this.Realm = RuntimeRealm.SharedRealm; this.runtimeObjects = moduleObjects; this.objectCount = moduleObjects.Length; this.properties = new Dictionary <EcmaPropertyKey, EcmaPropertyDescriptor> [objectCount]; for (int i = 0; i < objectCount; i++) { properties[i] = new Dictionary <EcmaPropertyKey, EcmaPropertyDescriptor>(); } OnBeforeInitializing(moduleObjects); DefineIntrinsicObjectsFromAssembly(this.GetType().Assembly); for (int i = 0; i < objectCount; i++) { DefineAllProperties(EnsureObject(i), properties[i]); } DefineAllProperties(this.Realm.GetRuntimeObject(WellKnownObject.Global), globals); this.runtimeObjects = container.FlushObjects(); OnAfterInitializing(new ReadOnlyCollection <RuntimeObject>(runtimeObjects)); }