2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "JSImageConstructor.h"
23 #include "HTMLImageElement.h"
24 #include "HTMLNames.h"
25 #include "JSHTMLImageElement.h"
27 #include <runtime/Error.h>
33 ASSERT_CLASS_FITS_IN_CELL(JSImageConstructor);
35 const ClassInfo JSImageConstructor::s_info = { "ImageConstructor", &DOMConstructorWithDocument::s_info, 0, 0 };
37 JSImageConstructor::JSImageConstructor(ExecState* exec, Structure* structure, JSDOMGlobalObject* globalObject)
38 : DOMConstructorWithDocument(structure, globalObject)
40 ASSERT(inherits(&s_info));
41 putDirect(exec->globalData(), exec->propertyNames().prototype, JSHTMLImageElementPrototype::self(exec, globalObject), None);
44 static EncodedJSValue JSC_HOST_CALL constructImage(ExecState* exec)
46 JSImageConstructor* jsConstructor = static_cast<JSImageConstructor*>(exec->callee());
47 Document* document = jsConstructor->document();
49 return throwVMError(exec, createReferenceError(exec, "Image constructor associated document is unavailable"));
51 // Calling toJS on the document causes the JS document wrapper to be
52 // added to the window object. This is done to ensure that JSDocument::visit
53 // will be called, which will cause the image element to be marked if necessary.
54 toJS(exec, jsConstructor->globalObject(), document);
57 int* optionalWidth = 0;
58 int* optionalHeight = 0;
59 if (exec->argumentCount() > 0) {
60 width = exec->argument(0).toInt32(exec);
61 optionalWidth = &width;
63 if (exec->argumentCount() > 1) {
64 height = exec->argument(1).toInt32(exec);
65 optionalHeight = &height;
68 return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(),
69 HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight))));
72 ConstructType JSImageConstructor::getConstructData(ConstructData& constructData)
74 constructData.native.function = constructImage;
75 return ConstructTypeHost;
78 } // namespace WebCore