JSDOMWindowProperties.cpp [plain text]
#include "config.h"
#include "JSDOMWindowProperties.h"
#include "Frame.h"
#include "HTMLDocument.h"
#include "JSDOMBinding.h"
#include "JSDOMWindowBase.h"
#include "JSElement.h"
#include "JSHTMLCollection.h"
namespace WebCore {
using namespace JSC;
const ClassInfo JSDOMWindowProperties::s_info = { "WindowProperties", &Base::s_info, 0, CREATE_METHOD_TABLE(JSDOMWindowProperties) };
static bool jsDOMWindowPropertiesGetOwnPropertySlotNamedItemGetter(JSDOMWindowProperties* thisObject, Frame& frame, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
if (auto* scopedChild = frame.tree().scopedChild(propertyNameToAtomicString(propertyName))) {
slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, toJS(exec, scopedChild->document()->domWindow()));
return true;
}
if (!BindingSecurity::shouldAllowAccessToFrame(exec, &frame, ThrowSecurityError))
return false;
Document* document = frame.document();
if (is<HTMLDocument>(*document)) {
auto& htmlDocument = downcast<HTMLDocument>(*document);
auto* atomicPropertyName = propertyName.publicName();
if (atomicPropertyName && htmlDocument.hasWindowNamedItem(*atomicPropertyName)) {
JSValue namedItem;
if (UNLIKELY(htmlDocument.windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
Ref<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
ASSERT(collection->length() > 1);
namedItem = toJS(exec, thisObject->globalObject(), collection);
} else
namedItem = toJS(exec, thisObject->globalObject(), htmlDocument.windowNamedItem(*atomicPropertyName));
slot.setValue(thisObject, ReadOnly | DontDelete | DontEnum, namedItem);
return true;
}
}
return false;
}
bool JSDOMWindowProperties::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
{
auto* thisObject = jsCast<JSDOMWindowProperties*>(object);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
if (Base::getOwnPropertySlot(thisObject, state, propertyName, slot))
return true;
JSValue proto = thisObject->getPrototypeDirect();
if (proto.isObject() && jsCast<JSObject*>(proto)->hasProperty(state, propertyName))
return false;
auto& window = jsCast<JSDOMWindowBase*>(thisObject->globalObject())->wrapped();
if (auto* frame = window.frame())
return jsDOMWindowPropertiesGetOwnPropertySlotNamedItemGetter(thisObject, *frame, state, propertyName, slot);
return false;
}
bool JSDOMWindowProperties::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
{
return getOwnPropertySlot(object, state, Identifier::from(state, index), slot);
}
}