Hey Chris,
No, mock-as3 is a mocking library along the lines of JMock, whereas
asmock is record-and-playback. Brian LeGros sent me a link to asmock
the other day, since it has a bytecode weaving library in it called
flemit. I looked through asmock and flemit, and the mocking and
bytecode generation parts are currently coupled, although Richard
mentioned on his site that he intends to split them apart after he
gets the mocking finished.
Richard has done a nice job with both libaries. It was kind of funny
looking through flemit since the domain classes are really similar to
Loom's (which is unsurprising since they both map the AVM2 spec).
However, the generation approach is different.
flemit/asmock's approach is:
1) List the classes you want to generate mocks for
2) Use describeType() to introspect them
3) Create class definitions from describeType's XML definitions,
replacing the opcodes with the mocking instructions
4) Write to bytecode
5) SWF-load the bytecode
6) Run the unit tests
Loom's approach is:
1) SWF-load, introspecting the ABC bytecode at load-time
2) Weave proxy subclasses based upon metadata tags in the original SWF
3) Run code
4) Advise at runtime
Advice can be added to Loom's proxies as you see fit on a per-
instance basis, since the advice will just be method closures.
Obviously, you'd use a factory to add the same advice over and over.
You could also weave opcodes during step 2 if you want to (which I
plan on having support for since it's what I'll to generate the
proxies), but then you have to understand AVM opcodes in depth, which
most people won't. I want people to be able to use Loom without
understanding the AVM, so the runtime proxy is the way to go. I also
plan to have a describeType()-based runtime loader/adapter, but it's
not my first priority since I already have an ABC parser.
> ... In order to handle that transparently, we would need to
> override accessors, and make them bindable. Actually, we'll need to
> preserve bindable wherever we find it.
Properties are different beasts than other slot traits in the ABC
bytecode, so we can differentiate them and handle them however we
want. I believe that the Flex compiler expands Bindable metadata in to
code, so we should get all the bindable stuff for free; you'd just
proceed a method invocation to the bound properties in the superclass
after applying advice. Worst case, we can write opcodes to do whatever
we want - you just write the code in Flex, use my abcdump utility to
get the opcodes, and use them as a template, then use Loom's API to
inject the opcodes during the load-and-weave step.
- max