Skip to content

Commit

Permalink
tests: Add test for confirming that target getter is called to determ…
Browse files Browse the repository at this point in the history
…ine whether to call clone

Test written by Adrian17
  • Loading branch information
Lord-McSweeney authored and torokati44 committed Jan 16, 2025
1 parent eb3a4e4 commit fc217ab
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/tests/swfs/avm2/event_target_getter/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// compiled with mxmlc

import flash.events.Event;
import flash.display.DisplayObject;

package {
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.Event;

public class Test extends MovieClip {
public function Test(){
var d = new MovieClip();
trace("// testing trivial getter")
var e1 = new E1("e1", d);
d.dispatchEvent(e1);

trace("// testing 1-cycle-delayed getter")
var e2 = new E2("e2", d);
d.dispatchEvent(e2);
}

}
}


class E1 extends Event {
private var dobj: DisplayObject;
public function E1(type, dobj){
super(type, false, false);
this.dobj = dobj;
}
override public function get target(): Object {
trace("in get target()");
return this.dobj;
}
override public function clone(): Event {
trace("in clone()");
return new E1(this.type, this.dobj);
}
}

class E2 extends Event {
private var ready: Boolean;
private var dobj: DisplayObject;
public function E2(type, d){
super(type, false, false);
this.ready = false;
this.dobj = dobj;
}
override public function get target(): Object {
trace("in get target()");
if (this.ready) {
return this.dobj;
}
this.ready = true;
return null;
}
override public function clone(): Event {
trace("in clone()");
return new E2(this.type, this.dobj);
}
}
5 changes: 5 additions & 0 deletions tests/tests/swfs/avm2/event_target_getter/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// testing trivial getter
in get target()
in clone()
// testing 1-cycle-delayed getter
in get target()
Binary file added tests/tests/swfs/avm2/event_target_getter/test.swf
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/tests/swfs/avm2/event_target_getter/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The test observes dispatcher accessing `.target` to check if event is being re-dispatched.
num_frames = 1

0 comments on commit fc217ab

Please sign in to comment.