Jurassic.Library.ObjectInstance.AddProperty C# (CSharp) Method

AddProperty() private method

Adds a property to this object. The property must not already exist.
private AddProperty ( object key, object value, PropertyAttributes attributes, bool throwOnError ) : bool
key object The property key of the property to add.
value object The desired value of the property. This can be a /// .
attributes PropertyAttributes Attributes describing how the property may be modified.
throwOnError bool true to throw an exception if the property could not /// be added (i.e. if the object is not extensible).
return bool
        private bool AddProperty(object key, object value, PropertyAttributes attributes, bool throwOnError)
        {
            // Make sure adding a property is allowed.
            if (this.IsExtensible == false)
            {
                if (throwOnError == true)
                    throw new JavaScriptException(this.Engine, ErrorType.TypeError, string.Format("The property '{0}' cannot be created as the object is not extensible.", key));
                return false;
            }

            // To avoid running out of memory, restrict the number of properties.
            if (this.schema.PropertyCount == 16384)
                throw new JavaScriptException(this.engine, ErrorType.Error, "Maximum number of named properties reached.");

            // Do not store nulls - null represents a non-existant value.
            value = value ?? Undefined.Value;

            // Add a new property to the schema.
            this.schema = this.schema.AddProperty(key, attributes);

            // Check if the value array needs to be resized.
            int propertyIndex = this.schema.NextValueIndex - 1;
            if (propertyIndex >= this.InlinePropertyValues.Length)
                Array.Resize(ref this.propertyValues, this.InlinePropertyValues.Length * 2);

            // Set the value of the property.
            this.propertyValues[propertyIndex] = value;

            // Success.
            return true;
        }