Ignore:
Timestamp:
Jan 16, 2011, 3:54:40 PM (14 years ago)
Author:
[email protected]
Message:

2011-01-16 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Strict mode restrictions on arguments and eval usage aren't complete
https://bugs.webkit.org/show_bug.cgi?id=52528

Add a helper function to aid parse failure tests by testing both direct
eval/global code, and nested code (so that we test the syntax checker
mode as well)

  • fast/js/basic-strict-mode-expected.txt:
  • fast/js/script-tests/basic-strict-mode.js: (shouldBeSyntaxError):

2011-01-16 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Strict mode restrictions on arguments and eval usage aren't complete
https://bugs.webkit.org/show_bug.cgi?id=52528

Fix a few bugs in strict mode where we incorrect allow mutation of
arguments and eval in the parser.

Alas the "optimisation" used by the syntax checker for validating
binary and unary expressions was too aggressive: we do actually need
a stack for operations and operands although it needn't be as complete
as that used for the full AST builder.

Also disallow assignment to arguments in all cases as allowing arguments
to be assignable is always an error in strict mode, regardless of context.

  • parser/ASTBuilder.h: (JSC::ASTBuilder::BinaryExprContext::BinaryExprContext): (JSC::ASTBuilder::UnaryExprContext::UnaryExprContext):
  • parser/JSParser.cpp: (JSC::JSParser::parseAssignmentExpression): (JSC::JSParser::parseBinaryExpression): (JSC::JSParser::parseUnaryExpression):
  • parser/SyntaxChecker.h: (JSC::SyntaxChecker::BinaryExprContext::BinaryExprContext): (JSC::SyntaxChecker::BinaryExprContext::~BinaryExprContext): (JSC::SyntaxChecker::UnaryExprContext::UnaryExprContext): (JSC::SyntaxChecker::UnaryExprContext::~UnaryExprContext): (JSC::SyntaxChecker::appendBinaryExpressionInfo): (JSC::SyntaxChecker::operatorStackPop):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/JSParser.cpp

    r75872 r75896  
    14911491        if (strictMode() && m_lastIdentifier && context.isResolve(lhs)) {
    14921492            failIfTrueIfStrict(m_globalData->propertyNames->eval == *m_lastIdentifier);
     1493            failIfTrueIfStrict(m_globalData->propertyNames->arguments == *m_lastIdentifier);
    14931494            declareWrite(m_lastIdentifier);
    14941495            m_lastIdentifier = 0;
     
    15461547    int operandStackDepth = 0;
    15471548    int operatorStackDepth = 0;
     1549    typename TreeBuilder::BinaryExprContext binaryExprContext(context);
    15481550    while (true) {
    15491551        int exprStart = tokenStart();
     
    19431945template <class TreeBuilder> TreeExpression JSParser::parseUnaryExpression(TreeBuilder& context)
    19441946{
     1947    typename TreeBuilder::UnaryExprContext unaryExprContext(context);
    19451948    AllowInOverride allowInOverride(this);
    19461949    int tokenStackDepth = 0;
     
    19781981    if (strictMode() && !m_syntaxAlreadyValidated) {
    19791982        if (context.isResolve(expr)) {
    1980             isEvalOrArguments = m_globalData->propertyNames->eval == *m_lastIdentifier;
    1981             if (!isEvalOrArguments && currentScope()->isFunction())
    1982                 isEvalOrArguments = m_globalData->propertyNames->arguments == *m_lastIdentifier;
     1983            isEvalOrArguments = *m_lastIdentifier == m_globalData->propertyNames->eval || *m_lastIdentifier == m_globalData->propertyNames->arguments;
    19831984        }
    19841985    }
Note: See TracChangeset for help on using the changeset viewer.