1 /* See license.txt for terms of usage */
  2 
  3 define([
  4     "firebug/lib/trace",
  5 ],
  6 function(FBTrace) {
  7 
  8 // ********************************************************************************************* //
  9 // Constants
 10 
 11 function ToggleBranch()
 12 {
 13     this.normal = {};
 14     this.meta = {};
 15 }
 16 
 17 var metaNames =
 18 [
 19  'prototype',
 20  'constructor',
 21  '__proto__',
 22  'toString',
 23  'toSource',
 24  'hasOwnProperty',
 25  'getPrototypeOf',
 26  '__defineGetter__',
 27  '__defineSetter__',
 28  '__lookupGetter__',
 29  '__lookupSetter__',
 30  '__noSuchMethod__',
 31  'propertyIsEnumerable',
 32  'isPrototypeOf',
 33  'watch',
 34  'unwatch',
 35  'valueOf',
 36  'toLocaleString'
 37 ];
 38 
 39 ToggleBranch.prototype =
 40 {
 41     // Another implementation could simply prefix all keys with "#".
 42     getMeta: function(name)
 43     {
 44         if (metaNames.indexOf(name) !== -1)
 45             return "meta_"+name;
 46     },
 47 
 48     get: function(name)  // return the toggle branch at name
 49     {
 50         var metaName = this.getMeta(name);
 51         if (metaName)
 52             var value = this.meta[metaName];
 53         else if (this.normal.hasOwnProperty(name))
 54             var value = this.normal[name];
 55         else
 56             var value = null;
 57 
 58         if (FBTrace.DBG_DOMPLATE)
 59             if (value && !(value instanceof ToggleBranch))
 60                 FBTrace.sysout("ERROR ToggleBranch.get("+name+") not set to a ToggleBranch!");
 61 
 62         return value;
 63     },
 64 
 65     set: function(name, value)  // value will be another toggle branch
 66     {
 67         if (FBTrace.DBG_DOMPLATE)
 68             if (value && !(value instanceof ToggleBranch))
 69                 FBTrace.sysout("ERROR ToggleBranch.set("+name+","+value+") not set to a ToggleBranch!");
 70 
 71         var metaName = this.getMeta(name);
 72         if (metaName)
 73             return this.meta[metaName] = value;
 74         else
 75             return this.normal[name] = value;
 76     },
 77 
 78     remove: function(name)  // remove the toggle branch at name
 79     {
 80         var metaName = this.getMeta(name);
 81         if (metaName)
 82             delete this.meta[metaName];
 83         else
 84             delete this.normal[name];
 85     },
 86 
 87     toString: function()
 88     {
 89         return "[ToggleBranch]";
 90     },
 91 };
 92 
 93 // ********************************************************************************************* //
 94 
 95 return {
 96     ToggleBranch: ToggleBranch
 97 };
 98 
 99 // ********************************************************************************************* //
100 });
101