Commit 2da30558 authored by fs's avatar fs Committed by Commit bot

Consolidate read-only exception throwing for SVG*TearOffs

Where possible, use the "standard" message for read-only objects from
ExceptionMessages. Move the setup of the ExceptionState with this
message to SVGPropertyTearOffBase and reuse. It also saves a small chunk
of code-space.

Also drop a bunch of vspace, reorder checks in
SVGPreserveAspectRatioTearOff to check for immutability first and do
less work on error in SVGMatrixTearOff.

Review-Url: https://codereview.chromium.org/2357463002
Cr-Commit-Position: refs/heads/master@{#419875}
parent d3bd7f0b
......@@ -5,7 +5,7 @@ Tests if gradientTransform of a gradient is animateable.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS gradient.gradientTransform.animVal.consolidate() threw exception NoModificationAllowedError: Failed to execute 'consolidate' on 'SVGTransformList': The attribute is read-only..
PASS gradient.gradientTransform.animVal.consolidate() threw exception NoModificationAllowedError: Failed to execute 'consolidate' on 'SVGTransformList': This object is read-only..
PASS gradient.gradientTransform.animVal.numberOfItems is 1
PASS gradient.gradientTransform.animVal.getItem(0).matrix.e is 0
PASS gradient.gradientTransform.animVal.getItem(0).type is SVGTransform.SVG_TRANSFORM_TRANSLATE
......
......@@ -6,7 +6,7 @@ svg.x.baseVal.value = 10
svg.x.animVal.value = 10
SUCCESS (1 of 2)
setting svg.x.animVal.value = 5
caught exception: Failed to set the 'value' property on 'SVGLength': The attribute is read-only.
caught exception: Failed to set the 'value' property on 'SVGLength': This object is read-only.
svg.x.baseVal.value = 10
svg.x.animVal.value = 10
SUCCESS (2 of 2)
......@@ -137,7 +137,7 @@ PASS text1.rotate.baseVal.appendItem(text1) threw exception TypeError: Failed to
PASS text1.rotate.baseVal.appendItem(null) threw exception TypeError: Failed to execute 'appendItem' on 'SVGNumberList': parameter 1 is not of type 'SVGNumber'..
Testing animVal clear throws
PASS text1.rotate.animVal.clear() threw exception NoModificationAllowedError: Failed to execute 'clear' on 'SVGNumberList': The object is read-only..
PASS text1.rotate.animVal.clear() threw exception NoModificationAllowedError: Failed to execute 'clear' on 'SVGNumberList': This object is read-only..
PASS text1.rotate.baseVal.clear() is undefined.
PASS successfullyParsed is true
......
......@@ -138,7 +138,7 @@ PASS transformList.appendItem(circle1) threw exception TypeError: Failed to exec
PASS transformList.appendItem(null) threw exception TypeError: Failed to execute 'appendItem' on 'SVGTransformList': parameter 1 is not of type 'SVGTransform'..
Testing animVal clear throws
PASS circle1.transform.animVal.clear() threw exception NoModificationAllowedError: Failed to execute 'clear' on 'SVGTransformList': The object is read-only..
PASS circle1.transform.animVal.clear() threw exception NoModificationAllowedError: Failed to execute 'clear' on 'SVGTransformList': This object is read-only..
PASS transformList.clear() is undefined.
Creating new SVGTransform, with 45 deg rotation about x=50, y=100 and append it to the transform list
......
......@@ -26,13 +26,13 @@ PASS currentView.zoomAndPan = SVGViewElement.SVG_ZOOMANDPAN_DISABLE threw except
PASS currentView.zoomAndPan is SVGViewElement.SVG_ZOOMANDPAN_MAGNIFY
Try changing viewBox - this has no affect on the SVGSVGElement the viewSpec belongs to - it exposed all its properties as read-only
PASS currentView.viewBox.baseVal.x = 10 threw exception NoModificationAllowedError: Failed to set the 'x' property on 'SVGRect': The attribute is read-only..
PASS currentView.viewBox.baseVal.x = 10 threw exception NoModificationAllowedError: Failed to set the 'x' property on 'SVGRect': This object is read-only..
PASS currentView.viewBox.baseVal.x is 0
PASS currentView.viewBox.baseVal.y = 20 threw exception NoModificationAllowedError: Failed to set the 'y' property on 'SVGRect': The attribute is read-only..
PASS currentView.viewBox.baseVal.y = 20 threw exception NoModificationAllowedError: Failed to set the 'y' property on 'SVGRect': This object is read-only..
PASS currentView.viewBox.baseVal.y is 0
PASS currentView.viewBox.baseVal.width = 50 threw exception NoModificationAllowedError: Failed to set the 'width' property on 'SVGRect': The attribute is read-only..
PASS currentView.viewBox.baseVal.width = 50 threw exception NoModificationAllowedError: Failed to set the 'width' property on 'SVGRect': This object is read-only..
PASS currentView.viewBox.baseVal.width is 0
PASS currentView.viewBox.baseVal.height = 100 threw exception NoModificationAllowedError: Failed to set the 'height' property on 'SVGRect': The attribute is read-only..
PASS currentView.viewBox.baseVal.height = 100 threw exception NoModificationAllowedError: Failed to set the 'height' property on 'SVGRect': This object is read-only..
PASS currentView.viewBox.baseVal.height is 0
PASS currentView.viewBoxString is "0 0 0 0"
......@@ -41,9 +41,9 @@ PASS currentView.viewBoxString = '1 2 3 4' is "1 2 3 4"
PASS currentView.viewBoxString is "0 0 0 0"
Try changing preserveAspectRatio
PASS currentView.preserveAspectRatio.baseVal.align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN threw exception NoModificationAllowedError: Failed to set the 'align' property on 'SVGPreserveAspectRatio': The attribute is read-only..
PASS currentView.preserveAspectRatio.baseVal.align = SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN threw exception NoModificationAllowedError: Failed to set the 'align' property on 'SVGPreserveAspectRatio': This object is read-only..
PASS currentView.preserveAspectRatio.baseVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID
PASS currentView.preserveAspectRatio.baseVal.meetOrSlice = SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE threw exception NoModificationAllowedError: Failed to set the 'meetOrSlice' property on 'SVGPreserveAspectRatio': The attribute is read-only..
PASS currentView.preserveAspectRatio.baseVal.meetOrSlice = SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE threw exception NoModificationAllowedError: Failed to set the 'meetOrSlice' property on 'SVGPreserveAspectRatio': This object is read-only..
PASS currentView.preserveAspectRatio.baseVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
Try changing preserveAspectRatioString
......@@ -63,7 +63,7 @@ PASS currentView.viewTargetString = '#test' is "#test"
PASS currentView.viewTargetString is ""
Try changing transform
PASS currentView.transform.clear() threw exception NoModificationAllowedError: Failed to execute 'clear' on 'SVGTransformList': The object is read-only..
PASS currentView.transform.clear() threw exception NoModificationAllowedError: Failed to execute 'clear' on 'SVGTransformList': This object is read-only..
PASS currentView.transform.numberOfItems is 0
PASS successfullyParsed is true
......
......@@ -31,7 +31,6 @@
#include "core/svg/SVGAngleTearOff.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ExceptionStatePlaceholder.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGElement.h"
......@@ -49,10 +48,9 @@ SVGAngleTearOff::~SVGAngleTearOff()
void SVGAngleTearOff::setValue(float value, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setValue(value);
commitChange();
}
......@@ -60,10 +58,9 @@ void SVGAngleTearOff::setValue(float value, ExceptionState& exceptionState)
void SVGAngleTearOff::setValueInSpecifiedUnits(float value, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setValueInSpecifiedUnits(value);
commitChange();
}
......@@ -71,15 +68,13 @@ void SVGAngleTearOff::setValueInSpecifiedUnits(float value, ExceptionState& exce
void SVGAngleTearOff::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
if (unitType == SVGAngle::kSvgAngletypeUnknown || unitType > SVGAngle::kSvgAngletypeGrad) {
exceptionState.throwDOMException(NotSupportedError, "Cannot set value with unknown or invalid units (" + String::number(unitType) + ").");
return;
}
target()->newValueSpecifiedUnits(static_cast<SVGAngle::SVGAngleType>(unitType), valueInSpecifiedUnits);
commitChange();
}
......@@ -87,20 +82,17 @@ void SVGAngleTearOff::newValueSpecifiedUnits(unsigned short unitType, float valu
void SVGAngleTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
if (unitType == SVGAngle::kSvgAngletypeUnknown || unitType > SVGAngle::kSvgAngletypeGrad) {
exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ").");
return;
}
if (target()->unitType() == SVGAngle::kSvgAngletypeUnknown) {
exceptionState.throwDOMException(NotSupportedError, "Cannot convert from unknown or invalid units.");
return;
}
target()->convertToSpecifiedUnits(static_cast<SVGAngle::SVGAngleType>(unitType));
commitChange();
}
......@@ -108,14 +100,11 @@ void SVGAngleTearOff::convertToSpecifiedUnits(unsigned short unitType, Exception
void SVGAngleTearOff::setValueAsString(const String& value, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
String oldValue = target()->valueAsString();
SVGParsingError status = target()->setValueAsString(value);
if (status == SVGParseStatus::NoError && !hasExposedAngleUnit()) {
target()->setValueAsString(oldValue); // rollback to old value
status = SVGParseStatus::ParsingFailed;
......@@ -124,7 +113,6 @@ void SVGAngleTearOff::setValueAsString(const String& value, ExceptionState& exce
exceptionState.throwDOMException(SyntaxError, "The value provided ('" + value + "') is invalid.");
return;
}
commitChange();
}
......
......@@ -129,7 +129,6 @@ float SVGLengthTearOff::value(ExceptionState& exceptionState)
exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length.");
return 0;
}
SVGLengthContext lengthContext(contextElement());
return target()->value(lengthContext);
}
......@@ -137,21 +136,18 @@ float SVGLengthTearOff::value(ExceptionState& exceptionState)
void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) {
exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length.");
return;
}
SVGLengthContext lengthContext(contextElement());
if (target()->isCalculated())
target()->setValueAsNumber(value);
else
target()->setValue(value, lengthContext);
commitChange();
}
......@@ -159,22 +155,19 @@ float SVGLengthTearOff::valueInSpecifiedUnits()
{
if (target()->isCalculated())
return 0;
return target()->valueInSpecifiedUnits();
}
void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
if (target()->isCalculated())
target()->setValueAsNumber(value);
else
target()->setValueInSpecifiedUnits(value);
commitChange();
}
......@@ -187,14 +180,11 @@ String SVGLengthTearOff::valueAsString()
void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
String oldValue = target()->valueAsString();
SVGParsingError status = target()->setValueAsString(str);
if (status == SVGParseStatus::NoError && !hasExposedLengthUnit()) {
target()->setValueAsString(oldValue); // rollback to old value
status = SVGParseStatus::ParsingFailed;
......@@ -203,22 +193,19 @@ void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& excep
exceptionState.throwDOMException(SyntaxError, "The value provided ('" + str + "') is invalid.");
return;
}
commitChange();
}
void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return;
}
if (!isValidLengthUnit(unitType)) {
exceptionState.throwDOMException(NotSupportedError, "Cannot set value with unknown or invalid units (" + String::number(unitType) + ").");
return;
}
target()->newValueSpecifiedUnits(toCSSUnitType(unitType), valueInSpecifiedUnits);
commitChange();
}
......@@ -226,21 +213,18 @@ void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return;
}
if (!isValidLengthUnit(unitType)) {
exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ").");
return;
}
if ((target()->isRelative() || CSSPrimitiveValue::isRelativeUnit(toCSSUnitType(unitType)))
&& !canResolveRelativeUnits(contextElement())) {
exceptionState.throwDOMException(NotSupportedError, "Could not resolve relative length.");
return;
}
SVGLengthContext lengthContext(contextElement());
target()->convertToSpecifiedUnits(toCSSUnitType(unitType), lengthContext);
commitChange();
......
......@@ -77,7 +77,7 @@ void SVGMatrixTearOff::commitChange()
void SVGMatrixTearOff::set##ATTRIBUTE(double f, ExceptionState& exceptionState) \
{ \
if (m_contextTransform && m_contextTransform->isImmutable()) { \
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); \
SVGPropertyTearOffBase::throwReadOnly(exceptionState); \
return; \
} \
mutableValue()->set##ATTRIBUTE(f); \
......@@ -158,18 +158,19 @@ SVGMatrixTearOff* SVGMatrixTearOff::multiply(SVGMatrixTearOff* other)
SVGMatrixTearOff* SVGMatrixTearOff::inverse(ExceptionState& exceptionState)
{
AffineTransform transform = value().inverse();
if (!value().isInvertible())
if (!value().isInvertible()) {
exceptionState.throwDOMException(InvalidStateError, "The matrix is not invertible.");
return create(transform);
return nullptr;
}
return create(value().inverse());
}
SVGMatrixTearOff* SVGMatrixTearOff::rotateFromVector(double x, double y, ExceptionState& exceptionState)
{
if (!x || !y)
if (!x || !y) {
exceptionState.throwDOMException(InvalidAccessError, "Arguments cannot be zero.");
return nullptr;
}
AffineTransform copy = value();
copy.rotateFromVector(x, y);
return create(copy);
......
......@@ -31,7 +31,6 @@
#ifndef SVGMatrixTearOff_h
#define SVGMatrixTearOff_h
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/CoreExport.h"
#include "platform/heap/Handle.h"
......@@ -39,6 +38,7 @@
namespace blink {
class ExceptionState;
class SVGTransformTearOff;
// SVGMatrixTearOff wraps a AffineTransform for Javascript.
......
......@@ -30,8 +30,6 @@
#include "core/svg/SVGNumberTearOff.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGElement.h"
namespace blink {
......@@ -44,10 +42,9 @@ SVGNumberTearOff::SVGNumberTearOff(SVGNumber* target, SVGElement* contextElement
void SVGNumberTearOff::setValue(float f, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setValue(f);
commitChange();
}
......
......@@ -30,8 +30,6 @@
#include "core/svg/SVGPointTearOff.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGElement.h"
#include "core/svg/SVGMatrixTearOff.h"
......@@ -45,10 +43,9 @@ SVGPointTearOff::SVGPointTearOff(SVGPoint* target, SVGElement* contextElement, P
void SVGPointTearOff::setX(float f, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setX(f);
commitChange();
}
......@@ -56,10 +53,9 @@ void SVGPointTearOff::setX(float f, ExceptionState& exceptionState)
void SVGPointTearOff::setY(float f, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setY(f);
commitChange();
}
......
......@@ -38,30 +38,28 @@ namespace blink {
void SVGPreserveAspectRatioTearOff::setAlign(unsigned short align, ExceptionState& exceptionState)
{
if (align == kSvgPreserveaspectratioUnknown || align > kSvgPreserveaspectratioXmaxymax) {
exceptionState.throwDOMException(NotSupportedError, "The alignment provided is invalid.");
if (isImmutable()) {
throwReadOnly(exceptionState);
return;
}
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
if (align == kSvgPreserveaspectratioUnknown || align > kSvgPreserveaspectratioXmaxymax) {
exceptionState.throwDOMException(NotSupportedError, "The alignment provided is invalid.");
return;
}
target()->setAlign(static_cast<SVGPreserveAspectRatio::SVGPreserveAspectRatioType>(align));
commitChange();
}
void SVGPreserveAspectRatioTearOff::setMeetOrSlice(unsigned short meetOrSlice, ExceptionState& exceptionState)
{
if (meetOrSlice == kSvgMeetorsliceUnknown || meetOrSlice > kSvgMeetorsliceSlice) {
exceptionState.throwDOMException(NotSupportedError, "The meetOrSlice provided is invalid.");
if (isImmutable()) {
throwReadOnly(exceptionState);
return;
}
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
if (meetOrSlice == kSvgMeetorsliceUnknown || meetOrSlice > kSvgMeetorsliceSlice) {
exceptionState.throwDOMException(NotSupportedError, "The meetOrSlice provided is invalid.");
return;
}
target()->setMeetOrSlice(static_cast<SVGPreserveAspectRatio::SVGMeetOrSliceType>(meetOrSlice));
commitChange();
}
......
......@@ -30,8 +30,6 @@
#include "core/svg/SVGRectTearOff.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGElement.h"
namespace blink {
......@@ -44,10 +42,9 @@ SVGRectTearOff::SVGRectTearOff(SVGRect* target, SVGElement* contextElement, Prop
void SVGRectTearOff::setX(float f, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setX(f);
commitChange();
}
......@@ -55,10 +52,9 @@ void SVGRectTearOff::setX(float f, ExceptionState& exceptionState)
void SVGRectTearOff::setY(float f, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setY(f);
commitChange();
}
......@@ -66,10 +62,9 @@ void SVGRectTearOff::setY(float f, ExceptionState& exceptionState)
void SVGRectTearOff::setWidth(float f, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setWidth(f);
commitChange();
}
......@@ -77,10 +72,9 @@ void SVGRectTearOff::setWidth(float f, ExceptionState& exceptionState)
void SVGRectTearOff::setHeight(float f, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setHeight(f);
commitChange();
}
......
......@@ -31,7 +31,7 @@
#ifndef SVGStringListTearOff_h
#define SVGStringListTearOff_h
#include "core/dom/ExceptionCode.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/svg/SVGStringList.h"
#include "core/svg/properties/SVGPropertyTearOff.h"
......@@ -56,10 +56,9 @@ public:
void clear(ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->clear();
commitChange();
}
......@@ -67,13 +66,11 @@ public:
String initialize(const String& item, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return String();
}
target()->initialize(item);
commitChange();
return item;
}
......@@ -85,26 +82,22 @@ public:
String insertItemBefore(const String& item, unsigned long index, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return String();
}
target()->insertItemBefore(item, index);
commitChange();
return item;
}
String replaceItem(const String& item, unsigned long index, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return String();
}
target()->replaceItem(item, index, exceptionState);
commitChange();
return item;
}
......@@ -117,26 +110,22 @@ public:
String removeItem(unsigned long index, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return String();
}
String removedItem = target()->removeItem(index, exceptionState);
commitChange();
return removedItem;
}
String appendItem(const String& item, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
throwReadOnly(exceptionState);
return String();
}
target()->appendItem(item);
commitChange();
return item;
}
......
......@@ -30,8 +30,6 @@
#include "core/svg/SVGTransformListTearOff.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGSVGElement.h"
namespace blink {
......@@ -53,10 +51,9 @@ SVGTransformTearOff* SVGTransformListTearOff::createSVGTransformFromMatrix(SVGMa
SVGTransformTearOff* SVGTransformListTearOff::consolidate(ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return nullptr;
}
return createItemTearOff(target()->consolidate());
}
......
......@@ -30,8 +30,6 @@
#include "core/svg/SVGTransformTearOff.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGElement.h"
namespace blink {
......@@ -53,20 +51,17 @@ DEFINE_TRACE(SVGTransformTearOff)
SVGMatrixTearOff* SVGTransformTearOff::matrix()
{
if (!m_matrixTearoff) {
if (!m_matrixTearoff)
m_matrixTearoff = SVGMatrixTearOff::create(this);
}
return m_matrixTearoff.get();
}
void SVGTransformTearOff::setMatrix(SVGMatrixTearOff* matrix, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setMatrix(matrix->value());
commitChange();
}
......@@ -74,10 +69,9 @@ void SVGTransformTearOff::setMatrix(SVGMatrixTearOff* matrix, ExceptionState& ex
void SVGTransformTearOff::setTranslate(float tx, float ty, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setTranslate(tx, ty);
commitChange();
}
......@@ -85,10 +79,9 @@ void SVGTransformTearOff::setTranslate(float tx, float ty, ExceptionState& excep
void SVGTransformTearOff::setScale(float sx, float sy, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setScale(sx, sy);
commitChange();
}
......@@ -96,10 +89,9 @@ void SVGTransformTearOff::setScale(float sx, float sy, ExceptionState& exception
void SVGTransformTearOff::setRotate(float angle, float cx, float cy, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setRotate(angle, cx, cy);
commitChange();
}
......@@ -107,10 +99,9 @@ void SVGTransformTearOff::setRotate(float angle, float cx, float cy, ExceptionSt
void SVGTransformTearOff::setSkewX(float x, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setSkewX(x);
commitChange();
}
......@@ -118,10 +109,9 @@ void SVGTransformTearOff::setSkewX(float x, ExceptionState& exceptionState)
void SVGTransformTearOff::setSkewY(float y, ExceptionState& exceptionState)
{
if (isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
throwReadOnly(exceptionState);
return;
}
target()->setSkewY(y);
commitChange();
}
......
......@@ -31,9 +31,7 @@
#ifndef SVGListPropertyTearOffHelper_h
#define SVGListPropertyTearOffHelper_h
#include "bindings/core/v8/ExceptionState.h"
#include "core/svg/properties/SVGPropertyTearOff.h"
#include "wtf/HashMap.h"
#include "wtf/TypeTraits.h"
namespace blink {
......@@ -90,25 +88,21 @@ public:
void clear(ExceptionState& exceptionState)
{
if (toDerived()->isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
SVGPropertyTearOffBase::throwReadOnly(exceptionState);
return;
}
toDerived()->target()->clear();
}
ItemTearOffType* initialize(ItemTearOffType* item, ExceptionState& exceptionState)
{
if (toDerived()->isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
SVGPropertyTearOffBase::throwReadOnly(exceptionState);
return nullptr;
}
ASSERT(item);
DCHECK(item);
ItemPropertyType* value = toDerived()->target()->initialize(getValueForInsertionFromTearOff(item));
toDerived()->commitChange();
return createItemTearOff(value);
}
......@@ -121,30 +115,24 @@ public:
ItemTearOffType* insertItemBefore(ItemTearOffType* item, unsigned long index, ExceptionState& exceptionState)
{
if (toDerived()->isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
SVGPropertyTearOffBase::throwReadOnly(exceptionState);
return nullptr;
}
ASSERT(item);
DCHECK(item);
ItemPropertyType* value = toDerived()->target()->insertItemBefore(getValueForInsertionFromTearOff(item), index);
toDerived()->commitChange();
return createItemTearOff(value);
}
ItemTearOffType* replaceItem(ItemTearOffType* item, unsigned long index, ExceptionState& exceptionState)
{
if (toDerived()->isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
SVGPropertyTearOffBase::throwReadOnly(exceptionState);
return nullptr;
}
ASSERT(item);
DCHECK(item);
ItemPropertyType* value = toDerived()->target()->replaceItem(getValueForInsertionFromTearOff(item), index, exceptionState);
toDerived()->commitChange();
return createItemTearOff(value);
}
......@@ -157,28 +145,23 @@ public:
ItemTearOffType* removeItem(unsigned long index, ExceptionState& exceptionState)
{
if (toDerived()->isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
SVGPropertyTearOffBase::throwReadOnly(exceptionState);
return nullptr;
}
ItemPropertyType* value = toDerived()->target()->removeItem(index, exceptionState);
toDerived()->commitChange();
return createItemTearOff(value);
}
ItemTearOffType* appendItem(ItemTearOffType* item, ExceptionState& exceptionState)
{
if (toDerived()->isImmutable()) {
exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
SVGPropertyTearOffBase::throwReadOnly(exceptionState);
return nullptr;
}
ASSERT(item);
DCHECK(item);
ItemPropertyType* value = toDerived()->target()->appendItem(getValueForInsertionFromTearOff(item));
toDerived()->commitChange();
return createItemTearOff(value);
}
......
......@@ -30,16 +30,24 @@
#include "core/svg/properties/SVGPropertyTearOff.h"
#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/svg/SVGElement.h"
namespace blink {
void SVGPropertyTearOffBase::throwReadOnly(ExceptionState& exceptionState)
{
exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessages::readOnly());
}
void SVGPropertyTearOffBase::commitChange()
{
ASSERT(!isImmutable());
DCHECK(!isImmutable());
if (!contextElement() || isAnimVal())
return;
ASSERT(m_attributeName != QualifiedName::null());
DCHECK(m_attributeName != QualifiedName::null());
contextElement()->invalidateSVGAttributes();
contextElement()->svgAttributeBaseValChanged(m_attributeName);
}
......
......@@ -38,6 +38,8 @@
namespace blink {
class ExceptionState;
enum PropertyIsAnimValType {
PropertyIsNotAnimVal,
PropertyIsAnimVal
......@@ -99,6 +101,8 @@ public:
{
}
static void throwReadOnly(ExceptionState&);
protected:
SVGPropertyTearOffBase(SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName = QualifiedName::null())
: m_contextElement(contextElement)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment