jsify method
Converts a Dart JSON-like object to the JavaScript equivalent if possible.
Effectively the inverse of JSAnyUtilityExtension.dartify, jsify takes a Dart JSON-like object and recursively converts it to a JavaScript value, doing the following:
- If the object is a JS value, returns the object.
- If the object is a Dart primitive type,
null
, or adart:typed_data
type, does the equivalenttoJS
operation if it exists and returns the result. - If the object is a Map, creates and returns a new JS object whose properties and associated values are the recursively converted keys and values of the Map.
- If the object is an Iterable, each item in it is recursively converted
and pushed into a new JS
Array
which is then returned. - Otherwise, the conversion is undefined.
If the object contains a cycle, the behavior is undefined.
Note
Prefer using the specific conversion method like toJS
if you know the
Dart type as this method may perform many type-checks. You should
generally call this method with objects that only contain JSON-like
values as the conversion may be platform- and compiler-specific
otherwise.
Implementation
// TODO(srujzs): We likely need stronger tests for this method to ensure
// consistency. We should also limit the accepted types in this API to avoid
// confusion. Once the conversion for unrelated types is consistent across all
// backends, we can update the documentation to say that the object is
// externalized instead of the conversion being undefined.
external JSAny? jsify();