From cabc2867aaf21c114207863e6efbae120afdea50 Mon Sep 17 00:00:00 2001 From: "mrbkap@gmail.com" Date: Mon, 9 Jul 2007 14:46:18 -0700 Subject: [PATCH] Don't create exceptions using the global object as the parent, since that's bogus, use the scope chain instead. bug 386695, r+sr=jst --- js/src/xpconnect/src/xpcthrower.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/js/src/xpconnect/src/xpcthrower.cpp b/js/src/xpconnect/src/xpcthrower.cpp index f807dcc40a3..ff49042ab0d 100644 --- a/js/src/xpconnect/src/xpcthrower.cpp +++ b/js/src/xpconnect/src/xpcthrower.cpp @@ -259,6 +259,16 @@ XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz) JS_ReportOutOfMemory(cx); } +static JSObject* +GetGlobalObject(JSContext* cx, JSObject* start) +{ + JSObject* parent; + + while((parent = JS_GetParent(cx, start)) != nsnull) + start = parent; + return start; +} + // static JSBool XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e) @@ -269,8 +279,10 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e) nsXPConnect* xpc = nsXPConnect::GetXPConnect(); if(xpc) { - // XXX funky JS_GetGlobalObject alert! - JSObject* glob = JS_GetGlobalObject(cx); + JSObject* glob = JS_GetScopeChain(cx); + if(!glob) + return JS_FALSE; + glob = GetGlobalObject(cx, glob); nsCOMPtr holder; nsresult rv = xpc->WrapNative(cx, glob, e,