tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 66b973dc4f5b7d61b9b6147a350c45286b85c9c2
parent 430017d12e9af3be497a3b1a1727577ccf07caf5
Author: Denis Palmeiro <dpalmeiro@mozilla.com>
Date:   Thu, 13 Nov 2025 04:16:38 +0000

Bug 1995614: Use atoms for attributes if available instead of expecting a StringBuffer. r=hsivonen,media-playback-reviewers,firefox-svg-reviewers,karlt,dholbert

Differential Revision: https://phabricator.services.mozilla.com/D271244

Diffstat:
Mdom/html/HTMLButtonElement.cpp | 8+++++---
Mdom/html/HTMLFontElement.cpp | 8++++++--
Mdom/html/HTMLFrameSetElement.cpp | 5++---
Mdom/html/HTMLInputElement.cpp | 9+++++----
Mdom/html/HTMLLinkElement.cpp | 4++--
Mdom/html/HTMLScriptElement.cpp | 3+--
Mdom/html/HTMLSourceElement.cpp | 19+++++++++----------
Mdom/html/HTMLTextAreaElement.cpp | 4+++-
Mdom/html/nsGenericHTMLElement.cpp | 15+++++++++------
Mdom/mathml/MathMLElement.cpp | 53++++++++++++++++++++++++++++++++++-------------------
Mdom/media/mediaelement/HTMLMediaElement.cpp | 8++++----
Mdom/svg/SVGAnimationElement.cpp | 10++++++----
Mdom/svg/SVGElement.cpp | 10++++++----
Mdom/svg/SVGMotionSMILAnimationFunction.cpp | 19++++++++++---------
14 files changed, 102 insertions(+), 73 deletions(-)

