internal void AddMember(ScriptProcessor processor, PrototypeMember member) { if (_prototypeMembers.ContainsKey(member.Identifier)) { processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassDuplicateDefinition, member.Identifier, Name); } _prototypeMembers.Add(member.Identifier, member); }
// TODO: C# 7: put proper Tuple handling in place. private static Tuple <PrototypeMember, string> ParseVarStatement(ScriptProcessor processor, ScriptStatement statement) { var code = statement.Code; var signature = code.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var assignment = ""; var isReadOnly = false; var isStatic = false; // Read static: if (signature.Contains(VarSignatureStatic)) { isStatic = true; signature.Remove(VarSignatureStatic); } // Read readonly: if (signature.Contains(VarSignatureReadonly)) { isReadOnly = true; signature.Remove(VarSignatureReadonly); } if (signature[0] != "var" || signature.Count < 2) { processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassInvalidVarDeclaration); } var identifier = signature[1]; if (!ScriptProcessor.IsValidIdentifier(identifier)) { processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxMissingVarName); } if (signature.Count > 2) { if (signature[2].StartsWith("=")) { assignment = code.Remove(0, code.IndexOf("=", StringComparison.Ordinal) + 1).Trim(); } else { processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MessageSyntaxClassInvalidVarDeclaration); } } var member = new PrototypeMember(identifier, processor.Undefined, isStatic, isReadOnly, false, false); return(new Tuple <PrototypeMember, string>(member, assignment)); }
public ArrayPrototype() : base("Array") { Constructor = new PrototypeMember("Constructor", new SFunction(ConstructorImpl)); }
public StringPrototype() : base("String") { Constructor = new PrototypeMember("constructor", new SFunction(ConstructorImpl)); }