<commit_before>import { IStackEntry } from "../interface/IStackEntry"
import { IMetadata } from "../interface/IMetadata"

/**
 * {class} CallStackIterator
 * this class contains all accessible references within the advice call stack and
 * controls when advices must be invoked, also whether or not main method should
 * be called
 */
export class CallStackIterator {
  private index: number = -1
  private proceed: boolean = true

    /**
     * {constructor}
     * receives all the metadata and builds up a shorted array with the current
     * call stack
     * @param {IMetadata} metadata  current metadata for this stack
     */
  constructor (private metadata: IMetadata, private stack: IStackEntry[], private exceptionEntry?: IStackEntry) {
    this.next()
  }

    /**
     * next - this method will resolve by calling the next advice in the call stack
     * or calling the main method
     */
  next() {
    this.index++

    let currentEntry = this.stack[this.index]

    if(currentEntry === undefined) {
      return
    }

    if(this.proceed && currentEntry === null) {
      if(!this.exceptionEntry) {
        this.invokeOriginal()
        this.next()
        return
      } else {
        try {
          this.invokeOriginal()
          this.next()
        } catch (err) {
          this.metadata.exception = err
          this.executeAdvice(this.exceptionEntry)
          return
        }
      }
    }

    if(currentEntry) {
      this.executeAdvice(currentEntry)
      return
    }
  }

    /**
     * stop - this method will alter proceed property of this stack which will
     * prevent main method to be invoked
     */
  stop () {
    this.proceed = false
  }

  private executeAdvice (currentEntry: IStackEntry) {
    currentEntry.advice.apply({ next: this.next.bind(this), stop: this.stop.bind(this) }, this.transformArguments(currentEntry))
    if(!this.isAsync(currentEntry.advice)) {
        this.next()
    }
  }

    /**
     * @private invokeOriginal
     *
     * this method is responsible of invoke the main method with the correct scope
     */
  private invokeOriginal (): void {
    this.metadata.result = this.metadata.rawMethod.apply(this.metadata.scope, this.metadata.args)
  }

    /**
     * @private transformArguments
     *
     * this method organize advice params at requested way<commit_msg>style: pass style check<commit_after>import { IStackEntry } from "../interface/IStackEntry"
import { IMetadata } from "../interface/IMetadata"

/**
 * {class} CallStackIterator
 * this class contains all accessible references within the advice call stack and
 * controls when advices must be invoked, also whether or not main method should
 * be called
 */
export class CallStackIterator {
  private index: number = -1
  private proceed: boolean = true

    /**
     * {constructor}
     * receives all the metadata and builds up a shorted array with the current
     * call stack
     * @param {IMetadata} metadata  current metadata for this stack
     */
  constructor (private metadata: IMetadata, private stack: IStackEntry[], private exceptionEntry?: IStackEntry) {
    this.next()
  }

    /**
     * next - this method will resolve by calling the next advice in the call stack
     * or calling the main method
     */
  next () {
    this.index++

    let currentEntry = this.stack[this.index]

    if (currentEntry === undefined) {
      return
    }

    if (this.proceed && currentEntry === null) {
      if (!this.exceptionEntry) {
        this.invokeOriginal()
        this.next()
        return
      } else {
        try {
          this.invokeOriginal()
          this.next()
        } catch (err) {
          this.metadata.exception = err
          this.executeAdvice(this.exceptionEntry)
          return
        }
      }
    }

    if (currentEntry) {
      this.executeAdvice(currentEntry)
      return
    }
  }

    /**
     * stop - this method will alter proceed property of this stack which will
     * prevent main method to be invoked
     */
  stop () {
    this.proceed = false
  }

  private executeAdvice (currentEntry: IStackEntry) {
    currentEntry.advice.apply({ next: this.next.bind(this), stop: this.stop.bind(this) }, this.transformArguments(currentEntry))
    if (!this.isAsync(currentEntry.advice)) {
      this.next()
    }
  }

    /**
     * @private invokeOriginal
     *
     * this method is responsible of invoke the main method with the correct scope
     */
  private invokeOriginal (): void {
    this.metadata.result = this.metadata.rawMethod.apply(this.metadata.scope, this.metadata.args)
  }

    /**
     * @private transformArguments
     *
     * this method organize advice params at requested way
{'fraction_non_alphanumeric': 0.0977427597955707, 'fraction_numerical': 0.00042589437819420784, 'mean_word_length': 2.468980797636632, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2463856', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1262, 'n_words': 395}