0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::js: Add reflection and decompilation at the task level.

This commit is contained in:
Jason Volk 2016-11-24 19:17:04 -08:00
parent fb06cd3567
commit fbbe8e604a
2 changed files with 22 additions and 0 deletions

View file

@ -58,6 +58,9 @@ struct task
static task &get();
};
string decompile(const task &, const bool &pretty = false);
object reflect(const task &);
inline task &
task::get()
{

View file

@ -380,6 +380,24 @@ ircd::js::task::tasks_next_pid()
return tasks.empty()? 0 : std::prev(std::end(tasks))->first + 1;
}
ircd::js::object
ircd::js::reflect(const task &task)
{
object ret;
const object global(task.global);
const object reflect(get(global, "Reflect"));
const function parse(get(reflect, "parse"));
ret = parse(global, decompile(task));
return ret;
}
ircd::js::string
ircd::js::decompile(const task &task,
const bool &pretty)
{
return decompile(task.main, "main", pretty);
}
///////////////////////////////////////////////////////////////////////////////
//
// ircd/js/global.h
@ -398,6 +416,7 @@ ircd::js::global::global(trap &trap,
if(!JS_InitStandardClasses(*cx, *this))
throw error("Failed to init standard classes for global object");
JS_InitReflectParse(*cx, *this);
JS_FireOnNewGlobalObject(*cx, *this);
}