<commit_before>const MovieClipDefinition = (function () {
  var def = {
    __class__: 'flash.display.MovieClip',

    initialize: function () {
      this._currentFrame = 0;
      this._currentFrameLabel = null;
      this._currentLabel = false;
      this._currentScene = { };
      this._depthMap = [];
      this._enabled = null;
      this._frameScripts = { };
      this._frameLabels = { };
      this._framesLoaded = 1;
      this._isPlaying = true;
      this._scenes = { };
      this._timeline = null;
      this._totalFrames = 1;
      this._scenes = { };

      var s = this.symbol;
      if (s) {
        this._timeline = s.timeline || null;
        this._framesLoaded = s.framesLoaded || 1;
        this._frameLabels = s.frameLabels || {};
        this._totalFrames = s.totalFrames || 1;
      }
    },

    _callFrame: function (frameNum) {
      if (frameNum in this._frameScripts) {
        var scripts = this._frameScripts[frameNum];
        for (var i = 0, n = scripts.length; i < n; i++)
          scripts[i].call(this);
      }
    },
    _getAS2Object: function () {
      if (!this.$as2Object) {
        new AS2MovieClip().$attachNativeObject(this);
      }
      return this.$as2Object;
    },
    _gotoFrame: function (frameNum, scene) {
      if (frameNum > this._totalFrames)
        frameNum = 1;

      if (frameNum > this.framesLoaded)
        frameNum = this.framesLoaded;

      if (frameNum === this._currentFrame)
        return;

      if (frameNum === 0) {
        // HACK there is no data for this frame, but AS2 can jump to this frame index
        this._currentFrame = 0;
        return;
      }

      var children = this._children;
      var depthMap = this._depthMap;
      var framePromise = this._timeline[frameNum - 1];
      var highestDepth = depthMap.length;
      var displayList = framePromise.value;
      var loader = this.loaderInfo._loader;

      for (var depth in displayList) {
        var cmd = displayList[depth];
        var current = depthMap[depth];
        if (cmd === null) {
          if (current && current._owned) {
            var index = children.indexOf(current);
            children.splice(index, 1);
            this._control.removeChild(current._control);

            if (depth <= highestDepth)
              depthMap[depth] = undefined;
            else
              depthMap.splice(-1);
          }
        } else {
          var clipDepth = cmd.clipDepth;
          var cxform = cmd.cxform;
          var matrix = cmd.matrix;
          var target;

          if (cmd.symbolId) {
            var index = 0;
            var symbolPromise = loader._dictionary[cmd.symbolId];
            var symbolInfo = symbolPromise.value;
            // HACK application domain may have the symbol class --
            // checking which domain has a symbol class
            var symbolClass = avm2.systemDomain.findClass(symbolInfo.className) ?
              avm2.systemDomain.getClass(symbolInfo.className) :
              avm2.applicationDomain.getClass(symbolInfo.className);
            var instance = symbolClass.createAsSymbol(symbolInfo.props);
            var replace = 0;

            if (current && current._owned) {
              if (!clipDepth)
                clipDepth = current._clipDepth;
              if (!cxform)
                cxform = current._cxform;
              index = children.indexOf(current);
              if (!matrix)
                matrix = current._currentTransform;
              replace = 1;
            } else {
              var top = null;
              for (var i = +depth + 1; i < highestDepth; i++) {
                var info = depthMap[i];
                if (info && info._animated)
                  top = info;
              }

              index = top ? children.indexOf(top) : children.length;
            }

            children.splice(index, replace, instance);
            depthMap[depth] = instance;

            target = instance;

            // If we bound the instance to a name, set it.
            //
            // XXX: I think this always has to be a trait.
            if (cmd.name)
              this[Multiname.getPublicQualifiedName(cmd.name)] = instance;

            // Call the constructor now that we've made the symbol instance,
            // instantiated all its children, and set the display list-specific
            // properties.
            //
            // XXX: I think we're supposed to throw if the symbol class
            // constructor is not nullary.
            symbolClass.instance.call(instance);

            if (!loader._isAvm2Enabled) {
              this._initAvm1Bindings(cmd, symbolInfo.props, instance);
            }

            instance._animated = true;
            instance._owned = true;
            instance._parent = this;
            instance._name = cmd.name || null;

            if (replace)
              this._control.replaceChild(instance._control, current._control);
            else
              this._control.appendChild(instance._control);

            instance.dispatchEvent(new flash.events.Event("load"));
          } else if (current && current._animated) {
            target = current;
          }

          if (clipDepth)
            target._clipDepth = clipDepth;
          if (cxform)
            target._cxform = cxform;
          if (matrix) {
            var a = matrix.a;
            var b = matrix.b;
            var c = matrix.c;
            var d = matrix.d;

            target._rotation = Math.atan2(b, a) * 180 / Math.PI;
            var sx = Math.sqrt(a * a + b * b);
            target._scaleX = a > 0 ? sx : -sx;
            var sy = Math.sqrt(d * d + c * c);
            target._scaleY = d > 0 ? sy : -sy;
            var x = target._x = matrix.tx;
            var y = target._y = matrix.ty;

            target._currentTransform = matrix;
          }
        }<commit_msg>Fix display list construction.<commit_after>const MovieClipDefinition = (function () {
  var def = {
    __class__: 'flash.display.MovieClip',

    initialize: function () {
      this._currentFrame = 0;
      this._currentFrameLabel = null;
      this._currentLabel = false;
      this._currentScene = { };
      this._depthMap = [];
      this._enabled = null;
      this._frameScripts = { };
      this._frameLabels = { };
      this._framesLoaded = 1;
      this._isPlaying = true;
      this._scenes = { };
      this._timeline = null;
      this._totalFrames = 1;
      this._scenes = { };

      var s = this.symbol;
      if (s) {
        this._timeline = s.timeline || null;
        this._framesLoaded = s.framesLoaded || 1;
        this._frameLabels = s.frameLabels || {};
        this._totalFrames = s.totalFrames || 1;
      }
    },

    _callFrame: function (frameNum) {
      if (frameNum in this._frameScripts) {
        var scripts = this._frameScripts[frameNum];
        for (var i = 0, n = scripts.length; i < n; i++)
          scripts[i].call(this);
      }
    },
    _getAS2Object: function () {
      if (!this.$as2Object) {
        new AS2MovieClip().$attachNativeObject(this);
      }
      return this.$as2Object;
    },
    _gotoFrame: function (frameNum, scene) {
      if (frameNum > this._totalFrames)
        frameNum = 1;

      if (frameNum > this.framesLoaded)
        frameNum = this.framesLoaded;

      var currentFrame = this._currentFrame;

      if (frameNum === currentFrame)
        return;

      if (frameNum === 0) {
        // HACK there is no data for this frame, but AS2 can jump to this frame index
        this._currentFrame = 0;
        return;
      }

      while (currentFrame++ < frameNum) {
        var children = this._children;
        var depthMap = this._depthMap;
        var framePromise = this._timeline[currentFrame - 1];
        var highestDepth = depthMap.length;
        var displayList = framePromise.value;
        var loader = this.loaderInfo._loader;

        for (var depth in displayList) {
          var cmd = displayList[depth];
          var current = depthMap[depth];
          if (cmd === null) {
            if (current && current._owned) {
              var index = children.indexOf(current);
              children.splice(index, 1);
              this._control.removeChild(current._control);

              if (depth < highestDepth)
                depthMap[depth] = undefined;
              else
                depthMap.splice(-1);
            }
          } else {
            var clipDepth = cmd.clipDepth;
            var cxform = cmd.cxform;
            var matrix = cmd.matrix;
            var target;

            if (cmd.symbolId) {
              var index = 0;
              var symbolPromise = loader._dictionary[cmd.symbolId];
              var symbolInfo = symbolPromise.value;
              // HACK application domain may have the symbol class --
              // checking which domain has a symbol class
              var symbolClass = avm2.systemDomain.findClass(symbolInfo.className) ?
                avm2.systemDomain.getClass(symbolInfo.className) :
                avm2.applicationDomain.getClass(symbolInfo.className);
              var instance = symbolClass.createAsSymbol(symbolInfo.props);
              var replace = 0;

              if (current && current._owned) {
                if (!clipDepth)
                  clipDepth = current._clipDepth;
                if (!cxform)
                  cxform = current._cxform;
                index = children.indexOf(current);
                if (!matrix)
                  matrix = current._currentTransform;
                replace = 1;
              } else {
                var top = null;
                for (var i = +depth + 1; i < highestDepth; i++) {
                  var info = depthMap[i];
                  if (info && info._animated) {
                    top = info;
                    break;
                  }
                }

                index = top ? children.indexOf(top) : children.length;
              }

              children.splice(index, replace, instance);
              depthMap[depth] = instance;

              target = instance;

              // If we bound the instance to a name, set it.
              //
              // XXX: I think this always has to be a trait.
              if (cmd.name)
                this[Multiname.getPublicQualifiedName(cmd.name)] = instance;

              // Call the constructor now that we've made the symbol instance,
              // instantiated all its children, and set the display list-specific
              // properties.
              //
              // XXX: I think we're supposed to throw if the symbol class
              // constructor is not nullary.
              symbolClass.instance.call(instance);

              if (!loader._isAvm2Enabled) {
                this._initAvm1Bindings(cmd, symbolInfo.props, instance);
              }

              instance._animated = true;
              instance._owned = true;
              instance._parent = this;
              instance._name = cmd.name || null;

              if (replace)
                this._control.replaceChild(instance._control, current._control);
              else
                this._control.appendChild(instance._control);

              instance.dispatchEvent(new flash.events.Event("load"));
            } else if (current && current._animated) {
              target = current;
            }

            if (clipDepth)
              target._clipDepth = clipDepth;
            if (cxform)
              target._cxform = cxform;
            if (matrix) {
              var a = matrix.a;
              var b = matrix.b;
              var c = matrix.c;
              var d = matrix.d;

              target._rotation = Math.atan2(b, a) * 180 / Math.PI;
              var sx = Math.sqrt(a * a + b * b);
              target._scaleX = a > 0 ? sx : -sx;
              var sy = Math.sqrt(d * d + c * c);
              target._scaleY = d > 0 ? sy : -sy;
              var x = target._x = matrix.tx;
              var y = target._y = matrix.ty;

              target._currentTransform = matrix;
            }
          }
        }
{'fraction_non_alphanumeric': 0.1013786840584496, 'fraction_numerical': 0.00528357962519607, 'mean_word_length': 1.5054808686659773, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3493129', 'n_tokens_mistral': 3286, 'n_tokens_neox': 3146, 'n_words': 830}