Commit b51d327e authored by haraken's avatar haraken Committed by Commit bot

WindowProxy::initialize should never return null

It's already guaranteed that WindowProxy::initialize never returns null.
This CL just does some refactoring to make the fact clearer.

BUG=

Review-Url: https://codereview.chromium.org/2601773002
Cr-Commit-Position: refs/heads/master@{#440834}
parent df5e64aa
......@@ -221,11 +221,11 @@ WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) {
WindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) {
WindowProxy* windowProxy = m_windowProxyManager->windowProxy(world);
if (!windowProxy->isContextInitialized() &&
windowProxy->initializeIfNeeded() && world.isMainWorld())
frame()->loader().dispatchDidClearWindowObjectInMainWorld();
// FIXME: There are some situations where we can return an uninitialized
// context. This is broken.
if (!windowProxy->isContextInitialized()) {
windowProxy->initializeIfNeeded();
if (world.isMainWorld())
frame()->loader().dispatchDidClearWindowObjectInMainWorld();
}
return windowProxy;
}
......
......@@ -218,14 +218,13 @@ void WindowProxy::setGlobal(v8::Local<v8::Object> global) {
// the frame. However, a new inner window is created for the new page.
// If there are JS code holds a closure to the old inner window,
// it won't be able to reach the outer window via its global object.
bool WindowProxy::initializeIfNeeded() {
void WindowProxy::initializeIfNeeded() {
if (isContextInitialized())
return true;
return initialize();
return;
initialize();
}
bool WindowProxy::initialize() {
void WindowProxy::initialize() {
TRACE_EVENT1("v8", "WindowProxy::initialize", "isMainWindow",
m_frame->isMainFrame());
SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
......@@ -237,24 +236,16 @@ bool WindowProxy::initialize() {
v8::HandleScope handleScope(m_isolate);
createContext();
if (!isContextInitialized())
return false;
CHECK(isContextInitialized());
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Context> context = m_scriptState->context();
if (m_globalProxy.isEmpty()) {
m_globalProxy.set(m_isolate, context->Global());
if (m_globalProxy.isEmpty()) {
disposeContext(DoNotDetachGlobal);
return false;
}
CHECK(!m_globalProxy.isEmpty());
}
if (!setupWindowPrototypeChain()) {
disposeContext(DoNotDetachGlobal);
return false;
}
setupWindowPrototypeChain();
SecurityOrigin* origin = 0;
if (m_world->isMainWorld()) {
......@@ -286,8 +277,6 @@ bool WindowProxy::initialize() {
if (m_world->isMainWorld()) {
installPendingConditionalFeaturesOnWindow(m_scriptState.get());
}
return true;
}
void WindowProxy::createContext() {
......@@ -335,7 +324,7 @@ void WindowProxy::createContext() {
m_scriptState = ScriptState::create(context, m_world);
}
bool WindowProxy::setupWindowPrototypeChain() {
void WindowProxy::setupWindowPrototypeChain() {
// Associate the window wrapper object and its prototype chain with the
// corresponding native DOMWindow object.
// The full structure of the global object's prototype chain is as follows:
......@@ -400,7 +389,6 @@ bool WindowProxy::setupWindowPrototypeChain() {
// PagePopupController in another way.
V8PagePopupControllerBinding::installPagePopupController(context,
windowWrapper);
return true;
}
void WindowProxy::updateDocumentProperty() {
......
......@@ -77,7 +77,7 @@ class WindowProxy final : public GarbageCollectedFinalized<WindowProxy> {
}
bool isGlobalInitialized() { return !m_globalProxy.isEmpty(); }
bool initializeIfNeeded();
void initializeIfNeeded();
void updateDocumentWrapper(v8::Local<v8::Object> wrapper);
void clearForNavigation();
......@@ -91,7 +91,7 @@ class WindowProxy final : public GarbageCollectedFinalized<WindowProxy> {
private:
WindowProxy(Frame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*);
bool initialize();
void initialize();
enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal };
void disposeContext(GlobalDetachmentBehavior);
......@@ -114,7 +114,7 @@ class WindowProxy final : public GarbageCollectedFinalized<WindowProxy> {
// Associates the window wrapper and its prototype chain with the native
// DOMWindow object. Also does some more Window-specific initialization.
bool setupWindowPrototypeChain();
void setupWindowPrototypeChain();
Member<Frame> m_frame;
v8::Isolate* m_isolate;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment