diff --git a/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/primitive_list.rs b/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/primitive_list.rs index de3c2932a3..f5adb4ff9b 100644 --- a/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/primitive_list.rs +++ b/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/primitive_list.rs @@ -6,8 +6,8 @@ use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; impl<'a> WireDartCodecDcoGeneratorDecoderTrait for PrimitiveListWireDartCodecDcoGenerator<'a> { fn generate_impl_decode_body(&self) -> String { match &self.mir.primitive { - MirTypePrimitive::I64 => "return Int64List.from(raw);".into(), - MirTypePrimitive::U64 => "return Uint64List.from(raw);".into(), + MirTypePrimitive::I64 => "return dcoDecodeInt64List(raw);".into(), + MirTypePrimitive::U64 => "return dcoDecodeUint64List(raw);".into(), _ => gen_decode_simple_type_cast(self.mir.clone().into(), self.context), } } diff --git a/frb_dart/lib/src/generalized_isolate/_web.dart b/frb_dart/lib/src/generalized_isolate/_web.dart index cd1a21060a..58452441ed 100644 --- a/frb_dart/lib/src/generalized_isolate/_web.dart +++ b/frb_dart/lib/src/generalized_isolate/_web.dart @@ -6,23 +6,21 @@ import 'dart:html' as html; import 'dart:html' hide MessagePort; import 'package:flutter_rust_bridge/src/platform_types/_web.dart'; -import 'package:flutter_rust_bridge/src/platform_utils/_web.dart'; /// {@macro flutter_rust_bridge.internal} String serializeNativePort(NativePortType port) => port.name; -/// {@macro flutter_rust_bridge.only_for_generated_code} -typedef MessagePort = _PortLike; - -/// {@macro flutter_rust_bridge.only_for_generated_code} -typedef SendPort = _PortLike; +/// {@macro flutter_rust_bridge.internal} +ReceivePort broadcastPort(String channelName) => ReceivePort._raw( + RawReceivePort._raw(_WebChannel.broadcastChannel(channelName))); -/// Web implementation of the `dart:isolate`'s ReceivePort. +/// {@template flutter_rust_bridge.same_as_native} +/// Web implementation of the one with same name in native. +/// {@endtemplate} class ReceivePort extends Stream { - /// The receive port. final RawReceivePort _rawReceivePort; - /// Create a new receive port from an optional [RawReceivePort]. + /// {@macro flutter_rust_bridge.same_as_native} factory ReceivePort() => ReceivePort._raw(); ReceivePort._raw([RawReceivePort? rawReceivePort]) @@ -35,7 +33,7 @@ class ReceivePort extends Stream { void Function()? onDone, bool? cancelOnError, }) { - return _rawReceivePort._receivePort.onMessage.map(_extractData).listen( + return _rawReceivePort._webReceivePort._onMessage.map(_extractData).listen( onData, onError: onError, onDone: onDone, @@ -45,69 +43,71 @@ class ReceivePort extends Stream { static dynamic _extractData(MessageEvent event) => event.data; - /// The send port. + /// {@macro flutter_rust_bridge.same_as_native} SendPort get sendPort => _rawReceivePort.sendPort; - /// Close the receive port, ignoring any further messages. + /// {@macro flutter_rust_bridge.same_as_native} void close() => _rawReceivePort.close(); } -/// Wrapper around a [MessageChannel]. +/// {@macro flutter_rust_bridge.same_as_native} class RawReceivePort { - /// The underlying message channel. - final _Channel _channel; + final _WebChannel _webChannel; - /// {@macro flutter_rust_bridge.only_for_generated_code} + /// {@macro flutter_rust_bridge.same_as_native} factory RawReceivePort() => RawReceivePort._raw(); - RawReceivePort._raw([_Channel? channel]) - : _channel = channel ?? _Channel.messageChannel(); + RawReceivePort._raw([_WebChannel? channel]) + : _webChannel = channel ?? _WebChannel.messageChannel(); + /// {@macro flutter_rust_bridge.same_as_native} set handler(Function(dynamic) handler) { - _receivePort.onMessage.listen((event) => handler(event.data)); + _webReceivePort._onMessage.listen((event) => handler(event.data)); } - /// Close the receive port. - void close() => _channel.receivePort.close(); + /// {@macro flutter_rust_bridge.same_as_native} + void close() => _webReceivePort._close(); - /// The port to be used by other workers. - SendPort get sendPort => _channel.sendPort; + /// {@macro flutter_rust_bridge.same_as_native} + SendPort get sendPort => _webChannel._sendPort; - SendPort get _receivePort => _channel.receivePort; + _WebPortLike get _webReceivePort => _webChannel._receivePort; } -/// {@macro flutter_rust_bridge.internal} -ReceivePort broadcastPort(String channelName) => ReceivePort._raw( - RawReceivePort._raw(_Channel.broadcastChannel(channelName))); +/// {@macro flutter_rust_bridge.same_as_native} +class SendPort { + /// {@macro flutter_rust_bridge.same_as_native} + final html.EventTarget nativePort; -abstract class _Channel { - SendPort get sendPort; + const SendPort._(this.nativePort); +} - SendPort get receivePort; +abstract class _WebChannel { + SendPort get _sendPort; - const _Channel(); + _WebPortLike get _receivePort; - factory _Channel.messageChannel() = _MessageChannelWrapper; + factory _WebChannel.messageChannel() = _WebMessageChannel; - factory _Channel.broadcastChannel(String channelName) = - _BroadcastChannelWrapper; + factory _WebChannel.broadcastChannel(String channelName) = + _WebBroadcastChannel; } -class _MessageChannelWrapper implements _Channel { - final channel = MessageChannel(); +class _WebMessageChannel implements _WebChannel { + final _channel = MessageChannel(); @override - SendPort get sendPort => _PortLike.messagePort(channel.port2); + SendPort get _sendPort => SendPort._(_channel.port2); @override - SendPort get receivePort => _PortLike.messagePort(channel.port1); + _WebPortLike get _receivePort => _WebPortLike._messagePort(_channel.port1); } -class _BroadcastChannelWrapper implements _Channel { +class _WebBroadcastChannel implements _WebChannel { final BroadcastChannel _sendChannel; final BroadcastChannel _receiveChannel; - _BroadcastChannelWrapper(String channelName) + _WebBroadcastChannel(String channelName) // Note: It is *wrong* to reuse the same HTML BroadcastChannel object, // because HTML BroadcastChannel spec says that, the event will not be fired // at the object which sends it. Therefore, we need two different objects. @@ -115,61 +115,48 @@ class _BroadcastChannelWrapper implements _Channel { _receiveChannel = BroadcastChannel(channelName); @override - SendPort get sendPort => _PortLike.broadcastChannel(_sendChannel); + SendPort get _sendPort => SendPort._(_sendChannel); @override - SendPort get receivePort => _PortLike.broadcastChannel(_receiveChannel); + _WebPortLike get _receivePort => + _WebPortLike._broadcastChannel(_receiveChannel); } -/// [html.MessagePort]'s interface. -abstract class _PortLike { - const _PortLike._(); +/// {@macro flutter_rust_bridge.same_as_native} +abstract class _WebPortLike { + const _WebPortLike._(); - factory _PortLike.messagePort(html.MessagePort port) = _MessagePortWrapper; + factory _WebPortLike._messagePort(html.MessagePort port) = _WebMessagePort; - factory _PortLike.broadcastChannel(BroadcastChannel channel) = - _BroadcastPortWrapper; + factory _WebPortLike._broadcastChannel(BroadcastChannel channel) = + _WebBroadcastPort; - void postMessage(Object? value); + void _close(); - void close(); + /// {@macro flutter_rust_bridge.same_as_native} + html.EventTarget get _nativePort; - html.EventTarget get nativePort; - - Stream get onMessage => _kMessageEvent.forTarget(nativePort); + Stream get _onMessage => _kMessageEvent.forTarget(_nativePort); static const _kMessageEvent = EventStreamProvider('message'); } -class _MessagePortWrapper extends _PortLike { +class _WebMessagePort extends _WebPortLike { @override - final html.MessagePort nativePort; - - _MessagePortWrapper(this.nativePort) : super._(); + final html.MessagePort _nativePort; - @override - void postMessage(message, [List? transfer]) => - nativePort.postMessage(message, transfer); + _WebMessagePort(this._nativePort) : super._(); @override - void close() => nativePort.close(); + void _close() => _nativePort.close(); } -class _BroadcastPortWrapper extends _PortLike { +// Indeed a BroadcastChannel, not a Broadcast "Port" +class _WebBroadcastPort extends _WebPortLike { @override - final html.BroadcastChannel nativePort; + final html.BroadcastChannel _nativePort; - _BroadcastPortWrapper(this.nativePort) : super._(); - - /// This presents a limitation of BroadcastChannel, - /// i.e. it cannot carry transferables and will unconditionally clone the items. - @override - void postMessage(message, [List? transfer]) { - if (transfer != null && transfer.isNotEmpty) { - jsConsoleWarn("Ignoring transferables for BroadcastPort:", transfer); - } - nativePort.postMessage(message ?? false); - } + _WebBroadcastPort(this._nativePort) : super._(); @override - void close() => nativePort.close(); + void _close() => _nativePort.close(); } diff --git a/frb_dart/lib/src/generalized_typed_data/_io.dart b/frb_dart/lib/src/generalized_typed_data/_io.dart index f6ff3ce186..97a56e4501 100644 --- a/frb_dart/lib/src/generalized_typed_data/_io.dart +++ b/frb_dart/lib/src/generalized_typed_data/_io.dart @@ -1,44 +1,19 @@ -import 'dart:collection'; import 'dart:typed_data' as $data; -import 'package:flutter_rust_bridge/src/exceptions.dart'; - -abstract class _TypedList extends ListMixin { - List get inner; - - @override - _TypedList operator +(Object other); - - T _raw2dart(int value); - - int _dart2raw(Object? value); - - @override - T operator [](int index) => _raw2dart(inner[index]); - - @override - void operator []=(int index, Object? value) => - inner[index] = _dart2raw(value); - - @override - int get length => inner.length; - - @override - set length(int newLength) => throw const UnmodifiableTypedListException(); -} +import 'package:flutter_rust_bridge/src/generalized_typed_data/common.dart'; /// A strict version of [$data.Int64List] which always returns a [BigInt]. -class Int64List extends _TypedList { +class Int64List extends TypedList { @override final $data.Int64List inner; - /// Construct a list from normal Int64List - Int64List.from(this.inner); + /// {@macro flutter_rust_bridge.only_for_generated_code} + Int64List.raw(this.inner); /// Construct a list of the [length]. - factory Int64List(int length) => Int64List.from($data.Int64List(length)); + factory Int64List(int length) => Int64List.raw($data.Int64List(length)); - /// Construct a list from `List`. + /// Construct a list raw `List`. Int64List.fromList(List ints) : inner = $data.Int64List.fromList(ints); /// Construct a list view @@ -50,14 +25,14 @@ class Int64List extends _TypedList { : inner = $data.Int64List.sublistView(data, start, end); @override - int _dart2raw(Object? value) { + int outer2inner(Object? value) { if (value is BigInt) return value.toInt(); if (value is int) return value; throw ArgumentError.value(value); } @override - BigInt _raw2dart(int value) => BigInt.from(value); + BigInt inner2outer(int value) => BigInt.from(value); @override Int64List operator +(Object other) { @@ -72,17 +47,17 @@ class Int64List extends _TypedList { } /// A strict version of [$data.Uint64List] which always returns a [BigInt]. -class Uint64List extends _TypedList { +class Uint64List extends TypedList { @override final $data.Uint64List inner; - /// Construct a list from normal Int64List - Uint64List.from(this.inner); + /// {@macro flutter_rust_bridge.only_for_generated_code} + Uint64List.raw(this.inner); /// Construct a list of the [length]. - factory Uint64List(int length) => Uint64List.from($data.Uint64List(length)); + factory Uint64List(int length) => Uint64List.raw($data.Uint64List(length)); - /// Construct a list from `List`. + /// Construct a list raw `List`. Uint64List.fromList(List ints) : inner = $data.Uint64List.fromList(ints); /// Construct a list view @@ -97,7 +72,7 @@ class Uint64List extends _TypedList { static const _minI64 = 0x8000000000000000; @override - BigInt _raw2dart(int value) { + BigInt inner2outer(int value) { if (value < 0) { // two's complement signed integer to unsigned bigint return _maxI64b + BigInt.from(value - _minI64) + BigInt.one; @@ -106,7 +81,7 @@ class Uint64List extends _TypedList { } @override - int _dart2raw(Object? value) { + int outer2inner(Object? value) { if (value is int) return value; if (value is BigInt) { if (value > _maxI64b) { diff --git a/frb_dart/lib/src/generalized_typed_data/_web.dart b/frb_dart/lib/src/generalized_typed_data/_web.dart index 988251a238..fe3d07b483 100644 --- a/frb_dart/lib/src/generalized_typed_data/_web.dart +++ b/frb_dart/lib/src/generalized_typed_data/_web.dart @@ -1,177 +1,69 @@ -@JS() -library html_typed_data; - -import 'dart:collection'; import 'dart:typed_data' hide Int64List, Uint64List; -import 'package:flutter_rust_bridge/src/exceptions.dart'; -import 'package:flutter_rust_bridge/src/platform_utils/_web.dart'; -import 'package:js/js.dart'; -import 'package:js/js_util.dart'; - -@JS('TypedArray') -abstract class _TypedArray { - external ByteBuffer get buffer; - - external int length; - - external BigInt at(int index); -} - -extension on _TypedArray { - operator []=(int index, Object? value) { - setProperty(this, index, value); - } -} - -/// An array whose element is BigInt64 -@JS('BigInt64Array') -abstract class BigInt64Array extends _TypedArray { - /// Construct the array - external factory BigInt64Array(Object lengthOrBuffer, - [int? offset, int? length]); - - /// Construct the array from `List` - factory BigInt64Array.fromList(List list) => - BigInt64Array(list.map((n) => BigInt.from(n)).toList()); - - /// Construct an array view - factory BigInt64Array.view( - ByteBuffer buffer, [ - int offset = 0, - int? length, - ]) => - BigInt64Array(buffer, offset, length); - - /// Construct an array sub-list view - factory BigInt64Array.sublistView(TypedData array, - [int offset = 0, int? length]) => - BigInt64Array(array.buffer, offset, length); -} - -/// An array whose element is BigUint64 -@JS('BigUint64Array') -abstract class BigUint64Array extends _TypedArray { - /// Construct the array - external factory BigUint64Array(Object lengthOrBuffer, - [int? offset, int? buffer]); - - /// Construct the array from `List` - factory BigUint64Array.fromList(List list) => - BigUint64Array(list.map((n) => BigInt.from(n)).toList()); - - /// Construct an array view - factory BigUint64Array.view(ByteBuffer buffer, - [int offset = 0, int? length]) => - BigUint64Array(buffer, offset, length); - - /// Construct an array sub-list view - factory BigUint64Array.sublistView(TypedData array, - [int offset = 0, int? length]) => - BigUint64Array(array.buffer, offset, length); -} +import 'package:flutter_rust_bridge/src/generalized_typed_data/common.dart'; -/// Opt out of type safety for setting the value. -/// Helpful if the array needs to accept multiple types. -abstract class _SetAnyListMixin extends ListMixin { +class _Int64OrUint64List extends TypedList { @override - void operator []=(int index, Object? value) { - this[index] = value; - } -} - -abstract class _TypedList extends _SetAnyListMixin { - _TypedArray get inner; + final List inner; - /// How to cast a raw JS value to an acceptable Dart value. - T _js2dart(Object? value); - - /// How to convert a Dart integer-like value to an acceptable JS value. - Object? _dart2js(Object? value); + /// {@macro flutter_rust_bridge.only_for_generated_code} + _Int64OrUint64List.raw(this.inner); @override - T operator [](int index) => _js2dart(inner.at(index)); + BigInt inner2outer(BigInt value) => value; @override - void operator []=(int index, value) { - inner[index] = _dart2js(value); + BigInt outer2inner(Object? value) { + if (value is int) return BigInt.from(value); + if (value is BigInt) return value; + throw ArgumentError.value(value); } - - @override - int get length => inner.length; - - @override - set length(int newLength) => throw const UnmodifiableTypedListException(); - - ByteBuffer get buffer => inner.buffer; -} - -Object _convertBigIntToJs(Object dart) { - if (dart is int) return BigInt.from(dart); - // Assume value is already JS safe. - return dart; } /// A list whose elements are Int64 -class Int64List extends _TypedList { - @override - final BigInt64Array inner; +class Int64List extends _Int64OrUint64List { + /// {@macro flutter_rust_bridge.only_for_generated_code} + Int64List.raw(super.inner) : super.raw(); /// Construct a list - Int64List.from(this.inner); - - @override - BigInt _js2dart(Object? value) => jsBigIntToDartBigInt(value!); - - @override - Object? _dart2js(Object? value) => _convertBigIntToJs(value!); - - /// Construct a list - factory Int64List(int length) => Int64List.from(BigInt64Array(length)); + factory Int64List(int length) => + Int64List.raw(List.filled(length, BigInt.zero)); /// Construct a list factory Int64List.fromList(List list) => - Int64List.from(BigInt64Array.fromList(list)); - - /// Construct a list - factory Int64List.view(ByteBuffer buffer, [int offset = 0, int? length]) => - Int64List.from(BigInt64Array.view(buffer, offset, length)); - - /// Construct a list - factory Int64List.sublistView(TypedData array, - [int offset = 0, int? length]) => - Int64List.from(BigInt64Array.sublistView(array, offset, length)); + Int64List.raw(list.map(BigInt.from).toList()); + +// /// Construct a list +// factory Int64List.view(ByteBuffer buffer, [int offset = 0, int? length]) => +// Int64List.from(BigInt64Array.view(buffer, offset, length)); +// +// /// Construct a list +// factory Int64List.sublistView(TypedData array, +// [int offset = 0, int? length]) => +// Int64List.from(BigInt64Array.sublistView(array, offset, length)); } /// A list whose elements are Uint64 -class Uint64List extends _TypedList { - @override - final BigUint64Array inner; +class Uint64List extends _Int64OrUint64List { + /// {@macro flutter_rust_bridge.only_for_generated_code} + Uint64List.raw(super.inner) : super.raw(); /// Construct a list - Uint64List.from(this.inner); - - @override - BigInt _js2dart(Object? value) => jsBigIntToDartBigInt(value!); - - @override - Object? _dart2js(Object? value) => _convertBigIntToJs(value!); - - /// Construct a list - factory Uint64List(int length) => Uint64List.from(BigUint64Array(length)); + factory Uint64List(int length) => + Uint64List.raw(List.filled(length, BigInt.zero)); /// Construct a list factory Uint64List.fromList(List list) => - Uint64List.from(BigUint64Array.fromList(list)); - - /// Construct a list - factory Uint64List.view(ByteBuffer buffer, [int offset = 0, int? length]) => - Uint64List.from(BigUint64Array.view(buffer, offset, length)); - - /// Construct a list - factory Uint64List.sublistView(TypedData array, - [int offset = 0, int? length]) => - Uint64List.from(BigUint64Array.sublistView(array, offset, length)); + Uint64List.raw(list.map(BigInt.from).toList()); + +// /// Construct a list +// factory Uint64List.view(ByteBuffer buffer, [int offset = 0, int? length]) => +// Uint64List.from(BigUint64Array.view(buffer, offset, length)); +// +// /// Construct a list +// factory Uint64List.sublistView(TypedData array, +// [int offset = 0, int? length]) => +// Uint64List.from(BigUint64Array.sublistView(array, offset, length)); } /// {@macro flutter_rust_bridge.internal} diff --git a/frb_dart/lib/src/generalized_typed_data/common.dart b/frb_dart/lib/src/generalized_typed_data/common.dart new file mode 100644 index 0000000000..c13ae08a53 --- /dev/null +++ b/frb_dart/lib/src/generalized_typed_data/common.dart @@ -0,0 +1,31 @@ +import 'dart:collection'; + +import 'package:flutter_rust_bridge/src/exceptions.dart'; +import 'package:meta/meta.dart'; + +/// {@macro flutter_rust_bridge.internal} +abstract class TypedList extends ListMixin { + /// {@macro flutter_rust_bridge.only_for_generated_code} + List get inner; + + /// {@macro flutter_rust_bridge.internal} + @protected + T inner2outer(TInner value); + + /// {@macro flutter_rust_bridge.internal} + @protected + TInner outer2inner(Object? value); + + @override + T operator [](int index) => inner2outer(inner[index]); + + @override + void operator []=(int index, Object? value) => + inner[index] = outer2inner(value); + + @override + int get length => inner.length; + + @override + set length(int newLength) => throw const UnmodifiableTypedListException(); +} diff --git a/frb_dart/lib/src/manual_impl/_io.dart b/frb_dart/lib/src/manual_impl/_io.dart index 78f11bf41f..5c6ed0b3c2 100644 --- a/frb_dart/lib/src/manual_impl/_io.dart +++ b/frb_dart/lib/src/manual_impl/_io.dart @@ -2,6 +2,8 @@ import 'dart:ffi'; import 'package:flutter_rust_bridge/src/dart_c_object_into_dart/_io.dart'; import 'package:flutter_rust_bridge/src/platform_types/_io.dart'; +import 'package:flutter_rust_bridge/src/generalized_typed_data/_io.dart'; +import 'dart:typed_data' as $data; /// Generates the dynamic Dart object from either an FFI struct or a JS value /// @@ -15,6 +17,12 @@ int dcoDecodeI64(int raw) => raw; /// {@macro flutter_rust_bridge.only_for_generated_code} BigInt dcoDecodeU64(int raw) => BigInt.from(raw).toUnsigned(64); +/// {@macro flutter_rust_bridge.only_for_generated_code} +Int64List dcoDecodeInt64List($data.Int64List raw) => Int64List.raw(raw); + +/// {@macro flutter_rust_bridge.only_for_generated_code} +Uint64List dcoDecodeUint64List($data.Uint64List raw) => Uint64List.raw(raw); + /// {@macro flutter_rust_bridge.only_for_generated_code} int sseEncodeCastedPrimitiveI64(int raw) => raw; diff --git a/frb_dart/lib/src/manual_impl/_web.dart b/frb_dart/lib/src/manual_impl/_web.dart index 57d911cbb5..0a3d9f0bbf 100644 --- a/frb_dart/lib/src/manual_impl/_web.dart +++ b/frb_dart/lib/src/manual_impl/_web.dart @@ -1,3 +1,4 @@ +import 'package:flutter_rust_bridge/src/generalized_typed_data/_web.dart'; import 'package:flutter_rust_bridge/src/platform_types/_web.dart'; import 'package:flutter_rust_bridge/src/platform_utils/_web.dart'; @@ -11,6 +12,17 @@ BigInt dcoDecodeI64(dynamic raw) => jsBigIntToDartBigInt(raw); /// {@macro flutter_rust_bridge.only_for_generated_code} BigInt dcoDecodeU64(dynamic raw) => jsBigIntToDartBigInt(raw); +/// {@macro flutter_rust_bridge.only_for_generated_code} +Int64List dcoDecodeInt64List(List raw) => + Int64List.raw(_toListBigInt(raw)); + +/// {@macro flutter_rust_bridge.only_for_generated_code} +Uint64List dcoDecodeUint64List(List raw) => + Uint64List.raw(_toListBigInt(raw)); + +List _toListBigInt(List raw) => + raw.map((x) => jsBigIntToDartBigInt(x!)).toList(); + /// {@macro flutter_rust_bridge.only_for_generated_code} BigInt sseEncodeCastedPrimitiveI64(int raw) => BigInt.from(raw); diff --git a/frb_dart/test/typed_data_test.dart b/frb_dart/test/typed_data_test.dart index ce164f3c82..9ddd07633d 100644 --- a/frb_dart/test/typed_data_test.dart +++ b/frb_dart/test/typed_data_test.dart @@ -17,7 +17,7 @@ void main() { expect(buf[0], i64maxb, reason: 'max'); buf[0] += BigInt.one; if (isWeb) { - expect(buf[0], i64minb, reason: 'max+1 (wrapped)'); + expect(buf[0], i64maxb + BigInt.from(1), reason: 'max+1 (bigint)'); } else { expect(buf[0], i64maxb, reason: 'max+1 (clamped)'); } @@ -31,7 +31,7 @@ void main() { expect(buf[1], i64maxb, reason: 'i64max'); buf[0] += BigInt.one; if (isWeb) { - expect(buf[0], BigInt.zero, reason: 'max+1 (wrapped)'); + expect(buf[0], u64maxb + BigInt.from(1), reason: 'max+1 (bigint)'); } else { expect(buf[0], u64maxb, reason: 'max+1 (clamped)'); } diff --git a/frb_example/pure_dart/lib/src/rust/frb_generated.dart b/frb_example/pure_dart/lib/src/rust/frb_generated.dart index e746cfb49d..a159f92828 100644 --- a/frb_example/pure_dart/lib/src/rust/frb_generated.dart +++ b/frb_example/pure_dart/lib/src/rust/frb_generated.dart @@ -109720,7 +109720,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @protected Int64List dco_decode_list_prim_i_64_strict(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs - return Int64List.from(raw); + return dcoDecodeInt64List(raw); } @protected @@ -109762,7 +109762,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @protected Uint64List dco_decode_list_prim_u_64_strict(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs - return Uint64List.from(raw); + return dcoDecodeUint64List(raw); } @protected diff --git a/frb_example/pure_dart/test/api/pseudo_manual/stream_misc_twin_sse_test.dart b/frb_example/pure_dart/test/api/pseudo_manual/stream_misc_twin_sse_test.dart index 890051e072..f9f068b5a5 100644 --- a/frb_example/pure_dart/test/api/pseudo_manual/stream_misc_twin_sse_test.dart +++ b/frb_example/pure_dart/test/api/pseudo_manual/stream_misc_twin_sse_test.dart @@ -8,8 +8,6 @@ import 'package:frb_example_pure_dart/src/rust/api/pseudo_manual/stream_misc_twi import 'package:frb_example_pure_dart/src/rust/frb_generated.dart'; import 'package:test/test.dart'; -import '../../test_utils.dart'; - Future main({bool skipRustLibInit = false}) async { if (!skipRustLibInit) await RustLib.init(); @@ -17,7 +15,7 @@ Future main({bool skipRustLibInit = false}) async { final stream = funcStreamRealisticTwinSse(arg: 'hello'); var cnt = 0; await for (final value in stream) { - debugPrint("output from func_stream's stream: $value"); + print("output from func_stream's stream: $value"); cnt++; } expect(cnt, 10); diff --git a/frb_example/pure_dart/test/api/stream_misc_test.dart b/frb_example/pure_dart/test/api/stream_misc_test.dart index 1f95b7c08c..dfc253c150 100644 --- a/frb_example/pure_dart/test/api/stream_misc_test.dart +++ b/frb_example/pure_dart/test/api/stream_misc_test.dart @@ -4,8 +4,6 @@ import 'package:frb_example_pure_dart/src/rust/api/stream_misc.dart'; import 'package:frb_example_pure_dart/src/rust/frb_generated.dart'; import 'package:test/test.dart'; -import '../test_utils.dart'; - Future main({bool skipRustLibInit = false}) async { if (!skipRustLibInit) await RustLib.init(); @@ -13,7 +11,7 @@ Future main({bool skipRustLibInit = false}) async { final stream = funcStreamRealisticTwinNormal(arg: 'hello'); var cnt = 0; await for (final value in stream) { - debugPrint("output from func_stream's stream: $value"); + print("output from func_stream's stream: $value"); cnt++; } expect(cnt, 10); diff --git a/frb_example/pure_dart_pde/lib/src/rust/frb_generated.dart b/frb_example/pure_dart_pde/lib/src/rust/frb_generated.dart index baf565bc90..e6dab104f6 100644 --- a/frb_example/pure_dart_pde/lib/src/rust/frb_generated.dart +++ b/frb_example/pure_dart_pde/lib/src/rust/frb_generated.dart @@ -47024,7 +47024,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @protected Int64List dco_decode_list_prim_i_64_strict(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs - return Int64List.from(raw); + return dcoDecodeInt64List(raw); } @protected @@ -47066,7 +47066,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @protected Uint64List dco_decode_list_prim_u_64_strict(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs - return Uint64List.from(raw); + return dcoDecodeUint64List(raw); } @protected diff --git a/frb_example/pure_dart_pde/test/api/stream_misc_test.dart b/frb_example/pure_dart_pde/test/api/stream_misc_test.dart index e7c839e854..a1a366a7e4 100644 --- a/frb_example/pure_dart_pde/test/api/stream_misc_test.dart +++ b/frb_example/pure_dart_pde/test/api/stream_misc_test.dart @@ -6,8 +6,6 @@ import 'package:frb_example_pure_dart_pde/src/rust/api/stream_misc.dart'; import 'package:frb_example_pure_dart_pde/src/rust/frb_generated.dart'; import 'package:test/test.dart'; -import '../test_utils.dart'; - Future main({bool skipRustLibInit = false}) async { if (!skipRustLibInit) await RustLib.init(); @@ -15,7 +13,7 @@ Future main({bool skipRustLibInit = false}) async { final stream = funcStreamRealisticTwinNormal(arg: 'hello'); var cnt = 0; await for (final value in stream) { - debugPrint("output from func_stream's stream: $value"); + print("output from func_stream's stream: $value"); cnt++; } expect(cnt, 10); diff --git a/frb_rust/src/generalized_isolate/web/into_dart.rs b/frb_rust/src/generalized_isolate/web/into_dart.rs index fb3c06b77c..a728b5c21a 100644 --- a/frb_rust/src/generalized_isolate/web/into_dart.rs +++ b/frb_rust/src/generalized_isolate/web/into_dart.rs @@ -4,7 +4,7 @@ use crate::platform_types::DartAbi; #[cfg(feature = "rust-async")] use crate::rust_auto_opaque::{inner::RustAutoOpaqueInner, RustAutoOpaqueBase}; use crate::rust_opaque::RustOpaqueBase; -use js_sys::{Array, BigInt64Array, BigUint64Array, Int32Array}; +use js_sys::Array; use std::collections::{HashMap, HashSet}; use std::iter::FromIterator; use wasm_bindgen::JsValue; @@ -290,19 +290,20 @@ macro_rules! impl_into_dart_for_primitive { impl_into_dart_for_primitive!(i8 u8 i16 u16 i32 u32 f32 f64); macro_rules! delegate_big_buffers { - ($($buf:ty => $buffer:ty)*) => {$( + ($($buf:ty)*) => {$( impl IntoDart for $buf { fn into_dart(self) -> DartAbi { - let buf: &[i32] = bytemuck::cast_slice(&self[..]); - let buf = Int32Array::from(buf); - <$buffer>::new(&buf.buffer()).into() + into_dart_iterator(self.into_iter()) + // let buf: &[i32] = bytemuck::cast_slice(&self[..]); + // let buf = Int32Array::from(buf); + // <$buffer>::new(&buf.buffer()).into() } } )*}; } delegate_big_buffers! { - Vec => BigInt64Array - Vec => BigUint64Array + Vec + Vec } macro_rules! impl_into_dart_for_tuple {