Merge from Chromium at DEPS revision 260540

This commit was generated by merge_to_master.py.

Change-Id: I59405d8a82d381c51259a8c53360f0c4e1b89f50
diff --git a/Source/bindings/v8/CustomElementConstructorBuilder.cpp b/Source/bindings/v8/CustomElementConstructorBuilder.cpp
index fd0f161..b4e4e84 100644
--- a/Source/bindings/v8/CustomElementConstructorBuilder.cpp
+++ b/Source/bindings/v8/CustomElementConstructorBuilder.cpp
@@ -66,7 +66,7 @@
 
 bool CustomElementConstructorBuilder::isFeatureAllowed() const
 {
-    return DOMWrapperWorld::world(m_context)->isMainWorld();
+    return DOMWrapperWorld::world(m_context).isMainWorld();
 }
 
 bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type, QualifiedName& tagName, ExceptionState& exceptionState)
diff --git a/Source/bindings/v8/CustomElementWrapper.cpp b/Source/bindings/v8/CustomElementWrapper.cpp
index f4fafbb..8e44d2a 100644
--- a/Source/bindings/v8/CustomElementWrapper.cpp
+++ b/Source/bindings/v8/CustomElementWrapper.cpp
@@ -95,7 +95,7 @@
     // to never pass an empty creation context.
     v8::Handle<v8::Context> context = creationContext.IsEmpty() ? isolate->GetCurrentContext() : creationContext->CreationContext();
 
-    if (!element->isUpgradedCustomElement() || DOMWrapperWorld::world(context)->isIsolatedWorld())
+    if (!element->isUpgradedCustomElement() || DOMWrapperWorld::world(context).isIsolatedWorld())
         return createUpgradeCandidateWrapper(element.get(), creationContext, isolate, createSpecificWrapper);
 
     V8PerContextData* perContextData = V8PerContextData::from(context);
diff --git a/Source/bindings/v8/DOMDataStore.cpp b/Source/bindings/v8/DOMDataStore.cpp
index e4ec115..c9ef7c4 100644
--- a/Source/bindings/v8/DOMDataStore.cpp
+++ b/Source/bindings/v8/DOMDataStore.cpp
@@ -51,7 +51,7 @@
 
 DOMDataStore& DOMDataStore::current(v8::Isolate* isolate)
 {
-    return DOMWrapperWorld::world(isolate->GetCurrentContext())->domDataStore();
+    return DOMWrapperWorld::current(isolate).domDataStore();
 }
 
 } // namespace WebCore
diff --git a/Source/bindings/v8/DOMDataStore.h b/Source/bindings/v8/DOMDataStore.h
index c45034c..a1a93b5 100644
--- a/Source/bindings/v8/DOMDataStore.h
+++ b/Source/bindings/v8/DOMDataStore.h
@@ -74,7 +74,7 @@
         if (holderContainsWrapper(holder, wrappable)) {
             if (ScriptWrappable::wrapperCanBeStoredInObject(object))
                 return ScriptWrappable::setReturnValueWithSecurityCheck<V8T>(returnValue, object);
-            return DOMWrapperWorld::mainWorld()->domDataStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object));
+            return DOMWrapperWorld::mainWorld().domDataStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object));
         }
         return current(returnValue.GetIsolate()).template setReturnValueFrom<V8T>(returnValue, object);
     }
@@ -92,7 +92,7 @@
     {
         if (ScriptWrappable::wrapperCanBeStoredInObject(object))
             return ScriptWrappable::setReturnValue(returnValue, object);
-        return DOMWrapperWorld::mainWorld()->domDataStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object));
+        return DOMWrapperWorld::mainWorld().domDataStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object));
     }
 
     template<typename V8T, typename T>
