From 2e6f64b5a297033d565d15365052ce701aced6b2 Mon Sep 17 00:00:00 2001 From: Fan DANG Date: Fri, 19 Jan 2024 22:02:12 +0800 Subject: [PATCH] A better way to be compatible with web --- lib/src/utils/arg.dart | 4 +--- lib/src/utils/utils.dart | 6 ------ lib/src/value/value.dart | 5 ++--- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/src/utils/arg.dart b/lib/src/utils/arg.dart index 67159c0..7e1b303 100644 --- a/lib/src/utils/arg.dart +++ b/lib/src/utils/arg.dart @@ -5,8 +5,6 @@ * Copyright : S.Hamblett */ -import 'utils.dart'; - /// The information encoded by additional Arg and the following bytes. abstract class Arg { const factory Arg.int(int arg) = _ArgInt; @@ -47,7 +45,7 @@ class _ArgInt implements Arg { final int value; @override - _ArgInt operator ~() => _ArgInt(kIsWeb ? -value - 1 : ~value); + _ArgInt operator ~() => _ArgInt((~value).toSigned(32)); @override final bool isIndefiniteLength = false; diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index e20ca26..598d351 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -137,9 +137,3 @@ bool isExpectConversion(int tag) { return false; } - -const bool kIsWeb = identical(0, 0.0); - -bool isWebDouble(Object a) { - return a is double && a.toInt() == a; -} diff --git a/lib/src/value/value.dart b/lib/src/value/value.dart index d5a4d21..5d68af5 100644 --- a/lib/src/value/value.dart +++ b/lib/src/value/value.dart @@ -8,7 +8,6 @@ import 'dart:typed_data'; import 'package:cbor/cbor.dart'; -import 'package:cbor/src/utils/utils.dart'; import 'package:meta/meta.dart'; import '../encoder/sink.dart'; @@ -62,12 +61,12 @@ abstract class CborValue { return CborNull(); } else if (object is CborValue) { return object; - } else if (object is double && (!kIsWeb || kIsWeb && isWebDouble(object))) { - return CborFloat(object); } else if (object is int) { return CborSmallInt(object); } else if (object is BigInt) { return CborInt(object); + } else if (object is double) { + return CborFloat(object); } else if (object is bool) { return CborBool(object); } else if (object is Uint8List) {