Closed
Bug 418734
Opened 18 years ago
Closed 18 years ago
[1.1] Implement XPath function: context()
Categories
(Core Graveyard :: XForms, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: msterlin, Assigned: msterlin)
Details
(Keywords: fixed1.8.1.17)
Attachments
(3 files, 6 obsolete files)
|
2.63 KB,
text/xml
|
Details | |
|
9.93 KB,
patch
|
Details | Diff | Splinter Review | |
|
10.65 KB,
patch
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b4pre) Gecko/2008020507 Minefield/3.0b4pre
We need to implement the XPath function context().
Reproducible: Always
| Assignee | ||
Comment 1•18 years ago
|
||
| Assignee | ||
Comment 2•18 years ago
|
||
Note that context is a reserved word in .idl so we have to rewrite the expression to rename the function to be called. The real function is named contextNode.
Attachment #304625 -
Flags: review?(aaronr)
| Assignee | ||
Comment 3•18 years ago
|
||
Assignee: nobody → msterlin
Status: UNCONFIRMED → NEW
Ever confirmed: true
| Assignee | ||
Updated•18 years ago
|
Status: NEW → ASSIGNED
Comment on attachment 304625 [details] [diff] [review]
patch
>Index: nsXFormsUtils.cpp
>===================================================================
>+ if (start != kNotFound) {
>+ if (start > 0) {
>+ // Append any part of the expression before 'context()'
>+ expr.Append(Substring(aExpression, start));
>+ }
>+ // Replace 'context()' with 'contextNode()'
>+ expr.AppendLiteral("contextNode()");
>+ if (start + contextExpr.Length() > aExpression.Length()) {
>+ // Append any remaining part of the expression after 'context()'
>+ expr.Append(Substring(aExpression, start + contextExpr.Length()));
>+ }
shouldn't that be '<'? And shouldn't your Substring call begin at start+contextExpr.Length() and not end there?
>Index: nsXFormsXPathFunctions.cpp
>===================================================================
>+NS_IMETHODIMP
>+nsXFormsXPathFunctions::ContextNode(txIFunctionEvaluationContext *aContext,
>+ txINodeSet **aResult)
>+{
...
>+
>+ // Get the context node of the xforms node.
>+ nsCOMPtr<nsIDOMNode> contextNode;
>+ PRUint32 contextNodesetSize = 0;
>+ PRInt32 contextPosition;
>+ nsCOMPtr<nsIModelElementPrivate> model;
>+ nsCOMPtr<nsIDOMElement> bindElement;
>+ nsCOMPtr<nsIXFormsControl> parentControl;
>+ PRBool outerBind;
>+
>+ nsCOMPtr<nsIDOMElement> element(do_QueryInterface(xfNode));
>+ if (!element) {
>+ result.swap(*aResult);
>+ return NS_OK;
>+ }
nit: this failure should never, ever happen since our xpath ns resolver node should always be an element. But if it does, it is more serious than returning a successful return code and an empty nodeset. I'd say either NS_ENSURE_TRUE(element, NS_ERROR_FAILURE) like you do if there is no xfNode or just don't do a check for element (in a similar situation in ::Index we do just that...assume the QI worked).
Also by eliminating the need to be able to return an empty nodeset in case of error, you can now move the do_CreateInstance down to after the return code check for GetNodeContext. That way we don't do this create instance until we know we've passed all of our error checks.
r-'ing for the logic error and Substring error above.
Attachment #304625 -
Flags: review?(aaronr) → review-
| Assignee | ||
Comment 5•18 years ago
|
||
(In reply to comment #4)
> (From update of attachment 304625 [details] [diff] [review])
> >Index: nsXFormsUtils.cpp
> >===================================================================
> >+ if (start != kNotFound) {
> >+ if (start > 0) {
> >+ // Append any part of the expression before 'context()'
> >+ expr.Append(Substring(aExpression, start));
> >+ }
> >+ // Replace 'context()' with 'contextNode()'
> >+ expr.AppendLiteral("contextNode()");
> >+ if (start + contextExpr.Length() > aExpression.Length()) {
> >+ // Append any remaining part of the expression after 'context()'
> >+ expr.Append(Substring(aExpression, start + contextExpr.Length()));
> >+ }
> shouldn't that be '<'? And shouldn't your Substring call begin at
> start+contextExpr.Length() and not end there?
No, it should be > 0. Find returns the starting index of the string so if the result is zero then the expression starts with context() and there are no characters before it that must be copied to the new expression.
The Substring call is wrong though; I was looking at the wrong overload and expected it to be the substring starting at zero and going for 'count' characters. Just need to change it to Substring(aExpression, 0, start).
| Assignee | ||
Comment 6•18 years ago
|
||
Fixing Substring call; rearranging code in ContextNode() function per Aaron's review comments.
Attachment #304625 -
Attachment is obsolete: true
Attachment #304777 -
Flags: review?(aaronr)
| Assignee | ||
Comment 7•18 years ago
|
||
Attachment #304777 -
Attachment is obsolete: true
Attachment #304793 -
Flags: review?(aaronr)
Attachment #304777 -
Flags: review?(aaronr)
Comment on attachment 304793 [details] [diff] [review]
patch3
Looks like you forgot the other EvaluateXPath in nsxformsutils.cpp. Which means you should probably separate out the logic into a separate function. Especially if we'll have to do something similar for id().
Attachment #304793 -
Flags: review?(aaronr) → review-
| Assignee | ||
Comment 9•18 years ago
|
||
Created a separate function, TranslateExpression, to do the work of rewriting the XPath expression so it can be called by both versions of EvaluateXPath.
Attachment #304793 -
Attachment is obsolete: true
Attachment #304863 -
Flags: review?(aaronr)
Comment 10•18 years ago
|
||
Comment on attachment 304863 [details] [diff] [review]
patch4
>Index: nsXFormsUtils.cpp
>===================================================================
>@@ -657,19 +663,25 @@ nsXFormsUtils::EvaluateXPath(nsIXPathEva
> nsIDOMXPathNSResolver *aResolver,
> nsIXFormsXPathState *aState,
> PRUint16 aResultType,
> PRInt32 aContextPosition,
> PRInt32 aContextSize,
> nsIDOMXPathResult *aInResult,
> nsIDOMXPathResult **aResult)
> {
>+ // If the XPath expression contains a function name that differs from its
>+ // internal name, translate the external name to the internal name.
>+ nsAutoString expr;
>+ nsresult rv = TranslateExpression(aExpression, expr);
>+ NS_ENSURE_SUCCESS(rv, rv);
>+
> nsCOMPtr<nsIDOMXPathExpression> expression;
>- nsresult rv = CreateExpression(aEvaluator, aExpression, aResolver, aState,
>- getter_AddRefs(expression));
>+ rv = CreateExpression(aEvaluator, aExpression, aResolver, aState,
>+ getter_AddRefs(expression));
Shouldn't you be passing 'expr' here and not aExpression?
with that, r=me
Attachment #304863 -
Flags: review?(aaronr) → review+
| Assignee | ||
Comment 11•18 years ago
|
||
(In reply to comment #10)
> >+ rv = CreateExpression(aEvaluator, aExpression, aResolver, aState,
> >+ getter_AddRefs(expression));
> Shouldn't you be passing 'expr' here and not aExpression?
> with that, r=me
Yep.
| Assignee | ||
Comment 12•18 years ago
|
||
Attachment #304863 -
Attachment is obsolete: true
Attachment #304868 -
Flags: review?(Olli.Pettay)
Comment 13•18 years ago
|
||
Comment on attachment 304868 [details] [diff] [review]
patch5
>+ txINodeSet contextNode(in txIFunctionEvaluationContext aContext);
Add a comment that contextNode is translated from context or something
>+ // context() is a valid XPath function but context is a reserved word
>+ // in .idl so we rename it to contextNode() if it exists.
>+ NS_NAMED_LITERAL_STRING(contextExpr, "context()");
Is context( ) a valid function call? Or context( ) ? or
context (). See http://www.w3.org/TR/xpath#exprlex .
I think context( ) is valid but context () isn't, because
there is possible expression in context((expr)?), although in this case it is empty.
Replacing context( with contextNode( should be ok, I guess.
With those fixed or otherwise addressed, r=me
Attachment #304868 -
Flags: review?(Olli.Pettay) → review+
| Assignee | ||
Comment 14•18 years ago
|
||
Only context() is valid but it can be part of a larger expression so I copy anything before it and after it to the renamed expression.
So context()/y becomes contextNode()/y.
| Assignee | ||
Updated•18 years ago
|
Attachment #304626 -
Flags: review?(aaronr)
| Assignee | ||
Updated•18 years ago
|
Attachment #304626 -
Flags: review?(Olli.Pettay)
Comment 15•18 years ago
|
||
Comment on attachment 304626 [details] [diff] [review]
patch for 1.8 branch
this is still the right patch for 1.8?
| Assignee | ||
Comment 16•18 years ago
|
||
(In reply to comment #15)
> (From update of attachment 304626 [details] [diff] [review])
> this is still the right patch for 1.8?
Yes, the 1.8 patch does not require renaming context() to contextNode() because the function is not defined using .idl.
Attachment #304626 -
Flags: review?(aaronr) → review+
Updated•18 years ago
|
Attachment #304626 -
Flags: review?(Olli.Pettay) → review+
Comment 17•18 years ago
|
||
Comment on attachment 304626 [details] [diff] [review]
patch for 1.8 branch
the branch patch affects the xforms xpath evaluator which is used only by xforms
Attachment #304626 -
Flags: superreview?(jonas)
| Assignee | ||
Comment 18•18 years ago
|
||
Updating to trunk.
Attachment #304868 -
Attachment is obsolete: true
Comment 19•18 years ago
|
||
checked into trunk for msterlin
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Whiteboard: xf-to-branch-11
Attachment #304626 -
Flags: superreview?(jonas) → superreview+
Comment 20•17 years ago
|
||
same as 1.8 branch patch, updated to current level
Attachment #304626 -
Attachment is obsolete: true
Comment 21•17 years ago
|
||
checked in 1.8 branch patch for msterlin
Keywords: fixed1.8.1.17
Whiteboard: xf-to-branch-11
Updated•9 years ago
|
Product: Core → Core Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•