diff --git a/Source/bindings/v8/DOMRequestState.h b/Source/bindings/v8/DOMRequestState.h
index 32992b8..59af33f 100644
--- a/Source/bindings/v8/DOMRequestState.h
+++ b/Source/bindings/v8/DOMRequestState.h
@@ -34,6 +34,7 @@
 
 namespace WebCore {
 
+// FIXME: DOMRequestState is deprecated and going to be removed. Use NewScriptState instead.
 class DOMRequestState {
 public:
     explicit DOMRequestState(ExecutionContext* executionContext)
@@ -65,7 +66,7 @@
     v8::Local<v8::Context> context()
     {
         ASSERT(m_executionContext);
-        return toV8Context(m_executionContext, m_world.get());
+        return toV8Context(m_executionContext, *m_world);
     }
 
     v8::Isolate* isolate() const
diff --git a/Source/bindings/v8/DOMWrapperWorld.cpp b/Source/bindings/v8/DOMWrapperWorld.cpp
index f85f815..b336abd 100644
--- a/Source/bindings/v8/DOMWrapperWorld.cpp
+++ b/Source/bindings/v8/DOMWrapperWorld.cpp
@@ -60,11 +60,11 @@
 {
 }
 
-DOMWrapperWorld* DOMWrapperWorld::mainWorld()
+DOMWrapperWorld& DOMWrapperWorld::mainWorld()
 {
     ASSERT(isMainThread());
     DEFINE_STATIC_REF(DOMWrapperWorld, cachedMainWorld, (DOMWrapperWorld::create(MainWorldId, mainWorldExtensionGroup)));
-    return cachedMainWorld;
+    return *cachedMainWorld;
 }
 
 typedef HashMap<int, DOMWrapperWorld*> WorldMap;
@@ -78,7 +78,7 @@
 void DOMWrapperWorld::allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds)
 {
     ASSERT(isMainThread());
-    worlds.append(mainWorld());
+    worlds.append(&mainWorld());
     WorldMap& isolatedWorlds = isolatedWorldMap();
     for (WorldMap::iterator it = isolatedWorlds.begin(); it != isolatedWorlds.end(); ++it)
         worlds.append(it->value);
diff --git a/Source/bindings/v8/DOMWrapperWorld.h b/Source/bindings/v8/DOMWrapperWorld.h
index b9e0533..4f3a4e7 100644
--- a/Source/bindings/v8/DOMWrapperWorld.h
+++ b/Source/bindings/v8/DOMWrapperWorld.h
@@ -31,7 +31,7 @@
 #ifndef DOMWrapperWorld_h
 #define DOMWrapperWorld_h
 
-#include "bindings/v8/V8PerContextData.h"
+#include "bindings/v8/NewScriptState.h"
 #include "platform/weborigin/SecurityOrigin.h"
 #include "wtf/MainThread.h"
 #include "wtf/PassRefPtr.h"
@@ -69,26 +69,24 @@
     static bool isolatedWorldsExist() { return isolatedWorldCount; }
     static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds);
 
-    static DOMWrapperWorld* world(v8::Handle<v8::Context> context)
+    static DOMWrapperWorld& world(v8::Handle<v8::Context> context)
     {
-        ASSERT(!context.IsEmpty());
-        return V8PerContextData::world(context);
+        return NewScriptState::from(context)->world();
     }
 
-    // Will return null if there is no DOMWrapperWorld for the current context.
-    static DOMWrapperWorld* current(v8::Isolate* isolate)
+    static DOMWrapperWorld& current(v8::Isolate* isolate)
     {
         if (isMainThread() && worldOfInitializingWindow) {
             // It's possible that current() is being called while window is being initialized.
             // In order to make current() workable during the initialization phase,
             // we cache the world of the initializing window on worldOfInitializingWindow.
             // If there is no initiazing window, worldOfInitializingWindow is 0.
-            return worldOfInitializingWindow;
+            return *worldOfInitializingWindow;
         }
         return world(isolate->GetCurrentContext());
     }
 
-    static DOMWrapperWorld* mainWorld();
+    static DOMWrapperWorld& mainWorld();
 
     // Associates an isolated world (see above for description) with a security
     // origin. XMLHttpRequest instances used in that world will be considered
diff --git a/Source/bindings/v8/MIDIAccessResolver.cpp b/Source/bindings/v8/MIDIAccessResolver.cpp
index 2ab4288..f7c9315 100644
--- a/Source/bindings/v8/MIDIAccessResolver.cpp
+++ b/Source/bindings/v8/MIDIAccessResolver.cpp
@@ -24,7 +24,7 @@
 void MIDIAccessResolver::resolve(MIDIAccess* access, ExecutionContext* executionContext)
 {
     v8::HandleScope handleScope(toIsolate(executionContext));
-    v8::Context::Scope contextScope(toV8Context(executionContext, m_world.get()));
+    v8::Context::Scope contextScope(toV8Context(executionContext, *m_world));
 
     m_resolver->resolve(access, executionContext);
 }
@@ -32,7 +32,7 @@
 void MIDIAccessResolver::reject(DOMError* error, ExecutionContext* executionContext)
 {
     v8::HandleScope handleScope(toIsolate(executionContext));
-    v8::Context::Scope contextScope(toV8Context(executionContext, m_world.get()));
+    v8::Context::Scope contextScope(toV8Context(executionContext, *m_world));
 
     m_resolver->reject(error, executionContext);
 }
diff --git a/Source/bindings/v8/NewScriptState.cpp b/Source/bindings/v8/NewScriptState.cpp
new file mode 100644
index 0000000..421ba28
--- /dev/null
+++ b/Source/bindings/v8/NewScriptState.cpp
@@ -0,0 +1,47 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "bindings/v8/NewScriptState.h"
+
+#include "bindings/v8/V8Binding.h"
+
+namespace WebCore {
+
+void NewScriptState::install(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperWorld> world)
+{
+    RefPtr<NewScriptState> scriptState = adoptRef(new NewScriptState(context, world));
+    scriptState->ref();
+}
+
+static void weakCallback(const v8::WeakCallbackData<v8::Context, NewScriptState>& data)
+{
+    data.GetValue()->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, 0);
+    data.GetParameter()->clearContext();
+    data.GetParameter()->deref();
+}
+
+NewScriptState::NewScriptState(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperWorld> world)
+    : m_isolate(context->GetIsolate())
+    , m_context(m_isolate, context)
+    , m_perContextData(0)
+    , m_world(world)
+{
+    ASSERT(m_world);
+    m_context.setWeak(this, &weakCallback);
+    context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, this);
+}
+
+NewScriptState::~NewScriptState()
+{
+    ASSERT(!m_perContextData);
+    ASSERT(m_context.isEmpty());
+}
+
+ExecutionContext* NewScriptState::executionContext() const
+{
+    return toExecutionContext(context());
+}
+
+}
diff --git a/Source/bindings/v8/NewScriptState.h b/Source/bindings/v8/NewScriptState.h
new file mode 100644
index 0000000..62536db
--- /dev/null
+++ b/Source/bindings/v8/NewScriptState.h
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NewScriptState_h
+#define NewScriptState_h
+
+#include "bindings/v8/ScopedPersistent.h"
+#include "bindings/v8/V8PerContextData.h"
+#include "wtf/RefCounted.h"
+#include <v8.h>
+
+namespace WebCore {
+
+class DOMWrapperWorld;
+class ExecutionContext;
+
+// NewScriptState is created when v8::Context is created.
+// NewScriptState is destroyed when v8::Context is garbage-collected and
+// all V8 proxy objects that have references to the NewScriptState are destructed.
+class NewScriptState : public RefCounted<NewScriptState> {
+    WTF_MAKE_NONCOPYABLE(NewScriptState);
+public:
+    static void install(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
+    ~NewScriptState();
+
+    static NewScriptState* current(v8::Isolate* isolate)
+    {
+        return from(isolate->GetCurrentContext());
+    }
+
+    static NewScriptState* from(v8::Handle<v8::Context> context)
+    {
+        ASSERT(!context.IsEmpty());
+        NewScriptState* scriptState = static_cast<NewScriptState*>(context->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex));
+        // NewScriptState::from() must not be called for a context that does not have
+        // valid embedder data in the embedder field.
+        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState);
+        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState->context() == context);
+        return scriptState;
+    }
+
+    v8::Isolate* isolate() const { return m_isolate; }
+    DOMWrapperWorld& world() const { return *m_world; }
+    // This can return an empty handle if the v8::Context is gone.
+    v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolate); }
+    void clearContext() { return m_context.clear(); }
+    ExecutionContext* executionContext() const;
+    V8PerContextData* perContextData() const { return m_perContextData; }
+    void setPerContextData(V8PerContextData* data) { m_perContextData = data; }
+
+private:
+    NewScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
+
+    v8::Isolate* m_isolate;
+    ScopedPersistent<v8::Context> m_context;
+    V8PerContextData* m_perContextData;
+    // This RefPtr doesn't cause a cycle because all persistent handles that DOMWrapperWorld holds are weak.
+    RefPtr<DOMWrapperWorld> m_world;
+};
+
+}
+
+#endif // NewScriptState_h
diff --git a/Source/bindings/v8/ScriptController.cpp b/Source/bindings/v8/ScriptController.cpp
index 545dd83..3ab83af 100644
--- a/Source/bindings/v8/ScriptController.cpp
+++ b/Source/bindings/v8/ScriptController.cpp
@@ -209,34 +209,30 @@
     return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized();
 }
 
