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

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

Issue 2990083002: dart2js_native tests: Migrate 'native STRING' to JS-calls - part 2/2 (Closed)
Patch Set: remove defunct comments Created 3 years, 4 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 import "native_testing.dart"; 5 import "native_testing.dart";
6 6
7 // Verify that we can have fields with names that start with g and s even 7 // Verify that we can have fields with names that start with g and s even
8 // though those names are reserved for getters and setters in minified mode. 8 // though those names are reserved for getters and setters in minified mode.
9 9
10 // Note: this works because end and send are both in the list of 10 // Note: this works because end and send are both in the list of
11 // reservedNativeProperties. In general we don't check arbitrary 11 // reservedNativeProperties. In general we don't check arbitrary
12 // names for clashes because it's hard - subclasses can force superclasses 12 // names for clashes because it's hard - subclasses can force superclasses
13 // to rename getters, and that can force unrelated classes to change their 13 // to rename getters, and that can force unrelated classes to change their
14 // getters too if they have a property that has the same name. 14 // getters too if they have a property that has the same name.
15 @Native("A") 15 @Native("A")
16 class A { 16 class A {
17 int bar; 17 int bar;
18 int g; 18 int g;
19 int s; 19 int s;
20 int end; 20 int end;
21 int gend; 21 int gend;
22 int send; 22 int send;
23 int gettersCalled; 23 int gettersCalled;
24 int settersCalled; 24 int settersCalled;
25 } 25 }
26 26
27 void setup() native r""" 27 void setup() {
28 function getter() { 28 JS('', r"""
29 this.gettersCalled++; 29 (function(){
30 return 42; 30 function getter() {
31 this.gettersCalled++;
32 return 42;
33 }
34
35 function setter(x) {
36 this.settersCalled++;
37 return 314;
38 }
39
40 var descriptor = {
41 get: getter,
42 set: setter,
43 configurable: false,
44 writeable: false
45 };
46
47 function A(){
48 var a = Object.create(
49 { constructor: A },
50 { bar: descriptor,
51 g: descriptor,
52 s: descriptor,
53 end: descriptor,
54 gend: descriptor,
55 send: descriptor
56 });
57 a.gettersCalled = 0;
58 a.settersCalled = 0;
59 return a;
60 }
61
62 makeA = function() { return new A(); };
63 self.nativeConstructor(A);
64 })()""");
31 } 65 }
32 66
33 function setter(x) {
34 this.settersCalled++;
35 return 314;
36 }
37
38 var descriptor = {
39 get: getter,
40 set: setter,
41 configurable: false,
42 writeable: false
43 };
44
45 function A(){
46 var a = Object.create(
47 { constructor: A },
48 { bar: descriptor,
49 g: descriptor,
50 s: descriptor,
51 end: descriptor,
52 gend: descriptor,
53 send: descriptor
54 });
55 a.gettersCalled = 0;
56 a.settersCalled = 0;
57 return a;
58 }
59
60 makeA = function() { return new A; };
61 self.nativeConstructor(A);
62 """;
63
64 A makeA() native; 67 A makeA() native;
65 68
66 class B {} 69 class B {}
67 70
68 main() { 71 main() {
69 nativeTesting(); 72 nativeTesting();
70 setup(); 73 setup();
71 confuse(new B()); 74 confuse(new B());
72 var a = makeA(); 75 var a = makeA();
73 76
(...skipping 20 matching lines...) Expand all
94 Expect.equals(42, a.send); 97 Expect.equals(42, a.send);
95 Expect.equals(271, a.bar = 271); 98 Expect.equals(271, a.bar = 271);
96 Expect.equals(271, a.g = 271); 99 Expect.equals(271, a.g = 271);
97 Expect.equals(271, a.s = 271); 100 Expect.equals(271, a.s = 271);
98 Expect.equals(271, a.end = 271); 101 Expect.equals(271, a.end = 271);
99 Expect.equals(271, a.gend = 271); 102 Expect.equals(271, a.gend = 271);
100 Expect.equals(271, a.send = 271); 103 Expect.equals(271, a.send = 271);
101 Expect.equals(12, a.gettersCalled); 104 Expect.equals(12, a.gettersCalled);
102 Expect.equals(12, a.settersCalled); 105 Expect.equals(12, a.settersCalled);
103 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698