<commit_before>/**
 * Copyright 2014 Mozilla Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// Class: DisplayObjectContainer
module Shumway.AVM2.AS.flash.display {
  import notImplemented = Shumway.Debug.notImplemented;
  import asCoerceString = Shumway.AVM2.Runtime.asCoerceString;
  import throwError = Shumway.AVM2.Runtime.throwError;
  import clamp = Shumway.NumberUtilities.clamp;

  var Event: typeof flash.events.Event;

  export class DisplayObjectContainer extends flash.display.InteractiveObject {
    static bindings: string [] = null;
    static classSymbols: string [] = null;
    static classInitializer: any = function () {
      Event = flash.events.Event;
    };

    static initializer: any = function () {
      var self: DisplayObjectContainer = this;
      self._tabChildren = true;
      self._mouseChildren = true;
      self._children = [];
    };

    _tabChildren: boolean;
    _mouseChildren: boolean;
    _children: DisplayObject [];

    constructor () {
      false && super();
      InteractiveObject.instanceConstructorNoInitialize.call(this);
    }

    /**
     * This object's children have changed.
     */
    private _invalidateChildren() {

    }

    get numChildren(): number {
      return this._children.length;
    }

    get textSnapshot(): flash.text.TextSnapshot {
      notImplemented("public DisplayObjectContainer::get textSnapshot"); return;
      // return this._textSnapshot;
    }

    get tabChildren(): boolean {
      return this._tabChildren;
    }

    set tabChildren(enable: boolean) {
      enable = !!enable;

      var old = this._tabChildren;
      this._tabChildren = enable;
      if (old !== enable) {
        this.dispatchEvent(new Event(Event.TAB_CHILDREN_CHANGE, true));
      }
    }

    get mouseChildren(): boolean {
      return this._mouseChildren;
    }

    set mouseChildren(enable: boolean) {
      this._mouseChildren = !!enable;
    }

    addChild(child: DisplayObject): DisplayObject {
      return this.addChildAt(child, this._children.length);
    }

    addChildAt(child: DisplayObject, index: number /*int*/): DisplayObject {
      index = index | 0;

      assert (child._hasFlags(DisplayObjectFlags.Constructed));
      if (child === this) {
        throwError('ArgumentError', Errors.CantAddSelfError);
      }
      if (DisplayObjectContainer.isType(child) && (<DisplayObjectContainer>child).contains(this)) {
        throwError('ArgumentError', Errors.CantAddParentError);
      }
      var children = this._children;
      if (index < 0 || index > children.length) {
        throwError('RangeError', Errors.ParamRangeError);
      }

      if (child._parent === this) {
        this.setChildIndex(child, index);
        return child;
      }

      if (child._parent) {
        child._parent.removeChild(child);
        // The children list could have been mutated as a result of |removeChild|.
        index = clamp(index, 0, children.length)
      }
      for (var i = children.length; i > index; i--) {
        children[i - 1]._index++;
      }
      children.splice(index, 0, child);
      child._index = index;
      child._parent = this;
      child._invalidatePosition();
      child.dispatchEvent(new Event(Event.ADDED, true));
      this._invalidateChildren();
      return child;
    }

    addChildAtDepth(child: flash.display.DisplayObject, depth: number /*int*/) {
      depth = depth | 0;

      var children = this._children;
      var maxIndex = children.length - 1;
      var index = maxIndex + 1;
      for (var i = maxIndex; i >= 0; i--) {
        var current = children[i];
        if (current._depth && current._depth < depth) {
          index = i;
          break;
        }
      }
      if (index > maxIndex) {
        children.push(child);
        child._index = index;
      } else {
        children.splice(i, 1, child);
        for (var i = index; i <= maxIndex; i++) {
          children[i]._index = i;
        }
      }
      child._parent = this;
      child._invalidatePosition();
    }

    removeChild(child: DisplayObject): DisplayObject {
      //child = child
      return this.removeChildAt(this.getChildIndex(child));
    }

    removeChildAt(index: number): DisplayObject {
      index = index | 0;

      var children = this._children;
      if (index < 0 || index >= children.length) {
        throwError('RangeError', Errors.ParamRangeError);
      }

      var child = children[index];
      if (child._hasFlags(DisplayObjectFlags.Constructed)) {<commit_msg>Fixing addChildAtDepth again<commit_after>/**
 * Copyright 2014 Mozilla Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// Class: DisplayObjectContainer
module Shumway.AVM2.AS.flash.display {
  import notImplemented = Shumway.Debug.notImplemented;
  import asCoerceString = Shumway.AVM2.Runtime.asCoerceString;
  import throwError = Shumway.AVM2.Runtime.throwError;
  import clamp = Shumway.NumberUtilities.clamp;

  var Event: typeof flash.events.Event;

  export class DisplayObjectContainer extends flash.display.InteractiveObject {
    static bindings: string [] = null;
    static classSymbols: string [] = null;
    static classInitializer: any = function () {
      Event = flash.events.Event;
    };

    static initializer: any = function () {
      var self: DisplayObjectContainer = this;
      self._tabChildren = true;
      self._mouseChildren = true;
      self._children = [];
    };

    _tabChildren: boolean;
    _mouseChildren: boolean;
    _children: DisplayObject [];

    constructor () {
      false && super();
      InteractiveObject.instanceConstructorNoInitialize.call(this);
    }

    /**
     * This object's children have changed.
     */
    private _invalidateChildren() {

    }

    get numChildren(): number {
      return this._children.length;
    }

    get textSnapshot(): flash.text.TextSnapshot {
      notImplemented("public DisplayObjectContainer::get textSnapshot"); return;
      // return this._textSnapshot;
    }

    get tabChildren(): boolean {
      return this._tabChildren;
    }

    set tabChildren(enable: boolean) {
      enable = !!enable;

      var old = this._tabChildren;
      this._tabChildren = enable;
      if (old !== enable) {
        this.dispatchEvent(new Event(Event.TAB_CHILDREN_CHANGE, true));
      }
    }

    get mouseChildren(): boolean {
      return this._mouseChildren;
    }

    set mouseChildren(enable: boolean) {
      this._mouseChildren = !!enable;
    }

    addChild(child: DisplayObject): DisplayObject {
      return this.addChildAt(child, this._children.length);
    }

    addChildAt(child: DisplayObject, index: number /*int*/): DisplayObject {
      index = index | 0;

      assert (child._hasFlags(DisplayObjectFlags.Constructed));
      if (child === this) {
        throwError('ArgumentError', Errors.CantAddSelfError);
      }
      if (DisplayObjectContainer.isType(child) && (<DisplayObjectContainer>child).contains(this)) {
        throwError('ArgumentError', Errors.CantAddParentError);
      }
      var children = this._children;
      if (index < 0 || index > children.length) {
        throwError('RangeError', Errors.ParamRangeError);
      }

      if (child._parent === this) {
        this.setChildIndex(child, index);
        return child;
      }

      if (child._parent) {
        child._parent.removeChild(child);
        // The children list could have been mutated as a result of |removeChild|.
        index = clamp(index, 0, children.length)
      }
      for (var i = children.length; i > index; i--) {
        children[i - 1]._index++;
      }
      children.splice(index, 0, child);
      child._index = index;
      child._parent = this;
      child._invalidatePosition();
      child.dispatchEvent(new Event(Event.ADDED, true));
      this._invalidateChildren();
      return child;
    }

    addChildAtDepth(child: flash.display.DisplayObject, depth: number /*int*/) {
      depth = depth | 0;

      var children = this._children;
      var maxIndex = children.length - 1;
      var index = maxIndex + 1;
      for (var i = maxIndex; i >= 0; i--) {
        var current = children[i];
        if (current._depth && current._depth < depth) {
          index = i + 1;
          break;
        }
      }
      if (index > maxIndex) {
        children.push(child);
        child._index = index;
      } else {
        children.splice(i, 1, child);
        for (var i = index; i <= maxIndex; i++) {
          children[i]._index = i;
        }
      }
      child._parent = this;
      child._invalidatePosition();
    }

    removeChild(child: DisplayObject): DisplayObject {
      //child = child
      return this.removeChildAt(this.getChildIndex(child));
    }

    removeChildAt(index: number): DisplayObject {
      index = index | 0;

      var children = this._children;
      if (index < 0 || index >= children.length) {
        throwError('RangeError', Errors.ParamRangeError);
      }

      var child = children[index];
      if (child._hasFlags(DisplayObjectFlags.Constructed)) {
{'fraction_non_alphanumeric': 0.11117734724292101, 'fraction_numerical': 0.004669647292598112, 'mean_word_length': 2.643141512848353, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1682902', 'n_tokens_mistral': 2876, 'n_tokens_neox': 2774, 'n_words': 741}