In bug 1100069, bz suggested I look at using Components.returnCode so a
JS component called by c++ can return failure without having an
exception logged.
However, this isn't working as I expect. Further, the few uses of this
in the tree also don't seem to work as expected.
SessionStore.js uses the pattern:
throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
If we trace through XPCWrappedJSClass.cpp, we see that this is treated
as a "normal" failure, so end up in CheckForException(). The fact we
are throwing an integer *does* mean the rv ends up as
NS_ERROR_INVALID_ARG - but at no point is Components.returnCode used as
a special case (ie, things work identically without setting
.returnCode). CheckForException() ends up with both a "js exception"
and an "xpc exception", ends up calling JS_ReportPendingException()
which still reports the error.
However, if instead of throwing an integer we do something like:
Components.returnCode = NS_ERROR_INVALID_ARG;
return;
(ie, set Components.returnCode and return without throwing) then we
*also* don't get the expected behaviour - we end up at
http://mxr.mozilla.org/mozilla-central/source/js/xpconnect/src/XPCWrappedJSClass.cpp#1405,
which is:
1405 // set to whatever the JS code might have set as the result
1406 retval = pending_result;
So the comment implies this is where the magic should happen, but
pending_result hasn't been updated - it's still NS_OK which is what it
was initialized to at the start of that function. If I change that line to:
retval = xpcc->GetPendingResult();
It works as expected.
So I guess I have 2 questions:
* Is Components.returnCode expected to be used when the code throws (as
SessionStore.jsm does) or when the code returns without an exception?
(Or maybe both?)
* If it is supposed to be used with a normal return, is the change so
GetPendingResult() is called the correct approach to take? (ie, should
I open a bug with that as the patch?)
Thanks,
Mark
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform