0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-02-18 01:30:12 +01:00

ircd::js: Improve off-thread compilation error handling.

This commit is contained in:
Jason Volk 2016-11-06 23:13:59 -08:00
parent c8402577c3
commit 559bc530c8
2 changed files with 14 additions and 2 deletions

View file

@ -100,7 +100,8 @@ script<L>::script(yielding_t,
// still be able to run.
auto future(compile_async(opts, src));
void *const token(future.get());
return JS::FinishOffThreadScript(*cx, *rt, token);
return token? JS::FinishOffThreadScript(*cx, *rt, token):
script(opts, src).get();
}()}
{
if(unlikely(!this->get()))

View file

@ -239,7 +239,7 @@ try
// TODO: options
JS::CompileOptions opts(*cx);
opts.forceAsync = true;
//opts.forceAsync = true;
// The function must be compiled in this scope and returned as a heap_function
// before the compartment destructs. The compilation is also conducted asynchronously:
@ -1162,6 +1162,17 @@ ircd::js::compile_async(const JS::ReadOnlyCompileOptions &opts,
const std::u16string &src)
{
auto promise(std::make_unique<ctx::promise<void *>>());
if(!JS::CanCompileOffThread(*cx, opts, src.size()))
{
log.warning("Context(%p): Rejected asynchronous script compile (script size: %zu)",
(const void *)cx,
src.size());
ctx::future<void *> ret(*promise);
promise->set_value(nullptr);
return ret;
}
if(!JS::CompileOffThread(*cx, opts, src.data(), src.size(), handle_compile_async, promise.get()))
throw internal_error("Failed to compile concurrent script");