Merge from Chromium at DEPS revision 222756

This commit was generated by merge_to_master.py.

Change-Id: I085d892f6f1583a45f10eb394f195bbea5a334ef
diff --git a/Source/bindings/v8/BindingSecurity.cpp b/Source/bindings/v8/BindingSecurity.cpp
index fe80634..56eb47d 100644
--- a/Source/bindings/v8/BindingSecurity.cpp
+++ b/Source/bindings/v8/BindingSecurity.cpp
@@ -91,7 +91,7 @@
 
 bool BindingSecurity::shouldAllowAccessToNode(Node* target)
 {
-    return target && canAccessDocument(target->document());
+    return target && canAccessDocument(&target->document());
 }
 
 }
diff --git a/Source/bindings/v8/CustomElementConstructorBuilder.cpp b/Source/bindings/v8/CustomElementConstructorBuilder.cpp
index f888790..ae717e1 100644
--- a/Source/bindings/v8/CustomElementConstructorBuilder.cpp
+++ b/Source/bindings/v8/CustomElementConstructorBuilder.cpp
@@ -69,84 +69,64 @@
     return !DOMWrapperWorld::isolatedWorld(m_context);
 }
 
-bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type, ExceptionState& es)
+bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type, QualifiedName& tagName, ExceptionState& es)
 {
     ASSERT(m_prototype.IsEmpty());
 
     ScriptValue prototypeScriptValue;
-    if (!m_options->get("prototype", prototypeScriptValue)) {
-        // FIXME: Implement the default value handling.
-        // Currently default value of the "prototype" parameter, which
-        // is HTMLSpanElement.prototype, has an ambiguity about its
-        // behavior. The spec should be fixed before WebKit implements
-        // it. https://www.w3.org/Bugs/Public/show_bug.cgi?id=20801
-        CustomElementException::throwException(CustomElementException::NotYetImplemented, type, es);
-        return false;
+    if (m_options->get("prototype", prototypeScriptValue) && !prototypeScriptValue.isNull()) {
+        m_prototype = prototypeScriptValue.v8Value().As<v8::Object>();
+        if (m_prototype.IsEmpty()) {
+            CustomElementException::throwException(CustomElementException::PrototypeNotAnObject, type, es);
+            return false;
+        }
+    } else {
+        m_prototype = v8::Object::New();
+        v8::Local<v8::Object> basePrototype = V8PerContextData::from(m_context)->prototypeForType(&V8HTMLElement::info);
+        if (!basePrototype.IsEmpty())
+            m_prototype->SetPrototype(basePrototype);
     }
 
-    v8::Handle<v8::Value> prototypeValue = prototypeScriptValue.v8Value();
-    if (prototypeValue.IsEmpty() || !prototypeValue->IsObject()) {
-        CustomElementException::throwException(CustomElementException::PrototypeNotAnObject, type, es);
-        return false;
-    }
-    m_prototype = prototypeValue.As<v8::Object>();
+    String extends;
+    bool extendsProvidedAndNonNull = m_options->get("extends", extends);
 
-    V8PerContextData* perContextData;
-    if (!(perContextData = V8PerContextData::from(m_context))) {
+    if (!V8PerContextData::from(m_context)) {
         // FIXME: This should generate an InvalidContext exception at a later point.
         CustomElementException::throwException(CustomElementException::ContextDestroyedCheckingPrototype, type, es);
         return false;
     }
 
-    if (hasValidPrototypeChainFor(perContextData, &V8HTMLElement::info)) {
-        m_namespaceURI = HTMLNames::xhtmlNamespaceURI;
-        return true;
+    AtomicString namespaceURI = HTMLNames::xhtmlNamespaceURI;
+    if (hasValidPrototypeChainFor(&V8SVGElement::info))
+        namespaceURI = SVGNames::svgNamespaceURI;
+
+    AtomicString localName;
+
+    if (extendsProvidedAndNonNull) {
+        localName = extends.lower();
+
+        if (!Document::isValidName(localName)) {
+            CustomElementException::throwException(CustomElementException::ExtendsIsInvalidName, type, es);
+            return false;
+        }
+        if (CustomElement::isValidName(localName)) {
+            CustomElementException::throwException(CustomElementException::ExtendsIsCustomElementName, type, es);
+            return false;
+        }
+    } else {
+        localName = type;
     }
 
-    if (hasValidPrototypeChainFor(perContextData, &V8SVGElement::info)) {
-        m_namespaceURI = SVGNames::svgNamespaceURI;
-        return true;
-    }
+    if (!extendsProvidedAndNonNull)
+        m_wrapperType = &V8HTMLElement::info;
+    else if (namespaceURI == HTMLNames::xhtmlNamespaceURI)
+        m_wrapperType = findWrapperTypeForHTMLTagName(localName);
+    else
+        m_wrapperType = findWrapperTypeForSVGTagName(localName);
 
-    if (hasValidPrototypeChainFor(perContextData, &V8Element::info)) {
-        m_namespaceURI = nullAtom;
-        // This generates a different DOM exception, so we feign success for now.
-        return true;
-    }
-
-    CustomElementException::throwException(CustomElementException::PrototypeDoesNotExtendHTMLElementSVGElementPrototype, type, es);
-    return false;
-}
-
-bool CustomElementConstructorBuilder::findTagName(const AtomicString& customElementType, QualifiedName& tagName)
-{
-    ASSERT(!m_prototype.IsEmpty());
-
-    m_wrapperType = findWrapperType(m_prototype);
-    if (!m_wrapperType) {
-        // Invalid prototype.
-        return false;
-    }
-
-    if (const QualifiedName* htmlName = findHTMLTagNameOfV8Type(m_wrapperType)) {
-        ASSERT(htmlName->namespaceURI() == m_namespaceURI);
-        tagName = *htmlName;
-        return true;
-    }
-
-    if (const QualifiedName* svgName = findSVGTagNameOfV8Type(m_wrapperType)) {
-        ASSERT(svgName->namespaceURI() == m_namespaceURI);
-        tagName = *svgName;
-        return true;
-    }
-
-    if (m_namespaceURI != nullAtom) {
-        // Use the custom element type as the tag's local name.
-        tagName = QualifiedName(nullAtom, customElementType, m_namespaceURI);
-        return true;
-    }
-
-    return false;
+    ASSERT(m_wrapperType);
+    tagName = QualifiedName(nullAtom, localName, namespaceURI);
+    return m_wrapperType;
 }
 
 PassRefPtr<CustomElementLifecycleCallbacks> CustomElementConstructorBuilder::createCallbacks()
@@ -160,11 +140,11 @@
 
     v8::Isolate* isolate = v8::Isolate::GetCurrent();
     v8::Handle<v8::Function> created = retrieveCallback(isolate, "createdCallback");
-    v8::Handle<v8::Function> enteredDocument = retrieveCallback(isolate, "enteredDocumentCallback");
-    v8::Handle<v8::Function> leftDocument = retrieveCallback(isolate, "leftDocumentCallback");
+    v8::Handle<v8::Function> enteredView = retrieveCallback(isolate, "enteredViewCallback");
+    v8::Handle<v8::Function> leftView = retrieveCallback(isolate, "leftViewCallback");
     v8::Handle<v8::Function> attributeChanged = retrieveCallback(isolate, "attributeChangedCallback");
 
-    m_callbacks = V8CustomElementLifecycleCallbacks::create(scriptExecutionContext.get(), m_prototype, created, enteredDocument, leftDocument, attributeChanged);
+    m_callbacks = V8CustomElementLifecycleCallbacks::create(scriptExecutionContext.get(), m_prototype, created, enteredView, leftView, attributeChanged);
     return m_callbacks.get();
 }
 
@@ -255,26 +235,9 @@
     return ScriptValue(m_constructor);
 }
 
-WrapperTypeInfo* CustomElementConstructorBuilder::findWrapperType(v8::Handle<v8::Value> chain)
+bool CustomElementConstructorBuilder::hasValidPrototypeChainFor(WrapperTypeInfo* type) const
 {
-    while (!chain.IsEmpty() && chain->IsObject()) {
-        v8::Handle<v8::Object> chainObject = chain.As<v8::Object>();
-        // Only prototype objects of native-backed types have the extra internal field storing WrapperTypeInfo.
-        if (v8PrototypeInternalFieldcount == chainObject->InternalFieldCount()) {
-            WrapperTypeInfo* wrapperType = reinterpret_cast<WrapperTypeInfo*>(chainObject->GetAlignedPointerFromInternalField(v8PrototypeTypeIndex));
-            ASSERT(wrapperType);
-            return wrapperType;
-        }
-        chain = chainObject->GetPrototype();
-    }
-
-    return 0;
-}
-
-bool CustomElementConstructorBuilder::hasValidPrototypeChainFor(V8PerContextData* perContextData, WrapperTypeInfo* typeInfo) const
-{
-    v8::Handle<v8::Object> elementConstructor = perContextData->constructorForType(typeInfo);
-    v8::Handle<v8::Object> elementPrototype = elementConstructor->Get(v8String("prototype", m_context->GetIsolate())).As<v8::Object>();
+    v8::Handle<v8::Object> elementPrototype = V8PerContextData::from(m_context)->prototypeForType(type);
     if (elementPrototype.IsEmpty())
         return false;
 
diff --git a/Source/bindings/v8/CustomElementConstructorBuilder.h b/Source/bindings/v8/CustomElementConstructorBuilder.h
index 84e46bb..705da91 100644
--- a/Source/bindings/v8/CustomElementConstructorBuilder.h
+++ b/Source/bindings/v8/CustomElementConstructorBuilder.h
@@ -67,8 +67,7 @@
     // (returns false), the calls must stop.
 
     bool isFeatureAllowed() const;
-    bool validateOptions(const AtomicString& type, ExceptionState&);
-    bool findTagName(const AtomicString& customElementType, QualifiedName& tagName);
+    bool validateOptions(const AtomicString& type, QualifiedName& tagName, ExceptionState&);
     PassRefPtr<CustomElementLifecycleCallbacks> createCallbacks();
     bool createConstructor(Document*, CustomElementDefinition*, ExceptionState&);
     bool didRegisterDefinition(CustomElementDefinition*) const;
@@ -79,8 +78,7 @@
     ScriptValue bindingsReturnValue() const;
 
 private:
-    static WrapperTypeInfo* findWrapperType(v8::Handle<v8::Value> chain);
-    bool hasValidPrototypeChainFor(V8PerContextData*, WrapperTypeInfo*) const;
+    bool hasValidPrototypeChainFor(WrapperTypeInfo*) const;
     bool prototypeIsValid(const AtomicString& type, ExceptionState&) const;
     v8::Handle<v8::Function> retrieveCallback(v8::Isolate*, const char* name);
 
@@ -88,7 +86,6 @@
     const Dictionary* m_options;
     v8::Handle<v8::Object> m_prototype;
     WrapperTypeInfo* m_wrapperType;
-    AtomicString m_namespaceURI;
     v8::Handle<v8::Function> m_constructor;
     RefPtr<V8CustomElementLifecycleCallbacks> m_callbacks;
 };
diff --git a/Source/bindings/v8/DOMRequestState.h b/Source/bindings/v8/DOMRequestState.h
index c5bf846..2bba072 100644
--- a/Source/bindings/v8/DOMRequestState.h
+++ b/Source/bindings/v8/DOMRequestState.h
@@ -39,6 +39,7 @@
     explicit DOMRequestState(ScriptExecutionContext* scriptExecutionContext)
         : m_scriptExecutionContext(scriptExecutionContext)
         , m_world(DOMWrapperWorld::current())
+        , m_isolate(getIsolateFromScriptExecutionContext(scriptExecutionContext))
     {
     }
 
@@ -51,7 +52,8 @@
     class Scope {
     public:
         explicit Scope(DOMRequestState& state)
-            : m_contextScope(state.context())
+            : m_handleScope(state.isolate())
+            , m_contextScope(state.context())
         {
         }
     private:
@@ -64,9 +66,15 @@
         return toV8Context(m_scriptExecutionContext, m_world.get());
     }
 
+    v8::Isolate* isolate() const
+    {
+        return m_isolate;
+    }
+
 private:
     ScriptExecutionContext* m_scriptExecutionContext;
     RefPtr<DOMWrapperWorld> m_world;
+    v8::Isolate* m_isolate;
 };
 
 }
diff --git a/Source/bindings/v8/DOMWrapperMap.h b/Source/bindings/v8/DOMWrapperMap.h
index f054ee0..963b679 100644
--- a/Source/bindings/v8/DOMWrapperMap.h
+++ b/Source/bindings/v8/DOMWrapperMap.h
@@ -80,7 +80,7 @@
     {
         ASSERT(static_cast<KeyType*>(toNative(wrapper)) == key);
         v8::Persistent<v8::Object> persistent(m_isolate, wrapper);
-        configuration.configureWrapper(&persistent, m_isolate);
+        configuration.configureWrapper(&persistent);
         persistent.MakeWeak(this, &makeWeakCallback);
         typename MapType::AddResult result = m_map.add(key, UnsafePersistent<v8::Object>());
         ASSERT(result.isNewEntry);
diff --git a/Source/bindings/v8/Dictionary.cpp b/Source/bindings/v8/Dictionary.cpp
index 6b29255..e34d440 100644
--- a/Source/bindings/v8/Dictionary.cpp
+++ b/Source/bindings/v8/Dictionary.cpp
@@ -170,11 +170,8 @@
     if (!getKey(key, v8Value))
         return false;
 
-    // FIXME: It is possible for this to throw in which case we'd be getting back
-    //        an empty string and returning true when we should be returning false.
-    //        See fast/dom/Geolocation/script-tests/argument-types.js for a similar
-    //        example.
-    value = toWebCoreString(v8Value);
+    V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, v8Value, false);
+    value = stringValue;
     return true;
 }
 
@@ -310,7 +307,8 @@
     v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
     for (size_t i = 0; i < v8Array->Length(); ++i) {
         v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(i, m_isolate));
-        value.add(toWebCoreString(indexedValue));
+        V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, indexedValue, false);
+        value.add(stringValue);
     }
 
     return true;
@@ -322,11 +320,13 @@
     if (!getKey(key, v8Value) || v8Value->IsNull() || v8Value->IsUndefined())
         return false;
 
-    // FIXME: It is possible for this to throw in which case we'd be getting back
-    //        an empty string and returning true when we should be returning false.
-    //        See fast/dom/Geolocation/script-tests/argument-types.js for a similar
-    //        example.
-    value = WebCore::isUndefinedOrNull(v8Value) ? String() : toWebCoreString(v8Value);
+    if (WebCore::isUndefinedOrNull(v8Value)) {
+        value = String();
+        return true;
+    }
+
+    V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, v8Value, false);
+    value = stringValue;
     return true;
 }
 
@@ -498,7 +498,8 @@
     v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
     for (size_t i = 0; i < v8Array->Length(); ++i) {
         v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(i));
-        value.append(toWebCoreString(indexedValue));
+        V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, indexedValue, false);
+        value.append(stringValue);
     }
 
     return true;
@@ -584,9 +585,9 @@
             continue;
 
         v8::Local<v8::Value> value = options->Get(key);
-        String stringKey = toWebCoreString(key);
-        String stringValue = toWebCoreString(value);
-        if (!stringKey.isEmpty())
+        V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringKey, key, false);
+        V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, value, false);
+        if (!static_cast<const String&>(stringKey).isEmpty())
             hashMap.set(stringKey, stringValue);
     }
 
@@ -609,7 +610,8 @@
         v8::Local<v8::String> key = properties->Get(i)->ToString();
         if (!options->Has(key))
             continue;
-        names.append(toWebCoreString(key));
+        V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringKey, key, false);
+        names.append(stringKey);
     }
 
     return true;
diff --git a/Source/bindings/v8/Dictionary.h b/Source/bindings/v8/Dictionary.h
index 4cc1c90..4a829a7 100644
--- a/Source/bindings/v8/Dictionary.h
+++ b/Source/bindings/v8/Dictionary.h
@@ -102,8 +102,6 @@
 
     bool getWithUndefinedOrNullCheck(const String&, String&) const;
 
-    PassRefPtr<EventListener> getEventListener(const String&, Notification*) const { return 0; }
-
 private:
     bool getKey(const String& key, v8::Local<v8::Value>&) const;
 
