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;
}