зеркало из https://github.com/mozilla/gecko-dev.git
Bug 966609 - nsWrapperCache for SandboxPrivate. r=bholley
This commit is contained in:
Родитель
4c8c8fe9a7
Коммит
d4b6762114
|
@ -360,7 +360,7 @@ function run_miscellaneous_tests() {
|
||||||
baseRange.setStart(null, 0);
|
baseRange.setStart(null, 0);
|
||||||
do_throw("Should have thrown NOT_OBJECT_ERR!");
|
do_throw("Should have thrown NOT_OBJECT_ERR!");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
do_check_eq(e instanceof TypeError, true);
|
do_check_eq(e.constructor.name, "TypeError");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalid start node
|
// Invalid start node
|
||||||
|
@ -368,7 +368,7 @@ function run_miscellaneous_tests() {
|
||||||
baseRange.setStart({}, 0);
|
baseRange.setStart({}, 0);
|
||||||
do_throw("Should have thrown SecurityError!");
|
do_throw("Should have thrown SecurityError!");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
do_check_true(e instanceof TypeError);
|
do_check_eq(e.constructor.name, "TypeError");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalid index
|
// Invalid index
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "nsIScriptObjectPrincipal.h"
|
#include "nsIScriptObjectPrincipal.h"
|
||||||
#include "nsIPrincipal.h"
|
#include "nsIPrincipal.h"
|
||||||
#include "nsWeakReference.h"
|
#include "nsWeakReference.h"
|
||||||
|
#include "nsWrapperCache.h"
|
||||||
|
|
||||||
#include "js/RootingAPI.h"
|
#include "js/RootingAPI.h"
|
||||||
|
|
||||||
|
@ -17,17 +18,20 @@
|
||||||
|
|
||||||
class SandboxPrivate : public nsIGlobalObject,
|
class SandboxPrivate : public nsIGlobalObject,
|
||||||
public nsIScriptObjectPrincipal,
|
public nsIScriptObjectPrincipal,
|
||||||
public nsSupportsWeakReference
|
public nsSupportsWeakReference,
|
||||||
|
public nsWrapperCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SandboxPrivate(nsIPrincipal *principal, JSObject *global)
|
SandboxPrivate(nsIPrincipal *principal, JSObject *global)
|
||||||
: mPrincipal(principal)
|
: mPrincipal(principal)
|
||||||
, mGlobalJSObject(global)
|
|
||||||
{
|
{
|
||||||
|
SetWrapper(global);
|
||||||
}
|
}
|
||||||
virtual ~SandboxPrivate() { }
|
virtual ~SandboxPrivate() { }
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(SandboxPrivate,
|
||||||
|
nsIGlobalObject)
|
||||||
|
|
||||||
nsIPrincipal *GetPrincipal()
|
nsIPrincipal *GetPrincipal()
|
||||||
{
|
{
|
||||||
|
@ -36,16 +40,15 @@ public:
|
||||||
|
|
||||||
JSObject *GetGlobalJSObject()
|
JSObject *GetGlobalJSObject()
|
||||||
{
|
{
|
||||||
return mGlobalJSObject;
|
return GetWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForgetGlobalObject()
|
void ForgetGlobalObject()
|
||||||
{
|
{
|
||||||
mGlobalJSObject = nullptr;
|
ClearWrapper();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||||
JS::TenuredHeap<JSObject*> mGlobalJSObject;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __SANDBOXPRIVATE_H__
|
#endif // __SANDBOXPRIVATE_H__
|
||||||
|
|
|
@ -43,10 +43,16 @@ using namespace xpc;
|
||||||
using mozilla::dom::DestroyProtoAndIfaceCache;
|
using mozilla::dom::DestroyProtoAndIfaceCache;
|
||||||
using mozilla::dom::indexedDB::IndexedDatabaseManager;
|
using mozilla::dom::indexedDB::IndexedDatabaseManager;
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS3(SandboxPrivate,
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(SandboxPrivate)
|
||||||
nsIScriptObjectPrincipal,
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(SandboxPrivate)
|
||||||
nsIGlobalObject,
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(SandboxPrivate)
|
||||||
nsISupportsWeakReference)
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SandboxPrivate)
|
||||||
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||||
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptObjectPrincipal)
|
||||||
|
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
|
||||||
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
||||||
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||||
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
const char kScriptSecurityManagerContractID[] = NS_SCRIPTSECURITYMANAGER_CONTRACTID;
|
const char kScriptSecurityManagerContractID[] = NS_SCRIPTSECURITYMANAGER_CONTRACTID;
|
||||||
|
|
||||||
|
|
|
@ -819,24 +819,17 @@ XPCConvert::NativeInterface2JSObject(MutableHandleValue d,
|
||||||
// object will create (and fill the cache) from its WrapObject call.
|
// object will create (and fill the cache) from its WrapObject call.
|
||||||
nsWrapperCache *cache = aHelper.GetWrapperCache();
|
nsWrapperCache *cache = aHelper.GetWrapperCache();
|
||||||
|
|
||||||
RootedObject flat(cx);
|
RootedObject flat(cx, cache ? cache->GetWrapper() : nullptr);
|
||||||
if (cache) {
|
if (!flat && cache && cache->IsDOMBinding()) {
|
||||||
flat = cache->GetWrapper();
|
RootedObject global(cx, xpcscope->GetGlobalJSObject());
|
||||||
if (cache->IsDOMBinding()) {
|
flat = cache->WrapObject(cx, global);
|
||||||
if (!flat) {
|
if (!flat)
|
||||||
RootedObject global(cx, xpcscope->GetGlobalJSObject());
|
return false;
|
||||||
flat = cache->WrapObject(cx, global);
|
}
|
||||||
if (!flat)
|
if (flat) {
|
||||||
return false;
|
if (allowNativeWrapper && !JS_WrapObject(cx, &flat))
|
||||||
}
|
return false;
|
||||||
|
return CreateHolderIfNeeded(flat, d, dest);
|
||||||
if (allowNativeWrapper && !JS_WrapObject(cx, &flat))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return CreateHolderIfNeeded(flat, d, dest);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
flat = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't double wrap CPOWs. This is a temporary measure for compatibility
|
// Don't double wrap CPOWs. This is a temporary measure for compatibility
|
||||||
|
|
|
@ -70,9 +70,13 @@ function run_test()
|
||||||
httpserver.stop(finishIfDone);
|
httpserver.stop(finishIfDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.checkResults = checkResults;
|
// We want to execute checkResults from the scope of the sandbox as well to
|
||||||
|
// make sure that there are no permission errors related to nsEP. For that
|
||||||
|
// we need to clone the function into the sandbox and make a few things
|
||||||
|
// available for it.
|
||||||
|
cu.evalInSandbox('var checkResults = ' + checkResults.toSource(), sb);
|
||||||
sb.do_check_eq = do_check_eq;
|
sb.do_check_eq = do_check_eq;
|
||||||
|
sb.httpbody = httpbody;
|
||||||
|
|
||||||
function changeListener(event) {
|
function changeListener(event) {
|
||||||
if (checkResults(async))
|
if (checkResults(async))
|
||||||
|
|
Загрузка…
Ссылка в новой задаче