From 798a9d84fa64412c398ffb81d29871afac1b744b Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Wed, 29 Sep 2021 07:24:44 +0000 Subject: [PATCH] Bug 1729329 - Make txExecutionState::addInstruction return the added instruction. r=farre Differential Revision: https://phabricator.services.mozilla.com/D124678 --- dom/xslt/xslt/txStylesheet.cpp | 2 +- dom/xslt/xslt/txStylesheetCompileHandlers.cpp | 247 +++++++----------- dom/xslt/xslt/txStylesheetCompiler.cpp | 7 +- dom/xslt/xslt/txStylesheetCompiler.h | 7 +- 4 files changed, 105 insertions(+), 158 deletions(-) diff --git a/dom/xslt/xslt/txStylesheet.cpp b/dom/xslt/xslt/txStylesheet.cpp index 433c2d403b0f..08aa532981a1 100644 --- a/dom/xslt/xslt/txStylesheet.cpp +++ b/dom/xslt/xslt/txStylesheet.cpp @@ -351,7 +351,7 @@ nsresult txStylesheet::addTemplate(txTemplateItem* aTemplate, aImportFrame->mMatchableTemplates.get(aTemplate->mMode); if (!templates) { - UniquePtr > newList( + UniquePtr> newList( new nsTArray); nsresult rv = aImportFrame->mMatchableTemplates.set(aTemplate->mMode, newList.get()); diff --git a/dom/xslt/xslt/txStylesheetCompileHandlers.cpp b/dom/xslt/xslt/txStylesheetCompileHandlers.cpp index d1ea98615736..c76397794bc6 100644 --- a/dom/xslt/xslt/txStylesheetCompileHandlers.cpp +++ b/dom/xslt/xslt/txStylesheetCompileHandlers.cpp @@ -96,8 +96,7 @@ static nsresult parseUseAttrSets(txStylesheetAttr* aAttributes, rv = name.init(tok.nextToken(), aState.mElementContext->mMappings, false); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr instr(new txInsertAttrSet(name)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(name)); } return NS_OK; } @@ -305,6 +304,16 @@ static nsresult getCharAttr(txStylesheetAttr* aAttributes, int32_t aAttrCount, return NS_OK; } +static void pushInstruction(txStylesheetCompilerState& aState, + UniquePtr aInstruction) { + aState.pushObject(aInstruction.release()); +} + +template +static UniquePtr popInstruction(txStylesheetCompilerState& aState) { + return UniquePtr(static_cast(aState.popObject())); +} + /** * Ignore and error handlers */ @@ -448,8 +457,7 @@ static nsresult txFnEndLREStylesheet(txStylesheetCompilerState& aState) { aState.popHandlerTable(); - UniquePtr instr(new txReturn()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); aState.closeInstructionContainer(); @@ -532,8 +540,7 @@ static nsresult txFnStartAttributeSet(int32_t aNamespaceID, nsAtom* aLocalName, static nsresult txFnEndAttributeSet(txStylesheetCompilerState& aState) { aState.popHandlerTable(); - UniquePtr instr(new txReturn()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); aState.closeInstructionContainer(); @@ -951,8 +958,7 @@ static nsresult txFnStartTemplate(int32_t aNamespaceID, nsAtom* aLocalName, static nsresult txFnEndTemplate(txStylesheetCompilerState& aState) { aState.popHandlerTable(); - UniquePtr instr(new txReturn()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); aState.closeInstructionContainer(); @@ -1005,8 +1011,7 @@ static nsresult txFnEndTopVariable(txStylesheetCompilerState& aState) { var->mValue = MakeUnique(u""_ns); } else if (!var->mValue) { // If we don't have a select-expression there mush be children. - UniquePtr instr(new txReturn()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); } aState.closeInstructionContainer(); @@ -1052,9 +1057,8 @@ static nsresult txFnStartLRE(int32_t aNamespaceID, nsAtom* aLocalName, txStylesheetCompilerState& aState) { nsresult rv = NS_OK; - UniquePtr instr( - new txStartLREElement(aNamespaceID, aLocalName, aPrefix)); - aState.addInstruction(std::move(instr)); + aState.addInstruction( + MakeUnique(aNamespaceID, aLocalName, aPrefix)); rv = parseExcludeResultPrefixes(aAttributes, aAttrCount, kNameSpaceID_XSLT); NS_ENSURE_SUCCESS(rv, rv); @@ -1079,17 +1083,15 @@ static nsresult txFnStartLRE(int32_t aNamespaceID, nsAtom* aLocalName, rv = txExprParser::createAVT(attr->mValue, &aState, getter_Transfers(avt)); NS_ENSURE_SUCCESS(rv, rv); - instr = MakeUnique(attr->mNamespaceID, attr->mLocalName, - attr->mPrefix, std::move(avt)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique( + attr->mNamespaceID, attr->mLocalName, attr->mPrefix, std::move(avt))); } return NS_OK; } static nsresult txFnEndLRE(txStylesheetCompilerState& aState) { - UniquePtr instr(new txEndElement); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); return NS_OK; } @@ -1103,8 +1105,7 @@ static nsresult txFnText(const nsAString& aStr, txStylesheetCompilerState& aState) { TX_RETURN_IF_WHITESPACE(aStr, aState); - UniquePtr instr(new txText(aStr, false)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(aStr, false)); return NS_OK; } @@ -1120,11 +1121,8 @@ static nsresult txFnStartApplyImports(int32_t aNamespaceID, nsAtom* aLocalName, txStylesheetAttr* aAttributes, int32_t aAttrCount, txStylesheetCompilerState& aState) { - UniquePtr instr(new txApplyImportsStart); - aState.addInstruction(std::move(instr)); - - instr = MakeUnique(); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); + aState.addInstruction(MakeUnique()); aState.pushHandlerTable(gTxIgnoreHandler); @@ -1154,15 +1152,14 @@ static nsresult txFnStartApplyTemplates(int32_t aNamespaceID, txStylesheetCompilerState& aState) { nsresult rv = NS_OK; - UniquePtr instr(new txPushParams); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); txExpandedName mode; rv = getQNameAttr(aAttributes, aAttrCount, nsGkAtoms::mode, false, aState, mode); NS_ENSURE_SUCCESS(rv, rv); - aState.pushObject(new txApplyTemplates(mode)); + pushInstruction(aState, MakeUnique(mode)); UniquePtr select; rv = getExprAttr(aAttributes, aAttrCount, nsGkAtoms::select, false, aState, @@ -1177,7 +1174,7 @@ static nsresult txFnStartApplyTemplates(int32_t aNamespaceID, UniquePtr pushcontext( new txPushNewContext(std::move(select))); aState.pushSorter(pushcontext.get()); - aState.pushObject(pushcontext.release()); + pushInstruction(aState, std::move(pushcontext)); aState.pushHandlerTable(gTxApplyTemplatesHandler); @@ -1188,23 +1185,15 @@ static nsresult txFnEndApplyTemplates(txStylesheetCompilerState& aState) { aState.popHandlerTable(); txPushNewContext* pushcontext = - static_cast(aState.popObject()); - UniquePtr instr(pushcontext); // txPushNewContext - aState.addInstruction(std::move(instr)); + aState.addInstruction(popInstruction(aState)); aState.popSorter(); - instr = WrapUnique( - static_cast(aState.popObject())); // txApplyTemplates - UniquePtr loop(new txLoopNodeSet(instr.get())); - aState.addInstruction(std::move(instr)); + // txApplyTemplates + txInstruction* instr = aState.addInstruction(popInstruction(aState)); + aState.addInstruction(MakeUnique(instr)); - instr = std::move(loop); - aState.addInstruction(std::move(instr)); - - instr = MakeUnique(); - pushcontext->mBailTarget = instr.get(); - aState.addInstruction(std::move(instr)); + pushcontext->mBailTarget = aState.addInstruction(MakeUnique()); return NS_OK; } @@ -1223,8 +1212,7 @@ static nsresult txFnStartAttribute(int32_t aNamespaceID, nsAtom* aLocalName, txStylesheetCompilerState& aState) { nsresult rv = NS_OK; - UniquePtr instr(new txPushStringHandler(true)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(true)); UniquePtr name; rv = getAVTAttr(aAttributes, aAttrCount, nsGkAtoms::name, true, aState, name); @@ -1235,8 +1223,9 @@ static nsresult txFnStartAttribute(int32_t aNamespaceID, nsAtom* aLocalName, nspace); NS_ENSURE_SUCCESS(rv, rv); - aState.pushObject(new txAttribute(std::move(name), std::move(nspace), - aState.mElementContext->mMappings)); + pushInstruction(aState, + MakeUnique(std::move(name), std::move(nspace), + aState.mElementContext->mMappings)); // We need to push the template-handler since the current might be // the attributeset-handler @@ -1247,9 +1236,7 @@ static nsresult txFnStartAttribute(int32_t aNamespaceID, nsAtom* aLocalName, static nsresult txFnEndAttribute(txStylesheetCompilerState& aState) { aState.popHandlerTable(); - UniquePtr instr( - static_cast(aState.popObject())); - aState.addInstruction(std::move(instr)); + aState.addInstruction(popInstruction(aState)); return NS_OK; } @@ -1269,15 +1256,14 @@ static nsresult txFnStartCallTemplate(int32_t aNamespaceID, nsAtom* aLocalName, txStylesheetCompilerState& aState) { nsresult rv = NS_OK; - UniquePtr instr(new txPushParams); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); txExpandedName name; rv = getQNameAttr(aAttributes, aAttrCount, nsGkAtoms::name, true, aState, name); NS_ENSURE_SUCCESS(rv, rv); - aState.pushObject(new txCallTemplate(name)); + pushInstruction(aState, MakeUnique(name)); aState.pushHandlerTable(gTxCallTemplateHandler); @@ -1288,12 +1274,9 @@ static nsresult txFnEndCallTemplate(txStylesheetCompilerState& aState) { aState.popHandlerTable(); // txCallTemplate - UniquePtr instr( - static_cast(aState.popObject())); - aState.addInstruction(std::move(instr)); + aState.addInstruction(popInstruction(aState)); - instr = MakeUnique(); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); return NS_OK; } @@ -1349,15 +1332,13 @@ static nsresult txFnStartComment(int32_t aNamespaceID, nsAtom* aLocalName, nsAtom* aPrefix, txStylesheetAttr* aAttributes, int32_t aAttrCount, txStylesheetCompilerState& aState) { - UniquePtr instr(new txPushStringHandler(true)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(true)); return NS_OK; } static nsresult txFnEndComment(txStylesheetCompilerState& aState) { - UniquePtr instr(new txComment); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); return NS_OK; } @@ -1375,24 +1356,16 @@ static nsresult txFnStartCopy(int32_t aNamespaceID, nsAtom* aLocalName, nsAtom* aPrefix, txStylesheetAttr* aAttributes, int32_t aAttrCount, txStylesheetCompilerState& aState) { - UniquePtr copy(new txCopy); - aState.pushPtr(copy.get(), aState.eCopy); - - UniquePtr instr(copy.release()); - aState.addInstruction(std::move(instr)); + aState.pushPtr(aState.addInstruction(MakeUnique()), aState.eCopy); return parseUseAttrSets(aAttributes, aAttrCount, false, aState); } static nsresult txFnEndCopy(txStylesheetCompilerState& aState) { - UniquePtr instr(new txEndElement); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); txCopy* copy = static_cast(aState.popPtr(aState.eCopy)); - nsresult rv = aState.addGotoTarget(©->mBailTarget); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; + return aState.addGotoTarget(©->mBailTarget); } /* @@ -1411,8 +1384,7 @@ static nsresult txFnStartCopyOf(int32_t aNamespaceID, nsAtom* aLocalName, select); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr instr(new txCopyOf(std::move(select))); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(std::move(select))); aState.pushHandlerTable(gTxIgnoreHandler); @@ -1447,9 +1419,8 @@ static nsresult txFnStartElement(int32_t aNamespaceID, nsAtom* aLocalName, nspace); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr instr(new txStartElement( + aState.addInstruction(MakeUnique( std::move(name), std::move(nspace), aState.mElementContext->mMappings)); - aState.addInstruction(std::move(instr)); rv = parseUseAttrSets(aAttributes, aAttrCount, false, aState); NS_ENSURE_SUCCESS(rv, rv); @@ -1458,8 +1429,7 @@ static nsresult txFnStartElement(int32_t aNamespaceID, nsAtom* aLocalName, } static nsresult txFnEndElement(txStylesheetCompilerState& aState) { - UniquePtr instr(new txEndElement); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); return NS_OK; } @@ -1509,17 +1479,13 @@ static nsresult txFnStartForEach(int32_t aNamespaceID, nsAtom* aLocalName, select); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr pushcontext( - new txPushNewContext(std::move(select))); - aState.pushPtr(pushcontext.get(), aState.ePushNewContext); - aState.pushSorter(pushcontext.get()); + txPushNewContext* pushcontext = + aState.addInstruction(MakeUnique(std::move(select))); + aState.pushPtr(pushcontext, aState.ePushNewContext); + aState.pushSorter(pushcontext); - aState.addInstruction(std::move(pushcontext)); - - auto rule = MakeUnique(); - aState.pushPtr(rule.get(), aState.ePushNullTemplateRule); - - aState.addInstruction(std::move(rule)); + aState.pushPtr(aState.addInstruction(MakeUnique()), + aState.ePushNullTemplateRule); aState.pushHandlerTable(gTxForEachHandler); @@ -1533,8 +1499,7 @@ static nsresult txFnEndForEach(txStylesheetCompilerState& aState) { txInstruction* pnullrule = static_cast(aState.popPtr(aState.ePushNullTemplateRule)); - UniquePtr instr(new txLoopNodeSet(pnullrule)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(pnullrule)); aState.popSorter(); txPushNewContext* pushcontext = @@ -1580,11 +1545,9 @@ static nsresult txFnStartIf(int32_t aNamespaceID, nsAtom* aLocalName, getExprAttr(aAttributes, aAttrCount, nsGkAtoms::test, true, aState, test); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr condGoto( - new txConditionalGoto(std::move(test), nullptr)); - aState.pushPtr(condGoto.get(), aState.eConditionalGoto); - - aState.addInstruction(std::move(condGoto)); + aState.pushPtr(aState.addInstruction( + MakeUnique(std::move(test), nullptr)), + aState.eConditionalGoto); return NS_OK; } @@ -1606,23 +1569,20 @@ static nsresult txFnStartMessage(int32_t aNamespaceID, nsAtom* aLocalName, nsAtom* aPrefix, txStylesheetAttr* aAttributes, int32_t aAttrCount, txStylesheetCompilerState& aState) { - UniquePtr instr(new txPushStringHandler(false)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(false)); txThreeState term; nsresult rv = getYesNoAttr(aAttributes, aAttrCount, nsGkAtoms::terminate, false, aState, term); NS_ENSURE_SUCCESS(rv, rv); - aState.pushObject(new txMessage(term == eTrue)); + pushInstruction(aState, MakeUnique(term == eTrue)); return NS_OK; } static nsresult txFnEndMessage(txStylesheetCompilerState& aState) { - UniquePtr instr( - static_cast(aState.popObject())); - aState.addInstruction(std::move(instr)); + aState.addInstruction(popInstruction(aState)); return NS_OK; } @@ -1692,11 +1652,10 @@ static nsresult txFnStartNumber(int32_t aNamespaceID, nsAtom* aLocalName, aState, groupingSize); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr instr( - new txNumber(level, std::move(count), std::move(from), std::move(value), - std::move(format), std::move(groupingSeparator), - std::move(groupingSize))); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique( + level, std::move(count), std::move(from), std::move(value), + std::move(format), std::move(groupingSeparator), + std::move(groupingSize))); aState.pushHandlerTable(gTxIgnoreHandler); @@ -1751,18 +1710,16 @@ static nsresult txFnStartParam(int32_t aNamespaceID, nsAtom* aLocalName, name); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr checkParam(new txCheckParam(name)); - - aState.pushPtr(checkParam.get(), aState.eCheckParam); - - aState.addInstruction(std::move(checkParam)); + aState.pushPtr(aState.addInstruction(MakeUnique(name)), + aState.eCheckParam); UniquePtr select; rv = getExprAttr(aAttributes, aAttrCount, nsGkAtoms::select, false, aState, select); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr var(new txSetVariable(name, std::move(select))); + UniquePtr var = + MakeUnique(name, std::move(select)); if (var->mValue) { // XXX should be gTxErrorHandler? aState.pushHandlerTable(gTxIgnoreHandler); @@ -1770,13 +1727,13 @@ static nsresult txFnStartParam(int32_t aNamespaceID, nsAtom* aLocalName, aState.pushHandlerTable(gTxVariableHandler); } - aState.pushObject(var.release()); + pushInstruction(aState, std::move(var)); return NS_OK; } static nsresult txFnEndParam(txStylesheetCompilerState& aState) { - UniquePtr var(static_cast(aState.popObject())); + UniquePtr var = popInstruction(aState); txHandlerTable* prev = aState.mHandlerTable; aState.popHandlerTable(); @@ -1789,8 +1746,7 @@ static nsresult txFnEndParam(txStylesheetCompilerState& aState) { nsresult rv = aState.addVariable(var->mName); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr instr(var.release()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(std::move(var)); txCheckParam* checkParam = static_cast(aState.popPtr(aState.eCheckParam)); @@ -1810,23 +1766,20 @@ static nsresult txFnStartPI(int32_t aNamespaceID, nsAtom* aLocalName, nsAtom* aPrefix, txStylesheetAttr* aAttributes, int32_t aAttrCount, txStylesheetCompilerState& aState) { - UniquePtr instr(new txPushStringHandler(true)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(true)); UniquePtr name; nsresult rv = getAVTAttr(aAttributes, aAttrCount, nsGkAtoms::name, true, aState, name); NS_ENSURE_SUCCESS(rv, rv); - aState.pushObject(new txProcessingInstruction(std::move(name))); + pushInstruction(aState, MakeUnique(std::move(name))); return NS_OK; } static nsresult txFnEndPI(txStylesheetCompilerState& aState) { - UniquePtr instr( - static_cast(aState.popObject())); - aState.addInstruction(std::move(instr)); + aState.addInstruction(popInstruction(aState)); return NS_OK; } @@ -1919,8 +1872,7 @@ static nsresult txFnEndText(txStylesheetCompilerState& aState) { static nsresult txFnTextText(const nsAString& aStr, txStylesheetCompilerState& aState) { - UniquePtr instr(new txText(aStr, aState.mDOE)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(aStr, aState.mDOE)); return NS_OK; } @@ -1946,9 +1898,7 @@ static nsresult txFnStartValueOf(int32_t aNamespaceID, nsAtom* aLocalName, select); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr instr( - new txValueOf(std::move(select), doe == eTrue)); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique(std::move(select), doe == eTrue)); aState.pushHandlerTable(gTxIgnoreHandler); @@ -1984,7 +1934,8 @@ static nsresult txFnStartVariable(int32_t aNamespaceID, nsAtom* aLocalName, select); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr var(new txSetVariable(name, std::move(select))); + UniquePtr var = + MakeUnique(name, std::move(select)); if (var->mValue) { // XXX should be gTxErrorHandler? aState.pushHandlerTable(gTxIgnoreHandler); @@ -1992,13 +1943,13 @@ static nsresult txFnStartVariable(int32_t aNamespaceID, nsAtom* aLocalName, aState.pushHandlerTable(gTxVariableHandler); } - aState.pushObject(var.release()); + pushInstruction(aState, std::move(var)); return NS_OK; } static nsresult txFnEndVariable(txStylesheetCompilerState& aState) { - UniquePtr var(static_cast(aState.popObject())); + UniquePtr var = popInstruction(aState); txHandlerTable* prev = aState.mHandlerTable; aState.popHandlerTable(); @@ -2012,8 +1963,7 @@ static nsresult txFnEndVariable(txStylesheetCompilerState& aState) { nsresult rv = aState.addVariable(var->mName); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr instr(var.release()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(std::move(var)); return NS_OK; } @@ -2023,8 +1973,7 @@ static nsresult txFnStartElementStartRTF(int32_t aNamespaceID, txStylesheetAttr* aAttributes, int32_t aAttrCount, txStylesheetCompilerState& aState) { - UniquePtr instr(new txPushRTFHandler); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); aState.mHandlerTable = gTxTemplateHandler; @@ -2035,8 +1984,7 @@ static nsresult txFnTextStartRTF(const nsAString& aStr, txStylesheetCompilerState& aState) { TX_RETURN_IF_WHITESPACE(aStr, aState); - UniquePtr instr(new txPushRTFHandler); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); aState.mHandlerTable = gTxTemplateHandler; @@ -2059,11 +2007,9 @@ static nsresult txFnStartWhen(int32_t aNamespaceID, nsAtom* aLocalName, getExprAttr(aAttributes, aAttrCount, nsGkAtoms::test, true, aState, test); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr condGoto( - new txConditionalGoto(std::move(test), nullptr)); - aState.pushPtr(condGoto.get(), aState.eConditionalGoto); - - aState.addInstruction(std::move(condGoto)); + aState.pushPtr(aState.addInstruction( + MakeUnique(std::move(test), nullptr)), + aState.eConditionalGoto); aState.pushHandlerTable(gTxTemplateHandler); @@ -2072,11 +2018,8 @@ static nsresult txFnStartWhen(int32_t aNamespaceID, nsAtom* aLocalName, static nsresult txFnEndWhen(txStylesheetCompilerState& aState) { aState.popHandlerTable(); - UniquePtr gotoinstr(new txGoTo(nullptr)); - aState.mChooseGotoList->add(gotoinstr.get()); - - UniquePtr instr(gotoinstr.release()); - aState.addInstruction(std::move(instr)); + aState.mChooseGotoList->add( + aState.addInstruction(MakeUnique(nullptr))); txConditionalGoto* condGoto = static_cast(aState.popPtr(aState.eConditionalGoto)); @@ -2110,7 +2053,7 @@ static nsresult txFnStartWithParam(int32_t aNamespaceID, nsAtom* aLocalName, select); NS_ENSURE_SUCCESS(rv, rv); - UniquePtr var(new txSetParam(name, std::move(select))); + UniquePtr var = MakeUnique(name, std::move(select)); if (var->mValue) { // XXX should be gTxErrorHandler? aState.pushHandlerTable(gTxIgnoreHandler); @@ -2118,13 +2061,13 @@ static nsresult txFnStartWithParam(int32_t aNamespaceID, nsAtom* aLocalName, aState.pushHandlerTable(gTxVariableHandler); } - aState.pushObject(var.release()); + pushInstruction(aState, std::move(var)); return NS_OK; } static nsresult txFnEndWithParam(txStylesheetCompilerState& aState) { - UniquePtr var(static_cast(aState.popObject())); + UniquePtr var = popInstruction(aState); txHandlerTable* prev = aState.mHandlerTable; aState.popHandlerTable(); @@ -2134,8 +2077,7 @@ static nsresult txFnEndWithParam(txStylesheetCompilerState& aState) { var->mValue = MakeUnique(u""_ns); } - UniquePtr instr(var.release()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(std::move(var)); return NS_OK; } @@ -2170,8 +2112,7 @@ static nsresult txFnEndUnknownInstruction(txStylesheetCompilerState& aState) { aState.popHandlerTable(); if (aState.mSearchingForFallback) { - UniquePtr instr(new txErrorInstruction()); - aState.addInstruction(std::move(instr)); + aState.addInstruction(MakeUnique()); } aState.mSearchingForFallback = false; diff --git a/dom/xslt/xslt/txStylesheetCompiler.cpp b/dom/xslt/xslt/txStylesheetCompiler.cpp index 6f11ee8f155a..7d15933343a3 100644 --- a/dom/xslt/xslt/txStylesheetCompiler.cpp +++ b/dom/xslt/xslt/txStylesheetCompiler.cpp @@ -293,8 +293,7 @@ nsresult txStylesheetCompiler::endElement() { for (i = mInScopeVariables.Length() - 1; i >= 0; --i) { txInScopeVariable* var = mInScopeVariables[i]; if (!--(var->mLevel)) { - UniquePtr instr(new txRemoveVariable(var->mName)); - addInstruction(std::move(instr)); + addInstruction(MakeUnique(var->mName)); mInScopeVariables.RemoveElementAt(i); delete var; @@ -607,7 +606,7 @@ void txStylesheetCompilerState::closeInstructionContainer() { mNextInstrPtr = 0; } -void txStylesheetCompilerState::addInstruction( +txInstruction* txStylesheetCompilerState::addInstruction( UniquePtr&& aInstruction) { MOZ_ASSERT(mNextInstrPtr, "adding instruction outside container"); @@ -621,6 +620,8 @@ void txStylesheetCompilerState::addInstruction( *mGotoTargetPointers[i] = newInstr; } mGotoTargetPointers.Clear(); + + return newInstr; } nsresult txStylesheetCompilerState::loadIncludedStylesheet( diff --git a/dom/xslt/xslt/txStylesheetCompiler.h b/dom/xslt/xslt/txStylesheetCompiler.h index 7ab5852178e0..5a00477092b8 100644 --- a/dom/xslt/xslt/txStylesheetCompiler.h +++ b/dom/xslt/xslt/txStylesheetCompiler.h @@ -102,7 +102,12 @@ class txStylesheetCompilerState : public txIParseContext { void addToplevelItem(txToplevelItem* aItem); nsresult openInstructionContainer(txInstructionContainer* aContainer); void closeInstructionContainer(); - void addInstruction(mozilla::UniquePtr&& aInstruction); + txInstruction* addInstruction( + mozilla::UniquePtr&& aInstruction); + template + T* addInstruction(mozilla::UniquePtr aInstruction) { + return static_cast(addInstruction(std::move(aInstruction))); + } nsresult loadIncludedStylesheet(const nsAString& aURI); nsresult loadImportedStylesheet(const nsAString& aURI, txStylesheet::ImportFrame* aFrame);