jcbloch / as3-commons

Automatically exported from code.google.com/p/as3-commons
0 stars 0 forks source link

ByteCodeType.methods are not always of type ByteCodeMethod, but Method (causes RTE) #70

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Execute ByteCodeType.forClass on a Flex Application class
2. Check the methods property (or see attached image)

What is the expected output? What do you see instead?
TypeError: Error #1034: Type Coercion failed: cannot convert 
org.as3commons.reflect::Method@20654481 to 
org.as3commons.bytecode.reflect.ByteCodeMethod.

What version of the product are you using? On what operating system?
Trunk, OSX 10.7

Please provide any additional information below.
In my case, I found this in ClassIntroducer.internalIntroduce in the for each 
loop. There are many instances of this throughout the framework that loops 
expect all items in ByteCodeType.methods to be ByteCodeMethod and not its 
subclass Method.

Original issue reported on code.google.com by jeff.ard...@gmail.com on 11 Aug 2011 at 3:19

Attachments:

GoogleCodeExporter commented 9 years ago
Hm, that's weird, I thought I had gotten rid of those... I'll have to 
investigate... Sorry :)

cheers,

Roland

Original comment by ihatelivelyids on 11 Aug 2011 at 4:30

GoogleCodeExporter commented 9 years ago
strange, I just added a unit test that does this:

var type:ByteCodeType = ByteCodeType.forClass(Application);
for each (var method:ByteCodeMethod in type.methods) {
  var i:int = 0;
}

And it passes, so there must be something different going on...

Original comment by ihatelivelyids on 11 Aug 2011 at 4:52

GoogleCodeExporter commented 9 years ago
Here is a simple test I had, see attached.

Original comment by jeff.ard...@gmail.com on 11 Aug 2011 at 4:59

Attachments:

GoogleCodeExporter commented 9 years ago
Hey there,

there was indeed a bit of legacy code left in ByteCodeType, I've removed it and 
all should be fine now.
However, if you want ByteCodeType to parse the framework libraries, you will 
need to tell the lib to do so, like this:

ByteCodeType.fromLoader(loaderInfo);
for (var info:* in systemManager.preloadedRSLs) {
    ByteCodeType.fromLoader(info);
}
for each (var m:ByteCodeMethod in ByteCodeType.forInstance(this).methods) {
    trace(m);
}

Otherwise you'll miss a couple of classes...

I'll close this ticket now. Did you try issue the fixes for 
https://code.google.com/p/as3-commons/issues/detail?id=69 as well?

cheers,

Roland

Original comment by ihatelivelyids on 11 Aug 2011 at 6:08

GoogleCodeExporter commented 9 years ago
That worked for that error, I still have another error further down the line in 
my actual use case which I believe maybe related to your note about the RSL's. 
I'm using ClassIntroducer to introduce one class into another and during build, 
its dying on BaseTypeBuilder.createInitializer as determinePushOpcode(slot) is 
returning null. I guess if the class I am trying to introduce extends in its 
chain classes which are defined in the RSL's (even though the root class is 
not), then I need to also parse the RSL's? Is that the case?

Original comment by jeff.ard...@gmail.com on 11 Aug 2011 at 6:48

GoogleCodeExporter commented 9 years ago
Hi again,

be very careful with using introductions, they aren't quite stable yet. And as 
the documentation states:

http://www.as3commons.org/as3-commons-bytecode/proxy.html#Introductions

"Introduced class can only inherit from the Object class"

The introductions seem to work ok in a debug build, but cause some weird 
parsing errors in release builds. Especially in method bodies that use switch 
statements, I'm still suffering from some very subtle bugs in the parsing logic 
for the opcodes.

cheers,

Roland

Original comment by ihatelivelyids on 11 Aug 2011 at 7:14