<commit_before>"use strict";

const path = require("path");
const SemVer = require("semver");
const FastObject = require("../lib/fast-object.js");
const isObject = require("../lib/utils.js").isObject;
const utils = require("./utils.js");
const reifySemVer = utils.getReifySemVer();
const reifyVersion = reifySemVer.version;
const hasOwn = Object.prototype.hasOwnProperty;

function getSymbolForKey(key) {
  return Symbol.for("reifyWrapperMap$" + key);
}

function addWrapper(object, key, wrapper) {
  const map = ensureWrapperMap(object, key);
  if (typeof map.wrappers[reifyVersion] !== "function") {
    map.versions.push(reifyVersion);
    map.wrappers[reifyVersion] = wrapper;
  }
}

exports.addWrapper = addWrapper;

function ensureWrapperMap(object, key) {
  let map = getWrapperMap(object, key);
  if (map === null) {
    const func = object[key];
    map = createWrapperMap(func);

    object[key] = function (param, filename) {
      const pkgInfo = utils.getPkgInfo(path.dirname(filename));
      const wrapper = pkgInfo === null ? null :
        findWrapper(object, key, pkgInfo.range);

      // A wrapper should only be null for reify < 0.10.
      return wrapper === null
        ? func.call(this, param, filename)
        : wrapper.call(this, func, pkgInfo, param, filename);
    };

    // Store the wrapper map on the object rather than on the function so
    // that other code can modify the same property without interfering
    // with our wrapper logic.
    object[getSymbolForKey(key)] = map;
  }

  return map;
}

exports.ensureWrapperMap = ensureWrapperMap;

function getWrapperMap(object, key) {
  const symbol = getSymbolForKey(key);
  if (hasOwn.call(object, symbol)) {
    const map = object[symbol];
    if (isObject(map)) {
      return map;
    }
  }
  return null;
}

function createWrapperMap(func) {
  const map = new FastObject;<commit_msg>Use only one Symbol for storing wrapper maps.<commit_after>"use strict";

const path = require("path");
const SemVer = require("semver");
const FastObject = require("../lib/fast-object.js");
const isObject = require("../lib/utils.js").isObject;
const utils = require("./utils.js");
const reifySemVer = utils.getReifySemVer();
const reifyVersion = reifySemVer.version;
const hasOwn = Object.prototype.hasOwnProperty;
const reifySymbol = Symbol.for("__reify");

function addWrapper(object, key, wrapper) {
  const map = ensureWrapperMap(object, key);
  if (typeof map.wrappers[reifyVersion] !== "function") {
    map.versions.push(reifyVersion);
    map.wrappers[reifyVersion] = wrapper;
  }
}

exports.addWrapper = addWrapper;

function ensureWrapperMap(object, key) {
  let map = getWrapperMap(object, key);
  if (map === null) {
    const func = object[key];
    map = createWrapperMap(func);

    object[key] = function (param, filename) {
      const pkgInfo = utils.getPkgInfo(path.dirname(filename));
      const wrapper = pkgInfo === null ? null :
        findWrapper(object, key, pkgInfo.range);

      // A wrapper should only be null for reify < 0.10.
      return wrapper === null
        ? func.call(this, param, filename)
        : wrapper.call(this, func, pkgInfo, param, filename);
    };

    const mapsByKey = hasOwn.call(object, reifySymbol)
      ? object[reifySymbol]
      : object[reifySymbol] = new FastObject;

    // Store the wrapper map as object[reifySymbol][key] rather than on
    // the function, so that other code can modify the same property
    // without interfering with our wrapper logic.
    mapsByKey[key] = map;
  }

  return map;
}

exports.ensureWrapperMap = ensureWrapperMap;

function getWrapperMap(object, key) {
  if (hasOwn.call(object, reifySymbol)) {
    const mapsByKey = object[reifySymbol];
    if (hasOwn.call(mapsByKey, key)) {
      const map = mapsByKey[key];
      if (isObject(map)) {
        return map;
      }
    }
  }

  return null;
}

function createWrapperMap(func) {
  const map = new FastObject;
{'fraction_non_alphanumeric': 0.12642802741812642, 'fraction_numerical': 0.0015232292460015233, 'mean_word_length': 3.6462264150943398, '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': '3464441', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1202, 'n_words': 324}