Allow getting the lineNumber of XPConnect expceptions. Bug 291377, r=sicking,sr=jst. r=mrbkap, sr=jst for the test.

This commit is contained in:
bzbarsky@mit.edu 2007-04-26 21:19:11 -07:00
Родитель 3e6af11b30
Коммит f7a3d5590c
6 изменённых файлов: 55 добавлений и 56 удалений

Просмотреть файл

@ -316,13 +316,18 @@ static nsresult
CreateXPConnectException(nsresult aResult, nsIException *aDefaultException,
nsIException **_retval)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIXPCException> exception(
do_CreateInstance("@mozilla.org/js/xpc/Exception;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
// See whether we already have a useful XPConnect exception. If we
// do, let's not create one with _less_ information!
nsCOMPtr<nsIXPCException> exception(do_QueryInterface(aDefaultException));
if (!exception) {
nsresult rv = NS_OK;
exception = do_CreateInstance("@mozilla.org/js/xpc/Exception;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = exception->Initialize(nsnull, aResult, nsnull, nsnull, nsnull, nsnull);
NS_ENSURE_SUCCESS(rv, rv);
rv = exception->Initialize(nsnull, aResult, nsnull, nsnull, nsnull,
nsnull);
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ADDREF(*_retval = exception);
return NS_OK;

Просмотреть файл

@ -45,6 +45,7 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_bug291377.html \
test_bug308856.html \
test_bug333983.html \
test_bug342448.html \

Просмотреть файл

@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=291377
-->
<head>
<title>Test for Bug 291377</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=291377">Mozilla Bug 291377</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 291377 **/
/* Do something that causes an XPConnect exception */
var threw = true;
try {
document.appendChild(); /* Not enough arguments */
threw = false;
} catch (e) {
/* Check that we can touch various properties */
is(e.lineNumber, 24, "Unexpected line number");
is(e.name, "NS_ERROR_XPC_NOT_ENOUGH_ARGS", "Unexpected exception name");
isnot(e.message, "", "Should have a message");
isnot(e.result, 0, "Should have a result");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
is(e.result, Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS);
}
is(threw, true, "Not enough arguments to a call should throw");
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -121,9 +121,6 @@ nsXPCException::GetNSResultCount()
NS_INTERFACE_MAP_BEGIN(nsXPCException)
NS_INTERFACE_MAP_ENTRY(nsIException)
NS_INTERFACE_MAP_ENTRY(nsIXPCException)
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
#endif
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)
NS_IMPL_QUERY_CLASSINFO(nsXPCException)
NS_INTERFACE_MAP_END_THREADSAFE
@ -484,43 +481,3 @@ nsXPCException::NewException(const char *aMessage,
*exceptn = NS_STATIC_CAST(nsIXPCException*, e);
return NS_OK;
}
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
/* string canCreateWrapper (in nsIIDPtr iid); */
NS_IMETHODIMP
nsXPCException::CanCreateWrapper(const nsIID * iid, char **_retval)
{
*_retval = xpc_CloneAllAccess();
return NS_OK;
}
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
NS_IMETHODIMP
nsXPCException::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
{
static const char* allowed[] = { "toString", nsnull};
*_retval = xpc_CheckAccessList(methodName, allowed);
return NS_OK;
}
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsXPCException::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
static const char* allowed[] = { "message", "result", "name", nsnull};
*_retval = xpc_CheckAccessList(propertyName, allowed);
return NS_OK;
}
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsXPCException::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
// If you have to ask, then the answer is NO
*_retval = nsnull;
return NS_OK;
}
#endif

Просмотреть файл

@ -85,7 +85,7 @@ static const nsModuleComponentInfo components[] = {
{nsnull, NS_JS_ID_CID, XPC_ID_CONTRACTID, nsJSIDConstructor },
{nsnull, NS_XPCONNECT_CID, XPC_XPCONNECT_CONTRACTID, nsIXPConnectConstructor },
{nsnull, NS_XPC_THREAD_JSCONTEXT_STACK_CID, XPC_CONTEXT_STACK_CONTRACTID, nsIJSContextStackConstructor },
{nsnull, NS_XPCEXCEPTION_CID, XPC_EXCEPTION_CONTRACTID, nsXPCExceptionConstructor, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(nsXPCException), nsnull, &NS_CLASSINFO_NAME(nsXPCException)},
{nsnull, NS_XPCEXCEPTION_CID, XPC_EXCEPTION_CONTRACTID, nsXPCExceptionConstructor, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(nsXPCException), nsnull, &NS_CLASSINFO_NAME(nsXPCException), nsIClassInfo::DOM_OBJECT },
{nsnull, NS_JS_RUNTIME_SERVICE_CID, XPC_RUNTIME_CONTRACTID, nsIJSRuntimeServiceConstructor},
{NS_SCRIPTERROR_CLASSNAME, NS_SCRIPTERROR_CID, NS_SCRIPTERROR_CONTRACTID, nsScriptErrorConstructor },
{nsnull, SCRIPTABLE_INTERFACES_CID, NS_SCRIPTABLE_INTERFACES_CONTRACTID, nsXPCComponents_InterfacesConstructor, 0, 0, 0, 0, 0, 0, nsIClassInfo::THREADSAFE },

Просмотреть файл

@ -2609,9 +2609,6 @@ private:
class nsXPCException :
public nsIXPCException
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
, public nsISecurityCheckedComponent
#endif
{
public:
NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCEXCEPTION_CID)
@ -2619,9 +2616,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEXCEPTION
NS_DECL_NSIXPCEXCEPTION
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
NS_DECL_NSISECURITYCHECKEDCOMPONENT
#endif
static nsresult NewException(const char *aMessage,
nsresult aResult,