Runtime.deserialize constructor

Runtime.deserialize(
  1. Object serialized
)

Converts a JSON-safe representation generated by serialize back into a Runtime.

Implementation

factory Runtime.deserialize(Object serialized) {
  if (serialized is String) {
    return builtIn
        .firstWhere((platform) => platform.identifier == serialized);
  }

  var map = serialized as Map;
  var name = map['name'] as String;
  var identifier = map['identifier'] as String;
  var defaultCompiler =
      Compiler.deserialize(map['defaultCompiler'] as Object);
  var supportedCompilers = [
    for (var compiler in map['supportedCompilers'] as List)
      Compiler.deserialize(compiler as Object),
  ];

  var parent = map['parent'];
  if (parent != null) {
    // Note that the returned platform's [parent] won't necessarily be `==` to
    // a separately-deserialized parent platform. This should be fine, though,
    // since we only deserialize platforms in the remote execution context
    // where they're only used to evaluate platform selectors.
    return Runtime._child(name, identifier, defaultCompiler,
        supportedCompilers, Runtime.deserialize(parent as Object));
  }

  return Runtime(name, identifier, defaultCompiler, supportedCompilers,
      isDartVM: map['isDartVM'] as bool,
      isBrowser: map['isBrowser'] as bool,
      isBlink: map['isBlink'] as bool,
      isHeadless: map['isHeadless'] as bool);
}