Skip to content

Commit

Permalink
A better way to be compatible with web
Browse files Browse the repository at this point in the history
  • Loading branch information
dangfan committed Jan 19, 2024
1 parent 00fdb84 commit 2e6f64b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
4 changes: 1 addition & 3 deletions lib/src/utils/arg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 2 additions & 3 deletions lib/src/value/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2e6f64b

Please sign in to comment.