mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 18:58:27 +00:00
Migrate samples/sample_extension to null safety
Closes https://github.com/dart-lang/sdk/issues/43711 Change-Id: I7628e4a6192efb26a12f8051b4fa87dfafabab9c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180960 Reviewed-by: Régis Crelier <regis@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
f438d72387
commit
91b0f16663
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
library sample_asynchronous_extension;
|
||||
|
||||
import 'dart:async';
|
||||
|
@ -12,15 +10,12 @@ import 'dart-ext:sample_extension';
|
|||
|
||||
// A class caches the native port used to call an asynchronous extension.
|
||||
class RandomArray {
|
||||
static SendPort _port;
|
||||
static SendPort? _port;
|
||||
|
||||
Future<List<int>> randomArray(int seed, int length) {
|
||||
var completer = new Completer<List<int>>();
|
||||
var replyPort = new RawReceivePort();
|
||||
var args = new List(3);
|
||||
args[0] = seed;
|
||||
args[1] = length;
|
||||
args[2] = replyPort.sendPort;
|
||||
var args = [seed, length, replyPort.sendPort];
|
||||
_servicePort.send(args);
|
||||
replyPort.handler = (result) {
|
||||
replyPort.close();
|
||||
|
@ -37,7 +32,7 @@ class RandomArray {
|
|||
if (_port == null) {
|
||||
_port = _newServicePort();
|
||||
}
|
||||
return _port;
|
||||
return _port!;
|
||||
}
|
||||
|
||||
SendPort _newServicePort() native "RandomArray_ServicePort";
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
library sample_synchronous_extension;
|
||||
|
||||
import 'dart-ext:sample_extension';
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
//
|
||||
// Dart test program for testing native extensions.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
// OtherResources=../sample_synchronous_extension.dart
|
||||
// OtherResources=../sample_asynchronous_extension.dart
|
||||
// OtherResources=../test_sample_synchronous_extension.dart
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
//
|
||||
// Dart test program for testing native extensions.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'sample_extension_test_helper.dart';
|
||||
|
||||
void main() {
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
//
|
||||
// Dart test program for testing native extensions.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
@ -26,7 +24,7 @@ Future copyFileToDirectory(String file, String directory) async {
|
|||
result = await Process.run('cmd.exe', ['/C', 'copy $src $dst']);
|
||||
break;
|
||||
default:
|
||||
Expect.fail('Unknown operating system ${Platform.operatingSystem}');
|
||||
throw 'Unknown operating system ${Platform.operatingSystem}';
|
||||
}
|
||||
if (result.exitCode != 0) {
|
||||
print(result.stdout);
|
||||
|
@ -46,7 +44,7 @@ Future run(String program, List<String> arguments) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future testNativeExtensions(String snapshotKind) async {
|
||||
Future testNativeExtensions(String? snapshotKind) async {
|
||||
String buildDirectory = dirname(Platform.executable);
|
||||
Directory tempDirectory =
|
||||
Directory.systemTemp.createTempSync('sample_extension_');
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
library test_sample_extension;
|
||||
|
||||
import 'sample_asynchronous_extension.dart';
|
||||
|
@ -32,16 +30,16 @@ void main() {
|
|||
void checkNormal(List l) {
|
||||
// Count how many times each byte value occurs. Assert that the counts
|
||||
// are all within a reasonable (six-sigma) range.
|
||||
List counts = new List<int>.filled(256, 0);
|
||||
List<int> counts = new List<int>.filled(256, 0);
|
||||
for (var e in l) {
|
||||
counts[e]++;
|
||||
}
|
||||
new RandomArray().randomArray(18, 256000).then(checkCorrelation(counts));
|
||||
}
|
||||
|
||||
Function checkCorrelation(List counts) {
|
||||
return (List l) {
|
||||
List counts_2 = new List<int>.filled(256, 0);
|
||||
dynamic Function(List<int>) checkCorrelation(List<int> counts) {
|
||||
return (List<int> l) {
|
||||
List<int> counts_2 = new List<int>.filled(256, 0);
|
||||
for (var e in l) {
|
||||
counts_2[e]++;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
library test_sample_extension;
|
||||
|
||||
import 'sample_synchronous_extension.dart';
|
||||
|
|
Loading…
Reference in a new issue