зеркало из https://github.com/mozilla/pjs.git
Print messages in JS console for existing exceptions in code. Bug 289297, r=doron+smaug, a=mkaply
This commit is contained in:
Родитель
74ce3f0cf3
Коммит
2fafb291c7
|
@ -111,6 +111,9 @@ nsXFormsControlStub::ResetBoundNode()
|
|||
{
|
||||
mBoundNode = nsnull;
|
||||
|
||||
if (!mHasParent)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIModelElementPrivate> modelNode;
|
||||
nsCOMPtr<nsIDOMXPathResult> result;
|
||||
nsresult rv =
|
||||
|
@ -337,9 +340,10 @@ nsXFormsControlStub::DocumentChanged(nsIDOMDocument *aNewDocument)
|
|||
NS_IMETHODIMP
|
||||
nsXFormsControlStub::ParentChanged(nsIDOMElement *aNewParent)
|
||||
{
|
||||
mHasParent = aNewParent != nsnull;
|
||||
// We need to re-evaluate our instance data binding when our parent changes,
|
||||
// since xmlns declarations or our context could have changed.
|
||||
if (aNewParent) {
|
||||
if (mHasParent) {
|
||||
Bind();
|
||||
Refresh();
|
||||
}
|
||||
|
|
|
@ -114,7 +114,8 @@ public:
|
|||
nsIXTFElement::NOTIFY_DOCUMENT_CHANGED |
|
||||
nsIXTFElement::NOTIFY_PARENT_CHANGED |
|
||||
nsIXTFElement::NOTIFY_HANDLE_DEFAULT),
|
||||
kElementFlags(nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR)
|
||||
kElementFlags(nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR),
|
||||
mHasParent(PR_FALSE)
|
||||
{};
|
||||
|
||||
protected:
|
||||
|
@ -133,6 +134,9 @@ protected:
|
|||
/** This event listener is used to create xforms-hint and xforms-help events. */
|
||||
nsCOMPtr<nsIDOMEventListener> mEventListener;
|
||||
|
||||
/** State that tells whether control has a parent or not */
|
||||
PRBool mHasParent;
|
||||
|
||||
/** Returns the read only state of the control (ie. mBoundNode) */
|
||||
PRBool GetReadOnlyState();
|
||||
|
||||
|
|
|
@ -325,7 +325,7 @@ nsXFormsInputElement::UpdateInstanceData()
|
|||
NS_IMETHODIMP
|
||||
nsXFormsInputElement::Refresh()
|
||||
{
|
||||
if (!mControl || !mModel)
|
||||
if (!mControl || !mModel || !mHasParent)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString text;
|
||||
|
|
|
@ -329,7 +329,8 @@ nsXFormsModelElement::DoneAddingChildren()
|
|||
}
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
// this is a fatal error
|
||||
// this is a fatal error (XXX)
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaLoadError"), mElement);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -694,6 +695,7 @@ NS_IMETHODIMP
|
|||
nsXFormsModelElement::OnError(nsresult aStatus,
|
||||
const nsAString &aStatusMessage)
|
||||
{
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaLoadError"), mElement);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -728,7 +730,8 @@ nsXFormsModelElement::HandleEvent(nsIDOMEvent* aEvent)
|
|||
mSchemaCount++;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
// this is a fatal error
|
||||
// this is a fatal error (XXX)
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaLoadError"), mElement);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -834,6 +837,7 @@ nsXFormsModelElement::InstanceLoadFinished(PRBool aSuccess)
|
|||
{
|
||||
--mPendingInstanceCount;
|
||||
if (!aSuccess) {
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("instanceLoadError"), mElement);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_LinkException);
|
||||
} else if (IsComplete()) {
|
||||
nsresult rv = FinishConstruction();
|
||||
|
@ -1115,8 +1119,7 @@ nsXFormsModelElement::FinishConstruction()
|
|||
nsresult rv = mSchemas->ProcessSchemaElement(element, nsnull,
|
||||
getter_AddRefs(schema));
|
||||
if (!NS_SUCCEEDED(rv)) {
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaProcessError"),
|
||||
nsnull, 0, node, node);
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("schemaProcessError"), node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1217,6 +1220,8 @@ nsXFormsModelElement::ProcessBind(nsIXFormsXPathEvaluator *aEvaluator,
|
|||
rv = aEvaluator->CreateExpression(propStrings[i], aBindElement,
|
||||
getter_AddRefs(props[i]));
|
||||
if (NS_FAILED(rv)) {
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("mipParseError"),
|
||||
aBindElement);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_ComputeException);
|
||||
return rv;
|
||||
}
|
||||
|
@ -1240,6 +1245,8 @@ nsXFormsModelElement::ProcessBind(nsIXFormsXPathEvaluator *aEvaluator,
|
|||
#ifdef DEBUG
|
||||
printf("xforms-binding-exception: XPath Evaluation failed\n");
|
||||
#endif
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("nodesetEvaluateError"),
|
||||
aBindElement);
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
||||
return rv;
|
||||
}
|
||||
|
@ -1352,6 +1359,8 @@ nsXFormsModelElement::ProcessBind(nsIXFormsXPathEvaluator *aEvaluator,
|
|||
#ifdef DEBUG
|
||||
printf("xforms-binding-exception: Multiple MIPs on same node!");
|
||||
#endif
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("multiMIPError"),
|
||||
aBindElement);
|
||||
nsXFormsUtils::DispatchEvent(aBindElement,
|
||||
eEvent_BindingException);
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -204,7 +204,7 @@ nsXFormsOutputElement::AttributeSet(nsIAtom *aName, const nsAString &aValue)
|
|||
nsresult
|
||||
nsXFormsOutputElement::Bind()
|
||||
{
|
||||
if (!mValue)
|
||||
if (!mValue || !mHasParent)
|
||||
return NS_OK;
|
||||
|
||||
mBoundNode = nsnull;
|
||||
|
@ -240,7 +240,7 @@ nsXFormsOutputElement::Bind()
|
|||
NS_IMETHODIMP
|
||||
nsXFormsOutputElement::Refresh()
|
||||
{
|
||||
if (!mValue)
|
||||
if (!mValue || !mHasParent)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoString text;
|
||||
|
|
|
@ -60,7 +60,7 @@ nsXFormsSendElement::HandleAction(nsIDOMEvent* aEvent,
|
|||
|
||||
NS_NAMED_LITERAL_STRING(submission, "submission");
|
||||
nsAutoString submissionID;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("submission"), submissionID);
|
||||
mElement->GetAttribute(submission, submissionID);
|
||||
if (submissionID.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
|
@ -73,6 +73,9 @@ nsXFormsSendElement::HandleAction(nsIDOMEvent* aEvent,
|
|||
doc->GetElementById(submissionID, getter_AddRefs(el));
|
||||
|
||||
if (!el || !nsXFormsUtils::IsXFormsElement(el, submission)) {
|
||||
const PRUnichar *strings[] = { submissionID.get(), submission.get() };
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("idRefError"),
|
||||
strings, 2, mElement, mElement);
|
||||
return nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,8 +73,10 @@ nsXFormsSetIndexElement::HandleAction(nsIDOMEvent *aEvent,
|
|||
|
||||
// Get @repeat and @index
|
||||
nsAutoString id, index;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("repeat"), id);
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("index"), index);
|
||||
NS_NAMED_LITERAL_STRING(repeatStr, "repeat");
|
||||
mElement->GetAttribute(repeatStr, id);
|
||||
NS_NAMED_LITERAL_STRING(indexStr, "index");
|
||||
mElement->GetAttribute(indexStr, index);
|
||||
if (id.IsEmpty() || index.IsEmpty()) {
|
||||
/// @todo Should we dispatch an exception, or just define that this does
|
||||
/// not happen as it is a non-validating form as both are required
|
||||
|
@ -91,13 +93,15 @@ nsXFormsSetIndexElement::HandleAction(nsIDOMEvent *aEvent,
|
|||
// checked that @index is present above
|
||||
rv = nsXFormsUtils::EvaluateNodeBinding(mElement,
|
||||
0,
|
||||
NS_LITERAL_STRING("index"),
|
||||
indexStr,
|
||||
EmptyString(),
|
||||
nsIDOMXPathResult::NUMBER_TYPE,
|
||||
getter_AddRefs(model),
|
||||
getter_AddRefs(result));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!result) {
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("indexEvalError"),
|
||||
mElement);
|
||||
// beaufour: This makes sense, but is not according to the spec. I guess...
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
||||
return NS_ERROR_ABORT;
|
||||
|
@ -121,6 +125,9 @@ nsXFormsSetIndexElement::HandleAction(nsIDOMEvent *aEvent,
|
|||
rv = domDoc->GetElementById(id, getter_AddRefs(repeatElem));
|
||||
nsCOMPtr<nsIXFormsRepeatElement> repeat = do_QueryInterface(repeatElem);
|
||||
if (!repeat) {
|
||||
const PRUnichar *strings[] = { id.get(), repeatStr.get() };
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("idRefError"),
|
||||
strings, 2, mElement, mElement);
|
||||
// beaufour: This makes sense, but is not according to the spec. I guess...
|
||||
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
||||
return NS_ERROR_ABORT;
|
||||
|
|
|
@ -343,6 +343,9 @@ nsXFormsSubmitElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled)
|
|||
nsCOMPtr<nsIXFormsSubmissionElement> xfSubmission(do_QueryInterface(submissionElement));
|
||||
|
||||
if (!xfSubmission) {
|
||||
const PRUnichar *strings[] = { submissionID.get(), submission.get() };
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("idRefError"),
|
||||
strings, 2, mElement, mElement);
|
||||
return nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
||||
}
|
||||
|
||||
|
|
|
@ -261,11 +261,15 @@ nsXFormsUtils::GetNodeContext(nsIDOMElement *aElement,
|
|||
NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
|
||||
|
||||
nsAutoString bindId;
|
||||
aElement->GetAttribute(NS_LITERAL_STRING("bind"), bindId);
|
||||
NS_NAMED_LITERAL_STRING(bindStr, "bind");
|
||||
aElement->GetAttribute(bindStr, bindId);
|
||||
if (!bindId.IsEmpty()) {
|
||||
// CASE 1: Use @bind
|
||||
domDoc->GetElementById(bindId, aBindElement);
|
||||
if (!IsXFormsElement(*aBindElement, NS_LITERAL_STRING("bind"))) {
|
||||
if (!IsXFormsElement(*aBindElement, bindStr)) {
|
||||
const PRUnichar *strings[] = { bindId.get(), bindStr.get() };
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("idRefError"),
|
||||
strings, 2, aElement, aElement);
|
||||
DispatchEvent(aElement, eEvent_BindingException);
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
@ -286,7 +290,8 @@ nsXFormsUtils::GetNodeContext(nsIDOMElement *aElement,
|
|||
// CASE 2: Use @model
|
||||
// If bind did not set model, and the element has a model attribute we use this
|
||||
nsAutoString modelId;
|
||||
aElement->GetAttribute(NS_LITERAL_STRING("model"), modelId);
|
||||
NS_NAMED_LITERAL_STRING(modelStr, "model");
|
||||
aElement->GetAttribute(modelStr, modelId);
|
||||
|
||||
if (!modelId.IsEmpty()) {
|
||||
nsCOMPtr<nsIDOMElement> modelElement;
|
||||
|
@ -295,6 +300,9 @@ nsXFormsUtils::GetNodeContext(nsIDOMElement *aElement,
|
|||
|
||||
// No element found, or element not a \<model\> element
|
||||
if (!model) {
|
||||
const PRUnichar *strings[] = { modelId.get(), modelStr.get() };
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("idRefError"),
|
||||
strings, 2, aElement, aElement);
|
||||
nsXFormsUtils::DispatchEvent(aElement, eEvent_BindingException);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -393,11 +401,13 @@ nsXFormsUtils::EvaluateXPath(const nsAString &aExpression,
|
|||
}
|
||||
CallQueryInterface(supResult, &result); // addrefs
|
||||
}
|
||||
else if(rv == NS_ERROR_XFORMS_CALCUATION_EXCEPTION){
|
||||
nsCOMPtr<nsIDOMElement> resolverElement = do_QueryInterface(aResolverNode);
|
||||
nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(resolverElement);
|
||||
nsCOMPtr<nsIDOMNode> model = do_QueryInterface(modelPriv);
|
||||
DispatchEvent(model, eEvent_ComputeException);
|
||||
else if (rv == NS_ERROR_XFORMS_CALCUATION_EXCEPTION) {
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("exprEvaluateError"),
|
||||
nsnull, 0, aContextNode, nsnull);
|
||||
nsCOMPtr<nsIDOMElement> resolverElement = do_QueryInterface(aResolverNode);
|
||||
nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(resolverElement);
|
||||
nsCOMPtr<nsIDOMNode> model = do_QueryInterface(modelPriv);
|
||||
DispatchEvent(model, eEvent_ComputeException);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -800,11 +810,8 @@ nsXFormsUtils::FindParentContext(nsIDOMElement *aElement,
|
|||
NS_ENSURE_ARG_POINTER(aModel);
|
||||
NS_ENSURE_ARG_POINTER(aContextNode);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> elementNode = do_QueryInterface(aElement);
|
||||
NS_ENSURE_TRUE(elementNode, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> curNode;
|
||||
nsresult rv = elementNode->GetParentNode(getter_AddRefs(curNode));
|
||||
nsresult rv = aElement->GetParentNode(getter_AddRefs(curNode));
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
// If a model is set, get its ID
|
||||
|
@ -881,6 +888,7 @@ nsXFormsUtils::FindParentContext(nsIDOMElement *aElement,
|
|||
model = do_QueryInterface(modelElement);
|
||||
}
|
||||
if (!model) {
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("noModelError"), aElement);
|
||||
DispatchEvent(aElement, eEvent_BindingException);
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
|
|
@ -362,11 +362,25 @@ public:
|
|||
* @param aContext If set, the node is used to output what element
|
||||
caused the error
|
||||
*/
|
||||
static NS_HIDDEN_(void) ReportError(const nsString& aMessageName,
|
||||
static NS_HIDDEN_(void) ReportError(const nsString &aMessageName,
|
||||
const PRUnichar **aParams,
|
||||
PRUint32 aParamLength,
|
||||
nsIDOMNode *aElement,
|
||||
nsIDOMNode *aContext);
|
||||
PRUint32 aParamLength,
|
||||
nsIDOMNode *aElement,
|
||||
nsIDOMNode *aContext);
|
||||
|
||||
/**
|
||||
* Simple version of ReportError(), used when reporting without message
|
||||
* arguments and file location and node is taken from same element (or
|
||||
* nsnull).
|
||||
*
|
||||
* @param aMessageName Name of string
|
||||
* @param aElement Element to use for location and context
|
||||
*/
|
||||
static NS_HIDDEN_(void) ReportError(const nsString &aMessageName,
|
||||
nsIDOMNode *aElement = nsnull)
|
||||
{
|
||||
nsXFormsUtils::ReportError(aMessageName, nsnull, 0, aElement, aElement);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
errorContext = \n\nContext: %S
|
||||
errorSource = \n\nSource: %S
|
||||
|
||||
missingTypeName = XForms Error (1): type (%S) missing type name.
|
||||
schemaProcessError = XForms Error (2): Failed to process inline schema.
|
||||
missingTypeName = XForms Error (1): type (%S) missing type name
|
||||
schemaProcessError = XForms Error (2): Failed to process inline schema
|
||||
schemaLoadError = XForms Error (3): Failed to load schema
|
||||
instanceLoadError = XForms Error (4): Failed to load instance
|
||||
mipParseError = XForms Error (5): Error while parsing model item property: %S
|
||||
nodesetEvaluateError = XForms Error (6): Error evaluating nodeset expression: %S
|
||||
multiMIPError = XForms Error (7): Multiply defined model item property on element
|
||||
idRefError = XForms Error (8): id (%S) does not refer to a %S element
|
||||
indexEvalError = XForms Error (9): Error evaluating index attribute: %S
|
||||
exprEvaluateError = XForms Error (10): Error evaluating XPath expression: %S
|
||||
noModelError = XForms Error (11): Could not find model for element
|
||||
|
|
Загрузка…
Ссылка в новой задаче