Title: [126484] trunk/Source/WebCore
Revision
126484
Author
[email protected]
Date
2012-08-23 14:45:42 -0700 (Thu, 23 Aug 2012)

Log Message

[V8] OwnHandle is a bit of a misnomer
https://bugs.webkit.org/show_bug.cgi?id=94841

Reviewed by Eric Seidel.

You don't really own the handle in the same way that you own a pointer
with OwnPtr. This class is more correctly called ScopedPersistent
because it just forces you to balance New() and Dispose() calls.

* WebCore.gypi:
* bindings/v8/_javascript_CallFrame.h:
(_javascript_CallFrame):
* bindings/v8/OwnHandle.h: Removed.
* bindings/v8/ScheduledAction.h:
(ScheduledAction):
* bindings/v8/ScopedPersistent.h: Copied from Source/WebCore/bindings/v8/OwnHandle.h.
(ScopedPersistent):
(WebCore::ScopedPersistent::ScopedPersistent):
(WebCore::ScopedPersistent::~ScopedPersistent):
* bindings/v8/ScriptDebugServer.cpp:
(WebCore::ScriptDebugServer::compileScript):
(WebCore::ScriptDebugServer::runScript):
* bindings/v8/ScriptDebugServer.h:
(ScriptDebugServer):
* bindings/v8/ScriptInstance.h:
(V8ScriptInstance):
* bindings/v8/V8PerContextData.h:
(V8PerContextData):

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126483 => 126484)


--- trunk/Source/WebCore/ChangeLog	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/ChangeLog	2012-08-23 21:45:42 UTC (rev 126484)
@@ -1,3 +1,34 @@
+2012-08-23  Adam Barth  <[email protected]>
+
+        [V8] OwnHandle is a bit of a misnomer
+        https://bugs.webkit.org/show_bug.cgi?id=94841
+
+        Reviewed by Eric Seidel.
+
+        You don't really own the handle in the same way that you own a pointer
+        with OwnPtr. This class is more correctly called ScopedPersistent
+        because it just forces you to balance New() and Dispose() calls.
+
+        * WebCore.gypi:
+        * bindings/v8/_javascript_CallFrame.h:
+        (_javascript_CallFrame):
+        * bindings/v8/OwnHandle.h: Removed.
+        * bindings/v8/ScheduledAction.h:
+        (ScheduledAction):
+        * bindings/v8/ScopedPersistent.h: Copied from Source/WebCore/bindings/v8/OwnHandle.h.
+        (ScopedPersistent):
+        (WebCore::ScopedPersistent::ScopedPersistent):
+        (WebCore::ScopedPersistent::~ScopedPersistent):
+        * bindings/v8/ScriptDebugServer.cpp:
+        (WebCore::ScriptDebugServer::compileScript):
+        (WebCore::ScriptDebugServer::runScript):
+        * bindings/v8/ScriptDebugServer.h:
+        (ScriptDebugServer):
+        * bindings/v8/ScriptInstance.h:
+        (V8ScriptInstance):
+        * bindings/v8/V8PerContextData.h:
+        (V8PerContextData):
+
 2012-08-23  Nate Chapin  <[email protected]>
 
         ProgressTracker never completes if iframe detached during parsing 

Modified: trunk/Source/WebCore/WebCore.gypi (126483 => 126484)


--- trunk/Source/WebCore/WebCore.gypi	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/WebCore.gypi	2012-08-23 21:45:42 UTC (rev 126484)
@@ -2205,7 +2205,6 @@
             'bindings/v8/NPV8Object.h',
             'bindings/v8/Dictionary.cpp',
             'bindings/v8/Dictionary.h',
-            'bindings/v8/OwnHandle.h',
             'bindings/v8/PageScriptDebugServer.cpp',
             'bindings/v8/PageScriptDebugServer.h',
             'bindings/v8/RetainedDOMInfo.cpp',
@@ -2215,6 +2214,7 @@
             'bindings/v8/ScheduledAction.h',
             'bindings/v8/ScopedDOMDataStore.cpp',
             'bindings/v8/ScopedDOMDataStore.h',
+            'bindings/v8/ScopedPersistent.h',
             'bindings/v8/ScriptCachedFrameData.cpp',
             'bindings/v8/ScriptCachedFrameData.h',
             'bindings/v8/ScriptCallStackFactory.cpp',

Modified: trunk/Source/WebCore/bindings/v8/_javascript_CallFrame.h (126483 => 126484)


--- trunk/Source/WebCore/bindings/v8/_javascript_CallFrame.h	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/bindings/v8/_javascript_CallFrame.h	2012-08-23 21:45:42 UTC (rev 126484)
@@ -33,8 +33,8 @@
 
 #if ENABLE(_javascript__DEBUGGER)
 
