<commit_before>/*jslint browser: true, for: true, node: true */
/*global window */

/*!

   hlsjs engine plugin for Flowplayer HTML5

   Copyright (c) 2015-2016, Flowplayer Oy

   Released under the MIT License:
   http://www.opensource.org/licenses/mit-license.php

   Includes hls.js
   Copyright (c) 2015 Dailymotion (http://www.dailymotion.com)
   https://github.com/dailymotion/hls.js/blob/master/LICENSE

   requires:
   - Flowplayer HTML5 version 6.x or greater
   - hls.js https://github.com/dailymotion/hls.js
   revision: $GIT_ID$

*/

(function (flowplayer, Hls) {
    "use strict";
    var engineName = "hlsjs",
        hlsconf,
        common = flowplayer.common,
        extend = flowplayer.extend,
        support = flowplayer.support,
        version = flowplayer.version,

        isHlsType = function (typ) {
            return typ.toLowerCase().indexOf("mpegurl") > -1;
        },

        engineImpl = function hlsjsEngine(player, root) {
            var bean = flowplayer.bean,
                videoTag,
                hls,
                recover,

                bc,
                has_bg,
                posterHack = function () {
                    // abuse timeupdate to re-instate poster
                    var posterClass = "is-poster",
                        etype = "progress." + engineName;

                    player.one(etype, function () {
                        common.addClass(root, posterClass);
                        player.poster = true;
                        player.one(etype, function () {
                            common.removeClass(root, posterClass);
                            player.poster = false;
                        });
                    });
                },

                getStartLevelConf = function () {
                    var value = hlsconf.startLevel;

                    switch (value) {
                    case "auto":
                        value = -1;
                        break;
                    case "firstLevel":
                        value = undefined;
                        break;
                    }
                    return value;
                },

                qActive = "active",
                removeAllQualityClasses = function () {
                    var qualities = player.qualities;

                    if (!qualities || !qualities.length) {
                        return;
                    }
                    common.removeClass(root, "quality-abr");
                    qualities.forEach(function (quality) {
                        common.removeClass(root, "quality-" + quality);
                    });
                },
                qClean = function () {
                    delete player.hlsQualities;
                    player.qualities = [];
                    removeAllQualityClasses();
                    common.find(".fp-quality-selector li", root).forEach(bean.off);
                    common.find(".fp-quality-selector", root).forEach(common.removeNode);
                },
                qIndex = function () {
                    return player.hlsQualities[player.qualities.indexOf(player.quality) + 1];
                },
                initQualitySelection = function (hlsQualitiesConf, data) {
                    var levels = data.levels,
                        levelIndex = 0,
                        selector;

                    player.hlsQualities = [];
                    levels.forEach(function (level) {
                        if ((hlsQualitiesConf === true || hlsQualitiesConf.indexOf(levelIndex) > -1) &&
                                level.videoCodec &&
                                window.MediaSource.isTypeSupported('video/mp4;codecs=' + level.videoCodec)) {
                            // do not check audioCodec,
                            // as e.g. HE_AAC is decoded as LC_AAC by hls.js on Android
                            player.hlsQualities.push(levelIndex);
                        }
                        levelIndex += 1;
                    });
                    if (player.hlsQualities.length < 2) {
                        qClean();
                        return;
                    }

                    player.qualities = [];
                    player.hlsQualities.forEach(function (levelIndex) {
                        var level = levels[levelIndex],
                            width = level.width,
                            height = level.height,
                            label = (width && height)
                                ? Math.min(width, height) + "p"
                                : "Level " + (levelIndex + 1);

                        player.qualities.push(label);
                    });

                    selector = common.createElement("ul", {
                        "class": "fp-quality-selector"
                    });
                    common.find(".fp-ui", root)[0].appendChild(selector);

                    player.hlsQualities.unshift(-1);

                    if (!player.quality || player.qualities.indexOf(player.quality) < 0) {
                        hls.startLevel = getStartLevelConf();
                        player.quality = "abr";
                    } else {
                        hls.startLevel = qIndex();
                    }

                    selector.appendChild(common.createElement("li", {
                        "data-quality": "abr"
                    }, "Auto"));
                    player.qualities.forEach(function (q) {
                        selector.appendChild(common.createElement("li", {
                            "data-quality": q
                        }, q));
                    });

                    common.addClass(root, "quality-" + player.quality);

                    bean.on(root, "click", ".fp-quality-selector li", function (e) {
                        var choice = e.currentTarget,
                            selectors,
                            active,
                            i;

                        if (common.hasClass(choice, qActive)) {
                            return;
                        }

                        selectors = common.find(".fp-quality-selector li", root);

                        for (i = 0; i < selectors.length; i += 1) {
                            active = selectors[i] === choice;
                            if (active) {
                                player.quality = i > 0
                                    ? player.qualities[i - 1]
                                    : "abr";
                                if (hlsconf.smoothSwitching) {
                                    hls.nextLevel = qIndex();
                                } else {
                                    hls.currentLevel = qIndex();
                                }
                                player.resume();
                                common.addClass(choice, qActive);
                            }
                            common.toggleClass(selectors[i], qActive, active);
                        }
                        removeAllQualityClasses();
                        common.addClass(root, "quality-" + player.quality);
                    });
                },

                engine = {
                    engineName: engineName,

                    pick: function (sources) {
                        var i,
                            source;

                        for (i = 0; i < sources.length; i += 1) {
                            source = sources[i];
                            if (isHlsType(source.type)
                                    && (!source.engine || source.engine === engineName)) {
                                if (typeof source.src === 'string') {
                                    source.src = common.createAbsoluteUrl(source.src);
                                }
                                return source;
                            }
                        }
                    },

                    load: function (video) {
                        var init = !hls,
                            conf = player.conf,
                            hlsQualitiesConf = conf.clip.hlsQualities || conf.hlsQualities,
                            hlsClientConf = extend({}, hlsconf),
                            hlsParams = [
                                "anamorphic", "autoLevelCapping", "recover",
                                "smoothSwitching", "startLevel", "strict"
                            ],
                            hlsEvents = [
                                "MEDIA_ATTACHING", "MEDIA_ATTACHED", "MEDIA_DETACHING", "MEDIA_DETACHED",
                                "MANIFEST_LOADING", "MANIFEST_LOADED", "MANIFEST_PARSED",
                                "LEVEL_LOADING", "LEVEL_LOADED", "LEVEL_UPDATED", "LEVEL_PTS_UPDATED", "LEVEL_SWITCH",
                                "KEY_LOADING", "KEY_LOADED",
                                "FRAG_LOADING", "FRAG_LOAD_PROGRESS", "FRAG_LOADED",
                                "FRAG_PARSING_INIT_SEGMENT", "FRAG_PARSING_METADATA", "FRAG_PARSING_DATA", "FRAG_PARSED",
                                "FRAG_BUFFERED", "FRAG_CHANGED",
                                "FPS_DROP",
                                "DESTROYING",
                                "ERROR"
                            ];

                        if (init) {
                            common.removeNode(common.findDirect("video", root)[0]
                                    || common.find(".fp-player > video", root)[0]);
                            videoTag = common.createElement("video", {
                                className: "fp-engine " + engineName + "-engine",
                                autoplay: conf.autoplay
                                    ? "autoplay"
                                    : false
                            });
                            videoTag.setAttribute("x-webkit-airplay", "allow");

                        } else {
                            hls.destroy();
                        }

                        bean.on(videoTag, "play", function () {
                            player.trigger('resume', [player]);
                        });
                        bean.on(videoTag, "pause", function () {
                            player.trigger('pause', [player]);
                        });
                        bean.on(videoTag, "timeupdate", function () {
                            player.trigger('progress', [player, videoTag.currentTime]);
                        });
                        bean.on(videoTag, "loadeddata", function () {
                            video = extend(video, {
                                duration: videoTag.duration,
                                seekable: videoTag.seekable.end(null),
                                width: videoTag.videoWidth,
                                height: videoTag.videoHeight,
                                url: videoTag.currentSrc
                            });
                            player.trigger('ready', [player, video]);

                            var quality = player.quality,
                                abr = quality === "abr",
                                selectorIndex;

                            if (quality) {
                                if (!abr) {
                                    hls.currentLevel = hls.startLevel;
                                }
                                selectorIndex = abr
                                    ? 0
                                    : player.qualities.indexOf(quality) + 1;
                                common.addClass(common.find(".fp-quality-selector li", root)[selectorIndex], qActive);
                            }
                        });
                        bean.on(videoTag, "seeked", function () {
                            player.trigger('seek', [player, videoTag.currentTime]);
                        });
                        bean.on(videoTag, "progress", function (e) {
                            var ct = videoTag.currentTime,
                                buffer = 0,
                                buffend,
                                buffered,
                                last,
                                i;

                            try {
                                buffered = videoTag.buffered;
                                last = buffered.length - 1;
                                buffend = 0;
                                // cycle through time ranges to obtain buffer
                                // nearest current time
                                if (ct) {
                                    for (i = last; i > -1; i -= 1) {
                                        buffend = buffered.end(i);

                                        if (buffend >= ct) {
                                            buffer = buffend;
                                        }
                                    }
                                }
                            } catch (ignore) {}

                            video.buffer = buffer;
                            player.trigger('buffer', [player, e]);
                        });
                        bean.on(videoTag, "ended", function () {
                            player.trigger('finish', [player]);
                        });
                        bean.on(videoTag, "volumechange", function () {
                            player.trigger('volume', [player, videoTag.volume]);
                        });

                        hlsParams.forEach(function (key) {
                            delete hlsClientConf[key];
                        });
                        hls = new Hls(hlsClientConf);
                        player.engine[engineName] = hls;

                        hlsParams.forEach(function (key) {
                            var value = hlsconf[key];

                            switch (key) {
                            case "autoLevelCapping":
                                if (value === false) {
                                    value = -1;
                                }
                                break;
                            case "recover":
                                recover = hlsconf.strict
                                    ? 0
                                    : value;
                                break;
                            case "startLevel":
                                value = (player.hlsQualities && player.quality)
                                    ? qIndex()
                                    : getStartLevelConf();
                                break;
                            }

                            if (key !== "strict" && key !== "recover" && value !== undefined) {
                                hls[key] = value;
                            }
                        });

                        qClean();

                        hlsEvents.forEach(function (e) {
                            hls.on(Hls.Events[e], function (etype, data) {
                                var fperr,
                                    errobj = {};

                                switch (e) {
                                case "MANIFEST_PARSED":
                                    if (support.inlineVideo && hlsQualitiesConf) {
                                        initQualitySelection(hlsQualitiesConf, data);
                                    } else {
                                        delete player.quality;
                                    }
                                    break;

                                case "ERROR":
                                    if (data.fatal || hlsconf.strict > 0) {
                                        switch (data.type) {
                                        case Hls.ErrorTypes.NETWORK_ERROR:
                                            if (recover) {
                                                hls.startLoad();
                                                if (recover > 0) {
                                                    recover -= 1;
                                                }
                                            } else if (data.frag && data.frag.url) {
                                                errobj.url = data.frag.url;
                                                fperr = 2;
                                            } else {
                                                fperr = 4;
                                            }
                                            break;
                                        case Hls.ErrorTypes.MEDIA_ERROR:
                                            if (recover) {
                                                hls.recoverMediaError();
                                                if (recover > 0) {
                                                    recover -= 1;
                                                }
                                            } else {
                                                fperr = 3;
                                            }
                                            break;
                                        default:
                                            fperr = 5;
                                        }

                                        if (fperr !== undefined) {
                                            errobj.code = fperr;
                                            if (fperr > 2) {
                                                errobj.video = extend(video, {
                                                    src: video.src,
                                                    url: data.url || video.src
                                                });
                                            }
                                            player.trigger('error', [player, errobj]);
                                            return;
                                        }
                                    }
                                    // log non fatals?
                                    break;
                                }

                                player.trigger(etype, [player, data]);
                            });
                        });

                        if (init) {
                            common.prepend(common.find(".fp-player", root)[0], videoTag);
                        }

                        hls.loadSource(video.src);
                        hls.attachMedia(videoTag);

                        if (videoTag.paused && (video.autoplay || conf.autoplay)) {
                            videoTag.play();
                        }
                    },

                    resume: function () {
                        videoTag.play();
                    },

                    pause: function () {
                        videoTag.pause();
                    },

                    seek: function (time) {
                        videoTag.currentTime = time;
                    },

                    volume: function (level) {
                        if (videoTag) {
                            videoTag.volume = level;
                        }
                    },

                    speed: function (val) {
                        videoTag.playbackRate = val;
                        player.trigger('speed', [player, val]);
                    },

                    unload: function () {
                        // hls conditional probably not needed once
                        // https://github.com/flowplayer/flowplayer/commit/871ff783a8f23aa603e1120f4319d4a892125b0a
                        // is released
                        if (hls) {
                            hls.destroy();
                            hls = 0;
                            bean.off(videoTag);
                            common.removeNode(videoTag);
                            videoTag = 0;
                            qClean();
                        }
                    }
                };

            // pre 6.0.4: no boolean api.conf.poster and no poster with autoplay
            if (/^6\.0\.[0-3]$/.test(version) &&
                    !player.conf.splash && !player.conf.poster && !player.conf.autoplay) {
                bc = common.css(root, 'backgroundColor');
                // spaces in rgba arg mandatory for recognition
                has_bg = common.css(root, 'backgroundImage') !== "none" ||
                        (bc && bc !== "rgba(0, 0, 0, 0)" && bc !== "transparent");
                if (has_bg) {
                    player.conf.poster = true;
                }
            }
            if (player.conf.poster) {
                // when engine is loaded or player stopped
                // the engine is too late to the party:
                // poster is already removed and api.poster is false
                // poster state must be set again
                player.on("ready." + engineName + " stop." + engineName, posterHack);
            }

            return engine;
        };

    if (Hls.isSupported() && version.indexOf("5.") !== 0) {
        // only load engine if it can be used
        engineImpl.engineName = engineName; // must be exposed
        engineImpl.canPlay = function (type, conf) {
            var b = support.browser,
                wn = window.navigator,
                IE11 = wn.userAgent.indexOf("Trident/7") > -1;

            if (conf[engineName] === false || conf.clip[engineName] === false) {
                // engine disabled for player or clip
                return false;
            }

            // merge hlsjs clip config at earliest opportunity
            hlsconf = extend({
                smoothSwitching: true,
                recover: 0
            }, flowplayer.conf[engineName], conf[engineName], conf.clip[engineName]);

            if (isHlsType(type)) {
                // allow all browsers for hlsjs debugging
                if (hlsconf.debug) {
                    return true;
                }
                // https://bugzilla.mozilla.org/show_bug.cgi?id=1244294
                if (hlsconf.anamorphic &&
                        wn.platform.indexOf("Win") === 0 && b.mozilla && b.version.indexOf("44.") === 0) {
                    return false;
                }

                // https://github.com/dailymotion/hls.js/issues/9
                return IE11 || !b.safari;
            }
            return false;
        };

        // put on top of engine stack
        // so hlsjs is tested before html5 video hls and flash hls
        flowplayer.engines.unshift(engineImpl);

        flowplayer(function (api) {
            // to take precedence over VOD quality selector
            // hlsQualities must be configure at player or global level
            var hlsQualities = api.conf.hlsQualities || flowplayer.conf.hlsQualities;
            if (hlsQualities) {
                api.pluginQualitySelectorEnabled = engineImpl.canPlay("application/x-mpegurl", api.conf);
            }
        });

    }

}.apply(null, (typeof module === 'object' && module.exports)
    ? [require('flowplayer'), require('hls.js')]
    : [window.flowplayer, window.Hls]));
