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()) | |
pfeldman
2014/10/06 19:40:13
That's a really bad name. Lets swap the semantics
Jens Widell
2014/10/07 05:22:23
https://codereview.chromium.org/622333002/
aandrey
2014/10/07 10:03:37
Acknowledged.
| |
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 const String errorMessage = "Unhandled promise rejection"; | |
188 Vector<ScriptValue> args; | |
189 args.append(ScriptValue(scriptState, v8String(scriptState->isolate(), er rorMessage))); | |
190 args.append(promise); | |
191 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create( scriptState, args); | |
192 | |
193 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea te(JSMessageSource, ErrorMessageLevel, errorMessage, "", 0); | |
194 consoleMessage->setScriptArguments(arguments); | |
195 scriptState->executionContext()->addConsoleMessage(consoleMessage.releas e()); | |
yurys
2014/10/07 05:32:44
We should be careful not to call this on ScriptSta
aandrey
2014/10/07 10:03:37
Added a test, this case does not repro.
Seems like
| |
196 } | |
197 } | |
198 | |
199 static void promiseRejectHandlerInMainThread(v8::Handle<v8::Promise> promise, v8 ::Handle<v8::Value> /*value*/, v8::PromiseRejectEvent event) | |
200 { | |
201 ASSERT(isMainThread()); | |
202 | |
203 if (event != v8::kPromiseRejectWithNoHandler) | |
204 return; | |
205 | |
206 // It's possible that promiseRejectHandlerInMainThread() is invoked while we 're initializing a window. | |
207 // In that half-baked situation, we don't have a valid context nor a valid w orld, | |
208 // so just return immediately. | |
209 if (DOMWrapperWorld::windowIsBeingInitialized()) | |
210 return; | |
211 | |
212 ScriptState* scriptState = ScriptState::current(promise->GetIsolate()); | |
213 promiseRejectMessageQueue().append(ScriptValue(scriptState, promise)); | |
214 } | |
215 | |
158 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8 ::AccessType type, v8::Local<v8::Value> data) | 216 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, v8 ::AccessType type, v8::Local<v8::Value> data) |
159 { | 217 { |
160 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 218 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
161 LocalFrame* target = findFrame(host, data, isolate); | 219 LocalFrame* target = findFrame(host, data, isolate); |
162 if (!target) | 220 if (!target) |
163 return; | 221 return; |
164 LocalDOMWindow* targetWindow = target->domWindow(); | 222 LocalDOMWindow* targetWindow = target->domWindow(); |
165 | 223 |
166 // FIXME: We should modify V8 to pass in more contextual information (contex t, property, and object). | 224 // 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); | 225 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(); | 269 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
212 | 270 |
213 initializeV8Common(isolate); | 271 initializeV8Common(isolate); |
214 | 272 |
215 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread); | 273 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread); |
216 v8::V8::AddMessageListener(messageHandlerInMainThread); | 274 v8::V8::AddMessageListener(messageHandlerInMainThread); |
217 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain Thread); | 275 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain Thread); |
218 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac kInMainThread); | 276 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac kInMainThread); |
219 | 277 |
220 isolate->SetEventLogger(timerTraceProfilerInMainThread); | 278 isolate->SetEventLogger(timerTraceProfilerInMainThread); |
279 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); | |
221 | 280 |
222 ScriptProfiler::initialize(); | 281 ScriptProfiler::initialize(); |
223 } | 282 } |
224 | 283 |
225 static void reportFatalErrorInWorker(const char* location, const char* message) | 284 static void reportFatalErrorInWorker(const char* location, const char* message) |
226 { | 285 { |
227 // FIXME: We temporarily deal with V8 internal error situations such as out- of-memory by crashing the worker. | 286 // FIXME: We temporarily deal with V8 internal error situations such as out- of-memory by crashing the worker. |
228 CRASH(); | 287 CRASH(); |
229 } | 288 } |
230 | 289 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 initializeV8Common(isolate); | 325 initializeV8Common(isolate); |
267 | 326 |
268 v8::V8::AddMessageListener(messageHandlerInWorker); | 327 v8::V8::AddMessageListener(messageHandlerInWorker); |
269 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); | 328 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); |
270 | 329 |
271 uint32_t here; | 330 uint32_t here; |
272 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi ze / sizeof(uint32_t*))); | 331 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi ze / sizeof(uint32_t*))); |
273 } | 332 } |
274 | 333 |
275 } // namespace blink | 334 } // namespace blink |
OLD | NEW |