Bug 1620999 - Part 8: Assign FunctionTree's box in the constructor. r=mgaudet

That way we don't need the extra `setFunctionBox()` method and with part 6 it's
now easier to spot that `FunctionTree::funbox_` doesn't change after construction.

Differential Revision: https://phabricator.services.mozilla.com/D66055

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2020-03-10 19:07:52 +00:00
parent 338b69f020
commit 6ec8c529d1
2 changed files with 6 additions and 7 deletions

View File

@ -26,21 +26,21 @@ class FunctionTree {
Vector<FunctionTree> children_;
public:
explicit FunctionTree(JSContext* cx) : funbox_(nullptr), children_(cx) {}
FunctionTree(JSContext* cx, FunctionBox* funbox)
: funbox_(funbox), children_(cx) {}
// Note: If we're using vector type, the pointer returned here
// is only valid if the tree is only added to in DFS order
//
// Open to suggestions about how to do that better.
FunctionTree* add(JSContext* cx) {
if (!children_.emplaceBack(cx)) {
FunctionTree* add(JSContext* cx, FunctionBox* funbox) {
if (!children_.emplaceBack(cx, funbox)) {
return nullptr;
}
return &children_.back();
}
FunctionBox* funbox() { return funbox_; }
void setFunctionBox(FunctionBox* node) { funbox_ = node; }
using FunctionTreeVisitorFunction = bool (*)(ParserBase*, FunctionTree*);
bool visitRecursively(JSContext* cx, ParserBase* parser,
@ -76,7 +76,7 @@ class FunctionTreeHolder {
public:
explicit FunctionTreeHolder(JSContext* cx)
: treeRoot_(cx), currentParent_(&treeRoot_) {}
: treeRoot_(cx, nullptr), currentParent_(&treeRoot_) {}
FunctionTree* getFunctionTree() { return &treeRoot_; }
FunctionTree* getCurrentParent() { return currentParent_; }

View File

@ -2670,11 +2670,10 @@ AutoPushTree::AutoPushTree(FunctionTreeHolder& holder)
bool AutoPushTree::init(JSContext* cx, FunctionBox* funbox) {
// Add a new child, and set it as the current parent.
FunctionTree* child = holder_.getCurrentParent()->add(cx);
FunctionTree* child = holder_.getCurrentParent()->add(cx, funbox);
if (!child) {
return false;
}
child->setFunctionBox(funbox);
holder_.setCurrentParent(child);
return true;
}