bug 580128 - Distinguish between XOW XrayWrappers and XPCNW XrayWrappers and use the new knowledge in a few places. r=gal

This commit is contained in:
Blake Kaplan 2010-10-10 15:42:18 -07:00
parent b49f4387f9
commit 4982e8d388
5 changed files with 19 additions and 9 deletions

View File

@ -6576,7 +6576,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSString *str = JSID_TO_STRING(id);
{
if (!xpc::WrapperFactory::IsXrayWrapper(obj) ||
xpc::WrapperFactory::IsPartiallyTransparent(obj)) {
nsCOMPtr<nsIDocShellTreeNode> dsn(do_QueryInterface(win->GetDocShell()));
PRInt32 count = 0;

View File

@ -34,6 +34,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=500931
let wrap = $('ifr').contentWindow.wrappedJSObject;
ok(!('obj' in XPCNativeWrapper(wrap)), "XPCNativeWrapper constructor works");
let iwin = $('ifr').contentWindow;
is(iwin.document.ELEMENT_NODE, 1, 'constants work through XrayWrapper');
is(iwin.document.nodeName, "#document", 'attributes work through XrayWrappe
location.foopy = 3;

View File

@ -161,8 +161,10 @@ FilteringWrapper<Base, Policy>::enter(JSContext *cx, JSObject *wrapper, jsid id,
template<> SOW SOW::singleton(0);
template<> COW COW::singleton(0);
template<> XOW XOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG);
template<> NNXOW NNXOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG);
template<> XOW XOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::PARTIALLY_TRANSPARENT);
template<> NNXOW NNXOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::PARTIALLY_TRANSPARENT);
template<> LW LW::singleton(0);
template<> XLW XLW::singleton(0);

View File

@ -46,7 +46,8 @@ class WrapperFactory {
public:
enum { WAIVE_XRAY_WRAPPER_FLAG = (1<<0),
IS_XRAY_WRAPPER_FLAG = (1<<1),
SCRIPT_ACCESS_ONLY_FLAG = (1<<2) };
SCRIPT_ACCESS_ONLY_FLAG = (1<<2),
PARTIALLY_TRANSPARENT = (1<<3) };
// Return true if any of any of the nested wrappers have the flag set.
static bool HasWrapperFlag(JSObject *wrapper, uintN flag) {
@ -59,6 +60,10 @@ class WrapperFactory {
return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG);
}
static bool IsPartiallyTransparent(JSObject *wrapper) {
return HasWrapperFlag(wrapper, PARTIALLY_TRANSPARENT);
}
// Prepare a given object for wrapping in a new compartment.
static JSObject *PrepareForWrapping(JSContext *cx,
JSObject *scope,

View File

@ -498,7 +498,7 @@ XrayWrapper<Base, Policy>::getPropertyDescriptor(JSContext *cx, JSObject *wrappe
}
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
if (UniversalXPConnect()) {
if (WrapperFactory::IsPartiallyTransparent(wrapper) && UniversalXPConnect()) {
JSObject *wnObject = GetWrappedNativeObjectFromHolder(cx, holder);
{
@ -538,7 +538,7 @@ XrayWrapper<Base, Policy>::defineProperty(JSContext *cx, JSObject *wrapper, jsid
JSPropertyDescriptor *jsdesc = Jsvalify(desc);
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
if (UniversalXPConnect()) {
if (WrapperFactory::IsPartiallyTransparent(wrapper) && UniversalXPConnect()) {
JSObject *wnObject = GetWrappedNativeObjectFromHolder(cx, holder);
JSAutoEnterCompartment ac;
@ -578,7 +578,7 @@ XrayWrapper<Base, Policy>::getOwnPropertyNames(JSContext *cx, JSObject *wrapper,
JSObject *holder = GetHolder(wrapper);
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
if (UniversalXPConnect()) {
if (WrapperFactory::IsPartiallyTransparent(wrapper) && UniversalXPConnect()) {
JSObject *wnObject = GetWrappedNativeObjectFromHolder(cx, holder);
JSAutoEnterCompartment ac;
@ -600,7 +600,7 @@ XrayWrapper<Base, Policy>::delete_(JSContext *cx, JSObject *wrapper, jsid id, bo
JSBool b;
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
if (UniversalXPConnect()) {
if (WrapperFactory::IsPartiallyTransparent(wrapper) && UniversalXPConnect()) {
JSObject *wnObject = GetWrappedNativeObjectFromHolder(cx, holder);
JSAutoEnterCompartment ac;
@ -626,7 +626,7 @@ XrayWrapper<Base, Policy>::enumerate(JSContext *cx, JSObject *wrapper, js::AutoI
JSObject *holder = GetHolder(wrapper);
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
if (UniversalXPConnect()) {
if (WrapperFactory::IsPartiallyTransparent(wrapper) && UniversalXPConnect()) {
JSObject *wnObject = GetWrappedNativeObjectFromHolder(cx, holder);
JSAutoEnterCompartment ac;