Skip to content

#3180. Add tests for NullableUndefineableJSAnyExtension. #3205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 [email protected]

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);
}
Original file line number Diff line number Diff line change
@@ -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 [email protected]

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);
}
Original file line number Diff line number Diff line change
@@ -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 [email protected]

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);
}
Original file line number Diff line number Diff line change
@@ -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 [email protected]

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);
}
11 changes: 11 additions & 0 deletions LibTest/js_interop/js_utils.dart
Original file line number Diff line number Diff line change
@@ -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 [email protected]

import 'dart:js_interop';

@JS()
external void eval(String code);