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) 2012 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2012 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 10 matching lines...) Expand all Loading... |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 * | 25 * |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/dom/ScriptExecutionContext.h" | 29 #include "core/dom/ScriptExecutionContext.h" |
30 | 30 |
| 31 #include "bindings/v8/SerializedScriptValue.h" |
31 #include "core/dom/ContextLifecycleNotifier.h" | 32 #include "core/dom/ContextLifecycleNotifier.h" |
32 #include "core/dom/ErrorEvent.h" | 33 #include "core/dom/ErrorEvent.h" |
33 #include "core/dom/EventTarget.h" | 34 #include "core/dom/EventTarget.h" |
34 #include "core/dom/MessagePort.h" | 35 #include "core/dom/MessagePort.h" |
35 #include "core/html/PublicURLManager.h" | 36 #include "core/html/PublicURLManager.h" |
36 #include "core/inspector/InspectorInstrumentation.h" | 37 #include "core/inspector/InspectorInstrumentation.h" |
37 #include "core/inspector/ScriptCallStack.h" | 38 #include "core/inspector/ScriptCallStack.h" |
38 #include "core/loader/cache/CachedScript.h" | 39 #include "core/loader/cache/CachedScript.h" |
39 #include "core/page/DOMTimer.h" | 40 #include "core/page/DOMTimer.h" |
40 #include "core/workers/WorkerGlobalScope.h" | 41 #include "core/workers/WorkerGlobalScope.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 189 } |
189 | 190 |
190 void ScriptExecutionContext::closeMessagePorts() { | 191 void ScriptExecutionContext::closeMessagePorts() { |
191 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); | 192 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); |
192 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter !=
messagePortsEnd; ++iter) { | 193 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter !=
messagePortsEnd; ++iter) { |
193 ASSERT((*iter)->scriptExecutionContext() == this); | 194 ASSERT((*iter)->scriptExecutionContext() == this); |
194 (*iter)->close(); | 195 (*iter)->close(); |
195 } | 196 } |
196 } | 197 } |
197 | 198 |
198 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line
Number, int& columnNumber, String& sourceURL, CachedScript* cachedScript) | 199 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line
Number, int& columnNumber, String& sourceURL, ScriptValue& error, CachedScript*
cachedScript) |
199 { | 200 { |
200 KURL targetURL = completeURL(sourceURL); | 201 KURL targetURL = completeURL(sourceURL); |
201 if (securityOrigin()->canRequest(targetURL) || (cachedScript && cachedScript
->passesAccessControlCheck(securityOrigin()))) | 202 if (securityOrigin()->canRequest(targetURL) || (cachedScript && cachedScript
->passesAccessControlCheck(securityOrigin()))) |
202 return false; | 203 return false; |
203 errorMessage = "Script error."; | 204 errorMessage = "Script error."; |
204 sourceURL = String(); | 205 sourceURL = String(); |
205 lineNumber = 0; | 206 lineNumber = 0; |
206 columnNumber = 0; | 207 columnNumber = 0; |
| 208 error.clear(); |
207 return true; | 209 return true; |
208 } | 210 } |
209 | 211 |
210 void ScriptExecutionContext::reportException(const String& errorMessage, int lin
eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>
callStack, CachedScript* cachedScript) | 212 void ScriptExecutionContext::reportException(const String& errorMessage, int lin
eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack>
callStack, const ScriptValue& error, CachedScript* cachedScript) |
211 { | 213 { |
212 if (m_inDispatchErrorEvent) { | 214 if (m_inDispatchErrorEvent) { |
213 if (!m_pendingExceptions) | 215 if (!m_pendingExceptions) |
214 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); | 216 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> >
()); |
215 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage,
lineNumber, columnNumber, sourceURL, callStack))); | 217 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage,
lineNumber, columnNumber, sourceURL, callStack))); |
216 return; | 218 return; |
217 } | 219 } |
218 | 220 |
219 // First report the original exception and only then all the nested ones. | 221 // First report the original exception and only then all the nested ones. |
220 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL, c
achedScript)) | 222 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL, e
rror, cachedScript)) |
221 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber,
callStack); | 223 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber,
callStack); |
222 | 224 |
223 if (!m_pendingExceptions) | 225 if (!m_pendingExceptions) |
224 return; | 226 return; |
225 | 227 |
226 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { | 228 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { |
227 PendingException* e = m_pendingExceptions->at(i).get(); | 229 PendingException* e = m_pendingExceptions->at(i).get(); |
228 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber
, e->m_columnNumber, e->m_callStack); | 230 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber
, e->m_columnNumber, e->m_callStack); |
229 } | 231 } |
230 m_pendingExceptions.clear(); | 232 m_pendingExceptions.clear(); |
231 } | 233 } |
232 | 234 |
233 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve
l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc
riptState* state, unsigned long requestIdentifier) | 235 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve
l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc
riptState* state, unsigned long requestIdentifier) |
234 { | 236 { |
235 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI
dentifier); | 237 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI
dentifier); |
236 } | 238 } |
237 | 239 |
238 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
lineNumber, int columnNumber, const String& sourceURL, CachedScript* cachedScrip
t) | 240 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int
lineNumber, int columnNumber, const String& sourceURL, const ScriptValue& errorO
bject, CachedScript* cachedScript) |
239 { | 241 { |
240 EventTarget* target = errorEventTarget(); | 242 EventTarget* target = errorEventTarget(); |
241 if (!target) | 243 if (!target) |
242 return false; | 244 return false; |
243 | 245 |
244 String message = errorMessage; | 246 String message = errorMessage; |
245 int line = lineNumber; | 247 int line = lineNumber; |
246 int column = columnNumber; | 248 int column = columnNumber; |
247 String sourceName = sourceURL; | 249 String sourceName = sourceURL; |
248 sanitizeScriptError(message, line, column, sourceName, cachedScript); | 250 ScriptValue error = errorObject; |
| 251 sanitizeScriptError(message, line, column, sourceName, error, cachedScript); |
249 | 252 |
250 ASSERT(!m_inDispatchErrorEvent); | 253 ASSERT(!m_inDispatchErrorEvent); |
251 m_inDispatchErrorEvent = true; | 254 m_inDispatchErrorEvent = true; |
252 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line
, column); | 255 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line
, column, error); |
253 target->dispatchEvent(errorEvent); | 256 target->dispatchEvent(errorEvent); |
254 m_inDispatchErrorEvent = false; | 257 m_inDispatchErrorEvent = false; |
255 return errorEvent->defaultPrevented(); | 258 return errorEvent->defaultPrevented(); |
256 } | 259 } |
257 | 260 |
258 int ScriptExecutionContext::circularSequentialID() | 261 int ScriptExecutionContext::circularSequentialID() |
259 { | 262 { |
260 ++m_circularSequentialID; | 263 ++m_circularSequentialID; |
261 if (m_circularSequentialID <= 0) | 264 if (m_circularSequentialID <= 0) |
262 m_circularSequentialID = 1; | 265 m_circularSequentialID = 1; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 ScriptExecutionContext::Task::~Task() | 326 ScriptExecutionContext::Task::~Task() |
324 { | 327 { |
325 } | 328 } |
326 | 329 |
327 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext
) | 330 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext
) |
328 { | 331 { |
329 m_databaseContext = databaseContext; | 332 m_databaseContext = databaseContext; |
330 } | 333 } |
331 | 334 |
332 } // namespace WebCore | 335 } // namespace WebCore |
OLD | NEW |