Created
January 5, 2011 10:53
-
-
Save drewbourne/766170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mockolate.bytecode | |
{ | |
import flash.events.Event; | |
import mx.core.FlexGlobals; | |
import org.as3commons.bytecode.proxy.ProxyFactory; | |
import org.as3commons.bytecode.reflect.ByteCodeType; | |
import org.flexunit.async.Async; | |
import org.hamcrest.assertThat; | |
import org.hamcrest.object.isTrue; | |
public class BytecodeTest | |
{ | |
public var factory:ProxyFactory = new ProxyFactory(); | |
[BeforeClass] | |
public static function beforeClass():void | |
{ | |
ByteCodeType.fromLoader(FlexGlobals.topLevelApplication.loaderInfo); | |
} | |
[Before(async)] | |
public function before():void | |
{ | |
factory = new ProxyFactory(); | |
factory.defineProxy(Flavour, MethodInterceptor); | |
Async.proceedOnEvent(this, factory, Event.COMPLETE); | |
factory.generateProxyClasses(); | |
factory.loadProxyClasses(); | |
} | |
[Test] | |
public function creatingClassFromAnotherClass():void | |
{ | |
var proxy:Flavour = factory.createProxy(Flavour) as Flavour; | |
var called:Boolean = false; | |
MethodInterceptor.callback = function(...args):Object | |
{ | |
called = true; | |
return false; | |
}; | |
proxy.combine(null); | |
assertThat(called, isTrue()); | |
} | |
} | |
} | |
import org.as3commons.bytecode.interception.IMethodInvocationInterceptor; | |
import org.as3commons.bytecode.interception.InvocationKind; | |
internal class MethodInterceptor implements IMethodInvocationInterceptor | |
{ | |
public static var callback:Function; | |
public function intercept(targetInstance:Object, kind:InvocationKind, member:QName, arguments:Array = null, method:Function = null):* | |
{ | |
if (callback != null) | |
callback.apply(null, [{ target: targetInstance, kind: kind, member: member, arguments: arguments, method: method }]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mockolate.bytecode | |
{ | |
public interface Flavour | |
{ | |
// read-only | |
function get name():String; | |
// read & write | |
function get ingredients():Array; | |
function set ingredients(value:Array):void; | |
// write-only | |
function set liked(value:Boolean):void; | |
// typed & rest | |
// function combine(flavour:Flavour, ... otherFlavours):Flavour; | |
function combine(...rest):void; | |
// no arg | |
function toString():String; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error: constant pool item cannot be null | |
at org.as3commons.lang::Assert$/notNull(Assert.as:78) | |
at org.as3commons.bytecode.abc::ConstantPool/addToPool(ConstantPool.as:517) | |
at org.as3commons.bytecode.abc::ConstantPool/addString(ConstantPool.as:413) | |
at org.as3commons.bytecode.abc::ConstantPool/addObject(ConstantPool.as:313) | |
at org.as3commons.bytecode.abc::ConstantPool/addNamespace(ConstantPool.as:457) | |
at org.as3commons.bytecode.abc::ConstantPool/addMultiname(ConstantPool.as:273) | |
at org.as3commons.bytecode.io::AbcSerializer/serializeTraits(AbcSerializer.as:180) | |
at org.as3commons.bytecode.io::AbcSerializer/serializeClassAndInstanceInfo(AbcSerializer.as:307) | |
at org.as3commons.bytecode.io::AbcSerializer/serializeAbcFile(AbcSerializer.as:101) | |
at org.as3commons.bytecode.swf::AbcClassLoader/loadAbcFile(AbcClassLoader.as:131) | |
at org.as3commons.bytecode.emit.impl::AbcBuilder/buildAndLoad(AbcBuilder.as:241) | |
at org.as3commons.bytecode.proxy::ProxyFactory/loadProxyClasses(ProxyFactory.as:237) | |
**[ at org.mockolate.bytecode::BytecodeTest/before(BytecodeTest.as:30) ] | |
at Function/http://adobe.com/AS3/2006/builtin::apply | |
at flex.lang.reflect::Method/apply(Method.as:244) | |
at org.flexunit.runners.model::FrameworkMethod/invokeExplosively(FrameworkMethod.as:201) | |
at org.flexunit.internals.runners.statements::InvokeMethod/evaluate(InvokeMethod.as:72) | |
at org.flexunit.internals.runners.statements::ExpectAsync/evaluate(ExpectAsync.as:595) | |
at org.flexunit.internals.runners.statements::SequencerWithDecoration/executeStep(SequencerWithDecoration.as:100) | |
at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete(StatementSequencer.as:141) | |
at org.flexunit.internals.runners.statements::StatementSequencer/evaluate(StatementSequencer.as:109) | |
at org.flexunit.internals.runners.statements::RunBeforesInline/evaluate(RunBeforesInline.as:70) | |
at org.flexunit.internals.runners.statements::StackAndFrameManagement/handleTimerComplete(StackAndFrameManagement.as:138) | |
at flash.events::EventDispatcher/dispatchEventFunction | |
at flash.events::EventDispatcher/dispatchEvent | |
at flash.utils::Timer/tick |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I tried this example, am getting =
Error: No ByteCodeType instance could be retrieved for class name 'String', make sure the same ApplicationDomain instance is passed to defineProxy
Any clue how I can ByteCodeType in flexunit tests?