Closed Bug 593413 Opened 15 years ago Closed 14 years ago

Have a default templatized createInstance to remove boilerplate

Categories

(Tamarin Graveyard :: Virtual Machine, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID
Future

People

(Reporter: treilly, Unassigned)

References

Details

We have tons of these: ScriptObject* ByteArrayClass::createInstance(VTable *ivtable, ScriptObject *prototype) { return new (core()->GetGC(), ivtable->getExtraSize()) ByteArrayObject(ivtable, prototype); } Why not have: template <class INSTANCE> class ClassClosure { INSTANCE* ByteArrayClass::createInstance(VTable *ivtable, ScriptObject *prototype) { return new (core()->GetGC(), ivtable->getExtraSize()) INSTANCE(ivtable, prototype); } }; In fact ByteArrayClass might be able to go away and be replaced with: typedef ByteArrayClass ClassClosure<ByteArrayObject>;
+1. It would simplify finding the exceptions to the rule (which seems to be a common exercise).
Depends on: 565664
Analyzer to find createInstance() overrides. http://hg.mozilla.org/users/edwsmith_adobe.com/analyzers/file/tip/createInstance.js Hand inspection of the resulting classes in TR shows all but one or two are pure boilerplate. A few more (ArrayClass, RegExpClass) pass generic default args to their ArrayObject/RegExpObject constructors, so could be made generic. I also noticed that ObjectVectorClass copies the type parameter to each *instance* of ObjectVector. Seems more appropraiate for the parameter to live on the instance vtable.
Blocks: 583074
Blocks: 597577
Status: NEW → ASSIGNED
This will be useful, but you might as well hold off - the exactgc work touches the createInstance methods extensively, you'll have massive merge conflicts (at least in Tamarin).
While we're at we should really figure out a way to get around having to write a boilerplate ctor to, ie: DomainObject::DomainObject(VTable *vtable, ScriptObject *delegate) : ScriptObject(vtable, delegate) {} Maybe the existing macros provided by the nativegen stuff could provide. The ctor should probably be private too and only createInstance should call it no. Actually we should probably declare and not implement a private default constructor too.
In general the ctor must be protected, because some native classes subclass other native classes. And not all constructors are trivial, though the majority are. So there needs to be an escape hatch. The private default constructor will be redundant if there's another constructor present, no?
(In reply to comment #3) > This will be useful, but you might as well hold off - the exactgc work touches > the createInstance methods extensively, you'll have massive merge conflicts (at > least in Tamarin). Yeah, not actively working on it, we can re-evaluate once exactgc lands.
(In reply to comment #5) > In general the ctor must be protected, because some native classes subclass > other native classes. > > And not all constructors are trivial, though the majority are. So there needs > to be an escape hatch. Yeah, this goes for createInstance and ctor (obviously). > The private default constructor will be redundant if there's another > constructor present, no? My concern was more about developer adding their own and using it. If we declare a private one and don't implement it we can keep that from happening.
No longer depends on: 565664
Is this still useful given Steven's ANI changes to auto-generate a createInstance equivalent?
Status: ASSIGNED → NEW
Flags: flashplayer-qrb+
Flags: flashplayer-bug-
Target Milestone: --- → Future
no
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.