[V8] Remove getToStringName() and getToStringTemplate() from V8Binding
authorharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2012 00:32:46 +0000 (00:32 +0000)
committerharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2012 00:32:46 +0000 (00:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94573

Reviewed by Adam Barth.

- Remove V8Binding::getToStringName() and V8Binding::getToStringTemplate().

- Replace getToStringName() with String::NewSymbol("toString").

- Fix V8PerIsolateData::getToStringTemplate() so that it caches a persistent
handle of a created FunctionTemplate. Before this patch, a FunctionTemplate
had been created for each toString().

No tests. No change in behavior.

* bindings/v8/V8Binding.cpp:
(WebCore::constructorToString):
* bindings/v8/V8Binding.h:
(WebCore):
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateImplementation):
* bindings/scripts/test/V8/V8Float64Array.cpp:
(WebCore::ConfigureV8Float64ArrayTemplate):
* bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
(WebCore::ConfigureV8TestActiveDOMObjectTemplate):
* bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp:
(WebCore::ConfigureV8TestCustomNamedGetterTemplate):
* bindings/scripts/test/V8/V8TestEventConstructor.cpp:
(WebCore::ConfigureV8TestEventConstructorTemplate):
* bindings/scripts/test/V8/V8TestEventTarget.cpp:
(WebCore::ConfigureV8TestEventTargetTemplate):
* bindings/scripts/test/V8/V8TestException.cpp:
(WebCore::ConfigureV8TestExceptionTemplate):
* bindings/scripts/test/V8/V8TestInterface.cpp:
(WebCore::ConfigureV8TestInterfaceTemplate):
* bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp:
(WebCore::ConfigureV8TestMediaQueryListListenerTemplate):
* bindings/scripts/test/V8/V8TestNamedConstructor.cpp:
(WebCore::ConfigureV8TestNamedConstructorTemplate):
* bindings/scripts/test/V8/V8TestNode.cpp:
(WebCore::ConfigureV8TestNodeTemplate):
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::ConfigureV8TestObjTemplate):
* bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
(WebCore::ConfigureV8TestSerializedScriptValueInterfaceTemplate):
* bindings/v8/V8PerIsolateData.h:
(V8PerIsolateData):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126237 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/V8/V8Float64Array.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestActiveDOMObject.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestEventConstructor.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestEventTarget.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestException.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestNamedConstructor.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestNode.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/v8/V8Binding.cpp
Source/WebCore/bindings/v8/V8Binding.h
Source/WebCore/bindings/v8/V8PerIsolateData.cpp
Source/WebCore/bindings/v8/V8PerIsolateData.h

index fce3590..afd3421 100644 (file)
@@ -1,3 +1,53 @@
+2012-08-20  Kentaro Hara  <haraken@chromium.org>
+
+        [V8] Remove getToStringName() and getToStringTemplate() from V8Binding
+        https://bugs.webkit.org/show_bug.cgi?id=94573
+
+        Reviewed by Adam Barth.
+
+        - Remove V8Binding::getToStringName() and V8Binding::getToStringTemplate().
+
+        - Replace getToStringName() with String::NewSymbol("toString").
+
+        - Fix V8PerIsolateData::getToStringTemplate() so that it caches a persistent
+        handle of a created FunctionTemplate. Before this patch, a FunctionTemplate
+        had been created for each toString().
+
+        No tests. No change in behavior.
+
+        * bindings/v8/V8Binding.cpp:
+        (WebCore::constructorToString):
+        * bindings/v8/V8Binding.h:
+        (WebCore):
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateImplementation):
+        * bindings/scripts/test/V8/V8Float64Array.cpp:
+        (WebCore::ConfigureV8Float64ArrayTemplate):
+        * bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
+        (WebCore::ConfigureV8TestActiveDOMObjectTemplate):
+        * bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp:
+        (WebCore::ConfigureV8TestCustomNamedGetterTemplate):
+        * bindings/scripts/test/V8/V8TestEventConstructor.cpp:
+        (WebCore::ConfigureV8TestEventConstructorTemplate):
+        * bindings/scripts/test/V8/V8TestEventTarget.cpp:
+        (WebCore::ConfigureV8TestEventTargetTemplate):
+        * bindings/scripts/test/V8/V8TestException.cpp:
+        (WebCore::ConfigureV8TestExceptionTemplate):
+        * bindings/scripts/test/V8/V8TestInterface.cpp:
+        (WebCore::ConfigureV8TestInterfaceTemplate):
+        * bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp:
+        (WebCore::ConfigureV8TestMediaQueryListListenerTemplate):
+        * bindings/scripts/test/V8/V8TestNamedConstructor.cpp:
+        (WebCore::ConfigureV8TestNamedConstructorTemplate):
+        * bindings/scripts/test/V8/V8TestNode.cpp:
+        (WebCore::ConfigureV8TestNodeTemplate):
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::ConfigureV8TestObjTemplate):
+        * bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
+        (WebCore::ConfigureV8TestSerializedScriptValueInterfaceTemplate):
+        * bindings/v8/V8PerIsolateData.h:
+        (V8PerIsolateData):
+
 2012-08-21  Arvid Nilsson  <anilsson@rim.com>
 
         [BlackBerry] WebGL Aquarium fails to render
