Changeset 60670 in webkit
- Timestamp:
- Jun 4, 2010 2:58:04 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r60668 r60670 1 2010-06-04 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 1 32 2010-06-04 Kwang Yul Seo <skyul@company100.net> 2 33 -
trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm
r60531 r60670 274 274 } 275 275 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); 280 END 281 } 282 276 283 my @enabledAtRuntime; 277 284 foreach my $function (@{$dataNode->functions}) { … … 361 368 if (IsSubType($dataNode, "Document")) { 362 369 push(@customInternalFields, "implementationIndex"); 363 if ($name eq "HTMLDocument") {364 push(@customInternalFields, ("markerIndex", "shadowIndex"));365 }366 370 } elsif ($name eq "DOMWindow") { 367 371 push(@customInternalFields, "enteredIsolatedWorldIndex"); … … 400 404 "Storage" => 1, 401 405 "HTMLAppletElement" => 1, 402 "HTMLDocument" => 1,403 406 "HTMLEmbedElement" => 1, 404 407 "HTMLObjectElement" => 1 … … 427 430 $hasCustomNamedGetter = 1; 428 431 } 432 if ($interfaceName eq "HTMLDocument") { 433 $hasCustomNamedGetter = 0; 434 $hasCustomIndexedGetter = 0; 435 } 429 436 my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName}; 430 437 … … 455 462 END 456 463 } 457 if ($hasCustomDeleters || $interfaceName eq "HTMLDocument") {464 if ($hasCustomDeleters) { 458 465 push(@headerContent, <<END); 459 466 static v8::Handle<v8::Boolean> namedPropertyDeleter(v8::Local<v8::String>, const v8::AccessorInfo&); … … 1506 1513 } 1507 1514 1515 if ($interfaceName eq "HTMLDocument") { 1516 $hasCustomGetter = 0; 1517 } 1518 1508 1519 my $hasGetter = $dataNode->extendedAttributes->{"HasNameGetter"} || $hasCustomGetter || $namedPropertyGetter; 1509 1520 if (!$hasGetter) { … … 1521 1532 1522 1533 my $hasSetter = $dataNode->extendedAttributes->{"DelegatingPutFunction"}; 1523 # FIXME: Try to remove hard-coded HTMLDocument reference by aligning handling of document.all with JSC bindings. 1524 my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"} || $interfaceName eq "HTMLDocument"; 1534 my $hasDeleter = $dataNode->extendedAttributes->{"CustomDeleteProperty"}; 1525 1535 my $hasEnumerator = $dataNode->extendedAttributes->{"CustomGetPropertyNames"}; 1526 1536 my $setOn = "Instance"; … … 2004 2014 // Turning on checks also invalidates inline caches of the object. 2005 2015 instance->SetAccessCheckCallbacks(V8DOMWindow::namedSecurityCheck, V8DOMWindow::indexedSecurityCheck, v8::External::Wrap(&V8DOMWindow::info), false); 2016 END 2017 } 2018 if ($interfaceName eq "HTMLDocument") { 2019 push(@implContent, <<END); 2020 desc->SetHiddenPrototype(true); 2006 2021 END 2007 2022 } -
trunk/WebCore/bindings/v8/ScriptController.cpp
r60473 r60670 457 457 void ScriptController::namedItemAdded(HTMLDocument* doc, const AtomicString& name) 458 458 { 459 m_proxy->windowShell()->namedItemAdded(doc, name); 459 460 } 460 461 461 462 void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& name) 462 463 { 464 m_proxy->windowShell()->namedItemRemoved(doc, name); 463 465 } 464 466 -
trunk/WebCore/bindings/v8/V8DOMWindowShell.cpp
r60473 r60670 51 51 #include "V8Document.h" 52 52 #include "V8GCForContextDispose.h" 53 #include "V8HTMLDocument.h" 53 54 #include "V8HiddenPropertyName.h" 54 55 #include "V8History.h" … … 403 404 } 404 405 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 405 412 void V8DOMWindowShell::updateDocumentWrapperCache() 406 413 { … … 421 428 422 429 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()); 423 434 424 435 // If instantiation of the document wrapper fails, clear the cache … … 498 509 } 499 510 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 500 544 void V8DOMWindowShell::updateSecurityOrigin() 501 545 { -
trunk/WebCore/bindings/v8/V8DOMWindowShell.h
r60473 r60670 32 32 #define V8DOMWindowShell_h 33 33 34 #include "AtomicString.h" 34 35 #include "WrapperTypeInfo.h" 35 36 #include <wtf/HashMap.h> … … 42 43 class DOMWindow; 43 44 class Frame; 45 class HTMLDocument; 44 46 class String; 45 47 … … 54 56 // Update document object of the frame. 55 57 void updateDocument(); 58 59 void namedItemAdded(HTMLDocument*, const AtomicString&); 60 void namedItemRemoved(HTMLDocument*, const AtomicString&); 56 61 57 62 // Update the security origin of a document -
trunk/WebCore/bindings/v8/V8DOMWrapper.cpp
r60473 r60670 287 287 // Avoid setting the DOM wrapper for failed allocations. 288 288 setDOMWrapper(instance, type, impl); 289 if (type == &V8HTMLDocument::info) 290 instance = V8HTMLDocument::WrapInShadowObject(instance, static_cast<Node*>(impl)); 289 291 } 290 292 return instance; -
trunk/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp
r60473 r60670 50 50 namespace WebCore { 51 51 52 v8:: Handle<v8::Boolean> V8HTMLDocument::namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info)52 v8::Local<v8::Object> V8HTMLDocument::WrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl) 53 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(); 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 } 61 66 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; 66 74 } 67 75 68 v8::Handle<v8::Value> V8HTMLDocument:: namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)76 v8::Handle<v8::Value> V8HTMLDocument::GetNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key) 69 77 { 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())); 90 79 91 80 RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key); 92 81 if (!items->length()) 93 return notHandledByInterceptor();82 return v8::Handle<v8::Value>(); 94 83 95 84 if (items->length() == 1) { … … 103 92 104 93 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);112 94 } 113 95 … … 194 176 void V8HTMLDocument::allAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) 195 177 { 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); 200 180 } 201 181 … … 211 191 proxy->windowShell()->updateDocumentWrapper(wrapper); 212 192 } 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);219 193 return wrapper; 220 194 }
Note: See TracChangeset
for help on using the changeset viewer.