diff --git a/Source/bindings/v8/IDBBindingUtilities.cpp b/Source/bindings/v8/IDBBindingUtilities.cpp
index 93b2217..a727a96 100644
--- a/Source/bindings/v8/IDBBindingUtilities.cpp
+++ b/Source/bindings/v8/IDBBindingUtilities.cpp
@@ -54,7 +54,7 @@
         ASSERT_NOT_REACHED();
         return v8Undefined();
     case IDBKey::NumberType:
-        return v8::Number::New(key->number());
+        return v8::Number::New(isolate, key->number());
     case IDBKey::StringType:
         return v8String(key->string(), isolate);
     case IDBKey::DateType:
@@ -138,7 +138,7 @@
 {
     if (object->IsString() && keyPathElement == "length") {
         int32_t length = v8::Handle<v8::String>::Cast(object)->Length();
-        result = v8::Number::New(length);
+        result = v8::Number::New(isolate, length);
         return true;
     }
     return object->IsObject() && getValueFrom(v8String(keyPathElement, isolate), result);
diff --git a/Source/bindings/v8/NPV8Object.cpp b/Source/bindings/v8/NPV8Object.cpp
index 80f29f6..eed1b96 100644
--- a/Source/bindings/v8/NPV8Object.cpp
+++ b/Source/bindings/v8/NPV8Object.cpp
@@ -336,7 +336,7 @@
     if (!v8NpObject)
         return false;
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(v8::Isolate::GetCurrent());
     v8::Handle<v8::Context> context = toV8Context(npp, npObject);
     if (context.IsEmpty())
         return false;
@@ -504,7 +504,7 @@
         return;
     }
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(v8::Isolate::GetCurrent());
     v8::Handle<v8::Context> context = toV8Context(0, npObject);
     if (context.IsEmpty())
         return;
diff --git a/Source/bindings/v8/ScheduledAction.cpp b/Source/bindings/v8/ScheduledAction.cpp
index a06c9a5..198cb87 100644
--- a/Source/bindings/v8/ScheduledAction.cpp
+++ b/Source/bindings/v8/ScheduledAction.cpp
@@ -114,7 +114,7 @@
     if (!m_function.isEmpty()) {
         Vector<v8::Handle<v8::Value> > args;
         createLocalHandlesForArgs(&args);
-        V8ScriptRunner::callFunction(m_function.newLocal(m_isolate), worker, context->Global(), args.size(), args.data());
+        V8ScriptRunner::callFunction(m_function.newLocal(m_isolate), worker, context->Global(), args.size(), args.data(), m_isolate);
     } else
         worker->script()->evaluate(m_code);
 }
diff --git a/Source/bindings/v8/ScheduledAction.h b/Source/bindings/v8/ScheduledAction.h
index d4a95de..17fa40c 100644
--- a/Source/bindings/v8/ScheduledAction.h
+++ b/Source/bindings/v8/ScheduledAction.h
@@ -33,6 +33,7 @@
 
 #include "bindings/v8/ScopedPersistent.h"
 #include "bindings/v8/ScriptSourceCode.h"
+#include "bindings/v8/UnsafePersistent.h"
 #include <v8.h>
 #include "wtf/Forward.h"
 #include "wtf/Vector.h"
diff --git a/Source/bindings/v8/ScriptCallStackFactory.cpp b/Source/bindings/v8/ScriptCallStackFactory.cpp
index 22de5f8..6f41872 100644
--- a/Source/bindings/v8/ScriptCallStackFactory.cpp
+++ b/Source/bindings/v8/ScriptCallStackFactory.cpp
@@ -40,6 +40,7 @@
 #include "core/inspector/ScriptCallFrame.h"
 #include "core/inspector/ScriptCallStack.h"
 #include "core/platform/JSONValues.h"
+#include "wtf/text/StringBuilder.h"
 
 #include <v8-debug.h>
 
@@ -49,6 +50,9 @@
 
 static ScriptCallFrame toScriptCallFrame(v8::Handle<v8::StackFrame> frame)
 {
+    StringBuilder stringBuilder;
+    stringBuilder.appendNumber(frame->GetScriptId());
+    String scriptId = stringBuilder.toString();
     String sourceName;
     v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL());
     if (!sourceNameValue.IsEmpty())
@@ -61,7 +65,7 @@
 
     int sourceLineNumber = frame->GetLineNumber();
     int sourceColumn = frame->GetColumn();
-    return ScriptCallFrame(functionName, sourceName, sourceLineNumber, sourceColumn);
+    return ScriptCallFrame(functionName, scriptId, sourceName, sourceLineNumber, sourceColumn);
 }
 
 static void toScriptCallFramesVector(v8::Handle<v8::StackTrace> stackTrace, Vector<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize, bool emptyStackIsAllowed)
@@ -78,31 +82,32 @@
         // Successfully grabbed stack trace, but there are no frames. It may happen in case
         // when a bound function is called from native code for example.
         // Fallback to setting lineNumber to 0, and source and function name to "undefined".
-        scriptCallFrames.append(ScriptCallFrame("undefined", "undefined", 0));
+        scriptCallFrames.append(ScriptCallFrame("undefined", "", "undefined", 0));
     }
 }
 
-static PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize, bool emptyStackIsAllowed)
+static PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize, bool emptyStackIsAllowed, v8::Isolate* isolate)
 {
     ASSERT(v8::Context::InContext());
-    v8::HandleScope scope;
+    v8::HandleScope scope(isolate);
     Vector<ScriptCallFrame> scriptCallFrames;
     toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, emptyStackIsAllowed);
     return ScriptCallStack::create(scriptCallFrames);
 }
 
-PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize)
+PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize, v8::Isolate* isolate)
 {
-    return createScriptCallStack(stackTrace, maxStackSize, true);
+    return createScriptCallStack(stackTrace, maxStackSize, true, isolate);
 }
 
 PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize, bool emptyStackIsAllowed)
 {
     if (!v8::Context::InContext())
         return 0;
-    v8::HandleScope handleScope;
+    v8::Isolate* isolate = v8::Isolate::GetCurrent();
+    v8::HandleScope handleScope(isolate);
     v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(maxStackSize, stackTraceOptions));
-    return createScriptCallStack(stackTrace, maxStackSize, emptyStackIsAllowed);
+    return createScriptCallStack(stackTrace, maxStackSize, emptyStackIsAllowed, isolate);
 }
 
 PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(size_t maxStackSize)
@@ -128,8 +133,9 @@
 
 PassRefPtr<ScriptArguments> createScriptArguments(const v8::FunctionCallbackInfo<v8::Value>& v8arguments, unsigned skipArgumentCount)
 {
-    v8::HandleScope scope;
-    v8::Local<v8::Context> context = v8::Context::GetCurrent();
+    v8::Isolate* isolate = v8arguments.GetIsolate();
+    v8::HandleScope scope(isolate);
+    v8::Local<v8::Context> context = isolate->GetCurrentContext();
     ScriptState* state = ScriptState::forContext(context);
 
     Vector<ScriptValue> arguments;
diff --git a/Source/bindings/v8/ScriptCallStackFactory.h b/Source/bindings/v8/ScriptCallStackFactory.h
index 54ae6fa..36f1cde 100644
--- a/Source/bindings/v8/ScriptCallStackFactory.h
+++ b/Source/bindings/v8/ScriptCallStackFactory.h
@@ -44,10 +44,11 @@
 const v8::StackTrace::StackTraceOptions stackTraceOptions = static_cast<v8::StackTrace::StackTraceOptions>(
       v8::StackTrace::kLineNumber
     | v8::StackTrace::kColumnOffset
+    | v8::StackTrace::kScriptId
     | v8::StackTrace::kScriptNameOrSourceURL
     | v8::StackTrace::kFunctionName);
 
-PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace>, size_t maxStackSize);
+PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace>, size_t maxStackSize, v8::Isolate*);
 PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize, bool emptyStackIsAllowed = false);
 PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(size_t maxStackSize = ScriptCallStack::maxCallStackSizeToCapture);
 PassRefPtr<ScriptArguments> createScriptArguments(const v8::FunctionCallbackInfo<v8::Value>& v8arguments, unsigned skipArgumentCount);
diff --git a/Source/bindings/v8/ScriptController.cpp b/Source/bindings/v8/ScriptController.cpp
index 85c070f..db933b8 100644
--- a/Source/bindings/v8/ScriptController.cpp
+++ b/Source/bindings/v8/ScriptController.cpp
@@ -156,7 +156,7 @@
 {
     // Keep Frame (and therefore ScriptController) alive.
     RefPtr<Frame> protect(m_frame);
-    return ScriptController::callFunctionWithInstrumentation(m_frame ? m_frame->document() : 0, function, receiver, argc, args);
+    return ScriptController::callFunctionWithInstrumentation(m_frame ? m_frame->document() : 0, function, receiver, argc, args, m_isolate);
 }
 
 ScriptValue ScriptController::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> argv[])
@@ -190,7 +190,7 @@
     return builder.toString();
 }
 
-v8::Local<v8::Value> ScriptController::callFunctionWithInstrumentation(ScriptExecutionContext* context, v8::Handle<v8::Function> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[])
+v8::Local<v8::Value> ScriptController::callFunctionWithInstrumentation(ScriptExecutionContext* context, v8::Handle<v8::Function> function, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[], v8::Isolate* isolate)
 {
     InspectorInstrumentationCookie cookie;
     if (InspectorInstrumentation::timelineAgentEnabled(context)) {
@@ -200,7 +200,7 @@
         cookie = InspectorInstrumentation::willCallFunction(context, resourceName, lineNumber);
     }
 
-    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context, receiver, argc, args);
+    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context, receiver, argc, args, isolate);
 
     InspectorInstrumentation::didCallFunction(cookie);
     return result;
@@ -230,7 +230,7 @@
 
         // Keep Frame (and therefore ScriptController) alive.
         RefPtr<Frame> protect(m_frame);
-        result = V8ScriptRunner::runCompiledScript(script, m_frame->document());
+        result = V8ScriptRunner::runCompiledScript(script, m_frame->document(), m_isolate);
         ASSERT(!tryCatch.HasCaught() || result.IsEmpty());
     }
 
@@ -354,7 +354,7 @@
 
     v8::Context::Scope scope(v8Context);
 
-    v8::Handle<v8::Object> value = createV8ObjectForNPObject(object, 0);
+    v8::Handle<v8::Object> value = createV8ObjectForNPObject(object, 0, m_isolate);
 
     // Attach to the global object.
     v8::Handle<v8::Object> global = v8Context->Global();
@@ -414,7 +414,7 @@
     // NPObject as part of its wrapper. However, before accessing the object
     // it must consult the _NPN_Registry.
 
-    v8::Local<v8::Object> wrapper = createV8ObjectForNPObject(npObject, 0);
+    v8::Local<v8::Object> wrapper = createV8ObjectForNPObject(npObject, 0, m_isolate);
 
     // Track the plugin object. We've been given a reference to the object.
     m_pluginObjects.set(widget, npObject);
@@ -455,9 +455,9 @@
     return 0;
 }
 
-static NPObject* createScriptObject(Frame* frame)
+static NPObject* createScriptObject(Frame* frame, v8::Isolate* isolate)
 {
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(isolate);
     v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(frame);
     if (v8Context.IsEmpty())
         return createNoScriptObject();
@@ -478,7 +478,7 @@
     if (canExecuteScripts(NotAboutToExecuteScript)) {
         // JavaScript is enabled, so there is a JavaScript window object.
         // Return an NPObject bound to the window object.
-        m_windowScriptNPObject = createScriptObject(m_frame);
+        m_windowScriptNPObject = createScriptObject(m_frame, m_isolate);
         _NPN_RegisterObject(m_windowScriptNPObject, 0);
     } else {
         // JavaScript is not enabled, so we cannot bind the NPObject to the
@@ -495,7 +495,7 @@
     if (!canExecuteScripts(NotAboutToExecuteScript))
         return createNoScriptObject();
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(m_isolate);
     v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_frame);
     if (v8Context.IsEmpty())
         return createNoScriptObject();
@@ -528,7 +528,7 @@
 
 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, SecurityOrigin*> >& result)
 {
-    v8::HandleScope handleScope;
+    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();
@@ -547,7 +547,7 @@
     ASSERT(debugId > 0);
     if (!m_windowShell->isContextInitialized())
         return false;
-    v8::HandleScope scope;
+    v8::HandleScope scope(m_isolate);
     v8::Local<v8::Context> context = m_windowShell->context();
     return V8PerContextDebugData::setContextDebugData(context, "page", debugId);
 }
@@ -663,7 +663,7 @@
     const String* savedSourceURL = m_sourceURL;
     m_sourceURL = &sourceURL;
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(m_isolate);
     v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_frame);
     if (v8Context.IsEmpty())
         return ScriptValue();
@@ -690,10 +690,10 @@
 {
     ASSERT(worldID > 0);
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(m_isolate);
     v8::Local<v8::Array> v8Results;
     {
-        v8::HandleScope evaluateHandleScope;
+        v8::HandleScope evaluateHandleScope(m_isolate);
         RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldID, extensionGroup);
         V8WindowShell* isolatedWorldShell = windowShell(world.get());
 
diff --git a/Source/bindings/v8/ScriptController.h b/Source/bindings/v8/ScriptController.h
index 996182f..975c24c 100644
--- a/Source/bindings/v8/ScriptController.h
+++ b/Source/bindings/v8/ScriptController.h
@@ -34,7 +34,7 @@
 #include "bindings/v8/ScriptInstance.h"
 #include "bindings/v8/ScriptValue.h"
 
-#include "core/loader/CrossOriginAccessControl.h"
+#include "core/fetch/CrossOriginAccessControl.h"
 #include "wtf/Forward.h"
 #include "wtf/HashMap.h"
 #include "wtf/RefCounted.h"
@@ -97,7 +97,7 @@
 
     v8::Local<v8::Value> callFunction(v8::Handle<v8::Function>, v8::Handle<v8::Object>, int argc, v8::Handle<v8::Value> argv[]);
     ScriptValue callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function>, v8::Handle<v8::Object>, int argc, v8::Handle<v8::Value> argv[]);
-    static v8::Local<v8::Value> callFunctionWithInstrumentation(ScriptExecutionContext*, v8::Handle<v8::Function>, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[]);
+    static v8::Local<v8::Value> callFunctionWithInstrumentation(ScriptExecutionContext*, v8::Handle<v8::Function>, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[], v8::Isolate*);
 
     // Returns true if the current world is isolated, and has its own Content
     // Security Policy. In this case, the policy of the main world should be
@@ -159,6 +159,8 @@
     bool setContextDebugId(int);
     static int contextDebugId(v8::Handle<v8::Context>);
 
+    v8::Isolate* isolate() const { return m_isolate; }
+
 private:
     typedef HashMap<int, OwnPtr<V8WindowShell> > IsolatedWorldMap;
     typedef HashMap<Widget*, NPObject*> PluginObjectMap;
diff --git a/Source/bindings/v8/ScriptDebugServer.cpp b/Source/bindings/v8/ScriptDebugServer.cpp
index 779917e..05e6539 100644
--- a/Source/bindings/v8/ScriptDebugServer.cpp
+++ b/Source/bindings/v8/ScriptDebugServer.cpp
@@ -598,7 +598,7 @@
         return;
     v8::Context::Scope contextScope(context);
     v8::TryCatch tryCatch;
-    v8::Local<v8::Value> value = V8ScriptRunner::runCompiledScript(script, state->scriptExecutionContext());
+    v8::Local<v8::Value> value = V8ScriptRunner::runCompiledScript(script, state->scriptExecutionContext(), m_isolate);
     *wasThrown = false;
     if (tryCatch.HasCaught()) {
         *wasThrown = true;
diff --git a/Source/bindings/v8/ScriptEventListener.cpp b/Source/bindings/v8/ScriptEventListener.cpp
index 1d4a7f3..7d4cc36 100644
--- a/Source/bindings/v8/ScriptEventListener.cpp
+++ b/Source/bindings/v8/ScriptEventListener.cpp
@@ -60,12 +60,12 @@
     TextPosition position(OrdinalNumber::fromZeroBasedInt(1), OrdinalNumber::first());
     String sourceURL;
 
-    if (Frame* frame = node->document()->frame()) {
+    if (Frame* frame = node->document().frame()) {
         ScriptController* scriptController = frame->script();
         if (!scriptController->canExecuteScripts(AboutToExecuteScript))
             return 0;
         position = scriptController->eventHandlerPosition();
-        sourceURL = node->document()->url().string();
+        sourceURL = node->document().url().string();
     }
 
     return V8LazyEventListener::create(name.localName().string(), eventParameterName(node->isSVGElement()), value, sourceURL, position, node);
@@ -94,7 +94,7 @@
     if (listener->type() != EventListener::JSEventListenerType)
         return "";
 
-    v8::HandleScope scope;
+    v8::HandleScope scope(getIsolateFromScriptExecutionContext(document));
     V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener);
     v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world());
     v8::Context::Scope contextScope(context);
