registerGlobalVariables static method

void registerGlobalVariables(
  1. D4rt interpreter,
  2. String importPath, {
  3. bool include(
    1. String? sourceUri
    )?,
})

Registers all global variables with the interpreter.

importPath is the package import path for library-scoped registration. Collects all registration errors and throws a single exception with all error details if any registrations fail.

Implementation

static void registerGlobalVariables(
  D4rt interpreter,
  String importPath, {
  bool Function(String? sourceUri)? include,
}) {
  final errors = <String>[];

  if (include == null ||
      include('package:tom_dcli_exec/src/api/cli_bridge.dart')) {
    try {
      interpreter.registerGlobalVariable(
        'cliLibrary',
        $tom_dcli_exec_2.cliLibrary,
        importPath,
        sourceUri: 'package:tom_dcli_exec/src/api/cli_bridge.dart',
      );
    } catch (e) {
      errors.add('Failed to register variable "cliLibrary": $e');
    }
  }
  if (include == null ||
      include('package:tom_dcli_exec/src/api/cli_bridge.dart')) {
    try {
      interpreter.registerGlobalVariable(
        'cliGlobalHolder',
        $tom_dcli_exec_2.cliGlobalHolder,
        importPath,
        sourceUri: 'package:tom_dcli_exec/src/api/cli_bridge.dart',
      );
    } catch (e) {
      errors.add('Failed to register variable "cliGlobalHolder": $e');
    }
  }
  if (include == null ||
      include('package:tom_dcli_exec/src/api/cli_test_utils.dart')) {
    interpreter.registerGlobalGetter(
      'verificationFailures',
      () => $tom_dcli_exec_8.verificationFailures,
      importPath,
      sourceUri: 'package:tom_dcli_exec/src/api/cli_test_utils.dart',
    );
  }

  if (errors.isNotEmpty) {
    throw StateError(
      'Bridge registration errors (cli_api):\n${errors.join("\n")}',
    );
  }
}