<commit_before>/* See license.txt for terms of usage */

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

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;

var EXPORTED_SYMBOLS = ["traceConsoleService"];

// ************************************************************************************************
// Service implementation

/**
 * This implementation serves as a proxy to the FBTrace extension. All logs are forwarded
 * to the FBTrace service.
 */
try
{
    Cu["import"]("resource://fbtrace/firebug-trace-service.js");
}
catch (err)
{
    var traceConsoleService =
    {
        getTracer: function(prefDomain)
        {
            var TraceAPI = ["dump", "sysout", "setScope", "matchesNode", "time", "timeEnd"];
            var TraceObj = {};
            for (var i=0; i<TraceAPI.length; i++)
                TraceObj[TraceAPI[i]] = function() {};

            var optionsSet = false;

            TraceObj.sysout = function(msg)
            {
                try
                {
                    var scope = {};
                    Cu.import("resource://fbtrace/firebug-trace-service.js", scope);
                    var FBTrace = scope.traceConsoleService.getTracer("extensions.firebug");
                    FBTrace.sysout.apply(FBTrace, arguments);

                    // Copy all options from real FBTrace object into the one that has
                    // been already created.
                    if (!optionsSet)
                    {
                        for (var p in FBTrace)
                            TraceObj[p] = FBTrace[p];
                        optionsSet = true;
                    }
                }
                catch (err)
                {
                    //Cu.reportError(getStackDump());
                    Cu.reportError(msg);
                }
            }

            return TraceObj;
        }
    };
}

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

function getStackDump()
{
    var lines = [];
    for (var frame = Components.stack; frame; frame = frame.caller)
        lines.push(frame.filename + " (" + frame.lineNumber + ")");

    return lines.join("\n");
};<commit_msg>Return Proxy if FBTrace is used before the console is ready<commit_after>/* See license.txt for terms of usage */

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

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;

var EXPORTED_SYMBOLS = ["traceConsoleService"];

// ********************************************************************************************* //
// Service implementation

/**
 * This implementation serves as a proxy to the FBTrace extension. All logs are forwarded
 * to the FBTrace service as soon as it's available.
 */
try
{
    Cu["import"]("resource://fbtrace/firebug-trace-service.js");
}
catch (err)
{
    var traceConsoleService =
    {
        getTracer: function(prefDomain)
        {
            // Will be initialized as soon as FBTrace console is available.
            var FBTrace;

            // Fake FBTrace object (empty implementation)
            var TraceObj = {};
            var TraceAPI = ["dump", "sysout", "setScope", "matchesNode", "time", "timeEnd"];
            for (var i=0; i<TraceAPI.length; i++)
                TraceObj[TraceAPI[i]] = function() {};

            // Create FBTrace proxy. As soon as FBTrace console is available it'll forward
            // all calls to it.
            return Proxy.create(
            {
                get: function(target, name)
                {
                    FBTrace = getFBTrace();
                    return FBTrace ? FBTrace[name] : TraceObj[name];
                },

                set: function(target, name, value)
                {
                    if (FBTrace)
                        FBTrace[name] = value;
                    return true;
                },
            });
        }
    };
}

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

function getFBTrace()
{
    try
    {
        var scope = {};
        Cu.import("resource://fbtrace/firebug-trace-service.js", scope);
        return scope.traceConsoleService.getTracer("extensions.firebug");
    }
    catch (err)
    {
        //Cu.reportError(getStackDump());
        //Cu.reportError(msg);
    }
}

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

function getStackDump()
{
    var lines = [];
    for (var frame = Components.stack; frame; frame = frame.caller)
        lines.push(frame.filename + " (" + frame.lineNumber + ")");

    return lines.join("\n");
};
{'fraction_non_alphanumeric': 0.23830825538836925, 'fraction_numerical': 0.00040666937779585197, 'mean_word_length': 2.023355869698832, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '662296', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1159, 'n_words': 295}