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

Unified Diff: tests/html/js_typed_interop_test.dart

Issue 1583773003: Support JS$ prefix for dart and fix bug where _operator_getter and the [] operator were used incons… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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/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 14d931f0d69ec46d16ee00151d29406804ad76fe..81c190cd1bd3dfa0bf8c4e070ed4513141b5f59b 100644
--- a/tests/html/js_typed_interop_test.dart
+++ b/tests/html/js_typed_interop_test.dart
@@ -130,11 +130,12 @@ class Foo {
@anonymous
@JS()
class ExampleLiteral {
- external factory ExampleLiteral({int x, String y, num z});
+ external factory ExampleLiteral({int x, String y, num z, String JS$class});
external int get x;
external String get y;
external num get z;
+ external String get JS$class;
}
@anonymous
@@ -167,6 +168,51 @@ addWithDefault(a, [b = 100]) => a + b;
external Function get returnNumArgs;
external Function get returnLastArg;
+/**
+ * Placeholder object for cases where we need to determine exactly how many
+ * args were passed to a function.
+ */
+const _UNDEFINED = const Object();
+
+// TODO(jacobr): this method is a hack to work around the lack of proper dart
+// support for varargs methods.
+List _stripUndefinedArgs(List args) =>
+ args.takeWhile((i) => i != _UNDEFINED).toList();
+
+int returnNumArgsDart([a1 = _UNDEFINED,
+ a2 = _UNDEFINED,
+ a3 = _UNDEFINED,
+ a4 = _UNDEFINED,
+ a5 = _UNDEFINED,
+ a6 = _UNDEFINED,
+ a7 = _UNDEFINED,
+ a8 = _UNDEFINED,
+ a9 = _UNDEFINED,
+ a10 = _UNDEFINED,
+ a11 = _UNDEFINED,
+ a12 = _UNDEFINED,
+ a13 = _UNDEFINED,
+ a14 = _UNDEFINED,
+ a15 = _UNDEFINED]) =>
+ _stripUndefinedArgs([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15]).length;
+
+returnLastArgDart([a1 = _UNDEFINED,
+ a2 = _UNDEFINED,
+ a3 = _UNDEFINED,
+ a4 = _UNDEFINED,
+ a5 = _UNDEFINED,
+ a6 = _UNDEFINED,
+ a7 = _UNDEFINED,
+ a8 = _UNDEFINED,
+ a9 = _UNDEFINED,
+ a10 = _UNDEFINED,
+ a11 = _UNDEFINED,
+ a12 = _UNDEFINED,
+ a13 = _UNDEFINED,
+ a14 = _UNDEFINED,
+ a15 = _UNDEFINED]) =>
+ _stripUndefinedArgs([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15]).last;
+
const STRINGIFY_LOCATION = "JSON.stringify";
@JS(STRINGIFY_LOCATION)
external String stringify(obj);
@@ -207,6 +253,11 @@ main() {
expect(l.y, isNull);
expect(l.z, equals(100));
expect(stringify(l), equals('{"z":100}'));
+ l = new ExampleLiteral(JS$class: "clazz");
+ expect(l.x, isNull);
+ expect(l.y, isNull);
+ expect(l.JS$class, equals("clazz"));
+ expect(stringify(l), equals('{"class":"clazz"}'));
});
test('empty', () {
@@ -340,15 +391,28 @@ main() {
});
test('call from dart', () {
- var returnNumArgsFn = returnNumArgs;
- var returnLastArgFn = returnLastArg;
- expect(returnNumArgsFn(), equals(0));
- expect(returnNumArgsFn("a", "b", "c"), equals(3));
- expect(returnNumArgsFn("a", "b", "c", null, null), equals(5));
- expect(returnNumArgsFn(1, 2, 3, 4, 5, 6, null), equals(7));
- expect(returnNumArgsFn(1, 2, 3, 4, 5, 6, 7, 8), equals(8));
- expect(returnLastArgFn(1, 2, "foo"), equals("foo"));
- expect(returnLastArgFn(1, 2, 3, 4, 5, 6, "foo"), equals("foo"));
+ testReturnNumArgs(Function fn) {
+ expect(fn(), equals(0));
+ expect(fn("a", "b", "c"), equals(3));
+ expect(fn("a", "b", "c", null, null), equals(5));
+ expect(fn(1, 2, 3, 4, 5, 6, null), equals(7));
+ expect(fn(1, 2, 3, 4, 5, 6, 7, 8), equals(8));
+ expect(fn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), equals(12));
+ }
+ testReturnLastArgFn(Function fn) {
+ expect(fn(1, 2, "foo"), equals("foo"));
+ expect(fn(1, 2, 3, 4, 5, 6, "foo"), equals("foo"));
+ expect(fn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "bar"), equals("bar"));
+ }
+ testReturnNumArgs(returnNumArgs);
+ testReturnLastArgFn(returnLastArg);
+
+ testReturnNumArgs(returnNumArgsDart);
+ testReturnLastArgFn(returnLastArgDart);
+
+ testReturnNumArgs(allowInterop(returnNumArgsDart));
+ testReturnLastArgFn(allowInterop(returnLastArgDart));
+ testReturnLastArgFn(allowInteropCaptureThis(returnLastArgDart));
});
});

Powered by Google App Engine
This is Rietveld 408576698