Bug 1611173 - Remove support for non-nsISupports XPIDL interfaces. r=nika

It used to be that some XPIDL interfaces were allowed to be non-nsISupports,
and were only used to hold a bunch of constants. It appears that we've now
had enough de-COM work happen that there are no longer any, so we can remove
support for this.

Differential Revision: https://phabricator.services.mozilla.com/D61008

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew McCreight 2020-01-24 23:13:30 +00:00
parent 02f3747734
commit 359a6cd8c2
8 changed files with 39 additions and 46 deletions

View File

@ -97,11 +97,7 @@ class MOZ_STACK_CLASS AutoSavePendingResult {
// static
const nsXPTInterfaceInfo* nsXPCWrappedJS::GetInterfaceInfo(REFNSIID aIID) {
const nsXPTInterfaceInfo* info = nsXPTInterfaceInfo::ByIID(aIID);
if (!info) {
return nullptr;
}
if (info->IsBuiltinClass() || !nsXPConnect::IsISupportsDescendant(info)) {
if (!info || info->IsBuiltinClass()) {
return nullptr;
}

View File

@ -248,16 +248,6 @@ already_AddRefed<XPCNativeInterface> XPCNativeInterface::NewInstance(
uint16_t methodCount = aInfo->MethodCount();
uint16_t constCount = aInfo->ConstantCount();
// If the interface does not have nsISupports in its inheritance chain
// then we know we can't reflect its methods. However, some interfaces that
// are used just to reflect constants are declared this way. We need to
// go ahead and build the thing. But, we'll ignore whatever methods it may
// have.
if (!nsXPConnect::IsISupportsDescendant(aInfo)) {
methodCount = 0;
}
totalCount = methodCount + constCount;
if (totalCount > MAX_LOCAL_MEMBER_COUNT) {

View File

@ -166,11 +166,6 @@ XPCJSRuntime* nsXPConnect::GetRuntimeInstance() {
return gSelf->mRuntime;
}
// static
bool nsXPConnect::IsISupportsDescendant(const nsXPTInterfaceInfo* info) {
return info && info->HasAncestor(NS_GET_IID(nsISupports));
}
void xpc::ErrorBase::Init(JSErrorBase* aReport) {
if (!aReport->filename) {
mFileName.SetIsVoid(true);

View File

@ -226,8 +226,6 @@ class nsXPConnect final : public nsIXPConnect {
static XPCJSRuntime* GetRuntimeInstance();
XPCJSContext* GetContext() { return mContext; }
static bool IsISupportsDescendant(const nsXPTInterfaceInfo* info);
static nsIScriptSecurityManager* SecurityManager() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(gScriptSecurityManager);

View File

@ -63,13 +63,15 @@ void bar();
self.assertEqual(xpidl.TypeId("void"), m.type)
def testMethodParams(self):
i = self.p.parse("""[uuid(abc)] interface foo {
long bar(in long a, in float b, [array] in long c);
};""", filename='f')
i = self.p.parse("""
[scriptable, uuid(aaa)] interface nsISupports {};
[uuid(abc)] interface foo : nsISupports {
long bar(in long a, in float b, [array] in long c);
};""", filename='f')
i.resolve([], self.p, {})
self.assertTrue(isinstance(i, xpidl.IDL))
self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
iface = i.productions[0]
self.assertTrue(isinstance(i.productions[1], xpidl.Interface))
iface = i.productions[1]
m = iface.members[0]
self.assertTrue(isinstance(m, xpidl.Method))
self.assertEqual("bar", m.name)
@ -97,10 +99,12 @@ attribute long bar;
self.assertEqual(xpidl.TypeId("long"), a.type)
def testOverloadedVirtual(self):
i = self.p.parse("""[uuid(abc)] interface foo {
attribute long bar;
void getBar();
};""", filename='f')
i = self.p.parse("""
[scriptable, uuid(00000000-0000-0000-0000-000000000000)] interface nsISupports {};
[uuid(abc)] interface foo : nsISupports {
attribute long bar;
void getBar();
};""", filename='f')
self.assertTrue(isinstance(i, xpidl.IDL))
i.resolve([], self.p, {})
@ -114,9 +118,24 @@ void getBar();
self.assertEqual(
e.args[0], "Unexpected overloaded virtual method GetBar in interface foo")
def testNotISupports(self):
i = self.p.parse("""
[uuid(abc)] interface foo {};
""", filename='f')
self.assertTrue(isinstance(i, xpidl.IDL))
try:
i.resolve([], self.p, {})
self.assertTrue(False,
"Must check that interfaces inherit from nsISupports")
except xpidl.IDLError as e:
self.assertEqual(
e.message,
"Interface 'foo' must inherit from nsISupports")
def testBuiltinClassParent(self):
i = self.p.parse("""
[scriptable, builtinclass, uuid(abc)] interface foo {};
[scriptable, uuid(aaa)] interface nsISupports {};
[scriptable, builtinclass, uuid(abc)] interface foo : nsISupports {};
[scriptable, uuid(def)] interface bar : foo {};
""", filename='f')
self.assertTrue(isinstance(i, xpidl.IDL))
@ -132,7 +151,8 @@ void getBar();
def testScriptableNotXPCOM(self):
# notxpcom method requires builtinclass on the interface
i = self.p.parse("""
[scriptable, uuid(abc)] interface nsIScriptableWithNotXPCOM {
[scriptable, uuid(aaa)] interface nsISupports {};
[scriptable, uuid(abc)] interface nsIScriptableWithNotXPCOM : nsISupports {
[notxpcom] void method2();
};
""", filename='f')
@ -150,7 +170,8 @@ void getBar();
# notxpcom attribute requires builtinclass on the interface
i = self.p.parse("""
interface nsISomeInterface;
[scriptable, uuid(abc)] interface nsIScriptableWithNotXPCOM {
[scriptable, uuid(aaa)] interface nsISupports {};
[scriptable, uuid(abc)] interface nsIScriptableWithNotXPCOM : nsISupports {
[notxpcom] attribute nsISomeInterface attrib;
};
""", filename='f')

View File

@ -479,12 +479,7 @@ def write_interface(iface, fd):
if iface.namemap is None:
raise Exception("Interface was not resolved.")
# if we see a base class-less type other than nsISupports, we just need
# to discard anything else about it other than its constants.
if iface.base is None and iface.name != "nsISupports":
assert len([m for m in iface.members
if type(m) == xpidl.Attribute or type(m) == xpidl.Method]) == 0
return
assert iface.base or (iface.name == "nsISupports")
# Extract the UUID's information so that it can be written into the struct definition
names = uuid_decoder.match(iface.attributes.uuid).groupdict()

View File

@ -51,12 +51,7 @@ def write_interface(iface, fd):
if iface.namemap is None:
raise Exception("Interface was not resolved.")
# if we see a base class-less type other than nsISupports, we just need
# to discard anything else about it other than its constants.
if iface.base is None and iface.name != "nsISupports":
assert len([m for m in iface.members
if type(m) == xpidl.Attribute or type(m) == xpidl.Method]) == 0
return
assert iface.base or (iface.name == "nsISupports")
base = 'Some("%s")' % iface.base if iface.base is not None else 'None'
try:

View File

@ -704,6 +704,9 @@ class Interface(object):
raise IDLError("interface '%s' is not builtinclass but derives from "
"builtinclass '%s'" %
(self.name, self.base), self.location)
elif self.name != 'nsISupports':
raise IDLError("Interface '%s' must inherit from nsISupports" %
self.name, self.location)
for member in self.members:
member.resolve(self)