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 12 matching lines...) Expand all Loading... |
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/core/v8/V8Initializer.h" | 27 #include "bindings/core/v8/V8Initializer.h" |
28 | 28 |
29 #include "bindings/core/v8/DOMWrapperWorld.h" | 29 #include "bindings/core/v8/DOMWrapperWorld.h" |
30 #include "bindings/core/v8/ScriptCallStackFactory.h" | 30 #include "bindings/core/v8/ScriptCallStackFactory.h" |
31 #include "bindings/core/v8/ScriptController.h" | 31 #include "bindings/core/v8/ScriptController.h" |
32 #include "bindings/core/v8/ScriptProfiler.h" | 32 #include "bindings/core/v8/ScriptProfiler.h" |
| 33 #include "bindings/core/v8/ScriptValue.h" |
33 #include "bindings/core/v8/V8Binding.h" | 34 #include "bindings/core/v8/V8Binding.h" |
34 #include "bindings/core/v8/V8DOMException.h" | 35 #include "bindings/core/v8/V8DOMException.h" |
35 #include "bindings/core/v8/V8ErrorEvent.h" | 36 #include "bindings/core/v8/V8ErrorEvent.h" |
36 #include "bindings/core/v8/V8ErrorHandler.h" | 37 #include "bindings/core/v8/V8ErrorHandler.h" |
37 #include "bindings/core/v8/V8GCController.h" | 38 #include "bindings/core/v8/V8GCController.h" |
38 #include "bindings/core/v8/V8History.h" | 39 #include "bindings/core/v8/V8History.h" |
39 #include "bindings/core/v8/V8Location.h" | 40 #include "bindings/core/v8/V8Location.h" |
40 #include "bindings/core/v8/V8PerContextData.h" | 41 #include "bindings/core/v8/V8PerContextData.h" |
41 #include "bindings/core/v8/V8Window.h" | 42 #include "bindings/core/v8/V8Window.h" |
42 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
43 #include "core/dom/ExceptionCode.h" | 44 #include "core/dom/ExceptionCode.h" |
44 #include "core/frame/ConsoleTypes.h" | 45 #include "core/frame/ConsoleTypes.h" |
45 #include "core/frame/LocalDOMWindow.h" | 46 #include "core/frame/LocalDOMWindow.h" |
46 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
47 #include "core/frame/csp/ContentSecurityPolicy.h" | 48 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 49 #include "core/inspector/ConsoleMessage.h" |
| 50 #include "core/inspector/ScriptArguments.h" |
48 #include "core/inspector/ScriptCallStack.h" | 51 #include "core/inspector/ScriptCallStack.h" |
49 #include "platform/EventDispatchForbiddenScope.h" | 52 #include "platform/EventDispatchForbiddenScope.h" |
50 #include "platform/TraceEvent.h" | 53 #include "platform/TraceEvent.h" |
51 #include "public/platform/Platform.h" | 54 #include "public/platform/Platform.h" |
52 #include "wtf/RefPtr.h" | 55 #include "wtf/RefPtr.h" |
53 #include "wtf/text/WTFString.h" | 56 #include "wtf/text/WTFString.h" |
54 #include <v8-debug.h> | 57 #include <v8-debug.h> |
55 | 58 |
56 namespace blink { | 59 namespace blink { |
57 | 60 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Allowing error events in private scripts is safe because error events
don't propagate to | 151 // Allowing error events in private scripts is safe because error events
don't propagate to |
149 // other isolated worlds (which means that the error events won't fire a
ny event listeners | 152 // other isolated worlds (which means that the error events won't fire a
ny event listeners |
150 // in user's scripts). | 153 // in user's scripts). |
151 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; | 154 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; |
152 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); | 155 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); |
153 } else { | 156 } else { |
154 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); | 157 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); |
155 } | 158 } |
156 } | 159 } |
157 | 160 |
| 161 typedef WillBeHeapDeque<ScriptValue> PromiseRejectMessageQueue; |
| 162 |
| 163 static PromiseRejectMessageQueue& promiseRejectMessageQueue() |
| 164 { |
| 165 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PromiseRejectMessageQueue>, queue
, (adoptPtrWillBeNoop(new PromiseRejectMessageQueue()))); |
| 166 return *queue; |
| 167 } |
| 168 |
| 169 void V8Initializer::reportRejectedPromises() |
| 170 { |
| 171 ASSERT(isMainThread()); |
| 172 |
| 173 PromiseRejectMessageQueue& queue = promiseRejectMessageQueue(); |
| 174 while (!queue.isEmpty()) { |
| 175 ScriptValue promise = queue.takeFirst(); |
| 176 ScriptState* scriptState = promise.scriptState(); |
| 177 if (!scriptState->contextIsValid()) |
| 178 continue; |
| 179 ScriptState::Scope scope(scriptState); |
| 180 |
| 181 ASSERT(!promise.isEmpty()); |
| 182 v8::Handle<v8::Value> value = promise.v8Value(); |
| 183 ASSERT(!value.IsEmpty() && value->IsPromise()); |
| 184 if (v8::Handle<v8::Promise>::Cast(value)->HasHandler()) |
| 185 continue; |
| 186 |
| 187 ExecutionContext* executionContext = scriptState->executionContext(); |
| 188 if (!executionContext) |
| 189 continue; |
| 190 |
| 191 const String errorMessage = "Unhandled promise rejection"; |
| 192 Vector<ScriptValue> args; |
| 193 args.append(ScriptValue(scriptState, v8String(scriptState->isolate(), er
rorMessage))); |
| 194 args.append(promise); |
| 195 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create(
scriptState, args); |
| 196 |
| 197 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea
te(JSMessageSource, ErrorMessageLevel, errorMessage, "", 0); |
| 198 consoleMessage->setScriptArguments(arguments); |
| 199 executionContext->addConsoleMessage(consoleMessage.release()); |
| 200 } |
| 201 } |
| 202 |
| 203 static void promiseRejectHandlerInMainThread(v8::PromiseRejectMessage message) |
| 204 { |
| 205 ASSERT(isMainThread()); |
| 206 |
| 207 if (message.GetEvent() != v8::kPromiseRejectWithNoHandler) |
| 208 return; |
| 209 |
| 210 // It's possible that promiseRejectHandlerInMainThread() is invoked while we
're initializing a window. |
| 211 // In that half-baked situation, we don't have a valid context nor a valid w
orld, |
| 212 // so just return immediately. |
| 213 if (DOMWrapperWorld::windowIsBeingInitialized()) |
| 214 return; |
| 215 |
| 216 v8::Handle<v8::Promise> promise = message.GetPromise(); |
| 217 |
| 218 // Bail out if called during context initialization. |
| 219 v8::Isolate* isolate = promise->GetIsolate(); |
| 220 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| 221 if (context.IsEmpty()) |
| 222 return; |
| 223 v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(contex
t->Global(), context->GetIsolate()); |
| 224 if (global.IsEmpty()) |
| 225 return; |
| 226 if (!toFrameIfNotDetached(context)) |
| 227 return; |
| 228 |
| 229 ScriptState* scriptState = ScriptState::from(context); |
| 230 promiseRejectMessageQueue().append(ScriptValue(scriptState, promise)); |
| 231 } |
| 232 |
158 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) | 233 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) |
159 { | 234 { |
160 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 235 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
161 LocalFrame* target = findFrame(host, data, isolate); | 236 LocalFrame* target = findFrame(host, data, isolate); |
162 if (!target) | 237 if (!target) |
163 return; | 238 return; |
164 LocalDOMWindow* targetWindow = target->domWindow(); | 239 LocalDOMWindow* targetWindow = target->domWindow(); |
165 | 240 |
166 // FIXME: We should modify V8 to pass in more contextual information (contex
t, property, and object). | 241 // FIXME: We should modify V8 to pass in more contextual information (contex
t, property, and object). |
167 ExceptionState exceptionState(ExceptionState::UnknownContext, 0, 0, isolate-
>GetCurrentContext()->Global(), isolate); | 242 ExceptionState exceptionState(ExceptionState::UnknownContext, 0, 0, isolate-
>GetCurrentContext()->Global(), isolate); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 286 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
212 | 287 |
213 initializeV8Common(isolate); | 288 initializeV8Common(isolate); |
214 | 289 |
215 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread); | 290 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread); |
216 v8::V8::AddMessageListener(messageHandlerInMainThread); | 291 v8::V8::AddMessageListener(messageHandlerInMainThread); |
217 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain
Thread); | 292 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain
Thread); |
218 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac
kInMainThread); | 293 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac
kInMainThread); |
219 | 294 |
220 isolate->SetEventLogger(timerTraceProfilerInMainThread); | 295 isolate->SetEventLogger(timerTraceProfilerInMainThread); |
| 296 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); |
221 | 297 |
222 ScriptProfiler::initialize(); | 298 ScriptProfiler::initialize(); |
223 } | 299 } |
224 | 300 |
225 static void reportFatalErrorInWorker(const char* location, const char* message) | 301 static void reportFatalErrorInWorker(const char* location, const char* message) |
226 { | 302 { |
227 // FIXME: We temporarily deal with V8 internal error situations such as out-
of-memory by crashing the worker. | 303 // FIXME: We temporarily deal with V8 internal error situations such as out-
of-memory by crashing the worker. |
228 CRASH(); | 304 CRASH(); |
229 } | 305 } |
230 | 306 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 initializeV8Common(isolate); | 342 initializeV8Common(isolate); |
267 | 343 |
268 v8::V8::AddMessageListener(messageHandlerInWorker); | 344 v8::V8::AddMessageListener(messageHandlerInWorker); |
269 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); | 345 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); |
270 | 346 |
271 uint32_t here; | 347 uint32_t here; |
272 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); | 348 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); |
273 } | 349 } |
274 | 350 |
275 } // namespace blink | 351 } // namespace blink |
OLD | NEW |