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

Side by Side Diff: tests/compiler/dart2js_native/native_field_rename_1_frog_test.dart

Issue 2383273002: Revert "Add native_testing library to mock @Native classes" (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // A native method prevents other members from having that name, including 5 // A native method prevents other members from having that name, including
6 // fields. However, native fields keep their name. The implication: a getter 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. 7 // for the field must be based on the field's name, not the field's jsname.
8 8
9 import 'native_testing.dart'; 9 import "package:expect/expect.dart";
10 import 'dart:_js_helper' show Native, JSName;
10 11
11 @Native("A") 12 @Native("A")
12 class A { 13 class A {
13 int key; // jsname is 'key' 14 int key; // jsname is 'key'
14 int getKey() => key; 15 int getKey() => key;
15 } 16 }
16 17
17 class B { 18 class B {
18 int key; // jsname is not 'key' 19 int key; // jsname is not 'key'
19 B([this.key = 222]); 20 B([this.key = 222]);
(...skipping 16 matching lines...) Expand all
36 void setup() native """ 37 void setup() native """
37 // This code is all inside 'setup' and so not accesible from the global scope. 38 // This code is all inside 'setup' and so not accesible from the global scope.
38 function A(){ this.key = 111; } 39 function A(){ this.key = 111; }
39 A.prototype.getKey = function(){return this.key;}; 40 A.prototype.getKey = function(){return this.key;};
40 41
41 function X(){} 42 function X(){}
42 X.prototype.key = function(){return 666;}; 43 X.prototype.key = function(){return 666;};
43 44
44 makeA = function(){return new A}; 45 makeA = function(){return new A};
45 makeX = function(){return new X}; 46 makeX = function(){return new X};
46
47 self.nativeConstructor(A);
48 self.nativeConstructor(X);
49 """; 47 """;
50 48
51 testDynamic() { 49 testDynamic() {
52 var a = confuse(makeA()); 50 var things = [makeA(), new B(), makeX()];
53 var b = confuse(new B()); 51 var a = things[0];
54 var x = confuse(makeX()); 52 var b = things[1];
53 var x = things[2];
55 54
56 Expect.equals(111, a.key); 55 Expect.equals(111, a.key);
57 Expect.equals(222, b.key); 56 Expect.equals(222, b.key);
58 Expect.equals(111, a.getKey()); 57 Expect.equals(111, a.getKey());
59 Expect.equals(222, b.getKey()); 58 Expect.equals(222, b.getKey());
60 59
61 Expect.equals(666, x.native_key_method()); 60 Expect.equals(666, x.native_key_method());
62 Expect.equals(666, x.key()); 61 Expect.equals(666, x.key());
63 // The getter for the closurized member must also have the right name. 62 // The getter for the closurized member must also have the right name.
64 var fn = x.key; 63 var fn = x.key;
65 Expect.equals(666, fn()); 64 Expect.equals(666, fn());
66 } 65 }
67 66
68 testTyped() { 67 testTyped() {
69 A a = makeA(); 68 A a = makeA();
70 B b = new B(); 69 B b = new B();
71 X x = makeX(); 70 X x = makeX();
72 71
73 Expect.equals(666, x.native_key_method()); 72 Expect.equals(666, x.native_key_method());
74 Expect.equals(111, a.key); 73 Expect.equals(111, a.key);
75 Expect.equals(222, b.key); 74 Expect.equals(222, b.key);
76 Expect.equals(111, a.getKey()); 75 Expect.equals(111, a.getKey());
77 Expect.equals(222, b.getKey()); 76 Expect.equals(222, b.getKey());
78 } 77 }
79 78
80 main() { 79 main() {
81 nativeTesting();
82 setup(); 80 setup();
83 81
84 testTyped(); 82 testTyped();
85 testDynamic(); 83 testDynamic();
86 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698