Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-25328

.mjs files do not hit breakpoints

    XMLWordPrintable

Details

    • e124ca962d20670d2f588352a129e73e72da099f (qt-creator/qt-creator/master)

    Description

      *.mjs files cannot be debugged. More accurately, you won’t hit a breakpoint set in one but you can step into a *.mjs.

      Here are the 2 most relevant methods from our scripting implementation.  In RunScriptSlot, you can see how it runs *.js and *.mjs scripts differently.  Generally speaking, we want to use *.mjs for everything, but I can only get breakpoints to work if I change the top level *.mjs script to a *.js and remove the “export” key words and the “function main() {…}” wrapper around the body of the script.  We want to use *.mjs  because we need scripts to import functions from lower level scripts and this is the only way I have been able to achieve that.

       

      void ScriptingWorker::SetupEngine()
      {
          myEngine_ = new QJSEngine(this);
          api_obj_->SetEngine(myEngine_);
          myEngine_->installExtensions(QJSEngine::AllExtensions);
          auto api_js_obj = myEngine_->newQObject(api_obj_);
          myEngine_->globalObject().setProperty("api", api_js_obj); //allow scripts to use this object's signals
          QString command_file = /*temp.join("/") +*/ ":/array_cmd/ArrayCommandApiTB34A.mjs";
          command_file.remove("file://");
          QJSValue module = myEngine_->importModule(command_file);
          myEngine_->globalObject().setProperty("ArrayCommand",  module);
          if (module.isError())
          {
              qDebug()
                      << "ScriptingApi::import  Uncaught exception at line"
                      << module.property("lineNumber").toInt()
                      << ":" << module.toString();
          }
      }
      
      void ScriptingWorker::RunScriptSlot(QUrl path)
      {    script_running_ = true;
          QString script_file_name = path.toString();    //We want to create a folder to hold the recordings created by the script being run.
          //These help direct everything to the right paces
          GetApi()->script_file_basename_ = path.fileName().remove(".mjs") + QDateTime::currentDateTime().toString("_MM_dd_yyyy__hh_mm_ss");
          QString folder_name = GetApi()->recording_uut_path_ + "/" + GetApi()->script_file_basename_; // Want to create a directory named after the script thats being run
          emit
          QDir temp;
          temp.mkpath(folder_name.remove("file://"));    //start table recording
          current_table_record_ = GetApi()->recording_uut_path_ + "/" + GetApi()->script_file_basename_ + "/" + QDateTime::currentDateTime().toString("'table'_MM_dd_yyyy__hh_mm_ss") + ".cts";
          emit StartTableRecording(current_table_record_);    QVariant qvar;
          QVariantMap qmap;
          qmap["id"] = "single_cycle";
          qmap["arg"] = "true";
          QVariantMap qmap_wrapper;
          qmap_wrapper["cmd"] = QVariant::fromValue(qmap);
          qvar = QVariant::fromValue(qmap_wrapper);    CommandSlot(QVariant::fromValue(qvar));    script_file_name.remove("file://");
          GetApi()->preTestUserInput();
          if (script_file_name.contains(".mjs"))
          {
             QJSValue top = api_obj_->import("top", script_file_name);
             top.property("main").call();
          }
          else  //script must be *.js
          {
             QFile scriptFile(script_file_name);
             if (!scriptFile.open(QIODevice::ReadOnly))
                 qDebug()<< "Could not open " << path << "\n";
             QTextStream stream(&scriptFile);
             QString contents = stream.readAll();
             scriptFile.close();
             QJSValue result = myEngine_->evaluate(contents, script_file_name);
          }    if(this->GetApi()->getTestStatus()) {
             GetApi()->setTestStatus(false); //If the script was aborted during the course of the script running, reset the flag for the next script       QVariant qvar = "script aborted";
             emit progress(qvar);       QVariantList qlist;
             QVariantMap qmap;
             qmap["Test Description"] = "Aborted";
             qmap["Test Result"] = "Aborted";
             qlist.push_back(qmap);       emit UserInputComplete(QVariant::fromValue(qlist));
          }
          GetApi()->postTestUserInput();    api_obj_->dropimport("top");    emit StopTableRecording();
          script_running_ = false;
          emit exportSignal("file://" + folder_name, "");
      }
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            max.goldstein Maximilian Goldstein
            pendletonic Corey Pendleton
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes