Index: tests/html/js_typed_interop_test.dart |
diff --git a/tests/html/js_typed_interop_test.dart b/tests/html/js_typed_interop_test.dart |
index 431d533037e10d83a3493fd049c0da557b007927..acb10e05ebc8f4b509b08b24300e54e6dcfc9775 100644 |
--- a/tests/html/js_typed_interop_test.dart |
+++ b/tests/html/js_typed_interop_test.dart |
@@ -71,6 +71,15 @@ _injectJs() { |
getA: function() { return this.a;} |
}; |
+ function _PrivateClass(a, b) { |
+ this._a = a; |
+ this._b = b; |
+ }; |
+ |
+ _PrivateClass.prototype = { |
+ _getA: function() { return this._a;} |
+ }; |
+ |
var selection = ["a", "b", "c", foo, bar]; |
function returnNumArgs() { return arguments.length; }; |
@@ -78,6 +87,9 @@ _injectJs() { |
function confuse(obj) { return obj; } |
+ window['class'] = function() { return 42; }; |
+ window['delete'] = 100; |
+ |
function StringWrapper(str) { |
this.str = str; |
} |
@@ -110,6 +122,26 @@ class ClassWithConstructor { |
external get b; |
} |
+@JS('ClassWithConstructor') |
+class _ClassWithConstructor { |
+ external _ClassWithConstructor(aParam, bParam); |
+ external getA(); |
+ external get a; |
+ external get b; |
+} |
+ |
+@JS() |
+class JS$_PrivateClass { |
+ external JS$_PrivateClass(aParam, bParam); |
+ external JS$_getA(); |
+ external get JS$_a; |
+ external get JS$_b; |
+ // Equivalent to JS$_a but only visible within |
+ // the class. |
+ external get _a; |
+} |
+ |
+ |
typedef num MultiplyWithDefault(num a, [num b]); |
@JS() |
@@ -118,6 +150,7 @@ class Foo { |
external set x(int v); |
external num multiplyByX(num y); |
external num multiplyBy2(num y); |
+ external num JS$multiplyBy2(num y); |
external MultiplyWithDefault get multiplyDefault2Function; |
external callClosureWithArgAndThis(Function closure, arg); |
@@ -126,14 +159,17 @@ class Foo { |
external Bar getBar(); |
external static num multiplyDefault2(num a, [num b]); |
+ // Should desugar to multiplyDefault2. |
+ external static num JS$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, JS$class}); |
external int get x; |
+ external int get JS$class; |
external String get y; |
external num get z; |
} |
@@ -182,6 +218,13 @@ class StringWrapper { |
@JS() |
external confuse(obj); |
+/// Desugars to calling the js method named class. |
+@JS() |
+external JS$class(); |
+ |
+@JS() |
+external get JS$delete; |
+ |
@JS() |
external CanvasRenderingContext2D getCanvasContext(); |
@@ -191,6 +234,16 @@ external num get propertyOnDocument; |
@JS('window.self.window.window.windowProperty') |
external num get propertyOnWindow; |
+@JS() |
+@anonymous |
+class Simple |
+{ |
+ external List<int> get numbers; |
+ external set numbers(List<int> numbers); |
+ |
+ external factory Simple({ List<int> numbers }); |
+} |
+ |
main() { |
_injectJs(); |
@@ -210,6 +263,17 @@ main() { |
expect(stringify(l), equals('{"z":100}')); |
}); |
+ test('with array', () { |
+ // Repro for https://github.com/dart-lang/sdk/issues/26768 |
+ var simple = new Simple(numbers: [ 1, 2, 3 ]); |
+ expect(stringify(simple), equals('{"numbers":[1,2,3]}')); |
+ }); |
+ |
+ test(r'JS$ escaped name', () { |
+ var l = new ExampleLiteral(JS$class: 3, y: "foo"); |
+ expect(l.JS$class, equals(3)); |
+ }); |
+ |
test('empty', () { |
var l = new EmptyLiteral(); |
expect(stringify(l), equals('{}')); |
@@ -225,6 +289,25 @@ main() { |
}); |
}); |
+ group('private class', () { |
+ test('simple', () { |
+ var o = new _ClassWithConstructor("foo", "bar"); |
+ expect(o.a, equals("foo")); |
+ expect(o.b, equals("bar")); |
+ expect(o.getA(), equals("foo")); |
+ }); |
+ }); |
+ |
+ group('private class', () { |
+ test('simple', () { |
+ var o = new JS$_PrivateClass("foo", "bar"); |
+ expect(o.JS$_a, equals("foo")); |
+ expect(o.JS$_b, equals("bar")); |
+ expect(o._a, equals("foo")); |
+ expect(o.JS$_getA(), equals("foo")); |
+ }); |
+ }); |
+ |
group('property', () { |
test('get', () { |
expect(foo.x, equals(3)); |
@@ -276,6 +359,14 @@ main() { |
expect(untypedFunction(), isNaN); |
}); |
+ |
+ test(r'JS$ escaped name', () { |
+ foo.x = 10; |
+ expect(foo.JS$multiplyBy2(5), equals(10)); |
+ |
+ Function multiplyBy2 = foo.JS$multiplyBy2; |
+ expect(multiplyBy2(5), equals(10)); |
+ }); |
}); |
group('static_method_call', () { |
@@ -283,6 +374,11 @@ main() { |
expect(Foo.multiplyDefault2(6, 7), equals(42)); |
expect(Foo.multiplyDefault2(6), equals(12)); |
}); |
+ |
+ test(r'JS$ escaped name', () { |
+ expect(Foo.JS$multiplyDefault2(6, 7), equals(42)); |
+ expect(Foo.JS$multiplyDefault2(6), equals(12)); |
+ }); |
}); |
// Note: these extra groups are added to be able to mark each test |
@@ -384,6 +480,13 @@ main() { |
}); |
}); |
+ group(r'JS$ escaped', () { |
+ test('top level', () { |
+ expect(JS$class(), equals(42)); |
+ expect(JS$delete, equals(100)); |
+ }); |
+ }); |
+ |
group('type check', () { |
test('js interfaces', () { |
// Is checks return true for all JavaScript interfaces. |