Title: [126564] trunk/Source/WebCore
Revision
126564
Author
[email protected]
Date
2012-08-24 02:27:16 -0700 (Fri, 24 Aug 2012)

Log Message

[V8] Improve the developer ergonomics of ScopedPersistent
https://bugs.webkit.org/show_bug.cgi?id=94901

Reviewed by Kentaro Hara.

As requested by haraken, this patch adds some helper functions to
ScopedPersistent so that we don't need to call get() all the time.

* bindings/v8/ScheduledAction.cpp:
(WebCore::ScheduledAction::execute):
* bindings/v8/ScopedPersistent.h:
(WebCore::ScopedPersistent::get):
(WebCore::ScopedPersistent::operator->):
(ScopedPersistent):
(WebCore::ScopedPersistent::isEmpty):
* bindings/v8/ScriptValue.cpp:
(WebCore::ScriptValue::getString):
(WebCore::ScriptValue::toString):
* bindings/v8/ScriptValue.h:
(WebCore::ScriptValue::isFunction):
(WebCore::ScriptValue::isNull):
(WebCore::ScriptValue::isUndefined):
(WebCore::ScriptValue::isObject):
(WebCore::ScriptValue::hasNoValue):
* bindings/v8/V8AbstractEventListener.cpp:
(WebCore::V8AbstractEventListener::~V8AbstractEventListener):
(WebCore::V8AbstractEventListener::getReceiverObject):
* bindings/v8/V8AbstractEventListener.h:
(WebCore::V8AbstractEventListener::hasExistingListenerObject):
* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::isContextInitialized):
(WebCore::V8DOMWindowShell::disposeContextHandles):
(WebCore::V8DOMWindowShell::clearForClose):
(WebCore::V8DOMWindowShell::clearForNavigation):
(WebCore::V8DOMWindowShell::initContextIfNeeded):
(WebCore::V8DOMWindowShell::updateDocumentWrapper):
(WebCore::V8DOMWindowShell::updateDocumentWrapperCache):
(WebCore::V8DOMWindowShell::clearDocumentWrapperCache):
(WebCore::V8DOMWindowShell::setSecurityToken):
(WebCore::V8DOMWindowShell::updateDocument):
(WebCore::V8DOMWindowShell::namedItemAdded):
(WebCore::V8DOMWindowShell::namedItemRemoved):
(WebCore::V8DOMWindowShell::updateSecurityOrigin):
* bindings/v8/V8PerContextData.cpp:
(WebCore::V8PerContextData::createWrapperFromCacheSlowCase):
(WebCore::V8PerContextData::constructorForTypeSlowCase):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126563 => 126564)


--- trunk/Source/WebCore/ChangeLog	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/ChangeLog	2012-08-24 09:27:16 UTC (rev 126564)
@@ -1,3 +1,52 @@
+2012-08-24  Adam Barth  <[email protected]>
+
+        [V8] Improve the developer ergonomics of ScopedPersistent
+        https://bugs.webkit.org/show_bug.cgi?id=94901
+
+        Reviewed by Kentaro Hara.
+
+        As requested by haraken, this patch adds some helper functions to
+        ScopedPersistent so that we don't need to call get() all the time.
+
+        * bindings/v8/ScheduledAction.cpp:
+        (WebCore::ScheduledAction::execute):
+        * bindings/v8/ScopedPersistent.h:
+        (WebCore::ScopedPersistent::get):
+        (WebCore::ScopedPersistent::operator->):
+        (ScopedPersistent):
+        (WebCore::ScopedPersistent::isEmpty):
+        * bindings/v8/ScriptValue.cpp:
+        (WebCore::ScriptValue::getString):
+        (WebCore::ScriptValue::toString):
+        * bindings/v8/ScriptValue.h:
+        (WebCore::ScriptValue::isFunction):
+        (WebCore::ScriptValue::isNull):
+        (WebCore::ScriptValue::isUndefined):
+        (WebCore::ScriptValue::isObject):
+        (WebCore::ScriptValue::hasNoValue):
+        * bindings/v8/V8AbstractEventListener.cpp:
+        (WebCore::V8AbstractEventListener::~V8AbstractEventListener):
+        (WebCore::V8AbstractEventListener::getReceiverObject):
+        * bindings/v8/V8AbstractEventListener.h:
+        (WebCore::V8AbstractEventListener::hasExistingListenerObject):
+        * bindings/v8/V8DOMWindowShell.cpp:
+        (WebCore::V8DOMWindowShell::isContextInitialized):
+        (WebCore::V8DOMWindowShell::disposeContextHandles):
+        (WebCore::V8DOMWindowShell::clearForClose):
+        (WebCore::V8DOMWindowShell::clearForNavigation):
+        (WebCore::V8DOMWindowShell::initContextIfNeeded):
+        (WebCore::V8DOMWindowShell::updateDocumentWrapper):
+        (WebCore::V8DOMWindowShell::updateDocumentWrapperCache):
+        (WebCore::V8DOMWindowShell::clearDocumentWrapperCache):
+        (WebCore::V8DOMWindowShell::setSecurityToken):
+        (WebCore::V8DOMWindowShell::updateDocument):
+        (WebCore::V8DOMWindowShell::namedItemAdded):
+        (WebCore::V8DOMWindowShell::namedItemRemoved):
+        (WebCore::V8DOMWindowShell::updateSecurityOrigin):
+        * bindings/v8/V8PerContextData.cpp:
+        (WebCore::V8PerContextData::createWrapperFromCacheSlowCase):
+        (WebCore::V8PerContextData::constructorForTypeSlowCase):
+
 2012-08-23  Pavel Feldman  <[email protected]>
 
         Web Inspector: move ResourceViews to "components" module - it is used from the Resources as well.

