WorkerOrWorkletScriptController.h [plain text]
#pragma once
#include "WorkerThreadType.h"
#include <JavaScriptCore/Debugger.h>
#include <JavaScriptCore/JSRunLoopTimer.h>
#include <wtf/Forward.h>
#include <wtf/Lock.h>
#include <wtf/NakedPtr.h>
namespace JSC {
class VM;
}
namespace JSC {
class JSGlobalObject;
}
namespace WebCore {
class JSDOMGlobalObject;
class ScriptSourceCode;
class WorkerConsoleClient;
class WorkerOrWorkletGlobalScope;
class WorkerOrWorkletScriptController {
WTF_MAKE_NONCOPYABLE(WorkerOrWorkletScriptController);
WTF_MAKE_FAST_ALLOCATED;
public:
WorkerOrWorkletScriptController(WorkerThreadType, Ref<JSC::VM>&&, WorkerOrWorkletGlobalScope*);
explicit WorkerOrWorkletScriptController(WorkerThreadType, WorkerOrWorkletGlobalScope*);
~WorkerOrWorkletScriptController();
void releaseHeapAccess();
void acquireHeapAccess();
void addTimerSetNotification(JSC::JSRunLoopTimer::TimerNotificationCallback);
void removeTimerSetNotification(JSC::JSRunLoopTimer::TimerNotificationCallback);
JSDOMGlobalObject* globalScopeWrapper()
{
initScriptIfNeeded();
return m_globalScopeWrapper.get();
}
void attachDebugger(JSC::Debugger*);
void detachDebugger(JSC::Debugger*);
void scheduleExecutionTermination();
bool isTerminatingExecution() const;
void forbidExecution();
bool isExecutionForbidden() const;
JSC::VM& vm() { return *m_vm; }
void setException(JSC::Exception*);
void disableEval(const String& errorMessage);
void disableWebAssembly(const String& errorMessage);
void evaluate(const ScriptSourceCode&, String* returnedExceptionMessage = nullptr);
void evaluate(const ScriptSourceCode&, NakedPtr<JSC::Exception>& returnedException, String* returnedExceptionMessage = nullptr);
protected:
WorkerOrWorkletGlobalScope* globalScope() const { return m_globalScope; }
void initScriptIfNeeded()
{
if (!m_globalScopeWrapper)
initScript();
}
WEBCORE_EXPORT void initScript();
private:
template<typename JSGlobalScopePrototype, typename JSGlobalScope, typename GlobalScope>
void initScriptWithSubclass();
RefPtr<JSC::VM> m_vm;
WorkerOrWorkletGlobalScope* m_globalScope;
JSC::Strong<JSDOMGlobalObject> m_globalScopeWrapper;
std::unique_ptr<WorkerConsoleClient> m_consoleClient;
mutable Lock m_scheduledTerminationMutex;
bool m_executionForbidden { false };
bool m_isTerminatingExecution { false };
};
}