public TypeSymbol GetAssignedType(ITypeManager typeManager, ArraySyntax?allowedSyntax) { var assignedType = this.GetDeclaredType(); // TODO: remove SyntaxHelper.TryGetAllowedSyntax when we drop parameter modifiers support. if (allowedSyntax is not null && !allowedSyntax.Items.Any()) { return(ErrorType.Create(DiagnosticBuilder.ForPosition(allowedSyntax).AllowedMustContainItems())); } var allowedItemTypes = allowedSyntax?.Items.Select(typeManager.GetTypeInfo); if (ReferenceEquals(assignedType, LanguageConstants.String)) { if (allowedItemTypes?.All(itemType => itemType is StringLiteralType) == true) { assignedType = UnionType.Create(allowedItemTypes); } else { // In order to support assignment for a generic string to enum-typed properties (which generally is forbidden), // we need to relax the validation for string parameters without 'allowed' values specified. assignedType = LanguageConstants.LooseString; } } if (ReferenceEquals(assignedType, LanguageConstants.Array) && allowedItemTypes?.All(itemType => itemType is StringLiteralType) == true) { assignedType = new TypedArrayType(UnionType.Create(allowedItemTypes), TypeSymbolValidationFlags.Default); } return(assignedType); }
// INITIALIZATION //_________________________________________________________________________________________ /// <summary> /// Creates a new typed array instance. /// </summary> /// <param name="prototype"> The next object in the prototype chain. </param> /// <param name="type"> Defines the element type and behaviour of the typed array. </param> /// <param name="buffer"> An existing ArrayBuffer to use as the storage for the new /// TypedArray object. </param> /// <param name="byteOffset"> The offset, in bytes, to the first byte in the specified /// buffer for the new view to reference. If not specified, the TypedArray will start /// with the first byte. </param> /// <param name="length"> The length (in elements) of the typed array. </param> internal TypedArrayInstance(ObjectInstance prototype, TypedArrayType type, ArrayBufferInstance buffer, int byteOffset, int length) : base(prototype) { this.type = type; this.buffer = buffer; this.byteOffset = byteOffset; this.length = length; }
// INITIALIZATION //_________________________________________________________________________________________ /// <summary> /// Creates a new typed array constructor. /// </summary> /// <param name="prototype"> The next object in the prototype chain. </param> /// <param name="type"> Defines the element type and behaviour of the typed array. </param> internal TypedArrayConstructor(ObjectInstance prototype, TypedArrayType type) : base(prototype, __STUB__Construct, __STUB__Call) { this.type = type; // Initialize the constructor properties. var properties = GetDeclarativeProperties(Engine); InitializeConstructorProperties(properties, type.ToString(), 3, TypedArrayInstance.CreatePrototype(Engine, this)); properties.Add(new PropertyNameAndValue("BYTES_PER_ELEMENT", BytesPerElement, PropertyAttributes.Sealed)); FastSetProperties(properties); }
public static IEnumerable <TypeProperty> CreateResourceProperties(ResourceTypeReference resourceTypeReference) { /* * The following properties are intentionally excluded from this model: * - SystemData - this is a read-only property that doesn't belong on PUTs * - id - that is not allowed in templates * - type - included in resource type on resource declarations * - apiVersion - included in resource type on resource declarations */ yield return(new TypeProperty("id", String, TypePropertyFlags.ReadOnly | TypePropertyFlags.SkipInlining)); yield return(new TypeProperty("name", String, TypePropertyFlags.Required | TypePropertyFlags.SkipInlining)); yield return(new TypeProperty("type", new StringLiteralType(resourceTypeReference.FullyQualifiedType), TypePropertyFlags.ReadOnly | TypePropertyFlags.SkipInlining)); yield return(new TypeProperty("apiVersion", new StringLiteralType(resourceTypeReference.ApiVersion), TypePropertyFlags.ReadOnly | TypePropertyFlags.SkipInlining)); // TODO: Model type fully yield return(new TypeProperty("sku", Object)); yield return(new TypeProperty("kind", String)); yield return(new TypeProperty("managedBy", String)); var stringArray = new TypedArrayType(String); yield return(new TypeProperty("managedByExtended", stringArray)); yield return(new TypeProperty("location", String)); // TODO: Model type fully yield return(new TypeProperty("extendedLocation", Object)); yield return(new TypeProperty("zones", stringArray)); yield return(new TypeProperty("plan", Object)); yield return(new TypeProperty("eTag", String)); yield return(new TypeProperty("tags", Tags)); // TODO: Model type fully yield return(new TypeProperty("scale", Object)); // TODO: Model type fully yield return(new TypeProperty("identity", Object)); yield return(new TypeProperty("properties", Object)); var resourceRefArray = new TypedArrayType(ResourceRef); yield return(new TypeProperty("dependsOn", resourceRefArray, TypePropertyFlags.WriteOnly)); }
// INITIALIZATION //_________________________________________________________________________________________ /// <summary> /// Creates a new typed array constructor. /// </summary> /// <param name="prototype"> The next object in the prototype chain. </param> /// <param name="type"> Defines the element type and behaviour of the typed array. </param> internal TypedArrayConstructor(ObjectInstance prototype, TypedArrayType type) : base(prototype, __STUB__Construct, __STUB__Call) { this.type = type; // Initialize the constructor properties. var properties = GetDeclarativeProperties(Engine); InitializeConstructorProperties(properties, type.ToString(), 3, TypedArrayInstance.CreatePrototype(Engine, this)); properties.Add(new PropertyNameAndValue("BYTES_PER_ELEMENT", BytesPerElement, PropertyAttributes.Sealed)); FastSetProperties(properties); }
public static IEnumerable <TypeProperty> CreateResourceProperties(ResourceTypeReference resourceTypeReference) { /* * The following properties are intentionally excluded from this model: * - SystemData - this is a read-only property that doesn't belong on PUTs * - id - that is not allowed in templates * - type - included in resource type on resource declarations * - apiVersion - included in resource type on resource declarations */ foreach (var prop in GetCommonResourceProperties(resourceTypeReference)) { yield return(prop); } // TODO: Model type fully yield return(new TypeProperty("sku", Object)); yield return(new TypeProperty("kind", String)); yield return(new TypeProperty("managedBy", String)); var stringArray = new TypedArrayType(String, TypeSymbolValidationFlags.Default); yield return(new TypeProperty("managedByExtended", stringArray)); yield return(new TypeProperty("location", String)); // TODO: Model type fully yield return(new TypeProperty("extendedLocation", Object)); yield return(new TypeProperty("zones", stringArray)); yield return(new TypeProperty("plan", Object)); yield return(new TypeProperty("eTag", String)); yield return(new TypeProperty("tags", Tags)); // TODO: Model type fully yield return(new TypeProperty("scale", Object)); // TODO: Model type fully yield return(new TypeProperty("identity", Object)); yield return(new TypeProperty("properties", Object)); var resourceRefArray = new TypedArrayType(ResourceRef, TypeSymbolValidationFlags.Default); yield return(new TypeProperty("dependsOn", resourceRefArray, TypePropertyFlags.WriteOnly)); }