rem: if (!m_tb_wasinited) { torbutton_init(); }  
context: function torbutton_hookdoc(win, doc) {    if (!m_tb_wasinited) {        torbutton_init();    }    if(typeof(win.wrappedJSObject) == 'undefined') {        torbutton_log(3, "No JSObject: "+doc.location);        return;    }    torbutton_log(2, "Hooking document: "+doc.location);    if(doc.doctype) {        torbutton_log(2, "Type: "+doc.doctype.name);    }      var wm = Components.classes["@torproject.org/content-window-mapper;1"]        .getService(Components.interfaces.nsISupports)        .wrappedJSObject;       // Expire the cache on page loads. FIXME: Do a timer instead..     if(win == win.top) wm.expireOldCache();    var browser = wm.getBrowserForContentWindow(win.top);    if(!browser) win.alert("No window found!");    torbutton_log(2, "Got browser "+browser.contentDocument.location+" for: "             + doc.location);    var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");    var js_enabled = m_tb_prefs.getBoolPref("javascript.enabled");    var kill_plugins = m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins");    if (!torbutton_check_flag(win.top, "__tb_did_hook")) {        torbutton_log(2, "Tagging browser for: " + doc.location);        torbutton_set_flag(win.top, "__tb_did_hook");        browser.__tb_tor_fetched = !tor_tag;        browser.docShell.allowPlugins = tor_tag || !kill_plugins;        browser.docShell.allowJavascript = js_enabled;    }    torbutton_log(1, "JS set to: " + js_enabled);        if(!js_enabled) // XXX: bug #460 hack        win.wrappedJSObject.__tb_hooks_ran = true;     // No need to hook js if tor is off    if(!js_enabled             || !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")             || !m_tb_prefs.getBoolPref('extensions.torbutton.kill_bad_js')) {        torbutton_log(2, "Finished non-hook of: " + doc.location);        return;    }    // Date Hooking:    /* Q: Do this better with XPCOM?     *    http://www.mozilla.org/projects/xpcom/nsIClassInfo.html     * A: Negatory.. Date() is not an XPCOM component :(     */        // So it looks like the race condition is actually a result of    // the insertion function returning before the injected code is evaluated.    // This code seems to do what we want.    var str2 = "with(window) { window.__tb_set_uagent="+m_tb_prefs.getBoolPref('extensions.torbutton.set_uagent')+";\r\n";    str2 += "window.__tb_oscpu=\""+m_tb_prefs.getCharPref('extensions.torbutton.oscpu_override')+"\";\r\n";    str2 += "window.__tb_platform=\""+m_tb_prefs.getCharPref('extensions.torbutton.platform_override')+"\";\r\n";    str2 += "window.__tb_productSub=\""+m_tb_prefs.getCharPref('extensions.torbutton.productsub_override')+"\";\r\n";    str2 += m_tb_jshooks + "}";    try {        torbutton_log(2, "Tupe of window: " + typeof(win));        torbutton_log(2, "Type of wrapped window: " + typeof(win.wrappedJSObject));        var s = new Components.utils.Sandbox(win.wrappedJSObject);        s.window = win.wrappedJSObject;        var result = Components.utils.evalInSandbox(str2, s);        if(result === 23) { // secret confirmation result code.            torbutton_log(3, "Javascript hooks applied successfully at: " + doc.location);        } else if(result === 13) {            torbutton_log(3, "Double-hook at: " + doc.location);        } else {            win.alert("Sandbox evaluation failed. Date hooks not applied!");            torbutton_log(5, "Hook evaluation failure at " + doc.location);        }    } catch (e) {        win.alert("Exception in sandbox evaluation. Date hooks not applied:\n"+e);        torbutton_log(5, "Hook exception at: "+doc.location+", "+e);    }    torbutton_log(2, "Finished hook: " + doc.location);    return;}
meta: 3444	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/3444/c2513fa317a4be7f1fd1a468d779ff7ce73806d2/torbutton.js/clean/src/chrome/content/torbutton.js