1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include <config.h> 32 33 #if ENABLE(SVG) 34 #include "V8SVGLength.h" 35 36 #include "SVGPropertyTearOff.h" 37 #include "V8Binding.h" 38 #include "V8BindingMacros.h" 39 40 namespace WebCore { 41 42 v8::Handle<v8::Value> V8SVGLength::valueAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) 43 { 44 INC_STATS("DOM.SVGLength.value._get"); 45 SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder()); 46 SVGLength& imp = wrapper->propertyReference(); 47 ExceptionCode ec = 0; 48 float value = imp.value(wrapper->contextElement(), ec); 49 if (UNLIKELY(ec)) { 50 V8Proxy::setDOMException(ec); 51 return v8::Handle<v8::Value>(); 52 } 53 return v8::Number::New(value); 54 } 55 56 void V8SVGLength::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) 57 { 58 INC_STATS("DOM.SVGLength.value._set"); 59 SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder()); 60 if (wrapper->role() == AnimValRole) { 61 V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR); 62 return; 63 } 64 65 if (!isUndefinedOrNull(value) && !value->IsNumber() && !value->IsBoolean()) { 66 V8Proxy::throwTypeError(); 67 return; 68 } 69 70 SVGLength& imp = wrapper->propertyReference(); 71 ExceptionCode ec = 0; 72 imp.setValue(static_cast<float>(value->NumberValue()), wrapper->contextElement(), ec); 73 if (UNLIKELY(ec)) 74 V8Proxy::setDOMException(ec); 75 else 76 wrapper->commitChange(); 77 } 78 79 v8::Handle<v8::Value> V8SVGLength::convertToSpecifiedUnitsCallback(const v8::Arguments& args) 80 { 81 INC_STATS("DOM.SVGLength.convertToSpecifiedUnits"); 82 SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(args.Holder()); 83 if (wrapper->role() == AnimValRole) { 84 V8Proxy::setDOMException(NO_MODIFICATION_ALLOWED_ERR); 85 return v8::Handle<v8::Value>(); 86 } 87 88 if (args.Length() < 1) 89 return throwError("Not enough arguments", V8Proxy::SyntaxError); 90 91 SVGLength& imp = wrapper->propertyReference(); 92 ExceptionCode ec = 0; 93 EXCEPTION_BLOCK(int, unitType, toUInt32(args[0])); 94 imp.convertToSpecifiedUnits(unitType, wrapper->contextElement(), ec); 95 if (UNLIKELY(ec)) 96 V8Proxy::setDOMException(ec); 97 else 98 wrapper->commitChange(); 99 return v8::Handle<v8::Value>(); 100 } 101 102 } // namespace WebCore 103 104 #endif 105