@@ -110,7 +110,7 @@
     if (listener->type() != EventListener::JSEventListenerType)
         return ScriptValue();
 
-    v8::HandleScope scope;
+    v8::HandleScope scope(getIsolateFromScriptExecutionContext(document));
     V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener);
     v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world());
     v8::Context::Scope contextScope(context);
@@ -125,7 +125,7 @@
     if (listener->type() != EventListener::JSEventListenerType)
         return 0;
     V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener);
-    v8::HandleScope scope;
+    v8::HandleScope scope(frame->script()->isolate());
     v8::Handle<v8::Context> v8Context = frame->script()->windowShell(v8Listener->world())->context();
     return ScriptState::forContext(v8Context);
 }
@@ -135,7 +135,7 @@
     if (listener->type() != EventListener::JSEventListenerType)
         return false;
 
-    v8::HandleScope scope;
+    v8::HandleScope scope(getIsolateFromScriptExecutionContext(document));
     V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener);
     v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world());
     v8::Context::Scope contextScope(context);
diff --git a/Source/bindings/v8/ScriptFunctionCall.cpp b/Source/bindings/v8/ScriptFunctionCall.cpp
index a4baf98..9bfd279 100644
--- a/Source/bindings/v8/ScriptFunctionCall.cpp
+++ b/Source/bindings/v8/ScriptFunctionCall.cpp
@@ -74,31 +74,31 @@
 void ScriptCallArgumentHandler::appendArgument(long argument)
 {
     ScriptScope scope(m_scriptState);
-    m_arguments.append(v8::Number::New(argument));
+    m_arguments.append(v8::Number::New(m_scriptState->isolate(), argument));
 }
 
 void ScriptCallArgumentHandler::appendArgument(long long argument)
 {
     ScriptScope scope(m_scriptState);
-    m_arguments.append(v8::Number::New(argument));
+    m_arguments.append(v8::Number::New(m_scriptState->isolate(), argument));
 }
 
 void ScriptCallArgumentHandler::appendArgument(unsigned int argument)
 {
     ScriptScope scope(m_scriptState);
-    m_arguments.append(v8::Number::New(argument));
+    m_arguments.append(v8::Number::New(m_scriptState->isolate(), argument));
 }
 
 void ScriptCallArgumentHandler::appendArgument(unsigned long argument)
 {
     ScriptScope scope(m_scriptState);
-    m_arguments.append(v8::Number::New(argument));
+    m_arguments.append(v8::Number::New(m_scriptState->isolate(), argument));
 }
 
 void ScriptCallArgumentHandler::appendArgument(int argument)
 {
     ScriptScope scope(m_scriptState);
-    m_arguments.append(v8::Number::New(argument));
+    m_arguments.append(v8::Number::New(m_scriptState->isolate(), argument));
 }
 
 void ScriptCallArgumentHandler::appendArgument(bool argument)
@@ -133,7 +133,7 @@
         ASSERT(!args[i].IsEmpty());
     }
 
-    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, getScriptExecutionContext(), thisObject, m_arguments.size(), args.get());
+    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, getScriptExecutionContext(), thisObject, m_arguments.size(), args.get(), m_scriptState->isolate());
     if (!scope.success()) {
         hadException = true;
         return ScriptValue();
@@ -195,7 +195,7 @@
     for (size_t i = 0; i < m_arguments.size(); ++i)
         args[i] = m_arguments[i].v8Value();
 
-    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, function, object, m_arguments.size(), args.get());
+    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, function, object, m_arguments.size(), args.get(), m_scriptState->isolate());
     return ScriptValue(result);
 }
 
diff --git a/Source/bindings/v8/ScriptHeapSnapshot.cpp b/Source/bindings/v8/ScriptHeapSnapshot.cpp
index dac1c47..76ea368 100644
--- a/Source/bindings/v8/ScriptHeapSnapshot.cpp
+++ b/Source/bindings/v8/ScriptHeapSnapshot.cpp
@@ -47,7 +47,7 @@
 
 String ScriptHeapSnapshot::title() const
 {
-    v8::HandleScope scope;
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
     return toWebCoreString(m_snapshot->GetTitle());
 }
 
diff --git a/Source/bindings/v8/ScriptObject.cpp b/Source/bindings/v8/ScriptObject.cpp
index 78fd5cc..c075c86 100644
--- a/Source/bindings/v8/ScriptObject.cpp
+++ b/Source/bindings/v8/ScriptObject.cpp
@@ -34,11 +34,7 @@
 #include "bindings/v8/ScriptScope.h"
 #include "bindings/v8/ScriptState.h"
 
-#include "V8InjectedScriptHost.h"
 #include "V8InspectorFrontendHost.h"
-#include "bindings/v8/V8Binding.h"
-#include "core/dom/Document.h"
-#include "core/page/Frame.h"
 
 #include <v8.h>
 
diff --git a/Source/bindings/v8/ScriptPreprocessor.cpp b/Source/bindings/v8/ScriptPreprocessor.cpp
index 232182e..390c4a2 100644
--- a/Source/bindings/v8/ScriptPreprocessor.cpp
+++ b/Source/bindings/v8/ScriptPreprocessor.cpp
@@ -32,14 +32,9 @@
 #include "bindings/v8/ScriptPreprocessor.h"
 
 #include "bindings/v8/ScriptController.h"
-#include "bindings/v8/ScriptDebugServer.h"
 #include "bindings/v8/ScriptSourceCode.h"
 #include "bindings/v8/ScriptValue.h"
-#include "bindings/v8/V8Binding.h"
 #include "bindings/v8/V8ScriptRunner.h"
-#include "core/page/DOMWindow.h"
-#include "core/page/Frame.h"
-#include "core/page/Page.h"
 #include "core/page/PageConsole.h"
 #include "wtf/TemporaryChange.h"
 
diff --git a/Source/bindings/v8/ScriptPromise.h b/Source/bindings/v8/ScriptPromise.h
new file mode 100644
index 0000000..02f0a22
--- /dev/null
+++ b/Source/bindings/v8/ScriptPromise.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScriptPromise_h
+#define ScriptPromise_h
+
+#include "bindings/v8/ScopedPersistent.h"
+#include "bindings/v8/ScriptValue.h"
+#include "bindings/v8/V8ScriptRunner.h"
+#include <v8.h>
+
+namespace WebCore {
+
+// ScriptPromise is the class for representing Promise values in C++ world.
+// ScriptPromise holds a Promise.
+// So holding a ScriptPromise as a member variable in DOM object causes
+// memory leaks since it has a reference from C++ to V8.
+//
+class ScriptPromise {
+public:
+    ScriptPromise()
+        : m_promise()
+    {
+    }
+
+    explicit ScriptPromise(ScriptValue promise)
+        : m_promise(promise)
+    {
+        ASSERT(!m_promise.hasNoValue());
+    }
+
+    explicit ScriptPromise(v8::Handle<v8::Value> promise)
+        : m_promise(promise)
+    {
+        ASSERT(!m_promise.hasNoValue());
+    }
+
+    bool isObject() const
+    {
+        return m_promise.isObject();
+    }
+
+    bool isNull() const
+    {
+        return m_promise.isNull();
+    }
+
+    bool isUndefinedOrNull() const
+    {
+        return m_promise.isUndefined() || m_promise.isNull();
+    }
+
+    v8::Handle<v8::Value> v8Value() const
+    {
+        return m_promise.v8Value();
+    }
+
+    bool hasNoValue() const
+    {
+        return m_promise.hasNoValue();
+    }
+
+    void clear()
+    {
+        m_promise.clear();
+    }
+
+private:
+    ScriptValue m_promise;
+};
+
+} // namespace WebCore
+
+
+#endif // ScriptPromise_h
diff --git a/Source/bindings/v8/ScriptPromiseResolver.cpp b/Source/bindings/v8/ScriptPromiseResolver.cpp
index 6d51b49..8743f73 100644
--- a/Source/bindings/v8/ScriptPromiseResolver.cpp
+++ b/Source/bindings/v8/ScriptPromiseResolver.cpp
@@ -48,7 +48,7 @@
     ASSERT(RuntimeEnabledFeatures::promiseEnabled());
     v8::Local<v8::Object> promise, resolver;
     V8PromiseCustom::createPromise(creationContext, &promise, &resolver, isolate);
-    m_promise.set(isolate, promise);
+    m_promise = ScriptPromise(promise);
     m_resolver.set(isolate, resolver);
 }
 
diff --git a/Source/bindings/v8/ScriptPromiseResolver.h b/Source/bindings/v8/ScriptPromiseResolver.h
index 18d3052..7140b39 100644
--- a/Source/bindings/v8/ScriptPromiseResolver.h
+++ b/Source/bindings/v8/ScriptPromiseResolver.h
@@ -33,6 +33,7 @@
 
 #include "bindings/v8/ScopedPersistent.h"
 #include "bindings/v8/ScriptObject.h"
+#include "bindings/v8/ScriptPromise.h"
 #include "bindings/v8/ScriptState.h"
 #include "bindings/v8/ScriptValue.h"
 #include "wtf/RefPtr.h"
@@ -51,7 +52,7 @@
 //  1. Create a ScriptPromiseResolver.
 //  2. Pass the promise object of the holder to a JavaScript program
 //     (such as XMLHttpRequest return value).
-//  3. Detach the promise object if you no long need it.
+//  3. Detach the promise object if you no longer need it.
 //  4. Call fulfill or reject when the operation completes or
 //     the operation fails respectively.
 //
@@ -59,6 +60,14 @@
 // To use ScriptPromiseResolver out of a v8 context the caller must
 // enter a v8 context, for example by using ScriptScope and ScriptState.
 //
+// If you hold ScriptPromiseResolver as a member variable in a DOM object,
+// it causes memory leaks unless you detach the promise and resolver object
+// manually.
+// So if you no longer need the promise object, you should call detachPromise.
+// And if the operation completes or fails, you should call fulfill / resolve /
+// reject. Destroying ScriptPromiseResolver will also detach the promise and
+// resolver object.
+//
 class ScriptPromiseResolver : public RefCounted<ScriptPromiseResolver> {
     WTF_MAKE_NONCOPYABLE(ScriptPromiseResolver);
 public:
@@ -83,10 +92,10 @@
     //  - The resolver's resolved flag is not set.
     bool isPending() const;
 
-    ScriptObject promise()
+    ScriptPromise promise()
     {
         ASSERT(v8::Context::InContext());
-        return ScriptObject(ScriptState::current(), m_promise.newLocal(m_isolate));
+        return m_promise;
     }
 
     // Fulfill with a C++ object which can be converted to a v8 object by toV8.
@@ -110,7 +119,7 @@
     void reject(v8::Handle<v8::Value>);
 
     v8::Isolate* m_isolate;
-    ScopedPersistent<v8::Object> m_promise;
+    ScriptPromise m_promise;
     ScopedPersistent<v8::Object> m_resolver;
     bool isPendingInternal() const;
 };
diff --git a/Source/bindings/v8/ScriptPromiseResolverTest.cpp b/Source/bindings/v8/ScriptPromiseResolverTest.cpp
index 3e71920..41fdf89 100644
--- a/Source/bindings/v8/ScriptPromiseResolverTest.cpp
+++ b/Source/bindings/v8/ScriptPromiseResolverTest.cpp
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "bindings/v8/ScriptPromiseResolver.h"
 
+#include "bindings/v8/ScriptPromise.h"
 #include "bindings/v8/V8Binding.h"
 #include "bindings/v8/custom/V8PromiseCustom.h"
 
@@ -79,7 +80,7 @@
     v8::Local<v8::Object> promise()
     {
         ASSERT(!m_promise.hasNoValue());
-        return m_promise.v8Object();
+        return m_promise.v8Value().As<v8::Object>();
     }
 
 protected:
@@ -88,7 +89,7 @@
     ScopedPersistent<v8::Context> m_context;
     v8::Context::Scope m_contextScope;
     RefPtr<ScriptPromiseResolver> m_resolver;
-    ScriptObject m_promise;
+    ScriptPromise m_promise;
     OwnPtr<V8PerContextData> m_perContextData;
 };
 
diff --git a/Source/bindings/v8/ScriptScope.cpp b/Source/bindings/v8/ScriptScope.cpp
index 248990f..7081511 100644
--- a/Source/bindings/v8/ScriptScope.cpp
+++ b/Source/bindings/v8/ScriptScope.cpp
@@ -39,7 +39,8 @@
 namespace WebCore {
 
 ScriptScope::ScriptScope(ScriptState* scriptState, bool reportExceptions)
-    : m_context(scriptState->context())
+    : m_handleScope(scriptState->isolate())
+    , m_context(scriptState->context())
     , m_scope(m_context)
 {
     m_exceptionCatcher.SetVerbose(reportExceptions);
diff --git a/Source/bindings/v8/ScriptState.cpp b/Source/bindings/v8/ScriptState.cpp
index 516eb94..e785641 100644
--- a/Source/bindings/v8/ScriptState.cpp
+++ b/Source/bindings/v8/ScriptState.cpp
@@ -83,8 +83,9 @@
 
 ScriptState* ScriptState::current()
 {
-    v8::HandleScope handleScope;
-    v8::Local<v8::Context> context = v8::Context::GetCurrent();
+    v8::Isolate* isolate = v8::Isolate::GetCurrent();
+    v8::HandleScope handleScope(isolate);
+    v8::Local<v8::Context> context = isolate->GetCurrentContext();
     ASSERT(!context.IsEmpty());
     return ScriptState::forContext(context);
 }
@@ -108,7 +109,7 @@
 
 ScriptState* mainWorldScriptState(Frame* frame)
 {
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(frame->script()->isolate());
     return ScriptState::forContext(frame->script()->mainWorldContext());
 }
 
@@ -118,7 +119,7 @@
     if (!script)
         return 0;
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(script->isolate());
     return ScriptState::forContext(script->context());
 }
 
diff --git a/Source/bindings/v8/ScriptState.h b/Source/bindings/v8/ScriptState.h
index 16a4a4a..b6f7e37 100644
--- a/Source/bindings/v8/ScriptState.h
+++ b/Source/bindings/v8/ScriptState.h
@@ -109,7 +109,7 @@
     ScriptStateProtectedPtr(ScriptState* scriptState)
         : m_scriptState(scriptState)
     {
-        v8::HandleScope handleScope;
+        v8::HandleScope handleScope(scriptState->isolate());
         // Keep the context from being GC'ed. ScriptState is guaranteed to be live while the context is live.
         m_context.set(scriptState->isolate(), scriptState->context());
     }
diff --git a/Source/bindings/v8/ScriptString.cpp b/Source/bindings/v8/ScriptString.cpp
index b031856..d97a77a 100644
--- a/Source/bindings/v8/ScriptString.cpp
+++ b/Source/bindings/v8/ScriptString.cpp
@@ -48,7 +48,7 @@
 {
     if (hasNoValue())
         return String();
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(v8::Isolate::GetCurrent());
     v8::Handle<v8::String> value = v8::Handle<v8::String>::Cast(v8Value());
     return v8StringToWebCoreString<String>(value, Externalize);
 }
diff --git a/Source/bindings/v8/ScriptWrappable.h b/Source/bindings/v8/ScriptWrappable.h
index c0d292a..b60fbba 100644
--- a/Source/bindings/v8/ScriptWrappable.h
+++ b/Source/bindings/v8/ScriptWrappable.h
@@ -69,7 +69,7 @@
             return;
         }
         v8::Persistent<v8::Object> persistent(isolate, wrapper);
-        configuration.configureWrapper(&persistent, isolate);
+        configuration.configureWrapper(&persistent);
         persistent.MakeWeak(this, &makeWeakCallback);
         m_wrapperOrTypeInfo = reinterpret_cast<uintptr_t>(persistent.ClearAndLeak()) | 1;
         ASSERT(containsWrapper());
