OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 75 |
76 worker->m_scriptLoader = WorkerScriptLoader::create(); | 76 worker->m_scriptLoader = WorkerScriptLoader::create(); |
77 worker->m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOri ginRequests, worker.get()); | 77 worker->m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOri ginRequests, worker.get()); |
78 worker->m_contextProxy = proxyProvider->createWorkerGlobalScopeProxy(worker. get()); | 78 worker->m_contextProxy = proxyProvider->createWorkerGlobalScopeProxy(worker. get()); |
79 return worker.release(); | 79 return worker.release(); |
80 } | 80 } |
81 | 81 |
82 Worker::~Worker() | 82 Worker::~Worker() |
83 { | 83 { |
84 ASSERT(isMainThread()); | 84 ASSERT(isMainThread()); |
85 if (!m_contextProxy) | |
86 return; | |
85 ASSERT(executionContext()); // The context is protected by worker context pr oxy, so it cannot be destroyed while a Worker exists. | 87 ASSERT(executionContext()); // The context is protected by worker context pr oxy, so it cannot be destroyed while a Worker exists. |
86 if (m_contextProxy) | 88 m_contextProxy->workerObjectDestroyed(); |
87 m_contextProxy->workerObjectDestroyed(); | |
88 } | 89 } |
89 | 90 |
90 const AtomicString& Worker::interfaceName() const | 91 const AtomicString& Worker::interfaceName() const |
91 { | 92 { |
92 return EventTargetNames::Worker; | 93 return EventTargetNames::Worker; |
93 } | 94 } |
94 | 95 |
95 void Worker::postMessage(PassRefPtr<SerializedScriptValue> message, const Messag ePortArray* ports, ExceptionState& exceptionState) | 96 void Worker::postMessage(PassRefPtr<SerializedScriptValue> message, const Messag ePortArray* ports, ExceptionState& exceptionState) |
96 { | 97 { |
haraken
2014/07/03 12:14:04
Add ASSERT(m_contextProxy)
sof
2014/07/03 12:23:10
Done.
| |
97 // Disentangle the port in preparation for sending it to the remote context. | 98 // Disentangle the port in preparation for sending it to the remote context. |
98 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState); | 99 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState); |
99 if (exceptionState.hadException()) | 100 if (exceptionState.hadException()) |
100 return; | 101 return; |
101 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); | 102 m_contextProxy->postMessageToWorkerGlobalScope(message, channels.release()); |
102 } | 103 } |
103 | 104 |
104 void Worker::terminate() | 105 void Worker::terminate() |
105 { | 106 { |
106 if (m_contextProxy) | 107 if (m_contextProxy) |
107 m_contextProxy->terminateWorkerGlobalScope(); | 108 m_contextProxy->terminateWorkerGlobalScope(); |
108 } | 109 } |
109 | 110 |
110 void Worker::stop() | 111 void Worker::stop() |
111 { | 112 { |
112 terminate(); | 113 terminate(); |
113 } | 114 } |
114 | 115 |
115 bool Worker::hasPendingActivity() const | 116 bool Worker::hasPendingActivity() const |
116 { | 117 { |
117 return m_contextProxy->hasPendingActivity() || ActiveDOMObject::hasPendingAc tivity(); | 118 return (m_contextProxy && m_contextProxy->hasPendingActivity()) || ActiveDOM Object::hasPendingActivity(); |
118 } | 119 } |
119 | 120 |
120 void Worker::didReceiveResponse(unsigned long identifier, const ResourceResponse &) | 121 void Worker::didReceiveResponse(unsigned long identifier, const ResourceResponse &) |
121 { | 122 { |
122 InspectorInstrumentation::didReceiveScriptResponse(executionContext(), ident ifier); | 123 InspectorInstrumentation::didReceiveScriptResponse(executionContext(), ident ifier); |
123 } | 124 } |
124 | 125 |
125 void Worker::notifyFinished() | 126 void Worker::notifyFinished() |
126 { | 127 { |
127 if (m_scriptLoader->failed()) { | 128 if (m_scriptLoader->failed()) { |
128 dispatchEvent(Event::createCancelable(EventTypeNames::error)); | 129 dispatchEvent(Event::createCancelable(EventTypeNames::error)); |
129 } else { | 130 } else { |
130 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; | 131 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; |
haraken
2014/07/03 12:14:03
Add ASSERT(m_contextProxy)
sof
2014/07/03 12:23:10
Why not; done.
| |
131 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio nContext())) | 132 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio nContext())) |
132 startMode = PauseWorkerGlobalScopeOnStart; | 133 startMode = PauseWorkerGlobalScopeOnStart; |
133 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode) ; | 134 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode) ; |
134 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa der->identifier(), m_scriptLoader->script()); | 135 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa der->identifier(), m_scriptLoader->script()); |
135 } | 136 } |
136 m_scriptLoader = nullptr; | 137 m_scriptLoader = nullptr; |
137 | 138 |
138 unsetPendingActivity(this); | 139 unsetPendingActivity(this); |
139 } | 140 } |
140 | 141 |
141 void Worker::trace(Visitor* visitor) | 142 void Worker::trace(Visitor* visitor) |
142 { | 143 { |
143 AbstractWorker::trace(visitor); | 144 AbstractWorker::trace(visitor); |
144 } | 145 } |
145 | 146 |
146 } // namespace WebCore | 147 } // namespace WebCore |
OLD | NEW |