diff --git a/include/ircd/js/trap.h b/include/ircd/js/trap.h index da32ed7a8..908153585 100644 --- a/include/ircd/js/trap.h +++ b/include/ircd/js/trap.h @@ -72,11 +72,12 @@ class trap auto &name() const { return _name; } auto &jsclass() const { return *_class; } - // Search for trap by relative path + // Get child by name (NOT PATH) const trap &child(const string &name) const; trap &child(const string &name); // Path is absolute to root + static trap &find(const string::handle &path); static trap &find(const std::string &path); operator const JSClass &() const { return jsclass(); } diff --git a/ircd/js.cc b/ircd/js.cc index f5ba4202d..5332bc215 100644 --- a/ircd/js.cc +++ b/ircd/js.cc @@ -465,6 +465,22 @@ ircd::js::trap::find(const std::string &path) return *ret; } +ircd::js::trap & +ircd::js::trap::find(const string::handle &path) +{ + if(unlikely(!tree)) + throw error("Failed to find trap tree root"); + + trap *ret(tree); + tokens(string(path), '.', basic::string_closure([&ret] + (const string &part) + { + ret = &ret->child(part); + })); + + return *ret; +} + ircd::js::trap & ircd::js::trap::child(const string &name) try