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

Unified Diff: tests/compiler/dart2js_native/fixup_get_tag_test.dart

Issue 19533006: Add dartExperimentalFixupGetTag for polymer experiments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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/compiler/dart2js_native/fixup_get_tag_test.dart
diff --git a/tests/compiler/dart2js_native/fixup_get_tag_test.dart b/tests/compiler/dart2js_native/fixup_get_tag_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fbf9e3ad965cb2eade9e6c0b5f59a6449be66291
--- /dev/null
+++ b/tests/compiler/dart2js_native/fixup_get_tag_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2013, 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.
+
+import "package:expect/expect.dart";
+
+// Test for dartExperimentalFixupGetTag.
+
+class Foo native "A" { // There is one native class with dispatch tag 'A'.
ahe 2013/07/24 08:46:18 Extract space before //.
sra1 2013/07/25 21:47:09 Hmm. I recall being told in a code review to put
+ token() native;
+}
+
+void setup() native r"""
+
+dartExperimentalFixupGetTag = function (originalGetTag) {
+ function fixedGetTag(obj) {
+ // Local JS 'class' B is made to be another implementation of the native
+ // class with tag 'A'.
+ if (obj instanceof B) return 'A';
+ // Other classes behave as before.
+ return originalGetTag(obj);
+ }
+ return fixedGetTag;
+};
+
+function A(){ }
+A.prototype.token = function () { return 'isA'; }
+
+function B(){ }
+B.prototype.token = function () { return 'isB'; }
+
+makeA = function() { return new A; };
+makeB = function() { return new B; };
+""";
+
+makeA() native;
+makeB() native;
+
+main() {
+ setup();
+
+ var a = makeA();
+ var b = makeB();
+
+ Expect.equals('isA', a.token());
+
+ // This call succeeds because the fixed-up 'getTag' method returns Foo's
+ // dispatch tag, and B is a faithful polyfil for Foo/A.
+ Expect.equals('isB', b.token());
ahe 2013/07/24 08:46:18 Would it make sense to add: Expect.isTrue(a is A)
sra1 2013/07/25 21:47:09 Should be: Expect.isTrue(b is Foo); Done.
+}
« sdk/lib/_internal/lib/native_helper.dart ('K') | « sdk/lib/_internal/lib/native_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698