<commit_msg>Format quality labels for data or class attributes<commit_after>/*jslint browser: true, for: true, node: true */
/*global window */

/*!

   hlsjs engine plugin for Flowplayer HTML5

   Copyright (c) 2015-2016, Flowplayer Oy

   Released under the MIT License:
   http://www.opensource.org/licenses/mit-license.php

   Includes hls.js
   Copyright (c) 2015 Dailymotion (http://www.dailymotion.com)
   https://github.com/dailymotion/hls.js/blob/master/LICENSE

   requires:
   - Flowplayer HTML5 version 6.x or greater
   - hls.js https://github.com/dailymotion/hls.js
   revision: $GIT_ID$

*/

(function (flowplayer, Hls) {
    "use strict";
    var engineName = "hlsjs",
        hlsconf,
        common = flowplayer.common,
        extend = flowplayer.extend,
        support = flowplayer.support,
        version = flowplayer.version,

        isHlsType = function (typ) {
            return typ.toLowerCase().indexOf("mpegurl") > -1;
        },

        engineImpl = function hlsjsEngine(player, root) {
            var bean = flowplayer.bean,
                videoTag,
                hls,
                recover,

                bc,
                has_bg,
                posterHack = function () {
                    // abuse timeupdate to re-instate poster
                    var posterClass = "is-poster",
                        etype = "progress." + engineName;

                    player.one(etype, function () {
                        common.addClass(root, posterClass);
                        player.poster = true;
                        player.one(etype, function () {
                            common.removeClass(root, posterClass);
                            player.poster = false;
                        });
                    });
                },

                getStartLevelConf = function () {
                    var value = hlsconf.startLevel;

                    switch (value) {
                    case "auto":
                        value = -1;
                        break;
                    case "firstLevel":
                        value = undefined;
                        break;
                    }
                    return value;
                },

                qActive = "active",
                dataQuality = function (quality) {
                    // e.g. "Level 1" -> "level1"
                    if (!quality) {
                        quality = player.quality;
                    }
                    return quality.toLowerCase().replace(/\ /g, "");
                },
                removeAllQualityClasses = function () {
                    var qualities = player.qualities;

                    if (!qualities || !qualities.length) {
                        return;
                    }
                    common.removeClass(root, "quality-abr");
                    qualities.forEach(function (quality) {
                        common.removeClass(root, "quality-" + dataQuality(quality));
                    });
                },
                qClean = function () {
                    delete player.hlsQualities;
                    player.qualities = [];
                    removeAllQualityClasses();
                    common.find(".fp-quality-selector li", root).forEach(bean.off);
                    common.find(".fp-quality-selector", root).forEach(common.removeNode);
                },
                qIndex = function () {
                    return player.hlsQualities[player.qualities.indexOf(player.quality) + 1];
                },
                initQualitySelection = function (hlsQualitiesConf, data) {
                    var levels = data.levels,
                        levelIndex = 0,
                        selector;

                    player.hlsQualities = [];
                    levels.forEach(function (level) {
                        if ((hlsQualitiesConf === true || hlsQualitiesConf.indexOf(levelIndex) > -1) &&
                                level.videoCodec &&
                                window.MediaSource.isTypeSupported('video/mp4;codecs=' + level.videoCodec)) {
                            // do not check audioCodec,
                            // as e.g. HE_AAC is decoded as LC_AAC by hls.js on Android
                            player.hlsQualities.push(levelIndex);
                        }
                        levelIndex += 1;
                    });
                    if (player.hlsQualities.length < 2) {
                        qClean();
                        return;
                    }

                    player.qualities = [];
                    player.hlsQualities.forEach(function (levelIndex) {
                        var level = levels[levelIndex],
                            width = level.width,
                            height = level.height,
                            label = (width && height)
                                ? Math.min(width, height) + "p"
                                : "Level " + (levelIndex + 1);

                        player.qualities.push(label);
                    });

                    selector = common.createElement("ul", {
                        "class": "fp-quality-selector"
                    });
                    common.find(".fp-ui", root)[0].appendChild(selector);

                    player.hlsQualities.unshift(-1);

                    if (!player.quality || player.qualities.indexOf(player.quality) < 0) {
                        hls.startLevel = getStartLevelConf();
                        player.quality = "abr";
                    } else {
                        hls.startLevel = qIndex();
                    }

                    selector.appendChild(common.createElement("li", {
                        "data-quality": "abr"
                    }, "Auto"));
                    player.qualities.forEach(function (q) {
                        selector.appendChild(common.createElement("li", {
                            "data-quality": dataQuality(q)
                        }, q));
                    });

                    common.addClass(root, "quality-" + dataQuality());

                    bean.on(root, "click", ".fp-quality-selector li", function (e) {
                        var choice = e.currentTarget,
                            selectors,
                            active,
                            i;

                        if (common.hasClass(choice, qActive)) {
                            return;
                        }

                        selectors = common.find(".fp-quality-selector li", root);

                        for (i = 0; i < selectors.length; i += 1) {
                            active = selectors[i] === choice;
                            if (active) {
                                player.quality = i > 0
                                    ? player.qualities[i - 1]
                                    : "abr";
                                if (hlsconf.smoothSwitching) {
                                    hls.nextLevel = qIndex();
                                } else {
                                    hls.currentLevel = qIndex();
                                }
                                player.resume();
                                common.addClass(choice, qActive);
                            }
                            common.toggleClass(selectors[i], qActive, active);
                        }
                        removeAllQualityClasses();
                        common.addClass(root, "quality-" + dataQuality());
                    });
                },

                engine = {
                    engineName: engineName,

                    pick: function (sources) {
                        var i,
                            source;

                        for (i = 0; i < sources.length; i += 1) {
                            source = sources[i];
                            if (isHlsType(source.type)
                                    && (!source.engine || source.engine === engineName)) {
                                if (typeof source.src === 'string') {
                                    source.src = common.createAbsoluteUrl(source.src);
                                }
                                return source;
                            }
                        }
                    },

                    load: function (video) {
                        var init = !hls,
                            conf = player.conf,
                            hlsQualitiesConf = conf.clip.hlsQualities || conf.hlsQualities,
                            hlsClientConf = extend({}, hlsconf),
                            hlsParams = [
                                "anamorphic", "autoLevelCapping", "recover",
                                "smoothSwitching", "startLevel", "strict"
                            ],
                            hlsEvents = [
                                "MEDIA_ATTACHING", "MEDIA_ATTACHED", "MEDIA_DETACHING", "MEDIA_DETACHED",
                                "MANIFEST_LOADING", "MANIFEST_LOADED", "MANIFEST_PARSED",
                                "LEVEL_LOADING", "LEVEL_LOADED", "LEVEL_UPDATED", "LEVEL_PTS_UPDATED", "LEVEL_SWITCH",
                                "KEY_LOADING", "KEY_LOADED",
                                "FRAG_LOADING", "FRAG_LOAD_PROGRESS", "FRAG_LOADED",
                                "FRAG_PARSING_INIT_SEGMENT", "FRAG_PARSING_METADATA", "FRAG_PARSING_DATA", "FRAG_PARSED",
                                "FRAG_BUFFERED", "FRAG_CHANGED",
                                "FPS_DROP",
                                "DESTROYING",
                                "ERROR"
                            ];

                        if (init) {
                            common.removeNode(common.findDirect("video", root)[0]
                                    || common.find(".fp-player > video", root)[0]);
                            videoTag = common.createElement("video", {
                                className: "fp-engine " + engineName + "-engine",
                                autoplay: conf.autoplay
                                    ? "autoplay"
                                    : false
                            });
                            videoTag.setAttribute("x-webkit-airplay", "allow");

                        } else {
                            hls.destroy();
                        }

                        bean.on(videoTag, "play", function () {
                            player.trigger('resume', [player]);
                        });
                        bean.on(videoTag, "pause", function () {
                            player.trigger('pause', [player]);
                        });
                        bean.on(videoTag, "timeupdate", function () {
                            player.trigger('progress', [player, videoTag.currentTime]);
                        });
                        bean.on(videoTag, "loadeddata", function () {
                            video = extend(video, {
                                duration: videoTag.duration,
                                seekable: videoTag.seekable.end(null),
                                width: videoTag.videoWidth,
                                height: videoTag.videoHeight,
                                url: videoTag.currentSrc
                            });
                            player.trigger('ready', [player, video]);

                            var quality = player.quality,
                                abr = quality === "abr",
                                selectorIndex;

                            if (quality) {
                                if (!abr) {
                                    hls.currentLevel = hls.startLevel;
                                }
                                selectorIndex = abr
                                    ? 0
                                    : player.qualities.indexOf(quality) + 1;
                                common.addClass(common.find(".fp-quality-selector li", root)[selectorIndex], qActive);
                            }
                        });
                        bean.on(videoTag, "seeked", function () {
                            player.trigger('seek', [player, videoTag.currentTime]);
                        });
                        bean.on(videoTag, "progress", function (e) {
                            var ct = videoTag.currentTime,
                                buffer = 0,
                                buffend,
                                buffered,
                                last,
                                i;

                            try {
                                buffered = videoTag.buffered;
                                last = buffered.length - 1;
                                buffend = 0;
                                // cycle through time ranges to obtain buffer
                                // nearest current time
                                if (ct) {
                                    for (i = last; i > -1; i -= 1) {
                                        buffend = buffered.end(i);

                                        if (buffend >= ct) {
                                            buffer = buffend;
                                        }
                                    }
                                }
                            } catch (ignore) {}

                            video.buffer = buffer;
                            player.trigger('buffer', [player, e]);
                        });
                        bean.on(videoTag, "ended", function () {
                            player.trigger('finish', [player]);
                        });
                        bean.on(videoTag, "volumechange", function () {
                            player.trigger('volume', [player, videoTag.volume]);
                        });

                        hlsParams.forEach(function (key) {
                            delete hlsClientConf[key];
                        });
                        hls = new Hls(hlsClientConf);
                        player.engine[engineName] = hls;

                        hlsParams.forEach(function (key) {
                            var value = hlsconf[key];

                            switch (key) {
                            case "autoLevelCapping":
                                if (value === false) {
                                    value = -1;
                                }
                                break;
                            case "recover":
                                recover = hlsconf.strict
                                    ? 0
                                    : value;
                                break;
                            case "startLevel":
                                value = (player.hlsQualities && player.quality)
                                    ? qIndex()
                                    : getStartLevelConf();
                                break;
                            }

                            if (key !== "strict" && key !== "recover" && value !== undefined) {
                                hls[key] = value;
                            }
                        });

                        qClean();

                        hlsEvents.forEach(function (e) {
                            hls.on(Hls.Events[e], function (etype, data) {
                                var fperr,
                                    errobj = {};

                                switch (e) {
                                case "MANIFEST_PARSED":
                                    if (support.inlineVideo && hlsQualitiesConf) {
                                        initQualitySelection(hlsQualitiesConf, data);
                                    } else {
                                        delete player.quality;
                                    }
                                    break;

                                case "ERROR":
                                    if (data.fatal || hlsconf.strict > 0) {
                                        switch (data.type) {
                                        case Hls.ErrorTypes.NETWORK_ERROR:
                                            if (recover) {
                                                hls.startLoad();
                                                if (recover > 0) {
                                                    recover -= 1;
                                                }
                                            } else if (data.frag && data.frag.url) {
                                                errobj.url = data.frag.url;
                                                fperr = 2;
                                            } else {
                                                fperr = 4;
                                            }
                                            break;
                                        case Hls.ErrorTypes.MEDIA_ERROR:
                                            if (recover) {
                                                hls.recoverMediaError();
                                                if (recover > 0) {
                                                    recover -= 1;
                                                }
                                            } else {
                                                fperr = 3;
                                            }
                                            break;
                                        default:
                                            fperr = 5;
                                        }

                                        if (fperr !== undefined) {
                                            errobj.code = fperr;
                                            if (fperr > 2) {
                                                errobj.video = extend(video, {
                                                    src: video.src,
                                                    url: data.url || video.src
                                                });
                                            }
                                            player.trigger('error', [player, errobj]);
                                            return;
                                        }
                                    }
                                    // log non fatals?
                                    break;
                                }

                                player.trigger(etype, [player, data]);
                            });
                        });

                        if (init) {
                            common.prepend(common.find(".fp-player", root)[0], videoTag);
                        }

                        hls.loadSource(video.src);
                        hls.attachMedia(videoTag);

                        if (videoTag.paused && (video.autoplay || conf.autoplay)) {
                            videoTag.play();
                        }
                    },

                    resume: function () {
                        videoTag.play();
                    },

                    pause: function () {
                        videoTag.pause();
                    },

                    seek: function (time) {
                        videoTag.currentTime = time;
                    },

                    volume: function (level) {
                        if (videoTag) {
                            videoTag.volume = level;
                        }
                    },

                    speed: function (val) {
                        videoTag.playbackRate = val;
                        player.trigger('speed', [player, val]);
                    },

                    unload: function () {
                        // hls conditional probably not needed once
                        // https://github.com/flowplayer/flowplayer/commit/871ff783a8f23aa603e1120f4319d4a892125b0a
                        // is released
                        if (hls) {
                            hls.destroy();
                            hls = 0;
                            bean.off(videoTag);
                            common.removeNode(videoTag);
                            videoTag = 0;
                            qClean();
                        }
                    }
                };

            // pre 6.0.4: no boolean api.conf.poster and no poster with autoplay
            if (/^6\.0\.[0-3]$/.test(version) &&
                    !player.conf.splash && !player.conf.poster && !player.conf.autoplay) {
                bc = common.css(root, 'backgroundColor');
                // spaces in rgba arg mandatory for recognition
                has_bg = common.css(root, 'backgroundImage') !== "none" ||
                        (bc && bc !== "rgba(0, 0, 0, 0)" && bc !== "transparent");
                if (has_bg) {
                    player.conf.poster = true;
                }
            }
            if (player.conf.poster) {
                // when engine is loaded or player stopped
                // the engine is too late to the party:
                // poster is already removed and api.poster is false
                // poster state must be set again
                player.on("ready." + engineName + " stop." + engineName, posterHack);
            }

            return engine;
        };

    if (Hls.isSupported() && version.indexOf("5.") !== 0) {
        // only load engine if it can be used
        engineImpl.engineName = engineName; // must be exposed
        engineImpl.canPlay = function (type, conf) {
            var b = support.browser,
                wn = window.navigator,
                IE11 = wn.userAgent.indexOf("Trident/7") > -1;

            if (conf[engineName] === false || conf.clip[engineName] === false) {
                // engine disabled for player or clip
                return false;
            }

            // merge hlsjs clip config at earliest opportunity
            hlsconf = extend({
                smoothSwitching: true,
                recover: 0
            }, flowplayer.conf[engineName], conf[engineName], conf.clip[engineName]);

            if (isHlsType(type)) {
                // allow all browsers for hlsjs debugging
                if (hlsconf.debug) {
                    return true;
                }
                // https://bugzilla.mozilla.org/show_bug.cgi?id=1244294
                if (hlsconf.anamorphic &&
                        wn.platform.indexOf("Win") === 0 && b.mozilla && b.version.indexOf("44.") === 0) {
                    return false;
                }

                // https://github.com/dailymotion/hls.js/issues/9
                return IE11 || !b.safari;
            }
            return false;
        };

        // put on top of engine stack
        // so hlsjs is tested before html5 video hls and flash hls
        flowplayer.engines.unshift(engineImpl);

        flowplayer(function (api) {
            // to take precedence over VOD quality selector
            // hlsQualities must be configure at player or global level
            var hlsQualities = api.conf.hlsQualities || flowplayer.conf.hlsQualities;
            if (hlsQualities) {
                api.pluginQualitySelectorEnabled = engineImpl.canPlay("application/x-mpegurl", api.conf);
            }
        });

    }

}.apply(null, (typeof module === 'object' && module.exports)
    ? [require('flowplayer'), require('hls.js')]
    : [window.flowplayer, window.Hls]));
