[XForms] index() with no repeat should return NaN. Bug 334018, r=me, sr=sicking

This commit is contained in:
allan%beaufour.dk 2006-05-29 08:41:16 +00:00
parent 0ba372b7aa
commit 3a0e3e1a34
3 changed files with 27 additions and 9 deletions

View File

@ -66,7 +66,7 @@ class nsIXFormsModelElement; /* forward declaration */
NS_IMETHOD IsNodeAssocWithModel(nsIDOMNode *aNode, nsIDOMNode *aModel, PRBool *_retval); \
NS_IMETHOD GetInstanceDocumentRoot(const nsAString & aID, nsIDOMNode *aModelNode, nsIDOMNode **_retval); \
NS_IMETHOD ValidateString(const nsAString & aValue, const nsAString & aType, const nsAString & aNamespace, PRBool *_retval); \
NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex); \
NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRInt32 *aIndex); \
NS_IMETHOD GetMonths(const nsAString & aValue, PRInt32 *aMonths); \
NS_IMETHOD GetSeconds(const nsAString & aValue, double *aSeconds); \
NS_IMETHOD GetSecondsFromDateTime(const nsAString & aValue, double *aSeconds); \
@ -124,8 +124,8 @@ class NS_NO_VTABLE nsIXFormsUtilityService : public nsISupports {
/**
* Function to retrieve the index from the given repeat element.
*/
/* unsigned long getRepeatIndex (in nsIDOMNode aRepeat); */
NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex) = 0;
/* long getRepeatIndex (in nsIDOMNode aRepeat); */
NS_IMETHOD GetRepeatIndex(nsIDOMNode *aRepeat, PRInt32 *aIndex) = 0;
/**
* Function to retrieve the number of months represented by the

View File

@ -228,11 +228,21 @@ XFormsFunctionCall::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
do_GetService("@mozilla.org/xforms-utility-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 index;
PRInt32 index = 0;
double res = Double::NaN;
rv = xformsService->GetRepeatIndex(repeatEle, &index);
NS_ENSURE_SUCCESS(rv, rv);
return aContext->recycler()->getNumberResult(index, aResult);
if (index >= 0) {
// repeat's index is 1-based. If it is 0, then that is still ok since
// repeat's index can be 0 if uninitialized or if the nodeset that it
// is bound to is empty (either initially or due to delete remove all
// of the instance nodes). If index == -1, then repeatEle isn't an
// XForms repeat element, so we need to return NaN per spec.
res = index;
}
return aContext->recycler()->getNumberResult(res, aResult);
}
case INSTANCE:

View File

@ -196,16 +196,24 @@ nsXFormsUtilityService::ValidateString(const nsAString & aValue,
}
NS_IMETHODIMP
nsXFormsUtilityService::GetRepeatIndex(nsIDOMNode *aRepeat, PRUint32 *aIndex)
nsXFormsUtilityService::GetRepeatIndex(nsIDOMNode *aRepeat, PRInt32 *aIndex)
{
NS_ASSERTION(aIndex, "no return buffer for index, we'll crash soon");
*aIndex = 0;
nsCOMPtr<nsIXFormsRepeatElement> repeatEle = do_QueryInterface(aRepeat);
if (!repeatEle) {
// if aRepeat isn't a repeat element, then setting aIndex to -1 to tell
// XPath to return NaN. Per 7.8.5 in the spec (1.0, 2nd edition)
*aIndex = -1;
} else {
PRUint32 retIndex = 0;
nsresult rv = repeatEle->GetIndex(&retIndex);
NS_ENSURE_SUCCESS(rv, rv);
*aIndex = retIndex;
}
///
/// @bug This should somehow end up in a NaN per the XForms 1.0 Errata (XXX)
return repeatEle ? repeatEle->GetIndex(aIndex) : NS_OK;
return NS_OK;
}
NS_IMETHODIMP