зеркало из https://github.com/mozilla/gecko-dev.git
Fixing first part of bug 453571. Use more [optional] idl arguments, and less nsAXPCNativeCallContext. r+sr=mrbkap@gmail.com
This commit is contained in:
Родитель
13c332e27d
Коммит
963bf56e91
|
@ -1323,6 +1323,9 @@ public:
|
|||
|
||||
static nsresult GetContextForEventHandlers(nsINode* aNode,
|
||||
nsIScriptContext** aContext);
|
||||
|
||||
static JSContext *GetCurrentJSContext();
|
||||
|
||||
private:
|
||||
|
||||
static PRBool InitializeEventTable();
|
||||
|
|
|
@ -4316,6 +4316,17 @@ nsContentUtils::GetContextForEventHandlers(nsINode* aNode,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */
|
||||
JSContext *
|
||||
nsContentUtils::GetCurrentJSContext()
|
||||
{
|
||||
JSContext *cx = nsnull;
|
||||
|
||||
sThreadJSContextStack->Peek(&cx);
|
||||
|
||||
return cx;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsAutoGCRoot::Shutdown()
|
||||
|
|
|
@ -1446,17 +1446,8 @@ txVariable::Convert(nsIVariant *aValue, txAExprResult** aResult)
|
|||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder =
|
||||
do_QueryInterface(supports);
|
||||
if (holder) {
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID(), &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAXPCNativeCallContext *cc = nsnull;
|
||||
rv = xpc->GetCurrentNativeCallContext(&cc);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
JSContext* cx;
|
||||
rv = cc->GetJSContext(&cx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
||||
NS_ENSURE_TRUE(cx, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
JSObject *jsobj;
|
||||
rv = holder->GetJSObject(&jsobj);
|
||||
|
|
|
@ -1786,14 +1786,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
|
|||
PRBool termFuncSet = PR_FALSE;
|
||||
|
||||
if (oldDoc == aDocument) {
|
||||
nsCOMPtr<nsIJSContextStack> stack =
|
||||
do_GetService(sJSStackContractID);
|
||||
|
||||
JSContext *cx = nsnull;
|
||||
|
||||
if (stack) {
|
||||
stack->Peek(&cx);
|
||||
}
|
||||
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
||||
|
||||
nsIScriptContext *callerScx;
|
||||
if (cx && (callerScx = GetScriptContextFromJSContext(cx))) {
|
||||
|
@ -3700,15 +3693,7 @@ nsGlobalWindow::DispatchCustomEvent(const char *aEventName)
|
|||
static already_AddRefed<nsIDocShellTreeItem>
|
||||
GetCallerDocShellTreeItem()
|
||||
{
|
||||
nsCOMPtr<nsIJSContextStack> stack =
|
||||
do_GetService(sJSStackContractID);
|
||||
|
||||
JSContext *cx = nsnull;
|
||||
|
||||
if (stack) {
|
||||
stack->Peek(&cx);
|
||||
}
|
||||
|
||||
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
||||
nsIDocShellTreeItem *callerItem = nsnull;
|
||||
|
||||
if (cx) {
|
||||
|
@ -4961,16 +4946,13 @@ nsGlobalWindow::FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
|
|||
|
||||
nsIURI *baseURL = 0;
|
||||
|
||||
nsCOMPtr<nsIJSContextStack> stack = do_GetService(sJSStackContractID);
|
||||
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
||||
nsCOMPtr<nsIDOMWindow> contextWindow;
|
||||
if (stack) {
|
||||
JSContext *cx = nsnull;
|
||||
stack->Peek(&cx);
|
||||
if (cx) {
|
||||
nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx);
|
||||
if (currentCX) {
|
||||
contextWindow = do_QueryInterface(currentCX->GetGlobalObject());
|
||||
}
|
||||
|
||||
if (cx) {
|
||||
nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx);
|
||||
if (currentCX) {
|
||||
contextWindow = do_QueryInterface(currentCX->GetGlobalObject());
|
||||
}
|
||||
}
|
||||
if (!contextWindow)
|
||||
|
@ -5157,16 +5139,10 @@ nsGlobalWindow::GetFrames(nsIDOMWindow** aFrames)
|
|||
nsGlobalWindow*
|
||||
nsGlobalWindow::CallerInnerWindow()
|
||||
{
|
||||
nsAXPCNativeCallContext *ncc;
|
||||
nsresult rv = nsContentUtils::XPConnect()->GetCurrentNativeCallContext(&ncc);
|
||||
if (NS_FAILED(rv) || !ncc) {
|
||||
NS_ASSERTION(ncc, "Please don't call this method from C++!");
|
||||
return nsnull;
|
||||
}
|
||||
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
||||
if (!cx) {
|
||||
NS_ERROR("Please don't call this method from C++!");
|
||||
|
||||
JSContext *cx = nsnull;
|
||||
if (NS_FAILED(ncc->GetJSContext(&cx))) {
|
||||
NS_WARNING("couldn't get JS context from native context");
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,23 +129,16 @@ nsDOMWorkerBase::PostMessageInternal(const nsAString& aMessage,
|
|||
nsresult
|
||||
nsDOMWorkerBase::PostMessageInternal(const nsAString& aMessage)
|
||||
{
|
||||
nsAXPCNativeCallContext* ncc;
|
||||
nsresult rv = nsContentUtils::XPConnect()->
|
||||
GetCurrentNativeCallContext(&ncc);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsRefPtr<nsDOMWorkerBase> source;
|
||||
if (ncc) {
|
||||
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
||||
|
||||
if (cx) {
|
||||
if (NS_IsMainThread()) {
|
||||
// Must be a normal DOM context, use the pool as the source.
|
||||
source = Pool();
|
||||
}
|
||||
else {
|
||||
// Must be a worker context, get the worker from the context private.
|
||||
JSContext* cx;
|
||||
rv = ncc->GetJSContext(&cx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsRefPtr<nsDOMWorkerThread> worker =
|
||||
(nsDOMWorkerThread*)JS_GetContextPrivate(cx);
|
||||
|
||||
|
@ -160,7 +153,7 @@ nsDOMWorkerBase::PostMessageInternal(const nsAString& aMessage)
|
|||
source = this;
|
||||
}
|
||||
|
||||
rv = PostMessageInternal(aMessage, source);
|
||||
nsresult rv = PostMessageInternal(aMessage, source);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -100,17 +100,10 @@ nsDOMWorkerPool::Init()
|
|||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsAXPCNativeCallContext* ncc;
|
||||
nsresult rv = nsContentUtils::XPConnect()->GetCurrentNativeCallContext(&ncc);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// GetCurrentNativeCallContext can return NS_OK and still hand out a null
|
||||
// context... We shouldn't ever see that here.
|
||||
NS_ENSURE_TRUE(ncc, NS_ERROR_UNEXPECTED);
|
||||
|
||||
JSContext* cx;
|
||||
rv = ncc->GetJSContext(&cx);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// GetCurrentJSContext () can return a null context... We shouldn't
|
||||
// ever see that here.
|
||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
||||
NS_ENSURE_TRUE(cx, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsIScriptContext* scriptContext = GetScriptContextFromJSContext(cx);
|
||||
NS_ENSURE_STATE(scriptContext);
|
||||
|
|
Загрузка…
Ссылка в новой задаче