/* See license.txt for terms of usage */

define([], function() {

// ********************************************************************************************* //
// Constants

var Wrapper = {};

// ********************************************************************************************* //
// Wrappers

Wrapper.getContentView = function(object)
{
    if (isPrimitive(object))
        return object;

    return object.wrappedJSObject;
};

Wrapper.unwrapObject = function(object)
{
    if (isPrimitive(object))
        return object;

    return XPCNativeWrapper.unwrap(object);
};

Wrapper.unwrapIValue = function(object, viewChrome)
{
    var unwrapped = object.getWrappedValue();
    if (viewChrome)
        return unwrapped;

    try
    {
        // XPCSafeJSObjectWrapper is not defined in Firefox 4.0
        // this should be the only call to getWrappedValue in firebug
        if (typeof(XPCSafeJSObjectWrapper) != "undefined")
        {
            return XPCSafeJSObjectWrapper(unwrapped);
        }
        else if (typeof(unwrapped) == "object")
        {
            var result = XPCNativeWrapper.unwrap(unwrapped);
            if (result)
                return result;
        }
    }
    catch (exc)
    {
        if (FBTrace.DBG_ERRORS)
        {
            FBTrace.sysout("unwrapIValue FAILS for " + object + " cause: " + exc,
                {exc: exc, object: object, unwrapped: unwrapped});
        }
    }

    return unwrapped;
};

Wrapper.unwrapIValueObject = function(scope, viewChrome)
{
    var scopeVars = {};
    var listValue = {value: null}, lengthValue = {value: 0};
    scope.getProperties(listValue, lengthValue);

    for (var i = 0; i < lengthValue.value; ++i)
    {
        var prop = listValue.value[i];
        var name = Wrapper.unwrapIValue(prop.name);

        if (prop.value.jsType === prop.value.TYPE_NULL) // null is an object (!)
        {
            scopeVars[name] = null;
        }
        else
        {
            if (!Wrapper.shouldIgnore(name))
                scopeVars[name] = Wrapper.unwrapIValue(prop.value, viewChrome);
        }
    }

    return scopeVars;
};

// ********************************************************************************************* //

Wrapper.ignoreVars =
{
    // We are forced to ignore Java-related variables, because
    // trying to access them causes browser freeze
    "sun": 1,
    "Packages": 1,
    "JavaArray": 1,
    "JavaMember": 1,
    "JavaObject": 1,
    "JavaClass": 1,
    "JavaPackage": 1,

    // internal firebug things XXXjjb todo we should privatize these
    "_firebug": 1,
    "_firebugUnwrappedDebuggerObject": 1,
    "__fb_scopedVars": 1,
    "_FirebugCommandLine": 1,
};

Wrapper.shouldIgnore = function(name)
{
    return (Wrapper.ignoreVars[name] === 1);
};

function isPrimitive(obj)
{
    return !(obj && (typeof obj === "object" || typeof obj === "function"));
}

// ********************************************************************************************* //

return Wrapper;

// ********************************************************************************************* //
});

@@ -581,24 +581,158 @@
 bject);%0A%7D;%0A%0A
+Wrapper.wrapObject = function(object)%0A%7B%0A    if (isPrimitive(object))%0A        return object;%0A%0A    return XPCNativeWrapper(object);%0A%7D;%0A%0A
 Wrapper.unwr

Add Wrapper.wrapObject