зеркало из https://github.com/mozilla/pjs.git
Bug 764916 - Replace nsDOMClassInfo::ThrowJSException with xpc::Throw. r=mrbkap
This commit is contained in:
Родитель
aa2ab7135c
Коммит
84580ec486
|
@ -55,7 +55,7 @@
|
|||
#include "nsNodeUtils.h"
|
||||
|
||||
// Nasty hack. Maybe we could move some of the classinfo utility methods
|
||||
// (e.g. WrapNative and ThrowJSException) over to nsContentUtils?
|
||||
// (e.g. WrapNative) over to nsContentUtils?
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "nsJSUtils.h"
|
||||
|
||||
|
@ -118,7 +118,7 @@ XBLResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsigned flags,
|
|||
|
||||
if (~nodeClass->flags &
|
||||
(JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);
|
||||
xpc::Throw(cx, NS_ERROR_UNEXPECTED);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ XBLResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsigned flags,
|
|||
|
||||
nsCOMPtr<nsIContent> content = do_QueryWrappedNative(xpcWrapper);
|
||||
if (!content) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);
|
||||
xpc::Throw(cx, NS_ERROR_UNEXPECTED);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -160,10 +160,7 @@ XBLResolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsigned flags,
|
|||
protoBinding->DocURI(),
|
||||
&didInstall);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (!::JS_IsExceptionPending(cx)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
}
|
||||
|
||||
xpc::Throw(cx, rv);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -2142,70 +2142,6 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
CreateExceptionFromResult(JSContext *cx, nsresult aResult)
|
||||
{
|
||||
nsCOMPtr<nsIExceptionService> xs =
|
||||
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
|
||||
if (!xs) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIExceptionManager> xm;
|
||||
nsresult rv = xs->GetCurrentExceptionManager(getter_AddRefs(xm));
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIException> exception;
|
||||
rv = xm->GetExceptionFromProvider(aResult, 0, getter_AddRefs(exception));
|
||||
if (NS_FAILED(rv) || !exception) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JS::Value jv;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, ::JS_GetGlobalObject(cx), exception,
|
||||
&NS_GET_IID(nsIException), false, &jv,
|
||||
getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv) || jv.isNull()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSAutoEnterCompartment ac;
|
||||
|
||||
if (jv.isObject()) {
|
||||
if (!ac.enter(cx, &jv.toObject())) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
|
||||
JS_SetPendingException(cx, jv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsDOMClassInfo::ThrowJSException(JSContext *cx, nsresult aResult)
|
||||
{
|
||||
JSAutoRequest ar(cx);
|
||||
|
||||
if (NS_SUCCEEDED(CreateExceptionFromResult(cx, aResult))) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX This probably wants to be localized, but that can fail in ways that
|
||||
// are hard to report correctly.
|
||||
JSString *str =
|
||||
JS_NewStringCopyZ(cx, "An error occurred throwing an exception");
|
||||
if (!str) {
|
||||
// JS_NewStringCopyZ reported the error for us.
|
||||
return NS_OK;
|
||||
}
|
||||
JS_SetPendingException(cx, STRING_TO_JSVAL(str));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
bool
|
||||
nsDOMClassInfo::ObjectIsNativeWrapper(JSContext* cx, JSObject* obj)
|
||||
|
@ -7130,9 +7066,7 @@ LocationSetter(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict,
|
|||
{
|
||||
nsresult rv = LocationSetterGuts<Interface>(cx, obj, vp);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (!::JS_IsExceptionPending(cx)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
}
|
||||
xpc::Throw(cx, rv);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -7805,9 +7739,7 @@ GetterShim(JSContext *cx, JSHandleObject obj, JSHandleId /* unused */, jsval *vp
|
|||
{
|
||||
nsresult rv = (*func)(cx, obj, vp);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (!::JS_IsExceptionPending(cx)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
}
|
||||
xpc::Throw(cx, rv);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -8972,7 +8904,7 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
|
|||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_FAILURE);
|
||||
xpc::Throw(cx, NS_ERROR_FAILURE);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -9024,7 +8956,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSHandleObject obj_,
|
|||
rv = nodeList->GetLength(&length);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
xpc::Throw(cx, rv);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -9040,7 +8972,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSHandleObject obj_,
|
|||
result = doc->GetDocumentAllResult(str, &cache, &rv);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
xpc::Throw(cx, rv);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -9068,7 +9000,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSHandleObject obj_,
|
|||
if (result) {
|
||||
rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx), result, cache, true, vp);
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
xpc::Throw(cx, rv);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -9160,7 +9092,7 @@ nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp)
|
|||
// XXX: Should throw NS_ERROR_XPC_NOT_ENOUGH_ARGS for argc < 1,
|
||||
// and create a new NS_ERROR_XPC_TOO_MANY_ARGS for argc > 1? IE
|
||||
// accepts nothing other than one arg.
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_INVALID_ARG);
|
||||
xpc::Throw(cx, NS_ERROR_INVALID_ARG);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -9254,7 +9186,7 @@ nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSHandleObject obj
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIHTMLDocument> doc = do_QueryWrapper(cx, obj, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
xpc::Throw(cx, rv);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -9332,7 +9264,7 @@ nsHTMLDocumentSH::DocumentAllTagsNewResolve(JSContext *cx, JSHandleObject obj,
|
|||
static_cast<nsINodeList*>(tags), tags, true,
|
||||
&v, getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
xpc::Throw(cx, rv);
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -9432,7 +9364,7 @@ nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
// Insert the helper into our prototype chain. helper's prototype
|
||||
// is already obj's current prototype.
|
||||
if (!::JS_SetPrototype(cx, obj, helper)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);
|
||||
xpc::Throw(cx, NS_ERROR_UNEXPECTED);
|
||||
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
|
|
@ -122,8 +122,6 @@ public:
|
|||
return new nsDOMClassInfo(aData);
|
||||
}
|
||||
|
||||
static nsresult ThrowJSException(JSContext *cx, nsresult aResult);
|
||||
|
||||
/*
|
||||
* The following two functions exist because of the way that Xray wrappers
|
||||
* work. In order to allow scriptable helpers to define non-IDL defined but
|
||||
|
|
|
@ -55,7 +55,6 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory()
|
|||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_SVG);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_XPATH);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_XPCONNECT);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_INDEXEDDB);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_FILEHANDLE);
|
||||
}
|
||||
|
@ -141,8 +140,6 @@ nsDOMScriptObjectFactory::Observe(nsISupports *aSubject,
|
|||
NS_ERROR_MODULE_SVG);
|
||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
||||
NS_ERROR_MODULE_DOM_XPATH);
|
||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
||||
NS_ERROR_MODULE_XPCONNECT);
|
||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
||||
NS_ERROR_MODULE_DOM_INDEXEDDB);
|
||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
||||
|
@ -156,27 +153,6 @@ nsDOMScriptObjectFactory::Observe(nsISupports *aSubject,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
CreateXPConnectException(nsresult aResult, nsIException *aDefaultException,
|
||||
nsIException **_retval)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
exception.forget(_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName,
|
||||
nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "nsXPCOMCIDInternal.h"
|
||||
#include "nsIXULRuntime.h"
|
||||
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "xpcpublic.h"
|
||||
|
||||
#include "jsdbgapi.h" // for JS_ClearWatchPointsForObject
|
||||
|
@ -3700,7 +3699,7 @@ NS_DOMReadStructuredClone(JSContext* cx,
|
|||
}
|
||||
|
||||
// Don't know what this is. Bail.
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
xpc::Throw(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
@ -3734,7 +3733,7 @@ NS_DOMWriteStructuredClone(JSContext* cx,
|
|||
}
|
||||
|
||||
// Don't know what this is. Bail.
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
xpc::Throw(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -3743,7 +3742,7 @@ NS_DOMStructuredCloneError(JSContext* cx,
|
|||
uint32_t errorid)
|
||||
{
|
||||
// We don't currently support any extensions to structured cloning.
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
xpc::Throw(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
}
|
||||
|
||||
//static
|
||||
|
|
|
@ -15,6 +15,7 @@ TEST_FILES = \
|
|||
test_domrequest.html \
|
||||
test_gsp-standards.html \
|
||||
test_gsp-quirks.html \
|
||||
test_nondomexception.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<!-- intentionally omiting doctype because this test requires document.all -->
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for non-DOM module exceptions</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
try {
|
||||
document.all();
|
||||
} catch (e) {
|
||||
is(typeof e, "object");
|
||||
is(e.filename, location);
|
||||
is(e.lineNumber, 18);
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "nsIXPConnect.h"
|
||||
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
@ -90,9 +89,7 @@ ThrowException(JSContext* aCx,
|
|||
nsresult aErrorCode)
|
||||
{
|
||||
NS_ASSERTION(NS_FAILED(aErrorCode), "Not an error code!");
|
||||
if (!JS_IsExceptionPending(aCx)) {
|
||||
nsDOMClassInfo::ThrowJSException(aCx, aErrorCode);
|
||||
}
|
||||
xpc::Throw(aCx, aErrorCode);
|
||||
}
|
||||
|
||||
inline
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "js/MemoryMetrics.h"
|
||||
#include "nsAlgorithm.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "nsDOMJSUtils.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsJSEnvironment.h"
|
||||
|
@ -2479,7 +2478,7 @@ WorkerPrivate::Create(JSContext* aCx, JSObject* aObj, WorkerPrivate* aParent,
|
|||
// First check to make sure the caller has permission to make a
|
||||
// ChromeWorker if they called the ChromeWorker constructor.
|
||||
if (aIsChromeWorker && !isChrome) {
|
||||
nsDOMClassInfo::ThrowJSException(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
||||
xpc::Throw(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
@ -2508,7 +2507,7 @@ WorkerPrivate::Create(JSContext* aCx, JSObject* aObj, WorkerPrivate* aParent,
|
|||
if (!window ||
|
||||
(globalWindow != window &&
|
||||
!nsContentUtils::CanCallerAccess(window))) {
|
||||
nsDOMClassInfo::ThrowJSException(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
||||
xpc::Throw(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "jsapi.h"
|
||||
|
||||
#include "nsCollationCID.h"
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
|
@ -20,6 +19,8 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
|
||||
#include "xpcpublic.h"
|
||||
|
||||
/**
|
||||
* JS locale callbacks implemented by XPCOM modules. This
|
||||
* implementation is "safe" up to the following restrictions
|
||||
|
@ -208,7 +209,7 @@ struct XPCLocaleCallbacks : public JSLocaleCallbacks
|
|||
}
|
||||
|
||||
if (!str) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY);
|
||||
xpc::Throw(cx, NS_ERROR_OUT_OF_MEMORY);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -240,7 +241,7 @@ struct XPCLocaleCallbacks : public JSLocaleCallbacks
|
|||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
xpc::Throw(cx, rv);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -256,7 +257,7 @@ struct XPCLocaleCallbacks : public JSLocaleCallbacks
|
|||
depStr1, depStr2, &result);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
xpc::Throw(cx, rv);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче