Changeset 60470 in webkit


Ignore:
Timestamp:
Jun 1, 2010 4:30:56 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-01 Anton Muhin <antonm@chromium.org>

Reviewed by Nate Chapin.

[Chromium] get rid of named interceptor on HTMLDocument and introduce/remove accessors when named items get deleted/removed
https://bugs.webkit.org/show_bug.cgi?id=39877

This patch makes callbacks invoked on named items addition/removal
install API accessors and thus there is no more need in
named and indexed interceptors on HTMLDocument which
speeds up invocation of methods on document.

  • bindings/scripts/CodeGeneratorV8.pm:
  • bindings/v8/ScriptController.cpp: (WebCore::ScriptController::namedItemAdded): (WebCore::ScriptController::namedItemRemoved):
  • bindings/v8/V8DOMWindowShell.cpp: (WebCore::checkDocumentWrapper): (WebCore::V8DOMWindowShell::updateDocumentWrapperCache): (WebCore::getter): (WebCore::V8DOMWindowShell::namedItemAdded): (WebCore::V8DOMWindowShell::namedItemRemoved):
  • bindings/v8/V8DOMWindowShell.h:
  • bindings/v8/V8DOMWrapper.cpp: (WebCore::V8DOMWrapper::instantiateV8Object):
  • bindings/v8/custom/V8HTMLDocumentCustom.cpp: (WebCore::V8HTMLDocument::WrapInShadowObject): (WebCore::V8HTMLDocument::GetNamedProperty): (WebCore::V8HTMLDocument::allAccessorSetter): (WebCore::toV8):
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r60466 r60470  
     12010-06-01  Anton Muhin  <antonm@chromium.org>
     2
     3        Reviewed by Nate Chapin.
     4
     5        [Chromium] get rid of named interceptor on HTMLDocument and introduce/remove accessors when named items get deleted/removed
     6        https://bugs.webkit.org/show_bug.cgi?id=39877
     7
     8        This patch makes callbacks invoked on named items addition/removal
     9        install API accessors and thus there is no more need in
     10        named and indexed interceptors on HTMLDocument which
     11        speeds up invocation of methods on document.
     12
     13        * bindings/scripts/CodeGeneratorV8.pm:
     14        * bindings/v8/ScriptController.cpp:
     15        (WebCore::ScriptController::namedItemAdded):
     16        (WebCore::ScriptController::namedItemRemoved):
     17        * bindings/v8/V8DOMWindowShell.cpp:
     18        (WebCore::checkDocumentWrapper):
     19        (WebCore::V8DOMWindowShell::updateDocumentWrapperCache):
     20        (WebCore::getter):
     21        (WebCore::V8DOMWindowShell::namedItemAdded):
     22        (WebCore::V8DOMWindowShell::namedItemRemoved):
     23        * bindings/v8/V8DOMWindowShell.h:
     24        * bindings/v8/V8DOMWrapper.cpp:
     25        (WebCore::V8DOMWrapper::instantiateV8Object):
     26        * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
     27        (WebCore::V8HTMLDocument::WrapInShadowObject):
     28        (WebCore::V8HTMLDocument::GetNamedProperty):
     29        (WebCore::V8HTMLDocument::allAccessorSetter):
     30        (WebCore::toV8):
     31
    1322010-06-01  Zoltan Herczeg  <zherczeg@webkit.org>
    233
  • trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r60330 r60470  
    274274    }
    275275
     276    if ($implClassName eq "HTMLDocument") {
     277      push(@headerContent, <<END);
     278  static v8::Local<v8::Object> WrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl);
     279  static v8::Handle<v8::Value> GetNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key);
     280END
     281    }
     282
    276283    my @enabledAtRuntime;
    277284    foreach my $function (@{$dataNode->functions}) {
     
    361368    if (IsSubType($dataNode, "Document")) {
    362369        push(@customInternalFields, "implementationIndex");
    363         if ($name eq "HTMLDocument") {
    364             push(@customInternalFields, ("markerIndex", "shadowIndex"));
    365         }
    366370    } elsif ($name eq "DOMWindow") {
    367371        push(@customInternalFields, "enteredIsolatedWorldIndex");
     
    400404    "Storage" => 1,
    401405    "HTMLAppletElement" => 1,
    402     "HTMLDocument" => 1,
    403406    "HTMLEmbedElement" => 1,
    404407    "HTMLObjectElement" => 1
     
    427430        $hasCustomNamedGetter = 1;
    428431    }
     432    if ($interfaceName eq "HTMLDocument") {
     433        $hasCustomNamedGetter = 0;
     434        $hasCustomIndexedGetter = 0;
     435    }
    429436    my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName};
    430437
     
    455462END
    456463    }
    457     if ($hasCustomDeleters || $interfaceName eq "HTMLDocument") {
     464    if ($hasCustomDeleters) {
    458465        push(@headerContent, <<END);
    459466    static v8::Handle<v8::Boolean> namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info);
     
    15051512    }
    15061513
     1514    if ($interfaceName eq "HTMLDocument") {
     1515        $hasCustomGetter = 0;
     1516    }
     1517
    15071518    my $hasGetter = $dataNode->extendedAttributes->{"HasNameGetter"} || $hasCustomGetter || $namedPropertyGetter;
    15081519    if (!$hasGetter) {
     
    15201531
    15211532    my $hasSetter = $dataNode->extendedAttributes->{"DelegatingPutFunction"};
    1522     # FIXME: Try to remove hard-coded HTMLDocument reference by aligning handling of document.all with JSC bindings.
    1523     my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"} || $interfaceName eq "HTMLDocument";
     1533    my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"};
    15241534    my $hasEnumerator = $dataNode->extendedAttributes->{"CustomGetPropertyNames"};
    15251535    my $setOn = "Instance";
     
    20022012    // Turning on checks also invalidates inline caches of the object.
    20032013    instance->SetAccessCheckCallbacks(V8DOMWindow::namedSecurityCheck, V8DOMWindow::indexedSecurityCheck, v8::External::Wrap(&V8DOMWindow::info), false);
     2014END
     2015    }
     2016    if ($interfaceName eq "HTMLDocument") {
     2017        push(@implContent, <<END);
     2018    desc->SetHiddenPrototype(true);
    20042019END
    20052020    }
  • trunk/WebCore/bindings/v8/ScriptController.cpp

    r60291 r60470  
    457457void ScriptController::namedItemAdded(HTMLDocument* doc, const AtomicString& name)
    458458{
     459    m_proxy->windowShell()->namedItemAdded(doc, name);
    459460}
    460461
    461462void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& name)
    462463{
     464    m_proxy->windowShell()->namedItemRemoved(doc, name);
    463465}
    464466
  • trunk/WebCore/bindings/v8/V8DOMWindowShell.cpp

    r57991 r60470  
    5151#include "V8Document.h"
    5252#include "V8GCForContextDispose.h"
     53#include "V8HTMLDocument.h"
    5354#include "V8HiddenPropertyName.h"
    5455#include "V8History.h"
     
    403404}
    404405
     406static void checkDocumentWrapper(v8::Handle<v8::Object> wrapper, Document* document)
     407{
     408    ASSERT(V8Document::toNative(wrapper) == document);
     409    ASSERT(!document->isHTMLDocument() || (V8Document::toNative(v8::Handle<v8::Object>::Cast(wrapper->GetPrototype())) == document));
     410}
     411
    405412void V8DOMWindowShell::updateDocumentWrapperCache()
    406413{
     
    421428
    422429    v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document());
     430    ASSERT(documentWrapper == m_document || m_document.IsEmpty());
     431    if (m_document.IsEmpty())
     432        updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper));
     433    checkDocumentWrapper(m_document, m_frame->document());
    423434
    424435    // If instantiation of the document wrapper fails, clear the cache
     
    498509}
    499510
     511v8::Handle<v8::Value> getter(v8::Local<v8::String> property, const v8::AccessorInfo& info)
     512{
     513    // FIXME(antonm): consider passing AtomicStringImpl directly.
     514    AtomicString name = v8StringToAtomicWebCoreString(property);
     515    HTMLDocument* htmlDocument = V8HTMLDocument::toNative(info.Holder());
     516    ASSERT(htmlDocument);
     517    return V8HTMLDocument::GetNamedProperty(htmlDocument, name);
     518}
     519
     520void V8DOMWindowShell::namedItemAdded(HTMLDocument* doc, const AtomicString& name)
     521{
     522    initContextIfNeeded();
     523
     524    v8::HandleScope handleScope;
     525    v8::Context::Scope contextScope(m_context);
     526
     527    ASSERT(!m_document.IsEmpty());
     528    checkDocumentWrapper(m_document, doc);
     529    m_document->SetAccessor(v8String(name), getter);
     530}
     531
     532void V8DOMWindowShell::namedItemRemoved(HTMLDocument* doc, const AtomicString& name)
     533{
     534    initContextIfNeeded();
     535
     536    v8::HandleScope handleScope;
     537    v8::Context::Scope contextScope(m_context);
     538
     539    ASSERT(!m_document.IsEmpty());
     540    checkDocumentWrapper(m_document, doc);
     541    m_document->Delete(v8String(name));
     542}
     543
    500544void V8DOMWindowShell::updateSecurityOrigin()
    501545{
  • trunk/WebCore/bindings/v8/V8DOMWindowShell.h

    r57991 r60470  
    3232#define V8DOMWindowShell_h
    3333
     34#include "AtomicString.h"
    3435#include "WrapperTypeInfo.h"
    3536#include <wtf/HashMap.h>
     
    4243class DOMWindow;
    4344class Frame;
     45class HTMLDocument;
    4446class String;
    4547
     
    5456    // Update document object of the frame.
    5557    void updateDocument();
     58
     59    void namedItemAdded(HTMLDocument*, const AtomicString&);
     60    void namedItemRemoved(HTMLDocument*, const AtomicString&);
    5661
    5762    // Update the security origin of a document
  • trunk/WebCore/bindings/v8/V8DOMWrapper.cpp

    r59499 r60470  
    287287        // Avoid setting the DOM wrapper for failed allocations.
    288288        setDOMWrapper(instance, type, impl);
     289        if (type == &V8HTMLDocument::info)
     290            instance = V8HTMLDocument::WrapInShadowObject(instance, static_cast<Node*>(impl));
    289291    }
    290292    return instance;
  • trunk/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp

    r54581 r60470  
    5050namespace WebCore {
    5151
    52 v8::Handle<v8::Boolean> V8HTMLDocument::namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     52v8::Local<v8::Object> V8HTMLDocument::WrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl)
    5353{
    54     // Only handle document.all.  Insert the marker object into the
    55     // shadow internal field to signal that document.all is no longer
    56     // shadowed.
    57     AtomicString key = v8StringToAtomicWebCoreString(name);
    58     DEFINE_STATIC_LOCAL(const AtomicString, all, ("all"));
    59     if (key != all)
    60         return deletionNotHandledByInterceptor();
     54    DEFINE_STATIC_LOCAL(v8::Persistent<v8::Function>, shadowConstructor, ());
     55    if (shadowConstructor.IsEmpty()) {
     56        v8::Local<v8::FunctionTemplate> shadowTemplate = v8::FunctionTemplate::New();
     57        if (shadowTemplate.IsEmpty())
     58            return v8::Local<v8::Object>();
     59        shadowTemplate->SetClassName(v8::String::New("HTMLDocument"));
     60        shadowTemplate->Inherit(V8HTMLDocument::GetTemplate());
     61        shadowTemplate->InstanceTemplate()->SetInternalFieldCount(V8HTMLDocument::internalFieldCount);
     62        shadowConstructor = v8::Persistent<v8::Function>::New(shadowTemplate->GetFunction());
     63        if (shadowConstructor.IsEmpty())
     64            return v8::Local<v8::Object>();
     65    }
    6166
    62     ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount);
    63     v8::Local<v8::Value> marker = info.Holder()->GetInternalField(V8HTMLDocument::markerIndex);
    64     info.Holder()->SetInternalField(V8HTMLDocument::shadowIndex, marker);
    65     return v8::True();
     67    ASSERT(!shadowConstructor.IsEmpty());
     68    v8::Local<v8::Object> shadow = shadowConstructor->NewInstance();
     69    if (shadow.IsEmpty())
     70        return v8::Local<v8::Object>();
     71    V8DOMWrapper::setDOMWrapper(shadow, &V8HTMLDocument::info, impl);
     72    shadow->SetPrototype(wrapper);
     73    return shadow;
    6674}
    6775
    68 v8::Handle<v8::Value> V8HTMLDocument::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     76v8::Handle<v8::Value> V8HTMLDocument::GetNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key)
    6977{
    70     INC_STATS("DOM.HTMLDocument.NamedPropertyGetter");
    71     AtomicString key = v8StringToAtomicWebCoreString(name);
    72 
    73     // Special case for document.all.  If the value in the shadow
    74     // internal field is not the marker object, then document.all has
    75     // been temporarily shadowed and we return the value.
    76     DEFINE_STATIC_LOCAL(const AtomicString, all, ("all"));
    77     if (key == all) {
    78         ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount);
    79         v8::Local<v8::Value> marker = info.Holder()->GetInternalField(V8HTMLDocument::markerIndex);
    80         v8::Local<v8::Value> value = info.Holder()->GetInternalField(V8HTMLDocument::shadowIndex);
    81         if (marker != value)
    82             return value;
    83     }
    84 
    85     HTMLDocument* htmlDocument = V8HTMLDocument::toNative(info.Holder());
    86 
    87     // Fast case for named elements that are not there.
    88     if (!htmlDocument->hasNamedItem(key.impl()) && !htmlDocument->hasExtraNamedItem(key.impl()))
    89         return v8::Handle<v8::Value>();
     78    ASSERT(htmlDocument->hasNamedItem(key.impl()) || htmlDocument->hasExtraNamedItem(key.impl()));
    9079
    9180    RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key);
    9281    if (!items->length())
    93         return notHandledByInterceptor();
     82        return v8::Handle<v8::Value>();
    9483
    9584    if (items->length() == 1) {
     
    10392
    10493    return toV8(items.release());
    105 }
    106 
    107 v8::Handle<v8::Value> V8HTMLDocument::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo &info)
    108 {
    109     INC_STATS("DOM.HTMLDocument.IndexedPropertyGetter");
    110     v8::Local<v8::Integer> indexV8 = v8::Integer::NewFromUnsigned(index);
    111     return namedPropertyGetter(indexV8->ToString(), info);
    11294}
    11395
     
    194176void V8HTMLDocument::allAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
    195177{
    196     INC_STATS("DOM.HTMLDocument.all._set");
    197     v8::Handle<v8::Object> holder = info.Holder();
    198     ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount);
    199     info.Holder()->SetInternalField(V8HTMLDocument::shadowIndex, value);
     178    // Just emulate a normal JS behaviour---install a property on this.
     179    info.This()->ForceSet(name, value);
    200180}
    201181
     
    211191            proxy->windowShell()->updateDocumentWrapper(wrapper);
    212192    }
    213     // Create marker object and insert it in two internal fields.
    214     // This is used to implement temporary shadowing of document.all.
    215     ASSERT(wrapper->InternalFieldCount() == V8HTMLDocument::internalFieldCount);
    216     v8::Local<v8::Object> marker = v8::Object::New();
    217     wrapper->SetInternalField(V8HTMLDocument::markerIndex, marker);
    218     wrapper->SetInternalField(V8HTMLDocument::shadowIndex, marker);
    219193    return wrapper;
    220194}
  • trunk/WebKit/chromium/DEPS

    r60457 r60470  
    3333vars = {
    3434  'chromium_svn': 'http://src.chromium.org/svn/trunk/src',
    35   'chromium_rev': '47248',
     35  'chromium_rev': '48481',
    3636
    3737  'pthreads-win32_rev': '26716',
Note: See TracChangeset for help on using the changeset viewer.