Uploaded image for project: 'Railo'
  1. Railo
  2. RAILO-3099

Function/Closure scopes binding to creation location and not caller location

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: 4.2.1.001, 4.1.3.002
    • Fix Version/s: None
    • Labels:
      None

      Description

      There is a difference between Railo 4.0.4.001 and 4.1+ when dynamically adding functions to a CFC and which scopes that function binds to.

      See a simplified same below where in component1.cfc I instantiate component2, and I define a function on the THIS scope of component2

      //component1.cfc
      component {

      variables.testValue = "Component1";

      public function test(){

      local.com2 = new component2();
      local.com2.override = function()

      { writeDump(this); //References the this scope of component1 when it should be component2 writeDump(variables); //References the variables scope of component1 when it should be component2 }


      local.com2.override();
      }
      }

      My intention is to be able to spy/inject values into component2 variables scope from component1 dynamically on the fly without having to write a temporary wrapper CFC to extend component 2. This worked as I expected in 4.0.4, but not in 4.1 or 4.2. Attached is the test code for those interested.

        Gliffy Diagrams

          Attachments

          1. 4.0.4.jpg
            4.0.4.jpg
            140 kB
          2. 4.2.jpg
            4.2.jpg
            174 kB
          3. inject_test.zip
            0.8 kB

            Activity

              People

              • Assignee:
                micstriit Michael Offner
                Reporter:
                rorylaitila Rory Laitila
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: