/// <summary> /// Creates an instance derived from this prototype. /// </summary> internal SProtoObject CreateInstance(ScriptProcessor processor, SObject[] parameters, bool executeCtor) { SProtoObject obj = CreateBaseObject(); obj.IsProtoInstance = true; obj.AddMember(MEMBER_NAME_PROTOTYPE, this); if (typeof(ObjectPrototype) != GetType()) { // If no extends class is explicitly specified, "Object" is assumed. if (Extends == null) { Extends = processor.Context.GetPrototype("Object"); } var superInstance = Extends.CreateInstance(processor, null, true); obj.AddMember(MEMBER_NAME_SUPER, superInstance); } foreach (var member in GetInstanceMembers()) { obj.AddMember(member.Identifier, member.Data); } var indexerGetFunction = GetIndexerGetFunction(); if (indexerGetFunction != null) { obj.IndexerGetFunction = indexerGetFunction; } var indexerSetFunction = GetIndexerSetFunction(); if (indexerSetFunction != null) { obj.IndexerSetFunction = indexerSetFunction; } if (executeCtor) { Constructor?.ToFunction().Call(processor, obj, obj, parameters); } // Lock all readonly members after the constructor call, so they can be set in the constructor: foreach (PrototypeMember member in GetReadOnlyInstanceMembers()) { obj.Members[member.Identifier].IsReadOnly = true; } return(obj); }
private static SObject TranslateExpandoObject(ScriptProcessor processor, ExpandoObject objIn) { var obj = new SProtoObject(); foreach (var member in objIn) { obj.AddMember(member.Key, Translate(processor, member.Value)); } return(obj); }