JSImageConstructor.cpp [plain text]
#include "config.h"
#include "JSImageConstructor.h"
#include "HTMLNames.h"
#include "JSDOMConstructor.h"
#include "JSHTMLImageElement.h"
#include "JSNode.h"
#include <runtime/Error.h>
using namespace JSC;
namespace WebCore {
typedef JSDOMNamedConstructor<JSHTMLImageElement> JSImageConstructor;
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSImageConstructor);
template<> void JSImageConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
{
putDirect(vm, vm.propertyNames->prototype, JSHTMLImageElement::prototype(vm, &globalObject), None);
}
template<> JSValue JSImageConstructor::prototypeForStructure(VM& vm, const JSDOMGlobalObject& globalObject)
{
return JSHTMLElement::getConstructor(vm, &globalObject);
}
template<> EncodedJSValue JSImageConstructor::construct(ExecState* state)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSImageConstructor* jsConstructor = jsCast<JSImageConstructor*>(state->jsCallee());
Document* document = jsConstructor->document();
if (!document)
return throwVMError(state, scope, createReferenceError(state, "Image constructor associated document is unavailable"));
toJS(state, jsConstructor->globalObject(), *document);
std::optional<unsigned> width;
std::optional<unsigned> height;
if (state->argumentCount() > 0) {
width = state->uncheckedArgument(0).toUInt32(state);
if (state->argumentCount() > 1)
height = state->uncheckedArgument(1).toUInt32(state);
}
return JSValue::encode(asObject(toJS(state, jsConstructor->globalObject(),
HTMLImageElement::createForJSConstructor(*document, width, height))));
}
template<> const ClassInfo JSImageConstructor::s_info = { "ImageConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSImageConstructor) };
JSC::JSValue createImageConstructor(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
{
return getDOMConstructor<JSImageConstructor>(vm, globalObject);
}
}