toMap method
Implementation
Map<String, dynamic> toMap({bool deep = true}) {
final map = <String, dynamic>{};
try {
// Get the keys of the JSObject using dart:js_interop
final jsKeys = _objectKeys(this);
final keys =
jsKeys.toDart.map((jsString) => jsString.toDart).toList();
// Iterate over the keys and assign values to the Dart map
if (keys.isEmpty) {
return map;
}
for (final key in keys) {
try {
final value = this[key];
map[key] = UtilsJS.dartify(value, deep: deep);
} catch (e) {
// Skip problematic keys in WASM to prevent crashes
continue;
}
}
} catch (e) {
// WASM fallback - return empty map if conversion fails
return {};
}
return map;
}