diff --git a/dom/html/HTMLButtonElement.cpp b/dom/html/HTMLButtonElement.cpp @@ -22,6 +22,7 @@ #include "mozilla/dom/HTMLButtonElementBinding.h" #include "mozilla/dom/HTMLFormElement.h" #include "nsAttrValueInlines.h" +#include "nsAttrValueOrString.h" #include "nsError.h" #include "nsFocusManager.h" #include "nsGkAtoms.h" @@ -575,8 +576,9 @@ void HTMLButtonElement::GetCommand(nsAString& aCommand) const { } if (command == Command::Custom) { const nsAttrValue* attr = GetParsedAttr(nsGkAtoms::command); - MOZ_ASSERT(attr->Type() == nsAttrValue::eString); - aCommand.Assign(attr->GetStringValue()); + MOZ_ASSERT(attr->Type() == nsAttrValue::eString || + attr->Type() == nsAttrValue::eAtom); + aCommand.Assign(nsAttrValueOrString(attr).String()); MOZ_ASSERT( aCommand.Length() >= 2, "Custom commands start with '--' so must be atleast 2 chars long!"); @@ -602,7 +604,7 @@ Element::Command HTMLButtonElement::GetCommand() const { } return command; } - if (StringBeginsWith(attr->GetStringValue(), u"--"_ns)) { + if (StringBeginsWith(nsAttrValueOrString(attr).String(), u"--"_ns)) { return Command::Custom; } } diff --git a/dom/html/HTMLFontElement.cpp b/dom/html/HTMLFontElement.cpp @@ -10,6 +10,7 @@ #include "mozilla/dom/Document.h" #include "mozilla/dom/HTMLFontElementBinding.h" #include "nsAttrValueInlines.h" +#include "nsAttrValueOrString.h" #include "nsContentUtils.h" NS_IMPL_NS_NEW_HTML_ELEMENT(Font) @@ -52,9 +53,12 @@ void HTMLFontElement::MapAttributesIntoRule( // face: string list if (!aBuilder.PropertyIsSet(eCSSProperty_font_family)) { const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::face); - if (value && value->Type() == nsAttrValue::eString && + if (value && + (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom) && !value->IsEmptyString()) { - aBuilder.SetFontFamily(NS_ConvertUTF16toUTF8(value->GetStringValue())); + aBuilder.SetFontFamily( + NS_ConvertUTF16toUTF8(nsAttrValueOrString(value).String())); } } // size: int diff --git a/dom/html/HTMLFrameSetElement.cpp b/dom/html/HTMLFrameSetElement.cpp @@ -9,6 +9,7 @@ #include "mozilla/dom/Document.h" #include "mozilla/dom/EventHandlerBinding.h" #include "mozilla/dom/HTMLFrameSetElementBinding.h" +#include "nsAttrValueOrString.h" #include "nsGlobalWindowInner.h" NS_IMPL_NS_NEW_HTML_ELEMENT(FrameSet) @@ -143,13 +144,11 @@ nsresult HTMLFrameSetElement::ParseRowCol(const nsAttrValue& aValue, return NS_OK; } - MOZ_ASSERT(aValue.Type() == nsAttrValue::eString); - static const char16_t sAster('*'); static const char16_t sPercent('%'); static const char16_t sComma(','); - nsAutoString spec(aValue.GetStringValue()); + nsAutoString spec(nsAttrValueOrString(&aValue).String()); // remove whitespace (Bug 33699) and quotation marks (bug 224598) // also remove leading/trailing commas (bug 31482) spec.StripChars(u" \n\r\t\"\'"); diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp @@ -55,6 +55,7 @@ #include "mozilla/dom/WindowGlobalChild.h" #include "mozilla/glean/DomMetrics.h" #include "nsAttrValueInlines.h" +#include "nsAttrValueOrString.h" #include "nsBaseCommandController.h" #include "nsCRTGlue.h" #include "nsColorControlFrame.h" @@ -1305,17 +1306,17 @@ void HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, if (aNameSpaceID == kNameSpaceID_None) { bool needValidityUpdate = false; if (aName == nsGkAtoms::src) { + nsAttrValueOrString value(aValue); mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal( - this, aValue ? aValue->GetStringValue() : EmptyString(), - aSubjectPrincipal); + this, value.String(), aSubjectPrincipal); if (aNotify && mType == FormControlType::InputImage) { if (aValue) { // Mark channel as urgent-start before load image if the image load is // initiated by a user interaction. mUseUrgentStartForChannel = UserActivation::IsHandlingUserInput(); - LoadImage(aValue->GetStringValue(), true, aNotify, - eImageLoadType_Normal, mSrcTriggeringPrincipal); + LoadImage(value.String(), true, aNotify, eImageLoadType_Normal, + mSrcTriggeringPrincipal); } else { // Null value means the attr got unset; drop the image CancelImageRequests(aNotify); diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp @@ -25,6 +25,7 @@ #include "mozilla/dom/ReferrerInfo.h" #include "mozilla/dom/ScriptLoader.h" #include "nsAttrValueInlines.h" +#include "nsAttrValueOrString.h" #include "nsContentUtils.h" #include "nsDOMTokenList.h" #include "nsGenericHTMLElement.h" @@ -223,8 +224,7 @@ void HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, CreateAndDispatchEvent(u"DOMLinkChanged"_ns); } mTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal( - this, aValue ? aValue->GetStringValue() : EmptyString(), - aSubjectPrincipal); + this, nsAttrValueOrString(aValue).String(), aSubjectPrincipal); // If the link has `rel=localization` and its `href` attribute is changed, // update the list of localization links. diff --git a/dom/html/HTMLScriptElement.cpp b/dom/html/HTMLScriptElement.cpp @@ -133,8 +133,7 @@ void HTMLScriptElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, } if (nsGkAtoms::src == aName && kNameSpaceID_None == aNamespaceID) { mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal( - this, aValue ? aValue->GetStringValue() : EmptyString(), - aMaybeScriptedPrincipal); + this, nsAttrValueOrString(aValue).String(), aMaybeScriptedPrincipal); } return nsGenericHTMLElement::AfterSetAttr( aNamespaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify); diff --git a/dom/html/HTMLSourceElement.cpp b/dom/html/HTMLSourceElement.cpp @@ -17,6 +17,7 @@ #include "mozilla/dom/MediaList.h" #include "mozilla/dom/MediaSource.h" #include "mozilla/dom/ResponsiveImageSelector.h" +#include "nsAttrValueOrString.h" #include "nsGkAtoms.h" NS_IMPL_NS_NEW_HTML_ELEMENT(Source) @@ -64,7 +65,7 @@ void HTMLSourceElement::UpdateMediaList(const nsAttrValue* aValue) { return; } - NS_ConvertUTF16toUTF8 mediaStr(aValue->GetStringValue()); + NS_ConvertUTF16toUTF8 mediaStr(nsAttrValueOrString(aValue).String()); mMediaList = MediaList::Create(mediaStr); } @@ -88,8 +89,7 @@ void HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, bool aNotify) { if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::srcset) { mSrcsetTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal( - this, aValue ? aValue->GetStringValue() : EmptyString(), - aMaybeScriptedPrincipal); + this, nsAttrValueOrString(aValue).String(), aMaybeScriptedPrincipal); } // If we are associated with a <picture> with a valid <img>, notify it of // responsive parameter changes @@ -101,15 +101,15 @@ void HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, UpdateMediaList(aValue); } - nsString strVal = aValue ? aValue->GetStringValue() : EmptyString(); + nsAttrValueOrString value(aValue); // Find all img siblings after this <source> and notify them of the change nsCOMPtr<nsIContent> sibling = AsContent(); while ((sibling = sibling->GetNextSibling())) { if (auto* img = HTMLImageElement::FromNode(sibling)) { if (aName == nsGkAtoms::srcset) { - img->PictureSourceSrcsetChanged(this, strVal, aNotify); + img->PictureSourceSrcsetChanged(this, value.String(), aNotify); } else if (aName == nsGkAtoms::sizes) { - img->PictureSourceSizesChanged(this, strVal, aNotify); + img->PictureSourceSizesChanged(this, value.String(), aNotify); } else if (aName == nsGkAtoms::media || aName == nsGkAtoms::type) { img->PictureSourceMediaOrTypeChanged(this, aNotify); } @@ -118,14 +118,13 @@ void HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, } else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::media) { UpdateMediaList(aValue); } else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) { + nsAttrValueOrString srcValue(aValue); mSrcTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal( - this, aValue ? aValue->GetStringValue() : EmptyString(), - aMaybeScriptedPrincipal); + this, srcValue.String(), aMaybeScriptedPrincipal); mSrcMediaSource = nullptr; if (aValue) { - nsString srcStr = aValue->GetStringValue(); nsCOMPtr<nsIURI> uri; - NewURIFromString(srcStr, getter_AddRefs(uri)); + NewURIFromString(srcValue.String(), getter_AddRefs(uri)); if (uri && IsMediaSourceURI(uri)) { NS_GetSourceForMediaSourceURI(uri, getter_AddRefs(mSrcMediaSource)); } diff --git a/dom/html/HTMLTextAreaElement.cpp b/dom/html/HTMLTextAreaElement.cpp @@ -380,7 +380,9 @@ void HTMLTextAreaElement::MapAttributesIntoRule( MappedDeclarationsBuilder& aBuilder) { // wrap=off const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::wrap); - if (value && value->Type() == nsAttrValue::eString && + if (value && + (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom) && value->Equals(nsGkAtoms::OFF, eIgnoreCase)) { // Equivalent to expanding `white-space; pre` aBuilder.SetKeywordValue(eCSSProperty_white_space_collapse, diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp @@ -58,6 +58,7 @@ #include "mozilla/dom/TouchEvent.h" #include "mozilla/dom/UnbindContext.h" #include "nsAtom.h" +#include "nsAttrValueOrString.h" #include "nsCOMPtr.h" #include "nsCaseTreatment.h" #include "nsComputedDOMStyle.h" @@ -721,9 +722,11 @@ void nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, bool aNotify) { if (aNamespaceID == kNameSpaceID_None) { if (IsEventAttributeName(aName) && aValue) { - MOZ_ASSERT(aValue->Type() == nsAttrValue::eString, - "Expected string value for script body"); - SetEventHandler(GetEventNameForAttr(aName), aValue->GetStringValue()); + MOZ_ASSERT(aValue->Type() == nsAttrValue::eString || + aValue->Type() == nsAttrValue::eAtom, + "Expected string or atom value for script body"); + SetEventHandler(GetEventNameForAttr(aName), + nsAttrValueOrString(aValue).String()); } else if (aNotify && aName == nsGkAtoms::spellcheck) { SyncEditorsOnSubtree(this); } else if (aName == nsGkAtoms::popover) { @@ -872,7 +875,7 @@ void nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, // the CSP list contains a header-delivered CSP. if (nsGkAtoms::nonce == aName) { if (aValue) { - SetNonce(aValue->GetStringValue()); + SetNonce(nsAttrValueOrString(aValue).String()); if (OwnerDoc()->GetHasCSPDeliveredThroughHeader()) { SetFlags(NODE_HAS_NONCE_AND_HEADER_CSP); } @@ -1677,8 +1680,8 @@ const nsAttrValue* nsGenericHTMLElement::GetURIAttr(nsAtom* aAttr, // Don't care about return value. If it fails, we still want to // return true, and *aURI will be null. - nsContentUtils::NewURIWithDocumentCharset(aURI, attr->GetStringValue(), - OwnerDoc(), baseURI); + nsContentUtils::NewURIWithDocumentCharset( + aURI, nsAttrValueOrString(attr).String(), OwnerDoc(), baseURI); return attr; } diff --git a/dom/mathml/MathMLElement.cpp b/dom/mathml/MathMLElement.cpp @@ -12,6 +12,7 @@ #include "mozilla/TextUtils.h" #include "mozilla/dom/BindContext.h" #include "mozilla/dom/Document.h" +#include "nsAttrValueOrString.h" #include "nsCSSValue.h" #include "nsContentUtils.h" #include "nsGkAtoms.h" @@ -356,9 +357,10 @@ void MathMLElement::MapMTableAttributesInto( const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::width); nsCSSValue width; // This does not handle auto and unitless values - if (value && value->Type() == nsAttrValue::eString) { - ParseNumericValue(value->GetStringValue(), width, 0, - &aBuilder.Document()); + if (value && (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom)) { + nsString str(nsAttrValueOrString(value).String()); + ParseNumericValue(str, width, 0, &aBuilder.Document()); if (width.GetUnit() == eCSSUnit_Percent) { aBuilder.SetPercentValue(eCSSProperty_width, width.GetPercentValue()); } else if (width.GetUnit() != eCSSUnit_Null) { @@ -374,10 +376,11 @@ void MathMLElement::MapMiAttributesInto(MappedDeclarationsBuilder& aBuilder) { // https://w3c.github.io/mathml-core/#dfn-mathvariant if (!aBuilder.PropertyIsSet(eCSSProperty_text_transform)) { const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::mathvariant); - if (value && value->Type() == nsAttrValue::eString) { - auto str = value->GetStringValue(); + if (value && (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom)) { + nsString str(nsAttrValueOrString(value).String()); str.CompressWhitespace(); - if (value->GetStringValue().LowerCaseEqualsASCII("normal")) { + if (str.LowerCaseEqualsASCII("normal")) { aBuilder.SetKeywordValue(eCSSProperty_text_transform, StyleTextTransform::NONE._0); } @@ -413,9 +416,11 @@ void MathMLElement::MapGlobalMathMLAttributesInto( // scriptlevel // https://w3c.github.io/mathml-core/#dfn-scriptlevel const nsAttrValue* value = aBuilder.GetAttr(nsGkAtoms::scriptlevel); - if (value && value->Type() == nsAttrValue::eString && + if (value && + (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom) && !aBuilder.PropertyIsSet(eCSSProperty_math_depth)) { - auto str = value->GetStringValue(); + nsString str(nsAttrValueOrString(value).String()); // FIXME: Should we remove whitespace trimming? // See https://github.com/w3c/mathml/issues/122 str.CompressWhitespace(); @@ -448,9 +453,11 @@ void MathMLElement::MapGlobalMathMLAttributesInto( // mathsize // https://w3c.github.io/mathml-core/#dfn-mathsize value = aBuilder.GetAttr(nsGkAtoms::mathsize); - if (value && value->Type() == nsAttrValue::eString && + if (value && + (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom) && !aBuilder.PropertyIsSet(eCSSProperty_font_size)) { - auto str = value->GetStringValue(); + nsString str(nsAttrValueOrString(value).String()); nsCSSValue fontSize; ParseNumericValue(str, fontSize, 0, nullptr); if (fontSize.GetUnit() == eCSSUnit_Percent) { @@ -474,9 +481,11 @@ void MathMLElement::MapGlobalMathMLAttributesInto( // default: normal (except on <mi>) // value = aBuilder.GetAttr(nsGkAtoms::mathvariant); - if (value && value->Type() == nsAttrValue::eString && + if (value && + (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom) && !aBuilder.PropertyIsSet(eCSSProperty__moz_math_variant)) { - auto str = value->GetStringValue(); + nsString str(nsAttrValueOrString(value).String()); str.CompressWhitespace(); // Instead of a big table that holds all sizes, store a compressed version @@ -577,9 +586,11 @@ void MathMLElement::MapGlobalMathMLAttributesInto( // dir // https://w3c.github.io/mathml-core/#dfn-dir value = aBuilder.GetAttr(nsGkAtoms::dir); - if (value && value->Type() == nsAttrValue::eString && + if (value && + (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom) && !aBuilder.PropertyIsSet(eCSSProperty_direction)) { - auto str = value->GetStringValue(); + nsString str(nsAttrValueOrString(value).String()); static const char dirs[][4] = {"ltr", "rtl"}; static const StyleDirection dirValues[std::size(dirs)] = { StyleDirection::Ltr, StyleDirection::Rtl}; @@ -594,9 +605,11 @@ void MathMLElement::MapGlobalMathMLAttributesInto( // displaystyle // https://mathml-refresh.github.io/mathml-core/#dfn-displaystyle value = aBuilder.GetAttr(nsGkAtoms::displaystyle); - if (value && value->Type() == nsAttrValue::eString && + if (value && + (value->Type() == nsAttrValue::eString || + value->Type() == nsAttrValue::eAtom) && !aBuilder.PropertyIsSet(eCSSProperty_math_style)) { - auto str = value->GetStringValue(); + nsString str(nsAttrValueOrString(value).String()); static const char displaystyles[][6] = {"false", "true"}; static const StyleMathStyle mathStyle[std::size(displaystyles)] = { StyleMathStyle::Compact, StyleMathStyle::Normal}; @@ -717,9 +730,11 @@ void MathMLElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, if (aNameSpaceID == kNameSpaceID_None) { if (IsEventAttributeName(aName) && aValue) { - MOZ_ASSERT(aValue->Type() == nsAttrValue::eString, - "Expected string value for script body"); - SetEventHandler(GetEventNameForAttr(aName), aValue->GetStringValue()); + MOZ_ASSERT(aValue->Type() == nsAttrValue::eString || + aValue->Type() == nsAttrValue::eAtom, + "Expected string or atom value for script body"); + SetEventHandler(GetEventNameForAttr(aName), + nsAttrValueOrString(aValue).String()); } } diff --git a/dom/media/mediaelement/HTMLMediaElement.cpp b/dom/media/mediaelement/HTMLMediaElement.cpp @@ -99,6 +99,7 @@ #include "mozilla/net/UrlClassifierFeatureFactory.h" #include "mozilla/nsVideoFrame.h" #include "nsAttrValueInlines.h" +#include "nsAttrValueOrString.h" #include "nsContentPolicyUtils.h" #include "nsContentUtils.h" #include "nsCycleCollectionParticipant.h" @@ -5218,13 +5219,12 @@ void HTMLMediaElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, if (aNameSpaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::src) { mSrcMediaSource = nullptr; + nsAttrValueOrString srcVal(aValue); mSrcAttrTriggeringPrincipal = nsContentUtils::GetAttrTriggeringPrincipal( - this, aValue ? aValue->GetStringValue() : EmptyString(), - aMaybeScriptedPrincipal); + this, srcVal.String(), aMaybeScriptedPrincipal); if (aValue) { - nsString srcStr = aValue->GetStringValue(); nsCOMPtr<nsIURI> uri; - NewURIFromString(srcStr, getter_AddRefs(uri)); + NewURIFromString(srcVal.String(), getter_AddRefs(uri)); if (uri && IsMediaSourceURI(uri)) { nsresult rv = NS_GetSourceForMediaSourceURI( uri, getter_AddRefs(mSrcMediaSource)); diff --git a/dom/svg/SVGAnimationElement.cpp b/dom/svg/SVGAnimationElement.cpp @@ -13,6 +13,7 @@ #include "mozilla/dom/ElementInlines.h" #include "mozilla/dom/SVGSVGElement.h" #include "mozilla/dom/SVGSwitchElement.h" +#include "nsAttrValueOrString.h" #include "nsContentUtils.h" #include "nsIContentInlines.h" @@ -256,7 +257,7 @@ void SVGAnimationElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, const nsAttrValue* xlinkHref = mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink); if (xlinkHref) { - UpdateHrefTarget(xlinkHref->GetStringValue()); + UpdateHrefTarget(nsAttrValueOrString(xlinkHref).String()); } } else if (!HasAttr(nsGkAtoms::href)) { mHrefTarget.Unlink(); @@ -267,9 +268,10 @@ void SVGAnimationElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, HasAttr(nsGkAtoms::href))) { // Note: "href" takes priority over xlink:href. So if "xlink:href" is being // set here, we only let that update our target if "href" is *unset*. - MOZ_ASSERT(aValue->Type() == nsAttrValue::eString, - "Expected href attribute to be string type"); - UpdateHrefTarget(aValue->GetStringValue()); + MOZ_ASSERT(aValue->Type() == nsAttrValue::eString || + aValue->Type() == nsAttrValue::eAtom, + "Expected href attribute to be string or atom type"); + UpdateHrefTarget(nsAttrValueOrString(aValue).String()); } // else: we're not yet in a document -- we'll update the target on // next BindToTree call. } diff --git a/dom/svg/SVGElement.cpp b/dom/svg/SVGElement.cpp @@ -361,9 +361,11 @@ void SVGElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, const nsAttrValue* aOldValue, nsIPrincipal* aSubjectPrincipal, bool aNotify) { if (IsEventAttributeName(aName) && aValue) { - MOZ_ASSERT(aValue->Type() == nsAttrValue::eString, - "Expected string value for script body"); - SetEventHandler(GetEventNameForAttr(aName), aValue->GetStringValue()); + MOZ_ASSERT(aValue->Type() == nsAttrValue::eString || + aValue->Type() == nsAttrValue::eAtom, + "Expected string or atom value for script body"); + SetEventHandler(GetEventNameForAttr(aName), + nsAttrValueOrString(aValue).String()); } // The nonce will be copied over to an internal slot and cleared from the @@ -371,7 +373,7 @@ void SVGElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, // the CSP list contains a header-delivered CSP. if (nsGkAtoms::nonce == aName && kNameSpaceID_None == aNamespaceID) { if (aValue) { - SetNonce(aValue->GetStringValue()); + SetNonce(nsAttrValueOrString(aValue).String()); if (OwnerDoc()->GetHasCSPDeliveredThroughHeader()) { SetFlags(NODE_HAS_NONCE_AND_HEADER_CSP); } diff --git a/dom/svg/SVGMotionSMILAnimationFunction.cpp b/dom/svg/SVGMotionSMILAnimationFunction.cpp @@ -16,6 +16,7 @@ #include "mozilla/gfx/2D.h" #include "nsAttrValue.h" #include "nsAttrValueInlines.h" +#include "nsAttrValueOrString.h" using namespace mozilla::dom; using namespace mozilla::dom::SVGAngle_Binding; @@ -150,15 +151,15 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromBasicAttrs( if (HasAttr(nsGkAtoms::values)) { // Generate path based on our values array mPathSourceType = ePathSourceType_ValuesAttr; - const nsAString& valuesStr = GetAttr(nsGkAtoms::values)->GetStringValue(); + nsAttrValueOrString valuesVal(GetAttr(nsGkAtoms::values)); SVGMotionSMILPathUtils::MotionValueParser parser(&pathGenerator, &mPathVertices); - success = SMILParserUtils::ParseValuesGeneric(valuesStr, parser); + success = SMILParserUtils::ParseValuesGeneric(valuesVal.String(), parser); } else if (HasAttr(nsGkAtoms::to) || HasAttr(nsGkAtoms::by)) { // Apply 'from' value (or a dummy 0,0 'from' value) if (HasAttr(nsGkAtoms::from)) { - const nsAString& fromStr = GetAttr(nsGkAtoms::from)->GetStringValue(); - success = pathGenerator.MoveToAbsolute(fromStr); + nsAttrValueOrString fromVal(GetAttr(nsGkAtoms::from)); + success = pathGenerator.MoveToAbsolute(fromVal.String()); if (!mPathVertices.AppendElement(0.0, fallible)) { success = false; } @@ -181,12 +182,12 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromBasicAttrs( double dist; if (HasAttr(nsGkAtoms::to)) { mPathSourceType = ePathSourceType_ToAttr; - const nsAString& toStr = GetAttr(nsGkAtoms::to)->GetStringValue(); - success = pathGenerator.LineToAbsolute(toStr, dist); + nsAttrValueOrString toVal(GetAttr(nsGkAtoms::to)); + success = pathGenerator.LineToAbsolute(toVal.String(), dist); } else { // HasAttr(nsGkAtoms::by) mPathSourceType = ePathSourceType_ByAttr; - const nsAString& byStr = GetAttr(nsGkAtoms::by)->GetStringValue(); - success = pathGenerator.LineToRelative(byStr, dist); + nsAttrValueOrString byVal(GetAttr(nsGkAtoms::by)); + success = pathGenerator.LineToRelative(byVal.String(), dist); } if (success) { if (!mPathVertices.AppendElement(dist, fallible)) { @@ -227,7 +228,7 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromMpathElem( } void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromPathAttr() { - const nsAString& pathSpec = GetAttr(nsGkAtoms::path)->GetStringValue(); + nsString pathSpec(nsAttrValueOrString(GetAttr(nsGkAtoms::path)).String()); mPathSourceType = ePathSourceType_PathAttr; // Generate Path from |path| attr