AtomicString v8ValueToAtomicWebCoreString(v8::Handle<v8::Value> v8Value) { if (v8Value->IsString()) return v8StringToAtomicWebCoreString(v8::Handle<v8::String>::Cast(v8Value)); String string = v8ValueToWebCoreString(v8Value); return AtomicString(string); }
v8::Handle<v8::Value> V8HTMLSelectElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLSelectElement.NamedPropertyGetter"); HTMLSelectElement* select = V8HTMLSelectElement::toNative(info.Holder()); v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); if (!value.IsEmpty()) return value; // Search local callback properties next to find IDL defined properties. if (info.Holder()->HasRealNamedCallbackProperty(name)) return notHandledByInterceptor(); PassRefPtr<HTMLOptionsCollection> collection = select->options(); Vector<RefPtr<Node> > items; collection->namedItems(v8StringToAtomicWebCoreString(name), items); if (!items.size()) return notHandledByInterceptor(); if (items.size() == 1) return toV8(items.at(0).release()); NodeList* list = new V8NamedNodesCollection(items); return toV8(list); }
v8::Handle<v8::Value> V8HTMLCollection::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLCollection.NamedPropertyGetter"); if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty()) return notHandledByInterceptor(); if (info.Holder()->HasRealNamedCallbackProperty(name)) return notHandledByInterceptor(); HTMLCollection* imp = V8HTMLCollection::toNative(info.Holder()); return getNamedItems(imp, v8StringToAtomicWebCoreString(name)); }
v8::Handle<v8::Value> V8HTMLFrameSetElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLFrameSetElement.NamedPropertyGetter"); HTMLFrameSetElement* imp = V8HTMLFrameSetElement::toNative(info.Holder()); Node* frameNode = imp->children()->namedItem(v8StringToAtomicWebCoreString(name)); if (frameNode && frameNode->hasTagName(HTMLNames::frameTag)) { Document* doc = static_cast<HTMLFrameElement*>(frameNode)->contentDocument(); if (!doc) return v8::Undefined(); if (Frame* frame = doc->frame()) return toV8(frame->domWindow()); } return notHandledByInterceptor(); }
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); v8::Handle<v8::Value> result = V8HTMLDocument::GetNamedProperty(htmlDocument, name); if (!result.IsEmpty()) return result; v8::Handle<v8::Value> prototype = info.Holder()->GetPrototype(); if (prototype->IsObject()) return prototype.As<v8::Object>()->Get(property); return v8::Undefined(); }
v8::Handle<v8::Value> V8HTMLCollection::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLCollection.NamedPropertyGetter"); // Search the prototype chain first. v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); if (!value.IsEmpty()) return value; // Search local callback properties next to find IDL defined // properties. if (info.Holder()->HasRealNamedCallbackProperty(name)) return v8::Handle<v8::Value>(); // Finally, search the DOM structure. HTMLCollection* imp = V8HTMLCollection::toNative(info.Holder()); return getNamedItems(imp, v8StringToAtomicWebCoreString(name)); }
v8::Handle<v8::Value> V8DOMWindow::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.DOMWindow.NamedPropertyGetter"); DOMWindow* window = V8DOMWindow::toNative(info.Holder()); if (!window) return notHandledByInterceptor(); Frame* frame = window->frame(); // window is detached from a frame. if (!frame) return notHandledByInterceptor(); // Search sub-frames. AtomicString propName = v8StringToAtomicWebCoreString(name); Frame* child = frame->tree()->child(propName); if (child) return toV8(child->domWindow()); // Search IDL functions defined in the prototype v8::Handle<v8::Value> result = info.Holder()->GetRealNamedProperty(name); if (!result.IsEmpty()) return result; // Search named items in the document. Document* doc = frame->document(); if (doc && doc->isHTMLDocument()) { if (static_cast<HTMLDocument*>(doc)->hasNamedItem(propName.impl()) || doc->hasElementWithId(propName.impl())) { RefPtr<HTMLCollection> items = doc->windowNamedItems(propName); if (items->length() >= 1) { if (items->length() == 1) return toV8(items->firstItem()); return toV8(items.release()); } } } return notHandledByInterceptor(); }