-V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld* world)
+V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld& world)
 {
-    ASSERT(world);
-
-    if (world->isMainWorld())
+    if (world.isMainWorld())
         return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0;
 
-    IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId());
+    IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId());
     if (iter == m_isolatedWorlds.end())
         return 0;
     return iter->value->isContextInitialized() ? iter->value.get() : 0;
 }
 
-V8WindowShell* ScriptController::windowShell(DOMWrapperWorld* world)
+V8WindowShell* ScriptController::windowShell(DOMWrapperWorld& world)
 {
-    ASSERT(world);
-
     V8WindowShell* shell = 0;
-    if (world->isMainWorld())
+    if (world.isMainWorld())
         shell = m_windowShell.get();
     else {
-        IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId());
+        IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId());
         if (iter != m_isolatedWorlds.end())
             shell = iter->value.get();
         else {
             OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_frame, world, m_isolate);
             shell = isolatedWorldShell.get();
-            m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release());
+            m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release());
         }
     }
     if (!shell->isContextInitialized() && shell->initializeIfNeeded())
@@ -249,8 +245,8 @@
     v8::Handle<v8::Context> context = m_isolate->GetCurrentContext();
     if (context.IsEmpty() || !toDOMWindow(context))
         return false;
-    DOMWrapperWorld* world = DOMWrapperWorld::current(m_isolate);
-    return world->isIsolatedWorld() ? world->isolatedWorldHasContentSecurityPolicy() : false;
+    DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate);
+    return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() : false;
 }
 
 TextPosition ScriptController::eventHandlerPosition() const
@@ -449,7 +445,7 @@
     v8::HandleScope handleScope(m_isolate);
     for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isolatedWorlds.end(); ++it) {
         V8WindowShell* isolatedWorldShell = it->value.get();
-        SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecurityOrigin();
+        SecurityOrigin* origin = isolatedWorldShell->world().isolatedWorldSecurityOrigin();
         if (!origin)
             continue;
         v8::Local<v8::Context> v8Context = isolatedWorldShell->context();
@@ -615,7 +611,7 @@
     {
         v8::EscapableHandleScope evaluateHandleScope(m_isolate);
         RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldID, extensionGroup);
-        V8WindowShell* isolatedWorldShell = windowShell(world.get());
+        V8WindowShell* isolatedWorldShell = windowShell(*world);
 
         if (!isolatedWorldShell->isContextInitialized())
             return;
diff --git a/Source/bindings/v8/ScriptController.h b/Source/bindings/v8/ScriptController.h
index 6a9ece2..c4f97e7 100644
--- a/Source/bindings/v8/ScriptController.h
+++ b/Source/bindings/v8/ScriptController.h
@@ -77,8 +77,8 @@
     ~ScriptController();
 
     bool initializeMainWorld();
-    V8WindowShell* windowShell(DOMWrapperWorld*);
-    V8WindowShell* existingWindowShell(DOMWrapperWorld*);
+    V8WindowShell* windowShell(DOMWrapperWorld&);
+    V8WindowShell* existingWindowShell(DOMWrapperWorld&);
 
     // Evaluate JavaScript in the main world.
     void executeScriptInMainWorld(const String&, ExecuteScriptPolicy = DoNotExecuteScriptWhenScriptsDisabled);
diff --git a/Source/bindings/v8/ScriptPreprocessor.cpp b/Source/bindings/v8/ScriptPreprocessor.cpp
index ecf71b7..8305ae4 100644
--- a/Source/bindings/v8/ScriptPreprocessor.cpp
+++ b/Source/bindings/v8/ScriptPreprocessor.cpp
@@ -67,7 +67,7 @@
     }
 
     m_world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWorldId, DOMWrapperWorld::mainWorldExtensionGroup);