diff --git a/Source/bindings/v8/SerializedScriptValue.cpp b/Source/bindings/v8/SerializedScriptValue.cpp
index 5a0c0d8..de2275a 100644
--- a/Source/bindings/v8/SerializedScriptValue.cpp
+++ b/Source/bindings/v8/SerializedScriptValue.cpp
@@ -532,10 +532,13 @@
         doWriteUint32(length);
     }
 
-    StringBuffer<BufferValueType>& data()
+    String takeWireString()
     {
+        COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes);
         fillHole();
-        return m_buffer;
+        String data = String(m_buffer.data(), m_buffer.size());
+        data.impl()->truncateAssumingIsolated((m_position + 1) / sizeof(BufferValueType));
+        return data;
     }
 
     void writeReferenceCount(uint32_t numberOfReferences)
@@ -643,10 +646,10 @@
         m_position += length;
     }
 
-    void ensureSpace(int extra)
+    void ensureSpace(unsigned extra)
     {
         COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes);
-        m_buffer.resize((m_position + extra + 1) / 2); // "+ 1" to round up.
+        m_buffer.resize((m_position + extra + 1) / sizeof(BufferValueType)); // "+ 1" to round up.
     }
 
     void fillHole()
@@ -660,7 +663,7 @@
 
     uint8_t* byteAt(int position)
     {
-        return reinterpret_cast<uint8_t*>(m_buffer.characters()) + position;
+        return reinterpret_cast<uint8_t*>(m_buffer.data()) + position;
     }
 
     int v8StringWriteOptions()
@@ -668,7 +671,7 @@
         return v8::String::NO_NULL_TERMINATION;
     }
 
-    StringBuffer<BufferValueType> m_buffer;
+    Vector<BufferValueType> m_buffer;
     unsigned m_position;
     v8::Isolate* m_isolate;
 };
@@ -1697,7 +1700,7 @@
         double number;
         if (!doReadNumber(&number))
             return false;
-        *value = v8::Number::New(number);
+        *value = v8::Number::New(m_isolate, number);
         return true;
     }
 
@@ -1880,7 +1883,7 @@
             return false;
         if (!readWebCoreString(&url))
             return false;
-        RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionContext(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, url), AsyncFileSystem::create());
+        RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionContext(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, url));
         *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate);
         return true;
     }
@@ -1985,7 +1988,7 @@
         if (!m_reader.readVersion(m_version) || m_version > wireFormatVersion)
             return v8NullWithCheck(m_reader.getIsolate());
         m_reader.setVersion(m_version);
-        v8::HandleScope scope;
+        v8::HandleScope scope(m_reader.getIsolate());
         while (!m_reader.isEof()) {
             if (!doDeserialize())
                 return v8NullWithCheck(m_reader.getIsolate());
@@ -2269,7 +2272,7 @@
 {
     Writer writer(isolate);
     writer.writeWebCoreString(data);
-    String wireData = String::adopt(writer.data());
+    String wireData = writer.takeWireString();
     return adoptRef(new SerializedScriptValue(wireData));
 }
 
@@ -2287,7 +2290,7 @@
 {
     Writer writer(isolate);
     writer.writeNull();
-    String wireData = String::adopt(writer.data());
+    String wireData = writer.takeWireString();
     return adoptRef(new SerializedScriptValue(wireData));
 }
 
@@ -2300,7 +2303,7 @@
 {
     Writer writer(isolate);
     writer.writeUndefined();
-    String wireData = String::adopt(writer.data());
+    String wireData = writer.takeWireString();
     return adoptRef(new SerializedScriptValue(wireData));
 }
 
@@ -2316,7 +2319,7 @@
         writer.writeTrue();
     else
         writer.writeFalse();
-    String wireData = String::adopt(writer.data());
+    String wireData = writer.takeWireString();
     return adoptRef(new SerializedScriptValue(wireData));
 }
 
@@ -2329,7 +2332,7 @@
 {
     Writer writer(isolate);
     writer.writeNumber(value);
-    String wireData = String::adopt(writer.data());
+    String wireData = writer.takeWireString();
     return adoptRef(new SerializedScriptValue(wireData));
 }
 
@@ -2463,8 +2466,8 @@
         didThrow = true;
         return;
     case Serializer::Success:
-        // FIXME: This call to isolatedCopy should be redundant.
-        m_data = String(String::adopt(writer.data())).isolatedCopy();
+        m_data = writer.takeWireString();
+        ASSERT(m_data.impl()->hasOneRef());
         if (arrayBuffers && arrayBuffers->size())
             m_arrayBufferContentsArray = transferArrayBuffers(*arrayBuffers, didThrow, isolate);
         return;
@@ -2507,7 +2510,7 @@
 
 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptState)
 {
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(scriptState->isolate());
     v8::Context::Scope contextScope(scriptState->context());
 
     return ScriptValue(deserialize(scriptState->isolate()));
diff --git a/Source/bindings/v8/V8AbstractEventListener.cpp b/Source/bindings/v8/V8AbstractEventListener.cpp
index 64c057c..e6937c9 100644
--- a/Source/bindings/v8/V8AbstractEventListener.cpp
+++ b/Source/bindings/v8/V8AbstractEventListener.cpp
@@ -38,11 +38,9 @@
 #include "bindings/v8/V8EventListenerList.h"
 #include "bindings/v8/V8HiddenPropertyName.h"
 #include "core/dom/BeforeUnloadEvent.h"
-#include "core/dom/Document.h"
 #include "core/dom/Event.h"
 #include "core/dom/EventNames.h"
 #include "core/inspector/InspectorCounters.h"
-#include "core/page/Frame.h"
 #include "core/workers/WorkerGlobalScope.h"
 
 namespace WebCore {
diff --git a/Source/bindings/v8/V8AbstractEventListener.h b/Source/bindings/v8/V8AbstractEventListener.h
index 6a2806d..9fcb915 100644
--- a/Source/bindings/v8/V8AbstractEventListener.h
+++ b/Source/bindings/v8/V8AbstractEventListener.h
@@ -110,6 +110,7 @@
         }
 
         virtual DOMWrapperWorld* world() const OVERRIDE FINAL { return m_world.get(); }
+        v8::Isolate* isolate() const { return m_isolate; }
 
     protected:
         V8AbstractEventListener(bool isAttribute, PassRefPtr<DOMWrapperWorld>, v8::Isolate*);
diff --git a/Source/bindings/v8/V8Binding.cpp b/Source/bindings/v8/V8Binding.cpp
index 5abfe44..fa134ca 100644
--- a/Source/bindings/v8/V8Binding.cpp
+++ b/Source/bindings/v8/V8Binding.cpp
@@ -411,7 +411,8 @@
     v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
     for (size_t i = 0; i < v8Array->Length(); ++i) {
         v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(i, isolate));
-        ret->append(toWebCoreString(indexedValue));
+        V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, indexedValue, 0);
+        ret->append(stringValue);
     }
     return ret.release();
 }
@@ -539,9 +540,9 @@
     return true;
 }
 
-v8::Local<v8::Value> handleMaxRecursionDepthExceeded()
+v8::Local<v8::Value> handleMaxRecursionDepthExceeded(v8::Isolate* isolate)
 {
-    throwError(v8RangeError, "Maximum call stack size exceeded.", v8::Isolate::GetCurrent());
+    throwError(v8RangeError, "Maximum call stack size exceeded.", isolate);
     return v8::Local<v8::Value>();
 }
 
@@ -590,4 +591,15 @@
     return wrapper.IsEmpty() ? v8::Local<v8::Value>() : wrapper->GetHiddenValue(key);
 }
 
+v8::Isolate* getIsolateFromScriptExecutionContext(ScriptExecutionContext* context)
+{
+    if (context && context->isDocument()) {
+        static v8::Isolate* mainWorldIsolate = 0;
+        if (!mainWorldIsolate)
+            mainWorldIsolate = v8::Isolate::GetCurrent();
+        return mainWorldIsolate;
+    }
+    return v8::Isolate::GetCurrent();
+}
+
 } // namespace WebCore
diff --git a/Source/bindings/v8/V8Binding.h b/Source/bindings/v8/V8Binding.h
index 409537d..723840b 100644
--- a/Source/bindings/v8/V8Binding.h
+++ b/Source/bindings/v8/V8Binding.h
@@ -264,17 +264,17 @@
 
     template<>
     struct V8ValueTraits<float> {
-        static inline v8::Handle<v8::Value> arrayV8Value(const float& value, v8::Isolate*)
+        static inline v8::Handle<v8::Value> arrayV8Value(const float& value, v8::Isolate* isolate)
         {
-            return v8::Number::New(value);
+            return v8::Number::New(isolate, value);
         }
     };
 
     template<>
     struct V8ValueTraits<double> {
-        static inline v8::Handle<v8::Value> arrayV8Value(const double& value, v8::Isolate*)
+        static inline v8::Handle<v8::Value> arrayV8Value(const double& value, v8::Isolate* isolate)
         {
-            return v8::Number::New(value);
+            return v8::Number::New(isolate, value);
         }
     };
 
@@ -435,13 +435,14 @@
             return Vector<RefPtr<T> >();
 
         Vector<RefPtr<T> > result;
+        result.reserveInitialCapacity(length);
         v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
         for (uint32_t i = 0; i < length; ++i) {
             v8::Handle<v8::Value> element = object->Get(i);
 
             if (V8T::HasInstance(element, isolate, worldType(isolate))) {
                 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(element);
-                result.append(V8T::toNative(elementObject));
+                result.uncheckedAppend(V8T::toNative(elementObject));
             } else {
                 if (success)
                     *success = false;
@@ -465,10 +466,11 @@
             return Vector<T>();
 
         Vector<T> result;
+        result.reserveInitialCapacity(length);
         typedef NativeValueTraits<T> TraitsType;
         v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
         for (uint32_t i = 0; i < length; ++i)
-            result.append(TraitsType::nativeValue(object->Get(i)));
+            result.uncheckedAppend(TraitsType::nativeValue(object->Get(i)));
         return result;
     }
 
@@ -479,8 +481,9 @@
         Vector<T> result;
         typedef NativeValueTraits<T> TraitsType;
         int length = args.Length();
+        result.reserveInitialCapacity(length);
         for (int i = startIndex; i < length; ++i)
-            result.append(TraitsType::nativeValue(args[i]));
+            result.uncheckedAppend(TraitsType::nativeValue(args[i]));
         return result;
     }
 
@@ -613,8 +616,7 @@
     // If the current context causes out of memory, JavaScript setting
     // is disabled and it returns true.
     bool handleOutOfMemory();
-    // FIXME: This should receive an Isolate.
-    v8::Local<v8::Value> handleMaxRecursionDepthExceeded();
+    v8::Local<v8::Value> handleMaxRecursionDepthExceeded(v8::Isolate*);
 
     void crashIfV8IsDead();
 
@@ -633,6 +635,8 @@
 
     v8::Local<v8::Value> getHiddenValueFromMainWorldWrapper(v8::Isolate*, ScriptWrappable*, v8::Handle<v8::String> key);
 
+    v8::Isolate* getIsolateFromScriptExecutionContext(ScriptExecutionContext*);
+
 } // namespace WebCore
 
 #endif // V8Binding_h
diff --git a/Source/bindings/v8/V8BindingMacros.h b/Source/bindings/v8/V8BindingMacros.h
index 53416e5..9fae960 100644
--- a/Source/bindings/v8/V8BindingMacros.h
+++ b/Source/bindings/v8/V8BindingMacros.h
@@ -53,20 +53,6 @@
         }                                 \
     }
 
-#define V8TRYCATCH_WITH_TYPECHECK(type, var, value, isolate) \
-    type var;                                                \
-    {                                                        \
-        bool ok = true;                                      \
-        {                                                    \
-            v8::TryCatch block;                              \
-            var = (value);                                   \
-            if (block.HasCaught())                           \
-                return block.ReThrow();                      \
-        }                                                    \
-        if (UNLIKELY(!ok))                                   \
-            return throwTypeError(isolate);                  \
-    }
-
 #define V8TRYCATCH_WITH_TYPECHECK_VOID(type, var, value, isolate) \
     type var;                                                     \
     {                                                             \
@@ -85,10 +71,13 @@
         }                                                         \
     }
 
+#define V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(type, var, value, retVal) \
+    type var(value);                                                     \
+    if (!var.prepare())                                                  \
+        return retVal;
+
 #define V8TRYCATCH_FOR_V8STRINGRESOURCE(type, var, value) \
-    type var(value);                                            \
-    if (!var.prepare())                                         \
-        return v8::Undefined();
+    V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(type, var, value, v8::Undefined());
 
 #define V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(type, var, value) \
     type var(value);                                                 \
diff --git a/Source/bindings/v8/V8Callback.cpp b/Source/bindings/v8/V8Callback.cpp
index 9879908..d103c34 100644
--- a/Source/bindings/v8/V8Callback.cpp
+++ b/Source/bindings/v8/V8Callback.cpp
@@ -36,12 +36,12 @@
 
 namespace WebCore {
 
-bool invokeCallback(v8::Handle<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
+bool invokeCallback(v8::Handle<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext, v8::Isolate* isolate)
 {
-    return invokeCallback(callback, v8::Context::GetCurrent()->Global(), argc, argv, callbackReturnValue, scriptExecutionContext);
+    return invokeCallback(callback, v8::Context::GetCurrent()->Global(), argc, argv, callbackReturnValue, scriptExecutionContext, isolate);
 }
 
-bool invokeCallback(v8::Handle<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
+bool invokeCallback(v8::Handle<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext, v8::Isolate* isolate)
 {
     v8::TryCatch exceptionCatcher;
     exceptionCatcher.SetVerbose(true);
@@ -59,7 +59,7 @@
     if (callbackFunction.IsEmpty())
         return false;
 
-    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(scriptExecutionContext, callbackFunction, thisObject, argc, argv);
+    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(scriptExecutionContext, callbackFunction, thisObject, argc, argv, isolate);
 
     callbackReturnValue = !result.IsEmpty() && result->BooleanValue();
     return exceptionCatcher.HasCaught();
diff --git a/Source/bindings/v8/V8Callback.h b/Source/bindings/v8/V8Callback.h
index c17cf7f..bfcaa60 100644
--- a/Source/bindings/v8/V8Callback.h
+++ b/Source/bindings/v8/V8Callback.h
@@ -40,8 +40,8 @@
 
 class ScriptExecutionContext;
 
-bool invokeCallback(v8::Handle<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*);
-bool invokeCallback(v8::Handle<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*);
+bool invokeCallback(v8::Handle<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*, v8::Isolate*);
+bool invokeCallback(v8::Handle<v8::Object> callback, v8::Handle<v8::Object> thisObject, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext*, v8::Isolate*);
 
 enum CallbackAllowedValueFlag {
     CallbackAllowUndefined = 1,
diff --git a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
index ede0046..206ce6b 100644
--- a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
+++ b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
@@ -45,11 +45,11 @@
 
 #define CALLBACK_LIST(V)                  \
     V(created, Created)                   \
-    V(enteredDocument, EnteredDocument)   \
-    V(leftDocument, LeftDocument)         \
+    V(enteredView, EnteredView)           \
+    V(leftView, LeftView)                 \
     V(attributeChanged, AttributeChanged)
 
-PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks::create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredDocument, v8::Handle<v8::Function> leftDocument, v8::Handle<v8::Function> attributeChanged)
+PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks::create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredView, v8::Handle<v8::Function> leftView, v8::Handle<v8::Function> attributeChanged)
 {
     // A given object can only be used as a Custom Element prototype
     // once; see customElementIsInterfacePrototypeObject
@@ -61,19 +61,19 @@
     CALLBACK_LIST(SET_HIDDEN_PROPERTY)
 #undef SET_HIDDEN_PROPERTY
 
-    return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext, prototype, created, enteredDocument, leftDocument, attributeChanged));
+    return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext, prototype, created, enteredView, leftView, attributeChanged));
 }
 