<|endoftext|>


<commit_before>/*jslint browser: true, for: true, node: true */
/*global window */

/*!

   hlsjs engine plugin for Flowplayer HTML5

   Copyright (c) 2015, Flowplayer Oy

   Released under the MIT License:
   http://www.opensource.org/licenses/mit-license.php

   Includes hls.min.js
   Copyright (c) 2015 Dailymotion (http://www.dailymotion.com)
   https://github.com/dailymotion/hls.js/blob/master/LICENSE

   requires:
   - Flowplayer HTML5 version 6.x or greater
   - hls.js https://github.com/dailymotion/hls.js
   revision: $GIT_ID$

*/

(function (flowplayer, Hls) {
    "use strict";
    var engineName = "hlsjs",
        hlsconf,
        common = flowplayer.common,
        extend = flowplayer.extend,
        version = flowplayer.version,

        isHlsType = function (typ) {
            return typ.toLowerCase().indexOf("mpegurl") > -1;
        },

        engineImpl = function hlsjsEngine(player, root) {
            var bean = flowplayer.bean,
                videoTag,
                hls,

                bc,
                has_bg,
                posterHack = function () {
                    // abuse timeupdate to re-instate poster
                    var posterClass = "is-poster",
                        etype = "progress." + engineName;

                    player.one(etype, function () {
                        common.addClass(root, posterClass);
                        player.poster = true;
                        player.one(etype, function () {
                            common.removeClass(root, posterClass);
                            player.poster = false;
                        });
                    });
                },

                engine = {
                    engineName: engineName,

                    pick: function (sources) {
                        var i,
                            source;

                        for (i = 0; i < sources.length; i += 1) {
                            source = sources[i];
                            if (isHlsType(source.type)
                                    && (!source.engine || source.engine === engineName)) {
                                if (typeof source.src === 'string') {
                                    source.src = common.createAbsoluteUrl(source.src);
                                }
                                return source;
                            }
                        }
                    },

                    load: function (video) {
                        var init = !hls,
                            conf = player.conf,
                            hlsClientConf = extend({}, hlsconf),
                            hlsParams = ["autoLevelCapping", "startLevel", "strict"];

                        if (init) {
                            common.removeNode(common.findDirect("video", root)[0]
                                    || common.find(".fp-player > video", root)[0]);
                            videoTag = common.createElement("video", {
                                className: "fp-engine " + engineName + "-engine",
                                autoplay: conf.autoplay
                                    ? "autoplay"
                                    : false
                            });
                            videoTag.setAttribute("x-webkit-airplay", "allow");

                        } else {
                            hls.destroy();
                        }

                        bean.on(videoTag, "play", function () {
                            player.trigger('resume', [player]);
                        });
                        bean.on(videoTag, "pause", function () {
                            player.trigger('pause', [player]);
                        });
                        bean.on(videoTag, "timeupdate", function () {
                            // https://github.com/dailymotion/hls.js/issues/83
                            if (!conf.live && videoTag.currentTime >= video.duration - 0.38) {
                                bean.fire(videoTag, 'ended');
                            } else {
                                player.trigger('progress', [player, videoTag.currentTime]);
                            }
                        });
                        bean.on(videoTag, "loadeddata", function () {
                            video = extend(video, {
                                duration: videoTag.duration,
                                seekable: videoTag.seekable.end(null),
                                width: videoTag.videoWidth,
                                height: videoTag.videoHeight,
                                url: videoTag.currentSrc
                            });
                            player.trigger('ready', [player, video]);
                        });
                        bean.on(videoTag, "seeked", function () {
                            player.trigger('seek', [player, videoTag.currentTime]);
                        });
                        bean.on(videoTag, "progress", function (e) {
                            var ct = videoTag.currentTime,
                                buffer = 0,
                                buffend,
                                buffered,
                                last,
                                i;

                            try {
                                buffered = videoTag.buffered;
                                last = buffered.length - 1;
                                buffend = 0;
                                // cycle through time ranges to obtain buffer
                                // nearest current time
                                if (ct) {
                                    for (i = last; i > -1; i -= 1) {
                                        buffend = buffered.end(i);

                                        if (buffend >= ct) {
                                            buffer = buffend;
                                        }
                                    }
                                }
                            } catch (ignored) {}

                            video.buffer = buffer;
                            player.trigger('buffer', [player, e]);
                        });
                        bean.on(videoTag, "ended", function () {
                            player.trigger('finish', [player]);
                        });
                        bean.on(videoTag, "volumechange", function () {
                            player.trigger('volume', [player, videoTag.volume]);
                        });

                        hlsParams.forEach(function (key) {
                            delete hlsClientConf[key];
                        });
                        hls = new Hls(hlsClientConf);

                        hlsParams.forEach(function (key) {
                            var value = hlsconf[key];

                            switch (key) {
                            case "autoLevelCapping":
                                if (value === false) {
                                    value = -1;
                                }
                                break;
                            case "startLevel":
                                switch (value) {
                                case "auto":
                                    value = -1;
                                    break;
                                case "firstLevel":
                                    value = undefined;
                                    break;
                                }
                                break;
                            }

                            if (value !== undefined) {
                                hls[key] = value;
                            }
                        });

                        hls.on(Hls.Events.ERROR, function (e, data) {
                            var fperr,
                                errobj = {};

                            if (data.fatal || hlsconf.strict) {
                                switch (data.type) {
                                case Hls.ErrorTypes.NETWORK_ERROR:
                                    if (data.frag && data.frag.url) {
                                        errobj.url = data.frag.url;
                                        fperr = 2;
                                    } else {
                                        fperr = 4;
                                    }
                                    break;
                                case Hls.ErrorTypes.MEDIA_ERROR:
                                    fperr = 3;
                                    break;
                                default:
                                    fperr = 5;
                                    break;
                                }
                                errobj.code = fperr;
                                if (fperr > 2) {
                                    errobj.video = extend(video, {
                                        src: video.src,
                                        url: data.url || video.src
                                    });
                                }
                                player.trigger('error', [player, errobj]);
                            }
                            /* TODO: */
                            // log non fatals
                        });

                        if (init) {
                            common.prepend(common.find(".fp-player", root)[0], videoTag);
                        }

                        hls.loadSource(video.src);
                        hls.attachVideo(videoTag);

                        if (videoTag.paused && (video.autoplay || conf.autoplay)) {
                            videoTag.play();
                        }
                    },

                    resume: function () {
                        videoTag.play();
                    },

                    pause: function () {
                        videoTag.pause();
                    },

                    seek: function (time) {
                        videoTag.currentTime = time;
                    },

                    volume: function (level) {
                        if (videoTag) {
                            videoTag.volume = level;
                        }
                    },

                    speed: function (val) {
                        videoTag.playbackRate = val;
                        player.trigger('speed', [player, val]);
                    },

                    unload: function () {
                        // hls conditional probably not needed once
                        // https://github.com/flowplayer/flowplayer/commit/871ff783a8f23aa603e1120f4319d4a892125b0a
                        // is released
                        if (hls) {
                            hls.destroy();
                            hls = 0;
                            bean.off(videoTag);
                            common.removeNode(videoTag);
                            videoTag = 0;
                        }
                    }
                };

            // pre 6.0.4: no boolean api.conf.poster and no poster with autoplay
            if (/^6\.0\.[0-3]$/.test(version) &&
                    !player.conf.splash && !player.conf.poster && !player.conf.autoplay) {
                bc = common.css(root, 'backgroundColor');
                // spaces in rgba arg mandatory for recognition
                has_bg = common.css(root, 'backgroundImage') !== "none" ||
                        (bc && bc !== "rgba(0, 0, 0, 0)" && bc !== "transparent");
                if (has_bg) {
                    player.conf.poster = true;
                }
            }
            if (player.conf.poster) {
                // when engine is loaded or player stopped
                // the engine is too late to the party:
                // poster is already removed and api.poster is false
                // poster state must be set again
                player.on("ready." + engineName + " stop." + engineName, posterHack);
            }

            return engine;
        };

    if (Hls.isSupported() && version.indexOf("5.") !== 0) {
        // only load engine if it can be used
        engineImpl.engineName = engineName; // must be exposed
        engineImpl.canPlay = function (type, conf) {
            var IE11 = navigator.userAgent.indexOf("Trident/7") > -1;

            if (conf[engineName] === false || conf.clip[engineName] === false) {
                // engine disabled for player or clip
                return false;
            }

            // merge hlsjs clip config at earliest opportunity
            hlsconf = extend({}, flowplayer.conf[engineName], conf[engineName], conf.clip[engineName]);

            // support Safari only when hlsjs debugging
            // https://github.com/dailymotion/hls.js/issues/9
            return isHlsType(type) &&
                    (IE11 || !flowplayer.support.browser.safari || hlsconf.debug);
        };

        // put on top of engine stack
        // so hlsjs is tested before html5 video hls and flash hls
        flowplayer.engines.unshift(engineImpl);

    }

}.apply(null, (typeof module === 'object' && module.exports)
    ? [require('flowplayer'), require('hls.js')]
    : [window.flowplayer, window.Hls]));
