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

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

Issue 12250002: dart2js: In minified mode shorter getter and setter names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
ngeoffray 2013/02/12 22:01:53 2011 -> 2013
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 // Verify that we can have fields with names that start with g and s even
6 // though those names are reserved for getters and setters in minified mode.
7
8 // Note: this works because end and send are both in the list of
9 // reservedNativeProperties. In general we don't check arbitrary
10 // names for clashes because it's hard - subclasses can force superclasses
11 // to rename getters, and that can force unrelated classes to change their
12 // getters too if they have a property that has the same name.
13 class A native "*A" {
14 int bar;
15 int g;
16 int s;
17 int end;
18 int gend;
19 int send;
20 int gettersCalled;
21 int settersCalled;
22 }
23
24
25 void setup() native r"""
26 function getter() {
27 this.gettersCalled++;
28 return 42;
29 }
30
31 function setter(x) {
32 this.settersCalled++;
33 return 314;
34 }
35
36 var descriptor = {
37 get: getter,
38 set: setter,
39 configurable: false,
40 writeable: false
41 };
42
43 function A(){
44 var a = Object.create(
45 { constructor: { name: 'A'}},
46 { bar: descriptor,
47 g: descriptor,
48 s: descriptor,
49 end: descriptor,
50 gend: descriptor,
51 send: descriptor
52 });
53 a.gettersCalled = 0;
54 a.settersCalled = 0;
55 return a;
56 }
57
58 makeA = function() { return new A; };
59 """;
60
61 A makeA() native;
62
63 class B {
64 }
65
66 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
67
68 main() {
69 setup();
70 var both = [makeA(), new B()];
71 var foo = both[inscrutable(0)];
72 Expect.equals(42, foo.bar);
73 Expect.equals(42, foo.g);
74 Expect.equals(42, foo.s);
75 Expect.equals(42, foo.end);
76 Expect.equals(42, foo.gend);
77 Expect.equals(42, foo.send);
78 Expect.equals(271, foo.bar = 271);
79 Expect.equals(271, foo.g = 271);
80 Expect.equals(271, foo.s = 271);
81 Expect.equals(271, foo.end = 271);
82 Expect.equals(271, foo.gend = 271);
83 Expect.equals(271, foo.send = 271);
84 Expect.equals(6, foo.gettersCalled);
85 Expect.equals(6, foo.settersCalled);
86 }
87
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698