Chromium Code Reviews| 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/page/DOMTimer.h" | 39 #include "core/page/DOMTimer.h" |
| 39 #include "core/workers/WorkerGlobalScope.h" | 40 #include "core/workers/WorkerGlobalScope.h" |
| 40 #include "core/workers/WorkerThread.h" | 41 #include "core/workers/WorkerThread.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 } | 188 } |
| 188 | 189 |
| 189 void ScriptExecutionContext::closeMessagePorts() { | 190 void ScriptExecutionContext::closeMessagePorts() { |
| 190 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); | 191 HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end(); |
| 191 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter != messagePortsEnd; ++iter) { | 192 for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter != messagePortsEnd; ++iter) { |
| 192 ASSERT((*iter)->scriptExecutionContext() == this); | 193 ASSERT((*iter)->scriptExecutionContext() == this); |
| 193 (*iter)->close(); | 194 (*iter)->close(); |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 | 197 |
| 197 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line Number, int& columnNumber, String& sourceURL) | 198 bool ScriptExecutionContext::sanitizeScriptError(String& errorMessage, int& line Number, int& columnNumber, String& sourceURL, ScriptValue& error) |
| 198 { | 199 { |
| 199 KURL targetURL = completeURL(sourceURL); | 200 KURL targetURL = completeURL(sourceURL); |
| 200 if (securityOrigin()->canRequest(targetURL)) | 201 if (securityOrigin()->canRequest(targetURL)) |
| 201 return false; | 202 return false; |
| 202 errorMessage = "Script error."; | 203 errorMessage = "Script error."; |
| 203 sourceURL = String(); | 204 sourceURL = String(); |
| 204 lineNumber = 0; | 205 lineNumber = 0; |
| 205 columnNumber = 0; | 206 columnNumber = 0; |
| 207 error.clear(); | |
| 206 return true; | 208 return true; |
| 207 } | 209 } |
| 208 | 210 |
| 209 void ScriptExecutionContext::reportException(const String& errorMessage, int lin eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack) | 211 void ScriptExecutionContext::reportException(const String& errorMessage, int lin eNumber, int columnNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack, const ScriptValue& error) |
| 210 { | 212 { |
| 211 if (m_inDispatchErrorEvent) { | 213 if (m_inDispatchErrorEvent) { |
| 212 if (!m_pendingExceptions) | 214 if (!m_pendingExceptions) |
| 213 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> > ()); | 215 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException> > ()); |
| 214 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage, lineNumber, columnNumber, sourceURL, callStack))); | 216 m_pendingExceptions->append(adoptPtr(new PendingException(errorMessage, lineNumber, columnNumber, sourceURL, callStack))); |
| 215 return; | 217 return; |
| 216 } | 218 } |
| 217 | 219 |
| 218 // First report the original exception and only then all the nested ones. | 220 // First report the original exception and only then all the nested ones. |
| 219 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL)) | 221 if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL, e rror)) |
| 220 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber, callStack); | 222 logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber, callStack); |
| 221 | 223 |
| 222 if (!m_pendingExceptions) | 224 if (!m_pendingExceptions) |
| 223 return; | 225 return; |
| 224 | 226 |
| 225 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { | 227 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { |
| 226 PendingException* e = m_pendingExceptions->at(i).get(); | 228 PendingException* e = m_pendingExceptions->at(i).get(); |
| 227 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber , e->m_columnNumber, e->m_callStack); | 229 logExceptionToConsole(e->m_errorMessage, e->m_sourceURL, e->m_lineNumber , e->m_columnNumber, e->m_callStack); |
| 228 } | 230 } |
| 229 m_pendingExceptions.clear(); | 231 m_pendingExceptions.clear(); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc riptState* state, unsigned long requestIdentifier) | 234 void ScriptExecutionContext::addConsoleMessage(MessageSource source, MessageLeve l level, const String& message, const String& sourceURL, unsigned lineNumber, Sc riptState* state, unsigned long requestIdentifier) |
| 233 { | 235 { |
| 234 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI dentifier); | 236 addMessage(source, level, message, sourceURL, lineNumber, 0, state, requestI dentifier); |
| 235 } | 237 } |
| 236 | 238 |
| 237 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) | 239 bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, const ScriptValue& errorO bject) |
| 238 { | 240 { |
| 239 EventTarget* target = errorEventTarget(); | 241 EventTarget* target = errorEventTarget(); |
| 240 if (!target) | 242 if (!target) |
| 241 return false; | 243 return false; |
| 242 | 244 |
| 243 String message = errorMessage; | 245 String message = errorMessage; |
| 244 int line = lineNumber; | 246 int line = lineNumber; |
| 245 int column = columnNumber; | 247 int column = columnNumber; |
| 246 String sourceName = sourceURL; | 248 String sourceName = sourceURL; |
| 247 sanitizeScriptError(message, line, column, sourceName); | 249 ScriptValue error = errorObject; |
| 250 sanitizeScriptError(message, line, column, sourceName, error); | |
| 248 | 251 |
| 249 ASSERT(!m_inDispatchErrorEvent); | 252 ASSERT(!m_inDispatchErrorEvent); |
| 250 m_inDispatchErrorEvent = true; | 253 m_inDispatchErrorEvent = true; |
| 251 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line , column); | 254 RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line , column, error); |
|
adamk
2013/07/30 15:46:41
It seems like the thing holding you back from just
Mike West
2013/07/30 15:53:37
Yup. You're entirely correct. But there are only a
adamk
2013/07/30 16:00:48
No need to teach it about worlds (though note that
| |
| 252 target->dispatchEvent(errorEvent); | 255 target->dispatchEvent(errorEvent); |
| 253 m_inDispatchErrorEvent = false; | 256 m_inDispatchErrorEvent = false; |
| 254 return errorEvent->defaultPrevented(); | 257 return errorEvent->defaultPrevented(); |
| 255 } | 258 } |
| 256 | 259 |
| 257 int ScriptExecutionContext::circularSequentialID() | 260 int ScriptExecutionContext::circularSequentialID() |
| 258 { | 261 { |
| 259 ++m_circularSequentialID; | 262 ++m_circularSequentialID; |
| 260 if (m_circularSequentialID <= 0) | 263 if (m_circularSequentialID <= 0) |
| 261 m_circularSequentialID = 1; | 264 m_circularSequentialID = 1; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 ScriptExecutionContext::Task::~Task() | 320 ScriptExecutionContext::Task::~Task() |
| 318 { | 321 { |
| 319 } | 322 } |
| 320 | 323 |
| 321 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext ) | 324 void ScriptExecutionContext::setDatabaseContext(DatabaseContext* databaseContext ) |
| 322 { | 325 { |
| 323 m_databaseContext = databaseContext; | 326 m_databaseContext = databaseContext; |
| 324 } | 327 } |
| 325 | 328 |
| 326 } // namespace WebCore | 329 } // namespace WebCore |
| OLD | NEW |