1 /* See license.txt for terms of usage */ 2 3 define([], function() { 4 5 // ********************************************************************************************* // 6 // Constants 7 8 var Ci = Components.interfaces; 9 var Cc = Components.classes; 10 var Cu = Components.utils; 11 12 var Wrapper = {}; 13 14 // ********************************************************************************************* // 15 // Wrappers 16 17 Wrapper.getContentView = function(object) 18 { 19 if (typeof(object) === "undefined" || object == null) 20 return false; 21 22 return (object.wrappedJSObject); 23 } 24 25 Wrapper.unwrapObject = function(object) 26 { 27 // TODO: We might be able to make this check more authoritative with QueryInterface. 28 if (typeof(object) === 'undefined' || object == null) 29 return object; 30 31 if (object.wrappedJSObject) 32 return object.wrappedJSObject; 33 34 return object; 35 } 36 37 Wrapper.unwrapIValue = function(object, viewChrome) 38 { 39 var unwrapped = object.getWrappedValue(); 40 if (viewChrome) 41 return unwrapped; 42 43 try 44 { 45 // XPCSafeJSObjectWrapper is not defined in Firefox 4.0 46 // this should be the only call to getWrappedValue in firebug 47 if (typeof(XPCSafeJSObjectWrapper) != "undefined") 48 { 49 return XPCSafeJSObjectWrapper(unwrapped); 50 } 51 else if (typeof(unwrapped) == "object") 52 { 53 var result = XPCNativeWrapper.unwrap(unwrapped); 54 if (result) 55 return result; 56 } 57 } 58 catch (exc) 59 { 60 if (FBTrace.DBG_ERRORS) 61 { 62 FBTrace.sysout("unwrapIValue FAILS for " + object + " cause: " + exc, 63 {exc: exc, object: object, unwrapped: unwrapped}); 64 } 65 } 66 67 return unwrapped; 68 } 69 70 Wrapper.unwrapIValueObject = function(scope, viewChrome) 71 { 72 var scopeVars = {}; 73 var listValue = {value: null}, lengthValue = {value: 0}; 74 scope.getProperties(listValue, lengthValue); 75 76 for (var i = 0; i < lengthValue.value; ++i) 77 { 78 var prop = listValue.value[i]; 79 var name = Wrapper.unwrapIValue(prop.name); 80 81 if (prop.value.jsType === prop.value.TYPE_NULL) // null is an object (!) 82 { 83 scopeVars[name] = null; 84 } 85 else 86 { 87 if (!Wrapper.shouldIgnore(name)) 88 scopeVars[name] = Wrapper.unwrapIValue(prop.value, viewChrome); 89 } 90 } 91 92 return scopeVars; 93 }; 94 95 // ********************************************************************************************* // 96 97 Wrapper.ignoreVars = 98 { 99 "__firebug__": 1, 100 "eval": 1, 101 102 // We are forced to ignore Java-related variables, because 103 // trying to access them causes browser freeze 104 "sun": 1, 105 "Packages": 1, 106 "JavaArray": 1, 107 "JavaMember": 1, 108 "JavaObject": 1, 109 "JavaClass": 1, 110 "JavaPackage": 1, 111 112 // internal firebug things XXXjjb todo we should privatize these 113 "_firebug": 1, 114 "_createFirebugConsole": 1, 115 "_FirebugCommandLine": 1, 116 "loadFirebugConsole": 1, 117 }; 118 119 Wrapper.shouldIgnore = function(name) 120 { 121 return (Wrapper.ignoreVars[name] === 1); 122 }; 123 124 // ********************************************************************************************* // 125 126 return Wrapper; 127 128 // ********************************************************************************************* // 129 }); 130