Skip to content

Commit

Permalink
[dartdevc/nnbd] Type fixes uncovered by strong param checking
Browse files Browse the repository at this point in the history
Change-Id: I86969c021ac2dea28455b40dfdbed8f5923b197e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135797
Commit-Queue: Vijay Menon <vsm@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
  • Loading branch information
vsmenon authored and commit-bot@chromium.org committed Feb 18, 2020
1 parent e5befd1 commit 999eeea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
76 changes: 39 additions & 37 deletions sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class Object {

// Everything is an Object.
@JSExportName('is')
static bool _is_Object(Object o) => o != null;
static bool _is_Object(Object? o) => o != null;

@JSExportName('as')
static Object _as_Object(Object o) =>
static Object _as_Object(Object? o) =>
o == null ? dart.cast(o, dart.unwrapType(Object), false) : o;

@JSExportName('_check')
static Object _check_Object(Object o) =>
static Object _check_Object(Object? o) =>
o == null ? dart.cast(o, dart.unwrapType(Object), true) : o;
}

Expand All @@ -83,17 +83,17 @@ class Null {
int get hashCode => super.hashCode;

@JSExportName('is')
static bool _is_Null(Object o) => o == null;
static bool _is_Null(Object? o) => o == null;

@JSExportName('as')
static Object _as_Null(Object o) {
static Object? _as_Null(Object? o) {
// Avoid extra function call to core.Null.is() by manually inlining.
if (o == null) return o;
return dart.cast(o, dart.unwrapType(Null), false);
}

@JSExportName('_check')
static Object _check_Null(Object o) {
static Object? _check_Null(Object? o) {
// Avoid extra function call to core.Null.is() by manually inlining.
if (o == null) return o;
return dart.cast(o, dart.unwrapType(Null), true);
Expand Down Expand Up @@ -128,20 +128,20 @@ class Function {
}

@JSExportName('is')
static bool _is_Function(Object o) =>
static bool _is_Function(Object? o) =>
JS<bool>('!', 'typeof $o == "function"');

@JSExportName('as')
static Object _as_Function(Object o) {
static Object? _as_Function(Object? o) {
// Avoid extra function call to core.Function.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "function"')) return o;
if (JS<bool>('!', 'typeof $o == "function"') || o == null) return o;
return dart.cast(o, dart.unwrapType(Function), false);
}

@JSExportName('_check')
static Object _check_Function(Object o) {
static Object? _check_Function(Object? o) {
// Avoid extra function call to core.Function.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "function"')) return o;
if (JS<bool>('!', 'typeof $o == "function"') || o == null) return o;
return dart.cast(o, dart.unwrapType(Function), true);
}
}
Expand Down Expand Up @@ -208,23 +208,25 @@ class int {
}

@JSExportName('is')
static bool _is_int(Object o) {
static bool _is_int(Object? o) {
return JS<bool>('!', 'typeof $o == "number" && Math.floor($o) == $o');
}

@JSExportName('as')
static Object _as_int(Object o) {
static Object? _as_int(Object? o) {
// Avoid extra function call to core.int.is() by manually inlining.
if (JS<bool>('!', '(typeof $o == "number" && Math.floor($o) == $o)')) {
if (JS<bool>('!', '(typeof $o == "number" && Math.floor($o) == $o)') ||
o == null) {
return o;
}
return dart.cast(o, dart.unwrapType(int), false);
}

@JSExportName('_check')
static Object _check_int(Object o) {
static Object? _check_int(Object? o) {
// Avoid extra function call to core.int.is() by manually inlining.
if (JS<bool>('!', '(typeof $o == "number" && Math.floor($o) == $o)')) {
if (JS<bool>('!', '(typeof $o == "number" && Math.floor($o) == $o)') ||
o == null) {
return o;
}
return dart.cast(o, dart.unwrapType(int), true);
Expand All @@ -245,43 +247,43 @@ class double {
}

@JSExportName('is')
static bool _is_double(o) {
static bool _is_double(Object? o) {
return JS<bool>('!', 'typeof $o == "number"');
}

@JSExportName('as')
static Object _as_double(o) {
static Object? _as_double(Object? o) {
// Avoid extra function call to core.double.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "number"')) return o;
if (JS<bool>('!', 'typeof $o == "number"') || o == null) return o;
return dart.cast(o, dart.unwrapType(double), false);
}

@JSExportName('_check')
static Object _check_double(o) {
static Object? _check_double(Object? o) {
// Avoid extra function call to core.double.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "number"')) return o;
if (JS<bool>('!', 'typeof $o == "number"') || o == null) return o;
return dart.cast(o, dart.unwrapType(double), true);
}
}

@patch
abstract class num implements Comparable<num> {
@JSExportName('is')
static bool _is_num(o) {
static bool _is_num(Object? o) {
return JS<bool>('!', 'typeof $o == "number"');
}

@JSExportName('as')
static Object _as_num(o) {
static Object? _as_num(Object? o) {
// Avoid extra function call to core.num.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "number"')) return o;
if (JS<bool>('!', 'typeof $o == "number"') || o == null) return o;
return dart.cast(o, dart.unwrapType(num), false);
}

@JSExportName('_check')
static Object _check_num(o) {
static Object? _check_num(Object? o) {
// Avoid extra function call to core.num.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "number"')) return o;
if (JS<bool>('!', 'typeof $o == "number"') || o == null) return o;
return dart.cast(o, dart.unwrapType(num), true);
}
}
Expand Down Expand Up @@ -653,21 +655,21 @@ class String {
}

@JSExportName('is')
static bool _is_String(Object o) {
static bool _is_String(Object? o) {
return JS<bool>('!', 'typeof $o == "string"');
}

@JSExportName('as')
static Object _as_String(Object o) {
static Object? _as_String(Object? o) {
// Avoid extra function call to core.String.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "string"')) return o;
if (JS<bool>('!', 'typeof $o == "string"') || o == null) return o;
return dart.cast(o, dart.unwrapType(String), false);
}

@JSExportName('_check')
static Object _check_String(Object o) {
static Object? _check_String(Object? o) {
// Avoid extra function call to core.String.is() by manually inlining.
if (JS<bool>('!', 'typeof $o == "string"')) return o;
if (JS<bool>('!', 'typeof $o == "string"') || o == null) return o;
return dart.cast(o, dart.unwrapType(String), true);
}
}
Expand All @@ -685,20 +687,20 @@ class bool {
int get hashCode => super.hashCode;

@JSExportName('is')
static bool _is_bool(Object o) =>
static bool _is_bool(Object? o) =>
JS<bool>('!', '$o === true || $o === false');

@JSExportName('as')
static Object _as_bool(Object o) {
static Object? _as_bool(Object? o) {
// Avoid extra function call to core.bool.is() by manually inlining.
if (JS<bool>("!", '$o === true || $o === false')) return o;
if (JS<bool>("!", '$o === true || $o === false') || o == null) return o;
return dart.cast(o, dart.unwrapType(bool), false);
}

@JSExportName('_check')
static Object _check_bool(Object o) {
static Object? _check_bool(Object? o) {
// Avoid extra function call to core.bool.is() by manually inlining.
if (JS<bool>("!", '$o === true || $o === false')) return o;
if (JS<bool>("!", '$o === true || $o === false') || o == null) return o;
return dart.cast(o, dart.unwrapType(bool), true);
}
}
Expand Down Expand Up @@ -786,7 +788,7 @@ class StringBuffer {
return string;
}

static String _writeOne(String string, Object obj) {
static String _writeOne(String string, Object? obj) {
return Primitives.stringConcatUnchecked(string, '$obj');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ final constantMaps = JS<Object>('!', 'new Map()');
// Keeping the paths is probably expensive. It would probably
// be more space efficient to just use a direct hash table with
// an appropriately defined structural equality function.
Object _lookupNonTerminal(Object map, Object key) {
Object _lookupNonTerminal(Object map, Object? key) {
var result = JS('', '#.get(#)', map, key);
if (result != null) return result;
JS('', '#.set(#, # = new Map())', map, key, result);
Expand Down

0 comments on commit 999eeea

Please sign in to comment.