コード例 #1
0
void CodeEditor::clear() {

    setPlainText("");
    script_filename = "no_name";
    emit scriptLoaded();

}
コード例 #2
0
bool CodeEditor::load(QString filename) {
    if (filename.isEmpty()) {
        filename = QString(".lua");
        filename = QFileDialog::getOpenFileName(this, "Open a script",
                                                script_filename, "lua source (*.lua);;All files (*)");
        if (filename.isEmpty())
            return false;
    }

    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly)) {

        /*
    QMessageBox::warning(this, tr("Application error"),
                         tr("Cannot read file %1\n").arg(filename));
    */
        return false;
    }

    QTextStream os(&file);
    QString p = os.readAll();
    file.close();
    setPlainText(p);
    script_filename = filename;
    emit scriptLoaded();

    return true;
}
コード例 #3
0
void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState& exceptionState)
{
    ASSERT(contentSecurityPolicy());
    ASSERT(getExecutionContext());

    ExecutionContext& executionContext = *this->getExecutionContext();

    Vector<KURL> completedURLs;
    for (const String& urlString : urls) {
        const KURL& url = executionContext.completeURL(urlString);
        if (!url.isValid()) {
            exceptionState.throwDOMException(SyntaxError, "The URL '" + urlString + "' is invalid.");
            return;
        }
        if (!contentSecurityPolicy()->allowScriptFromSource(url)) {
            exceptionState.throwDOMException(NetworkError, "The script at '" + url.elidedString() + "' failed to load.");
            return;
        }
        completedURLs.append(url);
    }

    for (const KURL& completeURL : completedURLs) {
        RefPtr<WorkerScriptLoader> scriptLoader(WorkerScriptLoader::create());
        scriptLoader->setRequestContext(WebURLRequest::RequestContextScript);
        scriptLoader->loadSynchronously(executionContext, completeURL, AllowCrossOriginRequests, executionContext.securityContext().addressSpace());

        // If the fetching attempt failed, throw a NetworkError exception and abort all these steps.
        if (scriptLoader->failed()) {
            exceptionState.throwDOMException(NetworkError, "The script at '" + completeURL.elidedString() + "' failed to load.");
            return;
        }

        InspectorInstrumentation::scriptImported(&executionContext, scriptLoader->identifier(), scriptLoader->script());
        scriptLoaded(scriptLoader->script().length(), scriptLoader->cachedMetadata() ? scriptLoader->cachedMetadata()->size() : 0);

        RawPtr<ErrorEvent> errorEvent = nullptr;
        OwnPtr<Vector<char>> cachedMetaData(scriptLoader->releaseCachedMetadata());
        RawPtr<CachedMetadataHandler> handler(createWorkerScriptCachedMetadataHandler(completeURL, cachedMetaData.get()));
        m_scriptController->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader->responseURL()), &errorEvent, handler.get(), m_v8CacheOptions);
        if (errorEvent) {
            m_scriptController->rethrowExceptionFromImportedScript(errorEvent.release(), exceptionState);
            return;
        }
    }
}
コード例 #4
0
ファイル: ScriptEngine.cpp プロジェクト: CiaranLaval/hifi
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
    if (_isRunning) {
        return;
    }

    _fileNameString = scriptURL.toString();
    _isReloading = reload;

    QUrl url(scriptURL);

    // if the scheme length is one or lower, maybe they typed in a file, let's try
    const int WINDOWS_DRIVE_LETTER_SIZE = 1;
    if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
        url = QUrl::fromLocalFile(_fileNameString);
    }

    // ok, let's see if it's valid... and if so, load it
    if (url.isValid()) {
        if (url.scheme() == "file") {
            _fileNameString = url.toLocalFile();
            QFile scriptFile(_fileNameString);
            if (scriptFile.open(QFile::ReadOnly | QFile::Text)) {
                qCDebug(scriptengine) << "ScriptEngine loading file:" << _fileNameString;
                QTextStream in(&scriptFile);
                _scriptContents = in.readAll();
                emit scriptLoaded(_fileNameString);
            } else {
                qCDebug(scriptengine) << "ERROR Loading file:" << _fileNameString << "line:" << __LINE__;
                emit errorLoadingScript(_fileNameString);
            }
        } else {
            bool isPending;
            auto scriptCache = DependencyManager::get<ScriptCache>();
            scriptCache->getScript(url, this, isPending, reload);
        }
    }
}
コード例 #5
0
ファイル: ScriptEngine.cpp プロジェクト: CiaranLaval/hifi
void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {
    _scriptContents = scriptContents;
    emit scriptLoaded(_fileNameString);
}