|
Lines 1489-1497
template <class TreeBuilder> TreeClassExpression Parser<LexerType>::parseClass(T
a/Source/JavaScriptCore/parser/Parser.cpp_sec1
|
| 1489 |
consumeOrFailWithFlags(OPENBRACE, TreeBuilder::DontBuildStrings, "Expected opening '{' at the start of a class body"); |
1489 |
consumeOrFailWithFlags(OPENBRACE, TreeBuilder::DontBuildStrings, "Expected opening '{' at the start of a class body"); |
| 1490 |
|
1490 |
|
| 1491 |
TreeExpression constructor = 0; |
1491 |
TreeExpression constructor = 0; |
| 1492 |
TreePropertyList staticMethods = 0; |
|
|
| 1493 |
TreePropertyList instanceMethods = 0; |
1492 |
TreePropertyList instanceMethods = 0; |
| 1494 |
TreePropertyList instanceMethodsTail = 0; |
1493 |
TreePropertyList instanceMethodsTail = 0; |
|
|
1494 |
TreePropertyList staticMethods = 0; |
| 1495 |
TreePropertyList staticMethodsTail = 0; |
1495 |
TreePropertyList staticMethodsTail = 0; |
| 1496 |
while (!match(CLOSEBRACE)) { |
1496 |
while (!match(CLOSEBRACE)) { |
| 1497 |
if (match(SEMICOLON)) |
1497 |
if (match(SEMICOLON)) |
|
Lines 1505-1545
template <class TreeBuilder> TreeClassExpression Parser<LexerType>::parseClass(T
a/Source/JavaScriptCore/parser/Parser.cpp_sec2
|
| 1505 |
if (isStaticMethod) |
1505 |
if (isStaticMethod) |
| 1506 |
next(); |
1506 |
next(); |
| 1507 |
|
1507 |
|
| 1508 |
matchOrFail(IDENT, "Expected an indentifier"); |
|
|
| 1509 |
|
| 1510 |
const CommonIdentifiers& propertyNames = *m_vm->propertyNames; |
1508 |
const CommonIdentifiers& propertyNames = *m_vm->propertyNames; |
| 1511 |
const Identifier& ident = *m_token.m_data.ident; |
|
|
| 1512 |
bool isGetter = ident == propertyNames.get; |
| 1513 |
bool isSetter = ident == propertyNames.set; |
| 1514 |
|
| 1515 |
TreeProperty property; |
1509 |
TreeProperty property; |
| 1516 |
const bool alwaysStrictInsideClass = true; |
1510 |
const bool alwaysStrictInsideClass = true; |
| 1517 |
if (isGetter || isSetter) { |
1511 |
if (match(OPENBRACKET)) { |
| 1518 |
semanticFailIfTrue(isStaticMethod, "Cannot declare a static", stringForFunctionMode(isGetter ? GetterMode : SetterMode)); |
1512 |
next(); |
| 1519 |
nextExpectIdentifier(LexerFlagsIgnoreReservedWords); |
1513 |
TreeExpression computedName = parseExpression(context); |
| 1520 |
property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart, constructorKind, SuperBinding::Needed); |
1514 |
failIfFalse(computedName, "Cannot parse computed property name"); |
| 1521 |
failIfFalse(property, "Cannot parse this method"); |
1515 |
handleProductionOrFail(CLOSEBRACKET, "]", "end", "computed property name"); |
|
|
1516 |
ParserFunctionInfo<TreeBuilder> computedMethodInfo; |
| 1517 |
computedMethodInfo.name = &propertyNames.nullIdentifier; |
| 1518 |
failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, |
| 1519 |
isStaticMethod ? FunctionMode : MethodMode, false, constructorKind, computedMethodInfo)), "Cannot parse this method"); |
| 1520 |
TreeExpression computedMethod = context.createFunctionExpr(methodLocation, computedMethodInfo, methodStart); |
| 1521 |
property = context.createProperty(computedName, computedMethod, PropertyNode::Constant, PropertyNode::KnownDirect, alwaysStrictInsideClass, SuperBinding::Needed); |
| 1522 |
} else { |
1522 |
} else { |
| 1523 |
ParserFunctionInfo<TreeBuilder> methodInfo; |
1523 |
matchOrFail(IDENT, "Expected an indentifier"); |
| 1524 |
failIfFalse((parseFunctionInfo(context, FunctionNeedsName, isStaticMethod ? FunctionMode : MethodMode, false, constructorKind, methodInfo)), "Cannot parse this method"); |
1524 |
|
| 1525 |
failIfFalse(methodInfo.name, "method must have a name"); |
1525 |
const Identifier& ident = *m_token.m_data.ident; |
| 1526 |
failIfFalse(declareVariable(methodInfo.name), "Cannot declare a method named '", methodInfo.name->impl(), "'"); |
1526 |
bool isGetter = ident == propertyNames.get; |
| 1527 |
|
1527 |
bool isSetter = ident == propertyNames.set; |
| 1528 |
bool isConstructor = !isStaticMethod && *methodInfo.name == propertyNames.constructor; |
|
|
| 1529 |
if (isConstructor) |
| 1530 |
methodInfo.name = className; |
| 1531 |
|
| 1532 |
TreeExpression method = context.createFunctionExpr(methodLocation, methodInfo, methodStart); |
| 1533 |
if (isConstructor) { |
| 1534 |
semanticFailIfTrue(constructor, "Cannot declare multiple constructors in a single class"); |
| 1535 |
constructor = method; |
| 1536 |
continue; |
| 1537 |
} |
| 1538 |
|
1528 |
|
| 1539 |
// FIXME: Syntax error when super() is called |
1529 |
if (isGetter || isSetter) { |
| 1540 |
semanticFailIfTrue(isStaticMethod && *methodInfo.name == propertyNames.prototype, |
1530 |
nextExpectIdentifier(LexerFlagsIgnoreReservedWords); |
| 1541 |
"Cannot declare a static method named 'prototype'"); |
1531 |
property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart, constructorKind, SuperBinding::Needed); |
| 1542 |
property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed); |
1532 |
failIfFalse(property, "Cannot parse this method"); |
|
|
1533 |
} else { |
| 1534 |
ParserFunctionInfo<TreeBuilder> methodInfo; |
| 1535 |
failIfFalse((parseFunctionInfo(context, FunctionNeedsName, isStaticMethod ? FunctionMode : MethodMode, false, constructorKind, methodInfo)), "Cannot parse this method"); |
| 1536 |
failIfFalse(methodInfo.name, "method must have a name"); |
| 1537 |
failIfFalse(declareVariable(methodInfo.name), "Cannot declare a method named '", methodInfo.name->impl(), "'"); |
| 1538 |
|
| 1539 |
bool isConstructor = !isStaticMethod && *methodInfo.name == propertyNames.constructor; |
| 1540 |
if (isConstructor) |
| 1541 |
methodInfo.name = className; |
| 1542 |
|
| 1543 |
TreeExpression method = context.createFunctionExpr(methodLocation, methodInfo, methodStart); |
| 1544 |
if (isConstructor) { |
| 1545 |
semanticFailIfTrue(constructor, "Cannot declare multiple constructors in a single class"); |
| 1546 |
constructor = method; |
| 1547 |
continue; |
| 1548 |
} |
| 1549 |
|
| 1550 |
// FIXME: Syntax error when super() is called |
| 1551 |
semanticFailIfTrue(isStaticMethod && *methodInfo.name == propertyNames.prototype, |
| 1552 |
"Cannot declare a static method named 'prototype'"); |
| 1553 |
property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed); |
| 1554 |
} |
| 1543 |
} |
1555 |
} |
| 1544 |
|
1556 |
|
| 1545 |
TreePropertyList& tail = isStaticMethod ? staticMethodsTail : instanceMethodsTail; |
1557 |
TreePropertyList& tail = isStaticMethod ? staticMethodsTail : instanceMethodsTail; |