Title: [126500] trunk/Source/WebCore
Revision
126500
Author
[email protected]
Date
2012-08-23 16:21:25 -0700 (Thu, 23 Aug 2012)

Log Message

[V8] ScriptValue should use ScopedPresistent rather than calling New/Dispose directly
https://bugs.webkit.org/show_bug.cgi?id=94864

Reviewed by Eric Seidel.

ScriptValue was created before ScopedPersistent existed and therefore
calls New/Dispose manually. Instead, it should use the less error-prone
approach of having ScopedPersistent balance those calls.

* bindings/v8/ScriptValue.cpp:
(WebCore::ScriptValue::serialize):
(WebCore::ScriptValue::getString):
(WebCore::ScriptValue::toString):
(WebCore::ScriptValue::toInspectorValue):
* bindings/v8/ScriptValue.h:
(WebCore::ScriptValue::ScriptValue):
(WebCore::ScriptValue::operator=):
(WebCore::ScriptValue::operator==):
(WebCore::ScriptValue::isEqual):
(WebCore::ScriptValue::isFunction):
(WebCore::ScriptValue::isNull):
(WebCore::ScriptValue::isUndefined):
(WebCore::ScriptValue::isObject):
(WebCore::ScriptValue::hasNoValue):
(WebCore::ScriptValue::clear):
(WebCore::ScriptValue::v8Value):
(ScriptValue):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126499 => 126500)


--- trunk/Source/WebCore/ChangeLog	2012-08-23 23:17:35 UTC (rev 126499)
+++ trunk/Source/WebCore/ChangeLog	2012-08-23 23:21:25 UTC (rev 126500)
@@ -1,3 +1,33 @@
+2012-08-23  Adam Barth  <[email protected]>
+
+        [V8] ScriptValue should use ScopedPresistent rather than calling New/Dispose directly
+        https://bugs.webkit.org/show_bug.cgi?id=94864
+
+        Reviewed by Eric Seidel.
+
+        ScriptValue was created before ScopedPersistent existed and therefore
+        calls New/Dispose manually. Instead, it should use the less error-prone
+        approach of having ScopedPersistent balance those calls.
+
+        * bindings/v8/ScriptValue.cpp:
+        (WebCore::ScriptValue::serialize):
+        (WebCore::ScriptValue::getString):
+        (WebCore::ScriptValue::toString):
+        (WebCore::ScriptValue::toInspectorValue):
+        * bindings/v8/ScriptValue.h:
+        (WebCore::ScriptValue::ScriptValue):
+        (WebCore::ScriptValue::operator=):
+        (WebCore::ScriptValue::operator==):
+        (WebCore::ScriptValue::isEqual):
+        (WebCore::ScriptValue::isFunction):
+        (WebCore::ScriptValue::isNull):
+        (WebCore::ScriptValue::isUndefined):
+        (WebCore::ScriptValue::isObject):
+        (WebCore::ScriptValue::hasNoValue):
+        (WebCore::ScriptValue::clear):
+        (WebCore::ScriptValue::v8Value):
+        (ScriptValue):
+
 2012-08-22  James Robinson  <[email protected]>
 
         [chromium] Remove WebLayer::setChildren API

Modified: trunk/Source/WebCore/bindings/v8/ScriptValue.cpp (126499 => 126500)


