From 3fcd3d2bb03db45e55baec859d60b574e733f075 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 30 Oct 2016 05:57:10 -0700 Subject: [PATCH] ircd::js: Trap find() overload with JSString type. --- include/ircd/js/trap.h | 3 ++- ircd/js.cc | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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