void WorkerContext::importScripts(const Vector<String>& urls, ExceptionCode& ec) { ec = 0; Vector<String>::const_iterator urlsEnd = urls.end(); Vector<KURL> completedURLs; for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it) { const KURL& url = scriptExecutionContext()->completeURL(*it); if (!url.isValid()) { ec = SYNTAX_ERR; return; } completedURLs.append(url); } Vector<KURL>::const_iterator end = completedURLs.end(); for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) { WorkerScriptLoader scriptLoader(ResourceRequestBase::TargetIsScript); scriptLoader.loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRequests); // If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps. if (scriptLoader.failed()) { ec = XMLHttpRequestException::NETWORK_ERR; return; } InspectorInstrumentation::scriptImported(scriptExecutionContext(), scriptLoader.identifier(), scriptLoader.script()); ScriptValue exception; m_script->evaluate(ScriptSourceCode(scriptLoader.script(), scriptLoader.responseURL()), &exception); if (!exception.hasNoValue()) { m_script->setException(exception); return; } } }
TEST_F(ScriptRunnerTest, QueueSingleScript_Async) { MockScriptLoader scriptLoader(m_element.get()); m_scriptRunner->queueScriptForExecution(&scriptLoader, ScriptRunner::ASYNC_EXECUTION); m_scriptRunner->notifyScriptReady(&scriptLoader, ScriptRunner::ASYNC_EXECUTION); EXPECT_CALL(scriptLoader, execute()); m_platform.runAllTasks(); }
TEST_F(ScriptRunnerTest, QueueSingleScript_InOrder) { MockScriptLoader scriptLoader(m_element.get()); m_scriptRunner->queueScriptForExecution(&scriptLoader, ScriptRunner::IN_ORDER_EXECUTION); m_scriptRunner->resume(); EXPECT_CALL(scriptLoader, isReady()).WillOnce(Return(true)); EXPECT_CALL(scriptLoader, execute()); m_platform.runAllTasks(); }
//------------------------------------------------------------------------ bool Engine::initializeEngine() { // give some info about the underlying engine NR_Log(Log::LOG_ENGINE | Log::LOG_CONSOLE | Log::LOG_KERNEL, (char*)"nrEngine v%s - %s", convertVersionToString(nrEngineVersion).c_str(), NR_VERSION_NAME); // initialize the clock SharedPtr<TimeSource> timeSource(new TimeSource()); // initialize profiler singleton _profiler = (new Profiler(timeSource)); if (_profiler == NULL) NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, (char*)"Profiler singleton could not be created. Probably memory is full"); // now add the clock into kernel _clock->setTimeSource(timeSource); _clock->setTaskType(TASK_SYSTEM); _kernel->AddTask(SharedPtr<ITask>(_clock, null_deleter()), ORDER_SYS_FIRST); // initialize resource manager singleton _event = (new EventManager()); if (_event == NULL) NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, (char*)"Event manager singleton could not be created. Probably memory is full"); _event->createChannel(NR_DEFAULT_EVENT_CHANNEL); _event->setTaskType(TASK_SYSTEM); _kernel->AddTask(SharedPtr<ITask>(_event, null_deleter()), ORDER_SYS_SECOND); // initialise default scripting methods DefaultScriptingFunctions::addMethods(); // initialize resource manager singleton _resmgr = (new ResourceManager()); if (_resmgr == NULL) NR_Log(Log::LOG_ENGINE, Log::LL_ERROR, (char*)"Resource manager singleton could not be created. Probably memory is full"); // Add the file reading functionality ResourceLoader fileLoader (new FileStreamLoader()); _resmgr->registerLoader((char*)"FileStreamLoader", fileLoader); // create an instance of plugin loader and add it to the resource manager ResourceLoader loader ( new PluginLoader() ); _resmgr->registerLoader((char*)"PluginLoader", loader); // create simple scripting language instancies ResourceLoader scriptLoader( new ScriptLoader() ); _resmgr->registerLoader((char*)"ScriptLoader", scriptLoader); return true; }
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; } } }
void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionCode& ec) { ASSERT(contentSecurityPolicy()); ec = 0; Vector<String>::const_iterator urlsEnd = urls.end(); Vector<KURL> completedURLs; for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it) { const KURL& url = scriptExecutionContext()->completeURL(*it); if (!url.isValid()) { ec = SYNTAX_ERR; return; } completedURLs.append(url); } Vector<KURL>::const_iterator end = completedURLs.end(); for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) { RefPtr<WorkerScriptLoader> scriptLoader(WorkerScriptLoader::create()); #if PLATFORM(BLACKBERRY) scriptLoader->setTargetType(ResourceRequest::TargetIsScript); #endif scriptLoader->loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRequests); // If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps. if (scriptLoader->failed()) { ec = XMLHttpRequestException::NETWORK_ERR; return; } InspectorInstrumentation::scriptImported(scriptExecutionContext(), scriptLoader->identifier(), scriptLoader->script()); ScriptValue exception; m_script->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader->responseURL()), &exception); if (!exception.hasNoValue()) { m_script->setException(exception); return; } } }
void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState& es) { ASSERT(contentSecurityPolicy()); Vector<String>::const_iterator urlsEnd = urls.end(); Vector<KURL> completedURLs; for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it) { const KURL& url = executionContext()->completeURL(*it); if (!url.isValid()) { es.throwDOMException(SyntaxError, "Failed to execute 'importScripts': the URL '" + *it + "' is invalid."); return; } completedURLs.append(url); } Vector<KURL>::const_iterator end = completedURLs.end(); for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) { RefPtr<WorkerScriptLoader> scriptLoader(WorkerScriptLoader::create()); scriptLoader->setTargetType(ResourceRequest::TargetIsScript); scriptLoader->loadSynchronously(executionContext(), *it, AllowCrossOriginRequests); // If the fetching attempt failed, throw a NetworkError exception and abort all these steps. if (scriptLoader->failed()) { es.throwDOMException(NetworkError, "Failed to execute 'importScripts': the script at '" + it->elidedString() + "' failed to load."); return; } InspectorInstrumentation::scriptImported(executionContext(), scriptLoader->identifier(), scriptLoader->script()); RefPtr<ErrorEvent> errorEvent; m_script->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader->responseURL()), &errorEvent); if (errorEvent) { m_script->rethrowExceptionFromImportedScript(errorEvent.release()); return; } } }