Skip to content

Commit

Permalink
Fix GM_log (because XRay wrappers literally hate me!)
Browse files Browse the repository at this point in the history
Closes GH-258
  • Loading branch information
nmaier committed Oct 24, 2014
1 parent 7f7c7b1 commit 3fcb12c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions extension/modules/api/GM_console.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
var EXPORTED_SYMBOLS = ["GM_console"];
var EXPORTED_SYMBOLS = ["GM_console", "GM_getConsoleFor"];

const Cu = Components.utils;
Cu.import("resource://scriptish/logging.js");
Expand All @@ -15,7 +15,7 @@ const aux_functions = ["assert", "dir", "dirxml", "group", "groupEnd", "time",
"timeEnd", "count", "profile", "profileEnd"
];

function getConsoleFor(contentWindow, chromeWindow) {
function GM_getConsoleFor(contentWindow, chromeWindow) {
// we dont have a chromeWindow for e10s atm, see Scriptish_injectScripts impl
if (chromeWindow) {
let (rv = Scriptish_getFirebugConsole(contentWindow, chromeWindow)) {
Expand All @@ -33,7 +33,7 @@ function getConsoleFor(contentWindow, chromeWindow) {
}

function GM_console_legacy(script, contentWindow, chromeWindow) {
const _console = getConsoleFor(contentWindow, chromeWindow);
const _console = GM_getConsoleFor(contentWindow, chromeWindow);
const console = { __exposedProps__: {__noSuchMethod__: "r"} };
const prefix = "[" + (script.id || "Scriptish") + "]";

Expand Down Expand Up @@ -92,7 +92,7 @@ function GM_console(sandbox, script, contentWindow, chromeWindow) {
return GM_console_legacy(script, contentWindow, chromeWindow);
}

const _console = getConsoleFor(contentWindow, chromeWindow);
const _console = GM_getConsoleFor(contentWindow, chromeWindow);
const console = Cu.createObjectIn(sandbox, {defineAs: "console"});
const prefix = "[" + (script.id || "Scriptish") + "]";

Expand Down
7 changes: 4 additions & 3 deletions extension/modules/utils/Scriptish_injectScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Cu.import("resource://scriptish/api/GM_sandboxScripts.js");
lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log", "Scriptish_logError"]);
lazyImport(this, "resource://scriptish/prefmanager.js", ["Scriptish_prefRoot"]);
lazyImport(this, "resource://scriptish/api.js", ["GM_API"]);
lazyImport(this, "resource://scriptish/api/GM_console.js", ["GM_console"]);
lazyImport(this, "resource://scriptish/api/GM_console.js", ["GM_console", "GM_getConsoleFor"]);
lazyImport(this, "resource://scriptish/api/GM_ScriptLogger.js", ["GM_ScriptLogger"]);

lazyImport(this, "resource://scriptish/third-party/Scriptish_getBrowserForContentWindow.js", ["Scriptish_getBrowserForContentWindow"]);
Expand Down Expand Up @@ -93,15 +93,16 @@ function Scriptish_injectScripts(options) {

if (!useGrants || script.grant['GM_log']) {
lazy(sandbox, "GM_log", function() {
const _console = GM_getConsoleFor(safeWisafeWin, chromeWin);
if (Scriptish_prefRoot.getValue("logToErrorConsole")) {
let logger = new GM_ScriptLogger(script);
return function() {
const args = Array.slice(arguments);
logger.log(args.join(" "));
sandbox.console.log.apply(sandbox.console, args);
_console.log.apply(_console, args);
}
}
return sandbox.console.log.bind(sandbox.console);
return _console.log.bind(_console);
});
}

Expand Down

0 comments on commit 3fcb12c

Please sign in to comment.