<commit_before>// Copyright 2011 Google Inc. All Rights Reserved.
// Author: <EMAIL> (<NAME>)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * Return an array of stack frames representing the stack attached to the
 * supplied error object, or an empty array if there is no stack. The returned
 * array is in order from the top of the stack to the bottom.
 *
 * @param {!Error} error
 * @return {!Array.<!gjstest.internal.StackFrame>}
 *
 * @suppress {missingProperties}
 */
gjstest.internal.getErrorStack = function(error) {
  // Temporarily replace Error.prepareStackTrace with a function that returns
  // the structured stack trace instead of a formatted one. See here for more
  // info:
  //
  //     http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  //
  var originalPrepareStackTrace = Error.prepareStackTrace;

  Error.prepareStackTrace =
      function(error, structuredStack) {
        return structuredStack;
      };

  // Grab the structured stack, then replace the prepareStackTrace function.
  var structuredStack = error.stack;
  Error.prepareStackTrace = originalPrepareStackTrace;

  // Some errors, e.g. stack overflows, don't return a stack.
  if (!structuredStack) {
    return [];
  }

  // Convert each CallSite object. See the link above for documentation on
  // CallSite objects.
  var stackFrames = [];
  for (var i = 0; i < structuredStack.length; ++i) {
    var callSite = structuredStack[i];

    var stackFrame = new gjstest.internal.StackFrame;
    stackFrames.push(stackFrame);

    // Avoid storing file name and line number information for native code.
    if (callSite.isNative()) continue;

    // Pull info out of the call site.
    stackFrame.fileName = callSite.getFileName();
    stackFrame.lineNumber = callSite.getLineNumber();
  }

  return stackFrames;
};<commit_msg>Guard against the stack property of error object being a string.<commit_after>// Copyright 2011 Google Inc. All Rights Reserved.
// Author: <EMAIL> (<NAME>)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * Return an array of stack frames representing the stack attached to the
 * supplied error object, or an empty array if there is no stack. The returned
 * array is in order from the top of the stack to the bottom.
 *
 * @param {!Error} error
 * @return {!Array.<!gjstest.internal.StackFrame>}
 *
 * @suppress {missingProperties}
 */
gjstest.internal.getErrorStack = function(error) {
  // Temporarily replace Error.prepareStackTrace with a function that returns
  // the structured stack trace instead of a formatted one. See here for more
  // info:
  //
  //     http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  //
  var originalPrepareStackTrace = Error.prepareStackTrace;

  Error.prepareStackTrace =
      function(error, structuredStack) {
        return structuredStack;
      };

  // Grab the structured stack, then replace the prepareStackTrace function.
  var structuredStack = error.stack;
  Error.prepareStackTrace = originalPrepareStackTrace;

  // Some errors, e.g. stack overflows, don't return a stack. Some browsers
  // always supply the stack property as a string, without calling the
  // Error.prepareStackTrace installed above.
  if (!structuredStack || typeof structuredStack == 'string') {
    return [];
  }

  // Convert each CallSite object. See the link above for documentation on
  // CallSite objects.
  var stackFrames = [];
  for (var i = 0; i < structuredStack.length; ++i) {
    var callSite = structuredStack[i];

    var stackFrame = new gjstest.internal.StackFrame;
    stackFrames.push(stackFrame);

    // Avoid storing file name and line number information for native code.
    if (callSite.isNative()) continue;

    // Pull info out of the call site.
    stackFrame.fileName = callSite.getFileName();
    stackFrame.lineNumber = callSite.getLineNumber();
  }

  return stackFrames;
};
{'fraction_non_alphanumeric': 0.09477124183006536, 'fraction_numerical': 0.004084967320261438, 'mean_word_length': 3.3919282511210764, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4804035', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1272, 'n_words': 531}