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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_field_rename_2_test.dart

Issue 23477028: Remove dart2js_foreign. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // A native method prevents other members from having that name, including
6 // fields. However, native fields keep their name. The implication: a getter
7 // for the field must be based on the field's name, not the field's jsname.
8
9 import "package:expect/expect.dart";
10 import 'native_metadata.dart';
11
12 abstract class I {
13 int key;
14 }
15
16 @Native("*A")
17 class A implements I {
18 int key; // jsname is 'key'
19 int getKey() => key;
20 }
21
22 class B implements I {
23 int key; // jsname is not 'key'
24 B([this.key = 222]);
25 int getKey() => key;
26 }
27
28 @Native("*X")
29 class X {
30 @Native('key') int native_key_method();
31 // This should cause B.key to be renamed, but not A.key.
32 @Native('key') int key();
33 }
34
35 @native A makeA();
36 @native X makeX();
37
38
39 @Native("""
40 // This code is all inside 'setup' and so not accesible from the global scope.
41 function A(){ this.key = 111; }
42 A.prototype.getKey = function(){return this.key;};
43
44 function X(){}
45 X.prototype.key = function(){return 666;};
46
47 makeA = function(){return new A};
48 makeX = function(){return new X};
49 """)
50 void setup();
51
52 testDynamic() {
53 var things = [makeA(), new B(), makeX()];
54 var a = things[0];
55 var b = things[1];
56 var x = things[2];
57
58 Expect.equals(111, a.key);
59 Expect.equals(222, b.key);
60 Expect.equals(111, a.getKey());
61 Expect.equals(222, b.getKey());
62
63 Expect.equals(666, x.native_key_method());
64 Expect.equals(666, x.key());
65 var fn = x.key;
66 Expect.equals(666, fn());
67 }
68
69 testPartial() {
70 var things = [makeA(), new B(), makeX()];
71 I a = things[0];
72 I b = things[1];
73
74 // All subtypes of I have a field 'key'. The compiler might be tempted to
75 // generate a direct property access, but that will fail since one of the
76 // fields is renamed. A getter call is required here.
77 Expect.equals(111, a.key);
78 Expect.equals(222, b.key);
79 }
80
81 testTyped() {
82 A a = makeA();
83 B b = new B();
84 X x = makeX();
85
86 Expect.equals(666, x.native_key_method());
87 Expect.equals(111, a.key);
88 Expect.equals(222, b.key);
89 Expect.equals(111, a.getKey());
90 Expect.equals(222, b.getKey());
91 }
92
93 main() {
94 setup();
95
96 testTyped();
97 testPartial();
98 testDynamic();
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698