public override JsInstance this[string index]
{
get {
if (index == THIS && thisDescriptor != null)
return thisDescriptor.Get(this);
if (index == ARGUMENTS && argumentsDescriptor != null)
return argumentsDescriptor.Get(this);
return base[index]; // will use overriden GetDescriptor
}
set {
if (index == THIS) {
if (thisDescriptor != null)
thisDescriptor.Set(this, value);
else {
DefineOwnProperty(index, thisDescriptor = new ValueDescriptor(this, index, value));
}
}
else if (index == ARGUMENTS) {
if (argumentsDescriptor != null)
argumentsDescriptor.Set(this, value);
else {
DefineOwnProperty(index, argumentsDescriptor = new ValueDescriptor(this, index, value));
}
}
else {
Descriptor d = GetDescriptor(index);
if (d != null) {
// we have a property in the scopes hierarchy or in the bag
if (d.Owner == bag || d.Owner == this || d.Owner.IsPrototypeOf(this)) {
// if this is an own property of the bag or in scopes
d.Set(d.Owner, value);
}
else {
// this property should be from one of prototypes of the bag
if (bag != null)
bag[index] = value;
}
}
else if (globalScope != null) {
// define missing property in the global scope
globalScope.DefineOwnProperty(index, value);
}
else {
// this scope is a global scope
DefineOwnProperty(index, value);
}
}
}
}