Changeset 145765 in webkit


Ignore:
Timestamp:
Mar 13, 2013 3:50:09 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[V8] Get rid of more function-level static FunctionTemplates and ObjectTemplates in bindings
https://bugs.webkit.org/show_bug.cgi?id=112262

Patch by Marja Hölttä <marja@chromium.org> on 2013-03-13
Reviewed by Jochen Eisinger.

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

No new tests (no changes in functionality yet; existing bindings
tests still pass).

  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateHeader):
(GenerateImplementation):

  • bindings/v8/V8DOMWindowShell.cpp:

(WebCore::V8DOMWindowShell::createContext):

  • bindings/v8/V8PerIsolateData.cpp:

(WebCore::V8PerIsolateData::hasPrivateTemplate):
(WebCore):

  • bindings/v8/V8PerIsolateData.h:

(V8PerIsolateData):

  • bindings/v8/custom/V8HTMLDocumentCustom.cpp:

(WebCore::V8HTMLDocument::wrapInShadowObject):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r145762 r145765  
     12013-03-13  Marja Hölttä  <marja@chromium.org>
     2
     3        [V8] Get rid of more function-level static FunctionTemplates and ObjectTemplates in bindings
     4        https://bugs.webkit.org/show_bug.cgi?id=112262
     5
     6        Reviewed by Jochen Eisinger.
     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 and object templates as static variables inside functions will
     11        break the functionality.
     12
     13        No new tests (no changes in functionality yet; existing bindings
     14        tests still pass).
     15
     16        * bindings/scripts/CodeGeneratorV8.pm:
     17        (GenerateHeader):
     18        (GenerateImplementation):
     19        * bindings/v8/V8DOMWindowShell.cpp:
     20        (WebCore::V8DOMWindowShell::createContext):
     21        * bindings/v8/V8PerIsolateData.cpp:
     22        (WebCore::V8PerIsolateData::hasPrivateTemplate):
     23        (WebCore):
     24        * bindings/v8/V8PerIsolateData.h:
     25        (V8PerIsolateData):
     26        * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
     27        (WebCore::V8HTMLDocument::wrapInShadowObject):
     28
    1292013-03-13  Julien Chaffraix  <jchaffraix@webkit.org>
    230
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r145745 r145765  
    385385    if ($interfaceName eq "DOMWindow") {
    386386        push(@headerContent, <<END);
    387     static v8::Persistent<v8::ObjectTemplate> GetShadowObjectTemplate(v8::Isolate*);
     387    static v8::Persistent<v8::ObjectTemplate> GetShadowObjectTemplate(v8::Isolate*, WrapperWorldType);
    388388END
    389389    }
     
    32613261    if ($interfaceName eq "DOMWindow") {
    32623262        push(@implContent, <<END);
    3263 v8::Persistent<v8::ObjectTemplate> V8DOMWindow::GetShadowObjectTemplate(v8::Isolate* isolate)
    3264 {
    3265     static v8::Persistent<v8::ObjectTemplate> V8DOMWindowShadowObjectCache;
    3266     if (V8DOMWindowShadowObjectCache.IsEmpty()) {
    3267         V8DOMWindowShadowObjectCache = v8::Persistent<v8::ObjectTemplate>::New(isolate, v8::ObjectTemplate::New());
    3268         ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCache, isolate);
    3269     }
    3270     return V8DOMWindowShadowObjectCache;
     3263v8::Persistent<v8::ObjectTemplate> V8DOMWindow::GetShadowObjectTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
     3264{
     3265    if (currentWorldType == MainWorld) {
     3266        static v8::Persistent<v8::ObjectTemplate> V8DOMWindowShadowObjectCacheForMainWorld;
     3267        if (V8DOMWindowShadowObjectCacheForMainWorld.IsEmpty()) {
     3268            V8DOMWindowShadowObjectCacheForMainWorld = v8::Persistent<v8::ObjectTemplate>::New(isolate, v8::ObjectTemplate::New());
     3269            ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCacheForMainWorld, isolate);
     3270        }
     3271        return V8DOMWindowShadowObjectCacheForMainWorld;
     3272    } else {
     3273        static v8::Persistent<v8::ObjectTemplate> V8DOMWindowShadowObjectCacheForNonMainWorld;
     3274        if (V8DOMWindowShadowObjectCacheForNonMainWorld.IsEmpty()) {
     3275            V8DOMWindowShadowObjectCacheForNonMainWorld = v8::Persistent<v8::ObjectTemplate>::New(isolate, v8::ObjectTemplate::New());
     3276            ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCacheForNonMainWorld, isolate);
     3277        }
     3278        return V8DOMWindowShadowObjectCacheForNonMainWorld;
     3279    }
    32713280}
    32723281
  • trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp

    r144805 r145765  
    282282    // Create a new environment using an empty template for the shadow
    283283    // object. Reuse the global object if one has been created earlier.
    284     v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate(m_isolate);
     284    v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate(m_isolate, m_world->isMainWorld() ? MainWorld : IsolatedWorld);
    285285    if (globalTemplate.IsEmpty())
    286286        return;
  • trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp

    r145575 r145765  
    123123}
    124124
     125bool V8PerIsolateData::hasPrivateTemplate(WrapperWorldType, void* privatePointer)
     126{
     127    return m_templates.find(privatePointer) != m_templates.end();
     128}
     129
    125130v8::Persistent<v8::FunctionTemplate> V8PerIsolateData::privateTemplate(WrapperWorldType, void* privatePointer, v8::InvocationCallback callback, v8::Handle<v8::Value> data, v8::Handle<v8::Signature> signature, int length)
    126131{
  • trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h

    r145575 r145765  
    129129    bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
    130130
     131    bool hasPrivateTemplate(WrapperWorldType, void* privatePointer);
    131132    v8::Persistent<v8::FunctionTemplate> privateTemplate(WrapperWorldType, void* privatePointer, v8::InvocationCallback, v8::Handle<v8::Value> data, v8::Handle<v8::Signature>, int length = 0);
    132133
  • trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp

    r144617 r145765  
    5555v8::Local<v8::Object> V8HTMLDocument::wrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl, v8::Isolate* isolate)
    5656{
    57     DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, shadowTemplate, ());
    58     if (shadowTemplate.IsEmpty()) {
     57    // This is only for getting a unique pointer which we can pass to privateTemplate.
     58    static const char* shadowTemplateUniqueKey = "wrapInShadowObjectShadowTemplate";
     59    WrapperWorldType currentWorldType = worldType(isolate);
     60    v8::Persistent<v8::FunctionTemplate> shadowTemplate;
     61    if (!V8PerIsolateData::from(isolate)->hasPrivateTemplate(currentWorldType, &shadowTemplateUniqueKey)) {
    5962        shadowTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New());
    6063        if (shadowTemplate.IsEmpty())
    6164            return v8::Local<v8::Object>();
    6265        shadowTemplate->SetClassName(v8::String::NewSymbol("HTMLDocument"));
    63         shadowTemplate->Inherit(V8HTMLDocument::GetTemplate(isolate, worldTypeInMainThread(isolate)));
     66        shadowTemplate->Inherit(V8HTMLDocument::GetTemplate(isolate, currentWorldType));
    6467        shadowTemplate->InstanceTemplate()->SetInternalFieldCount(V8HTMLDocument::internalFieldCount);
     68    } else {
     69        shadowTemplate = V8PerIsolateData::from(isolate)->privateTemplate(currentWorldType, &shadowTemplateUniqueKey, 0, v8::Handle<v8::Value>(), v8::Handle<v8::Signature>());
    6570    }
    66 
    6771    v8::Local<v8::Function> shadowConstructor = shadowTemplate->GetFunction();
    6872    if (shadowConstructor.IsEmpty())
Note: See TracChangeset for help on using the changeset viewer.