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 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 #include "V8ErrorEvent.h" | 29 #include "V8ErrorEvent.h" |
| 30 #include "V8History.h" | 30 #include "V8History.h" |
| 31 #include "V8Location.h" | 31 #include "V8Location.h" |
| 32 #include "V8Window.h" | 32 #include "V8Window.h" |
| 33 #include "bindings/v8/DOMWrapperWorld.h" | 33 #include "bindings/v8/DOMWrapperWorld.h" |
| 34 #include "bindings/v8/ScriptCallStackFactory.h" | 34 #include "bindings/v8/ScriptCallStackFactory.h" |
| 35 #include "bindings/v8/ScriptController.h" | 35 #include "bindings/v8/ScriptController.h" |
| 36 #include "bindings/v8/ScriptProfiler.h" | 36 #include "bindings/v8/ScriptProfiler.h" |
| 37 #include "bindings/v8/V8Binding.h" | 37 #include "bindings/v8/V8Binding.h" |
| 38 #include "bindings/v8/V8ErrorHandler.h" | |
| 38 #include "bindings/v8/V8GCController.h" | 39 #include "bindings/v8/V8GCController.h" |
| 39 #include "bindings/v8/V8HiddenPropertyName.h" | 40 #include "bindings/v8/V8HiddenPropertyName.h" |
| 40 #include "bindings/v8/V8PerContextData.h" | 41 #include "bindings/v8/V8PerContextData.h" |
| 41 #include "core/dom/Document.h" | 42 #include "core/dom/Document.h" |
| 42 #include "core/dom/ExceptionCode.h" | 43 #include "core/dom/ExceptionCode.h" |
| 43 #include "core/inspector/ScriptCallStack.h" | 44 #include "core/inspector/ScriptCallStack.h" |
| 44 #include "core/page/ConsoleTypes.h" | 45 #include "core/page/ConsoleTypes.h" |
| 45 #include "core/page/ContentSecurityPolicy.h" | 46 #include "core/page/ContentSecurityPolicy.h" |
| 46 #include "core/page/DOMWindow.h" | 47 #include "core/page/DOMWindow.h" |
| 47 #include "core/page/Frame.h" | 48 #include "core/page/Frame.h" |
| 48 #include "core/platform/MemoryUsageSupport.h" | 49 #include "core/platform/MemoryUsageSupport.h" |
| 49 #include <v8-debug.h> | |
| 50 #include "wtf/RefPtr.h" | 50 #include "wtf/RefPtr.h" |
| 51 #include "wtf/text/WTFString.h" | 51 #include "wtf/text/WTFString.h" |
| 52 #include <v8-debug.h> | |
|
adamk
2013/08/09 17:11:32
This #include seems wrong...
Mike West
2013/08/09 20:34:51
It's already included, this CL just moves it to st
adamk
2013/08/09 21:29:25
Ah, sorry, didn't see this was just a move.
| |
| 52 | 53 |
| 53 namespace WebCore { | 54 namespace WebCore { |
| 54 | 55 |
| 55 static Frame* findFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> data, v 8::Isolate* isolate) | 56 static Frame* findFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> data, v 8::Isolate* isolate) |
| 56 { | 57 { |
| 57 WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data); | 58 WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data); |
| 58 | 59 |
| 59 if (V8Window::info.equals(type)) { | 60 if (V8Window::info.equals(type)) { |
| 60 v8::Handle<v8::Object> windowWrapper = host->FindInstanceInPrototypeChai n(V8Window::GetTemplate(isolate, worldTypeInMainThread(isolate))); | 61 v8::Handle<v8::Object> windowWrapper = host->FindInstanceInPrototypeChai n(V8Window::GetTemplate(isolate, worldTypeInMainThread(isolate))); |
| 61 if (windowWrapper.IsEmpty()) | 62 if (windowWrapper.IsEmpty()) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 92 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); | 93 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); |
| 93 RefPtr<ScriptCallStack> callStack; | 94 RefPtr<ScriptCallStack> callStack; |
| 94 // Currently stack trace is only collected when inspector is open. | 95 // Currently stack trace is only collected when inspector is open. |
| 95 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) | 96 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) |
| 96 callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallSt ackSizeToCapture); | 97 callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallSt ackSizeToCapture); |
| 97 | 98 |
| 98 v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); | 99 v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); |
| 99 bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsStrin g(); | 100 bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsStrin g(); |
| 100 String resource = shouldUseDocumentURL ? firstWindow->document()->url() : to WebCoreString(resourceName); | 101 String resource = shouldUseDocumentURL ? firstWindow->document()->url() : to WebCoreString(resourceName); |
| 101 RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, messag e->GetLineNumber(), message->GetStartColumn()); | 102 RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, messag e->GetLineNumber(), message->GetStartColumn()); |
| 103 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCr ossOrigin : NotSharableCrossOrigin; | |
| 102 | 104 |
| 103 // messageHandlerInMainThread can be called while we're creating a new conte xt. | 105 V8ErrorHandler::storeExceptionOnErrorEventWrapper(getScriptExecutionContext( ), event.get(), data, v8::Isolate::GetCurrent()); |
| 104 // Since we cannot create a wrapper in the intermediate timing, we need to s kip | |
| 105 // creating a wrapper for |event|. | |
| 106 DOMWrapperWorld* world = DOMWrapperWorld::current(); | |
| 107 Frame* frame = firstWindow->document()->frame(); | |
| 108 if (world && frame && frame->script()->existingWindowShell(world)) { | |
| 109 v8::Local<v8::Value> wrappedEvent = toV8(event.get(), v8::Handle<v8::Obj ect>(), v8::Isolate::GetCurrent()); | |
| 110 if (!wrappedEvent.IsEmpty()) { | |
| 111 ASSERT(wrappedEvent->IsObject()); | |
| 112 v8::Local<v8::Object>::Cast(wrappedEvent)->SetHiddenValue(V8HiddenPr opertyName::error(), data); | |
| 113 } | |
| 114 } | |
| 115 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCr ossOrigin : NotSharableCrossOrigin; | |
| 116 firstWindow->document()->reportException(event.release(), callStack, corsSta tus); | 106 firstWindow->document()->reportException(event.release(), callStack, corsSta tus); |
| 117 } | 107 } |
| 118 | 108 |
| 119 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8 ::AccessType type, v8::Local<v8::Value> data) | 109 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8 ::AccessType type, v8::Local<v8::Value> data) |
| 120 { | 110 { |
| 121 Frame* target = findFrame(host, data, v8::Isolate::GetCurrent()); | 111 Frame* target = findFrame(host, data, v8::Isolate::GetCurrent()); |
| 122 if (!target) | 112 if (!target) |
| 123 return; | 113 return; |
| 124 DOMWindow* targetWindow = target->domWindow(); | 114 DOMWindow* targetWindow = target->domWindow(); |
| 125 | 115 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 // WorkerGlobalScope::reportException will send the exception to the worker object. | 166 // WorkerGlobalScope::reportException will send the exception to the worker object. |
| 177 if (isReportingException) | 167 if (isReportingException) |
| 178 return; | 168 return; |
| 179 isReportingException = true; | 169 isReportingException = true; |
| 180 | 170 |
| 181 // During the frame teardown, there may not be a valid context. | 171 // During the frame teardown, there may not be a valid context. |
| 182 if (ScriptExecutionContext* context = getScriptExecutionContext()) { | 172 if (ScriptExecutionContext* context = getScriptExecutionContext()) { |
| 183 String errorMessage = toWebCoreString(message->Get()); | 173 String errorMessage = toWebCoreString(message->Get()); |
| 184 String sourceURL = toWebCoreString(message->GetScriptResourceName()); | 174 String sourceURL = toWebCoreString(message->GetScriptResourceName()); |
| 185 RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, m essage->GetLineNumber(), message->GetStartColumn()); | 175 RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, m essage->GetLineNumber(), message->GetStartColumn()); |
| 186 v8::Local<v8::Value> wrappedEvent = toV8(event.get(), v8::Handle<v8::Obj ect>(), v8::Isolate::GetCurrent()); | |
| 187 if (!wrappedEvent.IsEmpty()) { | |
| 188 ASSERT(wrappedEvent->IsObject()); | |
| 189 v8::Local<v8::Object>::Cast(wrappedEvent)->SetHiddenValue(V8HiddenPr opertyName::error(), data); | |
| 190 } | |
| 191 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? Sharab leCrossOrigin : NotSharableCrossOrigin; | 176 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? Sharab leCrossOrigin : NotSharableCrossOrigin; |
| 177 | |
| 178 V8ErrorHandler::storeExceptionOnErrorEventWrapper(context, event.get(), data, v8::Isolate::GetCurrent()); | |
| 192 context->reportException(event.release(), 0, corsStatus); | 179 context->reportException(event.release(), 0, corsStatus); |
| 193 } | 180 } |
| 194 | 181 |
| 195 isReportingException = false; | 182 isReportingException = false; |
| 196 } | 183 } |
| 197 | 184 |
| 198 static const int kWorkerMaxStackSize = 500 * 1024; | 185 static const int kWorkerMaxStackSize = 500 * 1024; |
| 199 | 186 |
| 200 void V8Initializer::initializeWorker(v8::Isolate* isolate) | 187 void V8Initializer::initializeWorker(v8::Isolate* isolate) |
| 201 { | 188 { |
| 202 initializeV8Common(); | 189 initializeV8Common(); |
| 203 | 190 |
| 204 v8::V8::AddMessageListener(messageHandlerInWorker); | 191 v8::V8::AddMessageListener(messageHandlerInWorker); |
| 205 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); | 192 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); |
| 206 | 193 |
| 207 v8::ResourceConstraints resourceConstraints; | 194 v8::ResourceConstraints resourceConstraints; |
| 208 uint32_t here; | 195 uint32_t here; |
| 209 resourceConstraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uin t32_t*)); | 196 resourceConstraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uin t32_t*)); |
| 210 v8::SetResourceConstraints(&resourceConstraints); | 197 v8::SetResourceConstraints(&resourceConstraints); |
| 211 | 198 |
| 212 V8PerIsolateData::ensureInitialized(isolate); | 199 V8PerIsolateData::ensureInitialized(isolate); |
| 213 } | 200 } |
| 214 | 201 |
| 215 } // namespace WebCore | 202 } // namespace WebCore |
| OLD | NEW |