-#include "OwnHandle.h"
 #include "PlatformString.h"
+#include "ScopedPersistent.h"
 #include <v8-debug.h>
 #include <wtf/RefCounted.h>
 
@@ -66,8 +66,8 @@
     _javascript_CallFrame(v8::Handle<v8::Context> debuggerContext, v8::Handle<v8::Object> callFrame);
 
     RefPtr<_javascript_CallFrame> m_caller;
-    OwnHandle<v8::Context> m_debuggerContext;
-    OwnHandle<v8::Object> m_callFrame;
+    ScopedPersistent<v8::Context> m_debuggerContext;
+    ScopedPersistent<v8::Object> m_callFrame;
 };
 
 } // namespace WebCore

Deleted: trunk/Source/WebCore/bindings/v8/OwnHandle.h (126483 => 126484)


--- trunk/Source/WebCore/bindings/v8/OwnHandle.h	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/bindings/v8/OwnHandle.h	2012-08-23 21:45:42 UTC (rev 126484)
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2009 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 OwnHandle_h
-#define OwnHandle_h
-
-#include <v8.h>
-#include <wtf/Noncopyable.h>
-
-namespace WebCore {
-
-template<typename T>
-class OwnHandle {
-    WTF_MAKE_NONCOPYABLE(OwnHandle);
-public:
-    OwnHandle() { }
-
-    explicit OwnHandle(v8::Handle<T> handle)
-        : m_handle(v8::Persistent<T>::New(handle))
-    {
-    }
-
-    ~OwnHandle()
-    {
-        clear();
-    }
-
-    v8::Persistent<T> get() const { return m_handle; }
-
-    void set(v8::Handle<T> handle)
-    {
-        clear();
-        m_handle = v8::Persistent<T>::New(handle);
-    }
-
-    // Note: This is clear in the OwnPtr sense, not the v8::Handle sense.
-    void clear()
-    {
-        if (m_handle.IsEmpty())
-            return;
-        m_handle.Dispose();
-        m_handle.Clear();
-    }
-
-private:
-    v8::Persistent<T> m_handle;
-};
-
-} // namespace WebCore
-
-#endif // OwnHandle_h

Modified: trunk/Source/WebCore/bindings/v8/ScheduledAction.h (126483 => 126484)


--- trunk/Source/WebCore/bindings/v8/ScheduledAction.h	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/bindings/v8/ScheduledAction.h	2012-08-23 21:45:42 UTC (rev 126484)
@@ -31,7 +31,7 @@
 #ifndef ScheduledAction_h
 #define ScheduledAction_h
 
-#include "OwnHandle.h"
+#include "ScopedPersistent.h"
 #include "ScriptSourceCode.h"
 #include <v8.h>
 #include <wtf/Forward.h>
@@ -62,8 +62,8 @@
     void execute(WorkerContext*);
 #endif
 
-    OwnHandle<v8::Context> m_context;
-    OwnHandle<v8::Function> m_function;
+    ScopedPersistent<v8::Context> m_context;
+    ScopedPersistent<v8::Function> m_function;
     Vector<v8::Persistent<v8::Value> > m_args;
     ScriptSourceCode m_code;
 };

Copied: trunk/Source/WebCore/bindings/v8/ScopedPersistent.h (from rev 126473, trunk/Source/WebCore/bindings/v8/OwnHandle.h) (0 => 126484)


--- trunk/Source/WebCore/bindings/v8/ScopedPersistent.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/ScopedPersistent.h	2012-08-23 21:45:42 UTC (rev 126484)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2009 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 ScopedPersistent_h
+#define ScopedPersistent_h
+
+#include <v8.h>
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+template<typename T>
+class ScopedPersistent {
+    WTF_MAKE_NONCOPYABLE(ScopedPersistent);
+public:
+    ScopedPersistent() { }
+
+    explicit ScopedPersistent(v8::Handle<T> handle)
+        : m_handle(v8::Persistent<T>::New(handle))
+    {
+    }
+
+    ~ScopedPersistent()
+    {
+        clear();
+    }
+
+    v8::Persistent<T> get() const { return m_handle; }
+
+    void set(v8::Handle<T> handle)
+    {
+        clear();
+        m_handle = v8::Persistent<T>::New(handle);
+    }
+
+    // Note: This is clear in the OwnPtr sense, not the v8::Handle sense.
+    void clear()
+    {
+        if (m_handle.IsEmpty())
+            return;
+        m_handle.Dispose();
+        m_handle.Clear();
+    }
+
+private:
+    v8::Persistent<T> m_handle;
+};
+
+} // namespace WebCore
+
+#endif // ScopedPersistent_h

