1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const EXPORTED_METHODS = [
15 * Module that contains global session data.
17 export function GlobalState() {
18 let internal = new GlobalStateInternal();
20 for (let method of EXPORTED_METHODS) {
21 external[method] = internal[method].bind(internal);
23 return Object.freeze(external);
26 function GlobalStateInternal() {
27 // Storage for global state.
31 GlobalStateInternal.prototype = {
33 * Get all value from the global state.
40 * Clear all currently stored global state.
47 * Retrieve a value from the global state.
50 * A key the value is stored under.
51 * @return The value stored at aKey, or an empty string if no value is set.
54 return this.state[aKey] || "";
61 * A key to store the value under.
63 set(aKey, aStringValue) {
64 this.state[aKey] = aStringValue;
68 * Delete a global value.
71 * A key to delete the value for.
74 delete this.state[aKey];
78 * Set the current global state from a state object. Any previous global
79 * state will be removed, even if the new state does not contain a matching
83 * A state object to extract global state from to be set.
85 setFromState(aState) {
86 this.state = (aState && aState.global) || {};