diff options
Diffstat (limited to 'WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp')
-rw-r--r-- | WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp | 78 |
1 files changed, 26 insertions, 52 deletions
diff --git a/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp b/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp index 86f2eb5..e6f1b8f 100644 --- a/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp +++ b/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp @@ -49,48 +49,37 @@ namespace WebCore { -v8::Handle<v8::Boolean> V8HTMLDocument::namedPropertyDeleter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +v8::Local<v8::Object> V8HTMLDocument::WrapInShadowObject(v8::Local<v8::Object> wrapper, Node* impl) { - // Only handle document.all. Insert the marker object into the - // shadow internal field to signal that document.all is no longer - // shadowed. - AtomicString key = v8StringToAtomicWebCoreString(name); - DEFINE_STATIC_LOCAL(const AtomicString, all, ("all")); - if (key != all) - return deletionNotHandledByInterceptor(); - - ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount); - v8::Local<v8::Value> marker = info.Holder()->GetInternalField(V8HTMLDocument::markerIndex); - info.Holder()->SetInternalField(V8HTMLDocument::shadowIndex, marker); - return v8::True(); -} - -v8::Handle<v8::Value> V8HTMLDocument::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) -{ - INC_STATS("DOM.HTMLDocument.NamedPropertyGetter"); - AtomicString key = v8StringToAtomicWebCoreString(name); - - // Special case for document.all. If the value in the shadow - // internal field is not the marker object, then document.all has - // been temporarily shadowed and we return the value. - DEFINE_STATIC_LOCAL(const AtomicString, all, ("all")); - if (key == all) { - ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount); - v8::Local<v8::Value> marker = info.Holder()->GetInternalField(V8HTMLDocument::markerIndex); - v8::Local<v8::Value> value = info.Holder()->GetInternalField(V8HTMLDocument::shadowIndex); - if (marker != value) - return value; + DEFINE_STATIC_LOCAL(v8::Persistent<v8::Function>, shadowConstructor, ()); + if (shadowConstructor.IsEmpty()) { + v8::Local<v8::FunctionTemplate> shadowTemplate = v8::FunctionTemplate::New(); + if (shadowTemplate.IsEmpty()) + return v8::Local<v8::Object>(); + shadowTemplate->SetClassName(v8::String::New("HTMLDocument")); + shadowTemplate->Inherit(V8HTMLDocument::GetTemplate()); + shadowTemplate->InstanceTemplate()->SetInternalFieldCount(V8HTMLDocument::internalFieldCount); + shadowConstructor = v8::Persistent<v8::Function>::New(shadowTemplate->GetFunction()); + if (shadowConstructor.IsEmpty()) + return v8::Local<v8::Object>(); } - HTMLDocument* htmlDocument = V8HTMLDocument::toNative(info.Holder()); + ASSERT(!shadowConstructor.IsEmpty()); + v8::Local<v8::Object> shadow = shadowConstructor->NewInstance(); + if (shadow.IsEmpty()) + return v8::Local<v8::Object>(); + V8DOMWrapper::setDOMWrapper(shadow, &V8HTMLDocument::info, impl); + shadow->SetPrototype(wrapper); + return shadow; +} - // Fast case for named elements that are not there. - if (!htmlDocument->hasNamedItem(key.impl()) && !htmlDocument->hasExtraNamedItem(key.impl())) - return v8::Handle<v8::Value>(); +v8::Handle<v8::Value> V8HTMLDocument::GetNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key) +{ + ASSERT(htmlDocument->hasNamedItem(key.impl()) || htmlDocument->hasExtraNamedItem(key.impl())); RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key); if (!items->length()) - return notHandledByInterceptor(); + return v8::Handle<v8::Value>(); if (items->length() == 1) { Node* node = items->firstItem(); @@ -104,13 +93,6 @@ v8::Handle<v8::Value> V8HTMLDocument::namedPropertyGetter(v8::Local<v8::String> return toV8(items.release()); } -v8::Handle<v8::Value> V8HTMLDocument::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo &info) -{ - INC_STATS("DOM.HTMLDocument.IndexedPropertyGetter"); - v8::Local<v8::Integer> indexV8 = v8::Integer::NewFromUnsigned(index); - return namedPropertyGetter(indexV8->ToString(), info); -} - // HTMLDocument ---------------------------------------------------------------- // Concatenates "args" to a string. If args is empty, returns empty string. @@ -193,10 +175,8 @@ v8::Handle<v8::Value> V8HTMLDocument::allAccessorGetter(v8::Local<v8::String> na void V8HTMLDocument::allAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - INC_STATS("DOM.HTMLDocument.all._set"); - v8::Handle<v8::Object> holder = info.Holder(); - ASSERT(info.Holder()->InternalFieldCount() == V8HTMLDocument::internalFieldCount); - info.Holder()->SetInternalField(V8HTMLDocument::shadowIndex, value); + // Just emulate a normal JS behaviour---install a property on this. + info.This()->ForceSet(name, value); } v8::Handle<v8::Value> toV8(HTMLDocument* impl, bool forceNewObject) @@ -210,12 +190,6 @@ v8::Handle<v8::Value> toV8(HTMLDocument* impl, bool forceNewObject) if (V8Proxy* proxy = V8Proxy::retrieve(impl->frame())) proxy->windowShell()->updateDocumentWrapper(wrapper); } - // Create marker object and insert it in two internal fields. - // This is used to implement temporary shadowing of document.all. - ASSERT(wrapper->InternalFieldCount() == V8HTMLDocument::internalFieldCount); - v8::Local<v8::Object> marker = v8::Object::New(); - wrapper->SetInternalField(V8HTMLDocument::markerIndex, marker); - wrapper->SetInternalField(V8HTMLDocument::shadowIndex, marker); return wrapper; } |