Changeset 229608 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Mar 14, 2018, 1:00:21 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r229162 r229608 2796 2796 2797 2797 TreeExpression constructor = 0; 2798 TreePropertyList staticMethods = 0; 2799 TreePropertyList instanceMethods = 0; 2800 TreePropertyList instanceMethodsTail = 0; 2801 TreePropertyList staticMethodsTail = 0; 2798 TreePropertyList classElements = 0; 2799 TreePropertyList classElementsTail = 0; 2802 2800 while (!match(CLOSEBRACE)) { 2803 2801 if (match(SEMICOLON)) { … … 2810 2808 2811 2809 // For backwards compatibility, "static" is a non-reserved keyword in non-strict mode. 2812 bool isStaticMethod = false;2810 ClassElementTag tag = ClassElementTag::Instance; 2813 2811 if (match(RESERVED_IF_STRICT) && *m_token.m_data.ident == m_vm->propertyNames->staticKeyword) { 2814 2812 SavePoint savePoint = createSavePoint(); … … 2818 2816 restoreSavePoint(savePoint); 2819 2817 } else 2820 isStaticMethod = true;2818 tag = ClassElementTag::Static; 2821 2819 } 2822 2820 … … 2884 2882 const bool alwaysStrictInsideClass = true; 2885 2883 if (isGetter || isSetter) { 2886 bool isClassProperty = true;2887 2884 property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, 2888 methodStart, ConstructorKind::None, isClassProperty, isStaticMethod);2885 methodStart, ConstructorKind::None, tag); 2889 2886 failIfFalse(property, "Cannot parse this method"); 2890 2887 } else { 2891 2888 ParserFunctionInfo<TreeBuilder> methodInfo; 2892 bool isConstructor = !isStaticMethod&& *ident == propertyNames.constructor;2889 bool isConstructor = tag == ClassElementTag::Instance && *ident == propertyNames.constructor; 2893 2890 if (isAsyncMethodParseMode(parseMode) || isAsyncGeneratorMethodParseMode(parseMode) || isGeneratorMethodParseMode(parseMode)) { 2894 2891 isConstructor = false; … … 2908 2905 2909 2906 // FIXME: Syntax error when super() is called 2910 semanticFailIfTrue( isStaticMethod&& methodInfo.name && *methodInfo.name == propertyNames.prototype,2907 semanticFailIfTrue(tag == ClassElementTag::Static && methodInfo.name && *methodInfo.name == propertyNames.prototype, 2911 2908 "Cannot declare a static method named 'prototype'"); 2912 2909 2913 bool isClassProperty = true;2914 2910 if (computedPropertyName) { 2915 2911 property = context.createProperty(computedPropertyName, method, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), 2916 PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed, isClassProperty);2912 PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed, tag); 2917 2913 } else { 2918 2914 property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, 2919 PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed, InferName::Allowed, isClassProperty);2915 PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed, InferName::Allowed, tag); 2920 2916 } 2921 2917 } 2922 2918 2923 TreePropertyList& tail = isStaticMethod ? staticMethodsTail : instanceMethodsTail; 2924 if (tail) 2925 tail = context.createPropertyList(methodLocation, property, tail); 2926 else { 2927 tail = context.createPropertyList(methodLocation, property); 2928 if (isStaticMethod) 2929 staticMethods = tail; 2930 else 2931 instanceMethods = tail; 2932 } 2919 if (classElementsTail) 2920 classElementsTail = context.createPropertyList(methodLocation, property, classElementsTail); 2921 else 2922 classElements = classElementsTail = context.createPropertyList(methodLocation, property); 2933 2923 } 2934 2924 … … 2936 2926 consumeOrFail(CLOSEBRACE, "Expected a closing '}' after a class body"); 2937 2927 2938 auto classExpression = context.createClassExpr(location, info, classScope->finalizeLexicalEnvironment(), constructor, parentClass, instanceMethods, staticMethods);2928 auto classExpression = context.createClassExpr(location, info, classScope->finalizeLexicalEnvironment(), constructor, parentClass, classElements); 2939 2929 popScope(classScope, TreeBuilder::NeedsFreeVariableInfo); 2940 2930 return classExpression; … … 3899 3889 SourceParseMode parseMode = SourceParseMode::MethodMode; 3900 3890 bool wasIdent = false; 3901 bool isClassProperty = false;3902 bool isStaticMethod = false;3903 3891 3904 3892 if (consume(TIMES)) … … 3949 3937 context.setEndOffset(node, m_lexer->currentOffset()); 3950 3938 InferName inferName = ident && *ident == m_vm->propertyNames->underscoreProto ? InferName::Disallowed : InferName::Allowed; 3951 return context.createProperty(ident, node, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, inferName, isClassProperty);3939 return context.createProperty(ident, node, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, inferName, ClassElementTag::No); 3952 3940 } 3953 3941 … … 3955 3943 auto method = parsePropertyMethod(context, ident, parseMode); 3956 3944 propagateError(); 3957 return context.createProperty(ident, method, PropertyNode::Constant, PropertyNode::KnownDirect, complete, SuperBinding::Needed, InferName::Allowed, isClassProperty);3945 return context.createProperty(ident, method, PropertyNode::Constant, PropertyNode::KnownDirect, complete, SuperBinding::Needed, InferName::Allowed, ClassElementTag::No); 3958 3946 } 3959 3947 failIfTrue(parseMode != SourceParseMode::MethodMode, "Expected a parenthesis for argument list"); … … 3969 3957 currentScope()->setInnerArrowFunctionUsesEval(); 3970 3958 TreeExpression node = context.createResolve(location, *ident, start, lastTokenEndPosition()); 3971 return context.createProperty(ident, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Shorthand), PropertyNode::KnownDirect, complete, SuperBinding::NotNeeded, InferName::Allowed, isClassProperty);3959 return context.createProperty(ident, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Shorthand), PropertyNode::KnownDirect, complete, SuperBinding::NotNeeded, InferName::Allowed, ClassElementTag::No); 3972 3960 } 3973 3961 … … 3982 3970 else 3983 3971 failWithMessage("Expected a ':' following the property name '", ident->impl(), "'"); 3984 return parseGetterSetter(context, complete, type, getterOrSetterStartOffset, ConstructorKind::None, isClassProperty, isStaticMethod);3972 return parseGetterSetter(context, complete, type, getterOrSetterStartOffset, ConstructorKind::None, ClassElementTag::No); 3985 3973 } 3986 3974 case DOUBLE: … … 3993 3981 auto method = parsePropertyMethod(context, &ident, parseMode); 3994 3982 propagateError(); 3995 return context.createProperty(&ident, method, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::Needed, InferName::Allowed, isClassProperty);3983 return context.createProperty(&ident, method, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::Needed, InferName::Allowed, ClassElementTag::No); 3996 3984 } 3997 3985 failIfTrue(parseMode != SourceParseMode::MethodMode, "Expected a parenthesis for argument list"); … … 4001 3989 failIfFalse(node, "Cannot parse expression for property declaration"); 4002 3990 context.setEndOffset(node, m_lexer->currentOffset()); 4003 return context.createProperty(const_cast<VM*>(m_vm), m_parserArena, propertyName, node, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, isClassProperty);3991 return context.createProperty(const_cast<VM*>(m_vm), m_parserArena, propertyName, node, PropertyNode::Constant, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, ClassElementTag::No); 4004 3992 } 4005 3993 case OPENBRACKET: { … … 4012 4000 auto method = parsePropertyMethod(context, &m_vm->propertyNames->nullIdentifier, parseMode); 4013 4001 propagateError(); 4014 return context.createProperty(propertyName, method, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::KnownDirect, complete, SuperBinding::Needed, isClassProperty);4002 return context.createProperty(propertyName, method, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::KnownDirect, complete, SuperBinding::Needed, ClassElementTag::No); 4015 4003 } 4016 4004 failIfTrue(parseMode != SourceParseMode::MethodMode, "Expected a parenthesis for argument list"); … … 4020 4008 failIfFalse(node, "Cannot parse expression for property declaration"); 4021 4009 context.setEndOffset(node, m_lexer->currentOffset()); 4022 return context.createProperty(propertyName, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::Unknown, complete, SuperBinding::NotNeeded, isClassProperty);4010 return context.createProperty(propertyName, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Computed), PropertyNode::Unknown, complete, SuperBinding::NotNeeded, ClassElementTag::No); 4023 4011 } 4024 4012 case DOTDOTDOT: { … … 4031 4019 failIfFalse(elem, "Cannot parse subject of a spread operation"); 4032 4020 auto node = context.createObjectSpreadExpression(spreadLocation, elem, start, divot, m_lastTokenEndPosition); 4033 return context.createProperty(node, PropertyNode::Spread, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, isClassProperty);4021 return context.createProperty(node, PropertyNode::Spread, PropertyNode::Unknown, complete, SuperBinding::NotNeeded, ClassElementTag::No); 4034 4022 } 4035 4023 FALLTHROUGH; … … 4056 4044 template <typename LexerType> 4057 4045 template <class TreeBuilder> TreeProperty Parser<LexerType>::parseGetterSetter(TreeBuilder& context, bool strict, PropertyNode::Type type, unsigned getterOrSetterStartOffset, 4058 ConstructorKind constructorKind, bool isClassProperty, bool isStaticMethod)4046 ConstructorKind constructorKind, ClassElementTag tag) 4059 4047 { 4060 4048 const Identifier* stringPropertyName = 0; … … 4066 4054 if (matchSpecIdentifier() || match(STRING) || m_token.m_type & KeywordTokenFlag) { 4067 4055 stringPropertyName = m_token.m_data.ident; 4068 semanticFailIfTrue( isClassProperty && isStaticMethod&& *stringPropertyName == m_vm->propertyNames->prototype,4056 semanticFailIfTrue(tag == ClassElementTag::Static && *stringPropertyName == m_vm->propertyNames->prototype, 4069 4057 "Cannot declare a static method named 'prototype'"); 4070 semanticFailIfTrue( isClassProperty && !isStaticMethod&& *stringPropertyName == m_vm->propertyNames->constructor,4058 semanticFailIfTrue(tag == ClassElementTag::Instance && *stringPropertyName == m_vm->propertyNames->constructor, 4071 4059 "Cannot declare a getter or setter named 'constructor'"); 4072 4060 next(); … … 4092 4080 4093 4081 if (stringPropertyName) 4094 return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, isClassProperty);4082 return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, tag); 4095 4083 4096 4084 if (computedPropertyName) 4097 return context.createGetterOrSetterProperty(location, static_cast<PropertyNode::Type>(type | PropertyNode::Computed), strict, computedPropertyName, info, isClassProperty);4098 4099 return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, strict, numericPropertyName, info, isClassProperty);4085 return context.createGetterOrSetterProperty(location, static_cast<PropertyNode::Type>(type | PropertyNode::Computed), strict, computedPropertyName, info, tag); 4086 4087 return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, strict, numericPropertyName, info, tag); 4100 4088 } 4101 4089
Note:
See TracChangeset
for help on using the changeset viewer.