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

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

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 years, 1 month 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 "dart:_js_helper"; 5 import 'native_testing.dart';
6 import "package:expect/expect.dart";
7 6
8 // Check that native fields are not incorrectly renamed. 7 // Check that native fields are not incorrectly renamed.
9 8
10 @Native("A") 9 @Native("A")
11 class A { 10 class A {
12 int myLongPropertyName; 11 int myLongPropertyName;
13 int getValue; 12 int getValue;
14 13
15 int method(int z) => myLongPropertyName; 14 int method(int z) => myLongPropertyName;
16 } 15 }
17 16
18 // 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
19 // 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.
20 // 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.
21 void setup() native r""" 20 void setup() native r"""
22 function getter() { 21 function getter() {
23 return ++this.getValue; 22 return ++this.getValue;
24 } 23 }
25 24
26 function setter(x) { 25 function setter(x) {
27 this.getValue += 10; 26 this.getValue += 10;
28 } 27 }
29 28
30 function A(){ 29 function A(){
31 var a = Object.create( 30 var a = Object.create(
32 { constructor: { name: 'A'}}, 31 { constructor: A },
33 { myLongPropertyName: { get: getter, 32 { myLongPropertyName: { get: getter,
34 set: setter, 33 set: setter,
35 configurable: false, 34 configurable: false,
36 writeable: false 35 writeable: false
37 } 36 }
38 }); 37 });
39 a.getValue = 0; 38 a.getValue = 0;
40 return a; 39 return a;
41 } 40 }
42 41
43 makeA = function(){return new A;}; 42 makeA = function(){return new A;};
43
44 self.nativeConstructor(A);
44 """; 45 """;
45 46
46 A makeA() native ; 47 /*A*/ makeA() native ;
47 48
48 main() { 49 main() {
50 nativeTesting();
49 setup(); 51 setup();
50 var a = makeA(); 52 var a = makeA();
51 a.myLongPropertyName = 21; 53 a.myLongPropertyName = 21;
52 int gotten = a.myLongPropertyName; 54 int gotten = a.myLongPropertyName;
53 Expect.equals(11, gotten); 55 Expect.equals(11, gotten);
54 56
55 var a2 = makeA(); 57 var a2 = makeA();
56 if (a2 is A) { 58 if (a2 is A) {
57 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted 59 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted
58 // to access myLongPropertyName directly, using its minified name. But 60 // to access myLongPropertyName directly, using its minified name. But
59 // renaming of native properties can only work using getters and setters 61 // renaming of native properties can only work using getters and setters
60 // that access the original name. 62 // that access the original name.
61 a2.myLongPropertyName = 21; 63 a2.myLongPropertyName = 21;
62 int gotten = a2.myLongPropertyName; 64 int gotten = a2.myLongPropertyName;
63 Expect.equals(11, gotten); 65 Expect.equals(11, gotten);
64 } 66 }
65 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698