| 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> |
| 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 // This method might be called while we're creating a new context. In this c
ase, we |
| 104 // Since we cannot create a wrapper in the intermediate timing, we need to s
kip | 106 // avoid storing the exception object, as we can't create a wrapper during c
ontext creation. |
| 105 // creating a wrapper for |event|. | |
| 106 DOMWrapperWorld* world = DOMWrapperWorld::current(); | 107 DOMWrapperWorld* world = DOMWrapperWorld::current(); |
| 107 Frame* frame = firstWindow->document()->frame(); | 108 Frame* frame = firstWindow->document()->frame(); |
| 108 if (world && frame && frame->script()->existingWindowShell(world)) { | 109 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 V8ErrorHandler::storeExceptionOnErrorEventWrapper(event.get(), data, 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); | 111 firstWindow->document()->reportException(event.release(), callStack, corsSta
tus); |
| 117 } | 112 } |
| 118 | 113 |
| 119 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) | 114 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) |
| 120 { | 115 { |
| 121 Frame* target = findFrame(host, data, v8::Isolate::GetCurrent()); | 116 Frame* target = findFrame(host, data, v8::Isolate::GetCurrent()); |
| 122 if (!target) | 117 if (!target) |
| 123 return; | 118 return; |
| 124 DOMWindow* targetWindow = target->domWindow(); | 119 DOMWindow* targetWindow = target->domWindow(); |
| 125 | 120 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // WorkerGlobalScope::reportException will send the exception to the worker
object. | 171 // WorkerGlobalScope::reportException will send the exception to the worker
object. |
| 177 if (isReportingException) | 172 if (isReportingException) |
| 178 return; | 173 return; |
| 179 isReportingException = true; | 174 isReportingException = true; |
| 180 | 175 |
| 181 // During the frame teardown, there may not be a valid context. | 176 // During the frame teardown, there may not be a valid context. |
| 182 if (ScriptExecutionContext* context = getScriptExecutionContext()) { | 177 if (ScriptExecutionContext* context = getScriptExecutionContext()) { |
| 183 String errorMessage = toWebCoreString(message->Get()); | 178 String errorMessage = toWebCoreString(message->Get()); |
| 184 String sourceURL = toWebCoreString(message->GetScriptResourceName()); | 179 String sourceURL = toWebCoreString(message->GetScriptResourceName()); |
| 185 RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, m
essage->GetLineNumber(), message->GetStartColumn()); | 180 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; | 181 AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? Sharab
leCrossOrigin : NotSharableCrossOrigin; |
| 182 |
| 183 V8ErrorHandler::storeExceptionOnErrorEventWrapper(event.get(), data, v8:
:Isolate::GetCurrent()); |
| 192 context->reportException(event.release(), 0, corsStatus); | 184 context->reportException(event.release(), 0, corsStatus); |
| 193 } | 185 } |
| 194 | 186 |
| 195 isReportingException = false; | 187 isReportingException = false; |
| 196 } | 188 } |
| 197 | 189 |
| 198 static const int kWorkerMaxStackSize = 500 * 1024; | 190 static const int kWorkerMaxStackSize = 500 * 1024; |
| 199 | 191 |
| 200 void V8Initializer::initializeWorker(v8::Isolate* isolate) | 192 void V8Initializer::initializeWorker(v8::Isolate* isolate) |
| 201 { | 193 { |
| 202 initializeV8Common(); | 194 initializeV8Common(); |
| 203 | 195 |
| 204 v8::V8::AddMessageListener(messageHandlerInWorker); | 196 v8::V8::AddMessageListener(messageHandlerInWorker); |
| 205 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); | 197 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); |
| 206 | 198 |
| 207 v8::ResourceConstraints resourceConstraints; | 199 v8::ResourceConstraints resourceConstraints; |
| 208 uint32_t here; | 200 uint32_t here; |
| 209 resourceConstraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uin
t32_t*)); | 201 resourceConstraints.set_stack_limit(&here - kWorkerMaxStackSize / sizeof(uin
t32_t*)); |
| 210 v8::SetResourceConstraints(&resourceConstraints); | 202 v8::SetResourceConstraints(&resourceConstraints); |
| 211 | 203 |
| 212 V8PerIsolateData::ensureInitialized(isolate); | 204 V8PerIsolateData::ensureInitialized(isolate); |
| 213 } | 205 } |
| 214 | 206 |
| 215 } // namespace WebCore | 207 } // namespace WebCore |
| OLD | NEW |