registerGlobalVariables static method
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) {
final errors = <String>[];
try {
interpreter.registerGlobalVariable(
'posix',
$path_1.posix,
importPath,
sourceUri: 'package:path/path.dart',
);
} catch (e) {
errors.add('Failed to register variable "posix": $e');
}
try {
interpreter.registerGlobalVariable(
'windows',
$path_1.windows,
importPath,
sourceUri: 'package:path/path.dart',
);
} catch (e) {
errors.add('Failed to register variable "windows": $e');
}
try {
interpreter.registerGlobalVariable(
'url',
$path_1.url,
importPath,
sourceUri: 'package:path/path.dart',
);
} catch (e) {
errors.add('Failed to register variable "url": $e');
}
try {
interpreter.registerGlobalVariable(
'context',
$path_1.context,
importPath,
sourceUri: 'package:path/path.dart',
);
} catch (e) {
errors.add('Failed to register variable "context": $e');
}
interpreter.registerGlobalGetter(
'style',
() => $path_1.style,
importPath,
sourceUri: 'package:path/path.dart',
);
interpreter.registerGlobalGetter(
'current',
() => $path_1.current,
importPath,
sourceUri: 'package:path/path.dart',
);
interpreter.registerGlobalGetter(
'separator',
() => $path_1.separator,
importPath,
sourceUri: 'package:path/path.dart',
);
if (errors.isNotEmpty) {
throw StateError(
'Bridge registration errors (path):\n${errors.join("\n")}',
);
}
}