defineClass and mapInheritance

19 views
Skip to first unread message

Tim Schaub

unread,
Jun 4, 2012, 1:37:20 AM6/4/12
to mozill...@googlegroups.com
I've been having a bear of a time getting prototype chains set up
properly with defineClass. Its now clear to me that calling
defineClass twice on the same scope with two classes that share a
superclass doesn't work - the prototype for the superclass is created
twice, making instanceof checks fail for the first.

Here's a test that demonstrates the issue:
https://github.com/tschaub/rhino/commit/28aebe818e05f6c838b1f965369450ecb641f8ac

The problem (if others think this is a problem) is that there is never
a check to see if the prototype for the superclass has already been
added to the scope. The easiest way for me to fix this was to check
for the class prototype after calling buildClassCtor in defineClass.
This is a fair bit of extra work (calling buildClasCtor twice) before
deciding we've been here before. But again, it works.

https://github.com/mozilla/rhino/pull/48/files

Is there another way that defineClass is supposed to work with two siblings?

Thanks,
Tim
Reply all
Reply to author
Forward
0 new messages