Chromium Code Reviews| 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); |
| } |
| } |