<commit_msg>End of video workaround: also check whether current video is live<commit_after>/*jslint browser: true, for: true, node: true */
/*global window */

/*!

   hlsjs engine plugin for Flowplayer HTML5

   Copyright (c) 2015, Flowplayer Oy

   Released under the MIT License:
   http://www.opensource.org/licenses/mit-license.php

   Includes hls.min.js
   Copyright (c) 2015 Dailymotion (http://www.dailymotion.com)
   https://github.com/dailymotion/hls.js/blob/master/LICENSE

   requires:
   - Flowplayer HTML5 version 6.x or greater
   - hls.js https://github.com/dailymotion/hls.js
   revision: $GIT_ID$

*/

(function (flowplayer, Hls) {
    "use strict";
    var engineName = "hlsjs",
        hlsconf,
        common = flowplayer.common,
        extend = flowplayer.extend,
        version = flowplayer.version,

        isHlsType = function (typ) {
            return typ.toLowerCase().indexOf("mpegurl") > -1;
        },

        engineImpl = function hlsjsEngine(player, root) {
            var bean = flowplayer.bean,
                videoTag,
                hls,

                bc,
                has_bg,
                posterHack = function () {
                    // abuse timeupdate to re-instate poster
                    var posterClass = "is-poster",
                        etype = "progress." + engineName;

                    player.one(etype, function () {
                        common.addClass(root, posterClass);
                        player.poster = true;
                        player.one(etype, function () {
                            common.removeClass(root, posterClass);
                            player.poster = false;
                        });
                    });
                },

                engine = {
                    engineName: engineName,

                    pick: function (sources) {
                        var i,
                            source;

                        for (i = 0; i < sources.length; i += 1) {
                            source = sources[i];
                            if (isHlsType(source.type)
                                    && (!source.engine || source.engine === engineName)) {
                                if (typeof source.src === 'string') {
                                    source.src = common.createAbsoluteUrl(source.src);
                                }
                                return source;
                            }
                        }
                    },

                    load: function (video) {
                        var init = !hls,
                            conf = player.conf,
                            hlsClientConf = extend({}, hlsconf),
                            hlsParams = ["autoLevelCapping", "startLevel", "strict"];

                        if (init) {
                            common.removeNode(common.findDirect("video", root)[0]
                                    || common.find(".fp-player > video", root)[0]);
                            videoTag = common.createElement("video", {
                                className: "fp-engine " + engineName + "-engine",
                                autoplay: conf.autoplay
                                    ? "autoplay"
                                    : false
                            });
                            videoTag.setAttribute("x-webkit-airplay", "allow");

                        } else {
                            hls.destroy();
                        }

                        bean.on(videoTag, "play", function () {
                            player.trigger('resume', [player]);
                        });
                        bean.on(videoTag, "pause", function () {
                            player.trigger('pause', [player]);
                        });
                        bean.on(videoTag, "timeupdate", function () {
                            // https://github.com/dailymotion/hls.js/issues/83
                            if (!video.live && videoTag.currentTime >= video.duration - 0.38) {
                                bean.fire(videoTag, 'ended');
                            } else {
                                player.trigger('progress', [player, videoTag.currentTime]);
                            }
                        });
                        bean.on(videoTag, "loadeddata", function () {
                            video = extend(video, {
                                duration: videoTag.duration,
                                seekable: videoTag.seekable.end(null),
                                width: videoTag.videoWidth,
                                height: videoTag.videoHeight,
                                url: videoTag.currentSrc
                            });
                            player.trigger('ready', [player, video]);
                        });
                        bean.on(videoTag, "seeked", function () {
                            player.trigger('seek', [player, videoTag.currentTime]);
                        });
                        bean.on(videoTag, "progress", function (e) {
                            var ct = videoTag.currentTime,
                                buffer = 0,
                                buffend,
                                buffered,
                                last,
                                i;

                            try {
                                buffered = videoTag.buffered;
                                last = buffered.length - 1;
                                buffend = 0;
                                // cycle through time ranges to obtain buffer
                                // nearest current time
                                if (ct) {
                                    for (i = last; i > -1; i -= 1) {
                                        buffend = buffered.end(i);

                                        if (buffend >= ct) {
                                            buffer = buffend;
                                        }
                                    }
                                }
                            } catch (ignored) {}

                            video.buffer = buffer;
                            player.trigger('buffer', [player, e]);
                        });
                        bean.on(videoTag, "ended", function () {
                            player.trigger('finish', [player]);
                        });
                        bean.on(videoTag, "volumechange", function () {
                            player.trigger('volume', [player, videoTag.volume]);
                        });

                        hlsParams.forEach(function (key) {
                            delete hlsClientConf[key];
                        });
                        hls = new Hls(hlsClientConf);

                        hlsParams.forEach(function (key) {
                            var value = hlsconf[key];

                            switch (key) {
                            case "autoLevelCapping":
                                if (value === false) {
                                    value = -1;
                                }
                                break;
                            case "startLevel":
                                switch (value) {
                                case "auto":
                                    value = -1;
                                    break;
                                case "firstLevel":
                                    value = undefined;
                                    break;
                                }
                                break;
                            }

                            if (value !== undefined) {
                                hls[key] = value;
                            }
                        });

                        hls.on(Hls.Events.ERROR, function (e, data) {
                            var fperr,
                                errobj = {};

                            if (data.fatal || hlsconf.strict) {
                                switch (data.type) {
                                case Hls.ErrorTypes.NETWORK_ERROR:
                                    if (data.frag && data.frag.url) {
                                        errobj.url = data.frag.url;
                                        fperr = 2;
                                    } else {
                                        fperr = 4;
                                    }
                                    break;
                                case Hls.ErrorTypes.MEDIA_ERROR:
                                    fperr = 3;
                                    break;
                                default:
                                    fperr = 5;
                                    break;
                                }
                                errobj.code = fperr;
                                if (fperr > 2) {
                                    errobj.video = extend(video, {
                                        src: video.src,
                                        url: data.url || video.src
                                    });
                                }
                                player.trigger('error', [player, errobj]);
                            }
                            /* TODO: */
                            // log non fatals
                        });

                        if (init) {
                            common.prepend(common.find(".fp-player", root)[0], videoTag);
                        }

                        hls.loadSource(video.src);
                        hls.attachVideo(videoTag);

                        if (videoTag.paused && (video.autoplay || conf.autoplay)) {
                            videoTag.play();
                        }
                    },

                    resume: function () {
                        videoTag.play();
                    },

                    pause: function () {
                        videoTag.pause();
                    },

                    seek: function (time) {
                        videoTag.currentTime = time;
                    },

                    volume: function (level) {
                        if (videoTag) {
                            videoTag.volume = level;
                        }
                    },

                    speed: function (val) {
                        videoTag.playbackRate = val;
                        player.trigger('speed', [player, val]);
                    },

                    unload: function () {
                        // hls conditional probably not needed once
                        // https://github.com/flowplayer/flowplayer/commit/871ff783a8f23aa603e1120f4319d4a892125b0a
                        // is released
                        if (hls) {
                            hls.destroy();
                            hls = 0;
                            bean.off(videoTag);
                            common.removeNode(videoTag);
                            videoTag = 0;
                        }
                    }
                };

            // pre 6.0.4: no boolean api.conf.poster and no poster with autoplay
            if (/^6\.0\.[0-3]$/.test(version) &&
                    !player.conf.splash && !player.conf.poster && !player.conf.autoplay) {
                bc = common.css(root, 'backgroundColor');
                // spaces in rgba arg mandatory for recognition
                has_bg = common.css(root, 'backgroundImage') !== "none" ||
                        (bc && bc !== "rgba(0, 0, 0, 0)" && bc !== "transparent");
                if (has_bg) {
                    player.conf.poster = true;
                }
            }
            if (player.conf.poster) {
                // when engine is loaded or player stopped
                // the engine is too late to the party:
                // poster is already removed and api.poster is false
                // poster state must be set again
                player.on("ready." + engineName + " stop." + engineName, posterHack);
            }

            return engine;
        };

    if (Hls.isSupported() && version.indexOf("5.") !== 0) {
        // only load engine if it can be used
        engineImpl.engineName = engineName; // must be exposed
        engineImpl.canPlay = function (type, conf) {
            var IE11 = navigator.userAgent.indexOf("Trident/7") > -1;

            if (conf[engineName] === false || conf.clip[engineName] === false) {
                // engine disabled for player or clip
                return false;
            }

            // merge hlsjs clip config at earliest opportunity
            hlsconf = extend({}, flowplayer.conf[engineName], conf[engineName], conf.clip[engineName]);

            // support Safari only when hlsjs debugging
            // https://github.com/dailymotion/hls.js/issues/9
            return isHlsType(type) &&
                    (IE11 || !flowplayer.support.browser.safari || hlsconf.debug);
        };

        // put on top of engine stack
        // so hlsjs is tested before html5 video hls and flash hls
        flowplayer.engines.unshift(engineImpl);

    }

}.apply(null, (typeof module === 'object' && module.exports)
    ? [require('flowplayer'), require('hls.js')]
    : [window.flowplayer, window.Hls]));
