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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_field_rename_1_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 @Native("*A")
13 class A {
14 int key; // jsname is 'key'
15 int getKey() => key;
16 }
17
18 class B {
19 int key; // jsname is not 'key'
20 B([this.key = 222]);
21 int getKey() => key;
22 }
23
24 @Native("*X")
25 class X {
26 @Native('key') int native_key_method();
27 // This should cause B.key to be renamed, but not A.key.
28
29 @natve('key') int key();
30 }
31
32 @native A makeA();
33 @native X makeX();
34
35
36 @Native("""
37 // This code is all inside 'setup' and so not accesible from the global scope.
38 function A(){ this.key = 111; }
39 A.prototype.getKey = function(){return this.key;};
40
41 function X(){}
42 X.prototype.key = function(){return 666;};
43
44 makeA = function(){return new A};
45 makeX = function(){return new X};
46 """)
47 void setup();
48
49 testDynamic() {
50 var things = [makeA(), new B(), makeX()];
51 var a = things[0];
52 var b = things[1];
53 var x = things[2];
54
55 Expect.equals(111, a.key);
56 Expect.equals(222, b.key);
57 Expect.equals(111, a.getKey());
58 Expect.equals(222, b.getKey());
59
60
61 Expect.equals(666, x.native_key_method());
62 Expect.equals(666, x.key());
63 // The getter for the closurized member must also have the right name.
64 var fn = x.key;
65 Expect.equals(666, fn());
66 }
67
68 testTyped() {
69 A a = makeA();
70 B b = new B();
71 X x = makeX();
72
73 Expect.equals(666, x.native_key_method());
74 Expect.equals(111, a.key);
75 Expect.equals(222, b.key);
76 Expect.equals(111, a.getKey());
77 Expect.equals(222, b.getKey());
78 }
79
80 main() {
81 setup();
82
83 testTyped();
84 testDynamic();
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698