--- trunk/Source/WebCore/bindings/v8/ScriptValue.cpp	2012-08-23 23:17:35 UTC (rev 126499)
+++ trunk/Source/WebCore/bindings/v8/ScriptValue.cpp	2012-08-23 23:21:25 UTC (rev 126500)
@@ -40,14 +40,17 @@
 
 namespace WebCore {
 
+ScriptValue::~ScriptValue()
+{
+}
+
 PassRefPtr<SerializedScriptValue> ScriptValue::serialize(ScriptState* scriptState)
 {
     ScriptScope scope(scriptState);
     return SerializedScriptValue::create(v8Value());
 }
 
-PassRefPtr<SerializedScriptValue> ScriptValue::serialize(ScriptState* scriptState,
-                                                         MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow)
+PassRefPtr<SerializedScriptValue> ScriptValue::serialize(ScriptState* scriptState, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow)
 {
     ScriptScope scope(scriptState);
     return SerializedScriptValue::create(v8Value(), messagePorts, arrayBuffers, didThrow);
@@ -61,24 +64,23 @@
 
 bool ScriptValue::getString(String& result) const
 {
-    if (m_value.IsEmpty())
+    if (m_value.get().IsEmpty())
         return false;
 
-    if (!m_value->IsString())
+    if (!m_value.get()->IsString())
         return false;
 
-    result = toWebCoreString(m_value);
+    result = toWebCoreString(m_value.get());
     return true;
 }
 
 String ScriptValue::toString(ScriptState*) const
 {
     v8::TryCatch block;
-    v8::Handle<v8::String> s = m_value->ToString();
-    // Handle the case where an exception is thrown as part of invoking toString on the object.
+    v8::Handle<v8::String> string = m_value.get()->ToString();
     if (block.HasCaught())
         return String();
-    return v8StringToWebCoreString<String>(s, DoNotExternalize);
+    return v8StringToWebCoreString<String>(string, DoNotExternalize);
 }
 
 #if ENABLE(INSPECTOR)
@@ -140,7 +142,7 @@
     v8::HandleScope handleScope;
     // v8::Object::GetPropertyNames() expects current context to be not null.
     v8::Context::Scope contextScope(scriptState->context());
-    return v8ToInspectorValue(m_value, InspectorValue::maxDepth);
+    return v8ToInspectorValue(m_value.get(), InspectorValue::maxDepth);
 }
 #endif
 

Modified: trunk/Source/WebCore/bindings/v8/ScriptValue.h (126499 => 126500)


--- trunk/Source/WebCore/bindings/v8/ScriptValue.h	2012-08-23 23:17:35 UTC (rev 126499)
+++ trunk/Source/WebCore/bindings/v8/ScriptValue.h	2012-08-23 23:21:25 UTC (rev 126500)
@@ -31,18 +31,14 @@
 #ifndef ScriptValue_h
 #define ScriptValue_h
 
-#include "PlatformString.h"
+#include "ScopedPersistent.h"
 #include "ScriptState.h"
-
 #include <v8.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
 
-#ifndef NDEBUG
-#include "V8GCController.h"
-#endif
-
 namespace WTF {
 class ArrayBuffer;
 }
@@ -57,28 +53,21 @@
 
 class ScriptValue {
 public:
-    ScriptValue() {}
+    ScriptValue() { }
+    virtual ~ScriptValue();
 
     ScriptValue(v8::Handle<v8::Value> value) 
     {
         if (value.IsEmpty())
             return;
-
-        m_value = v8::Persistent<v8::Value>::New(value);
-#ifndef NDEBUG
-        V8GCController::registerGlobalHandle(SCRIPTVALUE, this, m_value);
-#endif
+        m_value.set(value);
     }
 
     ScriptValue(const ScriptValue& value) 
     {
-        if (value.m_value.IsEmpty())
+        if (value.hasNoValue())
             return;
-
-        m_value = v8::Persistent<v8::Value>::New(value.m_value);
-#ifndef NDEBUG
-        V8GCController::registerGlobalHandle(SCRIPTVALUE, this, m_value);
-#endif
+        m_value.set(value.m_value.get());
     }
 
     ScriptValue& operator=(const ScriptValue& value) 
@@ -86,32 +75,28 @@
         if (this == &value) 
             return *this;
 
-        clear();
+        m_value.clear();
 
-        if (value.m_value.IsEmpty())
+        if (value.hasNoValue())
             return *this;
 
-        m_value = v8::Persistent<v8::Value>::New(value.m_value);
-#ifndef NDEBUG
-        V8GCController::registerGlobalHandle(SCRIPTVALUE, this, m_value);
-#endif
-
+        m_value.set(value.m_value.get());
         return *this;
     }
 
     bool operator==(const ScriptValue& value) const
     {
-        return m_value == value.m_value;
+        return m_value.get() == value.m_value.get();
     }
 
     bool isEqual(ScriptState*, const ScriptValue& value) const
     {
-        return m_value == value.m_value;
+        return m_value.get() == value.m_value.get();
     }
 
     bool isFunction() const
     {
-        return m_value->IsFunction();
+        return m_value.get()->IsFunction();
     }
 
     bool operator!=(const ScriptValue& value) const
@@ -121,22 +106,22 @@
 
     bool isNull() const
     {
-        return m_value->IsNull();
+        return m_value.get()->IsNull();
     }
 
     bool isUndefined() const
     {
-        return m_value->IsUndefined();
+        return m_value.get()->IsUndefined();
     }
 
     bool isObject() const
     {
-        return m_value->IsObject();
+        return m_value.get()->IsObject();
     }
 
     bool hasNoValue() const
     {
-        return m_value.IsEmpty();
+        return m_value.get().IsEmpty();
     }
 
     PassRefPtr<SerializedScriptValue> serialize(ScriptState*);
@@ -145,22 +130,11 @@
 
     void clear()
     {
-        if (m_value.IsEmpty())
-            return;
-
-#ifndef NDEBUG
-        V8GCController::unregisterGlobalHandle(this, m_value);
-#endif
-        m_value.Dispose();
-        m_value.Clear();
+        m_value.clear();
     }
 
-    virtual ~ScriptValue() 
-    {
-        clear();
-    }
+    v8::Handle<v8::Value> v8Value() const { return m_value.get(); }
 
-    v8::Handle<v8::Value> v8Value() const { return m_value; }
     bool getString(ScriptState*, String& result) const { return getString(result); }
     bool getString(String& result) const;
     String toString(ScriptState*) const;
@@ -168,7 +142,7 @@
     PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const;
 
 private:
-    mutable v8::Persistent<v8::Value> m_value;
+    ScopedPersistent<v8::Value> m_value;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to