diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index f8fac53bd..c3da00cac 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -185,16 +185,9 @@ pub struct Activation<'a, 'gc: 'a> { /// The currently in use constant pool. constant_pool: Gc<'gc, Vec>>, - /// The immutable value of `this`. + /// The value of `this`. /// - /// This differs from Flash Player, where `this` is mutable and seems - /// to be part of the scope chain (e.g. a function with the `suppress_this` flag - /// set can modify the `this` value of its closure). - /// - /// Fortunately, ActionScript syntax prevents mutating `this` altogether, so - /// observing this behavior requires manually-crafted bytecode. - /// - /// TODO: implement correct semantics for mutable `this`. + /// While this is not *usually* modified, ActionScript does allow `this` to be modified this: Value<'gc>, /// The function object being called. @@ -2637,6 +2630,12 @@ impl<'a, 'gc> Activation<'a, 'gc> { return Ok(()); } + // Special case, mutating `this` + if path.as_wstr() == WStr::from_units(b"this") { + self.this = value; + return Ok(()); + } + // Find the right-most : or . in the path. // If we have one, we must resolve as a target path. let separator = path.rfind(b":.".as_ref()); diff --git a/tests/tests/swfs/avm1/mutable_this/output.txt b/tests/tests/swfs/avm1/mutable_this/output.txt new file mode 100644 index 000000000..0cd68fe3f --- /dev/null +++ b/tests/tests/swfs/avm1/mutable_this/output.txt @@ -0,0 +1,18 @@ +this = _level0 +typeof this = movieclip +this = test +typeof this = string +In foo +this = _level0 +typeof this = movieclip +this = 1234 +typeof this = number +In nested +this = _level0 +typeof this = movieclip +this = null +typeof this = null +Exit nested +this = 1234 +typeof this = number +Exit foo diff --git a/tests/tests/swfs/avm1/mutable_this/test.fla b/tests/tests/swfs/avm1/mutable_this/test.fla new file mode 100644 index 000000000..8afbaf125 Binary files /dev/null and b/tests/tests/swfs/avm1/mutable_this/test.fla differ diff --git a/tests/tests/swfs/avm1/mutable_this/test.swf b/tests/tests/swfs/avm1/mutable_this/test.swf new file mode 100644 index 000000000..e86cb6eb2 Binary files /dev/null and b/tests/tests/swfs/avm1/mutable_this/test.swf differ diff --git a/tests/tests/swfs/avm1/mutable_this/test.toml b/tests/tests/swfs/avm1/mutable_this/test.toml new file mode 100644 index 000000000..dbee897f5 --- /dev/null +++ b/tests/tests/swfs/avm1/mutable_this/test.toml @@ -0,0 +1 @@ +num_frames = 1