-static CustomElementLifecycleCallbacks::CallbackType flagSet(v8::Handle<v8::Function> enteredDocument, v8::Handle<v8::Function> leftDocument, v8::Handle<v8::Function> attributeChanged)
+static CustomElementLifecycleCallbacks::CallbackType flagSet(v8::Handle<v8::Function> enteredView, v8::Handle<v8::Function> leftView, v8::Handle<v8::Function> attributeChanged)
 {
     // V8 Custom Elements always run created to swizzle prototypes.
     int flags = CustomElementLifecycleCallbacks::Created;
 
-    if (!enteredDocument.IsEmpty())
-        flags |= CustomElementLifecycleCallbacks::EnteredDocument;
+    if (!enteredView.IsEmpty())
+        flags |= CustomElementLifecycleCallbacks::EnteredView;
 
-    if (!leftDocument.IsEmpty())
-        flags |= CustomElementLifecycleCallbacks::LeftDocument;
+    if (!leftView.IsEmpty())
+        flags |= CustomElementLifecycleCallbacks::LeftView;
 
     if (!attributeChanged.IsEmpty())
         flags |= CustomElementLifecycleCallbacks::AttributeChanged;
@@ -87,14 +87,14 @@
     handle->clear();
 }
 
-V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredDocument, v8::Handle<v8::Function> leftDocument, v8::Handle<v8::Function> attributeChanged)
-    : CustomElementLifecycleCallbacks(flagSet(enteredDocument, leftDocument, attributeChanged))
+V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredView, v8::Handle<v8::Function> leftView, v8::Handle<v8::Function> attributeChanged)
+    : CustomElementLifecycleCallbacks(flagSet(enteredView, leftView, attributeChanged))
     , ActiveDOMCallback(scriptExecutionContext)
     , m_world(DOMWrapperWorld::current())
     , m_prototype(prototype)
     , m_created(created)
-    , m_enteredDocument(enteredDocument)
-    , m_leftDocument(leftDocument)
+    , m_enteredView(enteredView)
+    , m_leftView(leftView)
     , m_attributeChanged(attributeChanged)
     , m_owner(0)
 {
@@ -125,7 +125,7 @@
     if (!m_owner)
         return;
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(getIsolateFromScriptExecutionContext(scriptExecutionContext()));
     if (V8PerContextData* perContextData = creationContextData())
         perContextData->clearCustomElementBinding(m_owner);
 }
@@ -153,13 +153,13 @@
 
     element->setCustomElementState(Element::Upgraded);
 
-    v8::HandleScope handleScope;
+    v8::Isolate* isolate = getIsolateFromScriptExecutionContext(scriptExecutionContext());
+    v8::HandleScope handleScope(isolate);
     v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_world.get());
     if (context.IsEmpty())
         return;
 
     v8::Context::Scope scope(context);
-    v8::Isolate* isolate = context->GetIsolate();
 
     v8::Handle<v8::Object> receiver = DOMDataStore::current(isolate)->get<V8Element>(element, isolate);
     if (!receiver.IsEmpty()) {
@@ -183,17 +183,17 @@
 
     v8::TryCatch exceptionCatcher;
     exceptionCatcher.SetVerbose(true);
-    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0);
+    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0, isolate);
 }
 
-void V8CustomElementLifecycleCallbacks::enteredDocument(Element* element)
+void V8CustomElementLifecycleCallbacks::enteredView(Element* element)
 {
-    call(m_enteredDocument, element);
+    call(m_enteredView, element);
 }
 
-void V8CustomElementLifecycleCallbacks::leftDocument(Element* element)
+void V8CustomElementLifecycleCallbacks::leftView(Element* element)
 {
-    call(m_leftDocument, element);
+    call(m_leftView, element);
 }
 
 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
@@ -201,13 +201,13 @@
     if (!canInvokeCallback())
         return;
 
-    v8::HandleScope handleScope;
+    v8::Isolate* isolate = getIsolateFromScriptExecutionContext(scriptExecutionContext());
+    v8::HandleScope handleScope(isolate);
     v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_world.get());
     if (context.IsEmpty())
         return;
 
     v8::Context::Scope scope(context);
-    v8::Isolate* isolate = context->GetIsolate();
 
     v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).As<v8::Object>();
     ASSERT(!receiver.IsEmpty());
@@ -224,7 +224,7 @@
 
     v8::TryCatch exceptionCatcher;
     exceptionCatcher.SetVerbose(true);
-    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, WTF_ARRAY_LENGTH(argv), argv);
+    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, WTF_ARRAY_LENGTH(argv), argv, isolate);
 }
 
 void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function>& weakCallback, Element* element)
@@ -232,7 +232,7 @@
     if (!canInvokeCallback())
         return;
 
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(getIsolateFromScriptExecutionContext(scriptExecutionContext()));
     v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_world.get());
     if (context.IsEmpty())
         return;
@@ -249,7 +249,7 @@
 
     v8::TryCatch exceptionCatcher;
     exceptionCatcher.SetVerbose(true);
-    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0);
+    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0, isolate);
 }
 
 } // namespace WebCore
diff --git a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.h b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.h
index 71313ee..c504ea5 100644
--- a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.h
+++ b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.h
@@ -48,18 +48,18 @@
 
 class V8CustomElementLifecycleCallbacks : public CustomElementLifecycleCallbacks, ActiveDOMCallback {
 public:
-    static PassRefPtr<V8CustomElementLifecycleCallbacks> create(ScriptExecutionContext*, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredDocument, v8::Handle<v8::Function> leftDocument, v8::Handle<v8::Function> attributeChanged);
+    static PassRefPtr<V8CustomElementLifecycleCallbacks> create(ScriptExecutionContext*, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredView, v8::Handle<v8::Function> leftView, v8::Handle<v8::Function> attributeChanged);
 
     virtual ~V8CustomElementLifecycleCallbacks();
 
     bool setBinding(CustomElementDefinition* owner, PassOwnPtr<CustomElementBinding>);
 
 private:
-    V8CustomElementLifecycleCallbacks(ScriptExecutionContext*, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredDocument, v8::Handle<v8::Function> leftDocument, v8::Handle<v8::Function> attributeChanged);
+    V8CustomElementLifecycleCallbacks(ScriptExecutionContext*, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> enteredView, v8::Handle<v8::Function> leftView, v8::Handle<v8::Function> attributeChanged);
 
     virtual void created(Element*) OVERRIDE;
-    virtual void enteredDocument(Element*) OVERRIDE;
-    virtual void leftDocument(Element*) OVERRIDE;
+    virtual void enteredView(Element*) OVERRIDE;
+    virtual void leftView(Element*) OVERRIDE;
     virtual void attributeChanged(Element*, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) OVERRIDE;
 
     void call(const ScopedPersistent<v8::Function>& weakCallback, Element*);
@@ -70,8 +70,8 @@
     RefPtr<DOMWrapperWorld> m_world;
     ScopedPersistent<v8::Object> m_prototype;
     ScopedPersistent<v8::Function> m_created;
-    ScopedPersistent<v8::Function> m_enteredDocument;
-    ScopedPersistent<v8::Function> m_leftDocument;
+    ScopedPersistent<v8::Function> m_enteredView;
+    ScopedPersistent<v8::Function> m_leftView;
     ScopedPersistent<v8::Function> m_attributeChanged;
 };
 
diff --git a/Source/bindings/v8/V8DOMConfiguration.cpp b/Source/bindings/v8/V8DOMConfiguration.cpp
index 1bd549d..a266907 100644
--- a/Source/bindings/v8/V8DOMConfiguration.cpp
+++ b/Source/bindings/v8/V8DOMConfiguration.cpp
@@ -54,7 +54,9 @@
         v8::FunctionCallback callback = callbacks[i].callback;
         if (currentWorldType == MainWorld && callbacks[i].callbackForMainWorld)
             callback = callbacks[i].callbackForMainWorld;
-        prototype->Set(v8::String::NewSymbol(callbacks[i].name), v8::FunctionTemplate::New(callback, v8Undefined(), signature, callbacks[i].length), attributes);
+        v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New(callback, v8Undefined(), signature, callbacks[i].length);
+        functionTemplate->RemovePrototype();
+        prototype->Set(v8::String::NewSymbol(callbacks[i].name), functionTemplate, attributes);
     }
 }
 
diff --git a/Source/bindings/v8/V8DOMWrapper.cpp b/Source/bindings/v8/V8DOMWrapper.cpp
index 86e71fa..b725c3d 100644
--- a/Source/bindings/v8/V8DOMWrapper.cpp
+++ b/Source/bindings/v8/V8DOMWrapper.cpp
@@ -135,7 +135,7 @@
     v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
     ASSERT(object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount);
 
-    v8::HandleScope scope;
+    v8::HandleScope scope(v8::Isolate::GetCurrent());
     ASSERT(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
 
     return true;
diff --git a/Source/bindings/v8/V8ErrorHandler.cpp b/Source/bindings/v8/V8ErrorHandler.cpp
index f7b9681..1037f59 100644
--- a/Source/bindings/v8/V8ErrorHandler.cpp
+++ b/Source/bindings/v8/V8ErrorHandler.cpp
@@ -55,8 +55,12 @@
         return V8EventListener::callListenerFunction(context, jsEvent, event);
 
     ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event);
-    v8::Local<v8::Object> listener = getListenerObject(context);
+
     v8::Isolate* isolate = toV8Context(context, world())->GetIsolate();
+    if (errorEvent->world() && errorEvent->world() != world())
+        return v8::Null(isolate);
+
+    v8::Local<v8::Object> listener = getListenerObject(context);
     v8::Local<v8::Value> returnValue;
     if (!listener.IsEmpty() && listener->IsFunction()) {
         v8::Local<v8::Function> callFunction = v8::Local<v8::Function>::Cast(listener);
@@ -70,9 +74,9 @@
         v8::TryCatch tryCatch;
         tryCatch.SetVerbose(true);
         if (worldType(isolate) == WorkerWorld)
-            returnValue = V8ScriptRunner::callFunction(callFunction, context, thisValue, WTF_ARRAY_LENGTH(parameters), parameters);
+            returnValue = V8ScriptRunner::callFunction(callFunction, context, thisValue, WTF_ARRAY_LENGTH(parameters), parameters, isolate);
         else
-            returnValue = ScriptController::callFunctionWithInstrumentation(0, callFunction, thisValue, WTF_ARRAY_LENGTH(parameters), parameters);
+            returnValue = ScriptController::callFunctionWithInstrumentation(0, callFunction, thisValue, WTF_ARRAY_LENGTH(parameters), parameters, isolate);
     }
     return returnValue;
 }
diff --git a/Source/bindings/v8/V8EventListenerList.h b/Source/bindings/v8/V8EventListenerList.h
index 474de8d..e670b2c 100644
--- a/Source/bindings/v8/V8EventListenerList.h
+++ b/Source/bindings/v8/V8EventListenerList.h
@@ -74,7 +74,7 @@
     static V8EventListener* doFindWrapper(v8::Local<v8::Object> object, v8::Handle<v8::String> wrapperProperty)
     {
         ASSERT(v8::Context::InContext());
-        v8::HandleScope scope;
+        v8::HandleScope scope(v8::Isolate::GetCurrent());
         v8::Local<v8::Value> listener = object->GetHiddenValue(wrapperProperty);
         if (listener.IsEmpty())
             return 0;
diff --git a/Source/bindings/v8/V8GCController.cpp b/Source/bindings/v8/V8GCController.cpp
index 92976b8..ab880d8 100644
--- a/Source/bindings/v8/V8GCController.cpp
+++ b/Source/bindings/v8/V8GCController.cpp
@@ -75,7 +75,7 @@
     // Maybe should image elements be active DOM nodes?
     // See https://code.google.com/p/chromium/issues/detail?id=164882
     if (node->inDocument() || (node->hasTagName(HTMLNames::imgTag) && toHTMLImageElement(node)->hasPendingActivity()))
-        return node->document();
+        return &node->document();
 
     if (node->isAttributeNode()) {
         Node* ownerElement = toAttr(node)->ownerElement();
@@ -209,7 +209,7 @@
             // v8::Persistent.
             UnsafePersistent<v8::Object> unsafeWrapper = (*nodeIterator)->unsafePersistent();
             v8::Persistent<v8::Object>* wrapper = unsafeWrapper.persistent();
-            wrapper->MarkPartiallyDependent(isolate);
+            wrapper->MarkPartiallyDependent();
             // FIXME: update this to use the upcasting function which v8 will provide
             v8::Persistent<v8::Value>* value = reinterpret_cast<v8::Persistent<v8::Value>*>(wrapper);
             isolate->SetObjectGroupId(*value, id);
@@ -242,7 +242,7 @@
 
         ASSERT(V8DOMWrapper::maybeDOMWrapper(*wrapper));
 
-        if (value->IsIndependent(m_isolate))
+        if (value->IsIndependent())
             return;
 
         WrapperTypeInfo* type = toWrapperTypeInfo(*wrapper);
@@ -272,7 +272,7 @@
         if (classId == v8DOMNodeClassId) {
             UNUSED_PARAM(m_isolate);
             ASSERT(V8Node::HasInstanceInAnyWorld(*wrapper, m_isolate));
-            ASSERT(!value->IsIndependent(m_isolate));
+            ASSERT(!value->IsIndependent());
 
             Node* node = static_cast<Node*>(object);
 
@@ -283,7 +283,7 @@
             if (m_constructRetainedObjectInfos)
                 m_groupsWhichNeedRetainerInfo.append(root);
         } else if (classId == v8DOMObjectClassId) {
-            ASSERT(!value->IsIndependent(m_isolate));
+            ASSERT(!value->IsIndependent());
             void* root = type->opaqueRootForGC(object, m_isolate);
             m_isolate->SetObjectGroupId(*value, v8::UniqueId(reinterpret_cast<intptr_t>(root)));
         } else {
diff --git a/Source/bindings/v8/V8HiddenPropertyName.h b/Source/bindings/v8/V8HiddenPropertyName.h
index 907bcf7..63b7c48 100644
--- a/Source/bindings/v8/V8HiddenPropertyName.h
+++ b/Source/bindings/v8/V8HiddenPropertyName.h
@@ -43,9 +43,9 @@
     V(customElementAttributeChanged) \
     V(customElementCreated) \
     V(customElementDocument) \
-    V(customElementEnteredDocument) \
+    V(customElementEnteredView) \
     V(customElementIsInterfacePrototypeObject) \
-    V(customElementLeftDocument) \
+    V(customElementLeftView) \
     V(customElementNamespaceURI) \
     V(customElementTagName) \
     V(customElementType) \
diff --git a/Source/bindings/v8/V8Initializer.cpp b/Source/bindings/v8/V8Initializer.cpp
index 4772252..e31c12f 100644
--- a/Source/bindings/v8/V8Initializer.cpp
+++ b/Source/bindings/v8/V8Initializer.cpp
@@ -95,14 +95,14 @@
     RefPtr<ScriptCallStack> callStack;
     // Currently stack trace is only collected when inspector is open.
     if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0)
-        callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture);
+        callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture, v8::Isolate::GetCurrent());
 
     v8::Handle<v8::Value> resourceName = message->GetScriptResourceName();
     bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsString();
     String resource = shouldUseDocumentURL ? firstWindow->document()->url() : toWebCoreString(resourceName);
     AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin;
 
-    RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, message->GetLineNumber(), message->GetStartColumn());
+    RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, message->GetLineNumber(), message->GetStartColumn(), DOMWrapperWorld::current());
     if (V8DOMWrapper::isDOMWrapper(data)) {
         v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(data);
         WrapperTypeInfo* type = toWrapperTypeInfo(obj);
@@ -190,7 +190,7 @@
     if (ScriptExecutionContext* context = getScriptExecutionContext()) {
         String errorMessage = toWebCoreString(message->Get());
         String sourceURL = toWebCoreString(message->GetScriptResourceName());
-        RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, message->GetLineNumber(), message->GetStartColumn());
+        RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sourceURL, message->GetLineNumber(), message->GetStartColumn(), DOMWrapperWorld::current());
         AccessControlStatus corsStatus = message->IsSharedCrossOrigin() ? SharableCrossOrigin : NotSharableCrossOrigin;
 
         V8ErrorHandler::storeExceptionOnErrorEventWrapper(event.get(), data, v8::Isolate::GetCurrent());
diff --git a/Source/bindings/v8/V8LazyEventListener.cpp b/Source/bindings/v8/V8LazyEventListener.cpp
index 592a932..ddb553f 100644
--- a/Source/bindings/v8/V8LazyEventListener.cpp
+++ b/Source/bindings/v8/V8LazyEventListener.cpp
@@ -120,11 +120,11 @@
 
     ASSERT(context->isDocument());
 
