Skip to content

Commit

Permalink
convert zircon and fuchsia to null-safety (flutter#20577)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaselatta authored Aug 18, 2020
1 parent 549339b commit 17e1ae4
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 48 deletions.
21 changes: 10 additions & 11 deletions shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
library fuchsia;

import 'dart:io';
Expand All @@ -14,25 +13,25 @@ import 'dart:zircon';

// TODO: refactors this incomingServices instead
@pragma('vm:entry-point')
Handle _environment;
Handle? _environment;

@pragma('vm:entry-point')
Handle _outgoingServices;
Handle? _outgoingServices;

@pragma('vm:entry-point')
Handle _viewRef;
Handle? _viewRef;

class MxStartupInfo {
// TODO: refactor Handle to a Channel
// https://github.com/flutter/flutter/issues/49439
static Handle takeEnvironment() {
if (_outgoingServices == null && Platform.isFuchsia) {
if (_environment == null && Platform.isFuchsia) {
throw Exception(
'Attempting to call takeEnvironment more than once per process');
}
Handle handle = _environment;
final handle = _environment;
_environment = null;
return handle;
return handle!;
}

// TODO: refactor Handle to a Channel
Expand All @@ -42,9 +41,9 @@ class MxStartupInfo {
throw Exception(
'Attempting to call takeOutgoingServices more than once per process');
}
Handle handle = _outgoingServices;
final handle = _outgoingServices;
_outgoingServices = null;
return handle;
return handle!;
}

// TODO: refactor Handle to a ViewRef
Expand All @@ -54,9 +53,9 @@ class MxStartupInfo {
throw Exception(
'Attempting to call takeViewRef more than once per process');
}
Handle handle = _viewRef;
final handle = _viewRef;
_viewRef = null;
return handle;
return handle!;
}
}

Expand Down
1 change: 0 additions & 1 deletion shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
part of zircon;

// ignore_for_file: native_function_body_in_non_sdk_code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
part of zircon;

// ignore_for_file: native_function_body_in_non_sdk_code
Expand Down
91 changes: 61 additions & 30 deletions shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
part of zircon;

// ignore_for_file: native_function_body_in_non_sdk_code
Expand All @@ -16,12 +15,12 @@ class _Namespace { // ignore: unused_element
// Library private variable set by the embedder used to cache the
// namespace (as an fdio_ns_t*).
@pragma('vm:entry-point')
static int _namespace; // ignore: unused_field
static int? _namespace; // ignore: unused_field
}

/// An exception representing an error returned as an zx_status_t.
class ZxStatusException implements Exception {
final String message;
final String? message;
final int status;

ZxStatusException(this.status, [this.message]);
Expand All @@ -35,85 +34,117 @@ class ZxStatusException implements Exception {
}
}

/// Users of the [_Result] subclasses should check the status before
/// trying to read any data. Attempting to use a value stored in a result
/// when the status in not OK will result in an exception.
class _Result {
final int status;
const _Result(this.status);
}

@pragma('vm:entry-point')
class HandleResult extends _Result {
final Handle handle;
final Handle? _handle;
Handle get handle => _handle!;

@pragma('vm:entry-point')
const HandleResult(final int status, [this.handle]) : super(status);
const HandleResult(final int status, [this._handle]) : super(status);
@override
String toString() => 'HandleResult(status=$status, handle=$handle)';
String toString() => 'HandleResult(status=$status, handle=$_handle)';
}

@pragma('vm:entry-point')
class HandlePairResult extends _Result {
final Handle first;
final Handle second;
final Handle? _first;
final Handle? _second;

Handle get first => _first!;
Handle get second => _second!;

@pragma('vm:entry-point')
const HandlePairResult(final int status, [this.first, this.second])
const HandlePairResult(final int status, [this._first, this._second])
: super(status);
@override
String toString() =>
'HandlePairResult(status=$status, first=$first, second=$second)';
'HandlePairResult(status=$status, first=$_first, second=$_second)';
}

