Skip to content

Commit

Permalink
WIP. Port to QuickJS-NG
Browse files Browse the repository at this point in the history
Change-Id: Ia6f7b2113743b832cff6b2b81e5b3027d0e09fda
  • Loading branch information
ABBAPOH committed Jan 8, 2025
1 parent 371a3b6 commit 8ac3b53
Show file tree
Hide file tree
Showing 23 changed files with 14,974 additions and 13,915 deletions.
2 changes: 1 addition & 1 deletion src/lib/corelib/buildgraph/rulecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void AbstractCommand::applyCommandProperties(JSContext *ctx, const JSValue *scri
if (m_predefinedProperties.contains(name))
return;
// TODO: Use script class for command objects, don't allow setting random properties
if (!isSimpleValue(desc.value)) {
if (!JS_IsSimpleValue(ctx, desc.value)) {
throw ErrorInfo(Tr::tr("Property '%1' has a type unsuitable for storing in a command "
"object.").arg(name), m_codeLocation);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/corelib/language/scriptengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void ScriptEngine::checkContext(const QString &operation,
if (!m_evalPositions.empty()) {
const JSValue exVal = JS_NewObject(m_context);
const auto &[file, line] = m_evalPositions.top();
build_backtrace(m_context, exVal, file.toUtf8().constData(), line, 0);
JS_BuildBacktrace(m_context, exVal, JS_UNDEFINED, file.toUtf8().constData(), line, 0, 0);
const JsException ex(m_context, exVal, {});
m_logger.printWarning(ErrorInfo(warning, ex.stackTrace()));
} else {
Expand Down Expand Up @@ -871,7 +871,7 @@ JSClassID ScriptEngine::registerClass(const char *name, JSClassCall *constructor
JSClassID id = 0;
const auto classIt = m_classes.constFind(QLatin1String(name));
if (classIt == m_classes.constEnd()) {
JS_NewClassID(&id);
JS_NewClassID(m_jsRuntime, &id);
const auto it = getProperty
? m_exoticMethods.insert(id, JSClassExoticMethods{getProperty, getPropertyNames})
: m_exoticMethods.end();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/corelib/tools/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ ErrorInfo::ErrorInfo(const QString &description, const QStringList &backtrace)
for (const QString &traceLine : backtrace) {
if (traceLine.contains(QStringLiteral("<eval>")))
continue;
static const std::regex regexpWithFunc("^(.+) at [^(]*\\((.+):(\\-?[0-9]+)\\)$");
static const std::regex regexpWithoutFunc("^(.+) at (.+):(\\-?[0-9]+)$");
static const std::regex regexpWithFunc("^(.+) at [^(]*\\((.+):(\\-?[0-9]+):(\\-?[0-9]+)\\)$");
static const std::regex regexpWithoutFunc("^(.+) at (.+):(\\-?[0-9]+):(\\-?[0-9]+)$");
std::smatch match;
const std::string tl = traceLine.toStdString();
bool hasMatch = std::regex_match(tl, match, regexpWithFunc);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/corelib/tools/scripttools.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class QBS_AUTOTEST_EXPORT JsException
JsException(const JsException &) = delete;
JsException &operator=(const JsException &) = delete;

operator bool() const { return !JS_IsNull(m_exception); }
operator bool() const { return m_exception.tag != JS_TAG_UNINITIALIZED; }
QString message() const;
const QStringList stackTrace() const;
ErrorInfo toErrorInfo() const;
Expand Down
1 change: 1 addition & 0 deletions src/shared/quickjs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_qbs_library(qbsquickjs
libunicode.c libunicode.h
list.h
quickjs-atom.h
quickjs-c-atomics.h
quickjs-opcode.h
quickjs.c quickjs.h
DEFINES
Expand Down
Loading

0 comments on commit 8ac3b53

Please sign in to comment.