Add back in null assertions for legacy weak mode

These assertions need to be added back into the nnbd sdk in order to be
compatible with weak mode.

Change-Id: Ie774fffda1fb0e79dbc7fe13cb75b9d28e4268fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136720
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
This commit is contained in:
Srujan Gaddam 2020-02-21 19:13:31 +00:00 committed by commit-bot@chromium.org
parent 8f61e17a6a
commit 6d051311b6
5 changed files with 24 additions and 34 deletions

View file

@ -10342,13 +10342,13 @@ class DocumentFragment extends Node
// Native field is used only by Dart code so does not lead to instantiation
// of native classes
@Creates('Null')
List<Element> _docChildren;
List<Element>? _docChildren;
List<Element> get children {
if (_docChildren == null) {
_docChildren = new FilteredElementList(this);
}
return _docChildren;
return _docChildren!;
}
set children(List<Element> value) {
@ -12814,6 +12814,7 @@ class Element extends Node
@pragma('dart2js:tryInline')
String? getAttribute(String name) {
// Protect [name] against string conversion to "null" or "undefined".
assert(name != null, 'Attribute name cannot be null');
return _getAttribute(name);
}
@ -12821,12 +12822,14 @@ class Element extends Node
String? getAttributeNS(String? namespaceURI, String name) {
// Protect [name] against string conversion to "null" or "undefined".
// [namespaceURI] does not need protecting, both `null` and `undefined` map to `null`.
assert(name != null, 'Attribute name cannot be null');
return _getAttributeNS(namespaceURI, name);
}
@pragma('dart2js:tryInline')
bool hasAttribute(String name) {
// Protect [name] against string conversion to "null" or "undefined".
assert(name != null, 'Attribute name cannot be null');
return _hasAttribute(name);
}
@ -12834,30 +12837,37 @@ class Element extends Node
bool hasAttributeNS(String? namespaceURI, String name) {
// Protect [name] against string conversion to "null" or "undefined".
// [namespaceURI] does not need protecting, both `null` and `undefined` map to `null`.
assert(name != null, 'Attribute name cannot be null');
return _hasAttributeNS(namespaceURI, name);
}
@pragma('dart2js:tryInline')
void removeAttribute(String name) {
// Protect [name] against string conversion to "null" or "undefined".
assert(name != null, 'Attribute name cannot be null');
_removeAttribute(name);
}
@pragma('dart2js:tryInline')
void removeAttributeNS(String? namespaceURI, String name) {
// Protect [name] against string conversion to "null" or "undefined".
assert(name != null, 'Attribute name cannot be null');
_removeAttributeNS(namespaceURI, name);
}
@pragma('dart2js:tryInline')
void setAttribute(String name, String value) {
// Protect [name] against string conversion to "null" or "undefined".
assert(name != null, 'Attribute name cannot be null');
// TODO(sra): assert(value != null, 'Attribute value cannot be null.');
_setAttribute(name, value);
}
@pragma('dart2js:tryInline')
void setAttributeNS(String? namespaceURI, String name, String value) {
// Protect [name] against string conversion to "null" or "undefined".
assert(name != null, 'Attribute name cannot be null');
// TODO(sra): assert(value != null, 'Attribute value cannot be null.');
_setAttributeNS(namespaceURI, name, value);
}
@ -32590,7 +32600,7 @@ class Window extends EventTarget
*/
int requestAnimationFrame(FrameRequestCallback callback) {
_ensureRequestAnimationFrame();
return _requestAnimationFrame(_wrapZone(callback));
return _requestAnimationFrame(_wrapZone(callback)!);
}
/**
@ -41233,15 +41243,17 @@ class _WrappedEvent implements Event {
// 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.
void Function(T) _wrapZone<T>(void Function(T) callback) {
void Function(T)? _wrapZone<T>(void Function(T) callback) {
// For performance reasons avoid wrapping if we are in the root zone.
if (Zone.current == Zone.root) return callback;
if (callback == null) return null;
return Zone.current.bindUnaryCallbackGuarded(callback);
}
void Function(T1, T2) _wrapBinaryZone<T1, T2>(void Function(T1, T2) callback) {
void Function(T1, T2)? _wrapBinaryZone<T1, T2>(void Function(T1, T2) callback) {
// For performance reasons avoid wrapping if we are in the root zone.
if (Zone.current == Zone.root) return callback;
if (callback == null) return null;
return Zone.current.bindBinaryCallbackGuarded(callback);
}

View file

@ -4,15 +4,17 @@
part of dart.dom.html;
void Function(T) _wrapZone<T>(void Function(T) callback) {
void Function(T)? _wrapZone<T>(void Function(T) callback) {
// For performance reasons avoid wrapping if we are in the root zone.
if (Zone.current == Zone.root) return callback;
if (callback == null) return null;
return Zone.current.bindUnaryCallbackGuarded(callback);
}
void Function(T1, T2) _wrapBinaryZone<T1, T2>(void Function(T1, T2) callback) {
void Function(T1, T2)? _wrapBinaryZone<T1, T2>(void Function(T1, T2) callback) {
// For performance reasons avoid wrapping if we are in the root zone.
if (Zone.current == Zone.root) return callback;
if (callback == null) return null;
return Zone.current.bindBinaryCallbackGuarded(callback);
}

View file

@ -29,13 +29,13 @@ $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
// Native field is used only by Dart code so does not lead to instantiation
// of native classes
@Creates('Null')
List<Element> _docChildren;
List<Element>$NULLABLE _docChildren;
List<Element> get children {
if (_docChildren == null) {
_docChildren = new FilteredElementList(this);
}
return _docChildren;
return _docChildren$NULLASSERT;
}
set children(List<Element> value) {

View file

@ -567,10 +567,7 @@ $(ANNOTATIONS)$(NATIVESPEC)class $CLASSNAME$EXTENDS$IMPLEMENTS {
@pragma('dart2js:tryInline')
String$NULLABLE getAttribute(String name) {
// Protect [name] against string conversion to "null" or "undefined".
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
$endif
return _getAttribute(name);
}
@ -578,20 +575,14 @@ $endif
String$NULLABLE getAttributeNS(String$NULLABLE namespaceURI, String name) {
// Protect [name] against string conversion to "null" or "undefined".
// [namespaceURI] does not need protecting, both `null` and `undefined` map to `null`.
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
$endif
return _getAttributeNS(namespaceURI, name);
}
@pragma('dart2js:tryInline')
bool hasAttribute(String name) {
// Protect [name] against string conversion to "null" or "undefined".
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
$endif
return _hasAttribute(name);
}
@ -599,52 +590,37 @@ $endif
bool hasAttributeNS(String$NULLABLE namespaceURI, String name) {
// Protect [name] against string conversion to "null" or "undefined".
// [namespaceURI] does not need protecting, both `null` and `undefined` map to `null`.
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
$endif
return _hasAttributeNS(namespaceURI, name);
}
@pragma('dart2js:tryInline')
void removeAttribute(String name) {
// Protect [name] against string conversion to "null" or "undefined".
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
$endif
_removeAttribute(name);
}
@pragma('dart2js:tryInline')
void removeAttributeNS(String$NULLABLE namespaceURI, String name) {
// Protect [name] against string conversion to "null" or "undefined".
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
$endif
_removeAttributeNS(namespaceURI, name);
}
@pragma('dart2js:tryInline')
void setAttribute(String name, String value) {
// Protect [name] against string conversion to "null" or "undefined".
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
// TODO(sra): assert(value != null, 'Attribute value cannot be null.');
$endif
_setAttribute(name, value);
}
@pragma('dart2js:tryInline')
void setAttributeNS(String$NULLABLE namespaceURI, String name, String value) {
// Protect [name] against string conversion to "null" or "undefined".
$if NNBD
$else
assert(name != null, 'Attribute name cannot be null');
// TODO(sra): assert(value != null, 'Attribute value cannot be null.');
$endif
_setAttributeNS(namespaceURI, name, value);
}

View file

@ -106,7 +106,7 @@ $(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS {
*/
int requestAnimationFrame(FrameRequestCallback callback) {
_ensureRequestAnimationFrame();
return _requestAnimationFrame(_wrapZone(callback));
return _requestAnimationFrame(_wrapZone(callback)$NULLASSERT);
}
/**