WasmFeatures.fromJson constructor

WasmFeatures.fromJson(
  1. Object? json_
)

Returns a new instance from a JSON value. May throw if the value does not have the expected structure.

Implementation

factory WasmFeatures.fromJson(Object? json_) {
  final json = json_ is Map
      ? _spec.fields.map((f) => json_[f.label]).toList(growable: false)
      : json_;
  return switch (json) {
    [
      final mutableGlobal,
      final saturatingFloatToInt,
      final signExtension,
      final referenceTypes,
      final multiValue,
      final bulkMemory,
      final simd,
      final relaxedSimd,
      final threads,
      final tailCall,
      final floats,
      final multiMemory,
      final exceptions,
      final memory64,
      final extendedConst,
      final componentModel,
      final functionReferences,
      final memoryControl,
      final gc
    ] ||
    (
      final mutableGlobal,
      final saturatingFloatToInt,
      final signExtension,
      final referenceTypes,
      final multiValue,
      final bulkMemory,
      final simd,
      final relaxedSimd,
      final threads,
      final tailCall,
      final floats,
      final multiMemory,
      final exceptions,
      final memory64,
      final extendedConst,
      final componentModel,
      final functionReferences,
      final memoryControl,
      final gc
    ) =>
      WasmFeatures(
        mutableGlobal: mutableGlobal! as bool,
        saturatingFloatToInt: saturatingFloatToInt! as bool,
        signExtension: signExtension! as bool,
        referenceTypes: referenceTypes! as bool,
        multiValue: multiValue! as bool,
        bulkMemory: bulkMemory! as bool,
        simd: simd! as bool,
        relaxedSimd: relaxedSimd! as bool,
        threads: threads! as bool,
        tailCall: tailCall! as bool,
        floats: floats! as bool,
        multiMemory: multiMemory! as bool,
        exceptions: exceptions! as bool,
        memory64: memory64! as bool,
        extendedConst: extendedConst! as bool,
        componentModel: componentModel! as bool,
        functionReferences: functionReferences! as bool,
        memoryControl: memoryControl! as bool,
        gc: gc! as bool,
      ),
    _ => throw Exception('Invalid JSON $json_')
  };
}