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" | |
34 #include "bindings/core/v8/V8Binding.h" | 33 #include "bindings/core/v8/V8Binding.h" |
35 #include "bindings/core/v8/V8DOMException.h" | 34 #include "bindings/core/v8/V8DOMException.h" |
36 #include "bindings/core/v8/V8ErrorEvent.h" | 35 #include "bindings/core/v8/V8ErrorEvent.h" |
37 #include "bindings/core/v8/V8ErrorHandler.h" | 36 #include "bindings/core/v8/V8ErrorHandler.h" |
38 #include "bindings/core/v8/V8GCController.h" | 37 #include "bindings/core/v8/V8GCController.h" |
39 #include "bindings/core/v8/V8History.h" | 38 #include "bindings/core/v8/V8History.h" |
40 #include "bindings/core/v8/V8Location.h" | 39 #include "bindings/core/v8/V8Location.h" |
41 #include "bindings/core/v8/V8PerContextData.h" | 40 #include "bindings/core/v8/V8PerContextData.h" |
42 #include "bindings/core/v8/V8Window.h" | 41 #include "bindings/core/v8/V8Window.h" |
43 #include "core/dom/Document.h" | 42 #include "core/dom/Document.h" |
44 #include "core/dom/ExceptionCode.h" | 43 #include "core/dom/ExceptionCode.h" |
45 #include "core/frame/ConsoleTypes.h" | 44 #include "core/frame/ConsoleTypes.h" |
46 #include "core/frame/LocalDOMWindow.h" | 45 #include "core/frame/LocalDOMWindow.h" |
47 #include "core/frame/LocalFrame.h" | 46 #include "core/frame/LocalFrame.h" |
48 #include "core/frame/csp/ContentSecurityPolicy.h" | 47 #include "core/frame/csp/ContentSecurityPolicy.h" |
49 #include "core/inspector/ConsoleMessage.h" | |
50 #include "core/inspector/ScriptArguments.h" | |
51 #include "core/inspector/ScriptCallStack.h" | 48 #include "core/inspector/ScriptCallStack.h" |
52 #include "platform/EventDispatchForbiddenScope.h" | 49 #include "platform/EventDispatchForbiddenScope.h" |
53 #include "platform/TraceEvent.h" | 50 #include "platform/TraceEvent.h" |
54 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
55 #include "wtf/RefPtr.h" | 52 #include "wtf/RefPtr.h" |
56 #include "wtf/text/WTFString.h" | 53 #include "wtf/text/WTFString.h" |
57 #include <v8-debug.h> | 54 #include <v8-debug.h> |
58 | 55 |
59 namespace blink { | 56 namespace blink { |
60 | 57 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // Allowing error events in private scripts is safe because error events
don't propagate to | 148 // Allowing error events in private scripts is safe because error events
don't propagate to |
152 // other isolated worlds (which means that the error events won't fire a
ny event listeners | 149 // other isolated worlds (which means that the error events won't fire a
ny event listeners |
153 // in user's scripts). | 150 // in user's scripts). |
154 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; | 151 EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents; |
155 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); | 152 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); |
156 } else { | 153 } else { |
157 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); | 154 enteredWindow->document()->reportException(event.release(), scriptId, ca
llStack, corsStatus); |
158 } | 155 } |
159 } | 156 } |
160 | 157 |
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 ScriptState* scriptState = ScriptState::current(promise->GetIsolate()); | |
218 promiseRejectMessageQueue().append(ScriptValue(scriptState, promise)); | |
219 } | |
220 | |
221 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) | 158 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8
::AccessType type, v8::Local<v8::Value> data) |
222 { | 159 { |
223 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 160 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
224 LocalFrame* target = findFrame(host, data, isolate); | 161 LocalFrame* target = findFrame(host, data, isolate); |
225 if (!target) | 162 if (!target) |
226 return; | 163 return; |
227 LocalDOMWindow* targetWindow = target->domWindow(); | 164 LocalDOMWindow* targetWindow = target->domWindow(); |
228 | 165 |
229 // FIXME: We should modify V8 to pass in more contextual information (contex
t, property, and object). | 166 // FIXME: We should modify V8 to pass in more contextual information (contex
t, property, and object). |
230 ExceptionState exceptionState(ExceptionState::UnknownContext, 0, 0, isolate-
>GetCurrentContext()->Global(), isolate); | 167 ExceptionState exceptionState(ExceptionState::UnknownContext, 0, 0, isolate-
>GetCurrentContext()->Global(), isolate); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 v8::Isolate* isolate = V8PerIsolateData::initialize(); | 211 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
275 | 212 |
276 initializeV8Common(isolate); | 213 initializeV8Common(isolate); |
277 | 214 |
278 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread); | 215 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread); |
279 v8::V8::AddMessageListener(messageHandlerInMainThread); | 216 v8::V8::AddMessageListener(messageHandlerInMainThread); |
280 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain
Thread); | 217 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain
Thread); |
281 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac
kInMainThread); | 218 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac
kInMainThread); |
282 | 219 |
283 isolate->SetEventLogger(timerTraceProfilerInMainThread); | 220 isolate->SetEventLogger(timerTraceProfilerInMainThread); |
284 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); | |
285 | 221 |
286 ScriptProfiler::initialize(); | 222 ScriptProfiler::initialize(); |
287 } | 223 } |
288 | 224 |
289 static void reportFatalErrorInWorker(const char* location, const char* message) | 225 static void reportFatalErrorInWorker(const char* location, const char* message) |
290 { | 226 { |
291 // FIXME: We temporarily deal with V8 internal error situations such as out-
of-memory by crashing the worker. | 227 // FIXME: We temporarily deal with V8 internal error situations such as out-
of-memory by crashing the worker. |
292 CRASH(); | 228 CRASH(); |
293 } | 229 } |
294 | 230 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 initializeV8Common(isolate); | 266 initializeV8Common(isolate); |
331 | 267 |
332 v8::V8::AddMessageListener(messageHandlerInWorker); | 268 v8::V8::AddMessageListener(messageHandlerInWorker); |
333 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); | 269 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); |
334 | 270 |
335 uint32_t here; | 271 uint32_t here; |
336 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); | 272 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi
ze / sizeof(uint32_t*))); |
337 } | 273 } |
338 | 274 |
339 } // namespace blink | 275 } // namespace blink |
OLD | NEW |