JSElementCustom.cpp [plain text]
#include "config.h"
#include "JSElement.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "HTMLFrameElementBase.h"
#include "HTMLNames.h"
#include "JSAttr.h"
#include "JSDOMBinding.h"
#include "JSHTMLElementWrapperFactory.h"
#include "JSNodeList.h"
#include "JSNodeOrString.h"
#include "JSSVGElementWrapperFactory.h"
#include "NodeList.h"
#include "SVGElement.h"
using namespace JSC;
namespace WebCore {
using namespace HTMLNames;
static JSValue createNewElementWrapper(JSDOMGlobalObject* globalObject, Ref<Element>&& element)
{
if (is<HTMLElement>(element.get()))
return createJSHTMLWrapper(globalObject, static_reference_cast<HTMLElement>(WTFMove(element)));
if (is<SVGElement>(element.get()))
return createJSSVGWrapper(globalObject, static_reference_cast<SVGElement>(WTFMove(element)));
return CREATE_DOM_WRAPPER(globalObject, Element, WTFMove(element));
}
JSValue toJS(ExecState*, JSDOMGlobalObject* globalObject, Element& element)
{
if (auto* wrapper = getCachedWrapper(globalObject->world(), element))
return wrapper;
return createNewElementWrapper(globalObject, element);
}
JSValue toJSNewlyCreated(ExecState*, JSDOMGlobalObject* globalObject, Ref<Element>&& element)
{
#if ENABLE(CUSTOM_ELEMENTS)
if (element->isCustomElement())
return getCachedWrapper(globalObject->world(), element);
#endif
ASSERT(!getCachedWrapper(globalObject->world(), element));
return createNewElementWrapper(globalObject, WTFMove(element));
}
JSValue JSElement::before(ExecState& state)
{
ExceptionCode ec = 0;
wrapped().before(toNodeOrStringVector(state), ec);
setDOMException(&state, ec);
return jsUndefined();
}
JSValue JSElement::after(ExecState& state)
{
ExceptionCode ec = 0;
wrapped().after(toNodeOrStringVector(state), ec);
setDOMException(&state, ec);
return jsUndefined();
}
JSValue JSElement::replaceWith(ExecState& state)
{
ExceptionCode ec = 0;
wrapped().replaceWith(toNodeOrStringVector(state), ec);
setDOMException(&state, ec);
return jsUndefined();
}
JSValue JSElement::prepend(ExecState& state)
{
ExceptionCode ec = 0;
wrapped().prepend(toNodeOrStringVector(state), ec);
setDOMException(&state, ec);
return jsUndefined();
}
JSValue JSElement::append(ExecState& state)
{
ExceptionCode ec = 0;
wrapped().append(toNodeOrStringVector(state), ec);
setDOMException(&state, ec);
return jsUndefined();
}
}