<commit_before>// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of dart._runtime;

// We need to set these properties while the sdk is only partially initialized
// so we cannot use regular Dart fields.
// The default values for these properties are set when the global_ final field
// in runtime.dart is initialized.

argumentError(value) {
  throw ArgumentError.value(value);
}

throwUnimplementedError(String message) {
  throw UnimplementedError(message);
}

// TODO(nshahan) Cleanup embeded strings and extract file location at runtime
// from the stacktrace.
assertFailed(String? message,
    [String? fileUri, int? line, int? column, String? conditionSource]) {
  throw AssertionErrorImpl(message, fileUri, line, column, conditionSource);
}

final _nullFailedSet = JS('!', 'new Set()');
// Run-time null safety assertion per:
// https://github.com/dart-lang/language/blob/master/accepted/future-releases/nnbd/feature-specification.md#automatic-debug-assertion-insertion
nullFailed(String? fileUri, int? line, int? column, String? variable) {
  if (_strictSubtypeChecks) {
    throw AssertionErrorImpl(
        'A null value was passed into a non-nullable parameter $variable',
        fileUri,
        line,
        column,
        '$variable != null');
  } else {
    var key = '$fileUri:$line:$column';
    if (!JS('!', '#.has(#)', _nullFailedSet, key)) {
      JS('', '#.add(#)', _nullFailedSet, key);
      _nullWarn(
          'A null value was passed into a non-nullable parameter $variable');
    }
  }
}

throwCyclicInitializationError([String? field]) {
  throw CyclicInitializationError(field);
}

throwNullValueError() {
  // TODO(vsm): Per spec, we should throw an NSM here.  Technically, we ought
  // to thread through method info, but that uglifies the code and can't
  // actually be queried ... it only affects how the error is printed.
  throw NoSuchMethodError(null, Symbol('<Unexpected Null Value>'), null, null);
}

castError(obj, expectedType) {
  var actualType = getReifiedType(obj);
  var message = _castErrorMessage(actualType, expectedType);
  throw TypeErrorImpl(message);
}

String _castErrorMessage(from, to) {
  // If both types are generic classes, see if we can infer generic type
  // arguments for `from` that would allow the subtype relation to work.
  var fromClass = getGenericClass(from);
  if (fromClass != null) {
    var fromTypeFormals = getGenericTypeFormals(fromClass);
    var fromType = instantiateClass(fromClass, fromTypeFormals);
    var inferrer = _TypeInferrer(fromTypeFormals);
    if (inferrer.trySubtypeMatch(fromType, to)) {
      var inferredTypes = inferrer.getInferredTypes();
      if (inferredTypes != null) {
        var inferred = instantiateClass(fromClass, inferredTypes);
        return "Type '${typeName(from)}' should be '${typeName(inferred)}' "
            "to implement expected type '${typeName(to)}'.";
      }
    }
  }
  return "Expected a value of type '${typeName(to)}', "
      "but got one of type '${typeName(from)}'";
}

/// The symbol that references the thrown Dart Object (typically but not
/// necessarily an [Error] or [Exception]), used by the [exception] function.
final Object _thrownValue = JS('', 'Symbol("_thrownValue")');

/// For a Dart [Error], this provides access to the JS Error object that
/// contains the stack trace if the error was thrown.
final Object _jsError = JS('', 'Symbol("_jsError")');

/// Gets the thrown Dart Object from an [error] caught by a JS catch.
///<commit_msg>[ddc] Disable type check failure suggestions<commit_after>// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of dart._runtime;

// We need to set these properties while the sdk is only partially initialized
// so we cannot use regular Dart fields.
// The default values for these properties are set when the global_ final field
// in runtime.dart is initialized.

argumentError(value) {
  throw ArgumentError.value(value);
}

throwUnimplementedError(String message) {
  throw UnimplementedError(message);
}

// TODO(nshahan) Cleanup embeded strings and extract file location at runtime
// from the stacktrace.
assertFailed(String? message,
    [String? fileUri, int? line, int? column, String? conditionSource]) {
  throw AssertionErrorImpl(message, fileUri, line, column, conditionSource);
}

final _nullFailedSet = JS('!', 'new Set()');
// Run-time null safety assertion per:
// https://github.com/dart-lang/language/blob/master/accepted/future-releases/nnbd/feature-specification.md#automatic-debug-assertion-insertion
nullFailed(String? fileUri, int? line, int? column, String? variable) {
  if (_strictSubtypeChecks) {
    throw AssertionErrorImpl(
        'A null value was passed into a non-nullable parameter $variable',
        fileUri,
        line,
        column,
        '$variable != null');
  } else {
    var key = '$fileUri:$line:$column';
    if (!JS('!', '#.has(#)', _nullFailedSet, key)) {
      JS('', '#.add(#)', _nullFailedSet, key);
      _nullWarn(
          'A null value was passed into a non-nullable parameter $variable');
    }
  }
}

throwCyclicInitializationError([String? field]) {
  throw CyclicInitializationError(field);
}

throwNullValueError() {
  // TODO(vsm): Per spec, we should throw an NSM here.  Technically, we ought
  // to thread through method info, but that uglifies the code and can't
  // actually be queried ... it only affects how the error is printed.
  throw NoSuchMethodError(null, Symbol('<Unexpected Null Value>'), null, null);
}

castError(obj, expectedType) {
  var actualType = getReifiedType(obj);
  var message = _castErrorMessage(actualType, expectedType);
  throw TypeErrorImpl(message);
}

String _castErrorMessage(from, to) {
  // If both types are generic classes, see if we can infer generic type
  // arguments for `from` that would allow the subtype relation to work.
  // TODO(#40326) Fix suggested type or remove this code if no longer needed.
  // var fromClass = getGenericClass(from);
  // if (fromClass != null) {
  //   var fromTypeFormals = getGenericTypeFormals(fromClass);
  //   var fromType = instantiateClass(fromClass, fromTypeFormals);
  //   var inferrer = _TypeInferrer(fromTypeFormals);
  //   if (inferrer.trySubtypeMatch(fromType, to)) {
  //     var inferredTypes = inferrer.getInferredTypes();
  //     if (inferredTypes != null) {
  //       var inferred = instantiateClass(fromClass, inferredTypes);
  //       return "Type '${typeName(from)}' should be '${typeName(inferred)}' "
  //           "to implement expected type '${typeName(to)}'.";
  //     }
  //   }
  // }
  return "Expected a value of type '${typeName(to)}', "
      "but got one of type '${typeName(from)}'";
}

/// The symbol that references the thrown Dart Object (typically but not
/// necessarily an [Error] or [Exception]), used by the [exception] function.
final Object _thrownValue = JS('', 'Symbol("_thrownValue")');

/// For a Dart [Error], this provides access to the JS Error object that
/// contains the stack trace if the error was thrown.
final Object _jsError = JS('', 'Symbol("_jsError")');

/// Gets the thrown Dart Object from an [error] caught by a JS catch.
///
{'fraction_non_alphanumeric': 0.11849672328473987, 'fraction_numerical': 0.0017386652400695466, 'mean_word_length': 3.7752234993614304, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5108056', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2137, 'n_words': 777}