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)
{
JSImageConstructor* jsConstructor = jsCast<JSImageConstructor*>(state->callee());
Document* document = jsConstructor->document();
if (!document)
return throwVMError(state, createReferenceError(state, "Image constructor associated document is unavailable"));
toJS(state, jsConstructor->globalObject(), *document);
int width;
int height;
int* optionalWidth = 0;
int* optionalHeight = 0;
if (state->argumentCount() > 0) {
width = state->argument(0).toInt32(state);
optionalWidth = &width;
}
if (state->argumentCount() > 1) {
height = state->argument(1).toInt32(state);
optionalHeight = &height;
}
return JSValue::encode(asObject(toJS(state, jsConstructor->globalObject(),
HTMLImageElement::createForJSConstructor(*document, optionalWidth, optionalHeight))));
}
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);
}
}