| Index: Source/core/workers/WorkerThread.cpp
|
| diff --git a/Source/core/workers/WorkerThread.cpp b/Source/core/workers/WorkerThread.cpp
|
| index ff101dd1e8a5f4749ca24b0bb1e505e6c8bed7e5..e30c938f27ada5d160dce055e1aae694f1625ede 100644
|
| --- a/Source/core/workers/WorkerThread.cpp
|
| +++ b/Source/core/workers/WorkerThread.cpp
|
| @@ -29,8 +29,6 @@
|
| #include "core/workers/WorkerThread.h"
|
|
|
| #include "bindings/core/v8/ScriptSourceCode.h"
|
| -#include "bindings/core/v8/V8GCController.h"
|
| -#include "bindings/core/v8/V8Initializer.h"
|
| #include "core/dom/Microtask.h"
|
| #include "core/inspector/InspectorInstrumentation.h"
|
| #include "core/inspector/WorkerInspectorController.h"
|
| @@ -256,7 +254,6 @@ WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, Work
|
| , m_workerLoaderProxy(workerLoaderProxy)
|
| , m_workerReportingProxy(workerReportingProxy)
|
| , m_webScheduler(nullptr)
|
| - , m_isolate(nullptr)
|
| , m_shutdownEvent(adoptPtr(Platform::current()->createWaitableEvent()))
|
| , m_terminationEvent(adoptPtr(Platform::current()->createWaitableEvent()))
|
| {
|
| @@ -315,9 +312,10 @@ void WorkerThread::initialize(PassOwnPtr<WorkerThreadStartupData> startupData)
|
|
|
| m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this));
|
| backingThread().addTaskObserver(m_microtaskRunner.get());
|
| - backingThread().initialize();
|
| + initializeBackingThread();
|
|
|
| - m_isolate = initializeIsolate();
|
| + // Make sure the isolate is intialized correctly.
|
| + m_isolateWrapper = createIsolateWrapper();
|
| m_workerGlobalScope = createWorkerGlobalScope(startupData);
|
| m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.get() ? cachedMetaData->size() : 0);
|
|
|
| @@ -358,7 +356,7 @@ void WorkerThread::shutdown()
|
|
|
| PlatformThreadData::current().threadTimers().setSharedTimer(nullptr);
|
| workerGlobalScope()->dispose();
|
| - willDestroyIsolate();
|
| + m_isolateWrapper->willDestroy();
|
|
|
| // This should be called before we start the shutdown procedure.
|
| workerReportingProxy().willDestroyWorkerGlobalScope();
|
| @@ -373,8 +371,8 @@ void WorkerThread::shutdown()
|
| m_workerGlobalScope = nullptr;
|
|
|
| backingThread().removeTaskObserver(m_microtaskRunner.get());
|
| - backingThread().shutdown();
|
| - destroyIsolate();
|
| + shutdownBackingThread();
|
| + m_isolateWrapper.clear();
|
|
|
| m_microtaskRunner = nullptr;
|
|
|
| @@ -457,6 +455,21 @@ void WorkerThread::didStopRunLoop()
|
| Platform::current()->didStopWorkerRunLoop();
|
| }
|
|
|
| +v8::Isolate* WorkerThread::isolate()
|
| +{
|
| + return m_isolateWrapper ? m_isolateWrapper->isolate() : nullptr;
|
| +}
|
| +
|
| +void WorkerThread::initializeBackingThread()
|
| +{
|
| + backingThread().initialize();
|
| +}
|
| +
|
| +void WorkerThread::shutdownBackingThread()
|
| +{
|
| + backingThread().shutdown();
|
| +}
|
| +
|
| void WorkerThread::terminateAndWaitForAllWorkers()
|
| {
|
| // Keep this lock to prevent WorkerThread instances from being destroyed.
|
| @@ -507,40 +520,16 @@ void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
|
| backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, task, true).leakPtr(), delayMs);
|
| }
|
|
|
| -v8::Isolate* WorkerThread::initializeIsolate()
|
| +PassOwnPtr<WorkerIsolateWrapper> WorkerThread::createIsolateWrapper()
|
| {
|
| - ASSERT(isCurrentThread());
|
| - ASSERT(!m_isolate);
|
| - v8::Isolate* isolate = V8PerIsolateData::initialize();
|
| - V8Initializer::initializeWorker(isolate);
|
| -
|
| - m_interruptor = adoptPtr(new V8IsolateInterruptor(isolate));
|
| - ThreadState::current()->addInterruptor(m_interruptor.get());
|
| - ThreadState::current()->registerTraceDOMWrappers(isolate, V8GCController::traceDOMWrappers);
|
| -
|
| - return isolate;
|
| -}
|
| -
|
| -void WorkerThread::willDestroyIsolate()
|
| -{
|
| - ASSERT(isCurrentThread());
|
| - ASSERT(m_isolate);
|
| - V8PerIsolateData::willBeDestroyed(m_isolate);
|
| - ThreadState::current()->removeInterruptor(m_interruptor.get());
|
| -}
|
| -
|
| -void WorkerThread::destroyIsolate()
|
| -{
|
| - ASSERT(isCurrentThread());
|
| - V8PerIsolateData::destroy(m_isolate);
|
| - m_isolate = nullptr;
|
| + return WorkerIsolateWrapper::createDefault();
|
| }
|
|
|
| void WorkerThread::terminateV8Execution()
|
| {
|
| ASSERT(isMainThread());
|
| m_workerGlobalScope->script()->willScheduleExecutionTermination();
|
| - v8::V8::TerminateExecution(m_isolate);
|
| + m_isolateWrapper->terminateExecution();
|
| }
|
|
|
| void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task)
|
|
|