Chromium Code Reviews| Index: Source/core/workers/WorkerThread.cpp |
| diff --git a/Source/core/workers/WorkerThread.cpp b/Source/core/workers/WorkerThread.cpp |
| index ff101dd1e8a5f4749ca24b0bb1e505e6c8bed7e5..07403354a728bf18513caa82248b2b2336a90476 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,11 @@ 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(); |
| + ASSERT(m_isolateWrapper); |
|
kinuko
2015/06/01 13:15:41
(This assert is probably not that desirable / help
sadrul
2015/06/01 14:21:16
Removed.
|
| m_workerGlobalScope = createWorkerGlobalScope(startupData); |
| m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.get() ? cachedMetaData->size() : 0); |
| @@ -358,7 +357,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 +372,8 @@ void WorkerThread::shutdown() |
| m_workerGlobalScope = nullptr; |
| backingThread().removeTaskObserver(m_microtaskRunner.get()); |
| - backingThread().shutdown(); |
| - destroyIsolate(); |
| + shutdownBackingThread(); |
| + m_isolateWrapper.clear(); |
| m_microtaskRunner = nullptr; |
| @@ -457,6 +456,21 @@ void WorkerThread::didStopRunLoop() |
| Platform::current()->didStopWorkerRunLoop(); |
| } |
| +v8::Isolate* WorkerThread::isolate() |
| +{ |
| + return m_shutdown ? nullptr : m_isolateWrapper->isolate(); |
|
kinuko
2015/06/01 13:15:41
Any reason this is not m_isolateWrapper ? m_isolat
sadrul
2015/06/01 14:21:16
Nope. Done.
|
| +} |
| + |
| +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 +521,11 @@ void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr< |
| backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, task, true).leakPtr(), delayMs); |
| } |
| -v8::Isolate* WorkerThread::initializeIsolate() |
| -{ |
| - 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; |
| -} |
| - |
| void WorkerThread::terminateV8Execution() |
| { |
| ASSERT(isMainThread()); |
| m_workerGlobalScope->script()->willScheduleExecutionTermination(); |
| - v8::V8::TerminateExecution(m_isolate); |
| + m_isolateWrapper->terminateExecution(); |
| } |
| void WorkerThread::appendDebuggerTask(PassOwnPtr<WebThread::Task> task) |