Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1280)

Unified Diff: tests/lib_strong/html/js_typed_interop_test.dart

Issue 2827333003: Tighten up handling of JS types and add test. (Closed)
Patch Set: Tighten up handling of JS types. Fix bug where helpers in js_mirrors were specifying name had type … Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/lib_strong/html/js_typed_interop_test.dart
diff --git a/tests/lib_strong/html/js_typed_interop_test.dart b/tests/lib_strong/html/js_typed_interop_test.dart
index 2f6194667578c38845141b6ae6ea35781abfd522..7f98ec7915afe2dfabdfb452e0a56a0e3bf0499d 100644
--- a/tests/lib_strong/html/js_typed_interop_test.dart
+++ b/tests/lib_strong/html/js_typed_interop_test.dart
@@ -14,6 +14,8 @@ _injectJs() {
document.body.append(new ScriptElement()
..type = 'text/javascript'
..innerHtml = r"""
+ "use strict";
+
var Foo = {
multiplyDefault2: function(a, b) {
if (arguments.length >= 2) return a *b;
@@ -119,6 +121,7 @@ class ClassWithFactory {
typedef num MultiplyWithDefault(num a, [num b]);
@JS()
+@anonymous
class Foo {
external int get x;
external set x(int v);
@@ -243,15 +246,19 @@ main() {
expect(foob.y, equals("why"));
// Exists in JS but not in API.
- expect(() => (foo as dynamic).zSomeInvalidName, throws);
+ // TODO(jacobr): add back this line once the appropriate metadata is
+ // tracked for anonymous JS classes.
vsm 2017/04/21 12:35:58 Is this a DDC issue? Either way, file a tracking
+ // expect(() => (foo as dynamic).zSomeInvalidName, throws);
expect(bar.multiplyByX, isTrue);
});
test('set', () {
foo.x = 42;
expect(foo.x, equals(42));
// Property tagged as read only in typed API.
- expect(() => (foob as dynamic).y = "bla", throws);
- expect(() => (foo as dynamic).unknownName = 42, throws);
+ // TODO(jacobr): add back this line once the appropriate metadata is
+ // tracked for anonymous JS classes.
+ // expect(() => (foob as dynamic).y = "bla", throws);
+ // expect(() => (foo as dynamic).unknownName = 42, throws);
});
});
@@ -267,10 +274,12 @@ main() {
foo.x = 10;
Function multiplyBy2 = foo.multiplyBy2;
expect(multiplyBy2(5), equals(10));
+ foo.x = 73;
Function multiplyByX = foo.multiplyByX;
// Tearing off a JS closure doesn't bind this.
// You will need to use the new method tearoff syntax to bind this.
- expect(multiplyByX(4), double.NAN);
+ // Invoking will trigger an error throwing because "this is undefined".
+ expect(() => multiplyByX(4), throws);
MultiplyWithDefault multiplyWithDefault = foo.multiplyDefault2Function;
expect(multiplyWithDefault(6, 6), equals(36));
@@ -286,7 +295,7 @@ main() {
// Calling a JavaScript method with too few arguments is also fine and
// defaults to JavaScript behavior of setting all unspecified arguments
// to undefined resulting in multiplying undefined by 2 == NAN.
- expect(untypedFunction(), double.NAN);
+ expect(untypedFunction().toString(), equals(double.NAN.toString()));
});
});
@@ -330,7 +339,11 @@ main() {
return foo.x + arg;
}
- var wrappedCaptureThisClosure = allowInteropCaptureThis(addThisXAndArg);
+ dynamic wrappedCaptureThisClosure =
+ allowInteropCaptureThis(addThisXAndArg);
+ expect(wrappedCaptureThisClosure is Function, isTrue);
+ expect(wrappedCaptureThisClosure is Map, isFalse);
+ expect(wrappedCaptureThisClosure is Object, isTrue);
foo.x = 20;
expect(foo.callClosureWithArgAndThis(wrappedCaptureThisClosure, 10),
equals(30));
@@ -398,9 +411,13 @@ main() {
group('type check', () {
test('js interfaces', () {
- // Is checks return true for all JavaScript interfaces.
- expect(foo is Bar, isTrue);
- expect(foo is Foob, isTrue);
+ // Is checks return true for all anonymous JS interfaces.
+ dynamic dartObject = new Object();
+ expect(foo is Foo, isTrue);
+ expect(foo is ExampleLiteral, isTrue);
+
+ expect(dartObject is Foo, isFalse);
+ expect(dartObject is ExampleLiteral, isFalse);
expect(selection is List, isTrue);

Powered by Google App Engine
This is Rietveld 408576698