Changeset 181293 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Mar 9, 2015, 4:47:06 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r181183 r181293 1256 1256 1257 1257 template <typename LexerType> 1258 template <class TreeBuilder> TreeFunctionBody Parser<LexerType>::parseFunctionBody(TreeBuilder& context )1258 template <class TreeBuilder> TreeFunctionBody Parser<LexerType>::parseFunctionBody(TreeBuilder& context, ConstructorKind constructorKind) 1259 1259 { 1260 1260 JSTokenLocation startLocation(tokenLocation()); … … 1264 1264 if (match(CLOSEBRACE)) { 1265 1265 unsigned endColumn = tokenColumn(); 1266 return context.createFunctionBody(startLocation, tokenLocation(), startColumn, endColumn, strictMode() );1266 return context.createFunctionBody(startLocation, tokenLocation(), startColumn, endColumn, strictMode(), constructorKind); 1267 1267 } 1268 1268 DepthManager statementDepth(&m_statementDepth); … … 1271 1271 failIfFalse(parseSourceElements(bodyBuilder, CheckForStrictMode), "Cannot parse body of this function"); 1272 1272 unsigned endColumn = tokenColumn(); 1273 return context.createFunctionBody(startLocation, tokenLocation(), startColumn, endColumn, strictMode() );1273 return context.createFunctionBody(startLocation, tokenLocation(), startColumn, endColumn, strictMode(), constructorKind); 1274 1274 } 1275 1275 … … 1291 1291 1292 1292 template <typename LexerType> 1293 template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuilder& context, FunctionRequirements requirements, FunctionParseMode mode, bool nameIsInContainingScope, ParserFunctionInfo<TreeBuilder>& info) 1293 template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuilder& context, FunctionRequirements requirements, FunctionParseMode mode, 1294 bool nameIsInContainingScope, ConstructorKind constructorKind, ParserFunctionInfo<TreeBuilder>& info) 1294 1295 { 1295 1296 AutoPopScopeRef functionScope(this, pushScope()); … … 1344 1345 unsigned currentLineStartOffset = m_token.m_location.lineStartOffset; 1345 1346 1346 info.body = context.createFunctionBody(startLocation, endLocation, info.bodyStartColumn, bodyEndColumn, cachedInfo->strictMode );1347 info.body = context.createFunctionBody(startLocation, endLocation, info.bodyStartColumn, bodyEndColumn, cachedInfo->strictMode, constructorKind); 1347 1348 1348 1349 functionScope->restoreFromSourceProviderCache(cachedInfo); … … 1367 1368 m_lastFunctionName = lastFunctionName; 1368 1369 ParserState oldState = saveState(); 1369 info.body = parseFunctionBody(context );1370 info.body = parseFunctionBody(context, constructorKind); 1370 1371 restoreState(oldState); 1371 1372 failIfFalse(info.body, "Cannot parse the body of this ", stringForFunctionMode(mode)); 1372 1373 context.setEndOffset(info.body, m_lexer->currentOffset()); 1373 1374 if (functionScope->strictMode() && info.name) { 1374 RELEASE_ASSERT(mode == FunctionMode );1375 RELEASE_ASSERT(mode == FunctionMode || mode == MethodMode); 1375 1376 semanticFailIfTrue(m_vm->propertyNames->arguments == *info.name, "'", info.name->impl(), "' is not a valid function name in strict mode"); 1376 1377 semanticFailIfTrue(m_vm->propertyNames->eval == *info.name, "'", info.name->impl(), "' is not a valid function name in strict mode"); 1378 } 1379 if (functionScope->hasDirectSuper()) { 1380 bool nameIsConstructor = info.name && *info.name == m_vm->propertyNames->constructor; 1381 semanticFailIfTrue(mode != MethodMode || !nameIsConstructor, "Cannot call super() outside of a class constructor"); 1377 1382 } 1378 1383 info.closeBraceOffset = m_token.m_data.offset; … … 1416 1421 next(); 1417 1422 ParserFunctionInfo<TreeBuilder> info; 1418 failIfFalse((parseFunctionInfo(context, FunctionNeedsName, FunctionMode, true, info)), "Cannot parse this function");1423 failIfFalse((parseFunctionInfo(context, FunctionNeedsName, FunctionMode, true, ConstructorKind::Base, info)), "Cannot parse this function"); 1419 1424 failIfFalse(info.name, "Function statements must have a name"); 1420 1425 failIfFalseIfStrict(declareVariable(info.name), "Cannot declare a function named '", info.name->impl(), "' in strict mode"); … … 1466 1471 parentClass = parsePrimaryExpression(context); 1467 1472 failIfFalse(parentClass, "Cannot parse the parent class name"); 1468 failWithMessage("Inheritance is not supported yet");1469 }1473 } 1474 const ConstructorKind constructorKind = parentClass ? ConstructorKind::Derived : ConstructorKind::Base; 1470 1475 1471 1476 consumeOrFailWithFlags(OPENBRACE, TreeBuilder::DontBuildStrings, "Expected opening '{' at the start of a class body"); … … 1499 1504 semanticFailIfTrue(isStaticMethod, "Cannot declare a static", stringForFunctionMode(isGetter ? GetterMode : SetterMode)); 1500 1505 nextExpectIdentifier(LexerFlagsIgnoreReservedWords); 1501 property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart );1506 property = parseGetterSetter(context, alwaysStrictInsideClass, isGetter ? PropertyNode::Getter : PropertyNode::Setter, methodStart, SuperBinding::Needed); 1502 1507 failIfFalse(property, "Cannot parse this method"); 1503 1508 } else { 1504 1509 ParserFunctionInfo<TreeBuilder> methodInfo; 1505 failIfFalse((parseFunctionInfo(context, FunctionNeedsName, FunctionMode, false, methodInfo)), "Cannot parse this method");1510 failIfFalse((parseFunctionInfo(context, FunctionNeedsName, MethodMode, false, constructorKind, methodInfo)), "Cannot parse this method"); 1506 1511 failIfFalse(methodInfo.name, "method must have a name"); 1507 1512 failIfFalse(declareVariable(methodInfo.name), "Cannot declare a method named '", methodInfo.name->impl(), "'"); … … 1521 1526 semanticFailIfTrue(isStaticMethod && *methodInfo.name == propertyNames.prototype, 1522 1527 "Cannot declare a static method named 'prototype'"); 1523 property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, PropertyNode::Unknown, alwaysStrictInsideClass );1528 property = context.createProperty(methodInfo.name, method, PropertyNode::Constant, PropertyNode::Unknown, alwaysStrictInsideClass, SuperBinding::Needed); 1524 1529 } 1525 1530 … … 2008 2013 unsigned methodStart = tokenStart(); 2009 2014 ParserFunctionInfo<TreeBuilder> methodInfo; 2010 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, MethodMode, false, methodInfo)), "Cannot parse this method");2015 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, MethodMode, false, ConstructorKind::Base, methodInfo)), "Cannot parse this method"); 2011 2016 methodInfo.name = methodName; 2012 2017 return context.createFunctionExpr(methodLocation, methodInfo, methodStart); … … 2014 2019 2015 2020 template <typename LexerType> 2016 template <class TreeBuilder> TreeProperty Parser<LexerType>::parseGetterSetter(TreeBuilder& context, bool strict, PropertyNode::Type type, unsigned getterOrSetterStartOffset )2021 template <class TreeBuilder> TreeProperty Parser<LexerType>::parseGetterSetter(TreeBuilder& context, bool strict, PropertyNode::Type type, unsigned getterOrSetterStartOffset, SuperBinding superBinding) 2017 2022 { 2018 2023 const Identifier* stringPropertyName = 0; … … 2029 2034 if (type == PropertyNode::Getter) { 2030 2035 failIfFalse(match(OPENPAREN), "Expected a parameter list for getter definition"); 2031 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, GetterMode, false, info)), "Cannot parse getter definition");2036 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, GetterMode, false, ConstructorKind::Base, info)), "Cannot parse getter definition"); 2032 2037 } else { 2033 2038 failIfFalse(match(OPENPAREN), "Expected a parameter list for setter definition"); 2034 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SetterMode, false, info)), "Cannot parse setter definition");2039 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SetterMode, false, ConstructorKind::Base, info)), "Cannot parse setter definition"); 2035 2040 } 2036 2041 if (stringPropertyName) 2037 return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, getterOrSetterStartOffset );2038 return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, strict, numericPropertyName, info, getterOrSetterStartOffset );2042 return context.createGetterOrSetterProperty(location, type, strict, stringPropertyName, info, getterOrSetterStartOffset, superBinding); 2043 return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), m_parserArena, location, type, strict, numericPropertyName, info, getterOrSetterStartOffset, superBinding); 2039 2044 } 2040 2045 … … 2221 2226 ParserFunctionInfo<TreeBuilder> info; 2222 2227 info.name = &m_vm->propertyNames->nullIdentifier; 2223 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, FunctionMode, false, info)), "Cannot parse function expression");2228 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, FunctionMode, false, ConstructorKind::Base, info)), "Cannot parse function expression"); 2224 2229 return context.createFunctionExpr(location, info, functionKeywordStart); 2225 2230 } … … 2371 2376 } 2372 2377 2373 base = parsePrimaryExpression(context); 2374 2378 #if ENABLE(ES6_CLASS_SYNTAX) 2379 bool baseIsSuper = match(SUPER); 2380 #else 2381 bool baseIsSuper = false; 2382 #endif 2383 2384 if (baseIsSuper) { 2385 base = context.superExpr(location); 2386 next(); 2387 } else 2388 base = parsePrimaryExpression(context); 2389 2375 2390 failIfFalse(base, "Cannot parse base expression"); 2376 2391 while (true) { … … 2403 2418 TreeArguments arguments = parseArguments(context, AllowSpread); 2404 2419 failIfFalse(arguments, "Cannot parse call arguments"); 2420 if (baseIsSuper) 2421 currentScope()->setHasDirectSuper(); 2405 2422 base = context.makeFunctionCallNode(startLocation, base, arguments, expressionStart, expressionEnd, lastTokenEndPosition()); 2406 2423 } … … 2420 2437 goto endMemberExpression; 2421 2438 } 2439 baseIsSuper = false; 2422 2440 } 2423 2441 endMemberExpression: 2442 semanticFailIfTrue(baseIsSuper && !newCount, "Cannot reference super"); 2424 2443 while (newCount--) 2425 2444 base = context.createNewExpr(location, base, expressionStart, lastTokenEndPosition());
Note:
See TracChangeset
for help on using the changeset viewer.