<|endoftext|>


<commit_before>'use strict';

var rooted_blacklist = [
	"/sbin/su",
	"/system/bin/su",
	"/system/bin/failsafe/su",
	"/system/xbin/su",
	"/system/sd/xbin/su",
	"/data/local/su",
	"/data/local/xbin/su",
	"/system/app/Superuser.apk"
];
Java.perform(function () {
	var File = Java.use("java.io.File");
	File.exists.implementation = function () {
		if (rooted_blacklist.indexOf(this.path['value']) > -1) {
			console.log(this.path['value']);
			return false;
		} else {
			return this.exists.call(this);
		}

	}
});

Java.perform(function (){
	var Runtime = Java.use("java.lang.Runtime");
	console.log(typeof Runtime.getRuntime());
	Runtime.getRuntime().exec.overload("java.lang.String").implementation = function(command) {
		console.log('exec: ' + command.toString());
		if(command.toString() === 'su') {
			return null;
		} else {
			return this.exec.call(this, command);
		}

	};

});<commit_msg>bug fix<commit_after>'use strict';

var rooted_blacklist = [
	"/sbin/su",
	"/system/bin/su",
	"/system/bin/failsafe/su",
	"/system/xbin/su",
	"/system/sd/xbin/su",
	"/data/local/su",
	"/data/local/xbin/su",
	"/system/app/Superuser.apk"
];
Java.perform(function () {
	var File = Java.use("java.io.File");
	var Runtime = Java.use("java.lang.Runtime");
	File.exists.implementation = function () {
		if (rooted_blacklist.indexOf(this.path['value']) > -1) {
			console.log("Dropped File Access: " + this.path['value']);
			return false;
		} else {
			return this.exists.call(this);
		}

	}

	Runtime.getRuntime().exec.overload("java.lang.String").implementation = function(command) {
		if(command.toString() === 'su') {
			console.log("Dropped Command: su");
			return null;
		} else {
			return this.exec.call(this, command);
		}
	};

});<|endoftext|>


