OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "core/workers/InProcessWorkerObjectProxy.h" | 45 #include "core/workers/InProcessWorkerObjectProxy.h" |
46 #include "core/workers/WorkerClients.h" | 46 #include "core/workers/WorkerClients.h" |
47 #include "core/workers/WorkerInspectorProxy.h" | 47 #include "core/workers/WorkerInspectorProxy.h" |
48 #include "core/workers/WorkerThreadStartupData.h" | 48 #include "core/workers/WorkerThreadStartupData.h" |
49 #include "wtf/WTF.h" | 49 #include "wtf/WTF.h" |
50 | 50 |
51 namespace blink { | 51 namespace blink { |
52 | 52 |
53 namespace { | 53 namespace { |
54 | 54 |
55 void processExceptionOnWorkerGlobalScope(int exceptionId, bool handled, Executio
nContext* scriptContext) | 55 void processUnhandledExceptionOnWorkerGlobalScope(const String& errorMessage, Pa
ssOwnPtr<SourceLocation> location, ExecutionContext* scriptContext) |
56 { | 56 { |
57 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); | 57 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); |
58 globalScope->exceptionHandled(exceptionId, handled); | 58 globalScope->exceptionUnhandled(errorMessage, std::move(location)); |
59 } | 59 } |
60 | 60 |
61 void processMessageOnWorkerGlobalScope(PassRefPtr<SerializedScriptValue> message
, PassOwnPtr<MessagePortChannelArray> channels, InProcessWorkerObjectProxy* work
erObjectProxy, ExecutionContext* scriptContext) | 61 void processMessageOnWorkerGlobalScope(PassRefPtr<SerializedScriptValue> message
, PassOwnPtr<MessagePortChannelArray> channels, InProcessWorkerObjectProxy* work
erObjectProxy, ExecutionContext* scriptContext) |
62 { | 62 { |
63 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); | 63 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); |
64 MessagePortArray* ports = MessagePort::entanglePorts(*scriptContext, std::mo
ve(channels)); | 64 MessagePortArray* ports = MessagePort::entanglePorts(*scriptContext, std::mo
ve(channels)); |
65 globalScope->dispatchEvent(MessageEvent::create(ports, message)); | 65 globalScope->dispatchEvent(MessageEvent::create(ports, message)); |
66 workerObjectProxy->confirmMessageFromWorkerObject(V8GCController::hasPending
Activity(globalScope->thread()->isolate(), scriptContext)); | 66 workerObjectProxy->confirmMessageFromWorkerObject(V8GCController::hasPending
Activity(globalScope->thread()->isolate(), scriptContext)); |
67 } | 67 } |
68 | 68 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 m_workerThread->postTask(BLINK_FROM_HERE, std::move(task)); | 151 m_workerThread->postTask(BLINK_FROM_HERE, std::move(task)); |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 void InProcessWorkerMessagingProxy::postTaskToLoader(std::unique_ptr<ExecutionCo
ntextTask> task) | 155 void InProcessWorkerMessagingProxy::postTaskToLoader(std::unique_ptr<ExecutionCo
ntextTask> task) |
156 { | 156 { |
157 DCHECK(getExecutionContext()->isDocument()); | 157 DCHECK(getExecutionContext()->isDocument()); |
158 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task)); | 158 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task)); |
159 } | 159 } |
160 | 160 |
161 void InProcessWorkerMessagingProxy::reportException(const String& errorMessage,
int lineNumber, int columnNumber, const String& sourceURL, int exceptionId) | 161 void InProcessWorkerMessagingProxy::reportException(const String& errorMessage,
PassOwnPtr<SourceLocation> location) |
162 { | 162 { |
163 DCHECK(isParentContextThread()); | 163 DCHECK(isParentContextThread()); |
164 if (!m_workerObject) | 164 if (!m_workerObject) |
165 return; | 165 return; |
166 | 166 |
167 // We don't bother checking the askedToTerminate() flag here, because | 167 // We don't bother checking the askedToTerminate() flag here, because |
168 // exceptions should *always* be reported even if the thread is terminated. | 168 // exceptions should *always* be reported even if the thread is terminated. |
169 // This is intentionally different than the behavior in MessageWorkerTask, | 169 // This is intentionally different than the behavior in MessageWorkerTask, |
170 // because terminated workers no longer deliver messages (section 4.6 of the | 170 // because terminated workers no longer deliver messages (section 4.6 of the |
171 // WebWorker spec), but they do report exceptions. | 171 // WebWorker spec), but they do report exceptions. |
172 | 172 |
173 ErrorEvent* event = ErrorEvent::create(errorMessage, sourceURL, lineNumber,
columnNumber, nullptr); | 173 ErrorEvent* event = ErrorEvent::create(errorMessage, location->url(), locati
on->lineNumber(), location->columnNumber(), nullptr); |
174 DispatchEventResult dispatchResult = m_workerObject->dispatchEvent(event); | 174 if (m_workerObject->dispatchEvent(event) == DispatchEventResult::NotCanceled
) |
175 postTaskToWorkerGlobalScope(createCrossThreadTask(&processExceptionOnWorkerG
lobalScope, exceptionId, dispatchResult != DispatchEventResult::NotCanceled)); | 175 postTaskToWorkerGlobalScope(createCrossThreadTask(&processUnhandledExcep
tionOnWorkerGlobalScope, errorMessage, passed(std::move(location)))); |
176 } | 176 } |
177 | 177 |
178 void InProcessWorkerMessagingProxy::reportConsoleMessage(MessageSource source, M
essageLevel level, const String& message, int lineNumber, const String& sourceUR
L) | 178 void InProcessWorkerMessagingProxy::reportConsoleMessage(MessageSource source, M
essageLevel level, const String& message, int lineNumber, const String& sourceUR
L) |
179 { | 179 { |
180 DCHECK(isParentContextThread()); | 180 DCHECK(isParentContextThread()); |
181 if (m_askedToTerminate) | 181 if (m_askedToTerminate) |
182 return; | 182 return; |
183 if (m_workerInspectorProxy) | 183 if (m_workerInspectorProxy) |
184 m_workerInspectorProxy->addConsoleMessageFromWorker(ConsoleMessage::crea
te(source, level, message, sourceURL, lineNumber, 0)); | 184 m_workerInspectorProxy->addConsoleMessageFromWorker(ConsoleMessage::crea
te(source, level, message, sourceURL, lineNumber, 0)); |
185 } | 185 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 294 |
295 bool InProcessWorkerMessagingProxy::isParentContextThread() const | 295 bool InProcessWorkerMessagingProxy::isParentContextThread() const |
296 { | 296 { |
297 // TODO(nhiroki): Nested worker is not supported yet, so the parent context | 297 // TODO(nhiroki): Nested worker is not supported yet, so the parent context |
298 // thread should be equal to the main thread (http://crbug.com/31666). | 298 // thread should be equal to the main thread (http://crbug.com/31666). |
299 DCHECK(getExecutionContext()->isDocument()); | 299 DCHECK(getExecutionContext()->isDocument()); |
300 return isMainThread(); | 300 return isMainThread(); |
301 } | 301 } |
302 | 302 |
303 } // namespace blink | 303 } // namespace blink |
OLD | NEW |