Modified: trunk/Source/WebCore/bindings/v8/ScriptDebugServer.cpp (126483 => 126484)


--- trunk/Source/WebCore/bindings/v8/ScriptDebugServer.cpp	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/bindings/v8/ScriptDebugServer.cpp	2012-08-23 21:45:42 UTC (rev 126484)
@@ -441,7 +441,7 @@
         return;
 
     *scriptId = toWebCoreStringWithNullOrUndefinedCheck(script->Id());
-    m_compiledScripts.set(*scriptId, adoptPtr(new OwnHandle<v8::Script>(script)));
+    m_compiledScripts.set(*scriptId, adoptPtr(new ScopedPersistent<v8::Script>(script)));
 }
 
 void ScriptDebugServer::clearCompiledScripts()
@@ -454,8 +454,8 @@
     if (!m_compiledScripts.contains(scriptId))
         return;
     v8::HandleScope handleScope;
-    OwnHandle<v8::Script>* scriptOwnHandle = m_compiledScripts.get(scriptId);
-    v8::Local<v8::Script> script = v8::Local<v8::Script>::New(scriptOwnHandle->get());
+    ScopedPersistent<v8::Script>* scriptHandle = m_compiledScripts.get(scriptId);
+    v8::Local<v8::Script> script = v8::Local<v8::Script>::New(scriptHandle->get());
     m_compiledScripts.remove(scriptId);
     if (script.IsEmpty())
         return;

Modified: trunk/Source/WebCore/bindings/v8/ScriptDebugServer.h (126483 => 126484)


--- trunk/Source/WebCore/bindings/v8/ScriptDebugServer.h	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/bindings/v8/ScriptDebugServer.h	2012-08-23 21:45:42 UTC (rev 126484)
@@ -33,8 +33,8 @@
 
 #if ENABLE(_javascript__DEBUGGER)
 
-#include "OwnHandle.h"
 #include "PlatformString.h"
+#include "ScopedPersistent.h"
 #include "ScriptBreakpoint.h"
 #include "Timer.h"
 #include <v8-debug.h>
@@ -125,13 +125,13 @@
     v8::Local<v8::Value> callDebuggerMethod(const char* functionName, int argc, v8::Handle<v8::Value> argv[]);
 
     PauseOnExceptionsState m_pauseOnExceptionsState;
-    OwnHandle<v8::Object> m_debuggerScript;
-    OwnHandle<v8::Object> m_executionState;
+    ScopedPersistent<v8::Object> m_debuggerScript;
+    ScopedPersistent<v8::Object> m_executionState;
     v8::Local<v8::Context> m_pausedContext;
 
     bool m_breakpointsActivated;
-    OwnHandle<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
-    HashMap<String, OwnPtr<OwnHandle<v8::Script> > > m_compiledScripts;
+    ScopedPersistent<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
+    HashMap<String, OwnPtr<ScopedPersistent<v8::Script> > > m_compiledScripts;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/ScriptInstance.h (126483 => 126484)


--- trunk/Source/WebCore/bindings/v8/ScriptInstance.h	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/bindings/v8/ScriptInstance.h	2012-08-23 21:45:42 UTC (rev 126484)
@@ -31,7 +31,7 @@
 #ifndef ScriptInstance_h
 #define ScriptInstance_h
 
-#include "OwnHandle.h"
+#include "ScopedPersistent.h"
 #include <v8.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -48,7 +48,7 @@
 private:
     explicit V8ScriptInstance(v8::Handle<v8::Object>);
 
-    OwnHandle<v8::Object> m_instance;
+    ScopedPersistent<v8::Object> m_instance;
 };
 
 typedef RefPtr<V8ScriptInstance> ScriptInstance;

Modified: trunk/Source/WebCore/bindings/v8/V8PerContextData.h (126483 => 126484)


--- trunk/Source/WebCore/bindings/v8/V8PerContextData.h	2012-08-23 21:26:07 UTC (rev 126483)
+++ trunk/Source/WebCore/bindings/v8/V8PerContextData.h	2012-08-23 21:45:42 UTC (rev 126484)
@@ -31,7 +31,7 @@
 #ifndef V8PerContextData_h
 #define V8PerContextData_h
 
-#include "OwnHandle.h"
+#include "ScopedPersistent.h"
 #include "WrapperTypeInfo.h"
 #include <v8.h>
 #include <wtf/HashMap.h>
@@ -90,8 +90,8 @@
     ConstructorMap m_constructorMap;
 
     v8::Handle<v8::Context> m_context;
-    OwnHandle<v8::Value> m_errorPrototype;
-    OwnHandle<v8::Value> m_objectPrototype;
+    ScopedPersistent<v8::Value> m_errorPrototype;
+    ScopedPersistent<v8::Value> m_objectPrototype;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to