<commit_before>'use strict';

const path          = require ('path');
const {expect}      = require ('chai');
const rowsExtractor = require ('../lib/rows-extractor.js');

const script = `/*  1 */
/*  2 */ 'use strict';
/*  3 */
/*  4 */describe ('foobar', function () {
/*  5 */  it ('_foo', function () {
/*  6 */    const a = true;
/*  7 */    if (true) {
/*  8 */      // foo
/*  9 */      foo ();
/* 10 */    } else {
/* 11 */      // bar
/* 12 */      bar ();
/* 13 */    }
/* 14 */  });
/* 15 */  it ('_bar', () => {
/* 16 */    const a = true;
/* 17 */    if (true) {
/* 18 */      // foo
/* 19 */      foo ();
/* 20 */    } else {
/* 21 */      // bar
/* 22 */      bar ();
/* 23 */    }
/* 24 */  });
/* 25 */});
`;

describe ('rows-extractor', function () {
  it ('#byFile (regex)', function () {
    expect (rowsExtractor.byFile (path.join (__dirname, './sample.js'), 'it', /a.[0-9]/))
      .to.be.eql ([5, 6]);
  });

  it ('#byFile (string)', function () {
    expect (rowsExtractor.byFile (path.join (__dirname, './sample.js'), 'it', 'a.1'))
      .to.be.eql ([5, 6]);
  });

  it ('#byData (regex)', function () {
    expect (rowsExtractor.byData (script, 'it', /^_.*/))
      .to.be.eql ([6, 7, 9, 10, 12, 16, 17, 19, 20, 22]);
  });

  it ('#byData (string)', function () {
    expect (rowsExtractor.byData (script, 'it', '_foo'))
      .to.be.eql ([6, 7, 9, 10, 12]);
  });
});
<commit_msg>Fix rowsExtractor tests<commit_after>'use strict';

const path          = require ('path');
const {expect}      = require ('chai');
const rowsExtractor = require ('../lib/rows-extractor.js');

const script = `/*  1 */
/*  2 */ 'use strict';
/*  3 */
/*  4 */describe ('foobar', function () {
/*  5 */  it ('_foo', function () {
/*  6 */    const a = true;
/*  7 */    if (true) {
/*  8 */      // foo
/*  9 */      foo ();
/* 10 */    } else {
/* 11 */      // bar
/* 12 */      bar ();
/* 13 */    }
/* 14 */  });
/* 15 */  it ('_bar', () => {
/* 16 */    const a = true;
/* 17 */    if (true) {
/* 18 */      // foo
/* 19 */      foo ();
/* 20 */    } else {
/* 21 */      // bar
/* 22 */      bar ();
/* 23 */    }
/* 24 */  });
/* 25 */});
`;

describe ('rows-extractor', function () {
  it ('#byFile (regex)', function () {
    expect (rowsExtractor.byFile (path.join (__dirname, './sample.js'), 'it', /a.[0-9]/))
      .to.be.eql ([13, 14]);
  });

  it ('#byFile (string)', function () {
    expect (rowsExtractor.byFile (path.join (__dirname, './sample.js'), 'it', 'a.1'))
      .to.be.eql ([13, 14]);
  });

  it ('#byData (regex)', function () {
    expect (rowsExtractor.byData (script, 'it', /^_.*/))
      .to.be.eql ([6, 7, 9, 10, 12, 16, 17, 19, 20, 22]);
  });

  it ('#byData (string)', function () {
    expect (rowsExtractor.byData (script, 'it', '_foo'))
      .to.be.eql ([6, 7, 9, 10, 12]);
  });
});
<|endoftext|>


<commit_before>'use strict';

const assert = require('./../../assert');
const common = require('./../../common');

let battle;

describe('Shell Bell', function () {
	afterEach(function () {
		battle.destroy();
	});

	it(`should heal from the damage against all targets of the move`, function () {
		battle = common.createBattle({gameType: 'doubles'}, [[
			{species: 'tornadus', ability: 'compoundeyes', moves: ['superfang']},
			{species: 'landorus', item: 'shellbell', moves: ['earthquake']},
		], [
			{species: 'roggenrola', ability: 'sturdy', level: 1, moves: ['sleeptalk']},
			{species: 'aron', ability: 'sturdy', level: 1, moves: ['sleeptalk']},
		]]);
		battle.makeChoices('move superfang -2, move earthquake', 'auto');
		const landorus = battle.p1.active[1];
		assert.equal(landorus.hp, landorus.maxhp - Math.floor(landorus.maxhp / 2) + (Math.floor(11 * 2 / 8)));
	});

	// Also applies to Parental Bond
	it.skip(`should heal from the damage from all hits of multi-hit moves`, function () {
		battle = common.createBattle([[
			{species: 'shelmet', moves: ['finalgambit']},
			{species: 'landorus', moves: ['sleeptalk']},
			{species: 'wynaut', moves: ['sleeptalk']},
		], [
			{species: 'cloyster', ability: 'skilllink', item: 'shellbell', evs: {hp: 4}, moves: ['sleeptalk', 'iciclespear']},
		]]);
		battle.makeChoices();
		battle.makeChoices('switch 2');
		battle.makeChoices('auto', 'move iciclespear');
		const landorus = battle.p1.active[0];
		const cloyster = battle.p2.active[0];
		assert.equal(cloyster.hp, 1 + Math.floor(landorus.maxhp / 8));
	});
});
<commit_msg>Tests: Unskip passing Shell Bell test<commit_after>'use strict';

const assert = require('./../../assert');
const common = require('./../../common');

let battle;

