#include "AtlasJsModule.hpp" #include "debug/DebugJsModule.hpp" #include "file_system/FsJsModule.hpp" #include "image/ImageJsModule.hpp" AtlasJsModule::AtlasJsModule(AtlasJsEngine* engine, QObject* parent) : QObject(parent) { // set the engine this->engine = engine; // load the submodules this->submodules[QStringLiteral("debug")] = std::make_shared(this->engine); this->submodules[QStringLiteral("fs")] = std::make_shared(this->engine); // this->submodules[QStringLiteral("image")] = std::make_shared(this->engine); // TODO(Faraphel): check if the filesystem is correctly restricted } QJSValue AtlasJsModule::require(const QString& name) const { std::shared_ptr submodule; try { // get the submodule from its name submodule = this->submodules.at(name); } catch (const std::out_of_range&) { // if not found, throw a Javascript error and return null this->engine->throwError( QJSValue::ReferenceError, QStringLiteral("the module \"") + name + QStringLiteral("\" does not exist.") ); return QJSValue(QJSPrimitiveNull()); } // return the module as a new javascript object return this->engine->newQObject(submodule.get()); } QJSValueList AtlasJsModule::getVersion() { // TODO(Faraphel): should be stored somewhere else. // TODO(Faraphel): The type should implement an easy comparison system, if possible QJSValueList version; version.append(1); version.append(0); version.append(0); return version; }