Chromium Code Reviews| Index: Source/core/svg/SVGLengthTearOff.cpp |
| diff --git a/Source/core/svg/SVGLengthTearOff.cpp b/Source/core/svg/SVGLengthTearOff.cpp |
| index 4706375632785d7d0968c17400b926015bf833b3..d02e2608fa68b6d693ef0dec48f382d3022949d3 100644 |
| --- a/Source/core/svg/SVGLengthTearOff.cpp |
| +++ b/Source/core/svg/SVGLengthTearOff.cpp |
| @@ -46,6 +46,11 @@ inline SVGLengthType toSVGLengthType(unsigned short type) |
| return static_cast<SVGLengthType>(type); |
| } |
| +inline bool canResolveRelativeUnits(const SVGElement* contextElement) |
| +{ |
| + return contextElement && contextElement->inDocument(); |
| +} |
| + |
| } // namespace |
| SVGLengthType SVGLengthTearOff::unitType() |
| @@ -58,21 +63,31 @@ SVGLengthMode SVGLengthTearOff::unitMode() |
| return target()->unitMode(); |
| } |
| -float SVGLengthTearOff::value(ExceptionState& es) |
| +float SVGLengthTearOff::value(ExceptionState& exceptionState) |
| { |
| + if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
| + exceptionState.throwDOMException(NotSupportedError, "No context could be found."); |
| + return 0; |
| + } |
| + |
| SVGLengthContext lengthContext(contextElement()); |
| - return target()->value(lengthContext, es); |
| + return target()->value(lengthContext); |
| } |
| -void SVGLengthTearOff::setValue(float value, ExceptionState& es) |
| +void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState) |
| { |
| if (isImmutable()) { |
| - es.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); |
| + exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); |
| + return; |
| + } |
| + |
| + if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
| + exceptionState.throwDOMException(NotSupportedError, "No context could be found."); |
| return; |
| } |
| SVGLengthContext lengthContext(contextElement()); |
| - target()->setValue(value, lengthContext, es); |
| + target()->setValue(value, lengthContext); |
| commitChange(); |
| } |
| @@ -135,8 +150,14 @@ void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio |
| return; |
| } |
| + if ((target()->isRelative() || SVGLength::isRelativeUnit(toSVGLengthType(unitType))) |
| + && !canResolveRelativeUnits(contextElement())) { |
| + exceptionState.throwDOMException(NotSupportedError, "No context could be found."); |
|
pdr.
2015/02/05 22:12:32
Bikeshed: is the concept of a length context somet
fs
2015/02/06 12:26:04
Funny you should say that, because that's pretty m
|
| + return; |
| + } |
| + |
| SVGLengthContext lengthContext(contextElement()); |
| - target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext, exceptionState); |
| + target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); |
| commitChange(); |
| } |