describe('Shell Bell', function () {
	afterEach(function () {
		battle.destroy();
	});

	it(`should heal from the damage against all targets of the move`, function () {
		battle = common.createBattle({gameType: 'doubles'}, [[
			{species: 'tornadus', ability: 'compoundeyes', moves: ['superfang']},
			{species: 'landorus', item: 'shellbell', moves: ['earthquake']},
		], [
			{species: 'roggenrola', ability: 'sturdy', level: 1, moves: ['sleeptalk']},
			{species: 'aron', ability: 'sturdy', level: 1, moves: ['sleeptalk']},
		]]);
		battle.makeChoices('move superfang -2, move earthquake', 'auto');
		const landorus = battle.p1.active[1];
		assert.equal(landorus.hp, landorus.maxhp - Math.floor(landorus.maxhp / 2) + (Math.floor(11 * 2 / 8)));
	});

	// Also applies to Parental Bond
	it(`should heal from the damage from all hits of multi-hit moves`, function () {
		battle = common.createBattle([[
			{species: 'shelmet', moves: ['finalgambit']},
			{species: 'landorus', moves: ['sleeptalk']},
			{species: 'wynaut', moves: ['sleeptalk']},
		], [
			{species: 'cloyster', ability: 'skilllink', item: 'shellbell', evs: {hp: 4}, moves: ['sleeptalk', 'iciclespear']},
		]]);
		battle.makeChoices();
		battle.makeChoices('switch 2');
		battle.makeChoices('auto', 'move iciclespear');
		const landorus = battle.p1.active[0];
		const cloyster = battle.p2.active[0];
		assert.equal(cloyster.hp, 1 + Math.floor(landorus.maxhp / 8));
	});
});
<|endoftext|>


