Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp

Issue 1885833002: Make messageHandlerInMainThread support main-thread worklets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp b/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
index 2aae5b22c7a59fd33cd33083d1b7ff233abc770f..df1b3a89933295f91cb6c218cabbd1ea869a4a55 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
@@ -111,11 +111,11 @@ static PassRefPtr<ScriptCallStack> extractCallStack(v8::Isolate* isolate, v8::Lo
return callStack.release();
}
-static String extractResourceName(v8::Local<v8::Message> message, const Document* document)
+static String extractResourceName(v8::Local<v8::Message> message, const ExecutionContext* context)
{
v8::Local<v8::Value> resourceName = message->GetScriptOrigin().ResourceName();
- bool shouldUseDocumentURL = document && (resourceName.IsEmpty() || !resourceName->IsString());
- return shouldUseDocumentURL ? document->url() : toCoreString(resourceName.As<v8::String>());
+ bool shouldUseDocumentURL = context && context->isDocument() && (resourceName.IsEmpty() || !resourceName->IsString());
+ return shouldUseDocumentURL ? context->url() : toCoreString(resourceName.As<v8::String>());
}
static String extractMessageForConsole(v8::Isolate* isolate, v8::Local<v8::Value> data)
@@ -146,11 +146,17 @@ static ErrorEvent* createErrorEventFromMesssage(ScriptState* scriptState, v8::Lo
static void messageHandlerInMainThread(v8::Local<v8::Message> message, v8::Local<v8::Value> data)
{
ASSERT(isMainThread());
+
v8::Isolate* isolate = v8::Isolate::GetCurrent();
- // If called during context initialization, there will be no entered window.
+ ScriptState* scriptState = ScriptState::current(isolate);
+ ExecutionContext* context = scriptState->getExecutionContext();
+
+ // If called during context initialization, there will be no entered context.
// TODO(haraken): Add a helper method to get an entered window that may be null.
- LocalDOMWindow* enteredWindow = toLocalDOMWindow(toDOMWindow(isolate->GetEnteredContext()));
- if (!enteredWindow || !enteredWindow->isCurrentlyDisplayedInFrame())
+ if (!context)
+ return;
+
+ if (context->isDocument() && !toDocument(context)->domWindow()->isCurrentlyDisplayedInFrame())
ikilpatrick 2016/04/13 04:21:09 Is toDocument(context)->domWindow() safe? (non-nul
haraken 2016/04/13 04:38:48 This can change existing behavior because the ente
ikilpatrick 2016/04/13 23:26:53 Done. Tried to clean up the other ScriptState chec
return;
int scriptId = 0;
@@ -162,9 +168,7 @@ static void messageHandlerInMainThread(v8::Local<v8::Message> message, v8::Local
else if (message->IsSharedCrossOrigin())
accessControlStatus = SharableCrossOrigin;
- ScriptState* scriptState = ScriptState::current(isolate);
-
- String resourceName = extractResourceName(message, enteredWindow->document());
+ String resourceName = extractResourceName(message, context);
ErrorEvent* event = createErrorEventFromMesssage(scriptState, message, resourceName);
String messageForConsole = extractMessageForConsole(isolate, data);
@@ -174,9 +178,11 @@ static void messageHandlerInMainThread(v8::Local<v8::Message> message, v8::Local
// This method might be called while we're creating a new context. In this case, we
// avoid storing the exception object, as we can't create a wrapper during context creation.
// FIXME: Can we even get here during initialization now that we bail out when GetEntered returns an empty handle?
- LocalFrame* frame = enteredWindow->document()->frame();
- if (frame && frame->script().existingWindowProxy(scriptState->world())) {
- V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, data, scriptState->context()->Global());
+ if (context->isDocument()) {
+ LocalFrame* frame = toDocument(context)->frame();
+ if (frame && frame->script().existingWindowProxy(scriptState->world())) {
+ V8ErrorHandler::storeExceptionOnErrorEventWrapper(scriptState, event, data, scriptState->context()->Global());
+ }
}
if (scriptState->world().isPrivateScriptIsolatedWorld()) {
@@ -187,9 +193,9 @@ static void messageHandlerInMainThread(v8::Local<v8::Message> message, v8::Local
// other isolated worlds (which means that the error events won't fire any event listeners
// in user's scripts).
EventDispatchForbiddenScope::AllowUserAgentEvents allowUserAgentEvents;
- enteredWindow->document()->reportException(event, scriptId, callStack, accessControlStatus);
+ context->reportException(event, scriptId, callStack, accessControlStatus);
} else {
- enteredWindow->document()->reportException(event, scriptId, callStack, accessControlStatus);
+ context->reportException(event, scriptId, callStack, accessControlStatus);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698