-    v8::Local<v8::Context> context = toV8Context(m_isolate, frame, m_world.get());
+    v8::Local<v8::Context> context = toV8Context(m_isolate, frame, *m_world);
 
     m_context.set(m_isolate, context);
     m_preprocessorFunction.set(m_isolate, v8::Handle<v8::Function>::Cast(preprocessorFunction.v8Value()));
diff --git a/Source/bindings/v8/ScriptState.h b/Source/bindings/v8/ScriptState.h
index b2d03cc..b84c74b 100644
--- a/Source/bindings/v8/ScriptState.h
+++ b/Source/bindings/v8/ScriptState.h
@@ -43,6 +43,7 @@
 class ExecutionContext;
 class WorkerGlobalScope;
 
+// FIXME: ScriptState is deprecated and going to be removed. Use NewScriptState instead.
 class ScriptState {
     WTF_MAKE_NONCOPYABLE(ScriptState);
 public:
diff --git a/Source/bindings/v8/SerializedScriptValue.cpp b/Source/bindings/v8/SerializedScriptValue.cpp
index 18e6458..aadb4c7 100644
--- a/Source/bindings/v8/SerializedScriptValue.cpp
+++ b/Source/bindings/v8/SerializedScriptValue.cpp
@@ -2772,7 +2772,7 @@
             }
         }
     } else {
-        v8::Handle<v8::Object> wrapper = DOMWrapperWorld::current(isolate)->domDataStore().get<V8ArrayBuffer>(object, isolate);
+        v8::Handle<v8::Object> wrapper = DOMDataStore::current(isolate).get<V8ArrayBuffer>(object, isolate);
         if (!wrapper.IsEmpty()) {
             ASSERT(wrapper->IsArrayBuffer());
             v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter();
diff --git a/Source/bindings/v8/V8AbstractEventListener.cpp b/Source/bindings/v8/V8AbstractEventListener.cpp
index 61720ea..dc74537 100644
--- a/Source/bindings/v8/V8AbstractEventListener.cpp
+++ b/Source/bindings/v8/V8AbstractEventListener.cpp
@@ -43,7 +43,7 @@
 
 namespace WebCore {
 
-V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, DOMWrapperWorld* world, v8::Isolate* isolate)
+V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, DOMWrapperWorld& world, v8::Isolate* isolate)
     : EventListener(JSEventListenerType)
     , m_isAttribute(isAttribute)
     , m_world(world)
@@ -177,7 +177,7 @@
 
 bool V8AbstractEventListener::belongsToTheCurrentWorld() const
 {
-    return m_isolate->InContext() && m_world == DOMWrapperWorld::current(m_isolate);
+    return m_isolate->InContext() && m_world == &DOMWrapperWorld::current(m_isolate);
 }
 
 void V8AbstractEventListener::setWeakCallback(const v8::WeakCallbackData<v8::Object, V8AbstractEventListener> &data)
diff --git a/Source/bindings/v8/V8AbstractEventListener.h b/Source/bindings/v8/V8AbstractEventListener.h
index 37b1542..ecae8f1 100644
--- a/Source/bindings/v8/V8AbstractEventListener.h
+++ b/Source/bindings/v8/V8AbstractEventListener.h
@@ -109,11 +109,11 @@
         }
 
         virtual bool belongsToTheCurrentWorld() const OVERRIDE FINAL;
-        virtual DOMWrapperWorld* world() const OVERRIDE FINAL { return m_world.get(); }
+        DOMWrapperWorld& world() const { return *m_world; }
         v8::Isolate* isolate() const { return m_isolate; }
 
     protected:
-        V8AbstractEventListener(bool isAttribute, DOMWrapperWorld*, v8::Isolate*);
+        V8AbstractEventListener(bool isAttribute, DOMWrapperWorld&, v8::Isolate*);
 
         virtual void prepareListenerObject(ExecutionContext*) { }
 
diff --git a/Source/bindings/v8/V8Binding.cpp b/Source/bindings/v8/V8Binding.cpp
index 58b2e23..1be9f25 100644
--- a/Source/bindings/v8/V8Binding.cpp
+++ b/Source/bindings/v8/V8Binding.cpp
@@ -549,7 +549,7 @@
     return 0;
 }
 
