From 0dac7918513ee906574d7b4f3b805200b5cc9812 Mon Sep 17 00:00:00 2001 From: Martok Date: Sun, 2 Apr 2023 17:38:52 +0200 Subject: [PATCH] Issue #2173 - Separate CodeNode into FunctionNode and ModuleNode ModuleNode only has a body and FunctionNode has many more attributes, and will get more in the following commit. Based-on: 1518391/2 --- js/src/builtin/ModuleObject.cpp | 2 +- js/src/builtin/ReflectParse.cpp | 20 +++--- js/src/frontend/BytecodeCompiler.cpp | 12 ++-- js/src/frontend/BytecodeEmitter.cpp | 24 ++++---- js/src/frontend/BytecodeEmitter.h | 4 +- js/src/frontend/FoldConstants.cpp | 16 ++--- js/src/frontend/FullParseHandler.h | 37 ++++++----- js/src/frontend/NameFunctions.cpp | 16 +++-- js/src/frontend/ParseNode-inl.h | 5 +- js/src/frontend/ParseNode.cpp | 36 ++++++++--- js/src/frontend/ParseNode.h | 92 +++++++++++++++++++--------- js/src/frontend/Parser.cpp | 72 +++++++++++----------- js/src/frontend/Parser.h | 56 ++++++++--------- js/src/frontend/SharedContext.h | 2 +- js/src/frontend/SyntaxParseHandler.h | 22 +++---- js/src/wasm/AsmJS.cpp | 26 ++++---- 16 files changed, 247 insertions(+), 195 deletions(-) diff --git a/js/src/builtin/ModuleObject.cpp b/js/src/builtin/ModuleObject.cpp index 25781ccc8b..53b6b76b21 100644 --- a/js/src/builtin/ModuleObject.cpp +++ b/js/src/builtin/ModuleObject.cpp @@ -1279,7 +1279,7 @@ ModuleBuilder::processExport(frontend::ParseNode* exportNode) } case PNK_FUNCTION: { - RootedFunction func(cx_, kid->as().funbox()->function()); + RootedFunction func(cx_, kid->as().funbox()->function()); MOZ_ASSERT(!func->isArrow()); RootedAtom localName(cx_, func->explicitName()); RootedAtom exportName(cx_, isDefault ? cx_->names().default_ : localName.get()); diff --git a/js/src/builtin/ReflectParse.cpp b/js/src/builtin/ReflectParse.cpp index fd38352dad..30318d9ce8 100644 --- a/js/src/builtin/ReflectParse.cpp +++ b/js/src/builtin/ReflectParse.cpp @@ -1867,7 +1867,7 @@ class ASTSerializer bool arrayPattern(ListNode* array, MutableHandleValue dst); bool objectPattern(ListNode* obj, MutableHandleValue dst); - bool function(CodeNode* funNode, ASTType type, MutableHandleValue dst); + bool function(FunctionNode* funNode, ASTType type, MutableHandleValue dst); bool functionArgsAndBody(ParseNode* pn, NodeVector& args, NodeVector& defaults, bool isAsync, bool isExpression, MutableHandleValue body, MutableHandleValue rest); @@ -2095,7 +2095,7 @@ ASTSerializer::declaration(ParseNode* pn, MutableHandleValue dst) switch (pn->getKind()) { case PNK_FUNCTION: - return function(&pn->as(), AST_FUNC_DECL, dst); + return function(&pn->as(), AST_FUNC_DECL, dst); case PNK_VAR: return variableDeclaration(&pn->as(), false, dst); @@ -2239,7 +2239,7 @@ ASTSerializer::exportDeclaration(ParseNode* exportNode, MutableHandleValue dst) } case PNK_FUNCTION: - if (!function(&kid->as(), AST_FUNC_DECL, &decl)) + if (!function(&kid->as(), AST_FUNC_DECL, &decl)) return false; break; @@ -2937,7 +2937,7 @@ ASTSerializer::expression(ParseNode* pn, MutableHandleValue dst) switch (pn->getKind()) { case PNK_FUNCTION: { - CodeNode* funNode = &pn->as(); + FunctionNode* funNode = &pn->as(); ASTType type = funNode->funbox()->function()->isArrow() ? AST_ARROW_EXPR : AST_FUNC_EXPR; return function(funNode, type, dst); } @@ -3081,7 +3081,7 @@ ASTSerializer::expression(ParseNode* pn, MutableHandleValue dst) ParseNode* callee = pn->as().left(); MOZ_ASSERT(callee->isKind(PNK_FUNCTION)); - ListNode* paramsBody = callee->as().body(); + ListNode* paramsBody = callee->as().body(); MOZ_ASSERT(paramsBody->isKind(PNK_PARAMSBODY)); ListNode* body = ¶msBody->last()->as(); @@ -3441,9 +3441,8 @@ ASTSerializer::property(ParseNode* pn, MutableHandleValue dst) ParseNode* valNode = node->right(); bool isShorthand = node->isKind(PNK_SHORTHAND); - bool isMethod = - valNode->isKind(PNK_FUNCTION) && - valNode->as().funbox()->function()->kind() == JSFunction::Method; + bool isMethod = valNode->is() && + valNode->as().funbox()->function()->kind() == JSFunction::Method; RootedValue key(cx), val(cx); return propertyName(keyNode, &key) && expression(valNode, &val) && @@ -3614,7 +3613,7 @@ ASTSerializer::identifier(NameNode* id, MutableHandleValue dst) } bool -ASTSerializer::function(CodeNode* funNode, ASTType type, MutableHandleValue dst) +ASTSerializer::function(FunctionNode* funNode, ASTType type, MutableHandleValue dst) { FunctionBox* funbox = funNode->funbox(); RootedFunction func(cx, funbox->function()); @@ -3938,8 +3937,7 @@ reflect_parse(JSContext* cx, uint32_t argc, Value* vp) if (!pn) return false; - MOZ_ASSERT(pn->getKind() == PNK_MODULE); - pn = pn->as().body(); + pn = pn->as().body(); } RootedValue val(cx); diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp index d2edd786a6..de04d41d60 100644 --- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -413,7 +413,7 @@ BytecodeCompiler::compileModule() Maybe emitter; if (!emplaceEmitter(emitter, &modulesc)) return nullptr; - if (!emitter->emitScript(pn->as().body())) + if (!emitter->emitScript(pn->as().body())) return nullptr; if (!NameFunctions(cx, pn)) @@ -457,7 +457,7 @@ BytecodeCompiler::compileStandaloneFunction(MutableHandleFunction fun, // function should have been parsed, we backup and reparse with the new set // of directives. - ParseNode* fn; + FunctionNode* fn; do { Directives newDirectives = directives; fn = parser->standaloneFunction(fun, enclosingScope, parameterListEnd, generatorKind, @@ -466,7 +466,7 @@ BytecodeCompiler::compileStandaloneFunction(MutableHandleFunction fun, return false; } while (!fn); - FunctionBox* funbox = fn->as().funbox(); + FunctionBox* funbox = fn->funbox(); if (funbox->function()->isInterpreted()) { MOZ_ASSERT(fun == funbox->function()); @@ -476,7 +476,7 @@ BytecodeCompiler::compileStandaloneFunction(MutableHandleFunction fun, Maybe emitter; if (!emplaceEmitter(emitter, funbox)) return false; - if (!emitter->emitFunctionScript(&fn->as())) + if (!emitter->emitFunctionScript(fn)) return false; } else { fun.set(funbox->function()); @@ -674,12 +674,12 @@ frontend::CompileLazyFunction(JSContext* cx, Handle lazy, const cha if (lazy->hasBeenCloned()) script->setHasBeenCloned(); - BytecodeEmitter bce(/* parent = */ nullptr, &parser, pn->as().funbox(), script, lazy, + BytecodeEmitter bce(/* parent = */ nullptr, &parser, pn->as().funbox(), script, lazy, pn->pn_pos, BytecodeEmitter::LazyFunction); if (!bce.init()) return false; - if (!bce.emitFunctionScript(&pn->as())) + if (!bce.emitFunctionScript(&pn->as())) return false; if (!NameFunctions(cx, pn)) diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 41260843dd..5adbf9f066 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -1415,7 +1415,7 @@ BytecodeEmitter::checkSideEffects(ParseNode* pn, bool* answer) return true; case PNK_FUNCTION: - MOZ_ASSERT(pn->is()); + MOZ_ASSERT(pn->is()); /* * A named function, contrary to ES3, is no longer effectful, because * we bind its name lexically (using JSOP_CALLEE) instead of creating @@ -2385,9 +2385,8 @@ BytecodeEmitter::emitScript(ParseNode* body) } bool -BytecodeEmitter::emitFunctionScript(CodeNode* funNode) +BytecodeEmitter::emitFunctionScript(FunctionNode* funNode) { - MOZ_ASSERT(funNode->isKind(PNK_FUNCTION)); ParseNode* body = funNode->body(); FunctionBox* funbox = sc->asFunctionBox(); @@ -2967,10 +2966,10 @@ bool BytecodeEmitter::setOrEmitSetFunName(ParseNode* maybeFun, HandleAtom name, FunctionPrefixKind prefixKind) { - if (maybeFun->isKind(PNK_FUNCTION)) { + if (maybeFun->is()) { // Function doesn't have 'name' property at this point. // Set function's name at compile time. - RootedFunction fun(cx, maybeFun->as().funbox()->function()); + RootedFunction fun(cx, maybeFun->as().funbox()->function()); // Single node can be emitted multiple times if it appears in // array destructuring default. If function already has a name, @@ -4355,7 +4354,7 @@ BytecodeEmitter::emitHoistedFunctionsInList(ListNode* stmtList) maybeFun = maybeFun->as().statement(); } - if (maybeFun->isKind(PNK_FUNCTION) && maybeFun->as().functionIsHoisted()) { + if (maybeFun->is() && maybeFun->as().functionIsHoisted()) { if (!emitTree(maybeFun)) return false; } @@ -5609,7 +5608,7 @@ BytecodeEmitter::emitComprehensionFor(ForNode* forNode) } MOZ_NEVER_INLINE bool -BytecodeEmitter::emitFunction(CodeNode* funNode, bool needsProto) +BytecodeEmitter::emitFunction(FunctionNode* funNode, bool needsProto) { FunctionBox* funbox = funNode->funbox(); RootedFunction fun(cx, funbox->function()); @@ -7808,10 +7807,9 @@ BytecodeEmitter::emitPropertyList(ListNode* obj, MutableHandlePlainObject objp, if (op == JSOP_INITPROP_GETTER || op == JSOP_INITPROP_SETTER) objp.set(nullptr); - if (propVal->isKind(PNK_FUNCTION) && - propVal->as().funbox()->needsHomeObject()) - { - FunctionBox* funbox = propVal->as().funbox(); + if (propVal->is() && + propVal->as().funbox()->needsHomeObject()) { + FunctionBox* funbox = propVal->as().funbox(); MOZ_ASSERT(funbox->function()->allowSuperProperty()); bool isAsync = funbox->isAsync(); if (isAsync) { @@ -8507,7 +8505,7 @@ BytecodeEmitter::emitClass(ClassNode* classNode) ParseNode* heritageExpression = classNode->heritage(); ListNode* classMethods = classNode->methodList(); - CodeNode* constructor = nullptr; + FunctionNode* constructor = nullptr; for (ParseNode* mn : classMethods->contents()) { ClassMethod& method = mn->as(); ParseNode& methodName = method.name(); @@ -8641,7 +8639,7 @@ BytecodeEmitter::emitTree(ParseNode* pn, ValueUsage valueUsage /* = ValueUsage:: switch (pn->getKind()) { case PNK_FUNCTION: - if (!emitFunction(&pn->as())) + if (!emitFunction(&pn->as())) return false; break; diff --git a/js/src/frontend/BytecodeEmitter.h b/js/src/frontend/BytecodeEmitter.h index 379f2060ab..7a59cf0825 100644 --- a/js/src/frontend/BytecodeEmitter.h +++ b/js/src/frontend/BytecodeEmitter.h @@ -416,7 +416,7 @@ struct MOZ_STACK_CLASS BytecodeEmitter MOZ_MUST_USE bool emitScript(ParseNode* body); // Emit function code for the tree rooted at body. - MOZ_MUST_USE bool emitFunctionScript(CodeNode* funNode); + MOZ_MUST_USE bool emitFunctionScript(FunctionNode* funNode); // If op is JOF_TYPESET (see the type barriers comment in TypeInference.h), // reserve a type set to store its result. @@ -508,7 +508,7 @@ struct MOZ_STACK_CLASS BytecodeEmitter MOZ_MUST_USE bool emitObjectPairOp(ObjectBox* objbox1, ObjectBox* objbox2, JSOp op); MOZ_MUST_USE bool emitRegExp(uint32_t index); - MOZ_NEVER_INLINE MOZ_MUST_USE bool emitFunction(CodeNode* funNode, bool needsProto = false); + MOZ_NEVER_INLINE MOZ_MUST_USE bool emitFunction(FunctionNode* funNode, bool needsProto = false); MOZ_NEVER_INLINE MOZ_MUST_USE bool emitObject(ListNode* objNode); MOZ_MUST_USE bool replaceNewInitWithNewObject(JSObject* obj, ptrdiff_t offset); diff --git a/js/src/frontend/FoldConstants.cpp b/js/src/frontend/FoldConstants.cpp index 0e27a09404..4b9cf55df4 100644 --- a/js/src/frontend/FoldConstants.cpp +++ b/js/src/frontend/FoldConstants.cpp @@ -91,7 +91,6 @@ ContainsHoistedDeclaration(ExclusiveContext* cx, ParseNode* node, bool* result) // that we preserve an unreachable function declaration node against // dead-code removal. case PNK_FUNCTION: - MOZ_ASSERT(node->is()); *result = false; return true; @@ -289,7 +288,7 @@ ContainsHoistedDeclaration(ExclusiveContext* cx, ParseNode* node, bool* result) LexicalScopeNode* scope = &node->as(); ParseNode* expr = scope->scopeBody(); - if (expr->isKind(PNK_FOR) || expr->isKind(PNK_FUNCTION)) + if (expr->isKind(PNK_FOR) || expr->is()) return ContainsHoistedDeclaration(cx, expr, result); MOZ_ASSERT(expr->isKind(PNK_STATEMENTLIST)); @@ -588,7 +587,7 @@ FoldTypeOfExpr(ExclusiveContext* cx, UnaryNode* node, Parser& result = cx->names().object; else if (expr->isKind(PNK_TRUE) || expr->isKind(PNK_FALSE)) result = cx->names().boolean; - else if (expr->isKind(PNK_FUNCTION)) + else if (expr->is()) result = cx->names().function; if (result) { @@ -1018,11 +1017,9 @@ FoldIf(ExclusiveContext* cx, ParseNode** nodePtr, Parser& pars } static bool -FoldFunction(ExclusiveContext* cx, CodeNode* node, Parser& parser, +FoldFunction(ExclusiveContext* cx, FunctionNode* node, Parser& parser, bool inGenexpLambda) { - MOZ_ASSERT(node->isKind(PNK_FUNCTION)); - // Don't constant-fold inside "use asm" code, as this could create a parse // tree that doesn't type-check as asm.js. if (node->funbox()->useAsmOrInsideUseAsm()) @@ -1080,9 +1077,8 @@ ComputeBinary(ParseNodeKind kind, double left, double right) } static bool -FoldModule(ExclusiveContext* cx, CodeNode* node, Parser& parser) +FoldModule(ExclusiveContext* cx, ModuleNode* node, Parser& parser) { - MOZ_ASSERT(node->isKind(PNK_MODULE)); MOZ_ASSERT(node->body()); return Fold(cx, node->unsafeBodyReference(), parser, false); } @@ -1775,10 +1771,10 @@ Fold(ExclusiveContext* cx, ParseNode** pnp, Parser& parser, bo return FoldLogical(cx, pnp, parser, inGenexpLambda); case PNK_FUNCTION: - return FoldFunction(cx, &pn->as(), parser, inGenexpLambda); + return FoldFunction(cx, &pn->as(), parser, inGenexpLambda); case PNK_MODULE: - return FoldModule(cx, &pn->as(), parser); + return FoldModule(cx, &pn->as(), parser); case PNK_SUB: case PNK_STAR: diff --git a/js/src/frontend/FullParseHandler.h b/js/src/frontend/FullParseHandler.h index 0c9eed78b1..8af543fc45 100644 --- a/js/src/frontend/FullParseHandler.h +++ b/js/src/frontend/FullParseHandler.h @@ -439,7 +439,7 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) return true; } - MOZ_MUST_USE bool addObjectMethodDefinition(ListNodeType literal, Node key, CodeNodeType funNode, + MOZ_MUST_USE bool addObjectMethodDefinition(ListNodeType literal, Node key, FunctionNodeType funNode, JSOp op) { MOZ_ASSERT(key->isKind(PNK_NUMBER) || @@ -455,7 +455,7 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) return true; } - MOZ_MUST_USE bool addClassMethodDefinition(ListNodeType methodList, Node key, CodeNodeType funNode, + MOZ_MUST_USE bool addClassMethodDefinition(ListNodeType methodList, Node key, FunctionNodeType funNode, JSOp op, bool isStatic) { MOZ_ASSERT(methodList->isKind(PNK_CLASSMETHODLIST)); @@ -505,7 +505,7 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) MOZ_MUST_USE bool isFunctionStmt(Node stmt) { while (stmt->isKind(PNK_LABEL)) stmt = stmt->as().statement(); - return stmt->isKind(PNK_FUNCTION); + return stmt->is(); } void addStatementToList(ListNodeType list, Node stmt) { @@ -713,7 +713,7 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) inline MOZ_MUST_USE bool addCatchBlock(ListNodeType catchList, LexicalScopeNodeType lexicalScope, Node catchBinding, Node catchGuard, Node catchBody); - inline MOZ_MUST_USE bool setLastFunctionFormalParameterDefault(CodeNodeType funNode, + inline MOZ_MUST_USE bool setLastFunctionFormalParameterDefault(FunctionNodeType funNode, Node defaultValue); inline void setLastFunctionFormalParameterDestructuring(Node funcpn, Node pn); @@ -722,19 +722,19 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) pn->setDirectRHSAnonFunction(true); } - CodeNodeType newFunctionStatement() { - return new_(PNK_FUNCTION, JSOP_NOP, pos()); + FunctionNodeType newFunctionStatement() { + return new_(JSOP_NOP, pos()); } - CodeNodeType newFunctionExpression() { - return new_(PNK_FUNCTION, JSOP_LAMBDA, pos()); + FunctionNodeType newFunctionExpression() { + return new_(JSOP_LAMBDA, pos()); } - CodeNodeType newArrowFunction() { - return new_(PNK_FUNCTION, JSOP_LAMBDA_ARROW, pos()); + FunctionNodeType newArrowFunction() { + return new_(JSOP_LAMBDA_ARROW, pos()); } - bool setComprehensionLambdaBody(CodeNodeType funNode, ListNodeType body) { + bool setComprehensionLambdaBody(FunctionNodeType funNode, ListNodeType body) { MOZ_ASSERT(body->isKind(PNK_STATEMENTLIST)); ListNode* paramsBody = newList(PNK_PARAMSBODY, body); if (!paramsBody) @@ -742,25 +742,24 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) setFunctionFormalParametersAndBody(funNode, paramsBody); return true; } - void setFunctionFormalParametersAndBody(CodeNodeType funNode, ListNodeType paramsBody) { + void setFunctionFormalParametersAndBody(FunctionNodeType funNode, ListNodeType paramsBody) { MOZ_ASSERT_IF(paramsBody, paramsBody->isKind(PNK_PARAMSBODY)); funNode->setBody(paramsBody); } - void setFunctionBox(CodeNodeType funNode, FunctionBox* funbox) { - MOZ_ASSERT(funNode->isKind(PNK_FUNCTION)); + void setFunctionBox(FunctionNodeType funNode, FunctionBox* funbox) { funNode->setFunbox(funbox); funbox->functionNode = funNode; } - void addFunctionFormalParameter(CodeNodeType funNode, Node argpn) { + void addFunctionFormalParameter(FunctionNodeType funNode, Node argpn) { addList(/* list = */ funNode->body(), /* child = */ argpn); } - void setFunctionBody(CodeNodeType funNode, LexicalScopeNodeType body) { + void setFunctionBody(FunctionNodeType funNode, LexicalScopeNodeType body) { MOZ_ASSERT(funNode->body()->isKind(PNK_PARAMSBODY)); addList(/* list = */ funNode->body(), /* child = */ body); } - CodeNodeType newModule() { - return new_(PNK_MODULE, JSOP_NOP, pos()); + ModuleNodeType newModule() { + return new_(pos()); } BinaryNodeType newNewExpression(uint32_t begin, Node ctor, Node args) { @@ -1009,7 +1008,7 @@ FullParseHandler::addCatchBlock(ListNodeType catchList, LexicalScopeNodeType lex } inline bool -FullParseHandler::setLastFunctionFormalParameterDefault(CodeNodeType funNode, Node defaultValue) +FullParseHandler::setLastFunctionFormalParameterDefault(FunctionNodeType funNode, Node defaultValue) { MOZ_ASSERT(funNode->isKind(PNK_FUNCTION)); ListNode* body = funNode->body(); diff --git a/js/src/frontend/NameFunctions.cpp b/js/src/frontend/NameFunctions.cpp index 7d17c51bbb..bb4fd6319a 100644 --- a/js/src/frontend/NameFunctions.cpp +++ b/js/src/frontend/NameFunctions.cpp @@ -190,9 +190,8 @@ class NameResolver * listed, then it is skipped. Otherwise an intelligent name is guessed to * assign to the function's displayAtom field. */ - bool resolveFun(CodeNode* funNode, HandleAtom prefix, MutableHandleAtom retAtom) { + bool resolveFun(FunctionNode* funNode, HandleAtom prefix, MutableHandleAtom retAtom) { MOZ_ASSERT(funNode != nullptr); - MOZ_ASSERT(funNode->isKind(PNK_FUNCTION)); RootedFunction fun(cx, funNode->funbox()->function()); StringBuffer buf(cx); @@ -359,10 +358,9 @@ class NameResolver if (cur == nullptr) return true; - MOZ_ASSERT((cur->isKind(PNK_FUNCTION) || cur->isKind(PNK_MODULE)) == cur->is()); - if (cur->isKind(PNK_FUNCTION)) { + if (cur->is()) { RootedAtom prefix2(cx); - if (!resolveFun(&cur->as(), prefix, &prefix2)) + if (!resolveFun(&cur->as(), prefix, &prefix2)) return false; /* @@ -866,8 +864,14 @@ class NameResolver break; case PNK_FUNCTION: + if (ParseNode* body = cur->as().body()) { + if (!resolve(body, prefix)) + return false; + } + break; + case PNK_MODULE: - if (ParseNode* body = cur->as().body()) { + if (ParseNode* body = cur->as().body()) { if (!resolve(body, prefix)) return false; } diff --git a/js/src/frontend/ParseNode-inl.h b/js/src/frontend/ParseNode-inl.h index 0b8c87f929..9e77e8b1e9 100644 --- a/js/src/frontend/ParseNode-inl.h +++ b/js/src/frontend/ParseNode-inl.h @@ -16,9 +16,8 @@ namespace frontend { inline PropertyName* ParseNode::name() const { - MOZ_ASSERT(isKind(PNK_FUNCTION) || isKind(PNK_NAME)); - JSAtom* atom = isKind(PNK_FUNCTION) - ? as().funbox()->function()->explicitName() + JSAtom* atom = is() + ? as().funbox()->function()->explicitName() : as().atom(); return atom->asPropertyName(); } diff --git a/js/src/frontend/ParseNode.cpp b/js/src/frontend/ParseNode.cpp index 31efe76558..6a7e4681d7 100644 --- a/js/src/frontend/ParseNode.cpp +++ b/js/src/frontend/ParseNode.cpp @@ -94,7 +94,7 @@ class NodeStack { enum class PushResult { Recyclable, CleanUpLater }; static PushResult -PushCodeNodeChildren(CodeNode* node, NodeStack* stack) +PushFunctionNodeChildren(FunctionNode* node, NodeStack* stack) { /* * Function nodes are linked into the function box tree, and may appear @@ -121,6 +121,15 @@ PushCodeNodeChildren(CodeNode* node, NodeStack* stack) return PushResult::CleanUpLater; } +static PushResult +PushModuleNodeChildren(ModuleNode* node, NodeStack* stack) +{ + stack->push(node->body()); + node->setBody(nullptr); + + return PushResult::CleanUpLater; +} + static PushResult PushNameNodeChildren(NameNode* node, NodeStack* stack) { @@ -506,8 +515,9 @@ PushNodeChildren(ParseNode* pn, NodeStack* stack) return PushScopeNodeChildren(&pn->as(), stack); case PNK_FUNCTION: + return PushFunctionNodeChildren(&pn->as(), stack); case PNK_MODULE: - return PushCodeNodeChildren(&pn->as(), stack); + return PushModuleNodeChildren(&pn->as(), stack); case PNK_LIMIT: // invalid sentinel value MOZ_CRASH("invalid node kind"); @@ -677,9 +687,11 @@ ParseNode::dump(int indent) case PN_TERNARY: as().dump(indent); return; - case PN_CODE: - as().dump(indent); + case PN_FUNCTION: + as().dump(indent); return; + case PN_MODULE: + as().dump(indent); case PN_LIST: as().dump(indent); return; @@ -802,7 +814,17 @@ TernaryNode::dump(int indent) } void -CodeNode::dump(int indent) +FunctionNode::dump(int indent) +{ + const char* name = parseNodeNames[getKind()]; + fprintf(stderr, "(%s ", name); + indent += strlen(name) + 2; + DumpParseTree(body(), indent); + fprintf(stderr, ")"); +} + +void +ModuleNode::dump(int indent) { const char* name = parseNodeNames[getKind()]; fprintf(stderr, "(%s ", name); @@ -979,8 +1001,8 @@ js::frontend::IsAnonymousFunctionDefinition(ParseNode* pn) // 14.1.12 (FunctionExpression). // 14.4.8 (GeneratorExpression). // 14.6.8 (AsyncFunctionExpression) - if (pn->isKind(PNK_FUNCTION) && - !pn->as().funbox()->function()->explicitName()) + if (pn->is() && + !pn->as().funbox()->function()->explicitName()) return true; // 14.5.8 (ClassExpression) diff --git a/js/src/frontend/ParseNode.h b/js/src/frontend/ParseNode.h index 10b2e96906..a31e9d3731 100644 --- a/js/src/frontend/ParseNode.h +++ b/js/src/frontend/ParseNode.h @@ -221,7 +221,7 @@ IsTypeofKind(ParseNodeKind kind) /* * - * PNK_FUNCTION (CodeNode) + * PNK_FUNCTION (FunctionNode) * funbox: ptr to js::FunctionBox holding function object containing arg and * var properties. We create the function object at parse (not emit) * time to specialize arg and var bytecodes early. @@ -259,9 +259,8 @@ IsTypeofKind(ParseNodeKind kind) * PNK_CLASSMETHOD (ClassMethod) * name: propertyName * method: methodDefinition - * PNK_MODULE (CodeNode) - * funbox: ? - * body: ? + * PNK_MODULE (ModuleNode) + * body: statement list of the module * * * PNK_STATEMENTLIST (ListNode) @@ -546,7 +545,8 @@ enum ParseNodeArity PN_UNARY, /* one kid, plus a couple of scalars */ PN_BINARY, /* two kids, plus a couple of scalars */ PN_TERNARY, /* three kids */ - PN_CODE, /* module or function definition node */ + PN_FUNCTION, /* function definition node */ + PN_MODULE, /* module node */ PN_LIST, /* generic singly linked list */ PN_NAME, /* name, label, string */ PN_NUMBER, /* numeric literal */ @@ -568,7 +568,8 @@ enum ParseNodeArity macro(OptionalPropertyByValue, OptionalPropertyByValueType, asOptionalPropertyByValue) \ macro(SwitchStatement, SwitchStatementType, asSwitchStatement) \ \ - macro(CodeNode, CodeNodeType, asCode) \ + macro(FunctionNode, FunctionNodeType, asFunction) \ + macro(ModuleNode, ModuleNodeType, asModule) \ \ macro(LexicalScopeNode, LexicalScopeNodeType, asLexicalScope) \ \ @@ -734,10 +735,15 @@ class ParseNode } regexp; struct { private: - friend class CodeNode; - FunctionBox* funbox; /* function object */ - ParseNode* body; /* module or function body */ - } code; + friend class FunctionNode; + FunctionBox* funbox; + ParseNode* body; + } function; + struct { + private: + friend class ModuleNode; + ParseNode* body; + } module; struct { private: friend class LexicalScopeNode; @@ -1418,24 +1424,22 @@ ParseNode::isForLoopDeclaration() const return false; } -class CodeNode : public ParseNode +class FunctionNode : public ParseNode { public: - CodeNode(ParseNodeKind kind, JSOp op, const TokenPos& pos) - : ParseNode(kind, op, PN_CODE, pos) + FunctionNode(JSOp op, const TokenPos& pos) + : ParseNode(PNK_FUNCTION, op, PN_FUNCTION, pos) { - MOZ_ASSERT(kind == PNK_FUNCTION || kind == PNK_MODULE); - MOZ_ASSERT_IF(kind == PNK_MODULE, op == JSOP_NOP); MOZ_ASSERT(op == JSOP_NOP || // statement, module op == JSOP_LAMBDA_ARROW || // arrow function op == JSOP_LAMBDA); // expression, method, comprehension, accessor, &c. - MOZ_ASSERT(!pn_u.code.body); - MOZ_ASSERT(!pn_u.code.funbox); + MOZ_ASSERT(!pn_u.function.body); + MOZ_ASSERT(!pn_u.function.funbox); } static bool test(const ParseNode& node) { - bool match = node.isKind(PNK_FUNCTION) || node.isKind(PNK_MODULE); - MOZ_ASSERT_IF(match, node.isArity(PN_CODE)); + bool match = node.isKind(PNK_FUNCTION); + MOZ_ASSERT_IF(match, node.isArity(PN_FUNCTION)); return match; } @@ -1444,28 +1448,27 @@ class CodeNode : public ParseNode #endif FunctionBox* funbox() const { - return pn_u.code.funbox; + return pn_u.function.funbox; } ListNode* body() const { - return pn_u.code.body ? &pn_u.code.body->as() : nullptr; + return pn_u.function.body ? &pn_u.function.body->as() : nullptr; } void setFunbox(FunctionBox* funbox) { - pn_u.code.funbox = funbox; + pn_u.function.funbox = funbox; } void setBody(ListNode* body) { - pn_u.code.body = body; + pn_u.function.body = body; } // Methods used by FoldConstants.cpp. ParseNode** unsafeBodyReference() { - return &pn_u.code.body; + return &pn_u.function.body; } bool functionIsHoisted() const { - MOZ_ASSERT(isKind(PNK_FUNCTION)); MOZ_ASSERT(isOp(JSOP_LAMBDA) || // lambda isOp(JSOP_LAMBDA_ARROW) || // arrow function isOp(JSOP_NOP)); // body-level function stmt in global code @@ -1473,6 +1476,39 @@ class CodeNode : public ParseNode } }; +class ModuleNode : public ParseNode +{ + public: + ModuleNode(const TokenPos& pos) + : ParseNode(PNK_MODULE, JSOP_NOP, PN_MODULE, pos) + { + MOZ_ASSERT(!pn_u.module.body); + } + + static bool test(const ParseNode& node) { + bool match = node.isKind(PNK_MODULE); + MOZ_ASSERT_IF(match, node.isArity(PN_MODULE)); + return match; + } + +#ifdef DEBUG + void dump(int indent); +#endif + + ListNode* body() const { + return &pn_u.module.body->as(); + } + + void setBody(ListNode* body) { + pn_u.module.body = body; + } + + // Methods used by FoldConstants.cpp. + ParseNode** unsafeBodyReference() { + return &pn_u.module.body; + } +}; + class NumericLiteral : public ParseNode { public: @@ -2012,8 +2048,8 @@ class ClassMethod : public BinaryNode ParseNode& name() const { return *left(); } - CodeNode& method() const { - return right()->as(); + FunctionNode& method() const { + return right()->as(); } bool isStatic() const { return pn_u.binary.isStatic; @@ -2254,7 +2290,7 @@ static inline ParseNode* FunctionFormalParametersList(ParseNode* fn, unsigned* numFormals) { MOZ_ASSERT(fn->isKind(PNK_FUNCTION)); - ListNode* argsBody = fn->as().body(); + ListNode* argsBody = fn->as().body(); MOZ_ASSERT(argsBody->isKind(PNK_PARAMSBODY)); *numFormals = argsBody->count(); if (*numFormals > 0 && diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 24be7af2d2..e40e583745 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -907,7 +907,7 @@ Parser::newObjectBox(JSObject* obj) template FunctionBox* -Parser::newFunctionBox(CodeNodeType funNode, JSFunction* fun, uint32_t toStringStart, +Parser::newFunctionBox(FunctionNodeType funNode, JSFunction* fun, uint32_t toStringStart, Directives inheritedDirectives, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB) @@ -1124,7 +1124,7 @@ Parser::reportRedeclaration(HandlePropertyName name, DeclarationKi // forbid duplicates.) template bool -Parser::notePositionalFormalParameter(CodeNodeType funNode, HandlePropertyName name, +Parser::notePositionalFormalParameter(FunctionNodeType funNode, HandlePropertyName name, uint32_t beginPos, bool disallowDuplicateParams, bool* duplicatedParam) @@ -1169,7 +1169,7 @@ Parser::notePositionalFormalParameter(CodeNodeType funNode, Handle template bool -Parser::noteDestructuredPositionalFormalParameter(CodeNodeType funNode, Node destruct) +Parser::noteDestructuredPositionalFormalParameter(FunctionNodeType funNode, Node destruct) { // Append an empty name to the positional formals vector to keep track of // argument slots when making FunctionScope::Data. @@ -2220,7 +2220,7 @@ Parser::globalBody(GlobalSharedContext* globalsc) } template <> -CodeNode* +ModuleNode* Parser::moduleBody(ModuleSharedContext* modulesc) { MOZ_ASSERT(checkOptionsCalled); @@ -2233,7 +2233,7 @@ Parser::moduleBody(ModuleSharedContext* modulesc) if (!varScope.init(pc)) return nullptr; - CodeNodeType moduleNode = handler.newModule(); + ModuleNodeType moduleNode = handler.newModule(); if (!moduleNode) return null(); @@ -2294,7 +2294,7 @@ Parser::moduleBody(ModuleSharedContext* modulesc) } template <> -SyntaxParseHandler::CodeNodeType +SyntaxParseHandler::ModuleNodeType Parser::moduleBody(ModuleSharedContext* modulesc) { MOZ_ALWAYS_FALSE(abortIfSyntaxParser()); @@ -2510,7 +2510,7 @@ GetYieldHandling(GeneratorKind generatorKind) } template <> -CodeNode* +FunctionNode* Parser::standaloneFunction(HandleFunction fun, HandleScope enclosingScope, Maybe parameterListEnd, @@ -2547,7 +2547,7 @@ Parser::standaloneFunction(HandleFunction fun, tokenStream.ungetToken(); } - CodeNodeType funNode = handler.newFunctionStatement(); + FunctionNodeType funNode = handler.newFunctionStatement(); if (!funNode) return null(); @@ -2585,7 +2585,7 @@ Parser::standaloneFunction(HandleFunction fun, ParseNode* node = funNode; if (!FoldConstants(context, &node, this)) return null(); - funNode = &node->as(); + funNode = &node->as(); return funNode; } @@ -2960,7 +2960,7 @@ Parser::prefixAccessorName(PropertyType propType, HandleAtom propA template bool Parser::functionArguments(YieldHandling yieldHandling, FunctionSyntaxKind kind, - CodeNodeType funNode) + FunctionNodeType funNode) { FunctionBox* funbox = pc->functionBox(); @@ -3221,7 +3221,7 @@ Parser::functionArguments(YieldHandling yieldHandling, FunctionSyn template <> bool -Parser::skipLazyInnerFunction(CodeNode* funNode, uint32_t toStringStart, +Parser::skipLazyInnerFunction(FunctionNode* funNode, uint32_t toStringStart, FunctionSyntaxKind kind, bool tryAnnexB) { // When a lazily-parsed function is called, we only fully parse (and emit) @@ -3268,7 +3268,7 @@ Parser::skipLazyInnerFunction(CodeNode* funNode, uint32_t toSt template <> bool -Parser::skipLazyInnerFunction(CodeNodeType funNode, uint32_t toStringStart, +Parser::skipLazyInnerFunction(FunctionNodeType funNode, uint32_t toStringStart, FunctionSyntaxKind kind, bool tryAnnexB) { MOZ_CRASH("Cannot skip lazy inner functions when syntax parsing"); @@ -3344,8 +3344,8 @@ Parser::templateLiteral(YieldHandling yieldHandling) } template -typename ParseHandler::CodeNodeType -Parser::functionDefinition(uint32_t toStringStart, CodeNodeType funNode, InHandling inHandling, +typename ParseHandler::FunctionNodeType +Parser::functionDefinition(uint32_t toStringStart, FunctionNodeType funNode, InHandling inHandling, YieldHandling yieldHandling, HandleAtom funName, FunctionSyntaxKind kind, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, @@ -3419,7 +3419,7 @@ Parser::functionDefinition(uint32_t toStringStart, CodeNodeType fu template <> bool -Parser::trySyntaxParseInnerFunction(CodeNode* funNode, HandleFunction fun, +Parser::trySyntaxParseInnerFunction(FunctionNode* funNode, HandleFunction fun, uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, @@ -3494,7 +3494,7 @@ Parser::trySyntaxParseInnerFunction(CodeNode* funNode, HandleF template <> bool -Parser::trySyntaxParseInnerFunction(CodeNodeType funNode, HandleFunction fun, +Parser::trySyntaxParseInnerFunction(FunctionNodeType funNode, HandleFunction fun, uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, @@ -3512,7 +3512,7 @@ Parser::trySyntaxParseInnerFunction(CodeNodeType funNode, Ha template bool -Parser::innerFunction(CodeNodeType funNode, ParseContext* outerpc, FunctionBox* funbox, +Parser::innerFunction(FunctionNodeType funNode, ParseContext* outerpc, FunctionBox* funbox, uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, FunctionSyntaxKind kind, Directives inheritedDirectives, @@ -3536,7 +3536,7 @@ Parser::innerFunction(CodeNodeType funNode, ParseContext* outerpc, template bool -Parser::innerFunction(CodeNodeType funNode, ParseContext* outerpc, HandleFunction fun, +Parser::innerFunction(FunctionNodeType funNode, ParseContext* outerpc, HandleFunction fun, uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, FunctionSyntaxKind kind, @@ -3579,14 +3579,14 @@ Parser::appendToCallSiteObj(CallSiteNodeType callSiteObj) } template <> -CodeNode* +FunctionNode* Parser::standaloneLazyFunction(HandleFunction fun, bool strict, GeneratorKind generatorKind, FunctionAsyncKind asyncKind) { MOZ_ASSERT(checkOptionsCalled); - CodeNodeType funNode = handler.newFunctionStatement(); + FunctionNodeType funNode = handler.newFunctionStatement(); if (!funNode) return null(); @@ -3633,7 +3633,7 @@ Parser::standaloneLazyFunction(HandleFunction fun, bool strict ParseNode* node = funNode; if (!FoldConstants(context, &node, this)) return null(); - funNode = &node->as(); + funNode = &node->as(); return funNode; } @@ -3642,7 +3642,7 @@ template bool Parser::functionFormalParametersAndBody(InHandling inHandling, YieldHandling yieldHandling, - CodeNodeType funNode, FunctionSyntaxKind kind, + FunctionNodeType funNode, FunctionSyntaxKind kind, Maybe parameterListEnd /* = Nothing() */, bool isStandaloneFunction /* = false */) { @@ -3788,7 +3788,7 @@ Parser::functionFormalParametersAndBody(InHandling inHandling, } template -typename ParseHandler::CodeNodeType +typename ParseHandler::FunctionNodeType Parser::functionStmt(uint32_t toStringStart, YieldHandling yieldHandling, DefaultHandling defaultHandling, FunctionAsyncKind asyncKind) { @@ -3864,7 +3864,7 @@ Parser::functionStmt(uint32_t toStringStart, YieldHandling yieldHa return null(); } - CodeNodeType funNode = handler.newFunctionStatement(); + FunctionNodeType funNode = handler.newFunctionStatement(); if (!funNode) return null(); @@ -3874,7 +3874,7 @@ Parser::functionStmt(uint32_t toStringStart, YieldHandling yieldHa } template -typename ParseHandler::CodeNodeType +typename ParseHandler::FunctionNodeType Parser::functionExpr(uint32_t toStringStart, InvokedPrediction invoked, FunctionAsyncKind asyncKind) { @@ -3903,7 +3903,7 @@ Parser::functionExpr(uint32_t toStringStart, InvokedPrediction inv tokenStream.ungetToken(); } - CodeNodeType funNode = handler.newFunctionExpression(); + FunctionNodeType funNode = handler.newFunctionExpression(); if (!funNode) return null(); @@ -5369,14 +5369,14 @@ Parser::checkExportedNameForClause(NameNodeType nameNode) template<> bool -Parser::checkExportedNameForFunction(CodeNodeType funNode) +Parser::checkExportedNameForFunction(FunctionNodeType funNode) { return checkExportedName(funNode->funbox()->function()->explicitName()); } template<> bool -Parser::checkExportedNameForFunction(CodeNodeType funNode) +Parser::checkExportedNameForFunction(FunctionNodeType funNode) { MOZ_ALWAYS_FALSE(abortIfSyntaxParser()); return false; @@ -5650,7 +5650,7 @@ Parser::exportFunctionDeclaration(uint32_t begin) if (!kid) return null(); - if (!checkExportedNameForFunction(handler.asCode(kid))) + if (!checkExportedNameForFunction(handler.asFunction(kid))) return null(); UnaryNodeType node = handler.newExportDeclaration(kid, TokenPos(begin, pos().end)); @@ -7398,8 +7398,8 @@ Parser::classDefinition(YieldHandling yieldHandling, // Calling toString on constructors need to return the source text for // the entire class. The end offset is unknown at this point in // parsing and will be amended when class parsing finishes below. - CodeNodeType funNode = methodDefinition(isConstructor ? classStartOffset : nameOffset, - propType, funName); + FunctionNodeType funNode = methodDefinition(isConstructor ? classStartOffset : nameOffset, + propType, funName); if (!funNode) return null(); @@ -8395,7 +8395,7 @@ Parser::assignExpr(InHandling inHandling, YieldHandling yieldHandl } } - CodeNodeType funNode = handler.newArrowFunction(); + FunctionNodeType funNode = handler.newArrowFunction(); if (!funNode) return null(); @@ -8792,7 +8792,7 @@ template typename ParseHandler::Node Parser::generatorComprehensionLambda(unsigned begin) { - CodeNodeType genfn = handler.newFunctionExpression(); + FunctionNodeType genfn = handler.newFunctionExpression(); if (!genfn) return null(); @@ -10277,7 +10277,7 @@ Parser::objectLiteral(YieldHandling yieldHandling, PossibleError* } } - CodeNodeType funNode = methodDefinition(namePos.begin, propType, funName); + FunctionNodeType funNode = methodDefinition(namePos.begin, propType, funName); if (!funNode) return null(); @@ -10312,7 +10312,7 @@ Parser::objectLiteral(YieldHandling yieldHandling, PossibleError* } template -typename ParseHandler::CodeNodeType +typename ParseHandler::FunctionNodeType Parser::methodDefinition(uint32_t toStringStart, PropertyType propType, HandleAtom funName) { @@ -10365,7 +10365,7 @@ Parser::methodDefinition(uint32_t toStringStart, PropertyType prop YieldHandling yieldHandling = GetYieldHandling(generatorKind); - CodeNodeType funNode = handler.newFunctionExpression(); + FunctionNodeType funNode = handler.newFunctionExpression(); if (!funNode) return null(); diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 1a35f321fe..317b497334 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -1085,7 +1085,7 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) * cx->tempLifoAlloc. */ ObjectBox* newObjectBox(JSObject* obj); - FunctionBox* newFunctionBox(CodeNodeType funNode, JSFunction* fun, uint32_t toStringStart, + FunctionBox* newFunctionBox(FunctionNodeType funNode, JSFunction* fun, uint32_t toStringStart, Directives directives, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB); @@ -1138,23 +1138,23 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) ListNodeType globalBody(GlobalSharedContext* globalsc); // Parse a module. - CodeNodeType moduleBody(ModuleSharedContext* modulesc); + ModuleNodeType moduleBody(ModuleSharedContext* modulesc); // Parse a function, used for the Function, GeneratorFunction, and // AsyncFunction constructors. - CodeNodeType standaloneFunction(HandleFunction fun, HandleScope enclosingScope, - mozilla::Maybe parameterListEnd, - GeneratorKind generatorKind, FunctionAsyncKind asyncKind, - Directives inheritedDirectives, Directives* newDirectives); + FunctionNodeType standaloneFunction(HandleFunction fun, HandleScope enclosingScope, + mozilla::Maybe parameterListEnd, + GeneratorKind generatorKind, FunctionAsyncKind asyncKind, + Directives inheritedDirectives, Directives* newDirectives); // Parse a function, given only its arguments and body. Used for lazily // parsed functions. - CodeNodeType standaloneLazyFunction(HandleFunction fun, bool strict, - GeneratorKind generatorKind, FunctionAsyncKind asyncKind); + FunctionNodeType standaloneLazyFunction(HandleFunction fun, bool strict, + GeneratorKind generatorKind, FunctionAsyncKind asyncKind); // Parse an inner function given an enclosing ParseContext and a // FunctionBox for the inner function. - bool innerFunction(CodeNodeType funNode, ParseContext* outerpc, FunctionBox* funbox, uint32_t toStringStart, + bool innerFunction(FunctionNodeType funNode, ParseContext* outerpc, FunctionBox* funbox, uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, FunctionSyntaxKind kind, Directives inheritedDirectives, Directives* newDirectives); @@ -1162,7 +1162,7 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) // Parse a function's formal parameters and its body assuming its function // ParseContext is already on the stack. bool functionFormalParametersAndBody(InHandling inHandling, YieldHandling yieldHandling, - CodeNodeType funNode, FunctionSyntaxKind kind, + FunctionNodeType funNode, FunctionSyntaxKind kind, mozilla::Maybe parameterListEnd = mozilla::Nothing(), bool isStandaloneFunction = false); @@ -1188,11 +1188,11 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) * Some parsers have two versions: an always-inlined version (with an 'i' * suffix) and a never-inlined version (with an 'n' suffix). */ - CodeNodeType functionStmt(uint32_t toStringStart, - YieldHandling yieldHandling, DefaultHandling defaultHandling, - FunctionAsyncKind asyncKind = SyncFunction); - CodeNodeType functionExpr(uint32_t toStringStart, InvokedPrediction invoked = PredictUninvoked, - FunctionAsyncKind asyncKind = SyncFunction); + FunctionNodeType functionStmt(uint32_t toStringStart, + YieldHandling yieldHandling, DefaultHandling defaultHandling, + FunctionAsyncKind asyncKind = SyncFunction); + FunctionNodeType functionExpr(uint32_t toStringStart, InvokedPrediction invoked = PredictUninvoked, + FunctionAsyncKind asyncKind = SyncFunction); ListNodeType statementList(YieldHandling yieldHandling); @@ -1346,19 +1346,19 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) bool tryNewTarget(BinaryNodeType* newTarget); bool checkAndMarkSuperScope(); - CodeNodeType methodDefinition(uint32_t toStringStart, PropertyType propType, HandleAtom funName); + FunctionNodeType methodDefinition(uint32_t toStringStart, PropertyType propType, HandleAtom funName); /* * Additional JS parsers. */ bool functionArguments(YieldHandling yieldHandling, FunctionSyntaxKind kind, - CodeNodeType funNode); + FunctionNodeType funNode); - CodeNodeType functionDefinition(uint32_t toStringStart, CodeNodeType funNode, - InHandling inHandling, YieldHandling yieldHandling, HandleAtom name, - FunctionSyntaxKind kind, - GeneratorKind generatorKind, FunctionAsyncKind asyncKind, - bool tryAnnexB = false); + FunctionNodeType functionDefinition(uint32_t toStringStart, FunctionNodeType funNode, + InHandling inHandling, YieldHandling yieldHandling, HandleAtom name, + FunctionSyntaxKind kind, + GeneratorKind generatorKind, FunctionAsyncKind asyncKind, + bool tryAnnexB = false); // Parse a function body. Pass StatementListBody if the body is a list of // statements; pass ExpressionBody if the body is a single expression. @@ -1394,7 +1394,7 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) bool checkExportedNamesForDeclarationList(ListNodeType node); bool checkExportedNameForClause(NameNodeType funNode); - bool checkExportedNameForFunction(CodeNodeType funNode); + bool checkExportedNameForFunction(FunctionNodeType funNode); bool checkExportedNameForClass(ClassNodeType classNode); enum ClassContext { ClassStatement, ClassExpression }; @@ -1449,14 +1449,14 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) NameNodeType newDotGeneratorName(); bool declareDotGeneratorName(); - bool skipLazyInnerFunction(CodeNodeType funNode, uint32_t toStringStart, FunctionSyntaxKind kind, + bool skipLazyInnerFunction(FunctionNodeType funNode, uint32_t toStringStart, FunctionSyntaxKind kind, bool tryAnnexB); - bool innerFunction(CodeNodeType funNode, ParseContext* outerpc, HandleFunction fun, uint32_t toStringStart, + bool innerFunction(FunctionNodeType funNode, ParseContext* outerpc, HandleFunction fun, uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, FunctionSyntaxKind kind, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB, Directives inheritedDirectives, Directives* newDirectives); - bool trySyntaxParseInnerFunction(CodeNodeType funNode, HandleFunction fun, uint32_t toStringStart, + bool trySyntaxParseInnerFunction(FunctionNodeType funNode, HandleFunction fun, uint32_t toStringStart, InHandling inHandling, YieldHandling yieldHandling, FunctionSyntaxKind kind, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, @@ -1489,9 +1489,9 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) void reportRedeclaration(HandlePropertyName name, DeclarationKind prevKind, TokenPos pos, uint32_t prevPos); - bool notePositionalFormalParameter(CodeNodeType funNode, HandlePropertyName name, uint32_t beginPos, + bool notePositionalFormalParameter(FunctionNodeType funNode, HandlePropertyName name, uint32_t beginPos, bool disallowDuplicateParams, bool* duplicatedParam); - bool noteDestructuredPositionalFormalParameter(CodeNodeType funNode, Node destruct); + bool noteDestructuredPositionalFormalParameter(FunctionNodeType funNode, Node destruct); mozilla::Maybe isVarRedeclaredInEval(HandlePropertyName name, DeclarationKind kind); bool tryDeclareVar(HandlePropertyName name, DeclarationKind kind, uint32_t beginPos, diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 41e5e707a1..81eb0885b0 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.h @@ -395,7 +395,7 @@ class FunctionBox : public ObjectBox, public SharedContext void initWithEnclosingScope(Scope* enclosingScope); public: - CodeNode* functionNode; /* back pointer used by asm.js for error messages */ + FunctionNode* functionNode; /* back pointer used by asm.js for error messages */ uint32_t bufStart; uint32_t bufEnd; uint32_t startLine; diff --git a/js/src/frontend/SyntaxParseHandler.h b/js/src/frontend/SyntaxParseHandler.h index 6a69e41398..a8a8cf49f3 100644 --- a/js/src/frontend/SyntaxParseHandler.h +++ b/js/src/frontend/SyntaxParseHandler.h @@ -330,8 +330,8 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) MOZ_MUST_USE bool addPropertyDefinition(ListNodeType literal, Node name, Node expr) { return true; } MOZ_MUST_USE bool addShorthand(ListNodeType literal, NameNodeType name, NameNodeType expr) { return true; } MOZ_MUST_USE bool addSpreadProperty(ListNodeType literal, uint32_t begin, Node inner) { return true; } - MOZ_MUST_USE bool addObjectMethodDefinition(ListNodeType literal, Node name, CodeNodeType funNode, JSOp op) { return true; } - MOZ_MUST_USE bool addClassMethodDefinition(ListNodeType literal, Node name, CodeNodeType funNode, JSOp op, bool isStatic) { return true; } + MOZ_MUST_USE bool addObjectMethodDefinition(ListNodeType literal, Node name, FunctionNodeType funNode, JSOp op) { return true; } + MOZ_MUST_USE bool addClassMethodDefinition(ListNodeType literal, Node name, FunctionNodeType funNode, JSOp op, bool isStatic) { return true; } UnaryNodeType newYieldExpression(uint32_t begin, Node value) { return NodeGeneric; } UnaryNodeType newYieldStarExpression(uint32_t begin, Node value) { return NodeGeneric; } UnaryNodeType newAwaitExpression(uint32_t begin, Node value) { return NodeGeneric; } @@ -407,19 +407,19 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS) MOZ_MUST_USE bool addCatchBlock(ListNodeType catchList, LexicalScopeNodeType lexicalScope, Node catchBinding, Node catchGuard, Node catchBody) { return true; } - MOZ_MUST_USE bool setLastFunctionFormalParameterDefault(CodeNodeType funNode, Node pn) { return true; } + MOZ_MUST_USE bool setLastFunctionFormalParameterDefault(FunctionNodeType funNode, Node pn) { return true; } void checkAndSetIsDirectRHSAnonFunction(Node pn) {} - CodeNodeType newFunctionStatement() { return NodeFunctionDefinition; } - CodeNodeType newFunctionExpression() { return NodeFunctionDefinition; } - CodeNodeType newArrowFunction() { return NodeFunctionDefinition; } + FunctionNodeType newFunctionStatement() { return NodeFunctionDefinition; } + FunctionNodeType newFunctionExpression() { return NodeFunctionDefinition; } + FunctionNodeType newArrowFunction() { return NodeFunctionDefinition; } - bool setComprehensionLambdaBody(CodeNodeType funNode, ListNodeType body) { return true; } - void setFunctionFormalParametersAndBody(CodeNodeType funNode, ListNodeType paramsBody) {} - void setFunctionBody(CodeNodeType funNode, LexicalScopeNodeType body) {} - void setFunctionBox(CodeNodeType funNode, FunctionBox* funbox) {} - void addFunctionFormalParameter(CodeNodeType funNode, Node argpn) {} + bool setComprehensionLambdaBody(FunctionNodeType funNode, ListNodeType body) { return true; } + void setFunctionFormalParametersAndBody(FunctionNodeType funNode, ListNodeType paramsBody) {} + void setFunctionBody(FunctionNodeType funNode, LexicalScopeNodeType body) {} + void setFunctionBox(FunctionNodeType funNode, FunctionBox* funbox) {} + void addFunctionFormalParameter(FunctionNodeType funNode, Node argpn) {} ForNodeType newForStatement(uint32_t begin, TernaryNodeType forHead, Node body, unsigned iflags) { return NodeGeneric; diff --git a/js/src/wasm/AsmJS.cpp b/js/src/wasm/AsmJS.cpp index 1a5f4dbccb..f139316952 100644 --- a/js/src/wasm/AsmJS.cpp +++ b/js/src/wasm/AsmJS.cpp @@ -650,14 +650,14 @@ ElemIndex(ParseNode* pn) } static inline JSFunction* -FunctionObject(CodeNode* funNode) +FunctionObject(FunctionNode* funNode) { MOZ_ASSERT(funNode->isKind(PNK_FUNCTION)); return funNode->funbox()->function(); } static inline PropertyName* -FunctionName(CodeNode* funNode) +FunctionName(FunctionNode* funNode) { if (JSAtom* name = FunctionObject(funNode)->explicitName()) return name->asPropertyName(); @@ -665,7 +665,7 @@ FunctionName(CodeNode* funNode) } static inline ParseNode* -FunctionStatementList(CodeNode* funNode) +FunctionStatementList(FunctionNode* funNode) { MOZ_ASSERT(funNode->body()->isKind(PNK_PARAMSBODY)); LexicalScopeNode* last = &funNode->body()->as().last()->as(); @@ -1615,7 +1615,7 @@ class MOZ_STACK_CLASS ModuleValidator ExclusiveContext* cx_; AsmJSParser& parser_; - CodeNode* moduleFunctionNode_; + FunctionNode* moduleFunctionNode_; PropertyName* moduleFunctionName_; PropertyName* globalArgumentName_; PropertyName* importArgumentName_; @@ -1694,7 +1694,7 @@ class MOZ_STACK_CLASS ModuleValidator } public: - ModuleValidator(ExclusiveContext* cx, AsmJSParser& parser, CodeNode* moduleFunctionNode) + ModuleValidator(ExclusiveContext* cx, AsmJSParser& parser, FunctionNode* moduleFunctionNode) : cx_(cx), parser_(parser), moduleFunctionNode_(moduleFunctionNode), @@ -3226,7 +3226,7 @@ CheckModuleLevelName(ModuleValidator& m, ParseNode* usepn, PropertyName* name) } static bool -CheckFunctionHead(ModuleValidator& m, CodeNode* funNode) +CheckFunctionHead(ModuleValidator& m, FunctionNode* funNode) { FunctionBox* funbox = funNode->funbox(); MOZ_ASSERT(!funbox->isExprBody()); @@ -3266,7 +3266,7 @@ CheckModuleArgument(ModuleValidator& m, ParseNode* arg, PropertyName** name) } static bool -CheckModuleArguments(ModuleValidator& m, CodeNode* funNode) +CheckModuleArguments(ModuleValidator& m, FunctionNode* funNode) { unsigned numFormals; ParseNode* arg1 = FunctionFormalParametersList(funNode, &numFormals); @@ -7026,7 +7026,7 @@ CheckStatement(FunctionValidator& f, ParseNode* stmt) } static bool -ParseFunction(ModuleValidator& m, CodeNode** funNodeOut, unsigned* line) +ParseFunction(ModuleValidator& m, FunctionNode** funNodeOut, unsigned* line) { TokenStream& tokenStream = m.tokenStream(); @@ -7044,7 +7044,7 @@ ParseFunction(ModuleValidator& m, CodeNode** funNodeOut, unsigned* line) if (!name) return false; - CodeNode* funNode = m.parser().handler.newFunctionStatement(); + FunctionNode* funNode = m.parser().handler.newFunctionStatement(); if (!funNode) return false; @@ -7086,7 +7086,7 @@ CheckFunction(ModuleValidator& m) // the backing LifoAlloc after parsing/compiling each function. AsmJSParser::Mark mark = m.parser().mark(); - CodeNode* funNode = nullptr; + FunctionNode* funNode = nullptr; unsigned line = 0; if (!ParseFunction(m, &funNode, &line)) return false; @@ -7336,7 +7336,7 @@ CheckModule(ExclusiveContext* cx, AsmJSParser& parser, ParseNode* stmtList, unsi { int64_t before = PRMJ_Now(); - CodeNode* moduleFunctionNode = parser.pc->functionBox()->functionNode; + FunctionNode* moduleFunctionNode = parser.pc->functionBox()->functionNode; ModuleValidator m(cx, parser, moduleFunctionNode); if (!m.init()) @@ -8292,7 +8292,7 @@ class ModuleCharsForStore : ModuleChars isFunCtor_ = parser.pc->isStandaloneFunctionBody(); if (isFunCtor_) { unsigned numArgs; - CodeNode* functionNode = parser.pc->functionBox()->functionNode; + FunctionNode* functionNode = parser.pc->functionBox()->functionNode; ParseNode* arg = FunctionFormalParametersList(functionNode, &numArgs); for (unsigned i = 0; i < numArgs; i++, arg = arg->pn_next) { UniqueChars name = StringToNewUTF8CharsZ(nullptr, *arg->name()); @@ -8373,7 +8373,7 @@ class ModuleCharsForLookup : ModuleChars if (parseBegin + chars_.length() != parseLimit) return false; unsigned numArgs; - CodeNode* functionNode = parser.pc->functionBox()->functionNode; + FunctionNode* functionNode = parser.pc->functionBox()->functionNode; ParseNode* arg = FunctionFormalParametersList(functionNode, &numArgs); if (funCtorArgs_.length() != numArgs) return false;