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

Side by Side Diff: tests/compiler/dart2js_native/native_field_name_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 // Check that native fields are not incorrectly renamed. 7 // Check that native fields are not incorrectly renamed.
8 8
9 @Native("A") 9 @Native("A")
10 class A { 10 class A {
11 int myLongPropertyName; 11 int myLongPropertyName;
12 int getValue; 12 int getValue;
13 13
14 int method(int z) => myLongPropertyName; 14 int method(int z) => myLongPropertyName;
15 } 15 }
16 16
17 // This code is inside the setup function, so the function names are not 17 // This code is inside the setup function, so the function names are not
18 // accessible, but the makeA variable is global through the magic of JS scoping. 18 // accessible, but the makeA variable is global through the magic of JS scoping.
19 // The contents of this are of course not analyzable by the compiler. 19 // The contents of this are of course not analyzable by the compiler.
20 void setup() native r""" 20 void setup() {
21 function getter() { 21 JS('', r"""
22 return ++this.getValue; 22 (function(){
23 function getter() {
24 return ++this.getValue;
25 }
26
27 function setter(x) {
28 this.getValue += 10;
29 }
30
31 function A(){
32 var a = Object.create(
33 { constructor: A },
34 { myLongPropertyName: { get: getter,
35 set: setter,
36 configurable: false,
37 writeable: false
38 }
39 });
40 a.getValue = 0;
41 return a;
42 }
43
44 makeA = function(){return new A()};
45
46 self.nativeConstructor(A);
47 })()""");
23 } 48 }
24 49
25 function setter(x) {
26 this.getValue += 10;
27 }
28
29 function A(){
30 var a = Object.create(
31 { constructor: A },
32 { myLongPropertyName: { get: getter,
33 set: setter,
34 configurable: false,
35 writeable: false
36 }
37 });
38 a.getValue = 0;
39 return a;
40 }
41
42 makeA = function(){return new A;};
43
44 self.nativeConstructor(A);
45 """;
46
47 /*A*/ makeA() native; 50 /*A*/ makeA() native;
48 51
49 main() { 52 main() {
50 nativeTesting(); 53 nativeTesting();
51 setup(); 54 setup();
52 var a = makeA(); 55 var a = makeA();
53 a.myLongPropertyName = 21; 56 a.myLongPropertyName = 21;
54 int gotten = a.myLongPropertyName; 57 int gotten = a.myLongPropertyName;
55 Expect.equals(11, gotten); 58 Expect.equals(11, gotten);
56 59
57 var a2 = makeA(); 60 var a2 = makeA();
58 if (a2 is A) { 61 if (a2 is A) {
59 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted 62 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted
60 // to access myLongPropertyName directly, using its minified name. But 63 // to access myLongPropertyName directly, using its minified name. But
61 // renaming of native properties can only work using getters and setters 64 // renaming of native properties can only work using getters and setters
62 // that access the original name. 65 // that access the original name.
63 a2.myLongPropertyName = 21; 66 a2.myLongPropertyName = 21;
64 int gotten = a2.myLongPropertyName; 67 int gotten = a2.myLongPropertyName;
65 Expect.equals(11, gotten); 68 Expect.equals(11, gotten);
66 } 69 }
67 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698