<commit_before>FBL.ns(function () {
  // Adapted from UseInCommandLine from the base Firebug source.
  var InspectKnockoutContext = FBL.extend(Firebug.Module, {
    dispatchName: "InspectKnockoutContext",

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Extends Module

    initialize: function () {
      Firebug.Module.initialize.apply(this, arguments);

      Firebug.registerUIListener(this);
    },

    shutdown: function () {
      Module.shutdown.apply(this, arguments);

      Firebug.unregisterUIListener(this);
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // UI Listener

    onContextMenu: function (items, object, target, context, panel, popup) {
      if (typeof object === "boolean" || object === undefined || object === null) {
        return;
      }

      var rep = Firebug.getRep(object, context);
      if (!rep || !rep.inspectable) {
        return;
      }

      // This was adapted from UseInCommandLine from the base Firebug source. The proceeding two checks may not be
      // needed.
      var realObject = rep.getRealObject(object, context);
      if (!FBL.isElement(realObject)) {
        return;
      }

      var window;
      var knockout;
      // REVIEW: Calling the function `contextFor` accessed via the `window.wrappedJSObject` property appears to be safe, but more investigation would be optimal.
      var knockoutContext = (window = context.window) && (knockout = window.wrappedJSObject.ko) && knockout.contextFor(object);
      if (!knockoutContext) {
        return;
      }

      FBL.createMenuSeparator(popup);

      FBL.createMenuItem(popup, {
        label: "Inspect Knockout context",
        tooltiptext: "Open the Knockout context for the current element in the DOM panel",
        command: this.inspectKnockoutContext.bind(this, knockoutContext)
      });
<commit_msg>Additional checking on availability of `contextFor`.<commit_after>FBL.ns(function () {
  /**
   *
   * @todo REVIEW: Calling the function `contextFor` accessed via the `window.wrappedJSObject` property appears to be safe, but more investigation would be optimal.
   *
   * @private
   *
   * @param context
   * @param object
   * @returns {Knockout.Context}
   */
  function getKnockoutContext(context, object) {
    var window;
    var knockout;
    var knockoutContextForFunction;

    knockoutContextForFunction = (window = context.window) && (knockout = window.wrappedJSObject.ko) && knockout.contextFor;

    if (knockoutContextForFunction && FBL.isFunction(knockoutContextForFunction)) {
      return knockoutContextForFunction(object);
    } else {
      return null;
    }
  }

  // Adapted from UseInCommandLine from the base Firebug source.
  var InspectKnockoutContext = FBL.extend(Firebug.Module, {
    dispatchName: "InspectKnockoutContext",

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Extends Module

    initialize: function () {
      Firebug.Module.initialize.apply(this, arguments);

      Firebug.registerUIListener(this);
    },

    shutdown: function () {
      Module.shutdown.apply(this, arguments);

      Firebug.unregisterUIListener(this);
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // UI Listener

    onContextMenu: function (items, object, target, context, panel, popup) {
      if (typeof object === "boolean" || object === undefined || object === null) {
        return;
      }

      var rep = Firebug.getRep(object, context);
      if (!rep || !rep.inspectable) {
        return;
      }

      // This was adapted from UseInCommandLine from the base Firebug source. The proceeding two checks may not be
      // needed.
      var realObject = rep.getRealObject(object, context);
      if (!FBL.isElement(realObject)) {
        return;
      }

      var knockoutContext = getKnockoutContext(context, object);
      if (!knockoutContext) {
        return;
      }

      FBL.createMenuSeparator(popup);

      FBL.createMenuItem(popup, {
        label: "Inspect Knockout context",
        tooltiptext: "Open the Knockout context for the current element in the DOM panel",
        command: this.inspectKnockoutContext.bind(this, knockoutContext)
      });

{'fraction_non_alphanumeric': 0.1399496912874457, 'fraction_numerical': 0.0, 'mean_word_length': 2.533117932148627, '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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '219381', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1300, 'n_words': 297}