Beispiel #1
0
        public Node parseFunctionExpression()
        {
            Token token;
            Node id = null;
            Token stricted;
            Token firstRestricted = null;
            string message = "";
            Options tmp;
            List<Node> @params = new List<Node>();

            List<Node> defaults = new List<Node>();
            List<Node> body;
            bool previousStrict;
            Node node = new Node();
            bool isGenerator;
            bool previousAllowYield;

            previousAllowYield = state.allowYield;

            expectKeyword("function");

            isGenerator = match("*");
            if (isGenerator)
            {
                lex();
            }

            state.allowYield = !isGenerator;
            if (!match("("))
            {
                token = lookahead;
                id = (!strict && !isGenerator && matchKeyword("yield"))
                    ? parseNonComputedProperty()
                    : parseVariableIdentifier();
                if (strict)
                {
                    if (isRestrictedWord(token.value))
                    {
                        tolerateUnexpectedToken(token, Messages.StrictFunctionName);
                    }
                }
                else
                {
                    if (isRestrictedWord(token.value))
                    {
                        firstRestricted = token;
                        message = Messages.StrictFunctionName;
                    }
                    else if (isStrictModeReservedWord(token.value))
                    {
                        firstRestricted = token;
                        message = Messages.StrictReservedWord;
                    }
                }
            }

            tmp = parseParams(firstRestricted);
            @params = tmp.@params;
            defaults = tmp.defaults;
            stricted = tmp.stricted;
            firstRestricted = tmp.firstRestricted;
            if (tmp.message != null)
            {
                message = tmp.message;
            }

            previousStrict = strict;
            body = new List<Node>() { parseFunctionSourceElements() };
            if (strict && firstRestricted != null)
            {
                throwUnexpectedToken(firstRestricted, message);
            }
            if (strict && stricted != null)
            {
                tolerateUnexpectedToken(stricted, message);
            }
            strict = previousStrict;
            state.allowYield = previousAllowYield;

            return node.finishFunctionExpression(id, @params, defaults, body, isGenerator);
        }
Beispiel #2
0
        // ECMA-262 12.2.6 Object Initializer

        public Node parsePropertyFunction(Node node, Options paramInfo, bool isGenerator)
        {
            bool previousStrict;
            List<Node> body;

            isAssignmentTarget = isBindingElement = false;

            previousStrict = strict;
            body = new List<Node>() { isolateCoverGrammar(parseFunctionSourceElements) };

            if (strict && paramInfo.firstRestricted != null)
            {
                tolerateUnexpectedToken(paramInfo.firstRestricted, paramInfo.message);
            }
            if (strict && paramInfo.stricted != null)
            {
                tolerateUnexpectedToken(paramInfo.stricted, paramInfo.message);
            }

            strict = previousStrict;
            return node.finishFunctionExpression(null, paramInfo.@params, paramInfo.defaults, body, isGenerator);
        }