1 /* 2 Copyright (C) 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 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. 8 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. 13 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. 18 */ 19 20 #include "config.h" 21 22 #if ENABLE(SVG) 23 #include "JSSVGLength.h" 24 25 #include <runtime/Error.h> 26 #include "SVGAnimatedProperty.h" 27 #include "SVGException.h" 28 29 using namespace JSC; 30 31 namespace WebCore { 32 33 JSValue JSSVGLength::value(ExecState* exec) const 34 { 35 SVGLength& podImp = impl()->propertyReference(); 36 ExceptionCode ec = 0; 37 float value = podImp.value(impl()->contextElement(), ec); 38 if (ec) { 39 setDOMException(exec, ec); 40 return jsUndefined(); 41 } 42 43 return jsNumber(value); 44 } 45 46 void JSSVGLength::setValue(ExecState* exec, JSValue value) 47 { 48 if (impl()->role() == AnimValRole) { 49 setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR); 50 return; 51 } 52 53 if (!value.isUndefinedOrNull() && !value.isNumber() && !value.isBoolean()) { 54 throwVMTypeError(exec); 55 return; 56 } 57 58 SVGLength& podImp = impl()->propertyReference(); 59 60 ExceptionCode ec = 0; 61 podImp.setValue(value.toFloat(exec), impl()->contextElement(), ec); 62 if (ec) { 63 setDOMException(exec, ec); 64 return; 65 } 66 67 impl()->commitChange(); 68 } 69 70 JSValue JSSVGLength::convertToSpecifiedUnits(ExecState* exec) 71 { 72 if (impl()->role() == AnimValRole) { 73 setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR); 74 return jsUndefined(); 75 } 76 77 SVGLength& podImp = impl()->propertyReference(); 78 79 // Mimic the behaviour of RequiresAllArguments=Raise. 80 if (exec->argumentCount() < 1) 81 return throwError(exec, createSyntaxError(exec, "Not enough arguments")); 82 83 unsigned short unitType = exec->argument(0).toUInt32(exec); 84 if (exec->hadException()) 85 return jsUndefined(); 86 87 ExceptionCode ec = 0; 88 podImp.convertToSpecifiedUnits(unitType, impl()->contextElement(), ec); 89 if (ec) { 90 setDOMException(exec, ec); 91 return jsUndefined(); 92 } 93 94 impl()->commitChange(); 95 return jsUndefined(); 96 } 97 98 } 99 100 #endif // ENABLE(SVG) 101