-    v8::HandleScope handleScope;
+    v8::Isolate* isolate = getIsolateFromScriptExecutionContext(context);
+    v8::HandleScope handleScope(isolate);
 
     // Use the outer scope to hold context.
     v8::Local<v8::Context> v8Context = toV8Context(context, world());
-    v8::Isolate* isolate = v8Context->GetIsolate();
     // Bail out if we cannot get the context.
     if (v8Context.IsEmpty())
         return;
diff --git a/Source/bindings/v8/V8MutationCallback.cpp b/Source/bindings/v8/V8MutationCallback.cpp
index 484666e..0731691 100644
--- a/Source/bindings/v8/V8MutationCallback.cpp
+++ b/Source/bindings/v8/V8MutationCallback.cpp
@@ -78,7 +78,7 @@
 
     v8::TryCatch exceptionCatcher;
     exceptionCatcher.SetVerbose(true);
-    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, thisObject, 2, argv);
+    ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, thisObject, 2, argv, m_isolate);
 }
 
 void V8MutationCallback::makeWeakCallback(v8::Isolate*, v8::Persistent<v8::Function>*, V8MutationCallback* callback)
diff --git a/Source/bindings/v8/V8NPObject.cpp b/Source/bindings/v8/V8NPObject.cpp
index 73ccff1..200c407 100644
--- a/Source/bindings/v8/V8NPObject.cpp
+++ b/Source/bindings/v8/V8NPObject.cpp
@@ -281,7 +281,7 @@
 void npObjectIndexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
 {
     NPIdentifier identifier = _NPN_GetIntIdentifier(index);
-    v8SetReturnValue(info, npObjectGetProperty(info.Holder(), identifier, v8::Number::New(index), info.GetIsolate()));
+    v8SetReturnValue(info, npObjectGetProperty(info.Holder(), identifier, v8::Number::New(info.GetIsolate(), index), info.GetIsolate()));
 }
 
 void npObjectGetNamedProperty(v8::Local<v8::Object> self, v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
@@ -293,7 +293,7 @@
 void npObjectGetIndexedProperty(v8::Local<v8::Object> self, uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
 {
     NPIdentifier identifier = _NPN_GetIntIdentifier(index);
-    v8SetReturnValue(info, npObjectGetProperty(self, identifier, v8::Number::New(index), info.GetIsolate()));
+    v8SetReturnValue(info, npObjectGetProperty(self, identifier, v8::Number::New(info.GetIsolate(), index), info.GetIsolate()));
 }
 
 void npObjectQueryProperty(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
@@ -415,14 +415,12 @@
         _NPN_ReleaseObject(npObject);
 }
 
-v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root)
+v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root, v8::Isolate* isolate)
 {
-    static v8::Persistent<v8::FunctionTemplate> npObjectDesc;
+    static v8::Eternal<v8::FunctionTemplate> npObjectDesc;
 
     ASSERT(v8::Context::InContext());
 
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-
     // If this is a v8 object, just return it.
     V8NPObject* v8NPObject = npObjectToV8NPObject(object);
     if (v8NPObject)
@@ -437,19 +435,19 @@
     // pointer, and field 1 is the type. There should be an api function that returns unused type id. The same Wrapper type
     // can be used by DOM bindings.
     if (npObjectDesc.IsEmpty()) {
-        v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
+        v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
         templ->InstanceTemplate()->SetInternalFieldCount(npObjectInternalFieldCount);
         templ->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedPropertyGetter, npObjectNamedPropertySetter, npObjectQueryProperty, 0, npObjectNamedPropertyEnumerator);
         templ->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedPropertyGetter, npObjectIndexedPropertySetter, 0, 0, npObjectIndexedPropertyEnumerator);
         templ->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaultHandler);
-        npObjectDesc.Reset(isolate, templ);
+        npObjectDesc.Set(isolate, templ);
     }
 
     // FIXME: Move staticNPObjectMap() to DOMDataStore.
     // Use V8DOMWrapper::createWrapper() and
     // V8DOMWrapper::associateObjectWithWrapper()
     // to create a wrapper object.
-    v8::Handle<v8::Function> v8Function = v8::Local<v8::FunctionTemplate>::New(isolate, npObjectDesc)->GetFunction();
+    v8::Handle<v8::Function> v8Function = npObjectDesc.Get(isolate)->GetFunction();
     v8::Local<v8::Object> value = V8ObjectConstructor::newInstance(v8Function);
     if (value.IsEmpty())
         return value;
diff --git a/Source/bindings/v8/V8NPObject.h b/Source/bindings/v8/V8NPObject.h
index cd8d403..4465b03 100644
--- a/Source/bindings/v8/V8NPObject.h
+++ b/Source/bindings/v8/V8NPObject.h
@@ -54,7 +54,7 @@
 // Get a wrapper for a NPObject.
 // If the object is already wrapped, the pre-existing wrapper will be returned. If the object is not wrapped, wrap it, and
 // give V8 a weak reference to the wrapper which will cleanup when there are no more JS references to the object.
-v8::Local<v8::Object> createV8ObjectForNPObject(NPObject*, NPObject* root);
+v8::Local<v8::Object> createV8ObjectForNPObject(NPObject*, NPObject* root, v8::Isolate*);
 
 // Tell V8 to forcibly remove an object.
 // This is used at plugin teardown so that the caller can aggressively unload the plugin library. After calling this
diff --git a/Source/bindings/v8/V8NPUtils.cpp b/Source/bindings/v8/V8NPUtils.cpp
index b8b13a4..eb2e1a5 100644
--- a/Source/bindings/v8/V8NPUtils.cpp
+++ b/Source/bindings/v8/V8NPUtils.cpp
@@ -37,7 +37,6 @@
 #include "bindings/v8/npruntime_impl.h"
 #include "bindings/v8/npruntime_priv.h"
 #include "core/page/DOMWindow.h"
-#include "core/page/Frame.h"
 #include "wtf/text/WTFString.h"
 
 namespace WebCore {
@@ -84,13 +83,13 @@
     case NPVariantType_Int32:
         return v8::Integer::New(NPVARIANT_TO_INT32(*variant), isolate);
     case NPVariantType_Double:
-        return v8::Number::New(NPVARIANT_TO_DOUBLE(*variant));
+        return v8::Number::New(isolate, NPVARIANT_TO_DOUBLE(*variant));
     case NPVariantType_Bool:
-        return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant));
+        return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant), isolate);
     case NPVariantType_Null:
-        return v8::Null();
+        return v8::Null(isolate);
     case NPVariantType_Void:
-        return v8::Undefined();
+        return v8::Undefined(isolate);
     case NPVariantType_String: {
         NPString src = NPVARIANT_TO_STRING(*variant);
         return v8::String::New(src.UTF8Characters, src.UTF8Length);
@@ -99,10 +98,10 @@
         NPObject* object = NPVARIANT_TO_OBJECT(*variant);
         if (V8NPObject* v8Object = npObjectToV8NPObject(object))
             return v8::Local<v8::Object>::New(isolate, v8Object->v8Object);
-        return createV8ObjectForNPObject(object, owner);
+        return createV8ObjectForNPObject(object, owner, isolate);
     }
     default:
-        return v8::Undefined();
+        return v8::Undefined(isolate);
     }
 }
 
diff --git a/Source/bindings/v8/V8NodeFilterCondition.cpp b/Source/bindings/v8/V8NodeFilterCondition.cpp
index ec2621e..5911953 100644
--- a/Source/bindings/v8/V8NodeFilterCondition.cpp
+++ b/Source/bindings/v8/V8NodeFilterCondition.cpp
@@ -81,7 +81,7 @@
     args[0] = toV8(node, v8::Handle<v8::Object>(), state->isolate());
 
     v8::Handle<v8::Object> object = v8::Context::GetCurrent()->Global();
-    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, callback, object, 1, args.get());
+    v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, callback, object, 1, args.get(), isolate);
 
     if (exceptionCatcher.HasCaught()) {
         state->setException(exceptionCatcher.Exception());
diff --git a/Source/bindings/v8/V8PerContextData.cpp b/Source/bindings/v8/V8PerContextData.cpp
index 6846eaf..f3ab0b8 100644
--- a/Source/bindings/v8/V8PerContextData.cpp
+++ b/Source/bindings/v8/V8PerContextData.cpp
@@ -138,6 +138,14 @@
     return function;
 }
 
+v8::Local<v8::Object> V8PerContextData::prototypeForType(WrapperTypeInfo* type)
+{
+    v8::Local<v8::Object> constructor = constructorForType(type);
+    if (constructor.IsEmpty())
+        return v8::Local<v8::Object>();
+    return constructor->Get(v8String("prototype", m_isolate)).As<v8::Object>();
+}
+
 void V8PerContextData::addCustomElementBinding(CustomElementDefinition* definition, PassOwnPtr<CustomElementBinding> binding)
 {
     ASSERT(!m_customElementBindings->contains(definition));
@@ -190,7 +198,7 @@
 {
     if (!debugData(context)->IsUndefined())
         return false;
-    v8::HandleScope scope;
+    v8::HandleScope scope(context->GetIsolate());
     v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId);
     setDebugData(context, debugData);
     return true;
@@ -198,7 +206,7 @@
 
 int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context)
 {
-    v8::HandleScope scope;
+    v8::HandleScope scope(context->GetIsolate());
     v8::Handle<v8::Value> data = debugData(context);
 
     if (!data->IsString())
diff --git a/Source/bindings/v8/V8PerContextData.h b/Source/bindings/v8/V8PerContextData.h
index c342ac4..5a9fe75 100644
--- a/Source/bindings/v8/V8PerContextData.h
+++ b/Source/bindings/v8/V8PerContextData.h
@@ -94,6 +94,8 @@
         return constructorForTypeSlowCase(type);
     }
 
+    v8::Local<v8::Object> prototypeForType(WrapperTypeInfo*);
+
     V8NPObjectMap* v8NPObjectMap()
     {
         return &m_v8NPObjectMap;
diff --git a/Source/bindings/v8/V8ScriptRunner.cpp b/Source/bindings/v8/V8ScriptRunner.cpp
index cab312f..9412ae6 100644
--- a/Source/bindings/v8/V8ScriptRunner.cpp
+++ b/Source/bindings/v8/V8ScriptRunner.cpp
@@ -30,8 +30,8 @@
 #include "bindings/v8/V8GCController.h"
 #include "bindings/v8/V8RecursionScope.h"
 #include "core/dom/ScriptExecutionContext.h"
+#include "core/fetch/CachedMetadata.h"
 #include "core/fetch/ScriptResource.h"
-#include "core/loader/CachedMetadata.h"
 #include "core/platform/chromium/TraceEvent.h"
 
 namespace WebCore {
@@ -75,7 +75,7 @@
     return v8::Script::Compile(code, &origin, scriptData);
 }
 
-v8::Local<v8::Value> V8ScriptRunner::runCompiledScript(v8::Handle<v8::Script> script, ScriptExecutionContext* context)
+v8::Local<v8::Value> V8ScriptRunner::runCompiledScript(v8::Handle<v8::Script> script, ScriptExecutionContext* context, v8::Isolate* isolate)
 {
     TRACE_EVENT0("v8", "v8.run");
     TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution");
@@ -83,7 +83,7 @@
         return v8::Local<v8::Value>();
 
     if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth)
-        return handleMaxRecursionDepthExceeded();
+        return handleMaxRecursionDepthExceeded(isolate);
 
     if (handleOutOfMemory())
         return v8::Local<v8::Value>();
@@ -119,13 +119,13 @@
     return result;
 }
 
-v8::Local<v8::Value> V8ScriptRunner::callFunction(v8::Handle<v8::Function> function, ScriptExecutionContext* context, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[])
+v8::Local<v8::Value> V8ScriptRunner::callFunction(v8::Handle<v8::Function> function, ScriptExecutionContext* context, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[], v8::Isolate* isolate)
 {
     TRACE_EVENT0("v8", "v8.callFunction");
     TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "Execution");
 
     if (V8RecursionScope::recursionLevel() >= kMaxRecursionDepth)
-        return handleMaxRecursionDepthExceeded();
+        return handleMaxRecursionDepthExceeded(isolate);
 
     V8RecursionScope recursionScope(context);
     v8::Local<v8::Value> result = function->Call(receiver, argc, args);
diff --git a/Source/bindings/v8/V8ScriptRunner.h b/Source/bindings/v8/V8ScriptRunner.h
index 36b614e..8ceab0f 100644
--- a/Source/bindings/v8/V8ScriptRunner.h
+++ b/Source/bindings/v8/V8ScriptRunner.h
@@ -26,7 +26,7 @@
 #ifndef V8ScriptRunner_h
 #define V8ScriptRunner_h
 
-#include "core/loader/CrossOriginAccessControl.h"
+#include "core/fetch/CrossOriginAccessControl.h"
 #include "wtf/PassOwnPtr.h"
 #include "wtf/text/TextPosition.h"
 #include "wtf/text/WTFString.h"
@@ -43,10 +43,10 @@
     // a HandleScope and a ContextScope.
     static PassOwnPtr<v8::ScriptData> precompileScript(v8::Handle<v8::String>, ScriptResource*);
     static v8::Local<v8::Script> compileScript(v8::Handle<v8::String>, const String&, const TextPosition&, v8::ScriptData*, v8::Isolate*, AccessControlStatus = SharableCrossOrigin);
-    static v8::Local<v8::Value> runCompiledScript(v8::Handle<v8::Script>, ScriptExecutionContext*);
+    static v8::Local<v8::Value> runCompiledScript(v8::Handle<v8::Script>, ScriptExecutionContext*, v8::Isolate*);
     static v8::Local<v8::Value> compileAndRunInternalScript(v8::Handle<v8::String>, v8::Isolate*, const String& = String(), const TextPosition& = TextPosition(), v8::ScriptData* = 0);
     static v8::Local<v8::Value> callInternalFunction(v8::Handle<v8::Function>, v8::Handle<v8::Object>, int argc, v8::Handle<v8::Value> args[], v8::Isolate*);
-    static v8::Local<v8::Value> callFunction(v8::Handle<v8::Function>, ScriptExecutionContext*, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[]);
+    static v8::Local<v8::Value> callFunction(v8::Handle<v8::Function>, ScriptExecutionContext*, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[], v8::Isolate*);
     static v8::Local<v8::Value> callAsFunction(v8::Handle<v8::Object>, v8::Handle<v8::Object> receiver, int argc, v8::Handle<v8::Value> args[]);
     static v8::Local<v8::Value> callAsConstructor(v8::Handle<v8::Object>, int argc, v8::Handle<v8::Value> args[]);
     static v8::Local<v8::Object> instantiateObject(v8::Handle<v8::ObjectTemplate>);
diff --git a/Source/bindings/v8/V8StringResource.h b/Source/bindings/v8/V8StringResource.h
index 31f1781..816e987 100644
--- a/Source/bindings/v8/V8StringResource.h
+++ b/Source/bindings/v8/V8StringResource.h
@@ -181,8 +181,8 @@
     }
 
     bool prepare();
-    operator String() { return toString<String>(); }
-    operator AtomicString() { return toString<AtomicString>(); }
+    operator String() const { return toString<String>(); }
+    operator AtomicString() const { return toString<AtomicString>(); }
 
 private:
     bool prepareBase()
@@ -216,10 +216,10 @@
     }
 
     template <class StringType>
-    StringType toString()
+    StringType toString() const
     {
         if (LIKELY(!m_v8Object.IsEmpty()))
-            return v8StringToWebCoreString<StringType>(m_v8Object.As<v8::String>(), m_mode);
+            return v8StringToWebCoreString<StringType>(const_cast<v8::Handle<v8::Value>*>(&m_v8Object)->As<v8::String>(), m_mode);
 
         return StringType(m_string);
     }
diff --git a/Source/bindings/v8/V8ValueCache.cpp b/Source/bindings/v8/V8ValueCache.cpp
index 3915759..77b0cbc 100644
--- a/Source/bindings/v8/V8ValueCache.cpp
+++ b/Source/bindings/v8/V8ValueCache.cpp
@@ -94,7 +94,7 @@
     v8::Persistent<v8::String> wrapper(isolate, newString);
 
     stringImpl->ref();
-    wrapper.MarkIndependent(isolate);
+    wrapper.MarkIndependent();
     wrapper.MakeWeak(stringImpl, &makeWeakCallback);
     m_lastV8String = UnsafePersistent<v8::String>(wrapper);
     m_lastStringImpl = stringImpl;
