Security:Strawman Model: Difference between revisions

Jump to navigation Jump to search
no edit summary
(User:Brendan moved to XPConnect:Security:XPCNativeWrapper Automation)
 
No edit summary
Line 1: Line 1:
#REDIRECT [[XPConnect:Security:XPCNativeWrapper Automation]]
</code>
$ cat Iterator.js
function Iterator() {
    var i = arguments.length;


    if (i < 0 && 2 < i)
        throw TypeError("Iterator requires 0 to 2 arguments");
    function generic_next() { return this(); };
    var arg0 = arguments[0];
    if (arg0 && typeof arg0 == "object") {
        if (i == 2 && typeof arg0 == "function") {
            var callable = arg0;
            var sentinel = arguments[1];
            var last;
            function funiter() {
                last = callable();
                if (last == sentinel)
                    throw "StopIteration";
                return last;
            }
            funiter.next = generic_next;
            funiter.done = function () { return last == sentinel; };
            return funiter;
        }
        var keys = [];
        for (i in arg0)
            keys.push(i);
        i = 0;
        function objiter() {
            if (i == keys.length)
                throw "StopIteration";
            return keys[i++];
        }
        objiter.next = generic_next;
        objiter.done = function () { return i == keys.length; };
        return objiter;
    }
    var end, start = 0, step = 1;
    i = 0;
    switch (arguments.length) {
      case 3:
        step = Number(arguments[2]);
      case 2:
        start = Number(arg0), i = 1;
      case 1:
        end = Number(arguments[i]);
        break;
    }
    i = start;
    function iter() {
        if (i == end)
            throw "StopIteration";
        var j = i;
        i += step;
        return j;
    }
    iter.next = generic_next;
    iter.done = function () { return i == end; };
    return iter;
}
</code>
Confirmed users, Bureaucrats and Sysops emeriti
419

edits

Navigation menu