-v8::Local<v8::Context> toV8Context(ExecutionContext* context, DOMWrapperWorld* world)
+v8::Local<v8::Context> toV8Context(ExecutionContext* context, DOMWrapperWorld& world)
 {
     ASSERT(context);
     if (context->isDocument()) {
@@ -562,7 +562,7 @@
     return v8::Local<v8::Context>();
 }
 
-v8::Local<v8::Context> toV8Context(v8::Isolate* isolate, LocalFrame* frame, DOMWrapperWorld* world)
+v8::Local<v8::Context> toV8Context(v8::Isolate* isolate, LocalFrame* frame, DOMWrapperWorld& world)
 {
     if (!frame)
         return v8::Local<v8::Context>();
diff --git a/Source/bindings/v8/V8Binding.h b/Source/bindings/v8/V8Binding.h
index dc33490..5afa6cd 100644
--- a/Source/bindings/v8/V8Binding.h
+++ b/Source/bindings/v8/V8Binding.h
@@ -657,10 +657,10 @@
 
 // Returns a V8 context associated with a ExecutionContext and a DOMWrapperWorld.
 // This method returns an empty context if there is no frame or the frame is already detached.
-v8::Local<v8::Context> toV8Context(ExecutionContext*, DOMWrapperWorld*);
+v8::Local<v8::Context> toV8Context(ExecutionContext*, DOMWrapperWorld&);
 // Returns a V8 context associated with a LocalFrame and a DOMWrapperWorld.
 // This method returns an empty context if the frame is already detached.
-v8::Local<v8::Context> toV8Context(v8::Isolate*, LocalFrame*, DOMWrapperWorld*);
+v8::Local<v8::Context> toV8Context(v8::Isolate*, LocalFrame*, DOMWrapperWorld&);
 
 // Returns the frame object of the window object associated with
 // a context, if the window is currently being displayed in the LocalFrame.
diff --git a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
index 9d03759..3f8a2c5 100644
--- a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
+++ b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
@@ -116,7 +116,7 @@
     if (!executionContext())
         return 0;
 
-    v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get());
+    v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world);
     if (context.IsEmpty())
         return 0;
 
@@ -160,7 +160,7 @@
     element->setCustomElementState(Element::Upgraded);
 
     v8::HandleScope handleScope(m_isolate);
-    v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get());
+    v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world);
     if (context.IsEmpty())
         return;
 
@@ -212,7 +212,7 @@
         return;
 
     v8::HandleScope handleScope(m_isolate);
-    v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get());
+    v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world);
     if (context.IsEmpty())
         return;
 
@@ -247,7 +247,7 @@
         return;
 
     v8::HandleScope handleScope(m_isolate);
-    v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get());
+    v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world);
     if (context.IsEmpty())
         return;
 
diff --git a/Source/bindings/v8/V8DOMConfiguration.cpp b/Source/bindings/v8/V8DOMConfiguration.cpp
index ffbee35..3d4daeb 100644
--- a/Source/bindings/v8/V8DOMConfiguration.cpp
+++ b/Source/bindings/v8/V8DOMConfiguration.cpp
@@ -41,7 +41,7 @@
 
 void V8DOMConfiguration::installAccessors(v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, const AccessorConfiguration* accessors, size_t accessorCount, v8::Isolate* isolate)
 {
-    bool isMainWorld = DOMWrapperWorld::current(isolate)->isMainWorld();
+    bool isMainWorld = DOMWrapperWorld::current(isolate).isMainWorld();
     for (size_t i = 0; i < accessorCount; ++i) {
         v8::FunctionCallback getterCallback = accessors[i].getter;
         v8::FunctionCallback setterCallback = accessors[i].setter;
@@ -78,7 +78,7 @@
 
 void V8DOMConfiguration::installCallbacks(v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const MethodConfiguration* callbacks, size_t callbackCount, v8::Isolate* isolate)
 {
-    bool isMainWorld = DOMWrapperWorld::current(isolate)->isMainWorld();
+    bool isMainWorld = DOMWrapperWorld::current(isolate).isMainWorld();
     for (size_t i = 0; i < callbackCount; ++i) {
         v8::FunctionCallback callback = callbacks[i].callback;
         if (isMainWorld && callbacks[i].callbackForMainWorld)
diff --git a/Source/bindings/v8/V8DOMConfiguration.h b/Source/bindings/v8/V8DOMConfiguration.h
index 29f1958..f8ef53a 100644
--- a/Source/bindings/v8/V8DOMConfiguration.h
+++ b/Source/bindings/v8/V8DOMConfiguration.h
@@ -76,7 +76,7 @@
     {
         v8::AccessorGetterCallback getter = attribute.getter;
         v8::AccessorSetterCallback setter = attribute.setter;
-        if (DOMWrapperWorld::current(isolate)->isMainWorld()) {
+        if (DOMWrapperWorld::current(isolate).isMainWorld()) {
             if (attribute.getterForMainWorld)
                 getter = attribute.getterForMainWorld;
             if (attribute.setterForMainWorld)
diff --git a/Source/bindings/v8/V8ErrorHandler.cpp b/Source/bindings/v8/V8ErrorHandler.cpp
index eb7d41a..c41d9d3 100644
--- a/Source/bindings/v8/V8ErrorHandler.cpp
+++ b/Source/bindings/v8/V8ErrorHandler.cpp
@@ -56,7 +56,7 @@
     ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event);
 
     v8::Isolate* isolate = toV8Context(context, world())->GetIsolate();
-    if (errorEvent->world() && errorEvent->world() != world())
+    if (errorEvent->world() && errorEvent->world() != &world())
         return v8::Null(isolate);
 
     v8::Local<v8::Object> listener = getListenerObject(context);
@@ -72,7 +72,7 @@
         v8::Handle<v8::Value> parameters[5] = { v8String(isolate, errorEvent->message()), v8String(isolate, errorEvent->filename()), v8::Integer::New(isolate, errorEvent->lineno()), v8::Integer::New(isolate, errorEvent->colno()), error };
         v8::TryCatch tryCatch;
         tryCatch.SetVerbose(true);
-        if (DOMWrapperWorld::current(isolate)->isWorkerWorld())
+        if (DOMWrapperWorld::current(isolate).isWorkerWorld())
             returnValue = V8ScriptRunner::callFunction(callFunction, context, thisValue, WTF_ARRAY_LENGTH(parameters), parameters, isolate);
         else
             returnValue = ScriptController::callFunction(context, callFunction, thisValue, WTF_ARRAY_LENGTH(parameters), parameters, isolate);
diff --git a/Source/bindings/v8/V8Initializer.cpp b/Source/bindings/v8/V8Initializer.cpp
index 98dce3b..1cd0262 100644
--- a/Source/bindings/v8/V8Initializer.cpp
+++ b/Source/bindings/v8/V8Initializer.cpp
@@ -111,8 +111,8 @@
     String resource = shouldUseDocumentURL ? enteredWindow->document()->url() : toCoreString(resourceName.As<v8::String>());
     AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin;
 
-    DOMWrapperWorld* world = DOMWrapperWorld::current(isolate);
-    RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, message->GetLineNumber(), message->GetStartColumn() + 1, world);
+    DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
+    RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, message->GetLineNumber(), message->GetStartColumn() + 1, &world);
     if (V8DOMWrapper::isDOMWrapper(data)) {
         v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(data);
         const WrapperTypeInfo* type = toWrapperTypeInfo(obj);
@@ -127,7 +127,7 @@
     // 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 (world && frame && frame->script().existingWindowShell(world))
+    if (frame && frame->script().existingWindowShell(world))
         V8ErrorHandler::storeExceptionOnErrorEventWrapper(event.get(), data, v8::Isolate::GetCurrent());
     enteredWindow->document()->reportException(event.release(), callStack, corsStatus);
 }
@@ -219,7 +219,7 @@
         String errorMessage = toCoreString(message->Get());
         V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, sourceURL, message->GetScriptResourceName());
 
-        RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, message->GetLineNumber(), message->GetStartColumn() + 1, DOMWrapperWorld::current(isolate));
+        RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, message->GetLineNumber(), message->GetStartColumn() + 1, &DOMWrapperWorld::current(isolate));
         AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin;
 
         V8ErrorHandler::storeExceptionOnErrorEventWrapper(event.get(), data, isolate);
diff --git a/Source/bindings/v8/V8MutationCallback.cpp b/Source/bindings/v8/V8MutationCallback.cpp
index da0320d..d6110f8 100644
--- a/Source/bindings/v8/V8MutationCallback.cpp
+++ b/Source/bindings/v8/V8MutationCallback.cpp
@@ -53,7 +53,7 @@
 
     v8::HandleScope handleScope(m_isolate);
 
-    v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.get());
+    v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), *m_world);
     if (v8Context.IsEmpty())
         return;
 
