diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 63ea48051e3..9fece52f1b0 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -824,7 +824,7 @@ Parser::checkStrictAssignment(Node lhs, AssignmentFlavor flavor) */ template bool -Parser::checkStrictBinding(HandlePropertyName name, Node pn) +Parser::checkStrictBinding(PropertyName *name, Node pn) { if (!pc->sc->needStrictChecks()) return true; @@ -1305,8 +1305,7 @@ ConvertDefinitionToNamedLambdaUse(TokenStream &ts, ParseContext bool -Parser::leaveFunction(ParseNode *fn, HandlePropertyName funName, - ParseContext *outerpc, +Parser::leaveFunction(ParseNode *fn, ParseContext *outerpc, FunctionSyntaxKind kind) { outerpc->blockidGen = pc->blockidGen; @@ -1321,7 +1320,7 @@ Parser::leaveFunction(ParseNode *fn, HandlePropertyName funNam Definition *dn = r.front().value().get(); JS_ASSERT(dn->isPlaceholder()); - if (atom == funName && kind == Expression) { + if (atom == funbox->function()->name() && kind == Expression) { if (!ConvertDefinitionToNamedLambdaUse(tokenStream, pc, funbox, dn)) return false; continue; @@ -1405,8 +1404,7 @@ Parser::leaveFunction(ParseNode *fn, HandlePropertyName funNam template <> bool -Parser::leaveFunction(Node fn, HandlePropertyName funName, - ParseContext *outerpc, +Parser::leaveFunction(Node fn, ParseContext *outerpc, FunctionSyntaxKind kind) { outerpc->blockidGen = pc->blockidGen; @@ -1940,7 +1938,7 @@ Parser::functionDef(HandlePropertyName funName, const TokenStream: // directive, we backup and reparse it as strict. bool initiallyStrict = pc->sc->strict; bool becameStrict; - if (!functionArgsAndBody(pn, fun, funName, startOffset, type, kind, initiallyStrict, + if (!functionArgsAndBody(pn, fun, startOffset, type, kind, initiallyStrict, &becameStrict)) { if (initiallyStrict || !becameStrict || tokenStream.hadError()) @@ -1954,7 +1952,7 @@ Parser::functionDef(HandlePropertyName funName, const TokenStream: // functionArgsAndBody may have already set pn->pn_body before failing. handler.setFunctionBody(pn, null()); - if (!functionArgsAndBody(pn, fun, funName, startOffset, type, kind, true)) + if (!functionArgsAndBody(pn, fun, startOffset, type, kind, true)) return null(); } @@ -2055,7 +2053,6 @@ Parser::finishFunctionDefinition(Node pn, FunctionBox *funbo template <> bool Parser::functionArgsAndBody(ParseNode *pn, HandleFunction fun, - HandlePropertyName funName, size_t startOffset, FunctionType type, FunctionSyntaxKind kind, bool strict, bool *becameStrict) @@ -2087,7 +2084,7 @@ Parser::functionArgsAndBody(ParseNode *pn, HandleFunction fun, return false; if (!parser->functionArgsAndBodyGeneric(SyntaxParseHandler::NodeGeneric, - fun, funName, type, kind, becameStrict)) + fun, type, kind, becameStrict)) { if (parser->hadAbortedSyntaxParse()) { // Try again with a full parse. @@ -2120,10 +2117,10 @@ Parser::functionArgsAndBody(ParseNode *pn, HandleFunction fun, if (!funpc.init()) return false; - if (!functionArgsAndBodyGeneric(pn, fun, funName, type, kind, becameStrict)) + if (!functionArgsAndBodyGeneric(pn, fun, type, kind, becameStrict)) return false; - if (!leaveFunction(pn, funName, outerpc, kind)) + if (!leaveFunction(pn, outerpc, kind)) return false; pn->pn_blockid = outerpc->blockid(); @@ -2140,10 +2137,8 @@ Parser::functionArgsAndBody(ParseNode *pn, HandleFunction fun, template <> bool -Parser::functionArgsAndBody(Node pn, HandleFunction fun, - HandlePropertyName funName, - size_t startOffset, FunctionType type, - FunctionSyntaxKind kind, +Parser::functionArgsAndBody(Node pn, HandleFunction fun, size_t startOffset, + FunctionType type, FunctionSyntaxKind kind, bool strict, bool *becameStrict) { if (becameStrict) @@ -2161,10 +2156,10 @@ Parser::functionArgsAndBody(Node pn, HandleFunction fun, if (!funpc.init()) return false; - if (!functionArgsAndBodyGeneric(pn, fun, funName, type, kind, becameStrict)) + if (!functionArgsAndBodyGeneric(pn, fun, type, kind, becameStrict)) return false; - if (!leaveFunction(pn, funName, outerpc, kind)) + if (!leaveFunction(pn, outerpc, kind)) return false; // This is a lazy function inner to another lazy function. Remember the @@ -2192,13 +2187,11 @@ Parser::standaloneLazyFunction(HandleFunction fun, unsigned st if (!funpc.init()) return null(); - RootedPropertyName funName(context, fun->atom() ? fun->atom()->asPropertyName() : NULL); - - if (!functionArgsAndBodyGeneric(pn, fun, funName, Normal, Statement, NULL)) + if (!functionArgsAndBodyGeneric(pn, fun, Normal, Statement, NULL)) return null(); if (fun->isNamedLambda()) { - if (AtomDefnPtr p = pc->lexdeps->lookup(funName)) { + if (AtomDefnPtr p = pc->lexdeps->lookup(fun->name())) { Definition *dn = p.value().get(); if (!ConvertDefinitionToNamedLambdaUse(tokenStream, pc, funbox, dn)) return NULL; @@ -2215,8 +2208,7 @@ Parser::standaloneLazyFunction(HandleFunction fun, unsigned st template bool -Parser::functionArgsAndBodyGeneric(Node pn, HandleFunction fun, - HandlePropertyName funName, FunctionType type, +Parser::functionArgsAndBodyGeneric(Node pn, HandleFunction fun, FunctionType type, FunctionSyntaxKind kind, bool *becameStrict) { // Given a properly initialized parse context, try to parse an actual @@ -2273,7 +2265,7 @@ Parser::functionArgsAndBodyGeneric(Node pn, HandleFunction fun, if (!yieldGuard.empty() && !yieldGuard.ref().checkValidBody(body, JSMSG_YIELD_IN_ARROW)) return false; - if (funName && !checkStrictBinding(funName, pn)) + if (fun->name() && !checkStrictBinding(fun->name(), pn)) return false; #if JS_HAS_EXPR_CLOSURES @@ -6026,8 +6018,7 @@ Parser::generatorExpr(ParseNode *kid) genfn->pn_pos.begin = body->pn_pos.begin = kid->pn_pos.begin; genfn->pn_pos.end = body->pn_pos.end = pos().end; - RootedPropertyName funName(context); - if (!leaveFunction(genfn, funName, outerpc)) + if (!leaveFunction(genfn, outerpc)) return null(); } diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 82336cc2ed3..cbf90dd3b4d 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -415,8 +415,7 @@ class Parser : private AutoGCRooter, public StrictModeGetter enum FunctionBodyType { StatementListBody, ExpressionBody }; Node functionBody(FunctionSyntaxKind kind, FunctionBodyType type); - bool functionArgsAndBodyGeneric(Node pn, HandleFunction fun, - HandlePropertyName funName, FunctionType type, + bool functionArgsAndBodyGeneric(Node pn, HandleFunction fun, FunctionType type, FunctionSyntaxKind kind, bool *becameStrict); virtual bool strictMode() { return pc->sc->strict; } @@ -486,8 +485,8 @@ class Parser : private AutoGCRooter, public StrictModeGetter Node functionDef(HandlePropertyName name, const TokenStream::Position &start, size_t startOffset, FunctionType type, FunctionSyntaxKind kind); - bool functionArgsAndBody(Node pn, HandleFunction fun, HandlePropertyName funName, - size_t startOffset, FunctionType type, FunctionSyntaxKind kind, + bool functionArgsAndBody(Node pn, HandleFunction fun, size_t startOffset, + FunctionType type, FunctionSyntaxKind kind, bool strict, bool *becameStrict = NULL); Node unaryOpExpr(ParseNodeKind kind, JSOp op, uint32_t begin); @@ -533,7 +532,7 @@ class Parser : private AutoGCRooter, public StrictModeGetter bool forDecl, bool forEach, bool forOf); bool checkAndMarkAsIncOperand(Node kid, TokenKind tt, bool preorder); bool checkStrictAssignment(Node lhs, AssignmentFlavor flavor); - bool checkStrictBinding(HandlePropertyName name, Node pn); + bool checkStrictBinding(PropertyName *name, Node pn); bool defineArg(Node funcpn, HandlePropertyName name, bool disallowDuplicateArgs = false, Node *duplicatedArg = NULL); Node pushLexicalScope(StmtInfoPC *stmt); @@ -572,8 +571,7 @@ class Parser : private AutoGCRooter, public StrictModeGetter bool checkFinalReturn(Node pn); DefinitionNode getOrCreateLexicalDependency(ParseContext *pc, JSAtom *atom); - bool leaveFunction(Node fn, HandlePropertyName funName, - ParseContext *outerpc, + bool leaveFunction(Node fn, ParseContext *outerpc, FunctionSyntaxKind kind = Expression); TokenPos pos() const { return tokenStream.currentToken().pos; }