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

Side by Side Diff: frog/tests/frog_native/native_field_rename_1_frog_test.dart

Issue 10536169: Move frog/tests/{leg,leg_only,frog_native} to tests/compiler/. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 class A native "*A" {
10 int key; // jsname is 'key'
11 int getKey() => key;
12 }
13
14 class B {
15 int key; // jsname is not 'key'
16 B([this.key = 222]);
17 int getKey() => key;
18 }
19
20 class X native "*X" {
21 int native_key_method() native 'key';
22 // This should cause B.key to be renamed, but not A.key.
23
24 int key() native 'key';
25 }
26
27 A makeA() native;
28 X makeX() native;
29
30
31 void setup() native """
32 // This code is all inside 'setup' and so not accesible from the global scope.
33 function A(){ this.key = 111; }
34 A.prototype.getKey = function(){return this.key;};
35
36 function X(){}
37 X.prototype.key = function(){return 666;};
38
39 makeA = function(){return new A};
40 makeX = function(){return new X};
41 """;
42
43 testDynamic() {
44 var things = [makeA(), new B(), makeX()];
45 var a = things[0];
46 var b = things[1];
47 var x = things[2];
48
49 Expect.equals(111, a.key);
50 Expect.equals(222, b.key);
51 Expect.equals(111, a.getKey());
52 Expect.equals(222, b.getKey());
53
54
55 Expect.equals(666, x.native_key_method());
56 Expect.equals(666, x.key());
57 // The getter for the closurized member must also have the right name.
58 var fn = x.key;
59 Expect.equals(666, fn());
60 }
61
62 testTyped() {
63 A a = makeA();
64 B b = new B();
65 X x = makeX();
66
67 Expect.equals(666, x.native_key_method());
68 Expect.equals(111, a.key);
69 Expect.equals(222, b.key);
70 Expect.equals(111, a.getKey());
71 Expect.equals(222, b.getKey());
72 }
73
74 main() {
75 setup();
76
77 testTyped();
78 testDynamic();
79 }
OLDNEW
« no previous file with comments | « frog/tests/frog_native/native_exceptions1_frog_test.dart ('k') | frog/tests/frog_native/native_field_rename_2_frog_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698