@pragma('vm:entry-point')
class ReadResult extends _Result {
final ByteData bytes;
final int numBytes;
final List<Handle> handles;
final ByteData? _bytes;
final int? _numBytes;
final List<Handle>? _handles;

ByteData get bytes => _bytes!;
int get numBytes => _numBytes!;
List<Handle> get handles => _handles!;

@pragma('vm:entry-point')
const ReadResult(final int status, [this.bytes, this.numBytes, this.handles])
const ReadResult(final int status, [this._bytes, this._numBytes, this._handles])
: super(status);
Uint8List bytesAsUint8List() =>
bytes.buffer.asUint8List(bytes.offsetInBytes, numBytes);

/// Returns the bytes as a Uint8List. If status != OK this will throw
/// an exception.
Uint8List bytesAsUint8List() {
return _bytes!.buffer.asUint8List(_bytes!.offsetInBytes, _numBytes!);
}

/// Returns the bytes as a String. If status != OK this will throw
/// an exception.
String bytesAsUTF8String() => utf8.decode(bytesAsUint8List());

@override
String toString() =>
'ReadResult(status=$status, bytes=$bytes, numBytes=$numBytes, handles=$handles)';
'ReadResult(status=$status, bytes=$_bytes, numBytes=$_numBytes, handles=$_handles)';
}

@pragma('vm:entry-point')
class WriteResult extends _Result {
final int numBytes;
final int? _numBytes;
int get numBytes => _numBytes!;

@pragma('vm:entry-point')
const WriteResult(final int status, [this.numBytes]) : super(status);
const WriteResult(final int status, [this._numBytes]) : super(status);
@override
String toString() => 'WriteResult(status=$status, numBytes=$numBytes)';
String toString() => 'WriteResult(status=$status, numBytes=$_numBytes)';
}

@pragma('vm:entry-point')
class GetSizeResult extends _Result {
final int size;
final int? _size;
int get size => _size!;

@pragma('vm:entry-point')
const GetSizeResult(final int status, [this.size]) : super(status);
const GetSizeResult(final int status, [this._size]) : super(status);
@override
String toString() => 'GetSizeResult(status=$status, size=$size)';
String toString() => 'GetSizeResult(status=$status, size=$_size)';
}

@pragma('vm:entry-point')
class FromFileResult extends _Result {
final Handle handle;
final int numBytes;
final Handle? _handle;
final int? _numBytes;

Handle get handle => _handle!;
int get numBytes => _numBytes!;

@pragma('vm:entry-point')
const FromFileResult(final int status, [this.handle, this.numBytes])
const FromFileResult(final int status, [this._handle, this._numBytes])
: super(status);
@override
String toString() =>
'FromFileResult(status=$status, handle=$handle, numBytes=$numBytes)';
'FromFileResult(status=$status, handle=$_handle, numBytes=$_numBytes)';
}

@pragma('vm:entry-point')
class MapResult extends _Result {
final Uint8List data;
final Uint8List? _data;
Uint8List get data => _data!;

@pragma('vm:entry-point')
const MapResult(final int status, [this.data]) : super(status);
const MapResult(final int status, [this._data]) : super(status);
@override
String toString() => 'MapResult(status=$status, data=$data)';
String toString() => 'MapResult(status=$status, data=$_data)';
}

@pragma('vm:entry-point')
Expand Down
1 change: 0 additions & 1 deletion shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
library zircon;

import 'dart:convert' show utf8;
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/fuchsia/dart_runner/embedder/builtin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
library fuchsia_builtin;

import 'dart:async';
Expand All @@ -25,7 +24,7 @@ class _Logger {
}

@pragma('vm:entry-point')
String _rawScript;
late String _rawScript;

Uri _scriptUri() {
if (_rawScript.startsWith('http:') ||
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/dart_runner/kernel/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ compile_platform("kernel_platform_files") {

args = [
"--enable-experiment=non-nullable",
"--nnbd-weak",
"--nnbd-agnostic",

# TODO(dartbug.com/36342): enable bytecode for core libraries when performance of bytecode
# pipeline is on par with default pipeline and continuously tracked.
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/kernel/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ compile_platform("kernel_platform_files") {

args = [
"--enable-experiment=non-nullable",
"--nnbd-weak",
"--nnbd-agnostic",

# TODO(dartbug.com/36342): enable bytecode for core libraries when performance of bytecode
# pipeline is on par with default pipeline and continuously tracked.
Expand Down

0 comments on commit 17e1ae4

Please sign in to comment.