<commit_before>var EXPORTED_SYMBOLS = [
    'MenuCommandListRequest', 'MenuCommandRespond',
    'MenuCommandRun', 'MenuCommandSandbox',
    ];


var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;


// Frame scope: Pass "list menu commands" message into sandbox as event.
function MenuCommandListRequest(aContent, aMessage) {
  var e = new aContent.CustomEvent(
      'greasemonkey-menu-command-list', {'detail': aMessage.data.cookie});
  aContent.dispatchEvent(e);
}


// Callback from script scope, pass "list menu commands" response up to
// parent process as a message.
function MenuCommandRespond(aCookie, aData) {
  var cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
      .getService(Ci.nsIMessageSender);
  cpmm.sendAsyncMessage(
      'greasemonkey:menu-command-response',
      {'commands': aData, 'cookie': aCookie});
}


// Frame scope: Respond to the "run this menu command" message coming
// from the parent, pass it into the sandbox.
function MenuCommandRun(aContent, aMessage) {
  var e = new aContent.CustomEvent(
      'greasemonkey-menu-command-run',
      {'detail': JSON.stringify(aMessage.data)});
  aContent.dispatchEvent(e);
}


// This function is injected into the sandbox, in a private scope wrapper, BY
// SOURCE.  Data and sensitive references are wrapped up inside its closure.
function MenuCommandSandbox(
    aScriptUuid, aScriptName, aCommandResponder, aInvalidAccesskeyErrorStr) {
  // 1) Internally to this function's private scope, maintain a set of
  // registered menu commands.
  var commands = {};
  var commandCookie = 0;
  // 2) Respond to requests to list those registered commands.
  addEventListener('greasemonkey-menu-command-list', function(e) {
    aCommandResponder(e.detail, commands);
  }, true);
  // 3) Respond to requests to run those registered commands.
  addEventListener('greasemonkey-menu-command-run', function(e) {
    var detail = JSON.parse(e.detail);
    if (aScriptUuid != detail.scriptUuid) return;
    var command = commands[detail.cookie];
    if (!command) {
      throw new Error('Could not run requested menu command!');
    } else {
      command.commandFunc();
    }
  }, true);
  // 4) Export the "register a command" API function to the sandbox scope.
  this.GM_registerMenuCommand = function(
      commandName, commandFunc, accessKey, unused, accessKey2) {
    // Legacy support: if all five parameters were specified, (from when two<commit_msg>Call menu command functions with undefined `this`.<commit_after>var EXPORTED_SYMBOLS = [
    'MenuCommandListRequest', 'MenuCommandRespond',
    'MenuCommandRun', 'MenuCommandSandbox',
    ];


var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;


// Frame scope: Pass "list menu commands" message into sandbox as event.
function MenuCommandListRequest(aContent, aMessage) {
  var e = new aContent.CustomEvent(
      'greasemonkey-menu-command-list', {'detail': aMessage.data.cookie});
  aContent.dispatchEvent(e);
}


// Callback from script scope, pass "list menu commands" response up to
// parent process as a message.
function MenuCommandRespond(aCookie, aData) {
  var cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
      .getService(Ci.nsIMessageSender);
  cpmm.sendAsyncMessage(
      'greasemonkey:menu-command-response',
      {'commands': aData, 'cookie': aCookie});
}


// Frame scope: Respond to the "run this menu command" message coming
// from the parent, pass it into the sandbox.
function MenuCommandRun(aContent, aMessage) {
  var e = new aContent.CustomEvent(
      'greasemonkey-menu-command-run',
      {'detail': JSON.stringify(aMessage.data)});
  aContent.dispatchEvent(e);
}


// This function is injected into the sandbox, in a private scope wrapper, BY
// SOURCE.  Data and sensitive references are wrapped up inside its closure.
function MenuCommandSandbox(
    aScriptUuid, aScriptName, aCommandResponder, aInvalidAccesskeyErrorStr) {
  // 1) Internally to this function's private scope, maintain a set of
  // registered menu commands.
  var commands = {};
  var commandCookie = 0;
  // 2) Respond to requests to list those registered commands.
  addEventListener('greasemonkey-menu-command-list', function(e) {
    aCommandResponder(e.detail, commands);
  }, true);
  // 3) Respond to requests to run those registered commands.
  addEventListener('greasemonkey-menu-command-run', function(e) {
    var detail = JSON.parse(e.detail);
    if (aScriptUuid != detail.scriptUuid) return;
    var command = commands[detail.cookie];
    if (!command) {
      throw new Error('Could not run requested menu command!');
    } else {
      command.commandFunc.call();
    }
  }, true);
  // 4) Export the "register a command" API function to the sandbox scope.
  this.GM_registerMenuCommand = function(
      commandName, commandFunc, accessKey, unused, accessKey2) {
    // Legacy support: if all five parameters were specified, (from when two
{'fraction_non_alphanumeric': 0.10856453558504221, 'fraction_numerical': 0.0028146361077603537, 'mean_word_length': 4.050761421319797, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2845460', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1426, 'n_words': 451}