diff options
Diffstat (limited to 'WebCore/bindings/v8/V8DOMWindowShell.cpp')
-rw-r--r-- | WebCore/bindings/v8/V8DOMWindowShell.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/WebCore/bindings/v8/V8DOMWindowShell.cpp b/WebCore/bindings/v8/V8DOMWindowShell.cpp index c7c77d3..99fea4c 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.cpp +++ b/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -50,6 +50,7 @@ #include "V8DOMWindow.h" #include "V8Document.h" #include "V8GCForContextDispose.h" +#include "V8HTMLDocument.h" #include "V8HiddenPropertyName.h" #include "V8History.h" #include "V8Location.h" @@ -414,6 +415,12 @@ void V8DOMWindowShell::clearDocumentWrapper() } } +static void checkDocumentWrapper(v8::Handle<v8::Object> wrapper, Document* document) +{ + ASSERT(V8Document::toNative(wrapper) == document); + ASSERT(!document->isHTMLDocument() || (V8Document::toNative(v8::Handle<v8::Object>::Cast(wrapper->GetPrototype())) == document)); +} + void V8DOMWindowShell::updateDocumentWrapperCache() { v8::HandleScope handleScope; @@ -432,6 +439,10 @@ void V8DOMWindowShell::updateDocumentWrapperCache() } v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document()); + ASSERT(documentWrapper == m_document || m_document.IsEmpty()); + if (m_document.IsEmpty()) + updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper)); + checkDocumentWrapper(m_document, m_frame->document()); // If instantiation of the document wrapper fails, clear the cache // and let the DOMWindow accessor handle access to the document. @@ -509,6 +520,39 @@ void V8DOMWindowShell::updateDocument() updateSecurityOrigin(); } +v8::Handle<v8::Value> getter(v8::Local<v8::String> property, const v8::AccessorInfo& info) +{ + // FIXME(antonm): consider passing AtomicStringImpl directly. + AtomicString name = v8StringToAtomicWebCoreString(property); + HTMLDocument* htmlDocument = V8HTMLDocument::toNative(info.Holder()); + ASSERT(htmlDocument); + return V8HTMLDocument::GetNamedProperty(htmlDocument, name); +} + +void V8DOMWindowShell::namedItemAdded(HTMLDocument* doc, const AtomicString& name) +{ + initContextIfNeeded(); + + v8::HandleScope handleScope; + v8::Context::Scope contextScope(m_context); + + ASSERT(!m_document.IsEmpty()); + checkDocumentWrapper(m_document, doc); + m_document->SetAccessor(v8String(name), getter); +} + +void V8DOMWindowShell::namedItemRemoved(HTMLDocument* doc, const AtomicString& name) +{ + initContextIfNeeded(); + + v8::HandleScope handleScope; + v8::Context::Scope contextScope(m_context); + + ASSERT(!m_document.IsEmpty()); + checkDocumentWrapper(m_document, doc); + m_document->Delete(v8String(name)); +} + void V8DOMWindowShell::updateSecurityOrigin() { v8::HandleScope scope; |