Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "bindings/v8/V8Initializer.h" | 27 #include "bindings/v8/V8Initializer.h" |
| 28 | 28 |
| 29 #include "V8ErrorEvent.h" | |
| 29 #include "V8History.h" | 30 #include "V8History.h" |
| 30 #include "V8Location.h" | 31 #include "V8Location.h" |
| 31 #include "V8Window.h" | 32 #include "V8Window.h" |
| 33 #include "bindings/v8/DOMWrapperWorld.h" | |
| 32 #include "bindings/v8/ScriptCallStackFactory.h" | 34 #include "bindings/v8/ScriptCallStackFactory.h" |
| 33 #include "bindings/v8/ScriptProfiler.h" | 35 #include "bindings/v8/ScriptProfiler.h" |
| 34 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
| 35 #include "bindings/v8/V8GCController.h" | 37 #include "bindings/v8/V8GCController.h" |
| 38 #include "bindings/v8/V8HiddenPropertyName.h" | |
| 36 #include "bindings/v8/V8PerContextData.h" | 39 #include "bindings/v8/V8PerContextData.h" |
| 37 #include "core/dom/Document.h" | 40 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExceptionCode.h" | 41 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/inspector/ScriptCallStack.h" | 42 #include "core/inspector/ScriptCallStack.h" |
| 40 #include "core/page/ConsoleTypes.h" | 43 #include "core/page/ConsoleTypes.h" |
| 41 #include "core/page/ContentSecurityPolicy.h" | 44 #include "core/page/ContentSecurityPolicy.h" |
| 42 #include "core/page/DOMWindow.h" | 45 #include "core/page/DOMWindow.h" |
| 43 #include "core/page/Frame.h" | 46 #include "core/page/Frame.h" |
| 44 #include "core/platform/MemoryUsageSupport.h" | 47 #include "core/platform/MemoryUsageSupport.h" |
| 45 #include <v8-debug.h> | 48 #include <v8-debug.h> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 90 |
| 88 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); | 91 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); |
| 89 RefPtr<ScriptCallStack> callStack; | 92 RefPtr<ScriptCallStack> callStack; |
| 90 // Currently stack trace is only collected when inspector is open. | 93 // Currently stack trace is only collected when inspector is open. |
| 91 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) | 94 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) |
| 92 callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallSt ackSizeToCapture); | 95 callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallSt ackSizeToCapture); |
| 93 | 96 |
| 94 v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); | 97 v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); |
| 95 bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsStrin g(); | 98 bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsStrin g(); |
| 96 String resource = shouldUseDocumentURL ? firstWindow->document()->url() : to WebCoreString(resourceName); | 99 String resource = shouldUseDocumentURL ? firstWindow->document()->url() : to WebCoreString(resourceName); |
| 97 firstWindow->document()->reportException(errorMessage, message->GetLineNumbe r(), message->GetStartColumn(), resource, callStack); | 100 RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, messag e->GetLineNumber(), message->GetStartColumn()); |
| 101 v8::Local<v8::Value> wrappedEvent = toV8(event.get(), v8::Handle<v8::Object> (), v8::Isolate::GetCurrent()); | |
| 102 if (!wrappedEvent.IsEmpty() && wrappedEvent->IsObject()) | |
|
adamk
2013/07/31 16:37:30
wrappedEvent->IsObject() can just be an ASSERT, I
Mike West
2013/08/01 07:52:15
Done.
| |
| 103 wrappedEvent->ToObject()->SetHiddenValue(V8HiddenPropertyName::error(), data); | |
|
adamk
2013/07/31 16:37:30
Rather than ToObject, I think this should be v8::L
Mike West
2013/08/01 07:52:15
Done.
| |
| 104 firstWindow->document()->reportException(event.release(), callStack); | |
| 98 } | 105 } |
| 99 | 106 |
| 100 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8 ::AccessType type, v8::Local<v8::Value> data) | 107 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8 ::AccessType type, v8::Local<v8::Value> data) |
| 101 { | 108 { |
| 102 Frame* target = findFrame(host, data, v8::Isolate::GetCurrent()); | 109 Frame* target = findFrame(host, data, v8::Isolate::GetCurrent()); |
| 103 if (!target) | 110 if (!target) |
| 104 return; | 111 return; |
| 105 DOMWindow* targetWindow = target->domWindow(); | 112 DOMWindow* targetWindow = target->domWindow(); |
| 106 | 113 |
| 107 setDOMException(SecurityError, targetWindow->crossDomainAccessErrorMessage(a ctiveDOMWindow()), v8::Isolate::GetCurrent()); | 114 setDOMException(SecurityError, targetWindow->crossDomainAccessErrorMessage(a ctiveDOMWindow()), v8::Isolate::GetCurrent()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 static bool isReportingException = false; | 162 static bool isReportingException = false; |
| 156 // Exceptions that occur in error handler should be ignored since in that ca se | 163 // Exceptions that occur in error handler should be ignored since in that ca se |
| 157 // WorkerGlobalScope::reportException will send the exception to the worker object. | 164 // WorkerGlobalScope::reportException will send the exception to the worker object. |
| 158 if (isReportingException) | 165 if (isReportingException) |
| 159 return; | 166 return; |
| 160 isReportingException = true; | 167 isReportingException = true; |
| 161 | 168 |
| 162 // During the frame teardown, there may not be a valid context. | 169 // During the frame teardown, there may not be a valid context. |
| 163 if (ScriptExecutionContext* context = getScriptExecutionContext()) { | 170 if (ScriptExecutionContext* context = getScriptExecutionContext()) { |
| 164 String errorMessage = toWebCoreString(message->Get()); | 171 String errorMessage = toWebCoreString(message->Get()); |
| 165 int lineNumber = message->GetLineNumber(); | |
| 166 int columnNumber = message->GetStartColumn(); | |
| 167 String sourceURL = toWebCoreString(message->GetScriptResourceName()); | 172 String sourceURL = toWebCoreString(message->GetScriptResourceName()); |
| 168 context->reportException(errorMessage, lineNumber, columnNumber, sourceU RL, 0); | 173 RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, m essage->GetLineNumber(), message->GetStartColumn()); |
| 174 v8::Local<v8::Value> wrappedEvent = toV8(event.get(), v8::Handle<v8::Obj ect>(), v8::Isolate::GetCurrent()); | |
| 175 if (!wrappedEvent.IsEmpty() && wrappedEvent->IsObject()) | |
|
adamk
2013/07/31 16:37:30
Same here as above
Mike West
2013/08/01 07:52:15
Done.
| |
| 176 wrappedEvent->ToObject()->SetHiddenValue(V8HiddenPropertyName::error (), data); | |
|
adamk
2013/07/31 16:37:30
and here too
Mike West
2013/08/01 07:52:15
Done.
| |
| 177 context->reportException(event.release(), 0); | |
| 169 } | 178 } |
| 170 | 179 |
| 171 isReportingException = false; | 180 isReportingException = false; |
| 172 } | 181 } |
| 173 | 182 |
| 174 static const int kWorkerMaxStackSize = 500 * 1024; | 183 static const int kWorkerMaxStackSize = 500 * 1024; |
| 175 | 184 |
| 176 void V8Initializer::initializeWorker(v8::Isolate* isolate) | 185 void V8Initializer::initializeWorker(v8::Isolate* isolate) |
| 177 { | 186 { |
| 178 initializeV8Common(); | 187 initializeV8Common(); |
| 179 | 188 |
| 180 v8::V8::AddMessageListener(messageHandlerInWorker); | 189 v8::V8::AddMessageListener(messageHandlerInWorker); |
| 181 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); | 190 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); |
| 182 | 191 |
| 183 v8::ResourceConstraints resourceConstraints; | 192 v8::ResourceConstraints resourceConstraints; |
| 184 uint32_t here; | 193 uint32_t here; |
| 185 resourceConstraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uin t32_t*)); | 194 resourceConstraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uin t32_t*)); |
| 186 v8::SetResourceConstraints(&resourceConstraints); | 195 v8::SetResourceConstraints(&resourceConstraints); |
| 187 | 196 |
| 188 V8PerIsolateData::ensureInitialized(isolate); | 197 V8PerIsolateData::ensureInitialized(isolate); |
| 189 } | 198 } |
| 190 | 199 |
| 191 } // namespace WebCore | 200 } // namespace WebCore |
| OLD | NEW |