dom/settings/SettingsQueue.jsm
author Kyle Huey <khuey@kylehuey.com>
Tue, 30 Oct 2012 12:28:11 -0700
changeset 120435 67cb43bb8865ecbcb79c2ea04a0494fd223cc69d
parent 120431 ad1d720d82b7f84d3c7e50f4b02b7c3201662ddb
child 120523 5bf3abe91210f94d5d92ba95e114181e366d82ea
permissions -rw-r--r--
Bug 798491: Add an option to stick all chrome JSMs/JS components in the same compartment. r=mrbkap,philikon

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

this.EXPORTED_SYMBOLS = ["Queue"];

this.Queue = function Queue() {
  this._queue = [];
  this._index = 0;
}

Queue.prototype = {
  getLength: function() { return (this._queue.length - this._index); },

  isEmpty: function() { return (this._queue.length == 0); },

  enqueue: function(item) { this._queue.push(item); },

  dequeue: function() {
    if(this.isEmpty())
      return undefined;

    var item = this._queue[this._index];
    if (++this._index * 2 >= this._queue.length){
      this._queue  = this._queue.slice(this._index);
      this._index = 0;
    }
    return item;
  }
}