<commit_before>describe("src/organism/OperatorsDos", () => {
    let OperatorsDos = require('../../../src/organism/OperatorsDos').default;
    let Helper       = require('../../../src/global/Helper').default;
    let Observer     = require('../../../src/global/Observer').default;

    it("Checking onVar() method", () => {
        let ops = new OperatorsDos([], [0, 0, 0, 0], new Observer());

        expect(ops.onVar(0x00ffffff, 0)).toEqual(1);
        expect(ops.vars[0] === 0).toEqual(true);
        expect(ops.vars[1] === 0).toEqual(true);
        expect(ops.vars[2] === 0).toEqual(true);
        expect(ops.vars[3] === 0).toEqual(true);
        expect(ops.onVar(0x000fffff, 0)).toEqual(1);
        expect(ops.vars[0] === 0).toEqual(true);
        expect(ops.vars[1] === 0).toEqual(true);
        expect(ops.vars[2] === 0).toEqual(true);
        expect(ops.vars[3] === 0).toEqual(true);
        expect(ops.onVar(0x0000ffff, 0)).toEqual(1);
        expect(ops.vars[0] === 0x3fff).toEqual(true);
        expect(ops.vars[1] === 0).toEqual(true);
        expect(ops.vars[2] === 0).toEqual(true);
        expect(ops.vars[3] === 0).toEqual(true);
    });

    // it("Checking onCondition() method", () => {
    //     let ops = new OperatorsDos([], [0, 1, 2, 3], new Observer());
    //
    //     expect(ops.onCondition(0x01ffffff), 0, 1).toEqual('yield;if(v3!=v3){');
    //     expect(ops.onCondition(0x011fffff), 0, 1).toEqual('yield;if(v0!=v1){');
    //     expect(ops.onCondition(0x011abfff), 0, 1).toEqual('yield;if(v0==v1){');
    //     expect(ops.onCondition(0x01ffffff), 0, 1).toEqual('yield;if(v3!=v3){');
    // });
    //
    // it("Checking onLoop() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onLoop(0x02ffffff), 0, 1).toEqual('for(v3=v3;v3<v3;v3++){yield');
    //     expect(ops.onLoop(0x028fffff), 0, 1).toEqual('for(v2=v0;v2<v3;v2++){yield');
    //     expect(ops.onLoop(0x0287ffff), 0, 1).toEqual('for(v2=v0;v2<v1;v2++){yield');
    //     expect(ops.onLoop(0x02ffffff), 0, 1).toEqual('for(v3=v3;v3<v3;v3++){yield');
    // });
    //
    // it("Checking onOperator() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onOperator(0x031a3fff), 0, 1).toEqual('v0=v1>>v2');
    //     expect(ops.onOperator(0x036c7fff), 0, 1).toEqual('v1=v2-v3');
    //     expect(ops.onOperator(0x036fffff), 0, 1).toEqual('v1=v2<=v3');
    //     expect(ops.onOperator(0x03ffffff), 0, 1).toEqual('v3=v3<=v3');
    // });
    //
    // it("Checking onNot() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onNot(0x041fffff), 0, 1).toEqual('v0=!v1');
    //     expect(ops.onNot(0x046fffff), 0, 1).toEqual('v1=!v2');
    //     expect(ops.onNot(0x04ffffff), 0, 1).toEqual('v3=!v3');
    // });
    //
    // it("Checking onPi() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onPi(0x053fffff), 0, 1).toEqual('v0=pi');
    //     expect(ops.onPi(0x057fffff), 0, 1).toEqual('v1=pi');
    //     expect(ops.onPi(0x05ffffff), 0, 1).toEqual('v3=pi');
    // });
    //
    // it("Checking onTrig() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onTrig(0x061bffff), 0, 1).toEqual('v0=Math.tan(v1)');
    //     expect(ops.onTrig(0x0663ffff), 0, 1).toEqual('v1=Math.sin(v2)');
    //     expect(ops.onTrig(0x06ffffff), 0, 1).toEqual('v3=Math.abs(v3)');
    // });
    //
    // it("Checking onLookAt() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onLookAt(0x071bffff), 0, 1).toEqual('v0=org.lookAt(v1,v2)');
    //     expect(ops.onLookAt(0x076fffff), 0, 1).toEqual('v1=org.lookAt(v2,v3)');
    //     expect(ops.onLookAt(0x07ffffff), 0, 1).toEqual('v3=org.lookAt(v3,v3)');
    // });
    //
    // it("Checking onEatLeft() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatLeft(0x081fffff), 0, 1).toEqual('v0=org.eatLeft(v1)');
    //     expect(ops.onEatLeft(0x086fffff), 0, 1).toEqual('v1=org.eatLeft(v2)');
    //     expect(ops.onEatLeft(0x08ffffff), 0, 1).toEqual('v3=org.eatLeft(v3)');
    // });
    // it("Checking onEatRight() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatRight(0x081fffff), 0, 1).toEqual('v0=org.eatRight(v1)');
    //     expect(ops.onEatRight(0x086fffff), 0, 1).toEqual('v1=org.eatRight(v2)');
    //     expect(ops.onEatRight(0x08ffffff), 0, 1).toEqual('v3=org.eatRight(v3)');
    // });
    // it("Checking onEatUp() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatUp(0x081fffff), 0, 1).toEqual('v0=org.eatUp(v1)');
    //     expect(ops.onEatUp(0x086fffff), 0, 1).toEqual('v1=org.eatUp(v2)');
    //     expect(ops.onEatUp(0x08ffffff), 0, 1).toEqual('v3=org.eatUp(v3)');
    // });
    // it("Checking onEatDown() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatDown(0x081fffff), 0, 1).toEqual('v0=org.eatDown(v1)');
    //     expect(ops.onEatDown(0x086fffff), 0, 1).toEqual('v1=org.eatDown(v2)');
    //     expect(ops.onEatDown(0x08ffffff), 0, 1).toEqual('v3=org.eatDown(v3)');
    // });
    //
    // it("Checking onStepLeft() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepLeft(0x081fffff), 0, 1).toEqual('v0=org.stepLeft()');
    //     expect(ops.onStepLeft(0x086fffff), 0, 1).toEqual('v1=org.stepLeft()');
    //     expect(ops.onStepLeft(0x08ffffff), 0, 1).toEqual('v3=org.stepLeft()');
    // });
    // it("Checking onStepRight() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepRight(0x081fffff), 0, 1).toEqual('v0=org.stepRight()');
    //     expect(ops.onStepRight(0x086fffff), 0, 1).toEqual('v1=org.stepRight()');
    //     expect(ops.onStepRight(0x08ffffff), 0, 1).toEqual('v3=org.stepRight()');
    // });
    // it("Checking onStepUp() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepUp(0x081fffff), 0, 1).toEqual('v0=org.stepUp()');
    //     expect(ops.onStepUp(0x086fffff), 0, 1).toEqual('v1=org.stepUp()');
    //     expect(ops.onStepUp(0x08ffffff), 0, 1).toEqual('v3=org.stepUp()');
    // });
    // it("Checking onStepDown() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepDown(0x081fffff), 0, 1).toEqual('v0=org.stepDown()');
    //     expect(ops.onStepDown(0x086fffff), 0, 1).toEqual('v1=org.stepDown()');
    //     expect(ops.onStepDown(0x08ffffff), 0, 1).toEqual('v3=org.stepDown()');
    // });
    //
    // it("Checking onFromMem() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onFromMem(0x081fffff), 0, 1).toEqual('v0=org.fromMem()');
    //     expect(ops.onFromMem(0x086fffff), 0, 1).toEqual('v1=org.fromMem()');
    //     expect(ops.onFromMem(0x08ffffff), 0, 1).toEqual('v3=org.fromMem()');
    // });
    //
    // it("Checking onToMem() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onToMem(0x081fffff), 0, 1).toEqual('org.toMem(v0)');
    //     expect(ops.onToMem(0x086fffff), 0, 1).toEqual('org.toMem(v1)');
    //     expect(ops.onToMem(0x08ffffff), 0, 1).toEqual('org.toMem(v3)');
    // });
    //
    // it("Checking onMyX() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onMyX(0x081fffff), 0, 1).toEqual('v0=org.myX()');
    //     expect(ops.onMyX(0x086fffff), 0, 1).toEqual('v1=org.myX()');
    //     expect(ops.onMyX(0x08ffffff), 0, 1).toEqual('v3=org.myX()');
    // });
    // it("Checking onMyY() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onMyY(0x081fffff), 0, 1).toEqual('v0=org.myY()');
    //     expect(ops.onMyY(0x086fffff), 0, 1).toEqual('v1=org.myY()');
    //     expect(ops.onMyY(0x08ffffff), 0, 1).toEqual('v3=org.myY()');
    // });
});<commit_msg>added test for OperatorsDos class #14<commit_after>describe("src/organism/OperatorsDos", () => {
    let OperatorsDos = require('../../../src/organism/OperatorsDos').default;
    let Helper       = require('../../../src/global/Helper').default;
    let Observer     = require('../../../src/global/Observer').default;

    it("Checking onVar() method", () => {
        let ops = new OperatorsDos([], [0, 0, 0, 0], new Observer());

        expect(ops.onVar(0x00ffffff, 0)).toEqual(1);
        expect(ops.vars[0] === 0).toEqual(true);
        expect(ops.vars[1] === 0).toEqual(true);
        expect(ops.vars[2] === 0).toEqual(true);
        expect(ops.vars[3] === 0).toEqual(true);
        expect(ops.onVar(0x000fffff, 0)).toEqual(1);
        expect(ops.vars[0] === 0).toEqual(true);
        expect(ops.vars[1] === 0).toEqual(true);
        expect(ops.vars[2] === 0).toEqual(true);
        expect(ops.vars[3] === 0).toEqual(true);
        expect(ops.onVar(0x0000ffff, 0)).toEqual(1);
        expect(ops.vars[0] === 0x3fff).toEqual(true);
        expect(ops.vars[1] === 0).toEqual(true);
        expect(ops.vars[2] === 0).toEqual(true);
        expect(ops.vars[3] === 0).toEqual(true);
    });

    it("Checking onCondition() method", () => {
        let ops = new OperatorsDos([], [0, 1, 2, 3], new Observer());

        expect(ops.onCondition(0x01ffffff, 0, {}, 0)).toEqual(0); //if(v3!=v3)');
        expect(ops.onCondition(0x011fffff, 0, {}, 0)).toEqual(1); //if(v0!=v1)');
        expect(ops.onCondition(0x011abfff, 0, {}, 0)).toEqual(0); //if(v0==v1)');
        expect(ops.onCondition(0x01ffffff, 0, {}, 0)).toEqual(0); //if(v3!=v3)');
    });
    //
    // it("Checking onLoop() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onLoop(0x02ffffff), 0, 1).toEqual('for(v3=v3;v3<v3;v3++){yield');
    //     expect(ops.onLoop(0x028fffff), 0, 1).toEqual('for(v2=v0;v2<v3;v2++){yield');
    //     expect(ops.onLoop(0x0287ffff), 0, 1).toEqual('for(v2=v0;v2<v1;v2++){yield');
    //     expect(ops.onLoop(0x02ffffff), 0, 1).toEqual('for(v3=v3;v3<v3;v3++){yield');
    // });
    //
    // it("Checking onOperator() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onOperator(0x031a3fff), 0, 1).toEqual('v0=v1>>v2');
    //     expect(ops.onOperator(0x036c7fff), 0, 1).toEqual('v1=v2-v3');
    //     expect(ops.onOperator(0x036fffff), 0, 1).toEqual('v1=v2<=v3');
    //     expect(ops.onOperator(0x03ffffff), 0, 1).toEqual('v3=v3<=v3');
    // });
    //
    // it("Checking onNot() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onNot(0x041fffff), 0, 1).toEqual('v0=!v1');
    //     expect(ops.onNot(0x046fffff), 0, 1).toEqual('v1=!v2');
    //     expect(ops.onNot(0x04ffffff), 0, 1).toEqual('v3=!v3');
    // });
    //
    // it("Checking onPi() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onPi(0x053fffff), 0, 1).toEqual('v0=pi');
    //     expect(ops.onPi(0x057fffff), 0, 1).toEqual('v1=pi');
    //     expect(ops.onPi(0x05ffffff), 0, 1).toEqual('v3=pi');
    // });
    //
    // it("Checking onTrig() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onTrig(0x061bffff), 0, 1).toEqual('v0=Math.tan(v1)');
    //     expect(ops.onTrig(0x0663ffff), 0, 1).toEqual('v1=Math.sin(v2)');
    //     expect(ops.onTrig(0x06ffffff), 0, 1).toEqual('v3=Math.abs(v3)');
    // });
    //
    // it("Checking onLookAt() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onLookAt(0x071bffff), 0, 1).toEqual('v0=org.lookAt(v1,v2)');
    //     expect(ops.onLookAt(0x076fffff), 0, 1).toEqual('v1=org.lookAt(v2,v3)');
    //     expect(ops.onLookAt(0x07ffffff), 0, 1).toEqual('v3=org.lookAt(v3,v3)');
    // });
    //
    // it("Checking onEatLeft() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatLeft(0x081fffff), 0, 1).toEqual('v0=org.eatLeft(v1)');
    //     expect(ops.onEatLeft(0x086fffff), 0, 1).toEqual('v1=org.eatLeft(v2)');
    //     expect(ops.onEatLeft(0x08ffffff), 0, 1).toEqual('v3=org.eatLeft(v3)');
    // });
    // it("Checking onEatRight() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatRight(0x081fffff), 0, 1).toEqual('v0=org.eatRight(v1)');
    //     expect(ops.onEatRight(0x086fffff), 0, 1).toEqual('v1=org.eatRight(v2)');
    //     expect(ops.onEatRight(0x08ffffff), 0, 1).toEqual('v3=org.eatRight(v3)');
    // });
    // it("Checking onEatUp() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatUp(0x081fffff), 0, 1).toEqual('v0=org.eatUp(v1)');
    //     expect(ops.onEatUp(0x086fffff), 0, 1).toEqual('v1=org.eatUp(v2)');
    //     expect(ops.onEatUp(0x08ffffff), 0, 1).toEqual('v3=org.eatUp(v3)');
    // });
    // it("Checking onEatDown() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onEatDown(0x081fffff), 0, 1).toEqual('v0=org.eatDown(v1)');
    //     expect(ops.onEatDown(0x086fffff), 0, 1).toEqual('v1=org.eatDown(v2)');
    //     expect(ops.onEatDown(0x08ffffff), 0, 1).toEqual('v3=org.eatDown(v3)');
    // });
    //
    // it("Checking onStepLeft() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepLeft(0x081fffff), 0, 1).toEqual('v0=org.stepLeft()');
    //     expect(ops.onStepLeft(0x086fffff), 0, 1).toEqual('v1=org.stepLeft()');
    //     expect(ops.onStepLeft(0x08ffffff), 0, 1).toEqual('v3=org.stepLeft()');
    // });
    // it("Checking onStepRight() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepRight(0x081fffff), 0, 1).toEqual('v0=org.stepRight()');
    //     expect(ops.onStepRight(0x086fffff), 0, 1).toEqual('v1=org.stepRight()');
    //     expect(ops.onStepRight(0x08ffffff), 0, 1).toEqual('v3=org.stepRight()');
    // });
    // it("Checking onStepUp() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepUp(0x081fffff), 0, 1).toEqual('v0=org.stepUp()');
    //     expect(ops.onStepUp(0x086fffff), 0, 1).toEqual('v1=org.stepUp()');
    //     expect(ops.onStepUp(0x08ffffff), 0, 1).toEqual('v3=org.stepUp()');
    // });
    // it("Checking onStepDown() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onStepDown(0x081fffff), 0, 1).toEqual('v0=org.stepDown()');
    //     expect(ops.onStepDown(0x086fffff), 0, 1).toEqual('v1=org.stepDown()');
    //     expect(ops.onStepDown(0x08ffffff), 0, 1).toEqual('v3=org.stepDown()');
    // });
    //
    // it("Checking onFromMem() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onFromMem(0x081fffff), 0, 1).toEqual('v0=org.fromMem()');
    //     expect(ops.onFromMem(0x086fffff), 0, 1).toEqual('v1=org.fromMem()');
    //     expect(ops.onFromMem(0x08ffffff), 0, 1).toEqual('v3=org.fromMem()');
    // });
    //
    // it("Checking onToMem() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onToMem(0x081fffff), 0, 1).toEqual('org.toMem(v0)');
    //     expect(ops.onToMem(0x086fffff), 0, 1).toEqual('org.toMem(v1)');
    //     expect(ops.onToMem(0x08ffffff), 0, 1).toEqual('org.toMem(v3)');
    // });
    //
    // it("Checking onMyX() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onMyX(0x081fffff), 0, 1).toEqual('v0=org.myX()');
    //     expect(ops.onMyX(0x086fffff), 0, 1).toEqual('v1=org.myX()');
    //     expect(ops.onMyX(0x08ffffff), 0, 1).toEqual('v3=org.myX()');
    // });
    // it("Checking onMyY() method", () => {
    //     let ops = new OperatorsDos([]);
    //
    //     expect(ops.onMyY(0x081fffff), 0, 1).toEqual('v0=org.myY()');
    //     expect(ops.onMyY(0x086fffff), 0, 1).toEqual('v1=org.myY()');
    //     expect(ops.onMyY(0x08ffffff), 0, 1).toEqual('v3=org.myY()');
    // });
});<|endoftext|>