Modified: trunk/Source/WebCore/bindings/v8/ScheduledAction.cpp (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/ScheduledAction.cpp	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/ScheduledAction.cpp	2012-08-24 09:27:16 UTC (rev 126564)
@@ -96,9 +96,8 @@
     TRACE_EVENT0("v8", "ScheduledAction::execute");
 #endif
 
-    v8::Handle<v8::Function> function = m_function.get();
-    if (!function.IsEmpty())
-        frame->script()->callFunction(function, context->Global(), m_args.size(), m_args.data());
+    if (!m_function.isEmpty())
+        frame->script()->callFunction(m_function.get(), context->Global(), m_args.size(), m_args.data());
     else
         frame->script()->compileAndRunScript(m_code);
 
@@ -112,15 +111,14 @@
 
     V8RecursionScope recursionScope(worker);
 
-    v8::Handle<v8::Function> function = m_function.get();
-    if (!function.IsEmpty()) {
+    if (!m_function.isEmpty()) {
         v8::HandleScope handleScope;
 
         v8::Handle<v8::Context> context = v8::Local<v8::Context>::New(m_context.get());
         ASSERT(!context.IsEmpty());
         v8::Context::Scope scope(context);
 
-        function->Call(context->Global(), m_args.size(), m_args.data());
+        m_function->Call(context->Global(), m_args.size(), m_args.data());
     } else
         worker->script()->evaluate(m_code);
 }

Modified: trunk/Source/WebCore/bindings/v8/ScopedPersistent.h (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/ScopedPersistent.h	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/ScopedPersistent.h	2012-08-24 09:27:16 UTC (rev 126564)
@@ -52,8 +52,11 @@
         clear();
     }
 
-    v8::Persistent<T> get() const { return m_handle; }
+    ALWAYS_INLINE v8::Persistent<T> get() const { return m_handle; }
+    ALWAYS_INLINE v8::Persistent<T> operator->() const { return m_handle; }
 
+    bool isEmpty() const { return m_handle.IsEmpty(); }
+
     void set(v8::Handle<T> handle)
     {
         clear();

Modified: trunk/Source/WebCore/bindings/v8/ScriptValue.cpp (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/ScriptValue.cpp	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/ScriptValue.cpp	2012-08-24 09:27:16 UTC (rev 126564)
@@ -64,10 +64,10 @@
 
 bool ScriptValue::getString(String& result) const
 {
-    if (m_value.get().IsEmpty())
+    if (m_value.isEmpty())
         return false;
 
-    if (!m_value.get()->IsString())
+    if (!m_value->IsString())
         return false;
 
     result = toWebCoreString(m_value.get());
@@ -77,7 +77,7 @@
 String ScriptValue::toString(ScriptState*) const
 {
     v8::TryCatch block;
-    v8::Handle<v8::String> string = m_value.get()->ToString();
+    v8::Handle<v8::String> string = m_value->ToString();
     if (block.HasCaught())
         return String();
     return v8StringToWebCoreString<String>(string, DoNotExternalize);

Modified: trunk/Source/WebCore/bindings/v8/ScriptValue.h (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/ScriptValue.h	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/ScriptValue.h	2012-08-24 09:27:16 UTC (rev 126564)
@@ -100,7 +100,7 @@
 
     bool isFunction() const
     {
-        return m_value.get()->IsFunction();
+        return m_value->IsFunction();
     }
 
     bool operator!=(const ScriptValue& value) const
@@ -110,22 +110,22 @@
 
     bool isNull() const
     {
-        return m_value.get()->IsNull();
+        return m_value->IsNull();
     }
 
     bool isUndefined() const
     {
-        return m_value.get()->IsUndefined();
+        return m_value->IsUndefined();
     }
 
     bool isObject() const
     {
-        return m_value.get()->IsObject();
+        return m_value->IsObject();
     }
 
     bool hasNoValue() const
     {
-        return m_value.get().IsEmpty();
+        return m_value.isEmpty();
     }
 
     PassRefPtr<SerializedScriptValue> serialize(ScriptState*);

Modified: trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.cpp (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.cpp	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.cpp	2012-08-24 09:27:16 UTC (rev 126564)
@@ -65,7 +65,7 @@
 
 V8AbstractEventListener::~V8AbstractEventListener()
 {
-    if (!m_listener.get().IsEmpty()) {
+    if (!m_listener.isEmpty()) {
         v8::HandleScope scope;
         V8EventListenerList::clearWrapper(v8::Local<v8::Object>::New(m_listener.get()), m_isAttribute);
     }
@@ -184,7 +184,7 @@
 
 v8::Local<v8::Object> V8AbstractEventListener::getReceiverObject(Event* event)
 {
-    if (!m_listener.get().IsEmpty() && !m_listener.get()->IsFunction())
+    if (!m_listener.isEmpty() && !m_listener->IsFunction())
         return v8::Local<v8::Object>::New(m_listener.get());
 
     EventTarget* target = event->currentTarget();

Modified: trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.h (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.h	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/V8AbstractEventListener.h	2012-08-24 09:27:16 UTC (rev 126564)
@@ -95,7 +95,7 @@
 
         bool hasExistingListenerObject()
         {
-            return !m_listener.get().IsEmpty();
+            return !m_listener.isEmpty();
         }
 
         const WorldContextHandle& worldContext() const { return m_worldContext; }

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-08-24 09:27:16 UTC (rev 126564)
@@ -198,13 +198,13 @@
 {
     // m_context, m_global, and m_wrapperBoilerplates should
     // all be non-empty if if m_context is non-empty.
-    ASSERT(m_context.get().IsEmpty() || !m_global.get().IsEmpty());
-    return !m_context.get().IsEmpty();
+    ASSERT(m_context.isEmpty() || !m_global.isEmpty());
+    return !m_context.isEmpty();
 }
 
 void V8DOMWindowShell::disposeContextHandles()
 {
-    if (!m_context.get().IsEmpty()) {
+    if (!m_context.isEmpty()) {
         m_frame->loader()->client()->willReleaseScriptContext(m_context.get(), 0);
         m_context.clear();
 
@@ -225,7 +225,7 @@
 
 void V8DOMWindowShell::clearForClose()
 {
-    if (m_context.get().IsEmpty())
+    if (m_context.isEmpty())
         return;
 
     v8::HandleScope handleScope;
@@ -235,7 +235,7 @@
 
 void V8DOMWindowShell::clearForNavigation()
 {
-    if (m_context.get().IsEmpty())
+    if (m_context.isEmpty())
         return;
 
     v8::HandleScope handleScope;
@@ -252,7 +252,7 @@
     v8::Handle<v8::Object> windowWrapper = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), m_global.get());
     ASSERT(!windowWrapper.IsEmpty());
     windowWrapper->TurnOnAccessCheck();
-    m_context.get()->DetachGlobal();
+    m_context->DetachGlobal();
     disposeContextHandles();
 }
 
@@ -293,7 +293,7 @@
 // it won't be able to reach the outer window via its global object.
 bool V8DOMWindowShell::initContextIfNeeded()
 {
-    if (!m_context.get().IsEmpty())
+    if (!m_context.isEmpty())
         return true;
 
     v8::HandleScope handleScope;
@@ -301,15 +301,15 @@
     initializeV8IfNeeded();
 
     m_context.adopt(createNewContext(m_global.get(), 0, 0));
-    if (m_context.get().IsEmpty())
+    if (m_context.isEmpty())
         return false;
 
     v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_context.get());
     v8::Context::Scope contextScope(context);
 
-    if (m_global.get().IsEmpty()) {
+    if (m_global.isEmpty()) {
         m_global.set(context->Global());
-        if (m_global.get().IsEmpty()) {
+        if (m_global.isEmpty()) {
             disposeContextHandles();
             return false;
         }
@@ -415,7 +415,7 @@
 {
     clearDocumentWrapper();
 
-    ASSERT(m_document.get().IsEmpty());
+    ASSERT(m_document.isEmpty());
     m_document.set(wrapper);
 }
 
@@ -450,8 +450,8 @@
     }
 
     v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document());
-    ASSERT(documentWrapper == m_document.get() || m_document.get().IsEmpty());
-    if (m_document.get().IsEmpty())
+    ASSERT(documentWrapper == m_document.get() || m_document.isEmpty());
+    if (m_document.isEmpty())
         updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper));
     checkDocumentWrapper(m_document.get(), m_frame->document());
 
@@ -462,19 +462,19 @@
         return;
     }
     ASSERT(documentWrapper->IsObject());
-    m_context.get()->Global()->ForceSet(v8::String::New("document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
+    m_context->Global()->ForceSet(v8::String::New("document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
 
     // We also stash a reference to the document on the real global object so that
     // DOMWindow objects we obtain from _javascript_ references are guaranteed to have
     // live Document objects.
-    v8::Handle<v8::Object> v8RealGlobal = v8::Handle<v8::Object>::Cast(m_context.get()->Global()->GetPrototype());
+    v8::Handle<v8::Object> v8RealGlobal = v8::Handle<v8::Object>::Cast(m_context->Global()->GetPrototype());
     v8RealGlobal->SetHiddenValue(V8HiddenPropertyName::document(), documentWrapper);
 }
 
 void V8DOMWindowShell::clearDocumentWrapperCache()
 {
-    ASSERT(!m_context.get().IsEmpty());
-    m_context.get()->Global()->ForceDelete(v8::String::New("document"));
+    ASSERT(!m_context.isEmpty());
+    m_context->Global()->ForceDelete(v8::String::New("document"));
 }
 
 void V8DOMWindowShell::setSecurityToken()
@@ -483,7 +483,7 @@
 
     // FIXME: This shouldn't be possible anymore.
     if (!document) {
-        m_context.get()->UseDefaultSecurityToken();
+        m_context->UseDefaultSecurityToken();
         return;
     }
 
@@ -503,14 +503,14 @@
     // case, we use the global object as the security token to avoid
     // calling canAccess when a script accesses its own objects.
     if (token.isEmpty() || token == "null") {
-        m_context.get()->UseDefaultSecurityToken();
+        m_context->UseDefaultSecurityToken();
         return;
     }
 
     CString utf8Token = token.utf8();
     // NOTE: V8 does identity comparison in fast path, must use a symbol
     // as the security token.
-    m_context.get()->SetSecurityToken(v8::String::NewSymbol(utf8Token.data(), utf8Token.length()));
+    m_context->SetSecurityToken(v8::String::NewSymbol(utf8Token.data(), utf8Token.length()));
 }
 
 void V8DOMWindowShell::updateDocument()
@@ -519,7 +519,7 @@
     if (!m_frame->document())
         return;
 
-    if (m_global.get().IsEmpty())
+    if (m_global.isEmpty())
         return;
 
     // There is an existing _javascript_ wrapper for the global object
@@ -559,9 +559,9 @@
     v8::HandleScope handleScope;
     v8::Context::Scope contextScope(m_context.get());
 
-    ASSERT(!m_document.get().IsEmpty());
+    ASSERT(!m_document.isEmpty());
     checkDocumentWrapper(m_document.get(), document);
-    m_document.get()->SetAccessor(v8String(name), getter);
+    m_document->SetAccessor(v8String(name), getter);
 }
 
 void V8DOMWindowShell::namedItemRemoved(HTMLDocument* document, const AtomicString& name)
@@ -575,14 +575,14 @@
     v8::HandleScope handleScope;
     v8::Context::Scope contextScope(m_context.get());
 
-    ASSERT(!m_document.get().IsEmpty());
+    ASSERT(!m_document.isEmpty());
     checkDocumentWrapper(m_document.get(), document);
-    m_document.get()->Delete(v8String(name));
+    m_document->Delete(v8String(name));
 }
 
 void V8DOMWindowShell::updateSecurityOrigin()
 {
-    if (m_context.get().IsEmpty())
+    if (m_context.isEmpty())
         return;
     v8::HandleScope handleScope;
     setSecurityToken();

Modified: trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp (126563 => 126564)


--- trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp	2012-08-24 09:23:31 UTC (rev 126563)
+++ trunk/Source/WebCore/bindings/v8/V8PerContextData.cpp	2012-08-24 09:27:16 UTC (rev 126564)
@@ -87,8 +87,8 @@
 
 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(WrapperTypeInfo* type)
 {
-    ASSERT(!m_errorPrototype.get().IsEmpty());
-    ASSERT(!m_objectPrototype.get().IsEmpty());
+    ASSERT(!m_errorPrototype.isEmpty());
+    ASSERT(!m_objectPrototype.isEmpty());
 
     v8::Context::Scope scope(m_context);
     v8::Local<v8::Function> function = constructorForType(type);
@@ -102,8 +102,8 @@
 
 v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(WrapperTypeInfo* type)
 {
-    ASSERT(!m_errorPrototype.get().IsEmpty());
-    ASSERT(!m_objectPrototype.get().IsEmpty());
+    ASSERT(!m_errorPrototype.isEmpty());
+    ASSERT(!m_objectPrototype.isEmpty());
 
     v8::Context::Scope scope(m_context);
     v8::Handle<v8::FunctionTemplate> functionTemplate = type->getTemplate();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to