<commit_before>var propagate = function(obj, e) {
        var key, val;

        for(key of Object.keys(obj)) {
            val = obj[key];

            if(typeof(val) === "object") {
                if(val instanceof ObjectEventTarget || Object.getPrototypeOf(val) instanceof ObjectEventTarget) {
                    obj[pDispatchEvent](e);

                    if(e.propagationStopped) {
                        break;
                    }
                }

                propagate(val, e);

                if(e.propagationStopped) {
                    break;
                }
            }
        }
    },
    pDispatchEvent = Symbol("dispatch event"),
    pListeners = Symbol("listeners"),
    pTarget, pEventPhase, pCurrentTarget;

import {Event as ObjectEvent} from "./event";

class ObjectEventTarget {
    constructor() {
        this[pListeners] = {};
    }

    addEventListener(type, listener, capturing = false) {
        var listeners = this[pListeners][type];

        if(!listeners) {
            this[pListeners][type] = [listener];
        } else if(listeners.indexOf(listener) !== -1) {
            listeners.push(listener);
        }
    }

    removeEventListener(type, listener) {
        var listeners = this[pListeners][type],
            index;

        if(listeners) {
            index = listeners.indexOf(listener);
            if(index !== -1) {
                listeners.splice(index, 1);
            }

            if(!listeners.length) {
                delete this[pListeners][type];
            }
        }
    }

    dispatchEvent(e) {
        if(!(e instanceof ObjectEvent || Object.getPrototypeOf(e) instanceof ObjectEvent)) {
            throw new TypeError("Argument 1 of ObjectEventTarget.dispatchEvent has to be an instance of ObjectEvent");
        }

        e[pTarget] = this;
        e[pEventPhase] = ObjectEvent.PHASE_AT_TARGET;
        this[pDispatchEvent](e);

        e[pEventPhase] = ObjectEvent.PHASE_SINKING;
        if(e.propagates && !e.propagationStopped) {
            propagate(this, e);
        }

        return !e.defaultPrevented;
    }

    createPromise(type, capturing = false) {
        return new Promise((resolve) => {
            this.addEventListener(type, function(e) {
                resolve(e);
            });
        });
    }
}

ObjectEventTarget.prototype[pDispatchEvent] = function(e) {
    var listeners = this[pListeners][e.type],
        listener;

    e[pCurrentTarget] = this;
    if(listeners) {
        listeners = listeners.slice();
        for(listener of listeners.values()) {
            if(typeof(listener) === "function") {
                listener.call(this, e);
            } else if(typeof(listener) === "object" && listener.isPromise) {
                listener.resolve(e);
            }
        }
    }
};

export const initTarget = function(_pTarget, _pEventPhase, _pCurrentTarget) {
    pTarget = _pTarget;
    pEventPhase = _pEventPhase;
    pCurrentTarget = _pCurrentTarget;
};

export const Target = ObjectEventTarget;<commit_msg>Rename capturing to rising<commit_after>var propagate = function(obj, e) {
        var key, val;

        for(key of Object.keys(obj)) {
            val = obj[key];

            if(typeof(val) === "object") {
                if(val instanceof ObjectEventTarget || Object.getPrototypeOf(val) instanceof ObjectEventTarget) {
                    obj[pDispatchEvent](e);

                    if(e.propagationStopped) {
                        break;
                    }
                }

                propagate(val, e);

                if(e.propagationStopped) {
                    break;
                }
            }
        }
    },
    pDispatchEvent = Symbol("dispatch event"),
    pListeners = Symbol("listeners"),
    pTarget, pEventPhase, pCurrentTarget;

import {Event as ObjectEvent} from "./event";

class ObjectEventTarget {
    constructor() {
        this[pListeners] = {};
    }

    addEventListener(type, listener, rising = false) {
        var listeners = this[pListeners][type];

        if(!listeners) {
            this[pListeners][type] = [listener];
        } else if(listeners.indexOf(listener) !== -1) {
            listeners.push(listener);
        }
    }

    removeEventListener(type, listener) {
        var listeners = this[pListeners][type],
            index;

        if(listeners) {
            index = listeners.indexOf(listener);
            if(index !== -1) {
                listeners.splice(index, 1);
            }

            if(!listeners.length) {
                delete this[pListeners][type];
            }
        }
    }

    dispatchEvent(e) {
        if(!(e instanceof ObjectEvent || Object.getPrototypeOf(e) instanceof ObjectEvent)) {
            throw new TypeError("Argument 1 of ObjectEventTarget.dispatchEvent has to be an instance of ObjectEvent");
        }

        e[pTarget] = this;
        e[pEventPhase] = ObjectEvent.PHASE_AT_TARGET;
        this[pDispatchEvent](e);

        e[pEventPhase] = ObjectEvent.PHASE_SINKING;
        if(e.propagates && !e.propagationStopped) {
            propagate(this, e);
        }

        return !e.defaultPrevented;
    }

    createPromise(type, rising = false) {
        return new Promise((resolve) => {
            this.addEventListener(type, function(e) {
                resolve(e);
            });
        });
    }
}

ObjectEventTarget.prototype[pDispatchEvent] = function(e) {
    var listeners = this[pListeners][e.type],
        listener;

    e[pCurrentTarget] = this;
    if(listeners) {
        listeners = listeners.slice();
        for(listener of listeners) {
            if(typeof(listener) === "function") {
                listener.call(this, e);
            } else if(typeof(listener) === "object" && listener.isPromise) {
                listener.resolve(e);
            }
        }
    }
};

export const initTarget = function(_pTarget, _pEventPhase, _pCurrentTarget) {
    pTarget = _pTarget;
    pEventPhase = _pEventPhase;
    pCurrentTarget = _pCurrentTarget;
};

export const Target = ObjectEventTarget;
{'fraction_non_alphanumeric': 0.11639776094830424, 'fraction_numerical': 0.0013170892327955218, 'mean_word_length': 1.8507742843735335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2585992', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1653, 'n_words': 314}