Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a0c3b4f

Browse files
fishythefishcommit-bot@chromium.org
authored andcommitted
[dart2js] Fix some types in NNBD SDK.
Change-Id: Ie401c5f6bae54f7394f5c30c7c1b9a28b70126dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137860 Reviewed-by: Sigmund Cherem <[email protected]>
1 parent fb547fc commit a0c3b4f

File tree

11 files changed

+85
-87
lines changed

11 files changed

+85
-87
lines changed

sdk/lib/_internal/js_runtime/lib/core_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Expando<T> {
106106
Expando([String name])
107107
: this.name = name,
108108
_jsWeakMapOrKey = JS('bool', 'typeof WeakMap == "function"')
109-
? JS('=Object|Null', 'new WeakMap()')
109+
? JS('=Object', 'new WeakMap()')
110110
: _createKey();
111111

112112
@patch

sdk/lib/_internal/js_runtime/lib/native_typed_data.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ class NativeFloat64x2List extends Object
313313
class NativeTypedData implements TypedData {
314314
/// Returns the byte buffer associated with this object.
315315
@Creates('NativeByteBuffer')
316-
// May be Null for IE's CanvasPixelArray.
317-
@Returns('NativeByteBuffer|Null')
316+
@Returns('NativeByteBuffer')
318317
final ByteBuffer buffer;
319318

320319
/// Returns the length of this view, in bytes.

sdk_nnbd/lib/_internal/js_dev_runtime/private/native_typed_data.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ class NativeFloat64x2List extends Object
311311
class NativeTypedData implements TypedData {
312312
/// Returns the byte buffer associated with this object.
313313
@Creates('NativeByteBuffer')
314-
// May be Null for IE's CanvasPixelArray.
315-
@Returns('NativeByteBuffer|Null')
314+
@Returns('NativeByteBuffer')
316315
external ByteBuffer get buffer;
317316

318317
/// Returns the length of this view, in bytes.

sdk_nnbd/lib/_internal/js_runtime/lib/constant_map.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class GeneralConstantMap<K, V> extends ConstantMap<K, V> {
194194
// We cannot create the backing map on creation since hashCode interceptors
195195
// have not been defined when constants are created.
196196
Map<K, V> _getMap() {
197-
LinkedHashMap<K, V> backingMap = JS('LinkedHashMap|Null', r'#.$map', this);
197+
LinkedHashMap<K, V>? backingMap = JS('LinkedHashMap|Null', r'#.$map', this);
198198
if (backingMap == null) {
199199
backingMap = new JsLinkedHashMap<K, V>();
200200
fillLiteralMap(_jsData, backingMap);

sdk_nnbd/lib/_internal/js_runtime/lib/core_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Expando<T> {
105105
Expando([String? name])
106106
: this.name = name,
107107
_jsWeakMapOrKey = JS('bool', 'typeof WeakMap == "function"')
108-
? JS('=Object|Null', 'new WeakMap()')
108+
? JS('=Object', 'new WeakMap()')
109109
: _createKey();
110110

111111
@patch

sdk_nnbd/lib/_internal/js_runtime/lib/interceptors.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ makeDispatchRecord(interceptor, proto, extension, indexability) {
110110
dispatchRecordInterceptor(record) => JS('', '#.i', record);
111111
dispatchRecordProto(record) => JS('', '#.p', record);
112112
dispatchRecordExtension(record) => JS('', '#.e', record);
113-
dispatchRecordIndexability(record) => JS('bool|Null', '#.x', record);
113+
bool? dispatchRecordIndexability(record) => JS('bool|Null', '#.x', record);
114114

115115
/// Returns the interceptor for a native class instance. Used by
116116
/// [getInterceptor].

sdk_nnbd/lib/_internal/js_runtime/lib/js_helper.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ String rawRtiToJsConstructorName(Object rti) {
128128
/// Given a raw constructor name, return the unminified name, if available,
129129
/// otherwise tag the name with `minified:`.
130130
String unminifyOrTag(String rawClassName) {
131-
String preserved = unmangleGlobalNameIfPreservedAnyways(rawClassName);
132-
if (preserved is String) return preserved;
131+
String? preserved = unmangleGlobalNameIfPreservedAnyways(rawClassName);
132+
if (preserved != null) return preserved;
133133
if (JS_GET_FLAG('MINIFIED')) return 'minified:${rawClassName}';
134134
return rawClassName;
135135
}
@@ -398,7 +398,7 @@ class JSInvocationMirror implements Invocation {
398398

399399
class Primitives {
400400
static int objectHashCode(object) {
401-
int hash = JS('int|Null', r'#.$identityHash', object);
401+
int? hash = JS('int|Null', r'#.$identityHash', object);
402402
if (hash == null) {
403403
hash = JS('int', '(Math.random() * 0x3fffffff) | 0');
404404
JS('void', r'#.$identityHash = #', object, hash);
@@ -786,7 +786,7 @@ class Primitives {
786786
// Example: "Wed May 16 2012 21:13:00 GMT+0200 (CEST)".
787787
// We extract this name using a regexp.
788788
var d = lazyAsJsDate(receiver);
789-
List match = JS('JSArray|Null', r'/\((.*)\)/.exec(#.toString())', d);
789+
List? match = JS('JSArray|Null', r'/\((.*)\)/.exec(#.toString())', d);
790790
if (match != null) return match[1];
791791

792792
// Internet Explorer 10+ emits the zone name without parenthesis:
@@ -1575,7 +1575,7 @@ class TypeErrorDecoder {
15751575
// Look for the special pattern \$camelCase\$ (all the $ symbols
15761576
// have been escaped already), as we will soon be inserting
15771577
// regular expression syntax that we want interpreted by RegExp.
1578-
List<String> match =
1578+
List<String>? match =
15791579
JS('JSExtendableArray|Null', r'#.match(/\\\$[a-zA-Z]+\\\$/g)', message);
15801580
if (match == null) match = [];
15811581

@@ -1926,7 +1926,7 @@ unwrapException(ex) {
19261926
return ex;
19271927
}
19281928

1929-
String tryStringifyException(ex) {
1929+
String? tryStringifyException(ex) {
19301930
// Since this function is called from [unwrapException] which is called from
19311931
// code injected into a catch-clause, use JavaScript try-catch to avoid a
19321932
// potential loop if stringifying crashes.
@@ -1950,7 +1950,7 @@ StackTrace getTraceFromException(exception) {
19501950
return exception.stackTrace;
19511951
}
19521952
if (exception == null) return new _StackTrace(exception);
1953-
_StackTrace trace = JS('_StackTrace|Null', r'#.$cachedTrace', exception);
1953+
_StackTrace? trace = JS('_StackTrace|Null', r'#.$cachedTrace', exception);
19541954
if (trace != null) return trace;
19551955
trace = new _StackTrace(exception);
19561956
return JS('_StackTrace', r'#.$cachedTrace = #', exception, trace);
@@ -2095,7 +2095,7 @@ abstract class Closure implements Function {
20952095
static fromTearOff(
20962096
receiver,
20972097
List functions,
2098-
int applyTrampolineIndex,
2098+
int? applyTrampolineIndex,
20992099
var reflectionInfo,
21002100
bool isStatic,
21012101
bool isIntercepted,
@@ -2116,8 +2116,8 @@ abstract class Closure implements Function {
21162116
// TODO(ahe): All the place below using \$ should be rewritten to go
21172117
// through the namer.
21182118
var function = JS('', '#[#]', functions, 0);
2119-
String name = JS('String|Null', '#.\$stubName', function);
2120-
String callName = JS('String|Null', '#[#]', function,
2119+
String? name = JS('String|Null', '#.\$stubName', function);
2120+
String? callName = JS('String|Null', '#[#]', function,
21212121
JS_GET_NAME(JsGetName.CALL_NAME_PROPERTY));
21222122

21232123
// This variable holds either an index into the types-table, or a function
@@ -2301,7 +2301,7 @@ abstract class Closure implements Function {
23012301
}
23022302

23032303
static cspForwardCall(
2304-
int arity, bool isSuperCall, String stubName, function) {
2304+
int arity, bool isSuperCall, String? stubName, function) {
23052305
var getSelf = RAW_DART_FUNCTION_REF(BoundClosure.selfOf);
23062306
// Handle intercepted stub-names with the default slow case.
23072307
if (isSuperCall) arity = -1;
@@ -2383,7 +2383,7 @@ abstract class Closure implements Function {
23832383

23842384
static forwardCallTo(receiver, function, bool isIntercepted) {
23852385
if (isIntercepted) return forwardInterceptedCallTo(receiver, function);
2386-
String stubName = JS('String|Null', '#.\$stubName', function);
2386+
String? stubName = JS('String|Null', '#.\$stubName', function);
23872387
int arity = JS('int', '#.length', function);
23882388
var lookedUpFunction = JS('', '#[#]', receiver, stubName);
23892389
// The receiver[stubName] may not be equal to the function if we try to
@@ -2420,7 +2420,7 @@ abstract class Closure implements Function {
24202420
}
24212421

24222422
static cspForwardInterceptedCall(
2423-
int arity, bool isSuperCall, String name, function) {
2423+
int arity, bool isSuperCall, String? name, function) {
24242424
var getSelf = RAW_DART_FUNCTION_REF(BoundClosure.selfOf);
24252425
var getReceiver = RAW_DART_FUNCTION_REF(BoundClosure.receiverOf);
24262426
// Handle intercepted stub-names with the default slow case.
@@ -2515,7 +2515,7 @@ abstract class Closure implements Function {
25152515
static forwardInterceptedCallTo(receiver, function) {
25162516
String selfField = BoundClosure.selfFieldName();
25172517
String receiverField = BoundClosure.receiverFieldName();
2518-
String stubName = JS('String|Null', '#.\$stubName', function);
2518+
String? stubName = JS('String|Null', '#.\$stubName', function);
25192519
int arity = JS('int', '#.length', function);
25202520
bool isCsp = JS_GET_FLAG('USE_CONTENT_SECURITY_POLICY');
25212521
var lookedUpFunction = JS('', '#[#]', receiver, stubName);
@@ -2587,7 +2587,7 @@ abstract class TearOffClosure extends Closure {}
25872587

25882588
class StaticClosure extends TearOffClosure {
25892589
String toString() {
2590-
String name =
2590+
String? name =
25912591
JS('String|Null', '#[#]', this, STATIC_FUNCTION_NAME_PROPERTY_NAME);
25922592
if (name == null) return 'Closure of unknown static method';
25932593
return "Closure '${unminifyOrTag(name)}'";
@@ -3241,7 +3241,7 @@ Future<Null> loadDeferredLibrary(String loadId) {
32413241
// by an index. There are two arrays, one that maps the index into a Uri and
32423242
// another that maps the index to a hash.
32433243
var partsMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_PARTS);
3244-
List indexes = JS('JSExtendableArray|Null', '#[#]', partsMap, loadId);
3244+
List? indexes = JS('JSExtendableArray|Null', '#[#]', partsMap, loadId);
32453245
if (indexes == null) return new Future.value(null);
32463246
List<String> uris = <String>[];
32473247
List<String> hashes = <String>[];
@@ -3323,7 +3323,7 @@ String? _cspNonce = _computeCspNonce();
33233323
String? _computeCspNonce() {
33243324
var currentScript = JS_EMBEDDED_GLOBAL('', CURRENT_SCRIPT);
33253325
if (currentScript == null) return null;
3326-
String nonce = JS('String|Null', '#.nonce', currentScript);
3326+
String? nonce = JS('String|Null', '#.nonce', currentScript);
33273327
return (nonce != null && nonce != '')
33283328
? nonce
33293329
: JS('String|Null', '#.getAttribute("nonce")', currentScript);

sdk_nnbd/lib/_internal/js_runtime/lib/js_names.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ List extractKeys(victim) {
148148
/// This is used, for example, to return unmangled names from TypeImpl.toString
149149
/// *if* names are being preserved for other reasons (use of dart:mirrors, for
150150
/// example).
151-
String unmangleGlobalNameIfPreservedAnyways(String name) {
151+
String? unmangleGlobalNameIfPreservedAnyways(String name) {
152152
var names = JS_EMBEDDED_GLOBAL('', MANGLED_GLOBAL_NAMES);
153153
return JS('String|Null', '#', JsCache.fetch(names, name));
154154
}

sdk_nnbd/lib/_internal/js_runtime/lib/native_typed_data.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ class NativeFloat64x2List extends Object
311311
class NativeTypedData implements TypedData {
312312
/// Returns the byte buffer associated with this object.
313313
@Creates('NativeByteBuffer')
314-
// May be Null for IE's CanvasPixelArray.
315-
@Returns('NativeByteBuffer|Null')
314+
@Returns('NativeByteBuffer')
316315
ByteBuffer get buffer native;
317316

318317
/// Returns the length of this view, in bytes.

sdk_nnbd/lib/_internal/js_runtime/lib/regexp_helper.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class JSSyntaxRegExp implements RegExp {
110110
}
111111

112112
RegExpMatch? firstMatch(String string) {
113-
JSArray m = JS('JSExtendableArray|Null', r'#.exec(#)', _nativeRegExp,
113+
JSArray? m = JS('JSExtendableArray|Null', r'#.exec(#)', _nativeRegExp,
114114
checkString(string));
115115
if (m == null) return null;
116116
return new _MatchImplementation(this, m);
@@ -138,15 +138,15 @@ class JSSyntaxRegExp implements RegExp {
138138
RegExpMatch? _execGlobal(String string, int start) {
139139
Object regexp = _nativeGlobalVersion;
140140
JS('void', '#.lastIndex = #', regexp, start);
141-
JSArray match = JS('JSExtendableArray|Null', '#.exec(#)', regexp, string);
141+
JSArray? match = JS('JSExtendableArray|Null', '#.exec(#)', regexp, string);
142142
if (match == null) return null;
143143
return new _MatchImplementation(this, match);
144144
}
145145

146146
RegExpMatch? _execAnchored(String string, int start) {
147147
Object regexp = _nativeAnchoredVersion;
148148
JS('void', '#.lastIndex = #', regexp, start);
149-
JSArray match = JS('JSExtendableArray|Null', '#.exec(#)', regexp, string);
149+
JSArray? match = JS('JSExtendableArray|Null', '#.exec(#)', regexp, string);
150150
if (match == null) return null;
151151
// If the last capture group participated, the original regexp did not
152152
// match at the start position.
@@ -194,14 +194,14 @@ class _MatchImplementation implements RegExpMatch {
194194

195195
// The JS below changes the static type to avoid an implicit cast.
196196
// TODO(sra): Find a nicer way to do this, e.g. unsafeCast.
197-
String group(int index) => JS('String|Null', '#', _match[index]);
197+
String? group(int index) => JS('String|Null', '#', _match[index]);
198198

199-
String operator [](int index) => group(index);
199+
String? operator [](int index) => group(index);
200200

201201
int get groupCount => _match.length - 1;
202202

203-
List<String> groups(List<int> groups) {
204-
List<String> out = [];
203+
List<String?> groups(List<int> groups) {
204+
List<String?> out = [];
205205
for (int i in groups) {
206206
out.add(group(i));
207207
}

0 commit comments

Comments
 (0)