本文整理汇总了C++中HTMLCollection::hasExactlyOneItem方法的典型用法代码示例。如果您正苦于以下问题:C++ HTMLCollection::hasExactlyOneItem方法的具体用法?C++ HTMLCollection::hasExactlyOneItem怎么用?C++ HTMLCollection::hasExactlyOneItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLCollection
的用法示例。
在下文中一共展示了HTMLCollection::hasExactlyOneItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toLocalFrame
void V8Window::namedPropertyGetterCustom(
const AtomicString& name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
DOMWindow* window = V8Window::toImpl(info.Holder());
if (!window)
return;
Frame* frame = window->frame();
// window is detached from a frame.
if (!frame)
return;
// Note that the spec doesn't allow any cross-origin named access to the
// window object. However, UAs have traditionally allowed named access to
// named child browsing contexts, even across origins. So first, search child
// frames for a frame with a matching name.
Frame* child = frame->tree().scopedChild(name);
if (child) {
v8SetReturnValueFast(info, child->domWindow(), window);
return;
}
// If the frame is remote, the caller will never be able to access further
// named results.
if (!frame->isLocalFrame())
return;
// Search named items in the document.
Document* doc = toLocalFrame(frame)->document();
if (!doc || !doc->isHTMLDocument())
return;
// This is an AllCanRead interceptor. Check that the caller has access to the
// named results.
if (!BindingSecurity::shouldAllowAccessTo(
currentDOMWindow(info.GetIsolate()), window,
BindingSecurity::ErrorReportOption::DoNotReport))
return;
bool hasNamedItem = toHTMLDocument(doc)->hasNamedItem(name);
bool hasIdItem = doc->hasElementWithId(name);
if (!hasNamedItem && !hasIdItem)
return;
if (!hasNamedItem && hasIdItem &&
!doc->containsMultipleElementsWithId(name)) {
v8SetReturnValueFast(info, doc->getElementById(name), window);
return;
}
HTMLCollection* items = doc->windowNamedItems(name);
if (!items->isEmpty()) {
// TODO(esprehn): Firefox doesn't return an HTMLCollection here if there's
// multiple with the same name, but Chrome and Safari does. What's the
// right behavior?
if (items->hasExactlyOneItem()) {
v8SetReturnValueFast(info, items->item(0), window);
return;
}
v8SetReturnValueFast(info, items, window);
return;
}
}