@@ -111,7 +111,7 @@
     ASSERT(stringCache->m_stringCache.contains(stringImpl));
     stringCache->m_stringCache.remove(stringImpl);
     stringImpl->deref();
-    wrapper->Dispose(isolate);
+    wrapper->Dispose();
 }
 
 } // namespace WebCore
diff --git a/Source/bindings/v8/V8WorkerGlobalScopeEventListener.cpp b/Source/bindings/v8/V8WorkerGlobalScopeEventListener.cpp
index 5ac095d..f2fee0d 100644
--- a/Source/bindings/v8/V8WorkerGlobalScopeEventListener.cpp
+++ b/Source/bindings/v8/V8WorkerGlobalScopeEventListener.cpp
@@ -58,7 +58,8 @@
     // See issue 889829.
     RefPtr<V8AbstractEventListener> protect(this);
 
-    v8::HandleScope handleScope;
+    v8::Isolate* isolate = getIsolateFromScriptExecutionContext(context);
+    v8::HandleScope handleScope(isolate);
 
     WorkerScriptController* script = toWorkerGlobalScope(context)->script();
     if (!script)
@@ -72,7 +73,6 @@
     v8::Context::Scope scope(v8Context);
 
     // Get the V8 wrapper for the event object.
-    v8::Isolate* isolate = v8Context->GetIsolate();
     v8::Handle<v8::Value> jsEvent = toV8(event, v8::Handle<v8::Object>(), isolate);
 
     invokeEventHandler(context, event, v8::Local<v8::Value>::New(isolate, jsEvent));
@@ -97,8 +97,9 @@
         cookie = InspectorInstrumentation::willCallFunction(context, resourceName, lineNumber);
     }
 
+    v8::Isolate* isolate = getIsolateFromScriptExecutionContext(context);
     v8::Handle<v8::Value> parameters[1] = { jsEvent };
-    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction, context, receiver, WTF_ARRAY_LENGTH(parameters), parameters);
+    v8::Local<v8::Value> result = V8ScriptRunner::callFunction(handlerFunction, context, receiver, WTF_ARRAY_LENGTH(parameters), parameters, isolate);
 
     InspectorInstrumentation::didCallFunction(cookie);
 
diff --git a/Source/bindings/v8/WorkerScriptController.cpp b/Source/bindings/v8/WorkerScriptController.cpp
index cbbf758..d2d151a 100644
--- a/Source/bindings/v8/WorkerScriptController.cpp
+++ b/Source/bindings/v8/WorkerScriptController.cpp
@@ -154,7 +154,7 @@
 
     v8::Handle<v8::String> scriptString = v8String(script, m_isolate);
     v8::Handle<v8::Script> compiledScript = V8ScriptRunner::compileScript(scriptString, fileName, scriptStartPosition, 0, m_isolate);
-    v8::Local<v8::Value> result = V8ScriptRunner::runCompiledScript(compiledScript, m_workerGlobalScope);
+    v8::Local<v8::Value> result = V8ScriptRunner::runCompiledScript(compiledScript, m_workerGlobalScope, m_isolate);
 
     if (!block.CanContinue()) {
         m_workerGlobalScope->script()->forbidExecution();
@@ -189,11 +189,11 @@
     if (state.hadException) {
         if (errorEvent) {
             *errorEvent = m_workerGlobalScope->shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin) ?
-                ErrorEvent::createSanitizedError() : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber);
+                ErrorEvent::createSanitizedError(0) : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, 0);
             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);
+            RefPtr<ErrorEvent> event = m_errorEventFromImportedScript ? m_errorEventFromImportedScript.release() : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, 0);
             m_workerGlobalScope->reportException(event, 0, NotSharableCrossOrigin);
         }
     }
diff --git a/Source/bindings/v8/WorkerScriptController.h b/Source/bindings/v8/WorkerScriptController.h
index b7da9f2..407a111 100644
--- a/Source/bindings/v8/WorkerScriptController.h
+++ b/Source/bindings/v8/WorkerScriptController.h
@@ -94,13 +94,15 @@
         ScriptValue evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, WorkerGlobalScopeExecutionState*);
 
         // Returns a local handle of the context.
-        v8::Local<v8::Context> context() { return m_context.newLocal(v8::Isolate::GetCurrent()); }
+        v8::Local<v8::Context> context() { return m_context.newLocal(m_isolate); }
 
         // Send a notification about current thread is going to be idle.
         // Returns true if the embedder should stop calling idleNotification
         // until real work has been done.
         bool idleNotification() { return v8::V8::IdleNotification(); }
 
+        v8::Isolate* isolate() const { return m_isolate; }
+
     private:
         bool initializeContextIfNeeded();
         void disposeContext();
diff --git a/Source/bindings/v8/WrapperTypeInfo.h b/Source/bindings/v8/WrapperTypeInfo.h
index 324e006..d77850a 100644
--- a/Source/bindings/v8/WrapperTypeInfo.h
+++ b/Source/bindings/v8/WrapperTypeInfo.h
@@ -181,11 +181,11 @@
             Dependent, Independent
         };
 
-        void configureWrapper(v8::Persistent<v8::Object>* wrapper, v8::Isolate* isolate) const
+        void configureWrapper(v8::Persistent<v8::Object>* wrapper) const
         {
-            wrapper->SetWrapperClassId(isolate, classId);
+            wrapper->SetWrapperClassId(classId);
             if (lifetime == Independent)
-                wrapper->MarkIndependent(isolate);
+                wrapper->MarkIndependent();
         }
 
         const uint16_t classId;
diff --git a/Source/bindings/v8/custom/V8AudioContextCustom.cpp b/Source/bindings/v8/custom/V8AudioContextCustom.cpp
index 99c8174..fedc602 100644
--- a/Source/bindings/v8/custom/V8AudioContextCustom.cpp
+++ b/Source/bindings/v8/custom/V8AudioContextCustom.cpp
@@ -33,7 +33,6 @@
 #include "bindings/v8/V8Binding.h"
 #include "bindings/v8/custom/V8ArrayBufferCustom.h"
 #include "core/dom/Document.h"
-#include "core/page/Frame.h"
 #include "modules/webaudio/AudioBuffer.h"
 #include "modules/webaudio/AudioContext.h"
 #include "modules/webaudio/OfflineAudioContext.h"
diff --git a/Source/bindings/v8/custom/V8ClipboardCustom.cpp b/Source/bindings/v8/custom/V8ClipboardCustom.cpp
index a5055ea..899debc 100644
--- a/Source/bindings/v8/custom/V8ClipboardCustom.cpp
+++ b/Source/bindings/v8/custom/V8ClipboardCustom.cpp
@@ -76,7 +76,7 @@
         return;
     }
 
-    String type = toWebCoreString(args[0]);
+    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, args[0]);
     clipboard->clearData(type);
 }
 
diff --git a/Source/bindings/v8/custom/V8CustomEventCustom.cpp b/Source/bindings/v8/custom/V8CustomEventCustom.cpp
index 8e05aa1..e07a680 100644
--- a/Source/bindings/v8/custom/V8CustomEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8CustomEventCustom.cpp
@@ -39,7 +39,6 @@
 #include "bindings/v8/V8DOMWrapper.h"
 #include "bindings/v8/V8HiddenPropertyName.h"
 #include "core/dom/ContextFeatures.h"
-#include "core/page/Frame.h"
 #include "RuntimeEnabledFeatures.h"
 
 namespace WebCore {
diff --git a/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp b/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
index 78f8e99..d16b206 100644
--- a/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
+++ b/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
@@ -72,7 +72,7 @@
     // statement, if any, or onto the next overall step otherwise. Otherwise,
     // the error callback did not return false, or there was no error callback.
     // Jump to the last step in the overall steps.
-    return invokeCallback(m_callback.newLocal(isolate), 2, argv, callbackReturnValue, scriptExecutionContext()) || callbackReturnValue;
+    return invokeCallback(m_callback.newLocal(isolate), 2, argv, callbackReturnValue, scriptExecutionContext(), isolate) || callbackReturnValue;
 }
 
 } // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8CustomXPathNSResolver.cpp b/Source/bindings/v8/custom/V8CustomXPathNSResolver.cpp
index d4a47ad..5d8ff3e 100644
--- a/Source/bindings/v8/custom/V8CustomXPathNSResolver.cpp
+++ b/Source/bindings/v8/custom/V8CustomXPathNSResolver.cpp
@@ -85,7 +85,7 @@
     v8::Handle<v8::Value> argv[argc] = { v8String(prefix, m_isolate) };
     v8::Handle<v8::Function> function = lookupNamespaceURIFunc.IsEmpty() ? v8::Handle<v8::Function>::Cast(m_resolver) : lookupNamespaceURIFunc;
 
-    v8::Handle<v8::Value> retval = ScriptController::callFunctionWithInstrumentation(0, function, m_resolver, argc, argv);
+    v8::Handle<v8::Value> retval = ScriptController::callFunctionWithInstrumentation(0, function, m_resolver, argc, argv, m_isolate);
 
     // Eat exceptions from namespace resolver and return an empty string. This will most likely cause NamespaceError.
     if (tryCatch.HasCaught())
diff --git a/Source/bindings/v8/custom/V8DocumentLocationCustom.cpp b/Source/bindings/v8/custom/V8DocumentLocationCustom.cpp
index fd4bab7..a913ba0 100644
--- a/Source/bindings/v8/custom/V8DocumentLocationCustom.cpp
+++ b/Source/bindings/v8/custom/V8DocumentLocationCustom.cpp
@@ -27,7 +27,6 @@
 #include "V8Location.h"
 #include "bindings/v8/V8Binding.h"
 #include "core/page/DOMWindow.h"
