Skip to content
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,43 @@
// 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 instanceOfString( String constructorName )
///
/// Whether this [JSAny?] is an `instanceof` the constructor that is defined by
/// `constructorName`, which is looked up in the `globalContext`.
///
/// If `constructorName` contains '.'s, the name is split into several parts in
/// order to get the constructor. For example, `library1.JSClass` would involve
/// fetching `library1` off of the `globalContext`, and then fetching `JSClass`
/// off of `library1` to get the constructor.
///
/// If `constructorName` is empty or any of the parts or the constructor don't
/// exist, returns `false`.
///
/// @description Checks that `instanceOfString()` returns `true` if this
/// `JSAny?` is is an `instanceof` the constructor that is defined by
/// `constructorName`.
/// @author sgrekhov22@gmail.com

import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';

main() {
eval(r'''
function A(id, name) {
this.id = id;
this.name = name;
}
function B() {}

globalThis.objA = new A(42, "A form JS");
globalThis.objB = new B();
''');
Expect.isTrue(globalContext["objA"].instanceOfString("A"));
Expect.isTrue(globalContext["objB"].instanceOfString("B"));
Expect.isFalse(globalContext["objA"].instanceOfString("B"));
Expect.isFalse(globalContext["objB"].instanceOfString("A"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 instanceOfString( String constructorName )
///
/// Whether this [JSAny?] is an `instanceof` the constructor that is defined by
/// `constructorName`, which is looked up in the `globalContext`.
///
/// If `constructorName` contains '.'s, the name is split into several parts in
/// order to get the constructor. For example, `library1.JSClass` would involve
/// fetching `library1` off of the `globalContext`, and then fetching `JSClass`
/// off of `library1` to get the constructor.
///
/// If `constructorName` is empty or any of the parts or the constructor don't
/// exist, returns `false`.
///
/// @description Checks that `instanceOfString()` returns `true` if this
/// `JSAny?` is is an `instanceof` the constructor that is defined by
/// `constructorName`.
/// @author sgrekhov22@gmail.com

import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';

main() {
eval(r'''
class A {
constructor(id, name) {
this.id = id;
this.name = name;
}
}
class B {
constructor() {}
}

globalThis.fnB = B;
globalThis.fnA = A;
globalThis.objA = new A(42, "A form JS");
globalThis.objB = new B();
''');
Expect.isTrue(globalContext["objA"].instanceOfString("fnA"));
Expect.isTrue(globalContext["objB"].instanceOfString("fnB"));
Expect.isFalse(globalContext["objA"].instanceOfString("B"));
Expect.isFalse(globalContext["objB"].instanceOfString("A"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 instanceOfString( String constructorName )
///
/// Whether this [JSAny?] is an `instanceof` the constructor that is defined by
/// `constructorName`, which is looked up in the `globalContext`.
///
/// If `constructorName` contains '.'s, the name is split into several parts in
/// order to get the constructor. For example, `library1.JSClass` would involve
/// fetching `library1` off of the `globalContext`, and then fetching `JSClass`
/// off of `library1` to get the constructor.
///
/// If `constructorName` is empty or any of the parts or the constructor don't
/// exist, returns `false`.
///
/// @description Checks that `instanceOfString()` returns `false` if
/// `constructorName` cannot be found in the `globalContext`.
/// @author sgrekhov22@gmail.com

import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';

main() {
eval(r'''
class A {
constructor(id, name) {
this.id = id;
this.name = name;
}
}
class B {
constructor() {}
}

globalThis.objA = new A(42, "A form JS");
globalThis.objB = new B();
''');
Expect.isFalse(globalContext["objA"].instanceOfString("A"));
Expect.isFalse(globalContext["objB"].instanceOfString("B"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 instanceOfString( String constructorName )
///
/// Whether this [JSAny?] is an `instanceof` the constructor that is defined by
/// `constructorName`, which is looked up in the `globalContext`.
///
/// If `constructorName` contains '.'s, the name is split into several parts in
/// order to get the constructor. For example, `library1.JSClass` would involve
/// fetching `library1` off of the `globalContext`, and then fetching `JSClass`
/// off of `library1` to get the constructor.
///
/// If `constructorName` is empty or any of the parts or the constructor don't
/// exist, returns `false`.
///
/// @description Checks that if `constructorName` then `instanceOfString`
/// returns `false`.
/// @author sgrekhov22@gmail.com

import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';

main() {
eval(r'''
class A {
constructor(id, name) {
this.id = id;
this.name = name;
}
}
class B {
constructor() {}
}
globalThis.objA = new A(42, "A form JS");
globalThis.objB = new B();
''');
Expect.isFalse(globalContext["objA"].instanceOfString(""));
Expect.isFalse(globalContext["objB"].instanceOfString(""));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 instanceOfString( String constructorName )
///
/// Whether this [JSAny?] is an `instanceof` the constructor that is defined by
/// `constructorName`, which is looked up in the `globalContext`.
///
/// If `constructorName` contains '.'s, the name is split into several parts in
/// order to get the constructor. For example, `library1.JSClass` would involve
/// fetching `library1` off of the `globalContext`, and then fetching `JSClass`
/// off of `library1` to get the constructor.
///
/// If `constructorName` is empty or any of the parts or the constructor don't
/// exist, returns `false`.
///
/// @description Checks that if any of the parts or the constructor don't exist,
/// `instanceOfString` returns `false`
/// @author sgrekhov22@gmail.com

import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';

main() {
eval(r'''
class A {
constructor(id, name) {
this.id = id;
this.name = name;
}
}
class B {
constructor() {}
}
globalThis.objA = new A(42, "A form JS");
globalThis.objB = new B();
''');
Expect.isFalse(globalContext["objA"].instanceOfString("lib1.A"));
Expect.isFalse(globalContext["objB"].instanceOfString("lib2.B"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 instanceOfString( String constructorName )
///
/// Whether this [JSAny?] is an `instanceof` the constructor that is defined by
/// `constructorName`, which is looked up in the `globalContext`.
///
/// If `constructorName` contains '.'s, the name is split into several parts in
/// order to get the constructor. For example, `library1.JSClass` would involve
/// fetching `library1` off of the `globalContext`, and then fetching `JSClass`
/// off of `library1` to get the constructor.
///
/// If `constructorName` is empty or any of the parts or the constructor don't
/// exist, returns `false`.
///
/// @description Checks that `instanceOfString()` works as expected if this
/// `JSAny?` is is an `instanceof` the constructor that is defined by
/// `constructorName`. Test the case when `constructorName` contains '.'.
/// @author sgrekhov22@gmail.com

// OtherResources=module.js
import 'dart:async';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';

final completer = Completer<String>();

void complete(String value) {
completer.complete(value);
}

main() {
globalContext["complete"] = complete.toJS;
eval(r'''
var lib1;
(async () => {
// This is path to the module on tryjobs. May not work locally.
lib1 = await import('/root_dart/tests/co19/src/LibTest/js_interop/JSAnyUtilityExtension/module.js');
globalThis.objA = new lib1.A(42, "A form JS");
globalThis.objB = new lib1.B();
console.log('initialized');
})().then(function(v) {
globalThis.complete("");
});
''');
asyncStart();
completer.future.then((_) {
Expect.isTrue(globalContext["objA"].instanceOfString("lib1.A"));
Expect.isTrue(globalContext["objB"].instanceOfString("lib1.B"));
Expect.isFalse(globalContext["objA"].instanceOfString("A"));
Expect.isFalse(globalContext["objB"].instanceOfString("B"));
asyncEnd();
});
}
43 changes: 43 additions & 0 deletions LibTest/js_interop/JSAnyUtilityExtension/instanceof_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 instanceof( JSFunction constructor )
///
/// Whether this `JSAny?` is an instance of `constructor`.
///
/// @description Checks that `instanceof()` returns `true` if this `JSAny?` is
/// an instance of `constructor` and `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'''
function A(id, name) {
this.id = id;
this.name = name;
}
function B() {}

globalThis.fnB = B;
globalThis.fnA = A;
globalThis.objA = new A(42, "A form JS");
globalThis.objB = new B();
''');
Expect.isTrue(
globalContext["objA"].instanceof(globalContext["fnA"] as JSFunction),
);
Expect.isTrue(
globalContext["objB"].instanceof(globalContext["fnB"] as JSFunction),
);
Expect.isFalse(
globalContext["objA"].instanceof(globalContext["fnB"] as JSFunction),
);
Expect.isFalse(
globalContext["objF"].instanceof(globalContext["fnA"] as JSFunction),
);
}
47 changes: 47 additions & 0 deletions LibTest/js_interop/JSAnyUtilityExtension/instanceof_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 instanceof( JSFunction constructor )
///
/// Whether this `JSAny?` is an instance of `constructor`.
///
/// @description Checks that `instanceof()` returns `true` if this `JSAny?` is
/// an instance of `constructor` and `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'''
class A {
constructor(id, name) {
this.id = id;
this.name = name;
}
}
class B {
constructor() {}
}

globalThis.fnB = B;
globalThis.fnA = A;
globalThis.objA = new A(42, "A form JS");
globalThis.objB = new B();
''');
Expect.isTrue(
globalContext["objA"].instanceof(globalContext["fnA"] as JSFunction),
);
Expect.isTrue(
globalContext["objB"].instanceof(globalContext["fnB"] as JSFunction),
);
Expect.isFalse(
globalContext["objA"].instanceof(globalContext["fnB"] as JSFunction),
);
Expect.isFalse(
globalContext["objF"].instanceof(globalContext["fnA"] as JSFunction),
);
}
6 changes: 6 additions & 0 deletions LibTest/js_interop/JSAnyUtilityExtension/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function A(id, name) {
this.id = id;
this.name = name;
}

export function B() {}