fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / khtml / bindings / js / JSSVGPathSegListCustom.cpp
blobdccb556fa517c54381f0f727d6b0d6367e89a7cf
1 /*
2 * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "config.h"
21 #include "wtf/Platform.h"
23 #if ENABLE(SVG)
24 #include "JSSVGPathSegList.h"
26 #include "Document.h"
27 #include "Frame.h"
28 #include "JSSVGPathSeg.h"
29 #include "SVGDocumentExtensions.h"
30 #include "SVGElement.h"
31 #include "SVGPathSegList.h"
33 #include <wtf/Assertions.h>
35 using namespace KJS;
36 using namespace DOM;
38 namespace khtml {
40 KJS::JSValue* JSSVGPathSegList::clear(ExecState* exec, const List& args)
42 ExceptionCode ec = 0;
44 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
45 imp->clear(ec);
47 setDOMException(exec, ec);
49 m_context->svgAttributeChanged(imp->associatedAttributeName());
50 return jsUndefined();
53 KJS::JSValue* JSSVGPathSegList::initialize(ExecState* exec, const List& args)
55 ExceptionCode ec = 0;
56 SVGPathSeg* newItem = toSVGPathSeg(args[0]);
58 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
60 SVGPathSeg* obj = WTF::getPtr(imp->initialize(newItem, ec));
62 KJS::JSValue* result = toJS(exec, obj, m_context.get());
63 setDOMException(exec, ec);
65 m_context->svgAttributeChanged(imp->associatedAttributeName());
66 return result;
69 KJS::JSValue* JSSVGPathSegList::getItem(ExecState* exec, const List& args)
71 ExceptionCode ec = 0;
73 bool indexOk;
74 unsigned index = args[0]->toInt32(exec, indexOk);
75 if (!indexOk) {
76 setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
77 return jsUndefined();
80 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
81 SVGPathSeg* obj = WTF::getPtr(imp->getItem(index, ec));
83 KJS::JSValue* result = toJS(exec, obj, m_context.get());
84 setDOMException(exec, ec);
85 return result;
88 KJS::JSValue* JSSVGPathSegList::insertItemBefore(ExecState* exec, const List& args)
90 ExceptionCode ec = 0;
91 SVGPathSeg* newItem = toSVGPathSeg(args[0]);
93 bool indexOk;
94 unsigned index = args[1]->toInt32(exec, indexOk);
95 if (!indexOk) {
96 setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
97 return jsUndefined();
100 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
102 KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->insertItemBefore(newItem, index, ec)), m_context.get());
103 setDOMException(exec, ec);
105 m_context->svgAttributeChanged(imp->associatedAttributeName());
106 return result;
109 KJS::JSValue* JSSVGPathSegList::replaceItem(ExecState* exec, const List& args)
111 ExceptionCode ec = 0;
112 SVGPathSeg* newItem = toSVGPathSeg(args[0]);
114 bool indexOk;
115 unsigned index = args[1]->toInt32(exec, indexOk);
116 if (!indexOk) {
117 setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
118 return jsUndefined();
121 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
123 KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->replaceItem(newItem, index, ec)), m_context.get());
124 setDOMException(exec, ec);
126 m_context->svgAttributeChanged(imp->associatedAttributeName());
127 return result;
130 KJS::JSValue* JSSVGPathSegList::removeItem(ExecState* exec, const List& args)
132 ExceptionCode ec = 0;
134 bool indexOk;
135 unsigned index = args[0]->toInt32(exec, indexOk);
136 if (!indexOk) {
137 setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
138 return jsUndefined();
141 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
143 RefPtr<SVGPathSeg> obj(imp->removeItem(index, ec));
145 KJS::JSValue* result = toJS(exec, obj.get(), m_context.get());
146 setDOMException(exec, ec);
148 m_context->svgAttributeChanged(imp->associatedAttributeName());
149 return result;
152 KJS::JSValue* JSSVGPathSegList::appendItem(ExecState* exec, const List& args)
154 ExceptionCode ec = 0;
155 SVGPathSeg* newItem = toSVGPathSeg(args[0]);
157 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
159 KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->appendItem(newItem, ec)), m_context.get());
160 setDOMException(exec, ec);
162 m_context->svgAttributeChanged(imp->associatedAttributeName());
163 return result;
168 #endif // ENABLE(SVG)