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

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

Issue 2654583002: Closes https://github.com/dart-lang/sdk/issues/28291 (Closed)
Patch Set: Created 3 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/lib_strong/html/js_extend_class_test.dart
diff --git a/tests/lib_strong/html/js_extend_class_test.dart b/tests/lib_strong/html/js_extend_class_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..eb6ea57a2d35c7db71be8ae858316cb807719756
--- /dev/null
+++ b/tests/lib_strong/html/js_extend_class_test.dart
@@ -0,0 +1,57 @@
+// Copyright (c) 2017, 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.
+
+@JS()
+library js_extend_class_test;
+
+import 'dart:html';
+
+import 'package:js/js.dart';
+import 'package:js/js_util.dart' as js_util;
+import 'package:expect/minitest.dart';
+
+@JS('Date')
+class JSDate {
+ external get jsField;
+ external get jsMethod;
+}
+
+@JS('Date.prototype.jsField')
+external set datePrototypeJSField(v);
+
+@JS('Date.prototype.jsMethod')
+external set datePrototypeJSMethod(v);
+
+// Extending a JS class with a Dart class is only supported by DDC for now.
+// We extend the Date class instead of a user defined JS class to avoid the
+// hassle of ensuring the JS class exists before we use it.
+class DartJsDate extends JSDate {
+ get dartField => 100;
+ int dartMethod(x) {
+ return x * 2;
+ }
+}
+
+main() {
+ // Monkey-patch the JS Date class.
+ datePrototypeJSField = 42;
+ datePrototypeJSMethod = allowInterop((x) => x * 10);
+
+ group('extend js class', () {
+ test('js class members', () {
+ var bar = new DartJsDate();
+ expect(bar.jsField, equals(42));
+ expect(bar.jsMethod(5), equals(50));
+
+ expect(bar.dartField, equals(100));
+ expect(bar.dartMethod(4), equals(8));
+ });
+
+ test('dart subclass members', () {
+ var bar = new DartJsDate();
+ expect(bar.dartField, equals(100));
+ expect(bar.dartMethod(4), equals(8));
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698