diff --git a/Source/bindings/v8/V8PerContextData.cpp b/Source/bindings/v8/V8PerContextData.cpp
index bd1f190..75602c0 100644
--- a/Source/bindings/v8/V8PerContextData.cpp
+++ b/Source/bindings/v8/V8PerContextData.cpp
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "bindings/v8/V8PerContextData.h"
 
+#include "bindings/v8/ScriptState.h"
 #include "bindings/v8/V8Binding.h"
 #include "bindings/v8/V8ObjectConstructor.h"
 #include "wtf/StringExtras.h"
@@ -48,54 +49,6 @@
     map->clear();
 }
 
-class V8PerContextDataHolder {
-    WTF_MAKE_NONCOPYABLE(V8PerContextDataHolder);
-public:
-    static void install(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperWorld> world)
-    {
-        new V8PerContextDataHolder(context, world);
-    }
-
-    static V8PerContextDataHolder* from(v8::Handle<v8::Context> context)
-    {
-        V8PerContextDataHolder* holder = static_cast<V8PerContextDataHolder*>(context->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex));
-        // V8PerContextDataHolder::from() must not be called for a context that does not have
-        // valid embedder data in the embedder field.
-        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(holder);
-        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(holder->context() == context);
-        return holder;
-    }
-
-    V8PerContextData* perContextData() const { return m_perContextData; }
-    void setPerContextData(V8PerContextData* data) { m_perContextData = data; }
-    DOMWrapperWorld* world() const { return m_world.get(); }
-    v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolate); }
-
-private:
-    V8PerContextDataHolder(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperWorld> world)
-        : m_isolate(context->GetIsolate())
-        , m_context(m_isolate, context)
-        , m_perContextData(0)
-        , m_world(world)
-    {
-        m_context.setWeak(this, &V8PerContextDataHolder::weakCallback);
-        context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, this);
-    }
-
-    ~V8PerContextDataHolder() { }
-
-    static void weakCallback(const v8::WeakCallbackData<v8::Context, V8PerContextDataHolder>& data)
-    {
-        data.GetValue()->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, 0);
-        delete data.GetParameter();
-    }
-
-    v8::Isolate* m_isolate;
-    ScopedPersistent<v8::Context> m_context;
-    V8PerContextData* m_perContextData;
-    RefPtr<DOMWrapperWorld> m_world;
-};
-
 V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperWorld> world)
     : m_activityLogger(0)
     , m_isolate(context->GetIsolate())
