Skip to content

Commit d19ab0d

Browse files
refactor: move JavaScript thread initialization to a separate function
1 parent 2b63676 commit d19ab0d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/shell/script/script.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <thread>
1919
#include <unordered_set>
2020

21-
2221
#include "FileWatch.hpp"
2322
#include "quickjs.h"
2423
#include "quickjspp.hpp"
@@ -152,12 +151,7 @@ void script_context::watch_folder(const std::filesystem::path &path,
152151
js_thread.emplace(
153152
[&, this]() {
154153
try {
155-
is_thread_js_main = true;
156-
set_thread_locale_utf8();
157-
rt = std::make_shared<qjs::Runtime>();
158-
JS_UpdateStackTop(rt->rt);
159-
js = std::make_shared<qjs::Context>(*rt);
160-
154+
init_js_thread();
161155
bind();
162156
try {
163157
JS_UpdateStackTop(rt->rt);
@@ -311,6 +305,13 @@ void script_context::watch_folder(const std::filesystem::path &path,
311305
}
312306
}
313307

308+
void script_context::init_js_thread() {
309+
is_thread_js_main = true;
310+
set_thread_locale_utf8();
311+
rt = std::make_shared<qjs::Runtime>();
312+
JS_UpdateStackTop(rt->rt);
313+
js = std::make_shared<qjs::Context>(*rt);
314+
}
314315
} // namespace mb_shell
315316

316317
extern "C" void qjs_notify_job_enqueued(JSContext *jsctx) {

src/shell/script/script.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct script_context {
2525
void bind();
2626
void run_event_loop();
2727
void stop();
28+
void init_js_thread();
2829

2930
void watch_folder(
3031
const std::filesystem::path &path,

0 commit comments

Comments
 (0)