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

Unified Diff: frog/tests/frog_native/native_field_rename_2_frog_test.dart

Issue 10354005: Fix for Issue 2878 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
« no previous file with comments | « frog/tests/frog_native/native_field_rename_1_frog_test.dart ('k') | frog/world.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/tests/frog_native/native_field_rename_2_frog_test.dart
diff --git a/frog/tests/frog_native/native_field_rename_2_frog_test.dart b/frog/tests/frog_native/native_field_rename_2_frog_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c6ae9c72e2fb75a87ab70f54ef856de338bb1dee
--- /dev/null
+++ b/frog/tests/frog_native/native_field_rename_2_frog_test.dart
@@ -0,0 +1,93 @@
+// Copyright (c) 2011, 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.
+
+// A native method prevents other members from having that name, including
+// fields. However, native fields keep their name. The implication: a getter
+// for the field must be based on the field's name, not the field's jsname.
+
+interface I {
+ int key;
+}
+
+class A implements I native "*A" {
+ int key; // jsname is 'key'
+ int getKey() => key;
+}
+
+class B implements I {
+ int key; // jsname is not 'key'
+ B([this.key = 222]);
+ int getKey() => key;
+}
+
+class X native "*X" {
+ int native_key_method() native 'key';
+ // This should cause B.key to be renamed, but not A.key.
+ int key() native 'key';
+}
+
+A makeA() native;
+X makeX() native;
+
+
+void setup() native """
+// This code is all inside 'setup' and so not accesible from the global scope.
+function A(){ this.key = 111; }
+A.prototype.getKey = function(){return this.key;};
+
+function X(){}
+X.prototype.key = function(){return 666;};
+
+makeA = function(){return new A};
+makeX = function(){return new X};
+""";
+
+testDynamic() {
+ var things = [makeA(), new B(), makeX()];
+ var a = things[0];
+ var b = things[1];
+ var x = things[2];
+
+ Expect.equals(111, a.key);
+ Expect.equals(222, b.key);
+ Expect.equals(111, a.getKey());
+ Expect.equals(222, b.getKey());
+
+ Expect.equals(666, x.native_key_method());
+ Expect.equals(666, x.key());
+ var fn = x.key;
+ Expect.equals(666, fn());
+}
+
+testPartial() {
+ var things = [makeA(), new B(), makeX()];
+ I a = things[0];
+ I b = things[1];
+
+ // All subtypes of I have a field 'key'. The compiler might be tempted to
+ // generate a direct property access, but that will fail since one of the
+ // fields is renamed. A getter call is required here.
+ Expect.equals(111, a.key);
+ Expect.equals(222, b.key);
+}
+
+testTyped() {
+ A a = makeA();
+ B b = new B();
+ X x = makeX();
+
+ Expect.equals(666, x.native_key_method());
+ Expect.equals(111, a.key);
+ Expect.equals(222, b.key);
+ Expect.equals(111, a.getKey());
+ Expect.equals(222, b.getKey());
+}
+
+main() {
+ setup();
+
+ testTyped();
+ testPartial();
+ testDynamic();
+}
« no previous file with comments | « frog/tests/frog_native/native_field_rename_1_frog_test.dart ('k') | frog/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698