@@ -104,8 +57,8 @@
     , m_customElementBindings(adoptPtr(new CustomElementBindingMap()))
 {
     m_contextHolder->SetContext(context);
-    V8PerContextDataHolder::install(context, world);
-    V8PerContextDataHolder::from(context)->setPerContextData(this);
+    NewScriptState::install(context, world);
+    NewScriptState::from(context)->setPerContextData(this);
 
     v8::Context::Scope contextScope(context);
     ASSERT(m_errorPrototype.isEmpty());
@@ -119,7 +72,7 @@
 V8PerContextData::~V8PerContextData()
 {
     v8::HandleScope handleScope(m_isolate);
-    V8PerContextDataHolder::from(m_context.newLocal(m_isolate))->setPerContextData(0);
+    NewScriptState::from(m_context.newLocal(m_isolate))->setPerContextData(0);
 
     disposeMapWithUnsafePersistentValues(&m_wrapperBoilerplates);
     disposeMapWithUnsafePersistentValues(&m_constructorMap);
@@ -127,14 +80,7 @@
 
 V8PerContextData* V8PerContextData::from(v8::Handle<v8::Context> context)
 {
-    return V8PerContextDataHolder::from(context)->perContextData();
-}
-
-DOMWrapperWorld* V8PerContextData::world(v8::Handle<v8::Context> context)
-{
-    DOMWrapperWorld* world = V8PerContextDataHolder::from(context)->world();
-    ASSERT(world);
-    return world;
+    return NewScriptState::from(context)->perContextData();
 }
 
 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const WrapperTypeInfo* type)
diff --git a/Source/bindings/v8/V8PerContextData.h b/Source/bindings/v8/V8PerContextData.h
index 9724bd1..4dcbd4c 100644
--- a/Source/bindings/v8/V8PerContextData.h
+++ b/Source/bindings/v8/V8PerContextData.h
@@ -67,7 +67,6 @@
     }
 
     static V8PerContextData* from(v8::Handle<v8::Context>);
-    static DOMWrapperWorld* world(v8::Handle<v8::Context>);
 
     ~V8PerContextData();
 
diff --git a/Source/bindings/v8/V8PerIsolateData.cpp b/Source/bindings/v8/V8PerIsolateData.cpp
index b0aca52..0f2063d 100644
--- a/Source/bindings/v8/V8PerIsolateData.cpp
+++ b/Source/bindings/v8/V8PerIsolateData.cpp
@@ -96,7 +96,7 @@
 
 V8PerIsolateData::DOMTemplateMap& V8PerIsolateData::currentDOMTemplateMap()
 {
-    if (DOMWrapperWorld::current(m_isolate)->isMainWorld())
+    if (DOMWrapperWorld::current(m_isolate).isMainWorld())
         return m_domTemplateMapForMainWorld;
     return m_domTemplateMapForNonMainWorld;
 }
diff --git a/Source/bindings/v8/V8WindowShell.cpp b/Source/bindings/v8/V8WindowShell.cpp
index 61a55ec..5e742fe 100644
--- a/Source/bindings/v8/V8WindowShell.cpp
+++ b/Source/bindings/v8/V8WindowShell.cpp
@@ -78,9 +78,9 @@
     V8PerContextDebugData::setContextDebugData(targetContext, "injected", debugId);
 }
 
-PassOwnPtr<V8WindowShell> V8WindowShell::create(LocalFrame* frame, PassRefPtr<DOMWrapperWorld> world, v8::Isolate* isolate)
+PassOwnPtr<V8WindowShell> V8WindowShell::create(LocalFrame* frame, DOMWrapperWorld& world, v8::Isolate* isolate)
 {
-    return adoptPtr(new V8WindowShell(frame, world, isolate));
+    return adoptPtr(new V8WindowShell(frame, &world, isolate));
 }
 
 V8WindowShell::V8WindowShell(LocalFrame* frame, PassRefPtr<DOMWrapperWorld> world, v8::Isolate* isolate)
diff --git a/Source/bindings/v8/V8WindowShell.h b/Source/bindings/v8/V8WindowShell.h
index 2ee6309..de6c901 100644
--- a/Source/bindings/v8/V8WindowShell.h
+++ b/Source/bindings/v8/V8WindowShell.h
@@ -55,7 +55,7 @@
 // persist between navigations.
 class V8WindowShell {
 public:
-    static PassOwnPtr<V8WindowShell> create(LocalFrame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*);
+    static PassOwnPtr<V8WindowShell> create(LocalFrame*, DOMWrapperWorld&, v8::Isolate*);
 
     v8::Local<v8::Context> context() const { return m_perContextData ? m_perContextData->context() : v8::Local<v8::Context>(); }
 
@@ -78,7 +78,7 @@
     void clearForNavigation();
     void clearForClose();
 
-    DOMWrapperWorld* world() { return m_world.get(); }
+    DOMWrapperWorld& world() { return *m_world; }
 
 private:
     V8WindowShell(LocalFrame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*);
diff --git a/Source/bindings/v8/WorkerScriptController.cpp b/Source/bindings/v8/WorkerScriptController.cpp
index c26d085..6127764 100644
--- a/Source/bindings/v8/WorkerScriptController.cpp
+++ b/Source/bindings/v8/WorkerScriptController.cpp
@@ -211,11 +211,11 @@
     if (state.hadException) {
         if (errorEvent) {
             *errorEvent = m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin) ?
-                ErrorEvent::createSanitizedError(0) : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, 0);
+                ErrorEvent::createSanitizedError(m_world.get()) : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get());
             V8ErrorHandler::storeExceptionOnErrorEventWrapper(errorEvent->get(), state.exception.v8Value(), m_isolate);
         } else {
             ASSERT(!m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin));
-            RefPtr<ErrorEvent> event = m_errorEventFromImportedScript ? m_errorEventFromImportedScript.release() : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, 0);
+            RefPtr<ErrorEvent> event = m_errorEventFromImportedScript ? m_errorEventFromImportedScript.release() : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get());
             m_workerGlobalScope.reportException(event, nullptr, NotSharableCrossOrigin);
         }
     }