index 2c170e2..300a365 100644 (file)
@@ -2961,7 +2961,7 @@ END
     push(@implContent, <<END);
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 534a8de..d033908 100644 (file)
@@ -110,7 +110,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8Float64ArrayTemplate(v8::
     proto->Set(v8::String::NewSymbol("foo"), v8::FunctionTemplate::New(Float64ArrayV8Internal::fooCallback, v8Undefined(), fooSignature));
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 86b1fd2..653eb1e 100644 (file)
@@ -140,7 +140,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestActiveDOMObjectTempla
     proto->SetAccessor(v8::String::NewSymbol("postMessage"), TestActiveDOMObjectV8Internal::postMessageAttrGetter, TestActiveDOMObjectV8Internal::TestActiveDOMObjectDomainSafeFunctionSetter, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 888cae8..0f9e64a 100644 (file)
@@ -73,7 +73,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestCustomNamedGetterTemp
     desc->InstanceTemplate()->SetNamedPropertyHandler(V8TestCustomNamedGetter::namedPropertyGetter, 0, 0, 0, 0);
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 2376913..32e13aa 100644 (file)
@@ -110,7 +110,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestEventConstructorTempl
     
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index cd2076c..427f1d5 100644 (file)
@@ -134,7 +134,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestEventTargetTemplate(v
     proto->Set(v8::String::NewSymbol("dispatchEvent"), v8::FunctionTemplate::New(TestEventTargetV8Internal::dispatchEventCallback, v8Undefined(), dispatchEventSignature));
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 9bb99ac..99eb522 100644 (file)
@@ -64,7 +64,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestExceptionTemplate(v8:
     
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index aaacc81..96cfd7a 100644 (file)
@@ -303,7 +303,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestInterfaceTemplate(v8:
     V8DOMConfiguration::batchConfigureConstants(desc, proto, TestInterfaceConsts, WTF_ARRAY_LENGTH(TestInterfaceConsts));
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 4d3d95b..2ede10b 100644 (file)
@@ -73,7 +73,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestMediaQueryListListene
     
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 78bd8d5..2989280 100644 (file)
@@ -114,7 +114,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestNamedConstructorTempl
     
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 7b380a0..c2a109f 100644 (file)
@@ -73,7 +73,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestNodeTemplate(v8::Pers
     
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index edce97e..a8b18c8 100644 (file)
@@ -2254,7 +2254,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestObjTemplate(v8::Persi
     V8DOMConfiguration::batchConfigureConstants(desc, proto, TestObjConsts, WTF_ARRAY_LENGTH(TestObjConsts));
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index 71f0a37..0f7b87b 100644 (file)
@@ -256,7 +256,7 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestSerializedScriptValue
     
 
     // Custom toString template
-    desc->Set(getToStringName(), getToStringTemplate());
+    desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
     return desc;
 }
 
index e4c966a..3525095 100644 (file)
@@ -325,39 +325,6 @@ v8::Persistent<v8::FunctionTemplate> createRawTemplate()
     return v8::Persistent<v8::FunctionTemplate>::New(result);
 }        
 
-v8::Persistent<v8::String> getToStringName()
-{
-    v8::Persistent<v8::String>& toStringName = V8PerIsolateData::current()->toStringName();
-    if (toStringName.IsEmpty())
-        toStringName = v8::Persistent<v8::String>::New(v8::String::New("toString"));
-    return *toStringName;
-
-}
-
-static v8::Handle<v8::Value> constructorToString(const v8::Arguments& args)
-{
-    // The DOM constructors' toString functions grab the current toString
-    // for Functions by taking the toString function of itself and then
-    // calling it with the constructor as its receiver. This means that
-    // changes to the Function prototype chain or toString function are
-    // reflected when printing DOM constructors. The only wart is that
-    // changes to a DOM constructor's toString's toString will cause the
-    // toString of the DOM constructor itself to change. This is extremely
-    // obscure and unlikely to be a problem.
-    v8::Handle<v8::Value> value = args.Callee()->Get(getToStringName());
-    if (!value->IsFunction()) 
-        return v8::String::New("");
-    return v8::Handle<v8::Function>::Cast(value)->Call(args.This(), 0, 0);
-}
-
-v8::Persistent<v8::FunctionTemplate> getToStringTemplate()
-{
-    v8::Persistent<v8::FunctionTemplate>& toStringTemplate = V8PerIsolateData::current()->toStringTemplate();
-    if (toStringTemplate.IsEmpty())
-        toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(constructorToString));
-    return toStringTemplate;
-}
-
 void StringCache::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
     MemoryClassInfo info(memoryObjectInfo, this, MemoryInstrumentation::Binding);
index 6742c0e..23a0ba1 100644 (file)
@@ -354,9 +354,6 @@ namespace WebCore {
 
     v8::Persistent<v8::FunctionTemplate> createRawTemplate();
 
-    v8::Persistent<v8::String> getToStringName();
-    v8::Persistent<v8::FunctionTemplate> getToStringTemplate();
-
     String int32ToWebCoreString(int value);
 
     PassRefPtr<DOMStringList> toDOMStringList(v8::Handle<v8::Value>);
index 16e4b0e..183c312 100644 (file)
@@ -106,4 +106,20 @@ void V8PerIsolateData::visitExternalStrings(ExternalStringVisitor* visitor)
 }
 #endif
 
+v8::Handle<v8::Value> V8PerIsolateData::constructorOfToString(const v8::Arguments& args)
+{
+    // The DOM constructors' toString functions grab the current toString
+    // for Functions by taking the toString function of itself and then
+    // calling it with the constructor as its receiver. This means that
+    // changes to the Function prototype chain or toString function are
+    // reflected when printing DOM constructors. The only wart is that
+    // changes to a DOM constructor's toString's toString will cause the
+    // toString of the DOM constructor itself to change. This is extremely
+    // obscure and unlikely to be a problem.
+    v8::Handle<v8::Value> value = args.Callee()->Get(v8::String::NewSymbol("toString"));
+    if (!value->IsFunction()) 
+        return v8::String::New("");
+    return v8::Handle<v8::Function>::Cast(value)->Call(args.This(), 0, 0);
+}
+
 } // namespace WebCore
index 72da77e..ceb2ee8 100644 (file)
@@ -69,8 +69,13 @@ public:
 
     TemplateMap& rawTemplateMap() { return m_rawTemplates; }
     TemplateMap& templateMap() { return m_templates; }
-    v8::Persistent<v8::String>& toStringName() { return m_toStringName; }
-    v8::Persistent<v8::FunctionTemplate>& toStringTemplate() { return m_toStringTemplate; }
+
+    v8::Persistent<v8::FunctionTemplate>& toStringTemplate()
+    {
+        if (m_toStringTemplate.IsEmpty())
+            m_toStringTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(constructorOfToString));
+        return m_toStringTemplate;
+    }
 
     v8::Persistent<v8::FunctionTemplate>& lazyEventListenerToStringTemplate()
     {
@@ -130,10 +135,10 @@ public:
 private:
     explicit V8PerIsolateData(v8::Isolate*);
     ~V8PerIsolateData();
+    static v8::Handle<v8::Value> constructorOfToString(const v8::Arguments&);
 
     TemplateMap m_rawTemplates;
     TemplateMap m_templates;
-    v8::Persistent<v8::String> m_toStringName;
     v8::Persistent<v8::FunctionTemplate> m_toStringTemplate;
     v8::Persistent<v8::FunctionTemplate> m_lazyEventListenerToStringTemplate;
     OwnPtr<StringCache> m_stringCache;