public override PropertyDescriptor GetOwnProperty(JsValue property) { if (property.IsSymbol()) { return(PropertyDescriptor.Undefined); } if (TryGetProperty(property, out var x)) { return(x); } var type = Target.GetType(); var key = new Engine.ClrPropertyDescriptorFactoriesKey(type, property.ToString()); if (!_engine.ClrPropertyDescriptorFactories.TryGetValue(key, out var factory)) { factory = ResolveProperty(type, property.ToString()); _engine.ClrPropertyDescriptorFactories[key] = factory; } var descriptor = factory(_engine, Target); AddProperty(property, descriptor); return(descriptor); }
private JsValue ToSymbolString(JsValue thisObject, JsValue[] arguments) { if (!thisObject.IsSymbol()) { ExceptionHelper.ThrowTypeError(Engine); } return(SymbolDescriptiveString((JsSymbol)thisObject)); }
public override PropertyDescriptor GetOwnProperty(JsValue property) { if (TryGetProperty(property, out var x)) { return(x); } // if we have array-like or dictionary or expando, we can provide iterator if (property.IsSymbol() && property == GlobalSymbolRegistry.Iterator && _typeDescriptor.Iterable) { var iteratorFunction = new ClrFunctionInstance( Engine, "iterator", Iterator, 1, PropertyFlag.Configurable); var iteratorProperty = new PropertyDescriptor(iteratorFunction, PropertyFlag.Configurable | PropertyFlag.Writable); SetProperty(GlobalSymbolRegistry.Iterator, iteratorProperty); return(iteratorProperty); } var member = property.ToString(); // if type is dictionary, we cannot enumerate anything other than keys // and we cannot store accessors as dictionary can change dynamically var isDictionary = _typeDescriptor.IsStringKeyedGenericDictionary; if (isDictionary) { if (_typeDescriptor.TryGetValue(Target, member, out var value)) { return(new PropertyDescriptor(FromObject(_engine, value), PropertyFlag.OnlyEnumerable)); } } var result = Engine.Options.Interop.MemberAccessor(Engine, Target, member); if (result is not null) { return(new PropertyDescriptor(result, PropertyFlag.OnlyEnumerable)); } var accessor = _engine.Options.Interop.TypeResolver.GetAccessor(_engine, Target.GetType(), member); var descriptor = accessor.CreatePropertyDescriptor(_engine, Target, enumerable: !isDictionary); if (!isDictionary) { SetProperty(member, descriptor); } return(descriptor); }
private JsValue ToPrimitive(JsValue thisObject, JsValue[] arguments) { if (thisObject.IsSymbol()) { return(thisObject); } // Steps 3. and 4. var o = thisObject.AsInstance <SymbolInstance>(); if (ReferenceEquals(o, null)) { ExceptionHelper.ThrowTypeError(Engine); } return(o.SymbolData); }