diff --git a/LibTest/js_interop/NullableUndefineableJSAnyExtension/isDefinedAndNotNull_t01.dart b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isDefinedAndNotNull_t01.dart new file mode 100644 index 0000000000..26d2297016 --- /dev/null +++ b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isDefinedAndNotNull_t01.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// 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. + +/// @assertion bool get isDefinedAndNotNull +/// +/// @description Checks that this getter returns `true` if this value is +/// defined (not `undefined`) and not `Null`. `false` otherwise. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; +import '../../../Utils/expect.dart'; +import '../js_utils.dart'; + +main() { + eval(r''' + var n = null; + var u = undefined; + var s = "s"; + '''); + + Expect.isFalse(globalContext["n"].isDefinedAndNotNull); + Expect.isTrue(42.toJS.isDefinedAndNotNull); + Expect.isFalse(globalContext["u"].isDefinedAndNotNull); + Expect.isTrue(globalContext["s"].isDefinedAndNotNull); + Expect.isFalse(null.isDefinedAndNotNull); +} diff --git a/LibTest/js_interop/NullableUndefineableJSAnyExtension/isNull_t01.dart b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isNull_t01.dart new file mode 100644 index 0000000000..ca1e3d9c38 --- /dev/null +++ b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isNull_t01.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// 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. + +/// @assertion bool get isNull +/// Whether this value corresponds to JavaScript `null`. +/// +/// @description Checks if this value corresponds to JavaScript `null`. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; +import '../../../Utils/expect.dart'; +import '../js_utils.dart'; + +main() { + eval(r''' + var n = null; + var u = undefined; + var s = "s"; + '''); + + Expect.isTrue(globalContext["n"].isNull); + Expect.isFalse(42.toJS.isNull); + Expect.isFalse(globalContext["u"].isNull); + Expect.isFalse(globalContext["s"].isNull); + Expect.isTrue(null.isNull); +} diff --git a/LibTest/js_interop/NullableUndefineableJSAnyExtension/isUndefinedOrNull_t01.dart b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isUndefinedOrNull_t01.dart new file mode 100644 index 0000000000..cb43b48bca --- /dev/null +++ b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isUndefinedOrNull_t01.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// 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. + +/// @assertion bool get isUndefinedOrNull +/// +/// @description Checks that this getter returns `true` if the value +/// corresponds to JavaScript `undefined` or `null`. `false` otherwise. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; +import '../../../Utils/expect.dart'; +import '../js_utils.dart'; + +main() { + eval(r''' + var n = null; + var u = undefined; + var s = "s"; + '''); + + Expect.isTrue(globalContext["n"].isUndefinedOrNull); + Expect.isFalse(42.toJS.isUndefinedOrNull); + Expect.isTrue(globalContext["u"].isUndefinedOrNull); + Expect.isFalse(globalContext["s"].isUndefinedOrNull); + Expect.isTrue(null.isUndefinedOrNull); +} diff --git a/LibTest/js_interop/NullableUndefineableJSAnyExtension/isUndefined_t01.dart b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isUndefined_t01.dart new file mode 100644 index 0000000000..049923375b --- /dev/null +++ b/LibTest/js_interop/NullableUndefineableJSAnyExtension/isUndefined_t01.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// 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. + +/// @assertion bool get isUndefined +/// Whether this value corresponds to JavaScript `undefined`. +/// +/// @description Checks if this value corresponds to JavaScript `undefined`. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; +import '../../../Utils/expect.dart'; +import '../js_utils.dart'; + +main() { + eval(r''' + var n = null; + var u = undefined; + var s = "s"; + '''); + + Expect.isFalse(globalContext["n"].isUndefined); + Expect.isFalse(42.toJS.isUndefined); + Expect.isTrue(globalContext["u"].isUndefined); + Expect.isFalse(globalContext["s"].isUndefined); + Expect.isFalse(null.isUndefined); +} diff --git a/LibTest/js_interop/js_utils.dart b/LibTest/js_interop/js_utils.dart new file mode 100644 index 0000000000..a25d7ebb02 --- /dev/null +++ b/LibTest/js_interop/js_utils.dart @@ -0,0 +1,11 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// 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. + +/// @description Common library for js_interop tests. +/// @author sgrekhov22@gmail.com + +import 'dart:js_interop'; + +@JS() +external void eval(String code);