Changeset 145494 in webkit


Ignore:
Timestamp:
Mar 12, 2013 12:52:32 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[V8] Get rid of function-level static FunctionTemplates in generated bindings code
https://bugs.webkit.org/show_bug.cgi?id=111971

Patch by Marja Hölttä <marja@chromium.org> on 2013-03-12
Reviewed by Kentaro Hara.

In the future we'll create and store function templates for main world
and non-main worlds separately (see bug 111724), having function
templates as static variables inside functions will break the
functionality.

No new tests (updated the bindings test expectations).

  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateDomainSafeFunctionGetter):

  • bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:

(WebCore::TestActiveDOMObjectV8Internal::postMessageAttrGetter):

  • bindings/v8/V8PerIsolateData.cpp:

(WebCore::V8PerIsolateData::V8PerIsolateData):
(WebCore::V8PerIsolateData::privateTemplate):
(WebCore):

  • bindings/v8/V8PerIsolateData.h:

(V8PerIsolateData):

  • bindings/v8/custom/V8LocationCustom.cpp:

(WebCore::V8Location::reloadAttrGetterCustom):
(WebCore::V8Location::replaceAttrGetterCustom):
(WebCore::V8Location::assignAttrGetterCustom):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r145493 r145494  
     12013-03-12  Marja Hölttä  <marja@chromium.org>
     2
     3        [V8] Get rid of function-level static FunctionTemplates in generated bindings code
     4        https://bugs.webkit.org/show_bug.cgi?id=111971
     5
     6        Reviewed by Kentaro Hara.
     7
     8        In the future we'll create and store function templates for main world
     9        and non-main worlds separately (see bug 111724), having function
     10        templates as static variables inside functions will break the
     11        functionality.
     12
     13        No new tests (updated the bindings test expectations).
     14
     15        * bindings/scripts/CodeGeneratorV8.pm:
     16        (GenerateDomainSafeFunctionGetter):
     17        * bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
     18        (WebCore::TestActiveDOMObjectV8Internal::postMessageAttrGetter):
     19        * bindings/v8/V8PerIsolateData.cpp:
     20        (WebCore::V8PerIsolateData::V8PerIsolateData):
     21        (WebCore::V8PerIsolateData::privateTemplate):
     22        (WebCore):
     23        * bindings/v8/V8PerIsolateData.h:
     24        (V8PerIsolateData):
     25        * bindings/v8/custom/V8LocationCustom.cpp:
     26        (WebCore::V8Location::reloadAttrGetterCustom):
     27        (WebCore::V8Location::replaceAttrGetterCustom):
     28        (WebCore::V8Location::assignAttrGetterCustom):
     29
    1302013-03-12  Tien-Ren Chen  <trchen@chromium.org>
    231
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r145043 r145494  
    787787    }
    788788
    789     my $newTemplateString = "v8::FunctionTemplate::New(${interfaceName}V8Internal::${funcName}MethodCallback, v8Undefined(), $signature)";
     789    my $newTemplateParams = "${interfaceName}V8Internal::${funcName}MethodCallback, v8Undefined(), $signature";
    790790
    791791    AddToImplIncludes("Frame.h");
     
    793793static v8::Handle<v8::Value> ${funcName}AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    794794{
    795     static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(info.GetIsolate(), $newTemplateString);
    796     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(${v8InterfaceName}::GetTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
     795    // This is only for getting a unique pointer which we can pass to privateTemplate.
     796    static String privateTemplateUniqueKey = "${funcName}PrivateTemplate";
     797    WrapperWorldType currentWorldType = worldType(info.GetIsolate());
     798    v8::Persistent<v8::FunctionTemplate> privateTemplate = V8PerIsolateData::from(info.GetIsolate())->privateTemplate(currentWorldType, &privateTemplateUniqueKey, $newTemplateParams);
     799
     800    v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(${v8InterfaceName}::GetTemplate(info.GetIsolate(), currentWorldType));
    797801    if (holder.IsEmpty()) {
    798802        // can only reach here by 'object.__proto__.func', and it should passed
     
    802806    ${interfaceName}* imp = ${v8InterfaceName}::toNative(holder);
    803807    if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) {
    804         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(info.GetIsolate(), $newTemplateString);
     808        static String sharedTemplateUniqueKey = "${funcName}SharedTemplate";
     809        v8::Persistent<v8::FunctionTemplate> sharedTemplate = V8PerIsolateData::from(info.GetIsolate())->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, $newTemplateParams);
    805810        return sharedTemplate->GetFunction();
    806811    }
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestActiveDOMObject.cpp

    r144651 r145494  
    129129static v8::Handle<v8::Value> postMessageAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    130130{
    131     static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(info.GetIsolate(), v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate(info.GetIsolate()))));
    132     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
     131    // This is only for getting a unique pointer which we can pass to privateTemplate.
     132    static String privateTemplateUniqueKey = "postMessagePrivateTemplate";
     133    WrapperWorldType currentWorldType = worldType(info.GetIsolate());
     134    v8::Persistent<v8::FunctionTemplate> privateTemplate = V8PerIsolateData::from(info.GetIsolate())->privateTemplate(currentWorldType, &privateTemplateUniqueKey, TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate(info.GetIsolate())));
     135
     136    v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate(info.GetIsolate(), currentWorldType));
    133137    if (holder.IsEmpty()) {
    134138        // can only reach here by 'object.__proto__.func', and it should passed
     
    138142    TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
    139143    if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) {
    140         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(info.GetIsolate(), v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate(info.GetIsolate()))));
     144        static String sharedTemplateUniqueKey = "postMessageSharedTemplate";
     145        v8::Persistent<v8::FunctionTemplate> sharedTemplate = V8PerIsolateData::from(info.GetIsolate())->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate(info.GetIsolate())));
    141146        return sharedTemplate->GetFunction();
    142147    }
  • trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp

    r141570 r145494  
    4545
    4646V8PerIsolateData::V8PerIsolateData(v8::Isolate* isolate)
    47     : m_stringCache(adoptPtr(new StringCache()))
     47    : m_isolate(isolate)
     48    , m_stringCache(adoptPtr(new StringCache()))
    4849    , m_integerCache(adoptPtr(new IntegerCache()))
    4950    , m_domDataStore(0)
     
    122123}
    123124
     125v8::Persistent<v8::FunctionTemplate> V8PerIsolateData::privateTemplate(WrapperWorldType, void* privatePointer, v8::InvocationCallback callback, v8::Handle<v8::Value> data, v8::Handle<v8::Signature> signature, int length)
     126{
     127    v8::Persistent<v8::FunctionTemplate> privateTemplate;
     128    V8PerIsolateData::TemplateMap::iterator result = m_templates.find(privatePointer);
     129    if (result != m_templates.end())
     130        return result->value;
     131    v8::Persistent<v8::FunctionTemplate> newPrivateTemplate = v8::Persistent<v8::FunctionTemplate>::New(m_isolate, v8::FunctionTemplate::New(callback, data, signature, length));
     132    m_templates.add(privatePointer, newPrivateTemplate);
     133    return newPrivateTemplate;
     134}
     135
    124136#if ENABLE(INSPECTOR)
    125137void V8PerIsolateData::visitExternalStrings(ExternalStringVisitor* visitor)
  • trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h

    r136815 r145494  
    2828
    2929#include "ScopedPersistent.h"
     30#include "WrapperTypeInfo.h"
    3031#include <v8.h>
    3132#include <wtf/Forward.h>
     
    6566    static void dispose(v8::Isolate*);
    6667
    67     typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
     68    typedef HashMap<void*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
    6869
    6970    TemplateMap& rawTemplateMap() { return m_rawTemplates; }
     
    128129    bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
    129130
     131    v8::Persistent<v8::FunctionTemplate> privateTemplate(WrapperWorldType, void* privatePointer, v8::InvocationCallback, v8::Handle<v8::Value> data, v8::Handle<v8::Signature>, int length = 0);
     132
    130133private:
    131134    explicit V8PerIsolateData(v8::Isolate*);
     
    133136    static v8::Handle<v8::Value> constructorOfToString(const v8::Arguments&);
    134137
     138    v8::Isolate* m_isolate;
    135139    TemplateMap m_rawTemplates;
    136140    TemplateMap m_templates;
  • trunk/Source/WebCore/bindings/v8/custom/V8LocationCustom.cpp

    r144617 r145494  
    140140{
    141141    v8::Isolate* isolate = info.GetIsolate();
    142     static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::reloadMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate))));
    143     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8Location::GetTemplate(isolate, worldType(isolate)));
     142    // This is only for getting a unique pointer which we can pass to privateTemplate.
     143    static String privateTemplateUniqueKey = "reloadPrivateTemplate";
     144    WrapperWorldType currentWorldType = worldType(isolate);
     145    v8::Persistent<v8::FunctionTemplate> privateTemplate = V8PerIsolateData::from(isolate)->privateTemplate(currentWorldType, &privateTemplateUniqueKey, V8Location::reloadMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)));
     146
     147    v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8Location::GetTemplate(isolate, currentWorldType));
    144148    if (holder.IsEmpty()) {
    145149        // can only reach here by 'object.__proto__.func', and it should passed
     
    149153    Location* imp = V8Location::toNative(holder);
    150154    if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) {
    151         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::reloadMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate))));
     155        static String sharedTemplateUniqueKey = "reloadSharedTemplate";
     156        v8::Persistent<v8::FunctionTemplate> sharedTemplate = V8PerIsolateData::from(info.GetIsolate())->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, V8Location::reloadMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)));
    152157        return sharedTemplate->GetFunction();
    153158    }
     
    158163{
    159164    v8::Isolate* isolate = info.GetIsolate();
    160     static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::replaceMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate))));
    161     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8Location::GetTemplate(isolate, worldType(isolate)));
     165    // This is only for getting a unique pointer which we can pass to privateTemplateMap.
     166    static String privateTemplateUniqueKey = "replacePrivateTemplate";
     167    WrapperWorldType currentWorldType = worldType(info.GetIsolate());
     168    v8::Persistent<v8::FunctionTemplate> privateTemplate = V8PerIsolateData::from(isolate)->privateTemplate(currentWorldType, &privateTemplateUniqueKey, V8Location::replaceMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)));
     169
     170    v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8Location::GetTemplate(isolate, currentWorldType));
    162171    if (holder.IsEmpty()) {
    163172        // can only reach here by 'object.__proto__.func', and it should passed
     
    167176    Location* imp = V8Location::toNative(holder);
    168177    if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) {
    169         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::replaceMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate))));
     178        static String sharedTemplateUniqueKey = "replaceSharedTemplate";
     179        v8::Persistent<v8::FunctionTemplate> sharedTemplate = V8PerIsolateData::from(info.GetIsolate())->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, V8Location::replaceMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)));
    170180        return sharedTemplate->GetFunction();
    171181    }
     
    176186{
    177187    v8::Isolate* isolate = info.GetIsolate();
    178     static v8::Persistent<v8::FunctionTemplate> privateTemplate =
    179         v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::assignMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate))));
    180     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8Location::GetTemplate(isolate, worldType(isolate)));
     188    // This is only for getting a unique pointer which we can pass to privateTemplateMap.
     189    static String privateTemplateUniqueKey = "assignPrivateTemplate";
     190    WrapperWorldType currentWorldType = worldType(info.GetIsolate());
     191    v8::Persistent<v8::FunctionTemplate> privateTemplate = V8PerIsolateData::from(isolate)->privateTemplate(currentWorldType, &privateTemplateUniqueKey, V8Location::assignMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)));
     192
     193    v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8Location::GetTemplate(isolate, currentWorldType));
    181194    if (holder.IsEmpty()) {
    182195        // can only reach here by 'object.__proto__.func', and it should passed
     
    186199    Location* imp = V8Location::toNative(holder);
    187200    if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) {
    188         static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::assignMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate))));
     201        static String sharedTemplateUniqueKey = "assignSharedTemplate";
     202        v8::Persistent<v8::FunctionTemplate> sharedTemplate = V8PerIsolateData::from(info.GetIsolate())->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, V8Location::assignMethodCustom, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)));
    189203        return sharedTemplate->GetFunction();
    190204    }
Note: See TracChangeset for help on using the changeset viewer.