[pkg/wasm_builder] analyze with package:lints

Change-Id: Ie067adab896b9b73a7eb76a04d813b8acd7ac478
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250763
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
This commit is contained in:
Devon Carew 2022-07-07 21:31:28 +00:00 committed by Commit Bot
parent 8fa8d1f1f1
commit bc0bb9e257
6 changed files with 19 additions and 8 deletions

View file

@ -0,0 +1 @@
include: package:lints/core.yaml

View file

@ -2,6 +2,8 @@
// 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.
// ignore_for_file: non_constant_identifier_names
import 'module.dart';
import 'serialize.dart';
import 'types.dart';

View file

@ -24,7 +24,7 @@ class Module with SerializerMixin {
final List<DataSegment> dataSegments = [];
final List<Global> globals = [];
final List<Export> exports = [];
BaseFunction? startFunction = null;
BaseFunction? startFunction;
bool anyFunctionsDefined = false;
bool anyTablesDefined = false;
@ -277,7 +277,7 @@ class Module with SerializerMixin {
}
/// Serialize the module to its binary representation.
Uint8List encode({bool emitNameSection: true}) {
Uint8List encode({bool emitNameSection = true}) {
// Wasm module preamble: magic number, version 1.
writeBytes(const [0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00]);
TypeSection(this).serialize(this);
@ -918,7 +918,7 @@ class ElementSection extends Section {
// each stretch as an element.
List<_Element> elements = [];
for (DefinedTable table in module.definedTables) {
_Element? current = null;
_Element? current;
for (int i = 0; i < table.elements.length; i++) {
BaseFunction? function = table.elements[i];
if (function != null) {

View file

@ -40,7 +40,9 @@ mixin SerializerMixin implements Serializer {
// Ensure space for at least `size` additional bytes.
if (_data.length < _index + size) {
int newLength = _data.length * 2;
while (newLength < _index + size) newLength *= 2;
while (newLength < _index + size) {
newLength *= 2;
}
_data = Uint8List(newLength)..setRange(0, _data.length, _data);
}
}
@ -107,7 +109,9 @@ mixin SerializerMixin implements Serializer {
void writeList(List<Serializable> objects) {
writeUnsigned(objects.length);
for (int i = 0; i < objects.length; i++) write(objects[i]);
for (int i = 0; i < objects.length; i++) {
write(objects[i]);
}
}
void writeData(Serializer chunk, [List<int>? watchPoints]) {

View file

@ -230,7 +230,7 @@ class RefType extends ValueType {
@override
String toString() {
if (nullable == heapType.nullableByDefault) return "${heapType}ref";
return "ref${nullable ? " null " : " "}${heapType}";
return "ref${nullable ? " null " : " "}$heapType";
}
@override
@ -553,10 +553,10 @@ class FieldType extends _WithMutability<StorageType> {
FieldType(super.type, {super.mutable = true});
/// The `i8` storage type as a field type.
FieldType.i8({bool mutable: true}) : this(PackedType.i8, mutable: mutable);
FieldType.i8({bool mutable = true}) : this(PackedType.i8, mutable: mutable);
/// The `i16` storage type as a field type.
FieldType.i16({bool mutable: true}) : this(PackedType.i16, mutable: mutable);
FieldType.i16({bool mutable = true}) : this(PackedType.i16, mutable: mutable);
bool isSubtypeOf(FieldType other) {
if (mutable != other.mutable) return false;

View file

@ -5,3 +5,7 @@ description: Generate binary Wasm modules
environment:
sdk: '>=2.17.0'
# Use 'any' constraints here; we get our versions from the DEPS file.
dev_dependency:
lints: any