From 39509bae5f7de28e428863ff1fec83d65700939f Mon Sep 17 00:00:00 2001 From: Srujan Gaddam Date: Fri, 3 Apr 2020 17:43:57 +0000 Subject: [PATCH] [dart:html] Migrate html js tests to NNBD Change-Id: I01cf3de95f4d7c67f97d440187a2d7254c7daecc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140646 Reviewed-by: Bob Nystrom --- tests/lib/html/js_array_test.dart | 4 +--- tests/lib/html/js_browser_test.dart | 6 ++--- tests/lib/html/js_dart_to_string_test.dart | 4 +--- tests/lib/html/js_function_getter_test.dart | 4 +--- tests/lib/html/js_interop_1_test.dart | 4 +--- tests/lib/html/js_test_util.dart | 4 +--- tests/lib/html/js_transferrables_test.dart | 6 ++--- .../js_typed_interop_anonymous2_exp_test.dart | 10 ++++----- .../js_typed_interop_anonymous2_test.dart | 10 ++++----- .../js_typed_interop_anonymous_exp_test.dart | 10 ++++----- .../html/js_typed_interop_anonymous_test.dart | 22 +++++++++---------- ...nterop_anonymous_unreachable_exp_test.dart | 4 +--- ...ed_interop_anonymous_unreachable_test.dart | 4 +--- .../html/js_typed_interop_bind_this_test.dart | 4 +--- ...js_typed_interop_callable_object_test.dart | 4 +--- .../js_typed_interop_default_arg_test.dart | 8 +++---- .../html/js_typed_interop_dynamic_test.dart | 12 +++++----- .../js_typed_interop_rename_static_test.dart | 4 +--- .../html/js_typed_interop_side_cast_test.dart | 8 +++---- tests/lib/html/js_typed_interop_test.dart | 18 +++++++-------- .../lib/html/js_typed_interop_type_test.dart | 8 +++---- ...js_typed_interop_window_property_test.dart | 4 +--- tests/lib/html/js_util_test.dart | 4 +--- 23 files changed, 60 insertions(+), 106 deletions(-) diff --git a/tests/lib/html/js_array_test.dart b/tests/lib/html/js_array_test.dart index eb9b47e4e56..1775ed448e6 100644 --- a/tests/lib/html/js_array_test.dart +++ b/tests/lib/html/js_array_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS("ArrayTest.Util") library js_array_test; @@ -15,7 +13,7 @@ import 'package:expect/minitest.dart'; import 'json_helper.dart' as json_helper; _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" ArrayTest = {}; diff --git a/tests/lib/html/js_browser_test.dart b/tests/lib/html/js_browser_test.dart index a0f23346035..8c0714b7500 100644 --- a/tests/lib/html/js_browser_test.dart +++ b/tests/lib/html/js_browser_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - import 'dart:html'; import 'dart:indexed_db' show IdbFactory, KeyRange; import 'dart:typed_data' show Int32List; @@ -26,8 +24,8 @@ main() { expect(node['testProperty'], 'test'); }); - test('primitives and null throw ArgumentError', () { - for (var v in ['a', 1, 2.0, true, null]) { + test('primitives throw ArgumentError', () { + for (var v in ['a', 1, 2.0, true]) { expect(() => new JsObject.fromBrowserObject(v), throwsArgumentError); } }); diff --git a/tests/lib/html/js_dart_to_string_test.dart b/tests/lib/html/js_dart_to_string_test.dart index 258580fc9f3..357b08d3110 100644 --- a/tests/lib/html/js_dart_to_string_test.dart +++ b/tests/lib/html/js_dart_to_string_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_dart_to_string_test; @@ -13,7 +11,7 @@ import 'package:js/js.dart'; import 'package:expect/minitest.dart'; _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" diff --git a/tests/lib/html/js_function_getter_test.dart b/tests/lib/html/js_function_getter_test.dart index 10a66b8525b..d01e29b5075 100644 --- a/tests/lib/html/js_function_getter_test.dart +++ b/tests/lib/html/js_function_getter_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_function_getter_test; @@ -13,7 +11,7 @@ import 'package:js/js.dart'; import 'package:expect/minitest.dart'; _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" var bar = { }; diff --git a/tests/lib/html/js_interop_1_test.dart b/tests/lib/html/js_interop_1_test.dart index e7e29b08b2a..5f57dfba5d8 100644 --- a/tests/lib/html/js_interop_1_test.dart +++ b/tests/lib/html/js_interop_1_test.dart @@ -2,8 +2,6 @@ // 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 -// @dart = 2.7 - library JsInterop1Test; import 'package:async_helper/async_helper.dart'; @@ -14,7 +12,7 @@ injectSource(code) { final script = new ScriptElement(); script.type = 'text/javascript'; script.innerHtml = code; - document.body.append(script); + document.body!.append(script); } main() { diff --git a/tests/lib/html/js_test_util.dart b/tests/lib/html/js_test_util.dart index 7dd0594f38d..e56887f8dc6 100644 --- a/tests/lib/html/js_test_util.dart +++ b/tests/lib/html/js_test_util.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - library TestJsUtils; import 'dart:html'; @@ -190,7 +188,7 @@ var someObject = Object.create(someProto); someObject.role = "object"; """; - document.body.append(script); + document.body!.append(script); } typedef bool StringToBool(String s); diff --git a/tests/lib/html/js_transferrables_test.dart b/tests/lib/html/js_transferrables_test.dart index 340c52a277d..46fcdcce36d 100644 --- a/tests/lib/html/js_transferrables_test.dart +++ b/tests/lib/html/js_transferrables_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - import 'dart:html'; import 'dart:indexed_db' show IdbFactory, KeyRange; import 'dart:typed_data' show Int32List; @@ -28,7 +26,7 @@ main() { test('foreign browser objects should be proxied', () { var iframe = new IFrameElement(); - document.body.children.add(iframe); + document.body!.children.add(iframe); var proxy = new JsObject.fromBrowserObject(iframe); // Window @@ -55,7 +53,7 @@ main() { test('foreign functions pass function is checks', () { var iframe = new IFrameElement(); - document.body.children.add(iframe); + document.body!.children.add(iframe); var proxy = new JsObject.fromBrowserObject(iframe); var contentWindow = proxy['contentWindow']; diff --git a/tests/lib/html/js_typed_interop_anonymous2_exp_test.dart b/tests/lib/html/js_typed_interop_anonymous2_exp_test.dart index 03c937193d9..2c827b8b3a2 100644 --- a/tests/lib/html/js_typed_interop_anonymous2_exp_test.dart +++ b/tests/lib/html/js_typed_interop_anonymous2_exp_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - // SharedOptions=--experimental-trust-js-interop-type-annotations // Same test as js_typed_interop_anonymous2, but using the @@ -20,17 +18,17 @@ import 'package:expect/minitest.dart'; @JS() @anonymous class A { - external factory A({B b}); + external factory A({B? b}); - external B get b; + external B? get b; } @JS() @anonymous class B { - external factory B({C c}); + external factory B({C? c}); - external C get c; + external C? get c; } @JS() diff --git a/tests/lib/html/js_typed_interop_anonymous2_test.dart b/tests/lib/html/js_typed_interop_anonymous2_test.dart index 2f8db0870c8..a5b53024b95 100644 --- a/tests/lib/html/js_typed_interop_anonymous2_test.dart +++ b/tests/lib/html/js_typed_interop_anonymous2_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_anonymous2_test; @@ -16,17 +14,17 @@ import 'package:expect/minitest.dart'; @JS() @anonymous class A { - external factory A({B b}); + external factory A({B? b}); - external B get b; + external B? get b; } @JS() @anonymous class B { - external factory B({C c}); + external factory B({C? c}); - external C get c; + external C? get c; } @JS() diff --git a/tests/lib/html/js_typed_interop_anonymous_exp_test.dart b/tests/lib/html/js_typed_interop_anonymous_exp_test.dart index f723fae9db1..e160bdd9f0a 100644 --- a/tests/lib/html/js_typed_interop_anonymous_exp_test.dart +++ b/tests/lib/html/js_typed_interop_anonymous_exp_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - // SharedOptions=--experimental-trust-js-interop-type-annotations // Same test as js_typed_interop_anonymous, but using the @@ -20,11 +18,11 @@ import 'package:expect/minitest.dart'; @JS() @anonymous class Literal { - external factory Literal({int x, String y, num z}); + external factory Literal({int? x, String? y, num? z}); - external int get x; - external String get y; - external num get z; + external int? get x; + external String? get y; + external num? get z; } main() { diff --git a/tests/lib/html/js_typed_interop_anonymous_test.dart b/tests/lib/html/js_typed_interop_anonymous_test.dart index 95ca87ad70e..485f8123375 100644 --- a/tests/lib/html/js_typed_interop_anonymous_test.dart +++ b/tests/lib/html/js_typed_interop_anonymous_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_anonymous_test; @@ -13,23 +11,23 @@ import 'package:expect/minitest.dart'; @JS() @anonymous class Literal { - external factory Literal({int x, String y, num z}); + external factory Literal({int? x, String? y, num? z}); - external set x(int v); - external int get x; - external String get y; - external num get z; + external set x(int? v); + external int? get x; + external String? get y; + external num? get z; } class MockLiteral implements Literal { - int _v = 0; - set x(int v) { + int? _v = 0; + set x(int? v) { _v = v; } - int get x => _v; - String get y => ""; - num get z => 1; + int? get x => _v; + String? get y => ""; + num? get z => 1; } main() { diff --git a/tests/lib/html/js_typed_interop_anonymous_unreachable_exp_test.dart b/tests/lib/html/js_typed_interop_anonymous_unreachable_exp_test.dart index 019d94b44fd..046dcffd8c5 100644 --- a/tests/lib/html/js_typed_interop_anonymous_unreachable_exp_test.dart +++ b/tests/lib/html/js_typed_interop_anonymous_unreachable_exp_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - // SharedOptions=--experimental-trust-js-interop-type-annotations // Same test as js_typed_interop_anonymous_unreachable, but using the @@ -20,7 +18,7 @@ import 'package:expect/minitest.dart'; @JS() @anonymous class Literal { - external factory Literal({int x, String y, num z}); + external factory Literal({required int x, required String y, required num z}); external int get x; external String get y; diff --git a/tests/lib/html/js_typed_interop_anonymous_unreachable_test.dart b/tests/lib/html/js_typed_interop_anonymous_unreachable_test.dart index b84c9c6ba03..e0dbaff4f41 100644 --- a/tests/lib/html/js_typed_interop_anonymous_unreachable_test.dart +++ b/tests/lib/html/js_typed_interop_anonymous_unreachable_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_anonymous_unreachable_test; @@ -16,7 +14,7 @@ import 'package:expect/minitest.dart'; @JS() @anonymous class Literal { - external factory Literal({int x, String y, num z}); + external factory Literal({required int x, required String y, required num z}); external int get x; external String get y; diff --git a/tests/lib/html/js_typed_interop_bind_this_test.dart b/tests/lib/html/js_typed_interop_bind_this_test.dart index 114a58d2697..a444043b0d3 100644 --- a/tests/lib/html/js_typed_interop_bind_this_test.dart +++ b/tests/lib/html/js_typed_interop_bind_this_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_bind_this_test; @@ -15,7 +13,7 @@ import 'package:expect/minitest.dart'; // This is a regression test for https://github.com/dart-lang/sdk/issues/25658 _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" "use strict"; diff --git a/tests/lib/html/js_typed_interop_callable_object_test.dart b/tests/lib/html/js_typed_interop_callable_object_test.dart index f2ba50cd798..659d2a915a5 100644 --- a/tests/lib/html/js_typed_interop_callable_object_test.dart +++ b/tests/lib/html/js_typed_interop_callable_object_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_callable_object_test; @@ -20,7 +18,7 @@ import 'package:expect/minitest.dart'; confuse(x) => x; _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" "use strict"; diff --git a/tests/lib/html/js_typed_interop_default_arg_test.dart b/tests/lib/html/js_typed_interop_default_arg_test.dart index fdcf6e583b4..27629e1689b 100644 --- a/tests/lib/html/js_typed_interop_default_arg_test.dart +++ b/tests/lib/html/js_typed_interop_default_arg_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_test; @@ -13,7 +11,7 @@ import 'package:js/js.dart'; import 'package:expect/minitest.dart'; _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" var Foo = { @@ -26,10 +24,10 @@ _injectJs() { @JS() class Foo { // Note: it's invalid to provide a default value. - external static num get42([num b + external static num get42([num? b = 3 // //# default_value: compile-time error ]); - external static num get43([num b]); + external static num get43([num? b]); } main() { diff --git a/tests/lib/html/js_typed_interop_dynamic_test.dart b/tests/lib/html/js_typed_interop_dynamic_test.dart index ce27ea94a21..030c9c234c5 100644 --- a/tests/lib/html/js_typed_interop_dynamic_test.dart +++ b/tests/lib/html/js_typed_interop_dynamic_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_anonymous_test; @@ -17,12 +15,12 @@ import 'package:expect/minitest.dart'; @JS() @anonymous class Literal { - external factory Literal({int x, String y, num z, Function foo}); + external factory Literal({int? x, String? y, num? z, Function? foo}); - external int get x; - external String get y; - external num get z; - external Function get foo; + external int? get x; + external String? get y; + external num? get z; + external Function? get foo; } @JS() diff --git a/tests/lib/html/js_typed_interop_rename_static_test.dart b/tests/lib/html/js_typed_interop_rename_static_test.dart index 5ecb7160713..48d68312931 100644 --- a/tests/lib/html/js_typed_interop_rename_static_test.dart +++ b/tests/lib/html/js_typed_interop_rename_static_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_rename_static_test; @@ -50,7 +48,7 @@ class Foo { } main() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" window.JSFoo = { diff --git a/tests/lib/html/js_typed_interop_side_cast_test.dart b/tests/lib/html/js_typed_interop_side_cast_test.dart index 63b0d1f7a56..c22207351ec 100644 --- a/tests/lib/html/js_typed_interop_side_cast_test.dart +++ b/tests/lib/html/js_typed_interop_side_cast_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_anonymous2_test; @@ -14,21 +12,21 @@ import 'package:expect/minitest.dart'; @anonymous class A { external int get x; - external factory A({int x}); + external factory A({required int x}); } @JS() @anonymous class C { external int get x; - external factory C({int x}); + external factory C({required int x}); } @JS() @anonymous class B { external int get x; - external factory B({int x}); + external factory B({required int x}); } main() { diff --git a/tests/lib/html/js_typed_interop_test.dart b/tests/lib/html/js_typed_interop_test.dart index 562d1d0183d..3ee46e01fb3 100644 --- a/tests/lib/html/js_typed_interop_test.dart +++ b/tests/lib/html/js_typed_interop_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_test; @@ -13,7 +11,7 @@ import 'package:js/js.dart'; import 'package:expect/minitest.dart'; _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" "use strict"; @@ -122,7 +120,7 @@ class ClassWithFactory { external get b; } -typedef num MultiplyWithDefault(num a, [num b]); +typedef num MultiplyWithDefault(num a, [num? b]); @JS() @anonymous @@ -138,17 +136,17 @@ class Foo { external callClosureWithArg2(Function closure, arg1, arg2); external Bar getBar(); - external static num multiplyDefault2(num a, [num b]); + external static num multiplyDefault2(num a, [num? b]); } @anonymous @JS() class ExampleLiteral { - external factory ExampleLiteral({int x, String y, num z}); + external factory ExampleLiteral({int? x, String? y, num? z}); - external int get x; - external String get y; - external num get z; + external int? get x; + external String? get y; + external num? get z; } @anonymous @@ -208,7 +206,7 @@ external num get propertyOnDocument; external num get propertyOnWindow; class DartClassWithNullField { - int x; + int? x; } main() { diff --git a/tests/lib/html/js_typed_interop_type_test.dart b/tests/lib/html/js_typed_interop_type_test.dart index f5330070470..c3967b50daa 100644 --- a/tests/lib/html/js_typed_interop_type_test.dart +++ b/tests/lib/html/js_typed_interop_type_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_type_test; @@ -28,7 +26,7 @@ class B { @JS() @anonymous class C { - final foo; + late final foo; external factory C({foo}); } @@ -36,7 +34,7 @@ class C { @JS() @anonymous class D { - final foo; + late final foo; external factory D({foo}); } @@ -84,7 +82,7 @@ testF(F o) { } _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" function A(foo) { diff --git a/tests/lib/html/js_typed_interop_window_property_test.dart b/tests/lib/html/js_typed_interop_window_property_test.dart index fc0f701040f..4790b7adb54 100644 --- a/tests/lib/html/js_typed_interop_window_property_test.dart +++ b/tests/lib/html/js_typed_interop_window_property_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_typed_interop_window_property_test; @@ -15,7 +13,7 @@ import 'package:expect/expect.dart'; // This is a regression test for https://github.com/dart-lang/sdk/issues/24817 _injectJs() { - document.body.append(new ScriptElement() + document.body!.append(new ScriptElement() ..type = 'text/javascript' ..innerHtml = r""" "use strict"; diff --git a/tests/lib/html/js_util_test.dart b/tests/lib/html/js_util_test.dart index 21dcb932949..ab74e4341d8 100644 --- a/tests/lib/html/js_util_test.dart +++ b/tests/lib/html/js_util_test.dart @@ -2,8 +2,6 @@ // 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. -// @dart = 2.7 - @JS() library js_native_test; @@ -65,7 +63,7 @@ function getResolvedPromise() { } """; - document.body.append(script); + document.body!.append(script); } @JS()