diff --git a/Source/bindings/v8/WorkerScriptController.h b/Source/bindings/v8/WorkerScriptController.h
index cd452e3..5b46cf9 100644
--- a/Source/bindings/v8/WorkerScriptController.h
+++ b/Source/bindings/v8/WorkerScriptController.h
@@ -91,7 +91,7 @@
         ScriptValue evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, WorkerGlobalScopeExecutionState*);
 
         v8::Isolate* isolate() const { return m_isolate; }
-        DOMWrapperWorld* world() const { return m_world.get(); }
+        DOMWrapperWorld& world() const { return *m_world; }
         v8::Local<v8::Context> context() { return m_perContextData ? m_perContextData->context() : v8::Local<v8::Context>(); }
 
         // Send a notification about current thread is going to be idle.
diff --git a/Source/bindings/v8/custom/V8ArrayBufferCustom.h b/Source/bindings/v8/custom/V8ArrayBufferCustom.h
index c90760a..779095f 100644
--- a/Source/bindings/v8/custom/V8ArrayBufferCustom.h
+++ b/Source/bindings/v8/custom/V8ArrayBufferCustom.h
@@ -108,7 +108,7 @@
 template<class CallbackInfo>
 inline void v8SetReturnValueForMainWorld(const CallbackInfo& info, ArrayBuffer* impl)
 {
-    ASSERT(DOMWrapperWorld::current(info.GetIsolate())->isMainWorld());
+    ASSERT(DOMWrapperWorld::current(info.GetIsolate()).isMainWorld());
     if (UNLIKELY(!impl)) {
         v8SetReturnValueNull(info);
         return;
diff --git a/Source/bindings/v8/custom/V8CustomEventCustom.cpp b/Source/bindings/v8/custom/V8CustomEventCustom.cpp
index 7241ffc..91b63f6 100644
--- a/Source/bindings/v8/custom/V8CustomEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8CustomEventCustom.cpp
@@ -92,7 +92,7 @@
 
     if (!detailsArg.IsEmpty()) {
         V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::detail(info.GetIsolate()), detailsArg);
-        if (DOMWrapperWorld::current(info.GetIsolate())->isIsolatedWorld())
+        if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
             event->setSerializedDetail(SerializedScriptValue::createAndSwallowExceptions(detailsArg, info.GetIsolate()));
     }
 }
diff --git a/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp b/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
index fc597c1..d6ed567 100644
--- a/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
+++ b/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
@@ -44,16 +44,16 @@
     if (!canInvokeCallback())
         return true;
 
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
+    v8::Isolate* isolate = m_scriptState->isolate();
     v8::HandleScope handleScope(isolate);
 
-    v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.get());
+    v8::Handle<v8::Context> v8Context = m_scriptState->context();
     if (v8Context.IsEmpty())
         return true;
 
     v8::Context::Scope scope(v8Context);
 
-    v8::Handle<v8::Value> transactionHandle = toV8(transaction, v8::Handle<v8::Object>(), v8Context->GetIsolate());
+    v8::Handle<v8::Value> transactionHandle = toV8(transaction, v8::Handle<v8::Object>(), isolate);
     v8::Handle<v8::Value> errorHandle = toV8(error, v8::Handle<v8::Object>(), isolate);
     if (transactionHandle.IsEmpty() || errorHandle.IsEmpty()) {
         if (!isScriptControllerTerminating())
diff --git a/Source/bindings/v8/custom/V8MessageEventCustom.cpp b/Source/bindings/v8/custom/V8MessageEventCustom.cpp
index c41449b..b14bb18 100644
--- a/Source/bindings/v8/custom/V8MessageEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8MessageEventCustom.cpp
@@ -156,7 +156,7 @@
 
     if (!dataArg.IsEmpty()) {
         V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), V8HiddenValue::data(info.GetIsolate()), dataArg);
-        if (DOMWrapperWorld::current(info.GetIsolate())->isIsolatedWorld())
+        if (DOMWrapperWorld::current(info.GetIsolate()).isIsolatedWorld())
             event->setSerializedData(SerializedScriptValue::createAndSwallowExceptions(dataArg, info.GetIsolate()));
     }
 }
diff --git a/Source/bindings/v8/custom/V8TypedArrayCustom.h b/Source/bindings/v8/custom/V8TypedArrayCustom.h
index d268d6d..09076a6 100644
--- a/Source/bindings/v8/custom/V8TypedArrayCustom.h
+++ b/Source/bindings/v8/custom/V8TypedArrayCustom.h
@@ -91,7 +91,7 @@
     template<typename CallbackInfo>
     static void v8SetReturnValueForMainWorld(const CallbackInfo& info, TypedArray* impl)
     {
-        ASSERT(DOMWrapperWorld::current(info.GetIsolate())->isMainWorld());
+        ASSERT(DOMWrapperWorld::current(info.GetIsolate()).isMainWorld());
         if (UNLIKELY(!impl)) {
             v8SetReturnValueNull(info);
             return;
diff --git a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
index c2422ef..83ccbba 100644
--- a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
+++ b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
@@ -57,9 +57,9 @@
 
     RefPtr<SecurityOrigin> securityOrigin;
     if (context->isDocument()) {
-        DOMWrapperWorld* world = DOMWrapperWorld::current(info.GetIsolate());
-        if (world->isIsolatedWorld())
-            securityOrigin = world->isolatedWorldSecurityOrigin();
+        DOMWrapperWorld& world = DOMWrapperWorld::current(info.GetIsolate());
+        if (world.isIsolatedWorld())
+            securityOrigin = world.isolatedWorldSecurityOrigin();
     }
 
     RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);