-#include "core/page/Frame.h"
 #include "core/page/Location.h"
 
 namespace WebCore {
diff --git a/Source/bindings/v8/custom/V8ErrorEventCustom.cpp b/Source/bindings/v8/custom/V8ErrorEventCustom.cpp
index 86ca1fc..98374aa 100644
--- a/Source/bindings/v8/custom/V8ErrorEventCustom.cpp
+++ b/Source/bindings/v8/custom/V8ErrorEventCustom.cpp
@@ -41,7 +41,6 @@
 #include "bindings/v8/V8DOMWrapper.h"
 #include "bindings/v8/V8HiddenPropertyName.h"
 #include "core/dom/ContextFeatures.h"
-#include "core/page/Frame.h"
 
 namespace WebCore {
 
diff --git a/Source/bindings/v8/custom/V8GeolocationCustom.cpp b/Source/bindings/v8/custom/V8GeolocationCustom.cpp
index 901ebdc..74b8bbd 100644
--- a/Source/bindings/v8/custom/V8GeolocationCustom.cpp
+++ b/Source/bindings/v8/custom/V8GeolocationCustom.cpp
@@ -31,7 +31,6 @@
 #include "bindings/v8/V8Binding.h"
 #include "bindings/v8/V8Callback.h"
 #include "bindings/v8/V8Utilities.h"
-#include "core/page/Frame.h"
 #include "modules/geolocation/Geolocation.h"
 
 using namespace std;
diff --git a/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp b/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
index b38ea29..56f9f91 100644
--- a/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
+++ b/Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
@@ -94,10 +94,10 @@
     }
     if (result->is2d()) {
         v8::Handle<v8::Value> v8Result = toV8(static_cast<CanvasRenderingContext2D*>(result), args.Holder(), args.GetIsolate());
-        if (InspectorInstrumentation::canvasAgentEnabled(imp->document())) {
+        if (InspectorInstrumentation::canvasAgentEnabled(&imp->document())) {
             ScriptState* scriptState = ScriptState::forContext(v8::Context::GetCurrent());
             ScriptObject context(scriptState, v8::Handle<v8::Object>::Cast(v8Result));
-            ScriptObject wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(imp->document(), context);
+            ScriptObject wrapped = InspectorInstrumentation::wrapCanvas2DRenderingContextForInstrumentation(&imp->document(), context);
             if (!wrapped.hasNoValue()) {
                 v8SetReturnValue(args, wrapped.v8Value());
                 return;
@@ -108,10 +108,10 @@
     }
     if (result->is3d()) {
         v8::Handle<v8::Value> v8Result = toV8(static_cast<WebGLRenderingContext*>(result), args.Holder(), args.GetIsolate());
-        if (InspectorInstrumentation::canvasAgentEnabled(imp->document())) {
+        if (InspectorInstrumentation::canvasAgentEnabled(&imp->document())) {
             ScriptState* scriptState = ScriptState::forContext(v8::Context::GetCurrent());
             ScriptObject glContext(scriptState, v8::Handle<v8::Object>::Cast(v8Result));
-            ScriptObject wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(imp->document(), glContext);
+            ScriptObject wrapped = InspectorInstrumentation::wrapWebGLRenderingContextForInstrumentation(&imp->document(), glContext);
             if (!wrapped.hasNoValue()) {
                 v8SetReturnValue(args, wrapped.v8Value());
                 return;
diff --git a/Source/bindings/v8/custom/V8HTMLImageElementConstructor.cpp b/Source/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
index 6e0f42f..290b50c 100644
--- a/Source/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
+++ b/Source/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
@@ -39,7 +39,6 @@
 #include "bindings/v8/V8ObjectConstructor.h"
 #include "core/dom/Document.h"
 #include "core/html/HTMLImageElement.h"
-#include "core/page/Frame.h"
 #include "wtf/RefPtr.h"
 
 namespace WebCore {
@@ -59,6 +58,7 @@
     }
 
     Document* document = currentDocument();
+    ASSERT(document);
 
     // Make sure the document is added to the DOM Node map. Otherwise, the HTMLImageElement instance
     // may end up being the only node in the map and get garbage-collected prematurely.
@@ -80,7 +80,7 @@
         optionalHeight = &height;
     }
 
-    RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight);
+    RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(*document, optionalWidth, optionalHeight);
     v8::Handle<v8::Object> wrapper = args.Holder();
     V8DOMWrapper::associateObjectWithWrapper<V8HTMLImageElement>(image.release(), &V8HTMLImageElementConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     v8SetReturnValue(args, wrapper);
diff --git a/Source/bindings/v8/custom/V8IDBAnyCustom.cpp b/Source/bindings/v8/custom/V8IDBAnyCustom.cpp
index 35bdce5..da9a4e4 100644
--- a/Source/bindings/v8/custom/V8IDBAnyCustom.cpp
+++ b/Source/bindings/v8/custom/V8IDBAnyCustom.cpp
@@ -90,7 +90,7 @@
     case IDBAny::StringType:
         return v8String(impl->string(), isolate);
     case IDBAny::IntegerType:
-        return v8::Number::New(impl->integer());
+        return v8::Number::New(isolate, impl->integer());
     case IDBAny::KeyPathType:
         return toV8(impl->keyPath(), creationContext, isolate);
     }
diff --git a/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
index 73b8d63..202c586 100644
--- a/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
+++ b/Source/bindings/v8/custom/V8InjectedScriptHostCustom.cpp
@@ -71,13 +71,13 @@
 
 ScriptValue InjectedScriptHost::nodeAsScriptValue(ScriptState* state, Node* node)
 {
-    v8::HandleScope scope;
+    v8::HandleScope scope(state->isolate());
     v8::Local<v8::Context> context = state->context();
     v8::Context::Scope contextScope(context);
 
     if (!BindingSecurity::shouldAllowAccessToNode(node))
         return ScriptValue(v8::Null());
-    return ScriptValue(toV8(node, v8::Handle<v8::Object>(), context->GetIsolate()));
+    return ScriptValue(toV8(node, v8::Handle<v8::Object>(), state->isolate()));
 }
 
 void V8InjectedScriptHost::inspectedObjectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
@@ -256,7 +256,7 @@
         v8::Local<v8::Object> listenerEntry = v8::Object::New();
         listenerEntry->Set(v8::String::NewSymbol("listener"), function);
         listenerEntry->Set(v8::String::NewSymbol("useCapture"), v8::Boolean::New(listenerInfo.eventListenerVector[i].useCapture));
-        result->Set(v8::Number::New(outputIndex++), listenerEntry);
+        result->Set(v8::Number::New(v8Listener->isolate(), outputIndex++), listenerEntry);
     }
     return result;
 }
@@ -272,10 +272,6 @@
     Node* node = V8Node::toNative(value->ToObject());
     if (!node)
         return;
-    // This can only happen for orphan DocumentType nodes.
-    Document* document = node->document();
-    if (!node->document())
-        return;
 
     InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder());
     Vector<EventListenerInfo> listenersArray;
@@ -283,7 +279,7 @@
 
     v8::Local<v8::Object> result = v8::Object::New();
     for (size_t i = 0; i < listenersArray.size(); ++i) {
-        v8::Handle<v8::Array> listeners = getJSListenerFunctions(document, listenersArray[i]);
+        v8::Handle<v8::Array> listeners = getJSListenerFunctions(&node->document(), listenersArray[i]);
         if (!listeners->Length())
             continue;
         AtomicString eventType = listenersArray[i].eventType;
diff --git a/Source/bindings/v8/custom/V8InjectedScriptManager.cpp b/Source/bindings/v8/custom/V8InjectedScriptManager.cpp
index 199b84c..5b551da 100644
--- a/Source/bindings/v8/custom/V8InjectedScriptManager.cpp
+++ b/Source/bindings/v8/custom/V8InjectedScriptManager.cpp
@@ -68,10 +68,10 @@
 
 ScriptObject InjectedScriptManager::createInjectedScript(const String& scriptSource, ScriptState* inspectedScriptState, int id)
 {
-    v8::HandleScope handleScope;
+    v8::Isolate* isolate = inspectedScriptState->isolate();
+    v8::HandleScope handleScope(isolate);
 
     v8::Local<v8::Context> inspectedContext = inspectedScriptState->context();
-    v8::Isolate* isolate = inspectedContext->GetIsolate();
     v8::Context::Scope contextScope(inspectedContext);
 
     // Call custom code to create InjectedScripHost wrapper specific for the context
@@ -92,14 +92,14 @@
     ASSERT(value->IsFunction());
 
     v8::Local<v8::Object> windowGlobal = inspectedContext->Global();
-    v8::Handle<v8::Value> args[] = { scriptHostWrapper, windowGlobal, v8::Number::New(id) };
+    v8::Handle<v8::Value> args[] = { scriptHostWrapper, windowGlobal, v8::Number::New(inspectedContext->GetIsolate(), id) };
     v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(args), args, inspectedContext->GetIsolate());
     return ScriptObject(inspectedScriptState, v8::Handle<v8::Object>::Cast(injectedScriptValue));
 }
 
 bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState)
 {
-    v8::HandleScope handleScope;
+    v8::HandleScope handleScope(scriptState->isolate());
     v8::Local<v8::Context> context = scriptState->context();
     v8::Local<v8::Object> global = context->Global();
     if (global.IsEmpty())
@@ -118,7 +118,7 @@
 void InjectedScriptManager::makeWeakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* object, InjectedScriptHost* host)
 {
     host->deref();
-    object->Dispose(isolate);
+    object->Dispose();
 }
 
 } // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp b/Source/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp
index e4faefc..2f8d3e8 100644
--- a/Source/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp
+++ b/Source/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp
@@ -44,7 +44,7 @@
 
 void V8InspectorFrontendHost::platformMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
 {
-#if OS(DARWIN)
+#if OS(MACOSX)
     v8SetReturnValue(args, v8::String::NewSymbol("mac"));
 #elif OS(LINUX)
     v8SetReturnValue(args, v8::String::NewSymbol("linux"));
@@ -52,7 +52,7 @@
     v8SetReturnValue(args, v8::String::NewSymbol("freebsd"));
 #elif OS(OPENBSD)
     v8SetReturnValue(args, v8::String::NewSymbol("openbsd"));
-#elif OS(WINDOWS)
+#elif OS(WIN)
     v8SetReturnValue(args, v8::String::NewSymbol("windows"));
 #else
     v8SetReturnValue(args, v8::String::NewSymbol("unknown"));
diff --git a/Source/bindings/v8/custom/V8MIDIInputCustom.cpp b/Source/bindings/v8/custom/V8MIDIInputCustom.cpp
new file mode 100644
index 0000000..6ad179c
--- /dev/null
+++ b/Source/bindings/v8/custom/V8MIDIInputCustom.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "V8MIDIInput.h"
+
+#include "V8MIDIAccess.h"
+#include "bindings/v8/V8HiddenPropertyName.h"
+
+namespace WebCore {
+
+v8::Handle<v8::Object> wrap(MIDIInput* input, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+    ASSERT(input);
+    ASSERT(!DOMDataStore::containsWrapper<V8MIDIInput>(input, isolate));
+
+    v8::Handle<v8::Object> wrapper = V8MIDIInput::createWrapper(input, creationContext, isolate);
+
+    if (input->midiAccess())
+        V8HiddenPropertyName::setNamedHiddenReference(wrapper, "access", toV8(input->midiAccess(), creationContext, isolate));
+
+    return wrapper;
+}
+
+} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8MIDIOutputCustom.cpp b/Source/bindings/v8/custom/V8MIDIOutputCustom.cpp
new file mode 100644
index 0000000..fa3b69a
--- /dev/null
+++ b/Source/bindings/v8/custom/V8MIDIOutputCustom.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "V8MIDIOutput.h"
+
+#include "V8MIDIAccess.h"
+#include "bindings/v8/V8HiddenPropertyName.h"
+
+namespace WebCore {
+
+v8::Handle<v8::Object> wrap(MIDIOutput* output, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+    ASSERT(output);
+    ASSERT(!DOMDataStore::containsWrapper<V8MIDIOutput>(output, isolate));
+
+    v8::Handle<v8::Object> wrapper = V8MIDIOutput::createWrapper(output, creationContext, isolate);
+
+    if (output->midiAccess())
+        V8HiddenPropertyName::setNamedHiddenReference(wrapper, "access", toV8(output->midiAccess(), creationContext, isolate));
+
+    return wrapper;
+}
+
+} // namespace WebCore
diff --git a/Source/bindings/v8/custom/V8MessageChannelCustom.cpp b/Source/bindings/v8/custom/V8MessageChannelCustom.cpp
index 3d2364a..9697cc9 100644
--- a/Source/bindings/v8/custom/V8MessageChannelCustom.cpp
+++ b/Source/bindings/v8/custom/V8MessageChannelCustom.cpp
@@ -35,9 +35,7 @@
 #include "bindings/v8/V8Binding.h"
 #include "bindings/v8/V8HiddenPropertyName.h"
 #include "bindings/v8/V8Utilities.h"
-#include "core/dom/Document.h"
 #include "core/dom/MessageChannel.h"
-#include "core/page/Frame.h"
 #include "core/workers/WorkerGlobalScope.h"
 
 #include "wtf/RefPtr.h"
diff --git a/Source/bindings/v8/custom/V8NodeCustom.cpp b/Source/bindings/v8/custom/V8NodeCustom.cpp
index 0887a91..2b844b5 100644
--- a/Source/bindings/v8/custom/V8NodeCustom.cpp
+++ b/Source/bindings/v8/custom/V8NodeCustom.cpp
@@ -139,23 +139,24 @@
     case Node::TEXT_NODE:
         return wrap(toText(impl), creationContext, isolate);
     case Node::CDATA_SECTION_NODE:
-        return wrap(static_cast<CDATASection*>(impl), creationContext, isolate);
-    case Node::ENTITY_NODE:
-        return wrap(static_cast<Entity*>(impl), creationContext, isolate);
+        return wrap(toCDATASection(impl), creationContext, isolate);
     case Node::PROCESSING_INSTRUCTION_NODE:
-        return wrap(static_cast<ProcessingInstruction*>(impl), creationContext, isolate);
+        return wrap(toProcessingInstruction(impl), creationContext, isolate);
     case Node::COMMENT_NODE:
-        return wrap(static_cast<Comment*>(impl), creationContext, isolate);
+        return wrap(toComment(impl), creationContext, isolate);
     case Node::DOCUMENT_NODE:
         return wrap(toDocument(impl), creationContext, isolate);
     case Node::DOCUMENT_TYPE_NODE:
-        return wrap(static_cast<DocumentType*>(impl), creationContext, isolate);
+        return wrap(toDocumentType(impl), creationContext, isolate);
     case Node::DOCUMENT_FRAGMENT_NODE:
         if (impl->isShadowRoot())
             return wrap(toShadowRoot(impl), creationContext, isolate);
-        return wrap(static_cast<DocumentFragment*>(impl), creationContext, isolate);
+        return wrap(toDocumentFragment(impl), creationContext, isolate);
+    case Node::ENTITY_NODE:
     case Node::NOTATION_NODE:
-        return wrap(static_cast<Notation*>(impl), creationContext, isolate);
+        // We never create objects of Entity and Notation.
+        ASSERT_NOT_REACHED();
+        break;
     default:
         break; // ENTITY_REFERENCE_NODE or XPATH_NAMESPACE_NODE
     }
diff --git a/Source/bindings/v8/custom/V8PromiseCustom.cpp b/Source/bindings/v8/custom/V8PromiseCustom.cpp
index ed6f15c..650f647 100644
--- a/Source/bindings/v8/custom/V8PromiseCustom.cpp
+++ b/Source/bindings/v8/custom/V8PromiseCustom.cpp
@@ -131,12 +131,12 @@
     }
     ASSERT(state);
 
-    v8::HandleScope handleScope;
+    v8::Isolate* isolate = state->isolate();
+    v8::HandleScope handleScope(isolate);
     v8::Handle<v8::Context> v8Context = state->context();
     v8::Context::Scope scope(v8Context);
-    v8::Isolate* isolate = v8Context->GetIsolate();
     v8::Handle<v8::Value> args[] = { m_result.newLocal(isolate) };
-    V8ScriptRunner::callFunction(m_callback.newLocal(isolate), context, m_receiver.newLocal(isolate), WTF_ARRAY_LENGTH(args), args);
+    V8ScriptRunner::callFunction(m_callback.newLocal(isolate), context, m_receiver.newLocal(isolate), WTF_ARRAY_LENGTH(args), args, isolate);
 };
 
 v8::Handle<v8::Value> postTask(v8::Handle<v8::Function> callback, v8::Handle<v8::Object> receiver, v8::Handle<v8::Value> value, v8::Isolate* isolate)
@@ -164,7 +164,7 @@
         result,
     };
     v8::TryCatch trycatch;
-    result = V8ScriptRunner::callFunction(callback, getScriptExecutionContext(), promise, WTF_ARRAY_LENGTH(argv), argv);
+    result = V8ScriptRunner::callFunction(callback, getScriptExecutionContext(), promise, WTF_ARRAY_LENGTH(argv), argv, isolate);
     if (result.IsEmpty()) {
         V8PromiseCustom::rejectResolver(resolver, trycatch.Exception(), V8PromiseCustom::Synchronous, isolate);
         return;
@@ -304,7 +304,7 @@
         resolver,
     };
     v8::TryCatch trycatch;
-    if (V8ScriptRunner::callFunction(init, getScriptExecutionContext(), promise, WTF_ARRAY_LENGTH(argv), argv).IsEmpty()) {
+    if (V8ScriptRunner::callFunction(init, getScriptExecutionContext(), promise, WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) {
         // An exception is thrown. Reject the promise if its resolved flag is unset.
         if (!V8PromiseCustom::isInternalDetached(resolver) && V8PromiseCustom::getState(V8PromiseCustom::getInternal(resolver)) == V8PromiseCustom::Pending)
             V8PromiseCustom::rejectResolver(resolver, trycatch.Exception(), V8PromiseCustom::Asynchronous, isolate);
@@ -533,7 +533,7 @@
             createClosure(promiseResolveCallback, resolver),
             createClosure(promiseRejectCallback, resolver),
         };
-        if (V8ScriptRunner::callFunction(then.As<v8::Function>(), getScriptExecutionContext(), result.As<v8::Object>(), WTF_ARRAY_LENGTH(argv), argv).IsEmpty())
+        if (V8ScriptRunner::callFunction(then.As<v8::Function>(), getScriptExecutionContext(), result.As<v8::Object>(), WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty())
             rejectResolver(resolver, trycatch.Exception(), mode, isolate);
         return;
     }
@@ -637,7 +637,7 @@
         // If an exception is thrown, catch it and do nothing.
         v8::TryCatch trycatch;
         v8::Handle<v8::Value> args[] = { result };
-        V8ScriptRunner::callFunction(function, getScriptExecutionContext(), receiver, WTF_ARRAY_LENGTH(args), args);
+        V8ScriptRunner::callFunction(function, getScriptExecutionContext(), receiver, WTF_ARRAY_LENGTH(args), args, isolate);
     } else {
         ASSERT(mode == Asynchronous);
         postTask(function, receiver, result, isolate);
diff --git a/Source/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp b/Source/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp
index 01c452c..c56441e 100644
--- a/Source/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp
+++ b/Source/bindings/v8/custom/V8SQLResultSetRowListCustom.cpp
@@ -72,7 +72,7 @@
                 value = v8::Null(args.GetIsolate());
                 break;
             case SQLValue::NumberValue:
-                value = v8::Number::New(sqlValue.number());
+                value = v8::Number::New(args.GetIsolate(), sqlValue.number());
                 break;
             default:
                 ASSERT_NOT_REACHED();
diff --git a/Source/bindings/v8/custom/V8TextCustom.cpp b/Source/bindings/v8/custom/V8TextCustom.cpp
index bca6320..478537c 100644
--- a/Source/bindings/v8/custom/V8TextCustom.cpp
+++ b/Source/bindings/v8/custom/V8TextCustom.cpp
@@ -29,8 +29,9 @@
  */
 
 #include "config.h"
-#include "V8CDATASection.h"
 #include "V8Text.h"
+
+#include "V8CDATASection.h"
 #include "core/dom/Node.h"
 #include "core/dom/Text.h"
 
@@ -40,8 +41,7 @@
 {
     ASSERT(impl);
     if (impl->nodeType() == Node::CDATA_SECTION_NODE)
-      return wrap(static_cast<CDATASection*>(impl), creationContext, isolate);
-
+        return wrap(toCDATASection(impl), creationContext, isolate);
     return V8Text::createWrapper(impl, creationContext, isolate);
 }
 
diff --git a/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp b/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
index 510bdb9..3baa1ea 100644
--- a/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
+++ b/Source/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp
@@ -134,7 +134,7 @@
         return array;
     }
     case WebGLGetInfo::kTypeFloat:
-        return v8::Number::New(info.getFloat());
+        return v8::Number::New(isolate, info.getFloat());
     case WebGLGetInfo::kTypeInt:
         return v8::Integer::New(info.getInt(), isolate);
     case WebGLGetInfo::kTypeNull:
diff --git a/Source/bindings/v8/custom/V8WorkerCustom.cpp b/Source/bindings/v8/custom/V8WorkerCustom.cpp
index 74ec3f8..acbb730 100644
--- a/Source/bindings/v8/custom/V8WorkerCustom.cpp
+++ b/Source/bindings/v8/custom/V8WorkerCustom.cpp
@@ -35,7 +35,6 @@
 #include "bindings/v8/SerializedScriptValue.h"
 #include "bindings/v8/V8Binding.h"
 #include "bindings/v8/V8Utilities.h"
-#include "core/page/Frame.h"
 #include "core/workers/Worker.h"
 #include "core/workers/WorkerGlobalScope.h"
 #include "wtf/ArrayBuffer.h"
diff --git a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
index f28fa19..eb0f4a1 100644
--- a/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
+++ b/Source/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
@@ -35,14 +35,15 @@
 #include "V8Document.h"
 #include "V8FormData.h"
 #include "V8HTMLDocument.h"
+#include "V8Stream.h"
 #include "bindings/v8/ExceptionState.h"
 #include "bindings/v8/V8Binding.h"
 #include "bindings/v8/V8Utilities.h"
 #include "bindings/v8/custom/V8ArrayBufferCustom.h"
 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h"
 #include "core/dom/Document.h"
+#include "core/fileapi/Stream.h"
 #include "core/inspector/InspectorInstrumentation.h"
-#include "core/page/Frame.h"
 #include "core/workers/WorkerGlobalScope.h"
 #include "core/xml/XMLHttpRequest.h"
 #include "wtf/ArrayBuffer.h"
@@ -136,6 +137,13 @@
             return;
         }
 
+    case XMLHttpRequest::ResponseTypeStream:
+        {
+            Stream* stream = xmlHttpRequest->responseStream();
+            v8SetReturnValueFast(info, stream, xmlHttpRequest);
+            return;
+        }
+
     case XMLHttpRequest::ResponseTypeArrayBuffer:
         {
             ArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer();