Changeset 63845 in webkit


Ignore:
Timestamp:
Jul 21, 2010 11:14:12 AM (14 years ago)
Author:
antonm@chromium.org
Message:

2010-07-21 Anton Muhin <antonm@chromium.org>

Reviewed by Adam Barth.

[v8] Revert r60670 as it introduced a regression: in some cases named children couldn't be retrieved.
https://bugs.webkit.org/show_bug.cgi?id=42766

See http://code.google.com/p/chromium/issues/detail?id=48804 for more details.

  • bindings/scripts/CodeGeneratorV8.pm:
  • bindings/v8/ScriptController.cpp: (WebCore::ScriptController::namedItemAdded): (WebCore::ScriptController::namedItemRemoved):
  • bindings/v8/V8DOMWindowShell.cpp: (WebCore::V8DOMWindowShell::updateDocumentWrapperCache):
  • bindings/v8/V8DOMWindowShell.h:
  • bindings/v8/V8DOMWrapper.cpp: (WebCore::V8DOMWrapper::instantiateV8Object):
  • bindings/v8/custom/V8HTMLDocumentCustom.cpp: (WebCore::V8HTMLDocument::namedPropertyDeleter): (WebCore::V8HTMLDocument::namedPropertyGetter): (WebCore::V8HTMLDocument::indexedPropertyGetter): (WebCore::V8HTMLDocument::allAccessorSetter): (WebCore::toV8):
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63844 r63845  
     12010-07-21  Anton Muhin  <antonm@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        [v8] Revert r60670 as it introduced a regression: in some cases named children couldn't be retrieved.
     6        https://bugs.webkit.org/show_bug.cgi?id=42766
     7
     8        See http://code.google.com/p/chromium/issues/detail?id=48804 for more details.
     9
     10        * bindings/scripts/CodeGeneratorV8.pm:
     11        * bindings/v8/ScriptController.cpp:
     12        (WebCore::ScriptController::namedItemAdded):
     13        (WebCore::ScriptController::namedItemRemoved):
     14        * bindings/v8/V8DOMWindowShell.cpp:
     15        (WebCore::V8DOMWindowShell::updateDocumentWrapperCache):
     16        * bindings/v8/V8DOMWindowShell.h:
     17        * bindings/v8/V8DOMWrapper.cpp:
     18        (WebCore::V8DOMWrapper::instantiateV8Object):
     19        * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
     20        (WebCore::V8HTMLDocument::namedPropertyDeleter):
     21        (WebCore::V8HTMLDocument::namedPropertyGetter):
     22        (WebCore::V8HTMLDocument::indexedPropertyGetter):
     23        (WebCore::V8HTMLDocument::allAccessorSetter):
     24        (WebCore::toV8):
     25
    1262010-07-21  Eric Carlson  <eric.carlson@apple.com>
    227
  • trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r63803 r63845  
    276276    }
    277277
    278     if ($implClassName eq "HTMLDocument") {
    279       push(@headerContent, <<END);
    280   static v8::Local<v8::Object> WrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl);
    281   static v8::Handle<v8::Value> GetNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key);
    282 END
    283     }
    284 
    285278    my @enabledAtRuntime;
    286279    foreach my $function (@{$dataNode->functions}) {
     
    370363    if (IsSubType($dataNode, "Document")) {
    371364        push(@customInternalFields, "implementationIndex");
     365        if ($name eq "HTMLDocument") {
     366            push(@customInternalFields, ("markerIndex", "shadowIndex"));
     367        }
    372368    } elsif ($name eq "DOMWindow") {
    373369        push(@customInternalFields, "enteredIsolatedWorldIndex");
     
    406402    "Storage" => 1,
    407403    "HTMLAppletElement" => 1,
     404    "HTMLDocument" => 1,
    408405    "HTMLEmbedElement" => 1,
    409406    "HTMLObjectElement" => 1
     
    432429        $hasCustomNamedGetter = 1;
    433430    }
    434     if ($interfaceName eq "HTMLDocument") {
    435         $hasCustomNamedGetter = 0;
    436         $hasCustomIndexedGetter = 0;
    437     }
    438431    my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName};
    439432
     
    464457END
    465458    }
    466     if ($hasCustomDeleters) {
     459    if ($hasCustomDeleters || $interfaceName eq "HTMLDocument") {
    467460        push(@headerContent, <<END);
    468461    static v8::Handle<v8::Boolean> namedPropertyDeleter(v8::Local<v8::String>, const v8::AccessorInfo&);
     
    14811474    }
    14821475
    1483     if ($interfaceName eq "HTMLDocument") {
    1484         $hasCustomGetter = 0;
    1485     }
    1486 
    14871476    my $hasGetter = $dataNode->extendedAttributes->{"HasNameGetter"} || $hasCustomGetter || $namedPropertyGetter;
    14881477    if (!$hasGetter) {
     
    15001489
    15011490    my $hasSetter = $dataNode->extendedAttributes->{"DelegatingPutFunction"};
    1502     my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"};
     1491    # FIXME: Try to remove hard-coded HTMLDocument reference by aligning handling of document.all with JSC bindings.
     1492    my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"} || $interfaceName eq "HTMLDocument";
    15031493    my $hasEnumerator = $dataNode->extendedAttributes->{"CustomGetPropertyNames"};
    15041494    my $setOn = "Instance";
     
    19831973    // Turning on checks also invalidates inline caches of the object.
    19841974    instance->SetAccessCheckCallbacks(V8DOMWindow::namedSecurityCheck, V8DOMWindow::indexedSecurityCheck, v8::External::Wrap(&V8DOMWindow::info), false);
    1985 END
    1986     }
    1987     if ($interfaceName eq "HTMLDocument") {
    1988         push(@implContent, <<END);
    1989     desc->SetHiddenPrototype(true);
    19901975END
    19911976    }
  • trunk/WebCore/bindings/v8/ScriptController.cpp

    r63805 r63845  
    472472void ScriptController::namedItemAdded(HTMLDocument* doc, const AtomicString& name)
    473473{
    474     m_proxy->windowShell()->namedItemAdded(doc, name);
    475474}
    476475
    477476void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& name)
    478477{
    479     m_proxy->windowShell()->namedItemRemoved(doc, name);
    480478}
    481479
  • trunk/WebCore/bindings/v8/V8DOMWindowShell.cpp

    r61467 r63845  
    5151#include "V8Document.h"
    5252#include "V8GCForContextDispose.h"
    53 #include "V8HTMLDocument.h"
    5453#include "V8HiddenPropertyName.h"
    5554#include "V8History.h"
     
    404403}
    405404
    406 static 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 
    412405void V8DOMWindowShell::updateDocumentWrapperCache()
    413406{
     
    428421
    429422    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());
    434423
    435424    // If instantiation of the document wrapper fails, clear the cache
     
    509498}
    510499
    511 v8::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 
    520 void 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 
    532 void 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 
    544500void V8DOMWindowShell::updateSecurityOrigin()
    545501{
  • trunk/WebCore/bindings/v8/V8DOMWindowShell.h

    r61467 r63845  
    3232#define V8DOMWindowShell_h
    3333
    34 #include "AtomicString.h"
    3534#include "WrapperTypeInfo.h"
    3635#include <wtf/HashMap.h>
     
    4342class DOMWindow;
    4443class Frame;
    45 class HTMLDocument;
    4644class String;
    4745
     
    5654    // Update document object of the frame.
    5755    void updateDocument();
    58 
    59     void namedItemAdded(HTMLDocument*, const AtomicString&);
    60     void namedItemRemoved(HTMLDocument*, const AtomicString&);
    6156
    6257    // Update the security origin of a document
  • trunk/WebCore/bindings/v8/V8DOMWrapper.cpp

    r62791 r63845  
    285285        // Avoid setting the DOM wrapper for failed allocations.
    286286        setDOMWrapper(instance, type, impl);
    287         if (type == &V8HTMLDocument::info)
    288             instance = V8HTMLDocument::WrapInShadowObject(instance, static_cast<Node*>(impl));
    289287    }
    290288    return instance;
  • trunk/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp

    r62763 r63845  
    5050namespace WebCore {
    5151
    52 v8::Local<v8::Object> V8HTMLDocument::WrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl)
    53 {
    54     DEFINE_STATIC_LOCAL(v8::Persistent<v8::FunctionTemplate>, shadowTemplate, ());
    55     if (shadowTemplate.IsEmpty()) {
    56         shadowTemplate = v8::Persistent<v8::FunctionTemplate>::New(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     }
    63 
    64     v8::Local<v8::Function> shadowConstructor = shadowTemplate->GetFunction();
    65     if (shadowConstructor.IsEmpty())
    66         return v8::Local<v8::Object>();
    67 
    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;
    74 }
    75 
    76 v8::Handle<v8::Value> V8HTMLDocument::GetNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key)
    77 {
    78     ASSERT(htmlDocument->hasNamedItem(key.impl()) || htmlDocument->hasExtraNamedItem(key.impl()));
     52v8::Handle<v8::Boolean> V8HTMLDocument::namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     53{
     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();
     61
     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();
     66}
     67
     68v8::Handle<v8::Value> V8HTMLDocument::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     69{
     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>();
    7990
    8091    RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key);
    8192    if (!items->length())
    82         return v8::Handle<v8::Value>();
     93        return notHandledByInterceptor();
    8394
    8495    if (items->length() == 1) {
     
    92103
    93104    return toV8(items.release());
     105}
     106
     107v8::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);
    94112}
    95113
     
    176194void V8HTMLDocument::allAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
    177195{
    178     // Just emulate a normal JS behaviour---install a property on this.
    179     info.This()->ForceSet(name, value);
     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);
    180200}
    181201
     
    191211            proxy->windowShell()->updateDocumentWrapper(wrapper);
    192212    }
     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);
    193219    return wrapper;
    194220}
Note: See TracChangeset for help on using the changeset viewer.