Bug 1134112 part 1. When doing fast-init of a Web IDL dictionary, do fast-init of its dictionary members and its ancestors too. r=peterv

This commit is contained in:
Boris Zbarsky 2015-02-19 14:36:26 -05:00
parent 2f91ccc894
commit 93775369fd
3 changed files with 37 additions and 3 deletions

View File

@ -39,6 +39,14 @@ protected:
bool StringifyToJSON(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsAString& aJSON) const;
// Struct used as a way to force a dictionary constructor to not init the
// dictionary (via constructing from a pointer to this class). We're putting
// it here so that all the dictionaries will have access to it, but outside
// code will not.
struct FastDictionaryInitializer {
};
private:
// aString is expected to actually be an nsAString*. Should only be
// called from StringifyToJSON.

View File

@ -11605,16 +11605,28 @@ class CGDictionary(CGThing):
visibility="public",
body=self.getMemberInitializer(m))
for m in self.memberInfo]
if d.parent:
# We always want to init our parent with our non-initializing
# constructor arg, because either we're about to init ourselves (and
# hence our parent) or we don't want any init happening.
baseConstructors = [
"%s(%s)" % (self.makeClassName(d.parent),
self.getNonInitializingCtorArg())
]
else:
baseConstructors = None
ctors = [
ClassConstructor(
[],
visibility="public",
baseConstructors=baseConstructors,
body=(
"// Safe to pass a null context if we pass a null value\n"
"Init(nullptr, JS::NullHandleValue);\n")),
ClassConstructor(
[Argument("int", "")],
visibility="protected",
[Argument("const FastDictionaryInitializer&", "")],
visibility="public",
baseConstructors=baseConstructors,
explicit=True,
bodyInHeader=True,
body='// Do nothing here; this is used by our "Fast" subclass\n')
@ -11663,7 +11675,9 @@ class CGDictionary(CGThing):
[],
visibility="public",
bodyInHeader=True,
baseConstructors=["%s(42)" % selfName],
baseConstructors=["%s(%s)" %
(selfName,
self.getNonInitializingCtorArg())],
body="// Doesn't matter what int we pass to the parent constructor\n")
fastStruct = CGClass("Fast" + selfName,
@ -11889,6 +11903,12 @@ class CGDictionary(CGThing):
return "JS::UndefinedValue()"
if type.isObject():
return "nullptr"
if type.isDictionary():
# When we construct ourselves, we don't want to init our member
# dictionaries. Either we're being constructed-but-not-initialized
# ourselves (and then we don't want to init them) or we're about to
# init ourselves and then we'll init them anyway.
return CGDictionary.getNonInitializingCtorArg();
return None
def getMemberSourceDescription(self, member):
@ -11899,6 +11919,10 @@ class CGDictionary(CGThing):
def makeIdName(name):
return IDLToCIdentifier(name) + "_id"
@staticmethod
def getNonInitializingCtorArg():
return "FastDictionaryInitializer()"
@staticmethod
def isDictionaryCopyConstructible(dictionary):
if (dictionary.parent and

View File

@ -990,6 +990,8 @@ dictionary Dict : ParentDict {
required long requiredLong;
required object requiredObject;
CustomEventInit customEventInit;
};
dictionary ParentDict : GrandparentDict {