<commit_before>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import type {Lane, Lanes} from './ReactFiberLane.old';
import type {Fiber} from './ReactInternalTypes';
import type {Wakeable} from 'shared/ReactTypes';

import {
  enableNewReconciler,
  enableSchedulingProfiler,
} from 'shared/ReactFeatureFlags';
import ReactVersion from 'shared/ReactVersion';
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
import {SCHEDULING_PROFILER_VERSION} from 'react-devtools-timeline/src/constants';

import {
  getLabelForLane as getLabelForLane_old,
  TotalLanes as TotalLanes_old,
} from 'react-reconciler/src/ReactFiberLane.old';
import {
  getLabelForLane as getLabelForLane_new,
  TotalLanes as TotalLanes_new,
} from 'react-reconciler/src/ReactFiberLane.new';

const getLabelForLane = enableNewReconciler
  ? getLabelForLane_new
  : getLabelForLane_old;

const TotalLanes = enableNewReconciler ? TotalLanes_new : TotalLanes_old;

/**
 * If performance exists and supports the subset of the User Timing API that we
 * require.
 */
const supportsUserTiming =
  typeof performance !== 'undefined' &&
  typeof performance.mark === 'function' &&
  typeof performance.clearMarks === 'function';

let supportsUserTimingV3 = false;
if (enableSchedulingProfiler) {
  if (supportsUserTiming) {
    const CHECK_V3_MARK = '__v3';
    const markOptions = {};
    // $FlowFixMe: Ignore Flow complaining about needing a value
    Object.defineProperty(markOptions, 'startTime', {
      get: function() {
        supportsUserTimingV3 = true;
        return 0;
      },
      set: function() {},
    });

    try {
      // $FlowFixMe: Flow expects the User Timing level 2 API.
      performance.mark(CHECK_V3_MARK, markOptions);
    } catch (error) {
      // Ignore
    } finally {
      performance.clearMarks(CHECK_V3_MARK);
    }
  }
}

const laneLabels: Array<string> = [];

export function getLaneLabels(): Array<string> {
  if (laneLabels.length === 0) {
    let lane = 1;
    for (let index = 0; index < TotalLanes; index++) {
      laneLabels.push(((getLabelForLane(lane): any): string));

      lane *= 2;
    }
  }
  return laneLabels;
}

function markLaneToLabelMetadata() {
  getLaneLabels();

  markAndClear(`--react-lane-labels-${laneLabels.join(',')}`);
}

function markAndClear(name) {
  performance.mark(name);
  performance.clearMarks(name);
}

function markVersionMetadata() {
  markAndClear(`--react-version-${ReactVersion}`);
  markAndClear(`--profiler-version-${SCHEDULING_PROFILER_VERSION}`);
}

function markInternalModuleRanges() {
  /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  if (
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.getInternalModuleRanges === 'function'
  ) {
    const ranges = __REACT_DEVTOOLS_GLOBAL_HOOK__.getInternalModuleRanges();
    for (let i = 0; i < ranges.length; i++) {
      const [startStackFrame, stopStackFrame] = ranges[i];

      markAndClear(`--react-internal-module-start-${startStackFrame}`);
      markAndClear(`--react-internal-module-stop-${stopStackFrame}`);<commit_msg>Add runtime type checks around module boundary code (#22748)<commit_after>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import type {Lane, Lanes} from './ReactFiberLane.old';
import type {Fiber} from './ReactInternalTypes';
import type {Wakeable} from 'shared/ReactTypes';

import {
  enableNewReconciler,
  enableSchedulingProfiler,
} from 'shared/ReactFeatureFlags';
import ReactVersion from 'shared/ReactVersion';
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
import {SCHEDULING_PROFILER_VERSION} from 'react-devtools-timeline/src/constants';
import isArray from 'shared/isArray';

import {
  getLabelForLane as getLabelForLane_old,
  TotalLanes as TotalLanes_old,
} from 'react-reconciler/src/ReactFiberLane.old';
import {
  getLabelForLane as getLabelForLane_new,
  TotalLanes as TotalLanes_new,
} from 'react-reconciler/src/ReactFiberLane.new';

const getLabelForLane = enableNewReconciler
  ? getLabelForLane_new
  : getLabelForLane_old;

const TotalLanes = enableNewReconciler ? TotalLanes_new : TotalLanes_old;

/**
 * If performance exists and supports the subset of the User Timing API that we
 * require.
 */
const supportsUserTiming =
  typeof performance !== 'undefined' &&
  typeof performance.mark === 'function' &&
  typeof performance.clearMarks === 'function';

let supportsUserTimingV3 = false;
if (enableSchedulingProfiler) {
  if (supportsUserTiming) {
    const CHECK_V3_MARK = '__v3';
    const markOptions = {};
    // $FlowFixMe: Ignore Flow complaining about needing a value
    Object.defineProperty(markOptions, 'startTime', {
      get: function() {
        supportsUserTimingV3 = true;
        return 0;
      },
      set: function() {},
    });

    try {
      // $FlowFixMe: Flow expects the User Timing level 2 API.
      performance.mark(CHECK_V3_MARK, markOptions);
    } catch (error) {
      // Ignore
    } finally {
      performance.clearMarks(CHECK_V3_MARK);
    }
  }
}

const laneLabels: Array<string> = [];

export function getLaneLabels(): Array<string> {
  if (laneLabels.length === 0) {
    let lane = 1;
    for (let index = 0; index < TotalLanes; index++) {
      laneLabels.push(((getLabelForLane(lane): any): string));

      lane *= 2;
    }
  }
  return laneLabels;
}

function markLaneToLabelMetadata() {
  getLaneLabels();

  markAndClear(`--react-lane-labels-${laneLabels.join(',')}`);
}

function markAndClear(name) {
  performance.mark(name);
  performance.clearMarks(name);
}

function markVersionMetadata() {
  markAndClear(`--react-version-${ReactVersion}`);
  markAndClear(`--profiler-version-${SCHEDULING_PROFILER_VERSION}`);
}

function markInternalModuleRanges() {
  /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  if (
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.getInternalModuleRanges === 'function'
  ) {
    const ranges = __REACT_DEVTOOLS_GLOBAL_HOOK__.getInternalModuleRanges();
    // This check would not be required,
    // except that it's possible for things to override __REACT_DEVTOOLS_GLOBAL_HOOK__.
    if (isArray(ranges)) {
      for (let i = 0; i < ranges.length; i++) {
        const range = ranges[i];
        if (isArray(range) && range.length === 2) {
          const [startStackFrame, stopStackFrame] = ranges[i];

          markAndClear(`--react-internal-module-start-${startStackFrame}`);
          markAndClear(`--react-internal-module-stop-${stopStackFrame}`);
        }
      }
{'fraction_non_alphanumeric': 0.11855072463768115, 'fraction_numerical': 0.00463768115942029, 'mean_word_length': 4.100517368810052, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6810381', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2240, 'n_words': 497}