Bug 1237503. Add support for [Cached] and [StoreInSlot] things on DOM proxies. r=qdot

The only difference between proxies and non-proxies is that proxies only support
up to MAX_FIXED_SLOTS slots all told (reserved plus private slot).  SpiderMonkey
already has static asserts to make sure we don't ask for too many reserved slots
on a proxy.
This commit is contained in:
Boris Zbarsky 2017-05-19 09:24:30 -04:00
parent a4fdbd6fad
commit 682fe478ec
3 changed files with 14 additions and 8 deletions

View File

@ -424,6 +424,10 @@ def DOMClass(descriptor):
hooks=NativePropertyHooks(descriptor))
def InstanceReservedSlots(descriptor):
return INSTANCE_RESERVED_SLOTS + descriptor.interface.totalMembersInSlots
class CGDOMJSClass(CGThing):
"""
Generate a DOMJSClass for a given descriptor
@ -438,7 +442,7 @@ class CGDOMJSClass(CGThing):
def define(self):
callHook = LEGACYCALLER_HOOK_NAME if self.descriptor.operations["LegacyCaller"] else 'nullptr'
objectMovedHook = OBJECT_MOVED_HOOK_NAME if self.descriptor.wrapperCache else 'nullptr'
slotCount = INSTANCE_RESERVED_SLOTS + self.descriptor.interface.totalMembersInSlots
slotCount = InstanceReservedSlots(self.descriptor)
classFlags = "JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | "
if self.descriptor.isGlobal():
classFlags += "JSCLASS_DOM_GLOBAL | JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS)"
@ -528,9 +532,10 @@ class CGDOMProxyJSClass(CGThing):
return ""
def define(self):
slotCount = InstanceReservedSlots(self.descriptor)
# We need one reserved slot (DOM_OBJECT_SLOT).
flags = ["JSCLASS_IS_DOMJSCLASS",
"JSCLASS_HAS_RESERVED_SLOTS(1)"]
"JSCLASS_HAS_RESERVED_SLOTS(%d)" % slotCount]
# We don't use an IDL annotation for JSCLASS_EMULATES_UNDEFINED because
# we don't want people ever adding that to any interface other than
# HTMLAllCollection. So just hardcode it here.
@ -12717,10 +12722,6 @@ class CGDescriptor(CGThing):
if descriptor.concrete:
if descriptor.proxy:
if descriptor.interface.totalMembersInSlots != 0:
raise TypeError("We can't have extra reserved slots for "
"proxy interface %s" %
descriptor.interface.identifier.name)
cgThings.append(CGGeneric(fill(
"""
static_assert(IsBaseOf<nsISupports, ${nativeType} >::value,
@ -12741,8 +12742,9 @@ class CGDescriptor(CGThing):
else:
cgThings.append(CGDOMJSClass(descriptor))
cgThings.append(CGGetJSClassMethod(descriptor))
if descriptor.interface.hasMembersInSlots():
cgThings.append(CGUpdateMemberSlotsMethod(descriptor))
if descriptor.interface.hasMembersInSlots():
cgThings.append(CGUpdateMemberSlotsMethod(descriptor))
if descriptor.isGlobal():
assert descriptor.wrapperCache

View File

@ -1217,6 +1217,8 @@ public:
uint32_t Item(uint32_t, bool&) = delete;
uint32_t Length();
void LegacyCall(JS::Handle<JS::Value>);
int32_t CachedAttr();
int32_t StoreInSlotAttr();
};
class TestNamedGetterInterface : public nsISupports,

View File

@ -1188,6 +1188,8 @@ interface TestIndexedGetterInterface {
getter long item(unsigned long idx);
readonly attribute unsigned long length;
legacycaller void();
[Cached, Pure] readonly attribute long cachedAttr;
[StoreInSlot, Pure] readonly attribute long storeInSlotAttr;
};
interface TestNamedGetterInterface {