diff options
author | fqian@google.com <fqian@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-03 21:06:11 +0000 |
---|---|---|
committer | fqian@google.com <fqian@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-03 21:06:11 +0000 |
commit | b59e5ba90f12b2de9761f68ccbbb4ff73016918c (patch) | |
tree | b9b16c9b2f22ec59811d40705946d696ce8e0884 /webkit | |
parent | 278e4686693dd331b5b9f409ebcc3491cf3a4402 (diff) | |
download | chromium_src-b59e5ba90f12b2de9761f68ccbbb4ff73016918c.zip chromium_src-b59e5ba90f12b2de9761f68ccbbb4ff73016918c.tar.gz chromium_src-b59e5ba90f12b2de9761f68ccbbb4ff73016918c.tar.bz2 |
Some cleanup of ScriptValue.
Review URL: http://codereview.chromium.org/13102
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6310 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/port/bindings/v8/ScriptValue.h | 43 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.h | 3 |
2 files changed, 38 insertions, 8 deletions
diff --git a/webkit/port/bindings/v8/ScriptValue.h b/webkit/port/bindings/v8/ScriptValue.h index 664858f..4695d0e 100644 --- a/webkit/port/bindings/v8/ScriptValue.h +++ b/webkit/port/bindings/v8/ScriptValue.h @@ -34,6 +34,10 @@ #include "v8.h" +#ifndef NDEBUG +#include "v8_proxy.h" // for register and unregister global handles. +#endif + namespace WebCore { class String; @@ -44,12 +48,22 @@ public: ScriptValue(v8::Handle<v8::Value> value) { - m_value = v8::Persistent<v8::Value>::New(value); + if (!value.IsEmpty()) { + m_value = v8::Persistent<v8::Value>::New(value); +#ifndef NDEBUG + V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); +#endif + } } ScriptValue(const ScriptValue& value) { - m_value = v8::Persistent<v8::Value>::New(value.m_value); + if (!value.m_value.IsEmpty()) { + m_value = v8::Persistent<v8::Value>::New(value.m_value); +#ifndef NDEBUG + V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); +#endif + } } ScriptValue& operator=(const ScriptValue& value) @@ -57,15 +71,30 @@ public: if (this == &value) return *this; - m_value.Dispose(); - m_value = v8::Persistent<v8::Value>::New(value.m_value); + clear(); + if (!value.m_value.IsEmpty()) { + m_value = v8::Persistent<v8::Value>::New(value.m_value); +#ifndef NDEBUG + V8Proxy::RegisterGlobalHandle(SCRIPTVALUE, this, m_value); +#endif + } + return *this; } + void clear() { + if (!m_value.IsEmpty()) { +#ifndef NDEBUG + V8Proxy::UnregisterGlobalHandle(this, m_value); +#endif + m_value.Dispose(); + m_value.Clear(); + } + } + ~ScriptValue() - { - m_value.Dispose(); - m_value.Clear(); + { + clear(); } bool getString(String& result) const; diff --git a/webkit/port/bindings/v8/v8_proxy.h b/webkit/port/bindings/v8/v8_proxy.h index eef19c0..724222f 100644 --- a/webkit/port/bindings/v8/v8_proxy.h +++ b/webkit/port/bindings/v8/v8_proxy.h @@ -86,7 +86,8 @@ void log_info(Frame* frame, const String& msg, const String& url); V(SCHEDULED_ACTION) \ V(EVENT_LISTENER) \ V(NODE_FILTER) \ - V(JSINSTANCE) \ + V(SCRIPTVALUE) \ + V(JSINSTANCE) // Host information of persistent handles. |