-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript_runner.h
More file actions
45 lines (38 loc) · 1.7 KB
/
Copy pathjavascript_runner.h
File metadata and controls
45 lines (38 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include "embedded_runner.h"
#include <QMutex>
// ─────────────────────────────────────────────────────────────────────────────
// JavascriptRunner — runs Javascript in-process.
//
// Output capture:
// Output is captured and returned in the Result object.
//
// Stdin injection:
// Stdin is handled via provided input string.
//
// Interpreter lifecycle:
// The interpreter stays alive for the lifetime of the JavascriptRunner object.
//
// IMPORTANT: only create ONE JavascriptRunner per process.
//
// Thread safety:
// m_mutex serialises all calls.
// ─────────────────────────────────────────────────────────────────────────────
class JavascriptRunner : public EmbeddedRunner
{
public:
// Initialises the interpreter. Call once per process.
explicit JavascriptRunner();
// Finalises the interpreter. Do not create another after this.
~JavascriptRunner() override;
Result execute(const QString &code,
const QString &stdinInput = "",
volatile bool *abort = nullptr,
const QMap<QString, QString> &additionalFiles = {}) override;
QString languageId() const override { return QStringLiteral("javascript"); }
QString languageName() const override { return QStringLiteral("Javascript"); }
bool isInitialised() const { return m_initialised; }
private:
bool m_initialised = false;
QMutex m_mutex;
};